VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
43 class VTKCHARTSCORE_EXPORT vtkControlPointsItem: public vtkPlot
44 {
45 public:
46  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
47  virtual void PrintSelf(ostream &os, vtkIndent indent);
48 
49  enum {
50  CurrentPointChangedEvent = vtkCommand::UserEvent,
51  CurrentPointEditEvent
52  };
53 
56  virtual void GetBounds(double bounds[4]);
57 
59 
62  vtkSetVector4Macro(UserBounds, double);
63  vtkGetVector4Macro(UserBounds, double);
65 
67 
70  vtkSetVector4Macro(ValidBounds, double);
71  vtkGetVector4Macro(ValidBounds, double);
73 
75 
76  vtkGetMacro(ScreenPointRadius, float);
77  vtkSetMacro(ScreenPointRadius, float);
79 
83  virtual bool Paint(vtkContext2D *painter);
84 
86  void SelectPoint(vtkIdType pointId);
87 
91  void SelectPoint(double* currentPoint);
92 
94  void SelectAllPoints();
95 
97  void DeselectPoint(vtkIdType pointId);
98 
102  void DeselectPoint(double* currentPoint);
103 
105  void DeselectAllPoints();
106 
109  void ToggleSelectPoint(vtkIdType pointId);
110 
114  void ToggleSelectPoint(double* currentPoint);
115 
117  virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
118 
120  vtkIdType GetNumberOfSelectedPoints()const;
121 
124  vtkIdType FindPoint(double* pos);
125 
129  bool IsOverPoint(double* pos, vtkIdType pointId);
130 
133  vtkIdType GetControlPointId(double* pos);
134 
136 
139  void GetControlPointsIds(vtkIdTypeArray* ids,
140  bool excludeFirstAndLast = false)const;
142 
144 
146  vtkGetMacro(StrokeMode, bool);
148 
150 
154  vtkSetMacro(SwitchPointsMode, bool);
155  vtkGetMacro(SwitchPointsMode, bool);
157 
159 
161  vtkSetMacro(EndPointsXMovable, bool);
162  vtkGetMacro(EndPointsXMovable, bool);
163  vtkSetMacro(EndPointsYMovable, bool);
164  vtkGetMacro(EndPointsYMovable, bool);
165  virtual bool GetEndPointsMovable();
167 
169 
171  vtkSetMacro(EndPointsRemovable, bool);
172  vtkGetMacro(EndPointsRemovable, bool);
174 
178  virtual vtkIdType AddPoint(double* newPos) = 0;
179 
183  virtual vtkIdType RemovePoint(double* pos) = 0;
184 
187  vtkIdType RemovePoint(vtkIdType pointId);
188 
190  inline void RemoveCurrentPoint();
191 
193  virtual vtkIdType GetNumberOfPoints()const = 0;
194 
198  virtual void GetControlPoint(vtkIdType index, double *point)const = 0;
199 
202  virtual void SetControlPoint(vtkIdType index, double *point) = 0;
203 
210  void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
211 
215  void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
216 
223  void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
224 
228  void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
229 
232  vtkIdType GetCurrentPoint()const;
233 
235  void SetCurrentPoint(vtkIdType index);
236 
238 
239  vtkGetObjectMacro(SelectedPointPen, vtkPen);
241 
243 
245  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
247 
250  void ResetBounds();
251 
253 
254  virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
255  virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse);
257 
259  virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
260 
261  virtual bool KeyPressEvent(const vtkContextKeyEvent &key);
262  virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key);
263 
264 protected:
266  virtual ~vtkControlPointsItem();
267 
268  void StartChanges();
269  void EndChanges();
270  void StartInteraction();
271  void StartInteractionIfNotStarted();
272  void Interaction();
273  void EndInteraction();
274  int GetInteractionsCount()const;
275  virtual void emitEvent(unsigned long event, void* params = 0) = 0;
276 
277  static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params);
278 
280 
282  virtual void ComputePoints();
283  virtual unsigned long int GetControlPointsMTime() =0;
285 
287  virtual bool Hit(const vtkContextMouseEvent &mouse);
288 
290 
292  bool ClampPos(double pos[2], double bounds[4]);
293  bool ClampValidPos(double pos[2]);
295 
297 
299  void DrawUnselectedPoints(vtkContext2D* painter);
300  void DrawSelectedPoints(vtkContext2D* painter);
301  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
303 
304  void SetCurrentPointPos(const vtkVector2f& newPos);
305  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
306  void MoveCurrentPoint(const vtkVector2f& translation);
307  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
308 
309  inline vtkVector2f GetSelectionCenterOfMass()const;
310  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const;
311 
312  void Stroke(const vtkVector2f& newPos);
313  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
315  virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
316 
317  void AddPointId(vtkIdType addedPointId);
318 
321  bool IsEndPointPicked();
322 
324  bool IsPointRemovable(vtkIdType pointId);
325 
332 
333  double Bounds[4];
334  double UserBounds[4];
335  double ValidBounds[4];
336 
337  vtkTransform2D* Transform;
339 
352 private:
353  vtkControlPointsItem(const vtkControlPointsItem &); // Not implemented.
354  void operator=(const vtkControlPointsItem &); // Not implemented.
355 
356  void ComputeBounds();
357  void ComputeBounds(double* bounds);
358 
359  vtkIdType RemovePointId(vtkIdType removedPointId);
360 };
361 
362 //-----------------------------------------------------------------------------
364 {
365  this->RemovePoint(this->GetCurrentPoint());
366 }
367 
368 //-----------------------------------------------------------------------------
370 {
371  return this->GetCenterOfMass(this->Selection);
372 }
373 
374 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkIdType GetCurrentPoint() const
vtkVector2f GetSelectionCenterOfMass() const
Abstract class for control points items.
virtual void GetBounds(double bounds[4])
Definition: vtkPlot.h:230
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:268
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
vtkIdTypeArray * Selection
Definition: vtkPlot.h:299
supports function callbacks
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
Abstract class for 2D plots.
Definition: vtkPlot.h:52
virtual vtkIdType RemovePoint(double *pos)=0
virtual void PrintSelf(ostream &os, vtkIndent indent)
vtkCallbackCommand * Callback