VTK  9.2.6
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 "vtkPlot.h"
35 
36 #include "vtkChartsCoreModule.h" // For export macro
37 #include "vtkCommand.h" // For vtkCommand enum
38 #include "vtkSmartPointer.h" // For SmartPointer
39 #include "vtkVector.h" // For vtkVector2f
40 #include <string> // Used by GetControlPointLabel
41 
42 class vtkCallbackCommand;
43 class vtkContext2D;
44 class vtkControlPointsAddPointItem;
46 class vtkPoints2D;
47 class vtkTransform2D;
48 
49 class VTKCHARTSCORE_EXPORT vtkControlPointsItem : public vtkPlot
50 {
51 public:
52  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
55  // Events fires by this class (and subclasses).
56  // \li CurrentPointChangedEvent is fired when the current point index is changed.
57  // \li CurrentPointEditEvent is fired to request the application to show UI to
58  // edit the current point.
59  // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
60  // to mark groups of changes to control points.
61  enum
62  {
63  CurrentPointChangedEvent = vtkCommand::UserEvent,
64  CurrentPointEditEvent
65  };
66 
71  void GetBounds(double bounds[4]) override;
72 
74 
79  vtkSetVector4Macro(UserBounds, double);
80  vtkGetVector4Macro(UserBounds, double);
82 
84 
89  vtkSetVector4Macro(ValidBounds, double);
90  vtkGetVector4Macro(ValidBounds, double);
92 
94 
98  vtkGetMacro(ScreenPointRadius, float);
99  vtkSetMacro(ScreenPointRadius, float);
101 
103 
107  vtkGetMacro(DrawPoints, bool);
108  vtkSetMacro(DrawPoints, bool);
109  vtkBooleanMacro(DrawPoints, bool);
111 
117  bool Paint(vtkContext2D* painter) override;
118 
122  void SelectPoint(vtkIdType pointId);
123 
129  void SelectPoint(double* currentPoint);
130 
134  void SelectAllPoints();
135 
139  void DeselectPoint(vtkIdType pointId);
140 
146  void DeselectPoint(double* currentPoint);
147 
151  void DeselectAllPoints();
152 
157  void ToggleSelectPoint(vtkIdType pointId);
158 
164  void ToggleSelectPoint(double* currentPoint);
165 
169  bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) override;
170 
174  vtkIdType GetNumberOfSelectedPoints() const;
175 
180  vtkIdType FindPoint(double* pos);
181 
187  bool IsOverPoint(double* pos, vtkIdType pointId);
188 
192  vtkIdType GetControlPointId(double* pos);
193 
199  void GetControlPointsIds(vtkIdTypeArray* ids, bool excludeFirstAndLast = false) const;
200 
202 
207  vtkSetMacro(StrokeMode, bool);
208  vtkGetMacro(StrokeMode, bool);
210 
212 
218  vtkSetMacro(SwitchPointsMode, bool);
219  vtkGetMacro(SwitchPointsMode, bool);
221 
223 
227  vtkSetMacro(EndPointsXMovable, bool);
228  vtkGetMacro(EndPointsXMovable, bool);
229  vtkSetMacro(EndPointsYMovable, bool);
230  vtkGetMacro(EndPointsYMovable, bool);
231  virtual bool GetEndPointsMovable();
233 
235 
239  vtkSetMacro(EndPointsRemovable, bool);
240  vtkGetMacro(EndPointsRemovable, bool);
242 
244 
248  vtkSetMacro(ShowLabels, bool);
249  vtkGetMacro(ShowLabels, bool);
251 
253 
256  vtkSetStringMacro(LabelFormat);
257  vtkGetStringMacro(LabelFormat);
259 
265  virtual vtkIdType AddPoint(double* newPos) = 0;
266 
272  virtual vtkIdType RemovePoint(double* pos) = 0;
273 
278  vtkIdType RemovePoint(vtkIdType pointId);
279 
283  void RemoveCurrentPoint();
284 
288  virtual vtkIdType GetNumberOfPoints() const = 0;
289 
295  virtual void GetControlPoint(vtkIdType index, double* point) const = 0;
296 
301  virtual void SetControlPoint(vtkIdType index, double* point) = 0;
302 
311  void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
312 
318  void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
319 
328  void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
329 
335  void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
336 
341  vtkIdType GetCurrentPoint() const;
342 
346  void SetCurrentPoint(vtkIdType index);
347 
349 
352  vtkGetObjectMacro(SelectedPointPen, vtkPen);
354 
356 
360  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
362 
364 
370  vtkGetMacro(UseAddPointItem, bool);
371  vtkSetMacro(UseAddPointItem, bool);
372  vtkBooleanMacro(UseAddPointItem, bool);
374 
379  vtkPlot* GetAddPointItem();
380 
385  void ResetBounds();
386 
388 
391  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
392  bool MouseDoubleClickEvent(const vtkContextMouseEvent& mouse) override;
393  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
394  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
395  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
396  bool KeyReleaseEvent(const vtkContextKeyEvent& key) override;
398 
399 protected:
401  ~vtkControlPointsItem() override;
402 
404 
405  void StartChanges();
406  void EndChanges();
407  void StartInteraction();
408  void StartInteractionIfNotStarted();
409  void Interaction();
410  void EndInteraction();
411  int GetInteractionsCount() const;
412  virtual void emitEvent(unsigned long event, void* params = nullptr) = 0;
413 
414  static void CallComputePoints(
415  vtkObject* sender, unsigned long event, void* receiver, void* params);
416 
418 
422  virtual void ComputePoints();
423  virtual vtkMTimeType GetControlPointsMTime() = 0;
425 
431  bool Hit(const vtkContextMouseEvent& mouse) override;
432 
434 
438  bool ClampValidDataPos(double pos[2]);
439  bool ClampValidScreenPos(double pos[2]);
441 
443 
447  void DrawUnselectedPoints(vtkContext2D* painter);
448  void DrawSelectedPoints(vtkContext2D* painter);
449  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
451 
452  void SetCurrentPointPos(const vtkVector2f& newPos);
453  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
454  void MoveCurrentPoint(const vtkVector2f& translation);
455  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
456 
457  vtkVector2f GetSelectionCenterOfMass() const;
458  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs) const;
459 
460  void Stroke(const vtkVector2f& newPos);
461  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
462 
466  virtual std::string GetControlPointLabel(vtkIdType index);
467 
468  void AddPointId(vtkIdType addedPointId);
469 
474  bool IsEndPointPicked();
475 
479  bool IsPointRemovable(vtkIdType pointId);
480 
487  virtual void ComputeBounds(double* bounds);
488 
492  int BlockUpdates = 0;
493  int StartedInteractions = 0;
494  int StartedChanges = 0;
495  vtkIdType CurrentPoint = -1;
496 
497  double Bounds[4] = { 0., -1., 0., -1. };
498  double UserBounds[4] = { 0., -1., 0., -1. };
499  double ValidBounds[4] = { 0., -1., 0., -1. };
500 
502  float ScreenPointRadius = 6.f;
503 
504  bool DrawPoints = true;
505  bool StrokeMode = false;
506  bool SwitchPointsMode = false;
507  bool MouseMoved = false;
508  bool EnforceValidFunction = true;
509  vtkIdType PointToDelete = -1;
510  bool PointAboutToBeDeleted = false;
511  vtkIdType PointToToggle = -1;
512  bool PointAboutToBeToggled = false;
513  bool InvertShadow = false;
514  bool EndPointsXMovable = true;
515  bool EndPointsYMovable = true;
516  bool EndPointsRemovable = true;
517  bool ShowLabels = false;
518  char* LabelFormat = nullptr;
519 
520 private:
522  void operator=(const vtkControlPointsItem&) = delete;
523 
524  void ComputeBounds();
525 
526  vtkIdType RemovePointId(vtkIdType removedPointId);
527 
528  bool UseAddPointItem = false;
530 };
531 #endif
vtkNew< vtkCallbackCommand > Callback
data structure to represent key events.
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
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:352
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:332
vtkNew< vtkTransform2D > ControlPointsTransform
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:57
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:40
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:39
represent and manipulate 2D points
Definition: vtkPoints2D.h:36
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:39
describes linear transformations via a 3x3 matrix
Abstract class for 2D plots.
Definition: vtkPlot.h:53
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)