VTK  9.3.1
vtkSplineWidget.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
75 #ifndef vtkSplineWidget_h
76 #define vtkSplineWidget_h
77 
78 #include "vtk3DWidget.h"
79 #include "vtkInteractionWidgetsModule.h" // For export macro
80 
81 VTK_ABI_NAMESPACE_BEGIN
82 class vtkActor;
83 class vtkCellPicker;
86 class vtkPlaneSource;
87 class vtkPoints;
88 class vtkPolyData;
89 class vtkProp;
90 class vtkProperty;
91 class vtkSphereSource;
92 class vtkTransform;
93 
94 #define VTK_PROJECTION_YZ 0
95 #define VTK_PROJECTION_XZ 1
96 #define VTK_PROJECTION_XY 2
97 #define VTK_PROJECTION_OBLIQUE 3
98 
99 class VTKINTERACTIONWIDGETS_EXPORT vtkSplineWidget : public vtk3DWidget
100 {
101 public:
105  static vtkSplineWidget* New();
106 
107  vtkTypeMacro(vtkSplineWidget, vtk3DWidget);
108  void PrintSelf(ostream& os, vtkIndent indent) override;
109 
111 
114  void SetEnabled(int) override;
115  void PlaceWidget(double bounds[6]) override;
116  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
118  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
119  {
120  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
121  }
123 
125 
133  vtkSetMacro(ProjectToPlane, vtkTypeBool);
134  vtkGetMacro(ProjectToPlane, vtkTypeBool);
135  vtkBooleanMacro(ProjectToPlane, vtkTypeBool);
137 
142  void SetPlaneSource(vtkPlaneSource* plane);
143 
144  vtkSetClampMacro(ProjectionNormal, int, VTK_PROJECTION_YZ, VTK_PROJECTION_OBLIQUE);
145  vtkGetMacro(ProjectionNormal, int);
146  void SetProjectionNormalToXAxes() { this->SetProjectionNormal(0); }
147  void SetProjectionNormalToYAxes() { this->SetProjectionNormal(1); }
148  void SetProjectionNormalToZAxes() { this->SetProjectionNormal(2); }
149  void SetProjectionNormalToOblique() { this->SetProjectionNormal(3); }
150 
152 
159  void SetProjectionPosition(double position);
160  vtkGetMacro(ProjectionPosition, double);
162 
170  void GetPolyData(vtkPolyData* pd);
171 
173 
177  virtual void SetHandleProperty(vtkProperty*);
178  vtkGetObjectMacro(HandleProperty, vtkProperty);
179  virtual void SetSelectedHandleProperty(vtkProperty*);
180  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
182 
184 
188  virtual void SetLineProperty(vtkProperty*);
189  vtkGetObjectMacro(LineProperty, vtkProperty);
190  virtual void SetSelectedLineProperty(vtkProperty*);
191  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
193 
195 
198  virtual void SetNumberOfHandles(int npts);
199  vtkGetMacro(NumberOfHandles, int);
201 
203 
207  void SetResolution(int resolution);
208  vtkGetMacro(Resolution, int);
210 
212 
220  virtual void SetParametricSpline(vtkParametricSpline*);
221  vtkGetObjectMacro(ParametricSpline, vtkParametricSpline);
223 
225 
229  void SetHandlePosition(int handle, double x, double y, double z);
230  void SetHandlePosition(int handle, double xyz[3]);
231  void GetHandlePosition(int handle, double xyz[3]);
232  double* GetHandlePosition(int handle) VTK_SIZEHINT(3);
234 
236 
243  void SetClosed(vtkTypeBool closed);
244  vtkGetMacro(Closed, vtkTypeBool);
245  vtkBooleanMacro(Closed, vtkTypeBool);
247 
253  int IsClosed();
254 
260  double GetSummedLength();
261 
268  void InitializeHandles(vtkPoints* points);
269 
271 
275  vtkSetClampMacro(ProcessEvents, vtkTypeBool, 0, 1);
276  vtkGetMacro(ProcessEvents, vtkTypeBool);
277  vtkBooleanMacro(ProcessEvents, vtkTypeBool);
279 
280 protected:
281  vtkSplineWidget();
282  ~vtkSplineWidget() override;
283 
284  // Manage the state of the widget
285  int State;
287  {
288  Start = 0,
294  Outside
295  };
296 
297  // handles the events
298  static void ProcessEventsHandler(
299  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
300 
301  // ProcessEventsHandler() dispatches to these methods.
302  void OnLeftButtonDown();
303  void OnLeftButtonUp();
304  void OnMiddleButtonDown();
305  void OnMiddleButtonUp();
306  void OnRightButtonDown();
307  void OnRightButtonUp();
308  void OnMouseMove();
309 
310  // Controlling vars
315 
316  // Projection capabilities
317  void ProjectPointsToPlane();
318  void ProjectPointsToOrthoPlane();
319  void ProjectPointsToObliquePlane();
320 
321  // The spline
326  void BuildRepresentation();
327 
328  // The line segments
330  void HighlightLine(int highlight);
332 
333  // Glyphs representing hot spots (e.g., handles)
336  void Initialize();
337  int HighlightHandle(vtkProp* prop); // returns handle index or -1 on fail
338  void SizeHandles() override;
339  void InsertHandleOnLine(double* pos);
340  void EraseHandle(const int&);
341 
342  // Do the picking
347 
348  // Register internal Pickers within PickingManager
349  void RegisterPickers() override;
350 
351  // Methods to manipulate the spline.
352  void MovePoint(double* p1, double* p2);
353  void Scale(double* p1, double* p2, int X, int Y);
354  void Translate(double* p1, double* p2);
355  void Spin(double* p1, double* p2, double* vpn);
356 
357  // Transform the control points (used for spinning)
359 
360  // Properties used to control the appearance of selected objects and
361  // the manipulator in general.
366  void CreateDefaultProperties();
367 
368  // For efficient spinning
369  double Centroid[3];
370  void CalculateCentroid();
372 
373 private:
374  vtkSplineWidget(const vtkSplineWidget&) = delete;
375  void operator=(const vtkSplineWidget&) = delete;
376 };
377 
378 VTK_ABI_NAMESPACE_END
379 #endif
vtkSphereSource ** HandleGeometry
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
vtkProperty * SelectedHandleProperty
void SetProjectionNormalToOblique()
vtkTypeBool ProjectToPlane
vtkParametricFunctionSource * ParametricFunctionSource
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:51
vtkActor * LineActor
represent surface properties of a geometric object
Definition: vtkProperty.h:56
void PlaceWidget() override
Methods that satisfy the superclass' API.
void SetProjectionNormalToXAxes()
virtual void SetEnabled(int)
Methods for turning the interactor observer on and off, and determining its state.
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Methods that satisfy the superclass' API.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:49
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
void SetProjectionNormalToZAxes()
vtkTypeBool Closed
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkProperty * LineProperty
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
vtkTransform * Transform
int vtkTypeBool
Definition: vtkABI.h:64
create a polygonal sphere centered at the origin
parametric function for 1D interpolating splines
a simple class to control print indentation
Definition: vtkIndent.h:28
void SetProjectionNormalToYAxes()
vtkProperty * HandleProperty
vtkCellPicker * LinePicker
3D widget for manipulating a spline
vtkActor * CurrentHandle
vtkPlaneSource * PlaneSource
#define VTK_PROJECTION_YZ
#define VTK_SIZEHINT(...)
create an array of quadrilaterals located in a plane
vtkActor ** Handle
vtkTypeBool ProcessEvents
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:61
vtkCellPicker * HandlePicker
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkProperty * SelectedLineProperty
#define VTK_PROJECTION_OBLIQUE
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:59
virtual void SizeHandles()
Definition: vtk3DWidget.h:144
virtual void PlaceWidget()
This method is used to initially place the widget.
represent and manipulate 3D points
Definition: vtkPoints.h:28
vtkParametricSpline * ParametricSpline
tessellate parametric functions