VTK
vtkControlPointsItem.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkControlPointsItem.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
15
31#ifndef vtkControlPointsItem_h
32#define vtkControlPointsItem_h
33
34#include "vtkChartsCoreModule.h" // For export macro
35#include "vtkCommand.h" // For vtkCommand enum
36#include "vtkPlot.h"
37#include "vtkVector.h" // For vtkVector2f
38
40class vtkContext2D;
41class vtkPoints2D;
42class vtkTransform2D;
43
44class VTKCHARTSCORE_EXPORT vtkControlPointsItem: public vtkPlot
45{
46public:
48 virtual void PrintSelf(ostream &os, vtkIndent indent);
49
50 // Events fires by this class (and subclasses).
51 // \li CurrentPointChangedEvent is fired when the current point index is changed.
52 // \li CurrentPointEditEvent is fired to request the application to show UI to
53 // edit the current point.
54 // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
55 // to mark groups of changes to control points.
56 enum {
57 CurrentPointChangedEvent = vtkCommand::UserEvent,
58 CurrentPointEditEvent
59 };
60
65 virtual void GetBounds(double bounds[4]);
66
68
73 vtkSetVector4Macro(UserBounds, double);
74 vtkGetVector4Macro(UserBounds, double);
76
78
83 vtkSetVector4Macro(ValidBounds, double);
84 vtkGetVector4Macro(ValidBounds, double);
86
88
92 vtkGetMacro(ScreenPointRadius, float);
93 vtkSetMacro(ScreenPointRadius, float);
95
101 virtual bool Paint(vtkContext2D *painter);
102
106 void SelectPoint(vtkIdType pointId);
107
113 void SelectPoint(double* currentPoint);
114
119
124
130 void DeselectPoint(double* currentPoint);
131
136
142
148 void ToggleSelectPoint(double* currentPoint);
149
153 virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
154
159
164 vtkIdType FindPoint(double* pos);
165
171 bool IsOverPoint(double* pos, vtkIdType pointId);
172
177
184 bool excludeFirstAndLast = false)const;
185
187
192 vtkGetMacro(StrokeMode, bool);
194
196
202 vtkSetMacro(SwitchPointsMode, bool);
203 vtkGetMacro(SwitchPointsMode, bool);
205
207
211 vtkSetMacro(EndPointsXMovable, bool);
212 vtkGetMacro(EndPointsXMovable, bool);
213 vtkSetMacro(EndPointsYMovable, bool);
214 vtkGetMacro(EndPointsYMovable, bool);
215 virtual bool GetEndPointsMovable();
217
219
223 vtkSetMacro(EndPointsRemovable, bool);
224 vtkGetMacro(EndPointsRemovable, bool);
226
228
232 vtkSetMacro(ShowLabels, bool);
233 vtkGetMacro(ShowLabels, bool);
235
237
240 vtkSetStringMacro(LabelFormat);
241 vtkGetStringMacro(LabelFormat);
243
249 virtual vtkIdType AddPoint(double* newPos) = 0;
250
256 virtual vtkIdType RemovePoint(double* pos) = 0;
257
263
267 inline void RemoveCurrentPoint();
268
272 virtual vtkIdType GetNumberOfPoints()const = 0;
273
279 virtual void GetControlPoint(vtkIdType index, double *point)const = 0;
280
285 virtual void SetControlPoint(vtkIdType index, double *point) = 0;
286
296
302 void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
303
312 void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
313
319 void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
320
326
331
333
336 vtkGetObjectMacro(SelectedPointPen, vtkPen);
338
340
344 vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
346
352
354
357 virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
358 virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse);
360
364 virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
365
368
369protected:
372
380 virtual void emitEvent(unsigned long event, void* params = 0) = 0;
381
382 static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params);
383
385
389 virtual void ComputePoints();
392
396 virtual bool Hit(const vtkContextMouseEvent &mouse);
397
399
403 virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
404 virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
406
408
412 virtual bool ClampPos(double pos[2], double bounds[4]);
413 bool ClampValidPos(double pos[2]);
415
417
423 virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
425
426 void SetCurrentPointPos(const vtkVector2f& newPos);
430
431 inline vtkVector2f GetSelectionCenterOfMass()const;
433
434 void Stroke(const vtkVector2f& newPos);
435 virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
440
445
446 void AddPointId(vtkIdType addedPointId);
447
453
458
465 virtual void ComputeBounds(double* bounds);
466
472 virtual bool UsingLogScale() { return false; }
473
481
482 double Bounds[4];
483 double UserBounds[4];
484 double ValidBounds[4];
485
488
503private:
504 vtkControlPointsItem(const vtkControlPointsItem &) VTK_DELETE_FUNCTION;
505 void operator=(const vtkControlPointsItem &) VTK_DELETE_FUNCTION;
506
507 void ComputeBounds();
508
509 vtkIdType RemovePointId(vtkIdType removedPointId);
510};
511
512//-----------------------------------------------------------------------------
514{
515 this->RemovePoint(this->GetCurrentPoint());
516}
517
518//-----------------------------------------------------------------------------
520{
521 return this->GetCenterOfMass(this->Selection);
522}
523
524#endif
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:38
supports function callbacks
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
data structure to represent key events.
data structure to represent mouse events.
Abstract class for control points items.
void SetCurrentPoint(vtkIdType index)
Sets the current point selected.
virtual bool ClampPos(double pos[2], double bounds[4])
Clamp the given 2D pos into the bounds of the function.
virtual vtkIdType RemovePoint(double *pos)=0
Remove a point of the function.
virtual void DrawPoint(vtkContext2D *painter, vtkIdType index)
static void CallComputePoints(vtkObject *sender, unsigned long event, void *receiver, void *params)
virtual ~vtkControlPointsItem()
virtual void TransformScreenToData(const vtkVector2f &in, vtkVector2f &out)
Transform the mouse event in the control-points space.
bool ClampValidPos(double pos[2])
virtual bool Paint(vtkContext2D *painter)
Paint the points with a fixed size (cosmetic) which doesn't depend on the scene zoom factor.
void SpreadPoints(float factor, bool dontSpreadFirstAndLast=false)
Utility function to spread all the control points of a given factor If dontSpreadFirstAndLast is true...
bool IsEndPointPicked()
Return true if any of the end points is current point or part of the selection.
vtkCallbackCommand * Callback
virtual void ComputeBounds(double *bounds)
Compute the bounds for this item.
void DeselectPoint(double *currentPoint)
Utility function that unselects a point providing its coordinates.
virtual void GetControlPoint(vtkIdType index, double *point) const =0
Returns the x and y coordinates as well as the midpoint and sharpness of the control point correspond...
vtkIdType GetCurrentPoint() const
Returns the current point ID selected or -1 if there is no point current.
virtual void TransformDataToScreen(const vtkVector2f &in, vtkVector2f &out)
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key)
Key release event.
void AddPointId(vtkIdType addedPointId)
void ToggleSelectPoint(double *currentPoint)
Utility function that toggles the selection a point providing its coordinates.
void ToggleSelectPoint(vtkIdType pointId)
Toggle the selection of a point by its ID.
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
Select all points in the specified rectangle.
virtual void GetBounds(double bounds[4])
Bounds of the item, typically the bound of all the control points except if custom bounds have been s...
virtual void SetControlPoint(vtkIdType index, double *point)=0
Sets the x and y coordinates as well as the midpoint and sharpness of the control point corresponding...
void MovePoints(const vtkVector2f &translation, bool dontMoveFirstAndLast=false)
Utility function to move all the control points of the given translation If dontMoveFirstAndLast is t...
void StartInteractionIfNotStarted()
void ResetBounds()
Recompute the bounds next time they are requested.
bool IsPointRemovable(vtkIdType pointId)
Return true if the point is removable.
virtual void ComputePoints()
Must be reimplemented by subclasses to calculate the points to draw.
virtual bool GetEndPointsMovable()
vtkIdType RemovePoint(vtkIdType pointId)
Remove a point give its id.
vtkVector2f GetSelectionCenterOfMass() const
void MoveCurrentPoint(const vtkVector2f &translation)
void SpreadPoints(float factor, vtkIdTypeArray *pointIds)
Spread the points referred by pointIds If factor > 0, points are moved away from each other.
virtual vtkIdType AddPoint(double *newPos)=0
Add a point to the function.
vtkIdType FindPoint(double *pos)
Returns the vtkIdType of the point given its coordinates and a tolerance based on the screen point si...
void RemoveCurrentPoint()
Remove the current point.
void SelectPoint(double *currentPoint)
Utility function that selects a point providing its coordinates.
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse)
Mouse button down event.
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
vtkTransform2D * Transform
virtual void emitEvent(unsigned long event, void *params=0)=0
void Stroke(const vtkVector2f &newPos)
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
Mouse button release event.
virtual vtkMTimeType GetControlPointsMTime()=0
void SelectAllPoints()
Select all the points.
vtkIdType SetPointPos(vtkIdType point, const vtkVector2f &newPos)
void DrawUnselectedPoints(vtkContext2D *painter)
Internal function that paints a collection of points and optionally excludes some.
bool IsOverPoint(double *pos, vtkIdType pointId)
Returns true if pos is above the pointId point, false otherwise.
vtkIdType MovePoint(vtkIdType point, const vtkVector2f &translation)
void DeselectAllPoints()
Unselect all the previously selected points.
void DrawSelectedPoints(vtkContext2D *painter)
virtual vtkIdType GetNumberOfPoints() const =0
Returns the total number of points.
virtual bool Hit(const vtkContextMouseEvent &mouse)
Returns true if the supplied x, y coordinate is on a control point.
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
void SetCurrentPointPos(const vtkVector2f &newPos)
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
void SelectPoint(vtkIdType pointId)
Select a point by its ID.
virtual bool UsingLogScale()
Returns true if control points are to be rendered in log-space.
vtkIdType GetControlPointId(double *pos)
Returns the id of the control point exactly matching pos, -1 if not found.
void MovePoints(const vtkVector2f &translation, vtkIdTypeArray *pointIds)
Move the points referred by pointIds by a given translation.
int GetInteractionsCount() const
vtkIdType GetNumberOfSelectedPoints() const
Return the number of selected points.
virtual vtkStdString GetControlPointLabel(vtkIdType index)
Generate label for a control point.
void GetControlPointsIds(vtkIdTypeArray *ids, bool excludeFirstAndLast=false) const
Utility function that returns an array of all the control points IDs Typically: [0,...
void DeselectPoint(vtkIdType pointId)
Unselect a point by its ID.
virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY))
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:40
Abstract class for 2D plots.
Definition: vtkPlot.h:53
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition: vtkPlot.h:453
represent and manipulate 2D points
Definition: vtkPoints2D.h:37
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:49
describes linear transformations via a 3x3 matrix
@ point
Definition: vtkX3D.h:236
@ key
Definition: vtkX3D.h:257
@ translation
Definition: vtkX3D.h:232
@ index
Definition: vtkX3D.h:246
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
int vtkIdType
Definition: vtkType.h:287
vtkTypeUInt64 vtkMTimeType
Definition: vtkType.h:248
#define max(a, b)