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 
28 #ifndef vtkControlPointsItem_h
29 #define vtkControlPointsItem_h
30 
31 #include "vtkChartsCoreModule.h" // For export macro
32 #include "vtkCommand.h" // For vtkCommand enum
33 #include "vtkPlot.h"
34 #include "vtkVector.h" // For vtkVector2f
35 
36 class vtkCallbackCommand;
37 class vtkContext2D;
38 class vtkPoints2D;
39 class vtkTransform2D;
41 
42 class VTKCHARTSCORE_EXPORT vtkControlPointsItem: public vtkPlot
43 {
44 public:
45  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
46  void PrintSelf(ostream &os, vtkIndent indent) override;
47 
48  // Events fires by this class (and subclasses).
49  // \li CurrentPointChangedEvent is fired when the current point index is changed.
50  // \li CurrentPointEditEvent is fired to request the application to show UI to
51  // edit the current point.
52  // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
53  // to mark groups of changes to control points.
54  enum {
55  CurrentPointChangedEvent = vtkCommand::UserEvent,
56  CurrentPointEditEvent
57  };
58 
63  void GetBounds(double bounds[4]) override;
64 
66 
71  vtkSetVector4Macro(UserBounds, double);
72  vtkGetVector4Macro(UserBounds, double);
74 
76 
81  vtkSetVector4Macro(ValidBounds, double);
82  vtkGetVector4Macro(ValidBounds, double);
84 
86 
90  vtkGetMacro(ScreenPointRadius, float);
91  vtkSetMacro(ScreenPointRadius, float);
93 
99  bool Paint(vtkContext2D *painter) override;
100 
104  void SelectPoint(vtkIdType pointId);
105 
111  void SelectPoint(double* currentPoint);
112 
116  void SelectAllPoints();
117 
121  void DeselectPoint(vtkIdType pointId);
122 
128  void DeselectPoint(double* currentPoint);
129 
133  void DeselectAllPoints();
134 
139  void ToggleSelectPoint(vtkIdType pointId);
140 
146  void ToggleSelectPoint(double* currentPoint);
147 
151  bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) override;
152 
156  vtkIdType GetNumberOfSelectedPoints()const;
157 
162  vtkIdType FindPoint(double* pos);
163 
169  bool IsOverPoint(double* pos, vtkIdType pointId);
170 
174  vtkIdType GetControlPointId(double* pos);
175 
181  void GetControlPointsIds(vtkIdTypeArray* ids,
182  bool excludeFirstAndLast = false)const;
183 
185 
190  vtkGetMacro(StrokeMode, bool);
192 
194 
200  vtkSetMacro(SwitchPointsMode, bool);
201  vtkGetMacro(SwitchPointsMode, bool);
203 
205 
209  vtkSetMacro(EndPointsXMovable, bool);
210  vtkGetMacro(EndPointsXMovable, bool);
211  vtkSetMacro(EndPointsYMovable, bool);
212  vtkGetMacro(EndPointsYMovable, bool);
213  virtual bool GetEndPointsMovable();
215 
217 
221  vtkSetMacro(EndPointsRemovable, bool);
222  vtkGetMacro(EndPointsRemovable, bool);
224 
226 
230  vtkSetMacro(ShowLabels, bool);
231  vtkGetMacro(ShowLabels, bool);
233 
235 
238  vtkSetStringMacro(LabelFormat);
239  vtkGetStringMacro(LabelFormat);
241 
247  virtual vtkIdType AddPoint(double* newPos) = 0;
248 
254  virtual vtkIdType RemovePoint(double* pos) = 0;
255 
260  vtkIdType RemovePoint(vtkIdType pointId);
261 
265  inline void RemoveCurrentPoint();
266 
270  virtual vtkIdType GetNumberOfPoints()const = 0;
271 
277  virtual void GetControlPoint(vtkIdType index, double *point)const = 0;
278 
283  virtual void SetControlPoint(vtkIdType index, double *point) = 0;
284 
293  void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
294 
300  void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
301 
310  void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
311 
317  void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
318 
323  vtkIdType GetCurrentPoint()const;
324 
328  void SetCurrentPoint(vtkIdType index);
329 
331 
334  vtkGetObjectMacro(SelectedPointPen, vtkPen);
336 
338 
342  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
344 
349  void ResetBounds();
350 
352 
355  bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override;
356  bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse) override;
358 
362  bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override;
363 
364  bool KeyPressEvent(const vtkContextKeyEvent &key) override;
365  bool KeyReleaseEvent(const vtkContextKeyEvent &key) override;
366 
367 protected:
369  ~vtkControlPointsItem() override;
370 
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 = nullptr) = 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) override;
397 
399 
403  virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
404  virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
405  virtual void TransformScreenToData(const double inX, const double inY,
406  double &outX, double &outY);
407  virtual void TransformDataToScreen(const double inX, const double inY,
408  double &outX, double &outY);
410 
412 
416  virtual bool ClampPos(double pos[2], double bounds[4]);
417  bool ClampValidDataPos(double pos[2]);
418  bool ClampValidScreenPos(double pos[2]);
420 
422 
426  void DrawUnselectedPoints(vtkContext2D* painter);
427  void DrawSelectedPoints(vtkContext2D* painter);
428  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
430 
431  void SetCurrentPointPos(const vtkVector2f& newPos);
432  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
433  void MoveCurrentPoint(const vtkVector2f& translation);
434  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
435 
436  inline vtkVector2f GetSelectionCenterOfMass()const;
437  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const;
438 
439  void Stroke(const vtkVector2f& newPos);
440  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
444  bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override;
445 
449  virtual vtkStdString GetControlPointLabel(vtkIdType index);
450 
451  void AddPointId(vtkIdType addedPointId);
452 
457  bool IsEndPointPicked();
458 
462  bool IsPointRemovable(vtkIdType pointId);
463 
470  virtual void ComputeBounds(double* bounds);
471 
479 
480  double Bounds[4];
481  double UserBounds[4];
482  double ValidBounds[4];
483 
486 
500  char* LabelFormat;
501 private:
502  vtkControlPointsItem(const vtkControlPointsItem &) = delete;
503  void operator=(const vtkControlPointsItem &) = delete;
504 
505  void ComputeBounds();
506 
507  vtkIdType RemovePointId(vtkIdType removedPointId);
508 };
509 
510 //-----------------------------------------------------------------------------
512 {
513  this->RemovePoint(this->GetCurrentPoint());
514 }
515 
516 //-----------------------------------------------------------------------------
518 {
519  return this->GetCenterOfMass(this->Selection);
520 }
521 
522 #endif
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:37
vtkPoints2D
represent and manipulate 2D points
Definition: vtkPoints2D.h:33
vtkControlPointsItem::EnforceValidFunction
bool EnforceValidFunction
Definition: vtkControlPointsItem.h:490
vtkControlPointsItem::SelectedPointBrush
vtkBrush * SelectedPointBrush
Definition: vtkControlPointsItem.h:474
vtkControlPointsItem::LabelFormat
char * LabelFormat
Definition: vtkControlPointsItem.h:500
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:34
vtkCommand::UserEvent
Definition: vtkCommand.h:448
vtkContextKeyEvent
data structure to represent key events.
Definition: vtkContextKeyEvent.h:34
vtkControlPointsItem::PointAboutToBeToggled
bool PointAboutToBeToggled
Definition: vtkControlPointsItem.h:494
vtkPlot.h
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:45
vtkX3D::key
Definition: vtkX3D.h:257
vtkControlPointsItem::EndPointsRemovable
bool EndPointsRemovable
Definition: vtkControlPointsItem.h:498
vtkControlPointsItem::InvertShadow
bool InvertShadow
Definition: vtkControlPointsItem.h:495
vtkAbstractContextItem::KeyPressEvent
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
vtkControlPointsItem::PointAboutToBeDeleted
bool PointAboutToBeDeleted
Definition: vtkControlPointsItem.h:492
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkVector.h
vtkControlPointsItem::CurrentPoint
vtkIdType CurrentPoint
Definition: vtkControlPointsItem.h:478
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
vtkCommand.h
vtkPlot
Abstract class for 2D plots.
Definition: vtkPlot.h:46
vtkPiecewisePointHandleItem
a vtkContextItem that draws handles around a point of a piecewise function
Definition: vtkPiecewisePointHandleItem.h:39
vtkControlPointsItem::StartedInteractions
int StartedInteractions
Definition: vtkControlPointsItem.h:476
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkControlPointsItem
Abstract class for control points items.
Definition: vtkControlPointsItem.h:42
vtkControlPointsItem::ShowLabels
bool ShowLabels
Definition: vtkControlPointsItem.h:499
vtkControlPointsItem::GetSelectionCenterOfMass
vtkVector2f GetSelectionCenterOfMass() const
Definition: vtkControlPointsItem.h:517
vtkX3D::point
Definition: vtkX3D.h:236
vtkPlot::SelectPoints
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
Select all points in the specified rectangle.
vtkControlPointsItem::EndPointsXMovable
bool EndPointsXMovable
Definition: vtkControlPointsItem.h:496
vtkControlPointsItem::MouseMoved
bool MouseMoved
Definition: vtkControlPointsItem.h:489
vtkControlPointsItem::RemovePoint
virtual vtkIdType RemovePoint(double *pos)=0
Remove a point of the function.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkControlPointsItem::SwitchPointsMode
bool SwitchPointsMode
Definition: vtkControlPointsItem.h:488
vtkAbstractContextItem::Hit
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
vtkControlPointsItem::StrokeMode
bool StrokeMode
Definition: vtkControlPointsItem.h:487
vtkControlPointsItem::Transform
vtkTransform2D * Transform
Definition: vtkControlPointsItem.h:484
vtkAbstractContextItem::MouseMoveEvent
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
vtkPlot::Selection
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition: vtkPlot.h:447
vtkAbstractContextItem::MouseButtonReleaseEvent
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
Mouse button release event.
vtkControlPointsItem::GetCenterOfMass
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
vtkControlPointsItem::EndPointsYMovable
bool EndPointsYMovable
Definition: vtkControlPointsItem.h:497
vtkControlPointsItem::BlockUpdates
int BlockUpdates
Definition: vtkControlPointsItem.h:475
vtkControlPointsItem::ScreenPointRadius
float ScreenPointRadius
Definition: vtkControlPointsItem.h:485
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:35
vtkAbstractContextItem::Paint
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
vtkControlPointsItem::SelectedPointPen
vtkPen * SelectedPointPen
Definition: vtkControlPointsItem.h:473
vtkControlPointsItem::GetCurrentPoint
vtkIdType GetCurrentPoint() const
Returns the current point ID selected or -1 if there is no point current.
vtkCallbackCommand
supports function callbacks
Definition: vtkCallbackCommand.h:44
vtkAbstractContextItem::MouseDoubleClickEvent
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
vtkAbstractContextItem::KeyReleaseEvent
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key)
Key release event.
vtkControlPointsItem::RemoveCurrentPoint
void RemoveCurrentPoint()
Remove the current point.
Definition: vtkControlPointsItem.h:511
vtkAbstractContextItem::MouseButtonPressEvent
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...
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:36
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkControlPointsItem::StartedChanges
int StartedChanges
Definition: vtkControlPointsItem.h:477
vtkControlPointsItem::PointToToggle
vtkIdType PointToToggle
Definition: vtkControlPointsItem.h:493
vtkX3D::translation
Definition: vtkX3D.h:232
vtkPlot::GetBounds
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition: vtkPlot.h:330
vtkControlPointsItem::PointToDelete
vtkIdType PointToDelete
Definition: vtkControlPointsItem.h:491
vtkX3D::index
Definition: vtkX3D.h:246
vtkPlot::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkVector2f
Definition: vtkVector.h:415
vtkControlPointsItem::Callback
vtkCallbackCommand * Callback
Definition: vtkControlPointsItem.h:472
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:302