VTK
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 "vtkInteractionWidgetsModule.h" // For export macro
89 #include "vtk3DWidget.h"
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
126  {this->Superclass::PlaceWidget();}
127  void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
128  double zmin, double zmax) override
129  {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
131 
133 
141  vtkSetMacro(ProjectToPlane,vtkTypeBool);
142  vtkGetMacro(ProjectToPlane,vtkTypeBool);
143  vtkBooleanMacro(ProjectToPlane,vtkTypeBool);
145 
150  void SetPlaneSource(vtkPlaneSource* plane);
151 
152  vtkSetClampMacro(ProjectionNormal,int,VTK_PROJECTION_YZ,VTK_PROJECTION_OBLIQUE);
153  vtkGetMacro(ProjectionNormal,int);
155  { this->SetProjectionNormal(0); }
157  { this->SetProjectionNormal(1); }
159  { this->SetProjectionNormal(2); }
161  { this->SetProjectionNormal(3); }
162 
164 
171  void SetProjectionPosition(double position);
172  vtkGetMacro(ProjectionPosition, double);
174 
182  void GetPolyData(vtkPolyData *pd);
183 
185 
189  virtual void SetHandleProperty(vtkProperty*);
190  vtkGetObjectMacro(HandleProperty, vtkProperty);
191  virtual void SetSelectedHandleProperty(vtkProperty*);
192  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
194 
196 
200  virtual void SetLineProperty(vtkProperty*);
201  vtkGetObjectMacro(LineProperty, vtkProperty);
202  virtual void SetSelectedLineProperty(vtkProperty*);
203  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
205 
207 
210  virtual void SetNumberOfHandles(int npts);
211  vtkGetMacro(NumberOfHandles, int);
213 
215 
219  void SetHandlePosition(int handle, double x, double y, double z);
220  void SetHandlePosition(int handle, double xyz[3]);
221  void GetHandlePosition(int handle, double xyz[3]);
222  double* GetHandlePosition(int handle);
224 
228  double GetSummedLength();
229 
234  void InitializeHandles(vtkPoints* points);
235 
237 
241  vtkSetClampMacro(ProcessEvents, vtkTypeBool, 0, 1);
242  vtkGetMacro(ProcessEvents, vtkTypeBool);
243  vtkBooleanMacro( ProcessEvents, vtkTypeBool );
245 
247 
251  vtkSetClampMacro(HandleSizeFactor, double, 0., 100.);
252  vtkGetMacro(HandleSizeFactor, double);
254 
255 protected:
257  ~vtkBrokenLineWidget() override;
258 
259  // Manage the state of the widget
260  int State;
262  {
263  Start=0,
269  Outside
270  };
271 
272  //handles the events
273  static void ProcessEventsHandler(vtkObject* object,
274  unsigned long event,
275  void* clientdata,
276  void* calldata);
277 
278  // ProcessEventsHandler() dispatches to these methods.
279  void OnLeftButtonDown();
280  void OnLeftButtonUp();
281  void OnMiddleButtonDown();
282  void OnMiddleButtonUp();
283  void OnRightButtonDown();
284  void OnRightButtonUp();
285  void OnMouseMove();
286 
287  // Controlling vars
292 
293  // Projection capabilities
294  void ProjectPointsToPlane();
295  void ProjectPointsToOrthoPlane();
296  void ProjectPointsToObliquePlane();
297 
298  // The broken line
302  void HighlightLine(int highlight);
304  void BuildRepresentation();
305 
306  // Glyphs representing hot spots (e.g., handles)
309  void Initialize();
310  int HighlightHandle(vtkProp *prop); //returns handle index or -1 on fail
311  void SizeHandles() override;
312  void InsertHandleOnLine(double* pos);
313  void EraseHandle(const int&);
314 
315  // Do the picking
320 
321  // Register internal Pickers within PickingManager
322  void RegisterPickers() override;
323 
324  // Methods to manipulate the broken line.
325  void MovePoint(double *p1, double *p2);
326  void Scale(double *p1, double *p2, int X, int Y);
327  void Translate(double *p1, double *p2);
328  void Spin(double *p1, double *p2, double *vpn);
329 
330  // Transform the control points (used for spinning)
332 
333  // Properties used to control the appearance of selected objects and
334  // the manipulator in general.
339  void CreateDefaultProperties();
340 
341  // For efficient spinning
342  double Centroid[3];
343  void CalculateCentroid();
345 
346  // Handle sizing factor
348 
349 private:
350  vtkBrokenLineWidget(const vtkBrokenLineWidget&) = delete;
351  void operator=(const vtkBrokenLineWidget&) = delete;
352 };
353 
354 #endif
vtkPolyDataMapper
map vtkPolyData to graphics primitives
Definition: vtkPolyDataMapper.h:42
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:39
vtkBrokenLineWidget
3D widget for manipulating a broken line
Definition: vtkBrokenLineWidget.h:108
vtkBrokenLineWidget::ProjectToPlane
vtkTypeBool ProjectToPlane
Definition: vtkBrokenLineWidget.h:290
VTK_PROJECTION_OBLIQUE
#define VTK_PROJECTION_OBLIQUE
Definition: vtkBrokenLineWidget.h:106
vtkBrokenLineWidget::NumberOfHandles
int NumberOfHandles
Definition: vtkBrokenLineWidget.h:303
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkPlaneSource
create an array of quadrilaterals located in a plane
Definition: vtkPlaneSource.h:60
vtkBrokenLineWidget::LineActor
vtkActor * LineActor
Definition: vtkBrokenLineWidget.h:299
VTK_PROJECTION_YZ
#define VTK_PROJECTION_YZ
Definition: vtkBrokenLineWidget.h:103
vtkBrokenLineWidget::State
int State
Definition: vtkBrokenLineWidget.h:260
vtkBrokenLineWidget::HandleProperty
vtkProperty * HandleProperty
Definition: vtkBrokenLineWidget.h:335
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkBrokenLineWidget::Transform
vtkTransform * Transform
Definition: vtkBrokenLineWidget.h:331
vtk3DWidget::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
vtkBrokenLineWidget::HandleSizeFactor
double HandleSizeFactor
Definition: vtkBrokenLineWidget.h:347
vtkBrokenLineWidget::SelectedLineProperty
vtkProperty * SelectedLineProperty
Definition: vtkBrokenLineWidget.h:338
vtkX3D::position
Definition: vtkX3D.h:261
vtkX3D::points
Definition: vtkX3D.h:446
vtkBrokenLineWidget::HandlePicker
vtkCellPicker * HandlePicker
Definition: vtkBrokenLineWidget.h:316
vtkBrokenLineWidget::LineProperty
vtkProperty * LineProperty
Definition: vtkBrokenLineWidget.h:337
vtkSphereSource
create a polygonal sphere centered at the origin
Definition: vtkSphereSource.h:46
vtkActor
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:51
vtkInteractorObserver::SetEnabled
virtual void SetEnabled(int)
Methods for turning the interactor observer on and off, and determining its state.
Definition: vtkInteractorObserver.h:73
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkBrokenLineWidget::LinePicker
vtkCellPicker * LinePicker
Definition: vtkBrokenLineWidget.h:317
vtkBrokenLineWidget::LineSource
vtkLineSource * LineSource
Definition: vtkBrokenLineWidget.h:301
vtkBrokenLineWidget::SelectedHandleProperty
vtkProperty * SelectedHandleProperty
Definition: vtkBrokenLineWidget.h:336
vtk3DWidget
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:67
vtkBrokenLineWidget::Spinning
Definition: vtkBrokenLineWidget.h:266
vtkBrokenLineWidget::LineMapper
vtkPolyDataMapper * LineMapper
Definition: vtkBrokenLineWidget.h:300
vtkBrokenLineWidget::SetProjectionNormalToOblique
void SetProjectionNormalToOblique()
Definition: vtkBrokenLineWidget.h:160
vtkLineSource
create a line defined by two end points
Definition: vtkLineSource.h:42
vtkBrokenLineWidget::SetProjectionNormalToXAxes
void SetProjectionNormalToXAxes()
Definition: vtkBrokenLineWidget.h:154
vtkBrokenLineWidget::CurrentHandle
vtkActor * CurrentHandle
Definition: vtkBrokenLineWidget.h:318
vtkBrokenLineWidget::Inserting
Definition: vtkBrokenLineWidget.h:267
vtkInteractorObserver::RegisterPickers
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:52
vtkBrokenLineWidget::Moving
Definition: vtkBrokenLineWidget.h:264
vtkBrokenLineWidget::ProjectionNormal
int ProjectionNormal
Definition: vtkBrokenLineWidget.h:288
vtk3DWidget::SizeHandles
virtual void SizeHandles()
Definition: vtk3DWidget.h:152
vtkBrokenLineWidget::PlaceWidget
void PlaceWidget() override
Definition: vtkBrokenLineWidget.h:125
vtk3DWidget::PlaceWidget
virtual void PlaceWidget()
vtkBrokenLineWidget::Scaling
Definition: vtkBrokenLineWidget.h:265
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkBrokenLineWidget::SetProjectionNormalToZAxes
void SetProjectionNormalToZAxes()
Definition: vtkBrokenLineWidget.h:158
vtkBrokenLineWidget::Handle
vtkActor ** Handle
Definition: vtkBrokenLineWidget.h:307
vtk3DWidget.h
vtkProperty
represent surface properties of a geometric object
Definition: vtkProperty.h:66
vtkBrokenLineWidget::ProcessEvents
vtkTypeBool ProcessEvents
Definition: vtkBrokenLineWidget.h:344
vtkBrokenLineWidget::PlaneSource
vtkPlaneSource * PlaneSource
Definition: vtkBrokenLineWidget.h:291
vtkCellPicker
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:69
vtkBrokenLineWidget::PlaceWidget
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Definition: vtkBrokenLineWidget.h:127
vtkBrokenLineWidget::Erasing
Definition: vtkBrokenLineWidget.h:268
vtkBrokenLineWidget::HandleGeometry
vtkSphereSource ** HandleGeometry
Definition: vtkBrokenLineWidget.h:308
vtkBrokenLineWidget::WidgetState
WidgetState
Definition: vtkBrokenLineWidget.h:261
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkBrokenLineWidget::ProjectionPosition
double ProjectionPosition
Definition: vtkBrokenLineWidget.h:289
vtkBrokenLineWidget::SetProjectionNormalToYAxes
void SetProjectionNormalToYAxes()
Definition: vtkBrokenLineWidget.h:156
vtkBrokenLineWidget::CurrentHandleIndex
int CurrentHandleIndex
Definition: vtkBrokenLineWidget.h:319