VTK  9.3.1
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:
106  static vtkBrokenLineWidget* New();
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 
143  void SetPlaneSource(vtkPlaneSource* plane);
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 
160  void SetProjectionPosition(double position);
161  vtkGetMacro(ProjectionPosition, double);
163 
171  void GetPolyData(vtkPolyData* pd);
172 
174 
178  virtual void SetHandleProperty(vtkProperty*);
179  vtkGetObjectMacro(HandleProperty, vtkProperty);
180  virtual void SetSelectedHandleProperty(vtkProperty*);
181  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
183 
185 
189  virtual void SetLineProperty(vtkProperty*);
190  vtkGetObjectMacro(LineProperty, vtkProperty);
191  virtual void SetSelectedLineProperty(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 
223  void InitializeHandles(vtkPoints* points);
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:
246  ~vtkBrokenLineWidget() override;
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.
266  void OnLeftButtonDown();
267  void OnLeftButtonUp();
268  void OnMiddleButtonDown();
269  void OnMiddleButtonUp();
270  void OnRightButtonDown();
271  void OnRightButtonUp();
272  void OnMouseMove();
273 
274  // Controlling vars
279 
280  // Projection capabilities
281  void ProjectPointsToPlane();
282  void ProjectPointsToOrthoPlane();
283  void ProjectPointsToObliquePlane();
284 
285  // The broken line
289  void HighlightLine(int highlight);
291  void BuildRepresentation();
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.
326  void CreateDefaultProperties();
327 
328  // For efficient spinning
329  double Centroid[3];
330  void CalculateCentroid();
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
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:40
3D widget for manipulating a broken line
abstract base class for most VTK objects
Definition: vtkObject.h:51
represent surface properties of a geometric object
Definition: vtkProperty.h:56
vtkProperty * SelectedHandleProperty
vtkCellPicker * HandlePicker
vtkPolyDataMapper * LineMapper
virtual void SetEnabled(int)
Methods for turning the interactor observer on and off, and determining its state.
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 PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkSphereSource ** HandleGeometry
#define VTK_PROJECTION_YZ
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
int vtkTypeBool
Definition: vtkABI.h:64
create a polygonal sphere centered at the origin
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkProperty * HandleProperty
vtkProperty * SelectedLineProperty
void PlaceWidget() override
Methods that satisfy the superclass' API.
create an array of quadrilaterals located in a plane
create a line defined by two end points
Definition: vtkLineSource.h:52
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Methods that satisfy the superclass' API.
map vtkPolyData to graphics primitives
vtkCellPicker * LinePicker
vtkPlaneSource * PlaneSource
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:61
vtkLineSource * LineSource
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
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
#define VTK_PROJECTION_OBLIQUE