VTK  9.1.0
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 
28 #ifndef vtkControlPointsItem_h
29 #define vtkControlPointsItem_h
30 
31 #include "vtkPlot.h"
32 
33 #include "vtkChartsCoreModule.h" // For export macro
34 #include "vtkCommand.h" // For vtkCommand enum
35 #include "vtkSmartPointer.h" // For SmartPointer
36 #include "vtkVector.h" // For vtkVector2f
37 #include <string> // Used by GetControlPointLabel
38 
39 class vtkCallbackCommand;
40 class vtkContext2D;
41 class vtkControlPointsAddPointItem;
43 class vtkPoints2D;
44 class vtkTransform2D;
45 
46 class VTKCHARTSCORE_EXPORT vtkControlPointsItem : public vtkPlot
47 {
48 public:
49  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
52  // Events fires by this class (and subclasses).
53  // \li CurrentPointChangedEvent is fired when the current point index is changed.
54  // \li CurrentPointEditEvent is fired to request the application to show UI to
55  // edit the current point.
56  // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
57  // to mark groups of changes to control points.
58  enum
59  {
60  CurrentPointChangedEvent = vtkCommand::UserEvent,
61  CurrentPointEditEvent
62  };
63 
68  void GetBounds(double bounds[4]) override;
69 
71 
76  vtkSetVector4Macro(UserBounds, double);
77  vtkGetVector4Macro(UserBounds, double);
79 
81 
86  vtkSetVector4Macro(ValidBounds, double);
87  vtkGetVector4Macro(ValidBounds, double);
89 
91 
95  vtkGetMacro(ScreenPointRadius, float);
96  vtkSetMacro(ScreenPointRadius, float);
98 
100 
104  vtkGetMacro(DrawPoints, bool);
105  vtkSetMacro(DrawPoints, bool);
106  vtkBooleanMacro(DrawPoints, bool);
108 
114  bool Paint(vtkContext2D* painter) override;
115 
119  void SelectPoint(vtkIdType pointId);
120 
126  void SelectPoint(double* currentPoint);
127 
132 
136  void DeselectPoint(vtkIdType pointId);
137 
143  void DeselectPoint(double* currentPoint);
144 
149 
155 
161  void ToggleSelectPoint(double* currentPoint);
162 
166  bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) override;
167 
172 
177  vtkIdType FindPoint(double* pos);
178 
184  bool IsOverPoint(double* pos, vtkIdType pointId);
185 
190 
196  void GetControlPointsIds(vtkIdTypeArray* ids, bool excludeFirstAndLast = false) const;
197 
199 
204  vtkSetMacro(StrokeMode, bool);
205  vtkGetMacro(StrokeMode, bool);
207 
209 
215  vtkSetMacro(SwitchPointsMode, bool);
216  vtkGetMacro(SwitchPointsMode, bool);
218 
220 
224  vtkSetMacro(EndPointsXMovable, bool);
225  vtkGetMacro(EndPointsXMovable, bool);
226  vtkSetMacro(EndPointsYMovable, bool);
227  vtkGetMacro(EndPointsYMovable, bool);
228  virtual bool GetEndPointsMovable();
230 
232 
236  vtkSetMacro(EndPointsRemovable, bool);
237  vtkGetMacro(EndPointsRemovable, bool);
239 
241 
245  vtkSetMacro(ShowLabels, bool);
246  vtkGetMacro(ShowLabels, bool);
248 
250 
253  vtkSetStringMacro(LabelFormat);
254  vtkGetStringMacro(LabelFormat);
256 
262  virtual vtkIdType AddPoint(double* newPos) = 0;
263 
269  virtual vtkIdType RemovePoint(double* pos) = 0;
270 
275  vtkIdType RemovePoint(vtkIdType pointId);
276 
281 
285  virtual vtkIdType GetNumberOfPoints() const = 0;
286 
292  virtual void GetControlPoint(vtkIdType index, double* point) const = 0;
293 
298  virtual void SetControlPoint(vtkIdType index, double* point) = 0;
299 
309 
315  void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
316 
325  void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
326 
332  void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
333 
339 
344 
346 
349  vtkGetObjectMacro(SelectedPointPen, vtkPen);
351 
353 
357  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
359 
361 
367  vtkGetMacro(UseAddPointItem, bool);
368  vtkSetMacro(UseAddPointItem, bool);
369  vtkBooleanMacro(UseAddPointItem, bool);
371 
377 
382  void ResetBounds();
383 
385 
388  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
389  bool MouseDoubleClickEvent(const vtkContextMouseEvent& mouse) override;
390  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
391  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
392  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
393  bool KeyReleaseEvent(const vtkContextKeyEvent& key) override;
395 
396 protected:
399 
401 
402  void StartChanges();
403  void EndChanges();
406  void Interaction();
408  int GetInteractionsCount() const;
409  virtual void emitEvent(unsigned long event, void* params = nullptr) = 0;
410 
411  static void CallComputePoints(
412  vtkObject* sender, unsigned long event, void* receiver, void* params);
413 
415 
419  virtual void ComputePoints();
422 
428  bool Hit(const vtkContextMouseEvent& mouse) override;
429 
431 
435  bool ClampValidDataPos(double pos[2]);
436  bool ClampValidScreenPos(double pos[2]);
438 
440 
446  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
448 
449  void SetCurrentPointPos(const vtkVector2f& newPos);
453 
456 
457  void Stroke(const vtkVector2f& newPos);
458  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
459 
464 
465  void AddPointId(vtkIdType addedPointId);
466 
472 
477 
484  virtual void ComputeBounds(double* bounds);
485 
489  int BlockUpdates = 0;
490  int StartedInteractions = 0;
491  int StartedChanges = 0;
492  vtkIdType CurrentPoint = -1;
493 
494  double Bounds[4] = { 0., -1., 0., -1. };
495  double UserBounds[4] = { 0., -1., 0., -1. };
496  double ValidBounds[4] = { 0., -1., 0., -1. };
497 
499  float ScreenPointRadius = 6.f;
500 
501  bool DrawPoints = true;
502  bool StrokeMode = false;
503  bool SwitchPointsMode = false;
504  bool MouseMoved = false;
505  bool EnforceValidFunction = true;
506  vtkIdType PointToDelete = -1;
507  bool PointAboutToBeDeleted = false;
508  vtkIdType PointToToggle = -1;
509  bool PointAboutToBeToggled = false;
510  bool InvertShadow = false;
511  bool EndPointsXMovable = true;
512  bool EndPointsYMovable = true;
513  bool EndPointsRemovable = true;
514  bool ShowLabels = false;
515  char* LabelFormat = nullptr;
516 
517 private:
519  void operator=(const vtkControlPointsItem&) = delete;
520 
521  void ComputeBounds();
522 
523  vtkIdType RemovePointId(vtkIdType removedPointId);
524 
525  bool UseAddPointItem = false;
527 };
528 #endif
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:97
vtkPoints2D
represent and manipulate 2D points
Definition: vtkPoints2D.h:34
vtkControlPointsItem::IsEndPointPicked
bool IsEndPointPicked()
Return true if any of the end points is current point or part of the selection.
vtkControlPointsItem::MouseButtonPressEvent
bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override
Mouse and key events.
vtkControlPointsItem::IsPointRemovable
bool IsPointRemovable(vtkIdType pointId)
Return true if the point is removable.
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:54
vtkControlPointsItem::EndInteraction
void EndInteraction()
vtkCommand::UserEvent
@ UserEvent
Definition: vtkCommand.h:461
vtkContextKeyEvent
data structure to represent key events.
Definition: vtkContextKeyEvent.h:35
vtkControlPointsItem::SetPointPos
vtkIdType SetPointPos(vtkIdType point, const vtkVector2f &newPos)
vtkControlPointsItem::SelectAllPoints
void SelectAllPoints()
Select all the points.
vtkControlPointsItem::GetNumberOfSelectedPoints
vtkIdType GetNumberOfSelectedPoints() const
Return the number of selected points.
vtkControlPointsItem::GetControlPoint
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...
vtkControlPointsItem::GetNumberOfPoints
virtual vtkIdType GetNumberOfPoints() const =0
Returns the total number of points.
vtkPlot.h
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkControlPointsItem::ComputePoints
virtual void ComputePoints()
Must be reimplemented by subclasses to calculate the points to draw.
vtkControlPointsItem::DrawSelectedPoints
void DrawSelectedPoints(vtkContext2D *painter)
Internal function that paints a collection of points and optionally excludes some.
vtkControlPointsItem::SelectedPointPen
vtkNew< vtkPen > SelectedPointPen
Definition: vtkControlPointsItem.h:487
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:46
vtkControlPointsItem::MouseDoubleClickEvent
bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse) override
Mouse and key events.
vtkControlPointsItem::EndChanges
void EndChanges()
vtkControlPointsItem::MoveCurrentPoint
void MoveCurrentPoint(const vtkVector2f &translation)
vtkX3D::key
@ key
Definition: vtkX3D.h:263
vtkControlPointsItem::SetControlPoint
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...
vtkControlPointsItem::DeselectPoint
void DeselectPoint(double *currentPoint)
Utility function that unselects a point providing its coordinates.
vtkControlPointsItem::DrawPoint
virtual void DrawPoint(vtkContext2D *painter, vtkIdType index)
Internal function that paints a collection of points and optionally excludes some.
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:82
vtkControlPointsItem::StartInteractionIfNotStarted
void StartInteractionIfNotStarted()
vtkVector.h
vtkControlPointsItem::SpreadPoints
void SpreadPoints(float factor, bool dontSpreadFirstAndLast=false)
Utility function to spread all the control points of a given factor If dontSpreadFirstAndLast is true...
vtkControlPointsItem::vtkControlPointsItem
vtkControlPointsItem()
vtkControlPointsItem::MovePoints
void MovePoints(const vtkVector2f &translation, vtkIdTypeArray *pointIds)
Move the points referred by pointIds by a given translation.
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:73
vtkControlPointsItem::SetCurrentPointPos
void SetCurrentPointPos(const vtkVector2f &newPos)
vtkControlPointsItem::AddPoint
virtual vtkIdType AddPoint(double *newPos)=0
Add a point to the function.
vtkCommand.h
vtkControlPointsItem::GetEndPointsMovable
virtual bool GetEndPointsMovable()
If EndPointsMovable is false, the two end points will not be moved.
vtkPlot
Abstract class for 2D plots.
Definition: vtkPlot.h:157
vtkPiecewisePointHandleItem
a vtkContextItem that draws handles around a point of a piecewise function
Definition: vtkPiecewisePointHandleItem.h:40
vtkControlPointsItem::GetControlPointId
vtkIdType GetControlPointId(double *pos)
Returns the id of the control point exactly matching pos, -1 if not found.
vtkControlPointsItem::SelectPoints
bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max) override
Select all points in the specified rectangle.
vtkControlPointsItem::~vtkControlPointsItem
~vtkControlPointsItem() override
vtkControlPointsItem::StartChanges
void StartChanges()
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkControlPointsItem::GetControlPointLabel
virtual std::string GetControlPointLabel(vtkIdType index)
Generate label for a control point.
vtkControlPointsItem::ToggleSelectPoint
void ToggleSelectPoint(double *currentPoint)
Utility function that toggles the selection a point providing its coordinates.
vtkControlPointsItem::DrawUnselectedPoints
void DrawUnselectedPoints(vtkContext2D *painter)
Internal function that paints a collection of points and optionally excludes some.
vtkControlPointsItem::Paint
bool Paint(vtkContext2D *painter) override
Paint the points with a fixed size (cosmetic) which doesn't depend on the scene zoom factor.
vtkControlPointsItem
Abstract class for control points items.
Definition: vtkControlPointsItem.h:47
vtkControlPointsItem::DeselectPoint
void DeselectPoint(vtkIdType pointId)
Unselect a point by its ID.
vtkControlPointsItem::SelectedPointBrush
vtkNew< vtkBrush > SelectedPointBrush
Definition: vtkControlPointsItem.h:488
vtkControlPointsItem::emitEvent
virtual void emitEvent(unsigned long event, void *params=nullptr)=0
vtkControlPointsItem::GetSelectionCenterOfMass
vtkVector2f GetSelectionCenterOfMass() const
vtkX3D::point
@ point
Definition: vtkX3D.h:242
vtkControlPointsItem::ComputeBounds
virtual void ComputeBounds(double *bounds)
Compute the bounds for this item.
vtkControlPointsItem::EditPoint
virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY))
vtkControlPointsItem::KeyPressEvent
bool KeyPressEvent(const vtkContextKeyEvent &key) override
Mouse and key events.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkControlPointsItem::MovePoints
void MovePoints(const vtkVector2f &translation, bool dontMoveFirstAndLast=false)
Utility function to move all the control points of the given translation If dontMoveFirstAndLast is t...
vtkControlPointsItem::MovePoint
vtkIdType MovePoint(vtkIdType point, const vtkVector2f &translation)
vtkControlPointsItem::GetBounds
void GetBounds(double bounds[4]) override
Bounds of the item, typically the bound of all the control points except if custom bounds have been s...
vtkSmartPointer.h
vtkControlPointsItem::ToggleSelectPoint
void ToggleSelectPoint(vtkIdType pointId)
Toggle the selection of a point by its ID.
vtkNew< vtkCallbackCommand >
vtkControlPointsItem::SetCurrentPoint
void SetCurrentPoint(vtkIdType index)
Sets the current point selected.
vtkControlPointsItem::Callback
vtkNew< vtkCallbackCommand > Callback
Definition: vtkControlPointsItem.h:486
vtkControlPointsItem::ControlPointsTransform
vtkNew< vtkTransform2D > ControlPointsTransform
Definition: vtkControlPointsItem.h:498
vtkControlPointsItem::AddPointId
void AddPointId(vtkIdType addedPointId)
vtkControlPointsItem::SelectPoint
void SelectPoint(vtkIdType pointId)
Select a point by its ID.
vtkControlPointsItem::SpreadPoints
void SpreadPoints(float factor, vtkIdTypeArray *pointIds)
Spread the points referred by pointIds If factor > 0, points are moved away from each other.
vtkControlPointsItem::GetCenterOfMass
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
vtkControlPointsItem::CallComputePoints
static void CallComputePoints(vtkObject *sender, unsigned long event, void *receiver, void *params)
vtkControlPointsItem::SelectPoint
void SelectPoint(double *currentPoint)
Utility function that selects a point providing its coordinates.
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkControlPointsItem::KeyReleaseEvent
bool KeyReleaseEvent(const vtkContextKeyEvent &key) override
Mouse and key events.
vtkControlPointsItem::DeselectAllPoints
void DeselectAllPoints()
Unselect all the previously selected points.
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:145
vtkControlPointsItem::MouseButtonReleaseEvent
bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override
Mouse and key events.
vtkControlPointsItem::GetCurrentPoint
vtkIdType GetCurrentPoint() const
Returns the current point ID selected or -1 if there is no point current.
vtkCallbackCommand
supports function callbacks
Definition: vtkCallbackCommand.h:154
vtkControlPointsItem::FindPoint
vtkIdType FindPoint(double *pos)
Returns the vtkIdType of the point given its coordinates and a tolerance based on the screen point si...
vtkControlPointsItem::RemoveCurrentPoint
void RemoveCurrentPoint()
Remove the current point.
vtkControlPointsItem::Stroke
void Stroke(const vtkVector2f &newPos)
vtkControlPointsItem::MouseMoveEvent
bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override
Mouse and key events.
vtkControlPointsItem::StartInteraction
void StartInteraction()
vtkControlPointsItem::GetInteractionsCount
int GetInteractionsCount() const
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:136
vtkControlPointsItem::GetAddPointItem
vtkPlot * GetAddPointItem()
Item dedicated to add point, to be added below all other items.
vtkX3D::translation
@ translation
Definition: vtkX3D.h:238
vtkControlPointsItem::Interaction
void Interaction()
vtkControlPointsItem::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkControlPointsItem::Hit
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the supplied x, y are within the bounds or on a control point.
vtkX3D::index
@ index
Definition: vtkX3D.h:252
vtkControlPointsItem::ClampValidDataPos
bool ClampValidDataPos(double pos[2])
Clamp the given 2D pos into the bounds of the function.
vtkControlPointsItem::ClampValidScreenPos
bool ClampValidScreenPos(double pos[2])
Clamp the given 2D pos into the bounds of the function.
vtkVector2f
Definition: vtkVector.h:491
vtkControlPointsItem::GetControlPointsMTime
virtual vtkMTimeType GetControlPointsMTime()=0
Must be reimplemented by subclasses to calculate the points to draw.
vtkControlPointsItem::GetControlPointsIds
void GetControlPointsIds(vtkIdTypeArray *ids, bool excludeFirstAndLast=false) const
Utility function that returns an array of all the control points IDs Typically: [0,...
vtkControlPointsItem::ResetBounds
void ResetBounds()
Recompute the bounds next time they are requested.
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
vtkControlPointsItem::IsOverPoint
bool IsOverPoint(double *pos, vtkIdType pointId)
Returns true if pos is above the pointId point, false otherwise.