VTK  9.0.1
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 "vtkChartsCoreModule.h" // For export macro
32 #include "vtkCommand.h" // For vtkCommand enum
33 #include "vtkPlot.h"
34 #include "vtkSmartPointer.h" // for SmartPointer
35 #include "vtkVector.h" // For vtkVector2f
36 
37 class vtkCallbackCommand;
38 class vtkContext2D;
39 class vtkControlPointsAddPointItem;
41 class vtkPoints2D;
42 class vtkTransform2D;
43 
44 class VTKCHARTSCORE_EXPORT vtkControlPointsItem : public vtkPlot
45 {
46 public:
47  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
48  void PrintSelf(ostream& os, vtkIndent indent) override;
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  {
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 
119  void SelectAllPoints();
120 
124  void DeselectPoint(vtkIdType pointId);
125 
131  void DeselectPoint(double* currentPoint);
132 
136  void DeselectAllPoints();
137 
142  void ToggleSelectPoint(vtkIdType pointId);
143 
149  void ToggleSelectPoint(double* currentPoint);
150 
154  bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) override;
155 
159  vtkIdType GetNumberOfSelectedPoints() const;
160 
165  vtkIdType FindPoint(double* pos);
166 
172  bool IsOverPoint(double* pos, vtkIdType pointId);
173 
177  vtkIdType GetControlPointId(double* pos);
178 
184  void GetControlPointsIds(vtkIdTypeArray* ids, 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 
262  vtkIdType RemovePoint(vtkIdType pointId);
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 
295  void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
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 
325  vtkIdType GetCurrentPoint() const;
326 
330  void SetCurrentPoint(vtkIdType index);
331 
333 
336  vtkGetObjectMacro(SelectedPointPen, vtkPen);
338 
340 
344  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
346 
348 
354  vtkGetMacro(UseAddPointItem, bool);
355  vtkSetMacro(UseAddPointItem, bool);
356  vtkBooleanMacro(UseAddPointItem, bool);
358 
363  vtkPlot* GetAddPointItem();
364 
369  void ResetBounds();
370 
372 
375  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
376  bool MouseDoubleClickEvent(const vtkContextMouseEvent& mouse) override;
377  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
378  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
379  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
380  bool KeyReleaseEvent(const vtkContextKeyEvent& key) override;
382 
383 protected:
385  ~vtkControlPointsItem() override;
386 
388 
389  void StartChanges();
390  void EndChanges();
391  void StartInteraction();
392  void StartInteractionIfNotStarted();
393  void Interaction();
394  void EndInteraction();
395  int GetInteractionsCount() const;
396  virtual void emitEvent(unsigned long event, void* params = nullptr) = 0;
397 
398  static void CallComputePoints(
399  vtkObject* sender, unsigned long event, void* receiver, void* params);
400 
402 
406  virtual void ComputePoints();
407  virtual vtkMTimeType GetControlPointsMTime() = 0;
409 
415  bool Hit(const vtkContextMouseEvent& mouse) override;
416 
418 
422  bool ClampValidDataPos(double pos[2]);
423  bool ClampValidScreenPos(double pos[2]);
425 
427 
431  void DrawUnselectedPoints(vtkContext2D* painter);
432  void DrawSelectedPoints(vtkContext2D* painter);
433  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
435 
436  void SetCurrentPointPos(const vtkVector2f& newPos);
437  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
438  void MoveCurrentPoint(const vtkVector2f& translation);
439  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
440 
441  inline vtkVector2f GetSelectionCenterOfMass() const;
442  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs) const;
443 
444  void Stroke(const vtkVector2f& newPos);
445  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
446 
450  virtual vtkStdString GetControlPointLabel(vtkIdType index);
451 
452  void AddPointId(vtkIdType addedPointId);
453 
458  bool IsEndPointPicked();
459 
463  bool IsPointRemovable(vtkIdType pointId);
464 
471  virtual void ComputeBounds(double* bounds);
472 
480 
481  double Bounds[4];
482  double UserBounds[4];
483  double ValidBounds[4];
484 
487 
501  char* LabelFormat;
502 
503 private:
505  void operator=(const vtkControlPointsItem&) = delete;
506 
507  void ComputeBounds();
508 
509  vtkIdType RemovePointId(vtkIdType removedPointId);
510 
511  bool UseAddPointItem = false;
513 };
514 
515 //-----------------------------------------------------------------------------
517 {
518  this->RemovePoint(this->GetCurrentPoint());
519 }
520 
521 //-----------------------------------------------------------------------------
523 {
524  return this->GetCenterOfMass(this->Selection);
525 }
526 
527 #endif
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:37
vtkPoints2D
represent and manipulate 2D points
Definition: vtkPoints2D.h:33
vtkControlPointsItem::EnforceValidFunction
bool EnforceValidFunction
Definition: vtkControlPointsItem.h:491
vtkControlPointsItem::SelectedPointBrush
vtkBrush * SelectedPointBrush
Definition: vtkControlPointsItem.h:475
vtkControlPointsItem::LabelFormat
char * LabelFormat
Definition: vtkControlPointsItem.h:501
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:34
vtkCommand::UserEvent
@ UserEvent
Definition: vtkCommand.h:454
vtkContextKeyEvent
data structure to represent key events.
Definition: vtkContextKeyEvent.h:34
vtkControlPointsItem::PointAboutToBeToggled
bool PointAboutToBeToggled
Definition: vtkControlPointsItem.h:495
vtkPlot.h
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:45
vtkX3D::key
@ key
Definition: vtkX3D.h:263
vtkControlPointsItem::EndPointsRemovable
bool EndPointsRemovable
Definition: vtkControlPointsItem.h:499
vtkControlPointsItem::InvertShadow
bool InvertShadow
Definition: vtkControlPointsItem.h:496
vtkAbstractContextItem::KeyPressEvent
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
vtkControlPointsItem::PointAboutToBeDeleted
bool PointAboutToBeDeleted
Definition: vtkControlPointsItem.h:493
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkVector.h
vtkControlPointsItem::CurrentPoint
vtkIdType CurrentPoint
Definition: vtkControlPointsItem.h:479
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
vtkCommand.h
vtkPlot
Abstract class for 2D plots.
Definition: vtkPlot.h:46
vtkPiecewisePointHandleItem
a vtkContextItem that draws handles around a point of a piecewise function
Definition: vtkPiecewisePointHandleItem.h:39
vtkControlPointsItem::StartedInteractions
int StartedInteractions
Definition: vtkControlPointsItem.h:477
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkControlPointsItem
Abstract class for control points items.
Definition: vtkControlPointsItem.h:44
vtkControlPointsItem::ShowLabels
bool ShowLabels
Definition: vtkControlPointsItem.h:500
vtkControlPointsItem::GetSelectionCenterOfMass
vtkVector2f GetSelectionCenterOfMass() const
Definition: vtkControlPointsItem.h:522
vtkX3D::point
@ point
Definition: vtkX3D.h:242
vtkPlot::SelectPoints
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
Select all points in the specified rectangle.
vtkControlPointsItem::EndPointsXMovable
bool EndPointsXMovable
Definition: vtkControlPointsItem.h:497
vtkControlPointsItem::MouseMoved
bool MouseMoved
Definition: vtkControlPointsItem.h:490
vtkControlPointsItem::RemovePoint
virtual vtkIdType RemovePoint(double *pos)=0
Remove a point of the function.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkControlPointsItem::SwitchPointsMode
bool SwitchPointsMode
Definition: vtkControlPointsItem.h:489
vtkAbstractContextItem::Hit
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
vtkControlPointsItem::StrokeMode
bool StrokeMode
Definition: vtkControlPointsItem.h:488
vtkSmartPointer.h
vtkNew< vtkControlPointsAddPointItem >
vtkControlPointsItem::Transform
vtkTransform2D * Transform
Definition: vtkControlPointsItem.h:485
vtkAbstractContextItem::MouseMoveEvent
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
vtkPlot::Selection
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition: vtkPlot.h:481
vtkAbstractContextItem::MouseButtonReleaseEvent
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
Mouse button release event.
vtkControlPointsItem::GetCenterOfMass
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
vtkControlPointsItem::EndPointsYMovable
bool EndPointsYMovable
Definition: vtkControlPointsItem.h:498
vtkControlPointsItem::BlockUpdates
int BlockUpdates
Definition: vtkControlPointsItem.h:476
vtkControlPointsItem::ScreenPointRadius
float ScreenPointRadius
Definition: vtkControlPointsItem.h:486
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:35
vtkAbstractContextItem::Paint
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
vtkControlPointsItem::SelectedPointPen
vtkPen * SelectedPointPen
Definition: vtkControlPointsItem.h:474
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:44
vtkAbstractContextItem::MouseDoubleClickEvent
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
vtkAbstractContextItem::KeyReleaseEvent
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key)
Key release event.
vtkControlPointsItem::RemoveCurrentPoint
void RemoveCurrentPoint()
Remove the current point.
Definition: vtkControlPointsItem.h:516
vtkAbstractContextItem::MouseButtonPressEvent
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse)
Mouse button down event Return true if the item holds the event, false if the event can be propagated...
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:36
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkControlPointsItem::StartedChanges
int StartedChanges
Definition: vtkControlPointsItem.h:478
vtkControlPointsItem::PointToToggle
vtkIdType PointToToggle
Definition: vtkControlPointsItem.h:494
vtkX3D::translation
@ translation
Definition: vtkX3D.h:238
vtkPlot::GetBounds
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition: vtkPlot.h:343
vtkControlPointsItem::PointToDelete
vtkIdType PointToDelete
Definition: vtkControlPointsItem.h:492
vtkX3D::index
@ index
Definition: vtkX3D.h:252
vtkPlot::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkVector2f
Definition: vtkVector.h:432
vtkControlPointsItem::Callback
vtkCallbackCommand * Callback
Definition: vtkControlPointsItem.h:473
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293