VTK  9.3.20240327
vtkBrokenLineWidget.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
76 #ifndef vtkBrokenLineWidget_h
77 #define vtkBrokenLineWidget_h
78 
79 #include "vtk3DWidget.h"
80 #include "vtkInteractionWidgetsModule.h" // For export macro
81 
82 VTK_ABI_NAMESPACE_BEGIN
83 class vtkActor;
84 class vtkCellPicker;
85 class vtkLineSource;
86 class vtkPlaneSource;
87 class vtkPoints;
88 class vtkPolyData;
89 class vtkPolyDataMapper;
90 class vtkProp;
91 class vtkProperty;
92 class vtkSphereSource;
93 class vtkTransform;
94 
95 #define VTK_PROJECTION_YZ 0
96 #define VTK_PROJECTION_XZ 1
97 #define VTK_PROJECTION_XY 2
98 #define VTK_PROJECTION_OBLIQUE 3
99 
100 class VTKINTERACTIONWIDGETS_EXPORT vtkBrokenLineWidget : public vtk3DWidget
101 {
102 public:
107 
109  void PrintSelf(ostream& os, vtkIndent indent) override;
110 
112 
115  void SetEnabled(int) override;
116  void PlaceWidget(double bounds[6]) override;
117  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
119  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
120  {
121  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
122  }
124 
126 
134  vtkSetMacro(ProjectToPlane, vtkTypeBool);
135  vtkGetMacro(ProjectToPlane, vtkTypeBool);
136  vtkBooleanMacro(ProjectToPlane, vtkTypeBool);
138 
144 
145  vtkSetClampMacro(ProjectionNormal, int, VTK_PROJECTION_YZ, VTK_PROJECTION_OBLIQUE);
146  vtkGetMacro(ProjectionNormal, int);
147  void SetProjectionNormalToXAxes() { this->SetProjectionNormal(0); }
148  void SetProjectionNormalToYAxes() { this->SetProjectionNormal(1); }
149  void SetProjectionNormalToZAxes() { this->SetProjectionNormal(2); }
150  void SetProjectionNormalToOblique() { this->SetProjectionNormal(3); }
151 
153 
161  vtkGetMacro(ProjectionPosition, double);
163 
172 
174 
179  vtkGetObjectMacro(HandleProperty, vtkProperty);
181  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
183 
185 
189  virtual void SetLineProperty(vtkProperty*);
190  vtkGetObjectMacro(LineProperty, vtkProperty);
192  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
194 
196 
199  virtual void SetNumberOfHandles(int npts);
200  vtkGetMacro(NumberOfHandles, int);
202 
204 
208  void SetHandlePosition(int handle, double x, double y, double z);
209  void SetHandlePosition(int handle, double xyz[3]);
210  void GetHandlePosition(int handle, double xyz[3]);
211  double* GetHandlePosition(int handle);
213 
217  double GetSummedLength();
218 
224 
226 
230  vtkSetClampMacro(ProcessEvents, vtkTypeBool, 0, 1);
231  vtkGetMacro(ProcessEvents, vtkTypeBool);
232  vtkBooleanMacro(ProcessEvents, vtkTypeBool);
234 
236 
240  vtkSetClampMacro(HandleSizeFactor, double, 0., 100.);
241  vtkGetMacro(HandleSizeFactor, double);
243 
244 protected:
247 
248  // Manage the state of the widget
249  int State;
251  {
252  Start = 0,
258  Outside
259  };
260 
261  // handles the events
262  static void ProcessEventsHandler(
263  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
264 
265  // ProcessEventsHandler() dispatches to these methods.
272  void OnMouseMove();
273 
274  // Controlling vars
279 
280  // Projection capabilities
284 
285  // The broken line
289  void HighlightLine(int highlight);
292 
293  // Glyphs representing hot spots (e.g., handles)
296  void Initialize();
297  int HighlightHandle(vtkProp* prop); // returns handle index or -1 on fail
298  void SizeHandles() override;
299  void InsertHandleOnLine(double* pos);
300  void EraseHandle(const int&);
301 
302  // Do the picking
307 
308  // Register internal Pickers within PickingManager
309  void RegisterPickers() override;
310 
311  // Methods to manipulate the broken line.
312  void MovePoint(double* p1, double* p2);
313  void Scale(double* p1, double* p2, int X, int Y);
314  void Translate(double* p1, double* p2);
315  void Spin(double* p1, double* p2, double* vpn);
316 
317  // Transform the control points (used for spinning)
319 
320  // Properties used to control the appearance of selected objects and
321  // the manipulator in general.
327 
328  // For efficient spinning
329  double Centroid[3];
332 
333  // Handle sizing factor
335 
336 private:
337  vtkBrokenLineWidget(const vtkBrokenLineWidget&) = delete;
338  void operator=(const vtkBrokenLineWidget&) = delete;
339 };
340 
341 VTK_ABI_NAMESPACE_END
342 #endif
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:60
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:150
3D widget for manipulating a broken line
double GetSummedLength()
Get the summed lengths of the individual straight line segments.
void EraseHandle(const int &)
void InsertHandleOnLine(double *pos)
int HighlightHandle(vtkProp *prop)
vtkProperty * SelectedLineProperty
double * GetHandlePosition(int handle)
Set/Get the position of the broken line handles.
vtkProperty * HandleProperty
static void ProcessEventsHandler(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
vtkPolyDataMapper * LineMapper
vtkSphereSource ** HandleGeometry
virtual void SetSelectedLineProperty(vtkProperty *)
Set/Get the line properties.
virtual void SetHandleProperty(vtkProperty *)
Set/Get the handle properties (the spheres are the handles).
void SetHandlePosition(int handle, double x, double y, double z)
Set/Get the position of the broken line handles.
void InitializeHandles(vtkPoints *points)
Convenience method to allocate and set the handles from a vtkPoints instance.
vtkPlaneSource * PlaneSource
void ProjectPointsToObliquePlane()
~vtkBrokenLineWidget() override
void SetPlaneSource(vtkPlaneSource *plane)
Set up a reference to a vtkPlaneSource that could be from another widget object, e....
void SetProjectionPosition(double position)
Set the position of broken line handles and points in terms of a plane's position.
void GetPolyData(vtkPolyData *pd)
Grab the polydata (including points) that defines the broken line.
void GetHandlePosition(int handle, double xyz[3])
Set/Get the position of the broken line handles.
virtual void SetSelectedHandleProperty(vtkProperty *)
Set/Get the handle properties (the spheres are the handles).
void Spin(double *p1, double *p2, double *vpn)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetEnabled(int) override
Methods that satisfy the superclass' API.
void Translate(double *p1, double *p2)
vtkLineSource * LineSource
void CreateDefaultProperties()
void SetHandlePosition(int handle, double xyz[3])
Set/Get the position of the broken line handles.
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
void HighlightLine(int highlight)
void PlaceWidget(double bounds[6]) override
Methods that satisfy the superclass' API.
virtual void SetNumberOfHandles(int npts)
Set/Get the number of handles for this widget.
void Scale(double *p1, double *p2, int X, int Y)
void ProjectPointsToOrthoPlane()
void PlaceWidget() override
Methods that satisfy the superclass' API.
vtkCellPicker * HandlePicker
virtual void SetLineProperty(vtkProperty *)
Set/Get the line properties.
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Methods that satisfy the superclass' API.
void MovePoint(double *p1, double *p2)
void SizeHandles() override
vtkCellPicker * LinePicker
static vtkBrokenLineWidget * New()
Instantiate the object.
vtkProperty * SelectedHandleProperty
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:91
a simple class to control print indentation
Definition: vtkIndent.h:108
create a line defined by two end points
abstract base class for most VTK objects
Definition: vtkObject.h:161
create an array of quadrilaterals located in a plane
represent and manipulate 3D points
Definition: vtkPoints.h:138
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:180
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:65
represent surface properties of a geometric object
Definition: vtkProperty.h:166
create a polygonal sphere centered at the origin
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:159
@ points
Definition: vtkX3D.h:446
@ position
Definition: vtkX3D.h:261
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_PROJECTION_YZ
#define VTK_PROJECTION_OBLIQUE