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 
39 class vtkCallbackCommand;
40 class vtkContext2D;
41 class vtkPoints2D;
42 class vtkTransform2D;
44 
45 class VTKCHARTSCORE_EXPORT vtkControlPointsItem: public vtkPlot
46 {
47 public:
48  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
49  void PrintSelf(ostream &os, vtkIndent indent) override;
50 
51  // Events fires by this class (and subclasses).
52  // \li CurrentPointChangedEvent is fired when the current point index is changed.
53  // \li CurrentPointEditEvent is fired to request the application to show UI to
54  // edit the current point.
55  // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
56  // to mark groups of changes to control points.
57  enum {
58  CurrentPointChangedEvent = vtkCommand::UserEvent,
59  CurrentPointEditEvent
60  };
61 
66  void GetBounds(double bounds[4]) override;
67 
69 
74  vtkSetVector4Macro(UserBounds, double);
75  vtkGetVector4Macro(UserBounds, double);
77 
79 
84  vtkSetVector4Macro(ValidBounds, double);
85  vtkGetVector4Macro(ValidBounds, double);
87 
89 
93  vtkGetMacro(ScreenPointRadius, float);
94  vtkSetMacro(ScreenPointRadius, float);
96 
102  bool Paint(vtkContext2D *painter) override;
103 
107  void SelectPoint(vtkIdType pointId);
108 
114  void SelectPoint(double* currentPoint);
115 
120 
124  void DeselectPoint(vtkIdType pointId);
125 
131  void DeselectPoint(double* currentPoint);
132 
137 
143 
149  void ToggleSelectPoint(double* currentPoint);
150 
154  bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) override;
155 
160 
165  vtkIdType FindPoint(double* pos);
166 
172  bool IsOverPoint(double* pos, vtkIdType pointId);
173 
178 
185  bool excludeFirstAndLast = false)const;
186 
188 
193  vtkGetMacro(StrokeMode, bool);
195 
197 
203  vtkSetMacro(SwitchPointsMode, bool);
204  vtkGetMacro(SwitchPointsMode, bool);
206 
208 
212  vtkSetMacro(EndPointsXMovable, bool);
213  vtkGetMacro(EndPointsXMovable, bool);
214  vtkSetMacro(EndPointsYMovable, bool);
215  vtkGetMacro(EndPointsYMovable, bool);
216  virtual bool GetEndPointsMovable();
218 
220 
224  vtkSetMacro(EndPointsRemovable, bool);
225  vtkGetMacro(EndPointsRemovable, bool);
227 
229 
233  vtkSetMacro(ShowLabels, bool);
234  vtkGetMacro(ShowLabels, bool);
236 
238 
241  vtkSetStringMacro(LabelFormat);
242  vtkGetStringMacro(LabelFormat);
244 
250  virtual vtkIdType AddPoint(double* newPos) = 0;
251 
257  virtual vtkIdType RemovePoint(double* pos) = 0;
258 
264 
268  inline void RemoveCurrentPoint();
269 
273  virtual vtkIdType GetNumberOfPoints()const = 0;
274 
280  virtual void GetControlPoint(vtkIdType index, double *point)const = 0;
281 
286  virtual void SetControlPoint(vtkIdType index, double *point) = 0;
287 
297 
303  void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
304 
313  void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
314 
320  void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
321 
327 
332 
334 
337  vtkGetObjectMacro(SelectedPointPen, vtkPen);
339 
341 
345  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
347 
352  void ResetBounds();
353 
355 
358  bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override;
359  bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse) override;
361 
365  bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override;
366 
367  bool KeyPressEvent(const vtkContextKeyEvent &key) override;
368  bool KeyReleaseEvent(const vtkContextKeyEvent &key) override;
369 
370 protected:
373 
375 
376  void StartChanges();
377  void EndChanges();
380  void Interaction();
383  virtual void emitEvent(unsigned long event, void* params = nullptr) = 0;
384 
385  static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params);
386 
388 
392  virtual void ComputePoints();
395 
399  bool Hit(const vtkContextMouseEvent &mouse) override;
400 
402 
406  virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
407  virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
408  virtual void TransformScreenToData(const double inX, const double inY,
409  double &outX, double &outY);
410  virtual void TransformDataToScreen(const double inX, const double inY,
411  double &outX, double &outY);
413 
415 
419  virtual bool ClampPos(double pos[2], double bounds[4]);
420  bool ClampValidDataPos(double pos[2]);
421  bool ClampValidScreenPos(double pos[2]);
423 
425 
431  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
433 
434  void SetCurrentPointPos(const vtkVector2f& newPos);
438 
439  inline vtkVector2f GetSelectionCenterOfMass()const;
441 
442  void Stroke(const vtkVector2f& newPos);
443  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
447  bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override;
448 
453 
454  void AddPointId(vtkIdType addedPointId);
455 
461 
466 
473  virtual void ComputeBounds(double* bounds);
474 
482 
483  double Bounds[4];
484  double UserBounds[4];
485  double ValidBounds[4];
486 
489 
503  char* LabelFormat;
504 private:
505  vtkControlPointsItem(const vtkControlPointsItem &) = delete;
506  void operator=(const vtkControlPointsItem &) = delete;
507 
508  void ComputeBounds();
509 
510  vtkIdType RemovePointId(vtkIdType removedPointId);
511 };
512 
513 //-----------------------------------------------------------------------------
515 {
516  this->RemovePoint(this->GetCurrentPoint());
517 }
518 
519 //-----------------------------------------------------------------------------
521 {
522  return this->GetCenterOfMass(this->Selection);
523 }
524 
525 #endif
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:41
vtkPoints2D
represent and manipulate 2D points
Definition: vtkPoints2D.h:37
vtkControlPointsItem::EnforceValidFunction
bool EnforceValidFunction
Definition: vtkControlPointsItem.h:493
vtkControlPointsItem::IsEndPointPicked
bool IsEndPointPicked()
Return true if any of the end points is current point or part of the selection.
vtkControlPointsItem::SelectedPointBrush
vtkBrush * SelectedPointBrush
Definition: vtkControlPointsItem.h:477
vtkControlPointsItem::LabelFormat
char * LabelFormat
Definition: vtkControlPointsItem.h:503
vtkControlPointsItem::MouseButtonPressEvent
bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override
Mouse button down event.
vtkControlPointsItem::IsPointRemovable
bool IsPointRemovable(vtkIdType pointId)
Return true if the point is removable.
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:41
vtkControlPointsItem::EndInteraction
void EndInteraction()
vtkCommand::UserEvent
@ UserEvent
Definition: vtkCommand.h:448
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::PointAboutToBeToggled
bool PointAboutToBeToggled
Definition: vtkControlPointsItem.h:497
vtkControlPointsItem::GetNumberOfPoints
virtual vtkIdType GetNumberOfPoints() const =0
Returns the total number of points.
vtkControlPointsItem::RemovePoint
vtkIdType RemovePoint(vtkIdType pointId)
Remove a point give its id.
vtkPlot.h
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkControlPointsItem::ComputePoints
virtual void ComputePoints()
Must be reimplemented by subclasses to calculate the points to draw.
vtkControlPointsItem::DrawSelectedPoints
void DrawSelectedPoints(vtkContext2D *painter)
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:52
vtkControlPointsItem::MouseDoubleClickEvent
bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse) override
Mouse button double click event.
vtkControlPointsItem::EndChanges
void EndChanges()
vtkControlPointsItem::MoveCurrentPoint
void MoveCurrentPoint(const vtkVector2f &translation)
vtkX3D::key
@ key
Definition: vtkX3D.h:257
vtkControlPointsItem::EndPointsRemovable
bool EndPointsRemovable
Definition: vtkControlPointsItem.h:501
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::InvertShadow
bool InvertShadow
Definition: vtkControlPointsItem.h:498
vtkControlPointsItem::DeselectPoint
void DeselectPoint(double *currentPoint)
Utility function that unselects a point providing its coordinates.
vtkControlPointsItem::PointAboutToBeDeleted
bool PointAboutToBeDeleted
Definition: vtkControlPointsItem.h:495
vtkControlPointsItem::DrawPoint
virtual void DrawPoint(vtkContext2D *painter, vtkIdType index)
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
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::CurrentPoint
vtkIdType CurrentPoint
Definition: vtkControlPointsItem.h:481
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:59
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()
vtkPlot
Abstract class for 2D plots.
Definition: vtkPlot.h:53
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::StartedInteractions
int StartedInteractions
Definition: vtkControlPointsItem.h:479
vtkControlPointsItem::GetControlPointLabel
virtual vtkStdString GetControlPointLabel(vtkIdType index)
Generate label for a control point.
vtkControlPointsItem::StartChanges
void StartChanges()
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
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:46
vtkControlPointsItem::DeselectPoint
void DeselectPoint(vtkIdType pointId)
Unselect a point by its ID.
vtkControlPointsItem::ShowLabels
bool ShowLabels
Definition: vtkControlPointsItem.h:502
vtkControlPointsItem::emitEvent
virtual void emitEvent(unsigned long event, void *params=nullptr)=0
vtkControlPointsItem::GetSelectionCenterOfMass
vtkVector2f GetSelectionCenterOfMass() const
Definition: vtkControlPointsItem.h:520
vtkX3D::point
@ point
Definition: vtkX3D.h:236
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::EndPointsXMovable
bool EndPointsXMovable
Definition: vtkControlPointsItem.h:499
vtkControlPointsItem::MouseMoved
bool MouseMoved
Definition: vtkControlPointsItem.h:492
vtkControlPointsItem::RemovePoint
virtual vtkIdType RemovePoint(double *pos)=0
Remove a point of the function.
vtkControlPointsItem::KeyPressEvent
bool KeyPressEvent(const vtkContextKeyEvent &key) override
Key press event.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkControlPointsItem::SwitchPointsMode
bool SwitchPointsMode
Definition: vtkControlPointsItem.h:491
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::StrokeMode
bool StrokeMode
Definition: vtkControlPointsItem.h:490
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...
vtkControlPointsItem::TransformScreenToData
virtual void TransformScreenToData(const double inX, const double inY, double &outX, double &outY)
vtkControlPointsItem::ToggleSelectPoint
void ToggleSelectPoint(vtkIdType pointId)
Toggle the selection of a point by its ID.
vtkControlPointsItem::TransformDataToScreen
virtual void TransformDataToScreen(const vtkVector2f &in, vtkVector2f &out)
vtkControlPointsItem::SetCurrentPoint
void SetCurrentPoint(vtkIdType index)
Sets the current point selected.
vtkControlPointsItem::Transform
vtkTransform2D * Transform
Definition: vtkControlPointsItem.h:487
vtkControlPointsItem::AddPointId
void AddPointId(vtkIdType addedPointId)
vtkControlPointsItem::TransformDataToScreen
virtual void TransformDataToScreen(const double inX, const double inY, double &outX, double &outY)
vtkPlot::Selection
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition: vtkPlot.h:453
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::ClampPos
virtual bool ClampPos(double pos[2], double bounds[4])
Clamp the given 2D pos into the bounds of the function.
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.
vtkControlPointsItem::EndPointsYMovable
bool EndPointsYMovable
Definition: vtkControlPointsItem.h:500
vtkControlPointsItem::KeyReleaseEvent
bool KeyReleaseEvent(const vtkContextKeyEvent &key) override
Key release event.
vtkControlPointsItem::BlockUpdates
int BlockUpdates
Definition: vtkControlPointsItem.h:478
vtkControlPointsItem::DeselectAllPoints
void DeselectAllPoints()
Unselect all the previously selected points.
vtkControlPointsItem::ScreenPointRadius
float ScreenPointRadius
Definition: vtkControlPointsItem.h:488
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:42
vtkControlPointsItem::MouseButtonReleaseEvent
bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override
Mouse button release event.
vtkControlPointsItem::SelectedPointPen
vtkPen * SelectedPointPen
Definition: vtkControlPointsItem.h:476
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:51
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.
Definition: vtkControlPointsItem.h:514
vtkControlPointsItem::Stroke
void Stroke(const vtkVector2f &newPos)
vtkControlPointsItem::MouseMoveEvent
bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override
Mouse move event.
vtkControlPointsItem::StartInteraction
void StartInteraction()
vtkControlPointsItem::TransformScreenToData
virtual void TransformScreenToData(const vtkVector2f &in, vtkVector2f &out)
Transform the mouse event in the control-points space.
vtkControlPointsItem::GetInteractionsCount
int GetInteractionsCount() const
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:40
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:41
vtkControlPointsItem::StartedChanges
int StartedChanges
Definition: vtkControlPointsItem.h:480
vtkControlPointsItem::PointToToggle
vtkIdType PointToToggle
Definition: vtkControlPointsItem.h:496
vtkX3D::translation
@ translation
Definition: vtkX3D.h:232
vtkControlPointsItem::Interaction
void Interaction()
vtkControlPointsItem::PointToDelete
vtkIdType PointToDelete
Definition: vtkControlPointsItem.h:494
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 coordinate is on a control point.
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkControlPointsItem::ClampValidDataPos
bool ClampValidDataPos(double pos[2])
vtkControlPointsItem::ClampValidScreenPos
bool ClampValidScreenPos(double pos[2])
vtkVector2f
Definition: vtkVector.h:419
vtkControlPointsItem::Callback
vtkCallbackCommand * Callback
Definition: vtkControlPointsItem.h:475
vtkControlPointsItem::GetControlPointsMTime
virtual vtkMTimeType GetControlPointsMTime()=0
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:302
vtkControlPointsItem::IsOverPoint
bool IsOverPoint(double *pos, vtkIdType pointId)
Returns true if pos is above the pointId point, false otherwise.