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 
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,
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 
263  vtkIdType RemovePoint(vtkIdType pointId);
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 
296  void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
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 
326  vtkIdType GetCurrentPoint()const;
327 
331  void SetCurrentPoint(vtkIdType index);
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:
372  ~vtkControlPointsItem() override;
373 
375 
376  void StartChanges();
377  void EndChanges();
378  void StartInteraction();
379  void StartInteractionIfNotStarted();
380  void Interaction();
381  void EndInteraction();
382  int GetInteractionsCount()const;
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();
393  virtual vtkMTimeType GetControlPointsMTime() =0;
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);
409 
411 
415  virtual bool ClampPos(double pos[2], double bounds[4]);
416  bool ClampValidPos(double pos[2]);
418 
420 
424  void DrawUnselectedPoints(vtkContext2D* painter);
425  void DrawSelectedPoints(vtkContext2D* painter);
426  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
428 
429  void SetCurrentPointPos(const vtkVector2f& newPos);
430  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
431  void MoveCurrentPoint(const vtkVector2f& translation);
432  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
433 
434  inline vtkVector2f GetSelectionCenterOfMass()const;
435  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const;
436 
437  void Stroke(const vtkVector2f& newPos);
438  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
442  bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override;
443 
447  virtual vtkStdString GetControlPointLabel(vtkIdType index);
448 
449  void AddPointId(vtkIdType addedPointId);
450 
455  bool IsEndPointPicked();
456 
460  bool IsPointRemovable(vtkIdType pointId);
461 
468  virtual void ComputeBounds(double* bounds);
469 
477 
478  double Bounds[4];
479  double UserBounds[4];
480  double ValidBounds[4];
481 
484 
498  char* LabelFormat;
499 private:
500  vtkControlPointsItem(const vtkControlPointsItem &) = delete;
501  void operator=(const vtkControlPointsItem &) = delete;
502 
503  void ComputeBounds();
504 
505  vtkIdType RemovePointId(vtkIdType removedPointId);
506 };
507 
508 //-----------------------------------------------------------------------------
510 {
511  this->RemovePoint(this->GetCurrentPoint());
512 }
513 
514 //-----------------------------------------------------------------------------
516 {
517  return this->GetCenterOfMass(this->Selection);
518 }
519 
520 #endif
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
data structure to represent key events.
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:300
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.
vtkVector2f GetSelectionCenterOfMass() const
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:336
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:345
void RemoveCurrentPoint()
Remove the current point.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
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.
vtkTransform2D * Transform
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.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
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:52
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
#define max(a, b)
vtkCallbackCommand * Callback