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 
30 #ifndef vtkControlPointsItem_h
31 #define vtkControlPointsItem_h
32 
33 #include "vtkChartsCoreModule.h" // For export macro
34 #include "vtkCommand.h" // For vtkCommand enum
35 #include "vtkPlot.h"
36 #include "vtkVector.h" // For vtkVector2f
37 
38 class vtkCallbackCommand;
39 class vtkContext2D;
40 class vtkPoints2D;
41 class vtkTransform2D;
42 
44 {
45 public:
46  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
47  virtual void PrintSelf(ostream &os, vtkIndent indent);
48 
49  // Events fires by this class (and subclasses).
50  // \li CurrentPointChangedEvent is fired when the current point index is changed.
51  // \li CurrentPointEditEvent is fired to request the application to show UI to
52  // edit the current point.
53  // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
54  // to mark groups of changes to control points.
55  enum {
56  CurrentPointChangedEvent = vtkCommand::UserEvent,
58  };
59 
62  virtual void GetBounds(double bounds[4]);
63 
65 
68  vtkSetVector4Macro(UserBounds, double);
69  vtkGetVector4Macro(UserBounds, double);
71 
73 
76  vtkSetVector4Macro(ValidBounds, double);
77  vtkGetVector4Macro(ValidBounds, double);
79 
81 
82  vtkGetMacro(ScreenPointRadius, float);
83  vtkSetMacro(ScreenPointRadius, float);
85 
89  virtual bool Paint(vtkContext2D *painter);
90 
92  void SelectPoint(vtkIdType pointId);
93 
97  void SelectPoint(double* currentPoint);
98 
100  void SelectAllPoints();
101 
103  void DeselectPoint(vtkIdType pointId);
104 
108  void DeselectPoint(double* currentPoint);
109 
111  void DeselectAllPoints();
112 
115  void ToggleSelectPoint(vtkIdType pointId);
116 
120  void ToggleSelectPoint(double* currentPoint);
121 
123  virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
124 
126  vtkIdType GetNumberOfSelectedPoints()const;
127 
130  vtkIdType FindPoint(double* pos);
131 
135  bool IsOverPoint(double* pos, vtkIdType pointId);
136 
139  vtkIdType GetControlPointId(double* pos);
140 
142 
145  void GetControlPointsIds(vtkIdTypeArray* ids,
146  bool excludeFirstAndLast = false)const;
148 
150 
152  vtkGetMacro(StrokeMode, bool);
154 
156 
160  vtkSetMacro(SwitchPointsMode, bool);
161  vtkGetMacro(SwitchPointsMode, bool);
163 
165 
167  vtkSetMacro(EndPointsXMovable, bool);
168  vtkGetMacro(EndPointsXMovable, bool);
169  vtkSetMacro(EndPointsYMovable, bool);
170  vtkGetMacro(EndPointsYMovable, bool);
171  virtual bool GetEndPointsMovable();
173 
175 
177  vtkSetMacro(EndPointsRemovable, bool);
178  vtkGetMacro(EndPointsRemovable, bool);
180 
182 
184  vtkSetMacro(ShowLabels, bool);
185  vtkGetMacro(ShowLabels, bool);
187 
189 
190  vtkSetStringMacro(LabelFormat);
191  vtkGetStringMacro(LabelFormat);
193 
197  virtual vtkIdType AddPoint(double* newPos) = 0;
198 
202  virtual vtkIdType RemovePoint(double* pos) = 0;
203 
206  vtkIdType RemovePoint(vtkIdType pointId);
207 
209  inline void RemoveCurrentPoint();
210 
212  virtual vtkIdType GetNumberOfPoints()const = 0;
213 
217  virtual void GetControlPoint(vtkIdType index, double *point)const = 0;
218 
221  virtual void SetControlPoint(vtkIdType index, double *point) = 0;
222 
229  void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
230 
234  void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
235 
242  void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
243 
247  void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
248 
251  vtkIdType GetCurrentPoint()const;
252 
254  void SetCurrentPoint(vtkIdType index);
255 
257 
258  vtkGetObjectMacro(SelectedPointPen, vtkPen);
260 
262 
264  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
266 
269  void ResetBounds();
270 
272 
273  virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
274  virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse);
276 
278  virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
279 
280  virtual bool KeyPressEvent(const vtkContextKeyEvent &key);
281  virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key);
282 
283 protected:
285  virtual ~vtkControlPointsItem();
286 
287  void StartChanges();
288  void EndChanges();
289  void StartInteraction();
290  void StartInteractionIfNotStarted();
291  void Interaction();
292  void EndInteraction();
293  int GetInteractionsCount()const;
294  virtual void emitEvent(unsigned long event, void* params = 0) = 0;
295 
296  static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params);
297 
299 
301  virtual void ComputePoints();
302  virtual unsigned long int GetControlPointsMTime() =0;
304 
306  virtual bool Hit(const vtkContextMouseEvent &mouse);
307 
309 
311  virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
312  virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
314 
316 
318  virtual bool ClampPos(double pos[2], double bounds[4]);
319  bool ClampValidPos(double pos[2]);
321 
323 
325  void DrawUnselectedPoints(vtkContext2D* painter);
326  void DrawSelectedPoints(vtkContext2D* painter);
327  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
329 
330  void SetCurrentPointPos(const vtkVector2f& newPos);
331  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
332  void MoveCurrentPoint(const vtkVector2f& translation);
333  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
334 
335  inline vtkVector2f GetSelectionCenterOfMass()const;
336  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const;
337 
338  void Stroke(const vtkVector2f& newPos);
339  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
341  virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
342 
344  virtual vtkStdString GetControlPointLabel(vtkIdType index);
345 
346  void AddPointId(vtkIdType addedPointId);
347 
350  bool IsEndPointPicked();
351 
353  bool IsPointRemovable(vtkIdType pointId);
354 
360  virtual void ComputeBounds(double* bounds);
361 
365  virtual bool UsingLogScale() { return false; }
366 
374 
375  double Bounds[4];
376  double UserBounds[4];
377  double ValidBounds[4];
378 
381 
395  char* LabelFormat;
396 private:
397  vtkControlPointsItem(const vtkControlPointsItem &); // Not implemented.
398  void operator=(const vtkControlPointsItem &); // Not implemented.
399 
400  void ComputeBounds();
401 
402  vtkIdType RemovePointId(vtkIdType removedPointId);
403 };
404 
405 //-----------------------------------------------------------------------------
407 {
408  this->RemovePoint(this->GetCurrentPoint());
409 }
410 
411 //-----------------------------------------------------------------------------
413 {
414  return this->GetCenterOfMass(this->Selection);
415 }
416 
417 #endif
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
data structure to represent key events.
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkIdType GetCurrentPoint() const
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse)
virtual bool Paint(vtkContext2D *painter)
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key)
vtkVector2f GetSelectionCenterOfMass() const
Abstract class for control points items.
virtual void GetBounds(double bounds[4])
Definition: vtkPlot.h:276
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
vtkIdTypeArray * Selection
Definition: vtkPlot.h:362
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:56
supports function callbacks
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:36
data structure to represent mouse events.
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
vtkTransform2D * Transform
a simple class to control print indentation
Definition: vtkIndent.h:38
represent and manipulate 2D points
Definition: vtkPoints2D.h:35
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:38
describes linear transformations via a 3x3 matrix
Abstract class for 2D plots.
Definition: vtkPlot.h:51
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
virtual vtkIdType RemovePoint(double *pos)=0
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
virtual bool Hit(const vtkContextMouseEvent &mouse)
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
#define max(a, b)
vtkCallbackCommand * Callback
#define VTKCHARTSCORE_EXPORT