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;
43 
44 class VTKCHARTSCORE_EXPORT vtkControlPointsItem: public vtkPlot
45 {
46 public:
47  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
48  void PrintSelf(ostream &os, vtkIndent indent) VTK_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  CurrentPointChangedEvent = vtkCommand::UserEvent,
58  CurrentPointEditEvent
59  };
60 
65  void GetBounds(double bounds[4]) VTK_OVERRIDE;
66 
68 
73  vtkSetVector4Macro(UserBounds, double);
74  vtkGetVector4Macro(UserBounds, double);
76 
78 
83  vtkSetVector4Macro(ValidBounds, double);
84  vtkGetVector4Macro(ValidBounds, double);
86 
88 
92  vtkGetMacro(ScreenPointRadius, float);
93  vtkSetMacro(ScreenPointRadius, float);
95 
101  bool Paint(vtkContext2D *painter) VTK_OVERRIDE;
102 
106  void SelectPoint(vtkIdType pointId);
107 
113  void SelectPoint(double* currentPoint);
114 
118  void SelectAllPoints();
119 
123  void DeselectPoint(vtkIdType pointId);
124 
130  void DeselectPoint(double* currentPoint);
131 
135  void DeselectAllPoints();
136 
141  void ToggleSelectPoint(vtkIdType pointId);
142 
148  void ToggleSelectPoint(double* currentPoint);
149 
153  bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) VTK_OVERRIDE;
154 
158  vtkIdType GetNumberOfSelectedPoints()const;
159 
164  vtkIdType FindPoint(double* pos);
165 
171  bool IsOverPoint(double* pos, vtkIdType pointId);
172 
176  vtkIdType GetControlPointId(double* pos);
177 
183  void GetControlPointsIds(vtkIdTypeArray* ids,
184  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 
351  void ResetBounds();
352 
354 
357  bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
358  bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
360 
364  bool MouseMoveEvent(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
365 
366  bool KeyPressEvent(const vtkContextKeyEvent &key) VTK_OVERRIDE;
367  bool KeyReleaseEvent(const vtkContextKeyEvent &key) VTK_OVERRIDE;
368 
369 protected:
371  ~vtkControlPointsItem() VTK_OVERRIDE;
372 
373  void StartChanges();
374  void EndChanges();
375  void StartInteraction();
376  void StartInteractionIfNotStarted();
377  void Interaction();
378  void EndInteraction();
379  int GetInteractionsCount()const;
380  virtual void emitEvent(unsigned long event, void* params = 0) = 0;
381 
382  static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params);
383 
385 
389  virtual void ComputePoints();
390  virtual vtkMTimeType GetControlPointsMTime() =0;
392 
396  bool Hit(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
397 
399 
403  virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
404  virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
406 
408 
412  virtual bool ClampPos(double pos[2], double bounds[4]);
413  bool ClampValidPos(double pos[2]);
415 
417 
421  void DrawUnselectedPoints(vtkContext2D* painter);
422  void DrawSelectedPoints(vtkContext2D* painter);
423  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
425 
426  void SetCurrentPointPos(const vtkVector2f& newPos);
427  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
428  void MoveCurrentPoint(const vtkVector2f& translation);
429  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
430 
431  inline vtkVector2f GetSelectionCenterOfMass()const;
432  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const;
433 
434  void Stroke(const vtkVector2f& newPos);
435  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
439  bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
440 
444  virtual vtkStdString GetControlPointLabel(vtkIdType index);
445 
446  void AddPointId(vtkIdType addedPointId);
447 
452  bool IsEndPointPicked();
453 
457  bool IsPointRemovable(vtkIdType pointId);
458 
465  virtual void ComputeBounds(double* bounds);
466 
472  virtual bool UsingLogScale() { return false; }
473 
481 
482  double Bounds[4];
483  double UserBounds[4];
484  double ValidBounds[4];
485 
488 
502  char* LabelFormat;
503 private:
504  vtkControlPointsItem(const vtkControlPointsItem &) VTK_DELETE_FUNCTION;
505  void operator=(const vtkControlPointsItem &) VTK_DELETE_FUNCTION;
506 
507  void ComputeBounds();
508 
509  vtkIdType RemovePointId(vtkIdType removedPointId);
510 };
511 
512 //-----------------------------------------------------------------------------
513 void vtkControlPointsItem::RemoveCurrentPoint()
514 {
515  this->RemovePoint(this->GetCurrentPoint());
516 }
517 
518 //-----------------------------------------------------------------------------
520 {
521  return this->GetCenterOfMass(this->Selection);
522 }
523 
524 #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
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
supports function callbacks
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
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 MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
#define max(a, b)
vtkCallbackCommand * Callback