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 "vtkCommand.h" // For vtkCommand enum
34 #include "vtkPlot.h"
35 #include "vtkVector.h" // For vtkVector2f
36 
37 class vtkCallbackCommand;
38 class vtkContext2D;
39 class vtkPoints2D;
40 class vtkTransform2D;
41 
43 {
44 public:
45  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
46  virtual void PrintSelf(ostream &os, vtkIndent indent);
47 
48  enum {
49  CurrentPointChangedEvent = vtkCommand::UserEvent,
50  CurrentPointEditEvent
51  };
52 
55  virtual void GetBounds(double bounds[4]);
56 
58 
61  vtkSetVector4Macro(UserBounds, double);
62  vtkGetVector4Macro(UserBounds, double);
64 
66 
69  vtkSetVector4Macro(ValidBounds, double);
70  vtkGetVector4Macro(ValidBounds, double);
72 
74 
75  vtkGetMacro(ScreenPointRadius, float);
76  vtkSetMacro(ScreenPointRadius, float);
78 
82  virtual bool Paint(vtkContext2D *painter);
83 
85  void SelectPoint(vtkIdType pointId);
86 
90  void SelectPoint(double* currentPoint);
91 
93  void SelectAllPoints();
94 
96  void DeselectPoint(vtkIdType pointId);
97 
101  void DeselectPoint(double* currentPoint);
102 
104  void DeselectAllPoints();
105 
108  void ToggleSelectPoint(vtkIdType pointId);
109 
113  void ToggleSelectPoint(double* currentPoint);
114 
116  virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
117 
119  vtkIdType GetNumberOfSelectedPoints()const;
120 
123  vtkIdType FindPoint(double* pos);
124 
128  bool IsOverPoint(double* pos, vtkIdType pointId);
129 
132  vtkIdType GetControlPointId(double* pos);
133 
137  vtkIdTypeArray* GetControlPointsIds()const;
138 
141  vtkIdTypeArray* GetControlPointsIds(bool excludeFirstAndLast)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 
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