VTK  9.3.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 <string> // Used by GetControlPointLabel
29 
30 VTK_ABI_NAMESPACE_BEGIN
31 class vtkCallbackCommand;
32 class vtkContext2D;
33 class vtkControlPointsAddPointItem;
35 class vtkPoints2D;
36 class vtkTransform2D;
37 
38 class VTKCHARTSCORE_EXPORT vtkControlPointsItem : public vtkPlot
39 {
40 public:
41  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
44  // Events fires by this class (and subclasses).
45  // \li CurrentPointChangedEvent is fired when the current point index is changed.
46  // \li CurrentPointEditEvent is fired to request the application to show UI to
47  // edit the current point.
48  // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
49  // to mark groups of changes to control points.
50  enum
51  {
52  CurrentPointChangedEvent = vtkCommand::UserEvent,
53  CurrentPointEditEvent
54  };
55 
60  void GetBounds(double bounds[4]) override;
61 
63 
68  vtkSetVector4Macro(UserBounds, double);
69  vtkGetVector4Macro(UserBounds, double);
71 
73 
78  vtkSetVector4Macro(ValidBounds, double);
79  vtkGetVector4Macro(ValidBounds, double);
81 
83 
87  vtkGetMacro(ScreenPointRadius, float);
88  vtkSetMacro(ScreenPointRadius, float);
90 
92 
96  vtkGetMacro(DrawPoints, bool);
97  vtkSetMacro(DrawPoints, bool);
98  vtkBooleanMacro(DrawPoints, bool);
100 
106  bool Paint(vtkContext2D* painter) override;
107 
111  void SelectPoint(vtkIdType pointId);
112 
118  void SelectPoint(double* currentPoint);
119 
123  void SelectAllPoints();
124 
128  void DeselectPoint(vtkIdType pointId);
129 
135  void DeselectPoint(double* currentPoint);
136 
140  void DeselectAllPoints();
141 
146  void ToggleSelectPoint(vtkIdType pointId);
147 
153  void ToggleSelectPoint(double* currentPoint);
154 
158  bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) override;
159 
163  vtkIdType GetNumberOfSelectedPoints() const;
164 
169  vtkIdType FindPoint(double* pos);
170 
176  bool IsOverPoint(double* pos, vtkIdType pointId);
177 
181  vtkIdType GetControlPointId(double* pos);
182 
188  void GetControlPointsIds(vtkIdTypeArray* ids, bool excludeFirstAndLast = false) const;
189 
191 
196  vtkSetMacro(StrokeMode, bool);
197  vtkGetMacro(StrokeMode, bool);
199 
201 
207  vtkSetMacro(SwitchPointsMode, bool);
208  vtkGetMacro(SwitchPointsMode, bool);
210 
212 
216  vtkSetMacro(EndPointsXMovable, bool);
217  vtkGetMacro(EndPointsXMovable, bool);
218  vtkSetMacro(EndPointsYMovable, bool);
219  vtkGetMacro(EndPointsYMovable, bool);
220  virtual bool GetEndPointsMovable();
222 
224 
228  vtkSetMacro(EndPointsRemovable, bool);
229  vtkGetMacro(EndPointsRemovable, bool);
231 
233 
237  vtkSetMacro(ShowLabels, bool);
238  vtkGetMacro(ShowLabels, bool);
240 
242 
245  vtkSetStringMacro(LabelFormat);
246  vtkGetStringMacro(LabelFormat);
248 
254  virtual vtkIdType AddPoint(double* newPos) = 0;
255 
261  virtual vtkIdType RemovePoint(double* pos) = 0;
262 
267  vtkIdType RemovePoint(vtkIdType pointId);
268 
272  void RemoveCurrentPoint();
273 
277  virtual vtkIdType GetNumberOfPoints() const = 0;
278 
284  virtual void GetControlPoint(vtkIdType index, double* point) const = 0;
285 
290  virtual void SetControlPoint(vtkIdType index, double* point) = 0;
291 
300  void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
301 
307  void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
308 
317  void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
318 
324  void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
325 
330  vtkIdType GetCurrentPoint() const;
331 
335  void SetCurrentPoint(vtkIdType index);
336 
338 
341  vtkGetObjectMacro(SelectedPointPen, vtkPen);
343 
345 
349  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
351 
353 
359  vtkGetMacro(UseAddPointItem, bool);
360  vtkSetMacro(UseAddPointItem, bool);
361  vtkBooleanMacro(UseAddPointItem, bool);
363 
368  vtkPlot* GetAddPointItem();
369 
374  void ResetBounds();
375 
377 
380  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
381  bool MouseDoubleClickEvent(const vtkContextMouseEvent& mouse) override;
382  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
383  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
384  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
385  bool KeyReleaseEvent(const vtkContextKeyEvent& key) override;
387 
388 protected:
390  ~vtkControlPointsItem() override;
391 
393 
394  void StartChanges();
395  void EndChanges();
396  void StartInteraction();
397  void StartInteractionIfNotStarted();
398  void Interaction();
399  void EndInteraction();
400  int GetInteractionsCount() const;
401  virtual void emitEvent(unsigned long event, void* params = nullptr) = 0;
402 
403  static void CallComputePoints(
404  vtkObject* sender, unsigned long event, void* receiver, void* params);
405 
407 
411  virtual void ComputePoints();
412  virtual vtkMTimeType GetControlPointsMTime() = 0;
414 
420  bool Hit(const vtkContextMouseEvent& mouse) override;
421 
423 
427  bool ClampValidDataPos(double pos[2]);
428  bool ClampValidScreenPos(double pos[2]);
430 
432 
436  void DrawUnselectedPoints(vtkContext2D* painter);
437  void DrawSelectedPoints(vtkContext2D* painter);
438  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
440 
441  void SetCurrentPointPos(const vtkVector2f& newPos);
442  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
443  void MoveCurrentPoint(const vtkVector2f& translation);
444  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
445 
446  vtkVector2f GetSelectionCenterOfMass() const;
447  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs) const;
448 
449  void Stroke(const vtkVector2f& newPos);
450  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
451 
455  virtual std::string GetControlPointLabel(vtkIdType index);
456 
457  void AddPointId(vtkIdType addedPointId);
458 
463  bool IsEndPointPicked();
464 
468  bool IsPointRemovable(vtkIdType pointId);
469 
476  virtual void ComputeBounds(double* bounds);
477 
481  int BlockUpdates = 0;
482  int StartedInteractions = 0;
483  int StartedChanges = 0;
484  vtkIdType CurrentPoint = -1;
485 
486  double Bounds[4] = { 0., -1., 0., -1. };
487  double UserBounds[4] = { 0., -1., 0., -1. };
488  double ValidBounds[4] = { 0., -1., 0., -1. };
489 
491  float ScreenPointRadius = 6.f;
492 
493  bool DrawPoints = true;
494  bool StrokeMode = false;
495  bool SwitchPointsMode = false;
496  bool MouseMoved = false;
497  bool EnforceValidFunction = true;
498  vtkIdType PointToDelete = -1;
499  bool PointAboutToBeDeleted = false;
500  vtkIdType PointToToggle = -1;
501  bool PointAboutToBeToggled = false;
502  bool InvertShadow = false;
503  bool EndPointsXMovable = true;
504  bool EndPointsYMovable = true;
505  bool EndPointsRemovable = true;
506  bool ShowLabels = false;
507  char* LabelFormat = nullptr;
508 
509 private:
511  void operator=(const vtkControlPointsItem&) = delete;
512 
513  void ComputeBounds();
514 
515  vtkIdType RemovePointId(vtkIdType removedPointId);
516 
517  bool UseAddPointItem = false;
519 };
520 VTK_ABI_NAMESPACE_END
521 #endif
vtkNew< vtkCallbackCommand > Callback
data structure to represent key events.
abstract base class for most VTK objects
Definition: vtkObject.h:51
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
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:367
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:315
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:29
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:25
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
Mouse button release event.
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:28
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.
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
#define max(a, b)