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
vtkVector2f GetSelectionCenterOfMass() const
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
data structure to represent key events.
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkIdType GetCurrentPoint() const
Returns the current point ID selected or -1 if there is no point current.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:302
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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...
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key)
Key release event.
Abstract class for control points items.
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition: vtkPlot.h:330
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition: vtkPlot.h:447
void RemoveCurrentPoint()
Remove the current point.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
supports function callbacks
a vtkContextItem that draws handles around a point of a piecewise function
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:37
data structure to represent mouse events.
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
Select all points in the specified rectangle.
vtkTransform2D * Transform
a simple class to control print indentation
Definition: vtkIndent.h:33
represent and manipulate 2D points
Definition: vtkPoints2D.h:33
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
Mouse button release event.
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:36
describes linear transformations via a 3x3 matrix
Abstract class for 2D plots.
Definition: vtkPlot.h:46
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
virtual vtkIdType RemovePoint(double *pos)=0
Remove a point of the function.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
#define max(a, b)
vtkCallbackCommand * Callback