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;
40 
41 class VTKCHARTSCORE_EXPORT vtkControlPointsItem: public vtkPlot
42 {
43 public:
44  vtkTypeMacro(vtkControlPointsItem, vtkPlot);
45  void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE;
46 
47  // Events fires by this class (and subclasses).
48  // \li CurrentPointChangedEvent is fired when the current point index is changed.
49  // \li CurrentPointEditEvent is fired to request the application to show UI to
50  // edit the current point.
51  // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
52  // to mark groups of changes to control points.
53  enum {
54  CurrentPointChangedEvent = vtkCommand::UserEvent,
55  CurrentPointEditEvent
56  };
57 
62  void GetBounds(double bounds[4]) VTK_OVERRIDE;
63 
65 
70  vtkSetVector4Macro(UserBounds, double);
71  vtkGetVector4Macro(UserBounds, double);
73 
75 
80  vtkSetVector4Macro(ValidBounds, double);
81  vtkGetVector4Macro(ValidBounds, double);
83 
85 
89  vtkGetMacro(ScreenPointRadius, float);
90  vtkSetMacro(ScreenPointRadius, float);
92 
98  bool Paint(vtkContext2D *painter) VTK_OVERRIDE;
99 
103  void SelectPoint(vtkIdType pointId);
104 
110  void SelectPoint(double* currentPoint);
111 
115  void SelectAllPoints();
116 
120  void DeselectPoint(vtkIdType pointId);
121 
127  void DeselectPoint(double* currentPoint);
128 
132  void DeselectAllPoints();
133 
138  void ToggleSelectPoint(vtkIdType pointId);
139 
145  void ToggleSelectPoint(double* currentPoint);
146 
150  bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) VTK_OVERRIDE;
151 
155  vtkIdType GetNumberOfSelectedPoints()const;
156 
161  vtkIdType FindPoint(double* pos);
162 
168  bool IsOverPoint(double* pos, vtkIdType pointId);
169 
173  vtkIdType GetControlPointId(double* pos);
174 
180  void GetControlPointsIds(vtkIdTypeArray* ids,
181  bool excludeFirstAndLast = false)const;
182 
184 
189  vtkGetMacro(StrokeMode, bool);
191 
193 
199  vtkSetMacro(SwitchPointsMode, bool);
200  vtkGetMacro(SwitchPointsMode, bool);
202 
204 
208  vtkSetMacro(EndPointsXMovable, bool);
209  vtkGetMacro(EndPointsXMovable, bool);
210  vtkSetMacro(EndPointsYMovable, bool);
211  vtkGetMacro(EndPointsYMovable, bool);
212  virtual bool GetEndPointsMovable();
214 
216 
220  vtkSetMacro(EndPointsRemovable, bool);
221  vtkGetMacro(EndPointsRemovable, bool);
223 
225 
229  vtkSetMacro(ShowLabels, bool);
230  vtkGetMacro(ShowLabels, bool);
232 
234 
237  vtkSetStringMacro(LabelFormat);
238  vtkGetStringMacro(LabelFormat);
240 
246  virtual vtkIdType AddPoint(double* newPos) = 0;
247 
253  virtual vtkIdType RemovePoint(double* pos) = 0;
254 
259  vtkIdType RemovePoint(vtkIdType pointId);
260 
264  inline void RemoveCurrentPoint();
265 
269  virtual vtkIdType GetNumberOfPoints()const = 0;
270 
276  virtual void GetControlPoint(vtkIdType index, double *point)const = 0;
277 
282  virtual void SetControlPoint(vtkIdType index, double *point) = 0;
283 
292  void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
293 
299  void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
300 
309  void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
310 
316  void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
317 
322  vtkIdType GetCurrentPoint()const;
323 
327  void SetCurrentPoint(vtkIdType index);
328 
330 
333  vtkGetObjectMacro(SelectedPointPen, vtkPen);
335 
337 
341  vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
343 
348  void ResetBounds();
349 
351 
354  bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
355  bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
357 
361  bool MouseMoveEvent(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
362 
363  bool KeyPressEvent(const vtkContextKeyEvent &key) VTK_OVERRIDE;
364  bool KeyReleaseEvent(const vtkContextKeyEvent &key) VTK_OVERRIDE;
365 
366 protected:
368  ~vtkControlPointsItem() VTK_OVERRIDE;
369 
370  void StartChanges();
371  void EndChanges();
372  void StartInteraction();
373  void StartInteractionIfNotStarted();
374  void Interaction();
375  void EndInteraction();
376  int GetInteractionsCount()const;
377  virtual void emitEvent(unsigned long event, void* params = 0) = 0;
378 
379  static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params);
380 
382 
386  virtual void ComputePoints();
387  virtual vtkMTimeType GetControlPointsMTime() =0;
389 
393  bool Hit(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
394 
396 
400  virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
401  virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
403 
405 
409  virtual bool ClampPos(double pos[2], double bounds[4]);
410  bool ClampValidPos(double pos[2]);
412 
414 
418  void DrawUnselectedPoints(vtkContext2D* painter);
419  void DrawSelectedPoints(vtkContext2D* painter);
420  virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
422 
423  void SetCurrentPointPos(const vtkVector2f& newPos);
424  vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
425  void MoveCurrentPoint(const vtkVector2f& translation);
426  vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
427 
428  inline vtkVector2f GetSelectionCenterOfMass()const;
429  vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const;
430 
431  void Stroke(const vtkVector2f& newPos);
432  virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
436  bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) VTK_OVERRIDE;
437 
441  virtual vtkStdString GetControlPointLabel(vtkIdType index);
442 
443  void AddPointId(vtkIdType addedPointId);
444 
449  bool IsEndPointPicked();
450 
454  bool IsPointRemovable(vtkIdType pointId);
455 
462  virtual void ComputeBounds(double* bounds);
463 
469  virtual bool UsingLogScale() { return false; }
470 
478 
479  double Bounds[4];
480  double UserBounds[4];
481  double ValidBounds[4];
482 
485 
499  char* LabelFormat;
500 private:
501  vtkControlPointsItem(const vtkControlPointsItem &) VTK_DELETE_FUNCTION;
502  void operator=(const vtkControlPointsItem &) VTK_DELETE_FUNCTION;
503 
504  void ComputeBounds();
505 
506  vtkIdType RemovePointId(vtkIdType removedPointId);
507 };
508 
509 //-----------------------------------------------------------------------------
511 {
512  this->RemovePoint(this->GetCurrentPoint());
513 }
514 
515 //-----------------------------------------------------------------------------
517 {
518  return this->GetCenterOfMass(this->Selection);
519 }
520 
521 #endif
vtkVector2f GetSelectionCenterOfMass() const
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:41
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:300
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:345
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
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
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
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.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
virtual vtkIdType RemovePoint(double *pos)=0
Remove a point of the function.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
#define max(a, b)
vtkCallbackCommand * Callback