VTK  9.7.1
vtkControlPointsItem.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
19 #ifndef vtkControlPointsItem_h
20 #define vtkControlPointsItem_h
21 
22 #include "vtkPlot.h"
23 
24 #include "vtkChartsCoreModule.h" // For export macro
25 #include "vtkCommand.h" // For vtkCommand enum
26 #include "vtkSmartPointer.h" // For SmartPointer
27 #include "vtkVector.h" // For vtkVector2f
28 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
29 #include <string> // Used by GetControlPointLabel
30 
31 VTK_ABI_NAMESPACE_BEGIN
32 class vtkCallbackCommand;
33 class vtkContext2D;
34 class vtkControlPointsAddPointItem;
36 class vtkPoints2D;
37 class vtkTransform2D;
38 
39 class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkControlPointsItem : public vtkPlot
40 {
41 public:
42  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
43  void PrintSelf(ostream& os, vtkIndent indent) override;
44 
45  // Events fires by this class (and subclasses).
46  // \li CurrentPointChangedEvent is fired when the current point index is changed.
47  // \li CurrentPointEditEvent is fired to request the application to show UI to
48  // edit the current point.
49  // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
50  // to mark groups of changes to control points.
51  enum
52  {
53  CurrentPointChangedEvent = vtkCommand::UserEvent,
54  CurrentPointEditEvent
55  };
56 
61  void GetBounds(double bounds[4]) override;
62 
64 
69  vtkSetVector4Macro(UserBounds, double);
70  vtkGetVector4Macro(UserBounds, double);
72 
74 
79  vtkSetVector4Macro(ValidBounds, double);
80  vtkGetVector4Macro(ValidBounds, double);
82 
84 
88  vtkGetMacro(ScreenPointRadius, float);
89  vtkSetMacro(ScreenPointRadius, float);
91 
93 
97  vtkGetMacro(DrawPoints, bool);
98  vtkSetMacro(DrawPoints, bool);
99  vtkBooleanMacro(DrawPoints, bool);
101 
107  bool Paint(vtkContext2D* painter) override;
108 
112  void SelectPoint(vtkIdType pointId);
113 
119  void SelectPoint(double* currentPoint);
120 
124  void SelectAllPoints();
125 
129  void DeselectPoint(vtkIdType pointId);
130 
136  void DeselectPoint(double* currentPoint);
137 
141  void DeselectAllPoints();
142 
147  void ToggleSelectPoint(vtkIdType pointId);
148 
154  void ToggleSelectPoint(double* currentPoint);
155 
159  bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) override;
160 
164  vtkIdType GetNumberOfSelectedPoints() const;
165 
170  vtkIdType FindPoint(double* pos);
171 
177  bool IsOverPoint(double* pos, vtkIdType pointId);
178 
182  vtkIdType GetControlPointId(double* pos);
183 
189  void GetControlPointsIds(vtkIdTypeArray* ids, bool excludeFirstAndLast = false) const;
190 
192 
197  vtkSetMacro(StrokeMode, bool);
198  vtkGetMacro(StrokeMode, bool);
200 
202 
208  vtkSetMacro(SwitchPointsMode, bool);
209  vtkGetMacro(SwitchPointsMode, bool);
211 
213 
217  vtkSetMacro(EndPointsXMovable, bool);
218  vtkGetMacro(EndPointsXMovable, bool);
219  vtkSetMacro(EndPointsYMovable, bool);
220  vtkGetMacro(EndPointsYMovable, bool);
221  virtual bool GetEndPointsMovable();
223 
225 
229  vtkSetMacro(EndPointsRemovable, bool);
230  vtkGetMacro(EndPointsRemovable, bool);
232 
234 
238  vtkSetMacro(ShowLabels, bool);
239  vtkGetMacro(ShowLabels, bool);
241 
243 
247  vtkSetStringMacro(LabelFormat);
248  vtkGetStringMacro(LabelFormat);
250 
256  virtual vtkIdType AddPoint(double* newPos) = 0;
257 
263  virtual vtkIdType RemovePoint(double* pos) = 0;
264 
269  vtkIdType RemovePoint(vtkIdType pointId);
270 
274  void RemoveCurrentPoint();
275 
279  virtual vtkIdType GetNumberOfPoints() const = 0;
280 
286  virtual void GetControlPoint(vtkIdType index, double* point) const = 0;
287 
292  virtual void SetControlPoint(vtkIdType index, double* point) = 0;
293 
302  void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
303 
309  void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
310 
319  void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
320 
326  void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
327 
332  vtkIdType GetCurrentPoint() const;
333 
337  void SetCurrentPoint(vtkIdType index);
338 
340 
343  vtkGetObjectMacro(SelectedPointPen, vtkPen);
345 
347 
351  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
353 
355 
361  vtkGetMacro(UseAddPointItem, bool);
362  vtkSetMacro(UseAddPointItem, bool);
363  vtkBooleanMacro(UseAddPointItem, bool);
365 
370  vtkPlot* GetAddPointItem();
371 
376  void ResetBounds();
377 
379 
382  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
383  bool MouseDoubleClickEvent(const vtkContextMouseEvent& mouse) override;
384  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
385  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
386  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
387  bool KeyReleaseEvent(const vtkContextKeyEvent& key) override;
389 
390 protected:
392  ~vtkControlPointsItem() override;
393 
395 
396  void StartChanges();
397  void EndChanges();
398  void StartInteraction();
399  void StartInteractionIfNotStarted();
400  void Interaction();
401  void EndInteraction();
402  int GetInteractionsCount() const;
403  virtual void emitEvent(unsigned long event, void* params = nullptr) = 0;
404 
405  static void CallComputePoints(
406  vtkObject* sender, unsigned long event, void* receiver, void* params);
407 
409 
413  virtual void ComputePoints();
414  virtual vtkMTimeType GetControlPointsMTime() = 0;
416 
422  bool Hit(const vtkContextMouseEvent& mouse) override;
423 
425 
429  bool ClampValidDataPos(double pos[2]);
430  bool ClampValidScreenPos(double pos[2]);
432 
434 
438  void DrawUnselectedPoints(vtkContext2D* painter);
439  void DrawSelectedPoints(vtkContext2D* painter);
440  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
442 
443  void SetCurrentPointPos(const vtkVector2f& newPos);
444  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
445  void MoveCurrentPoint(const vtkVector2f& translation);
446  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
447 
448  vtkVector2f GetSelectionCenterOfMass() const;
449  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs) const;
450 
451  void Stroke(const vtkVector2f& newPos);
452  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
453 
457  virtual std::string GetControlPointLabel(vtkIdType index);
458 
459  void AddPointId(vtkIdType addedPointId);
460 
465  bool IsEndPointPicked();
466 
470  bool IsPointRemovable(vtkIdType pointId);
471 
478  virtual void ComputeBounds(double* bounds);
479 
483  int BlockUpdates = 0;
484  int StartedInteractions = 0;
485  int StartedChanges = 0;
486  vtkIdType CurrentPoint = -1;
487 
488  double Bounds[4] = { 0., -1., 0., -1. };
489  double UserBounds[4] = { 0., -1., 0., -1. };
490  double ValidBounds[4] = { 0., -1., 0., -1. };
491 
493  float ScreenPointRadius = 6.f;
494 
495  bool DrawPoints = true;
496  bool StrokeMode = false;
497  bool SwitchPointsMode = false;
498  bool MouseMoved = false;
499  bool EnforceValidFunction = true;
500  vtkIdType PointToDelete = -1;
501  bool PointAboutToBeDeleted = false;
502  vtkIdType PointToToggle = -1;
503  bool PointAboutToBeToggled = false;
504  bool InvertShadow = false;
505  bool EndPointsXMovable = true;
506  bool EndPointsYMovable = true;
507  bool EndPointsRemovable = true;
508  bool ShowLabels = false;
509  char* LabelFormat = nullptr;
510 
511 private:
513  void operator=(const vtkControlPointsItem&) = delete;
514 
515  void ComputeBounds();
516 
517  vtkIdType RemovePointId(vtkIdType removedPointId);
518 
519  bool UseAddPointItem = false;
521 };
522 VTK_ABI_NAMESPACE_END
523 #endif
vtkNew< vtkCallbackCommand > Callback
data structure to represent key events.
abstract base class for most VTK objects
Definition: vtkObject.h:52
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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...
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key)
Key release event.
Abstract class for control points items.
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition: vtkPlot.h:393
dynamic, self-adjusting array of vtkIdType
vtkNew< vtkBrush > SelectedPointBrush
vtkNew< vtkPen > SelectedPointPen
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the supplied x, y coordinate is inside the item.
int vtkIdType
Definition: vtkType.h:363
vtkNew< vtkTransform2D > ControlPointsTransform
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
supports function callbacks
a vtkContextItem that draws handles around a point of a piecewise function
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:30
data structure to represent mouse events.
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
Select all points in the specified rectangle.
a simple class to control print indentation
Definition: vtkIndent.h:28
represent and manipulate 2D points
Definition: vtkPoints2D.h:27
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
Mouse button release event.
const std::string pointIds
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:29
describes linear transformations via a 3x3 matrix
Abstract class for 2D plots.
Definition: vtkPlot.h:43
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
#define VTK_MARSHALAUTO
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
#define max(a, b)