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:
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 
101 
103  void DeselectPoint(vtkIdType pointId);
104 
108  void DeselectPoint(double* currentPoint);
109 
112 
116 
120  void ToggleSelectPoint(double* currentPoint);
121 
123  virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
124 
127 
130  vtkIdType FindPoint(double* pos);
131 
135  bool IsOverPoint(double* pos, vtkIdType pointId);
136 
140 
142 
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 
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 
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 
252 
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:
286 
287  void StartChanges();
288  void EndChanges();
291  void Interaction();
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 
327  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
329 
330  void SetCurrentPointPos(const vtkVector2f& newPos);
334 
335  inline vtkVector2f GetSelectionCenterOfMass()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 
345 
346  void AddPointId(vtkIdType addedPointId);
347 
351 
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
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:37
vtkPoints2D
represent and manipulate 2D points
Definition: vtkPoints2D.h:36
vtkControlPointsItem::EnforceValidFunction
bool EnforceValidFunction
Definition: vtkControlPointsItem.h:385
vtkControlPointsItem::IsEndPointPicked
bool IsEndPointPicked()
vtkControlPointsItem::SelectedPointBrush
vtkBrush * SelectedPointBrush
Definition: vtkControlPointsItem.h:369
vtkControlPointsItem::LabelFormat
char * LabelFormat
Definition: vtkControlPointsItem.h:395
vtkChartsCoreModule.h
vtkControlPointsItem::IsPointRemovable
bool IsPointRemovable(vtkIdType pointId)
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:40
vtkGetObjectMacro
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:232
vtkControlPointsItem::EndInteraction
void EndInteraction()
vtkContextKeyEvent
data structure to represent key events.
Definition: vtkContextKeyEvent.h:34
vtkControlPointsItem::SetPointPos
vtkIdType SetPointPos(vtkIdType point, const vtkVector2f &newPos)
vtkControlPointsItem::SelectAllPoints
void SelectAllPoints()
vtkControlPointsItem::GetNumberOfSelectedPoints
vtkIdType GetNumberOfSelectedPoints() const
vtkControlPointsItem::GetControlPoint
virtual void GetControlPoint(vtkIdType index, double *point) const =0
vtkControlPointsItem::MouseButtonReleaseEvent
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
vtkControlPointsItem::GetBounds
virtual void GetBounds(double bounds[4])
vtkControlPointsItem::PointAboutToBeToggled
bool PointAboutToBeToggled
Definition: vtkControlPointsItem.h:389
vtkControlPointsItem::GetNumberOfPoints
virtual vtkIdType GetNumberOfPoints() const =0
vtkControlPointsItem::RemovePoint
vtkIdType RemovePoint(vtkIdType pointId)
vtkPlot.h
vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkControlPointsItem::ComputePoints
virtual void ComputePoints()
vtkControlPointsItem::DrawSelectedPoints
void DrawSelectedPoints(vtkContext2D *painter)
vtkControlPointsItem::KeyPressEvent
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:47
vtkControlPointsItem::EndChanges
void EndChanges()
vtkControlPointsItem::MoveCurrentPoint
void MoveCurrentPoint(const vtkVector2f &translation)
vtkX3D::key
@ key
Definition: vtkX3D.h:257
vtkControlPointsItem::EndPointsRemovable
bool EndPointsRemovable
Definition: vtkControlPointsItem.h:393
vtkControlPointsItem::SetControlPoint
virtual void SetControlPoint(vtkIdType index, double *point)=0
vtkControlPointsItem::InvertShadow
bool InvertShadow
Definition: vtkControlPointsItem.h:390
vtkControlPointsItem::DeselectPoint
void DeselectPoint(double *currentPoint)
vtkControlPointsItem::PointAboutToBeDeleted
bool PointAboutToBeDeleted
Definition: vtkControlPointsItem.h:387
vtkControlPointsItem::DrawPoint
virtual void DrawPoint(vtkContext2D *painter, vtkIdType index)
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkControlPointsItem::MouseDoubleClickEvent
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkControlPointsItem::StartInteractionIfNotStarted
void StartInteractionIfNotStarted()
vtkVector.h
vtkControlPointsItem::SpreadPoints
void SpreadPoints(float factor, bool dontSpreadFirstAndLast=false)
vtkControlPointsItem::CurrentPoint
vtkIdType CurrentPoint
Definition: vtkControlPointsItem.h:373
vtkControlPointsItem::vtkControlPointsItem
vtkControlPointsItem()
vtkControlPointsItem::MovePoints
void MovePoints(const vtkVector2f &translation, vtkIdTypeArray *pointIds)
vtkControlPointsItem::MouseMoveEvent
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:57
vtkControlPointsItem::SetCurrentPointPos
void SetCurrentPointPos(const vtkVector2f &newPos)
vtkControlPointsItem::SelectPoints
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
vtkControlPointsItem::AddPoint
virtual vtkIdType AddPoint(double *newPos)=0
vtkCommand.h
vtkControlPointsItem::GetEndPointsMovable
virtual bool GetEndPointsMovable()
vtkPlot
Abstract class for 2D plots.
Definition: vtkPlot.h:52
vtkControlPointsItem::GetControlPointId
vtkIdType GetControlPointId(double *pos)
vtkgl::in
GLuint in
Definition: vtkgl.h:16905
vtkControlPointsItem::StartedInteractions
int StartedInteractions
Definition: vtkControlPointsItem.h:371
vtkControlPointsItem::GetControlPointLabel
virtual vtkStdString GetControlPointLabel(vtkIdType index)
vtkgl::event
struct _cl_event * event
Definition: vtkgl.h:14387
vtkControlPointsItem::StartChanges
void StartChanges()
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:30
vtkControlPointsItem::ToggleSelectPoint
void ToggleSelectPoint(double *currentPoint)
vtkControlPointsItem::UsingLogScale
virtual bool UsingLogScale()
Definition: vtkControlPointsItem.h:365
vtkControlPointsItem::DrawUnselectedPoints
void DrawUnselectedPoints(vtkContext2D *painter)
vtkControlPointsItem
Abstract class for control points items.
Definition: vtkControlPointsItem.h:44
vtkControlPointsItem::DeselectPoint
void DeselectPoint(vtkIdType pointId)
vtkControlPointsItem::ShowLabels
bool ShowLabels
Definition: vtkControlPointsItem.h:394
vtkControlPointsItem::GetSelectionCenterOfMass
vtkVector2f GetSelectionCenterOfMass() const
Definition: vtkControlPointsItem.h:412
vtkX3D::point
@ point
Definition: vtkX3D.h:236
vtkControlPointsItem::ComputeBounds
virtual void ComputeBounds(double *bounds)
vtkNotUsed
#define vtkNotUsed(x)
Definition: vtkSetGet.h:557
vtkControlPointsItem::EditPoint
virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY))
vtkControlPointsItem::EndPointsXMovable
bool EndPointsXMovable
Definition: vtkControlPointsItem.h:391
vtkgl::ids
GLuint * ids
Definition: vtkgl.h:11831
vtkgl::params
GLenum const GLfloat * params
Definition: vtkgl.h:11333
vtkControlPointsItem::Paint
virtual bool Paint(vtkContext2D *painter)
vtkControlPointsItem::MouseMoved
bool MouseMoved
Definition: vtkControlPointsItem.h:384
vtkControlPointsItem::RemovePoint
virtual vtkIdType RemovePoint(double *pos)=0
vtkControlPointsItem::Hit
virtual bool Hit(const vtkContextMouseEvent &mouse)
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkControlPointsItem::SwitchPointsMode
bool SwitchPointsMode
Definition: vtkControlPointsItem.h:383
vtkControlPointsItem::MovePoints
void MovePoints(const vtkVector2f &translation, bool dontMoveFirstAndLast=false)
vtkSetStringMacro
#define vtkSetStringMacro(name)
Definition: vtkSetGet.h:104
vtkControlPointsItem::StrokeMode
bool StrokeMode
Definition: vtkControlPointsItem.h:382
vtkControlPointsItem::MovePoint
vtkIdType MovePoint(vtkIdType point, const vtkVector2f &translation)
vtkControlPointsItem::ToggleSelectPoint
void ToggleSelectPoint(vtkIdType pointId)
vtkControlPointsItem::TransformDataToScreen
virtual void TransformDataToScreen(const vtkVector2f &in, vtkVector2f &out)
vtkControlPointsItem::ClampValidPos
bool ClampValidPos(double pos[2])
vtkControlPointsItem::SetCurrentPoint
void SetCurrentPoint(vtkIdType index)
vtkGetMacro
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:93
vtkControlPointsItem::Transform
vtkTransform2D * Transform
Definition: vtkControlPointsItem.h:379
vtkGetStringMacro
vtkGetStringMacro(ExtensionsString)
vtkControlPointsItem::AddPointId
void AddPointId(vtkIdType addedPointId)
vtkPlot::Selection
vtkIdTypeArray * Selection
Definition: vtkPlot.h:362
vtkControlPointsItem::SelectPoint
void SelectPoint(vtkIdType pointId)
vtkControlPointsItem::SpreadPoints
void SpreadPoints(float factor, vtkIdTypeArray *pointIds)
vtkControlPointsItem::ClampPos
virtual bool ClampPos(double pos[2], double bounds[4])
vtkControlPointsItem::GetCenterOfMass
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
vtkControlPointsItem::CallComputePoints
static void CallComputePoints(vtkObject *sender, unsigned long event, void *receiver, void *params)
vtkControlPointsItem::KeyReleaseEvent
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key)
vtkControlPointsItem::SelectPoint
void SelectPoint(double *currentPoint)
vtkControlPointsItem::emitEvent
virtual void emitEvent(unsigned long event, void *params=0)=0
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
vtkControlPointsItem::EndPointsYMovable
bool EndPointsYMovable
Definition: vtkControlPointsItem.h:392
vtkSetVector4Macro
#define vtkSetVector4Macro(name, type)
Definition: vtkSetGet.h:322
vtkgl::index
GLuint index
Definition: vtkgl.h:11983
vtkControlPointsItem::BlockUpdates
int BlockUpdates
Definition: vtkControlPointsItem.h:370
vtkControlPointsItem::DeselectAllPoints
void DeselectAllPoints()
vtkControlPointsItem::GetControlPointsMTime
virtual unsigned long int GetControlPointsMTime()=0
vtkControlPointsItem::~vtkControlPointsItem
virtual ~vtkControlPointsItem()
vtkControlPointsItem::ScreenPointRadius
float ScreenPointRadius
Definition: vtkControlPointsItem.h:380
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:49
vtkControlPointsItem::CurrentPointEditEvent
@ CurrentPointEditEvent
Definition: vtkControlPointsItem.h:57
vtkControlPointsItem::SelectedPointPen
vtkPen * SelectedPointPen
Definition: vtkControlPointsItem.h:368
vtkControlPointsItem::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
vtkControlPointsItem::GetCurrentPoint
vtkIdType GetCurrentPoint() const
vtkCallbackCommand
supports function callbacks
Definition: vtkCallbackCommand.h:50
vtkControlPointsItem::MouseButtonPressEvent
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse)
vtkControlPointsItem::FindPoint
vtkIdType FindPoint(double *pos)
vtkControlPointsItem::RemoveCurrentPoint
void RemoveCurrentPoint()
Definition: vtkControlPointsItem.h:406
vtkControlPointsItem::Stroke
void Stroke(const vtkVector2f &newPos)
vtkControlPointsItem::StartInteraction
void StartInteraction()
vtkControlPointsItem::TransformScreenToData
virtual void TransformScreenToData(const vtkVector2f &in, vtkVector2f &out)
vtkControlPointsItem::GetInteractionsCount
int GetInteractionsCount() const
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:39
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:48
vtkControlPointsItem::StartedChanges
int StartedChanges
Definition: vtkControlPointsItem.h:372
VTKCHARTSCORE_EXPORT
#define VTKCHARTSCORE_EXPORT
Definition: vtkChartsCoreModule.h:15
vtkControlPointsItem::PointToToggle
vtkIdType PointToToggle
Definition: vtkControlPointsItem.h:388
vtkX3D::translation
@ translation
Definition: vtkX3D.h:232
vtkControlPointsItem::Interaction
void Interaction()
vtkControlPointsItem::PointToDelete
vtkIdType PointToDelete
Definition: vtkControlPointsItem.h:386
vtkGetVector4Macro
#define vtkGetVector4Macro(name, type)
Definition: vtkSetGet.h:341
vtkVector2f
Definition: vtkVector.h:277
vtkControlPointsItem::Callback
vtkCallbackCommand * Callback
Definition: vtkControlPointsItem.h:367
vtkControlPointsItem::GetControlPointsIds
void GetControlPointsIds(vtkIdTypeArray *ids, bool excludeFirstAndLast=false) const
vtkControlPointsItem::ResetBounds
void ResetBounds()
vtkControlPointsItem::IsOverPoint
bool IsOverPoint(double *pos, vtkIdType pointId)