VTK  9.0.1
vtkBrokenLineWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkBrokenLineWidget.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 =========================================================================*/
85 #ifndef vtkBrokenLineWidget_h
86 #define vtkBrokenLineWidget_h
87 
88 #include "vtk3DWidget.h"
89 #include "vtkInteractionWidgetsModule.h" // For export macro
90 
91 class vtkActor;
92 class vtkCellPicker;
93 class vtkLineSource;
94 class vtkPlaneSource;
95 class vtkPoints;
96 class vtkPolyData;
97 class vtkPolyDataMapper;
98 class vtkProp;
99 class vtkProperty;
100 class vtkSphereSource;
101 class vtkTransform;
102 
103 #define VTK_PROJECTION_YZ 0
104 #define VTK_PROJECTION_XZ 1
105 #define VTK_PROJECTION_XY 2
106 #define VTK_PROJECTION_OBLIQUE 3
107 
108 class VTKINTERACTIONWIDGETS_EXPORT vtkBrokenLineWidget : public vtk3DWidget
109 {
110 public:
114  static vtkBrokenLineWidget* New();
115 
117  void PrintSelf(ostream& os, vtkIndent indent) override;
118 
120 
123  void SetEnabled(int) override;
124  void PlaceWidget(double bounds[6]) override;
125  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
127  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
128  {
129  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
130  }
132 
134 
142  vtkSetMacro(ProjectToPlane, vtkTypeBool);
143  vtkGetMacro(ProjectToPlane, vtkTypeBool);
144  vtkBooleanMacro(ProjectToPlane, vtkTypeBool);
146 
151  void SetPlaneSource(vtkPlaneSource* plane);
152 
153  vtkSetClampMacro(ProjectionNormal, int, VTK_PROJECTION_YZ, VTK_PROJECTION_OBLIQUE);
154  vtkGetMacro(ProjectionNormal, int);
155  void SetProjectionNormalToXAxes() { this->SetProjectionNormal(0); }
156  void SetProjectionNormalToYAxes() { this->SetProjectionNormal(1); }
157  void SetProjectionNormalToZAxes() { this->SetProjectionNormal(2); }
158  void SetProjectionNormalToOblique() { this->SetProjectionNormal(3); }
159 
161 
168  void SetProjectionPosition(double position);
169  vtkGetMacro(ProjectionPosition, double);
171 
179  void GetPolyData(vtkPolyData* pd);
180 
182 
186  virtual void SetHandleProperty(vtkProperty*);
187  vtkGetObjectMacro(HandleProperty, vtkProperty);
188  virtual void SetSelectedHandleProperty(vtkProperty*);
189  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
191 
193 
197  virtual void SetLineProperty(vtkProperty*);
198  vtkGetObjectMacro(LineProperty, vtkProperty);
199  virtual void SetSelectedLineProperty(vtkProperty*);
200  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
202 
204 
207  virtual void SetNumberOfHandles(int npts);
208  vtkGetMacro(NumberOfHandles, int);
210 
212 
216  void SetHandlePosition(int handle, double x, double y, double z);
217  void SetHandlePosition(int handle, double xyz[3]);
218  void GetHandlePosition(int handle, double xyz[3]);
219  double* GetHandlePosition(int handle);
221 
225  double GetSummedLength();
226 
231  void InitializeHandles(vtkPoints* points);
232 
234 
238  vtkSetClampMacro(ProcessEvents, vtkTypeBool, 0, 1);
239  vtkGetMacro(ProcessEvents, vtkTypeBool);
240  vtkBooleanMacro(ProcessEvents, vtkTypeBool);
242 
244 
248  vtkSetClampMacro(HandleSizeFactor, double, 0., 100.);
249  vtkGetMacro(HandleSizeFactor, double);
251 
252 protected:
254  ~vtkBrokenLineWidget() override;
255 
256  // Manage the state of the widget
257  int State;
259  {
260  Start = 0,
266  Outside
267  };
268 
269  // handles the events
270  static void ProcessEventsHandler(
271  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
272 
273  // ProcessEventsHandler() dispatches to these methods.
274  void OnLeftButtonDown();
275  void OnLeftButtonUp();
276  void OnMiddleButtonDown();
277  void OnMiddleButtonUp();
278  void OnRightButtonDown();
279  void OnRightButtonUp();
280  void OnMouseMove();
281 
282  // Controlling vars
287 
288  // Projection capabilities
289  void ProjectPointsToPlane();
290  void ProjectPointsToOrthoPlane();
291  void ProjectPointsToObliquePlane();
292 
293  // The broken line
297  void HighlightLine(int highlight);
299  void BuildRepresentation();
300 
301  // Glyphs representing hot spots (e.g., handles)
304  void Initialize();
305  int HighlightHandle(vtkProp* prop); // returns handle index or -1 on fail
306  void SizeHandles() override;
307  void InsertHandleOnLine(double* pos);
308  void EraseHandle(const int&);
309 
310  // Do the picking
315 
316  // Register internal Pickers within PickingManager
317  void RegisterPickers() override;
318 
319  // Methods to manipulate the broken line.
320  void MovePoint(double* p1, double* p2);
321  void Scale(double* p1, double* p2, int X, int Y);
322  void Translate(double* p1, double* p2);
323  void Spin(double* p1, double* p2, double* vpn);
324 
325  // Transform the control points (used for spinning)
327 
328  // Properties used to control the appearance of selected objects and
329  // the manipulator in general.
334  void CreateDefaultProperties();
335 
336  // For efficient spinning
337  double Centroid[3];
338  void CalculateCentroid();
340 
341  // Handle sizing factor
343 
344 private:
345  vtkBrokenLineWidget(const vtkBrokenLineWidget&) = delete;
346  void operator=(const vtkBrokenLineWidget&) = delete;
347 };
348 
349 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:50
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:45
3D widget for manipulating a broken line
abstract base class for most VTK objects
Definition: vtkObject.h:56
represent surface properties of a geometric object
Definition: vtkProperty.h:61
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:54
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
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:69
create a polygonal sphere centered at the origin
a simple class to control print indentation
Definition: vtkIndent.h:33
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:60
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:66
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:70
virtual void SizeHandles()
Definition: vtk3DWidget.h:155
virtual void PlaceWidget()
This method is used to initially place the widget.
represent and manipulate 3D points
Definition: vtkPoints.h:33
#define VTK_PROJECTION_OBLIQUE