VTK
vtkLineWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkLineWidget.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 =========================================================================*/
67 #ifndef vtkLineWidget_h
68 #define vtkLineWidget_h
69 
70 #include "vtkInteractionWidgetsModule.h" // For export macro
71 #include "vtk3DWidget.h"
72 #include "vtkLineSource.h" // For passing calls to it
73 
74 class vtkActor;
75 class vtkPolyDataMapper;
76 class vtkPoints;
77 class vtkPolyData;
78 class vtkProp;
79 class vtkProperty;
80 class vtkSphereSource;
81 class vtkCellPicker;
82 class vtkPointWidget;
83 class vtkPWCallback;
84 class vtkPW1Callback;
85 class vtkPW2Callback;
86 
87 class VTKINTERACTIONWIDGETS_EXPORT vtkLineWidget : public vtk3DWidget
88 {
89 public:
93  static vtkLineWidget *New();
94 
95  vtkTypeMacro(vtkLineWidget,vtk3DWidget);
96  void PrintSelf(ostream& os, vtkIndent indent) override;
97 
99 
102  void SetEnabled(int) override;
103  void PlaceWidget(double bounds[6]) override;
104  void PlaceWidget() override
105  {this->Superclass::PlaceWidget();}
106  void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
107  double zmin, double zmax) override
108  {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
110 
114  void SetResolution(int r)
115  { this->LineSource->SetResolution(r); }
117  { return this->LineSource->GetResolution(); }
118 
122  void SetPoint1(double x, double y, double z);
123  void SetPoint1(double x[3])
124  {this->SetPoint1(x[0], x[1], x[2]); }
125  double* GetPoint1() VTK_SIZEHINT(3)
126  {return this->LineSource->GetPoint1();}
127  void GetPoint1(double xyz[3])
128  {this->LineSource->GetPoint1(xyz);}
129 
133  void SetPoint2(double x, double y, double z);
134  void SetPoint2(double x[3])
135  {this->SetPoint2(x[0], x[1], x[2]);}
136  double* GetPoint2() VTK_SIZEHINT(3)
137  {return this->LineSource->GetPoint2();}
138  void GetPoint2(double xyz[3])
139  {this->LineSource->GetPoint2(xyz);}
140 
142 
148  vtkSetClampMacro(Align, int, XAxis, None);
149  vtkGetMacro(Align, int);
150  void SetAlignToXAxis() { this->SetAlign(XAxis); }
151  void SetAlignToYAxis() { this->SetAlign(YAxis); }
152  void SetAlignToZAxis() { this->SetAlign(ZAxis); }
153  void SetAlignToNone() { this->SetAlign(None); }
155 
157 
163  vtkSetMacro(ClampToBounds,vtkTypeBool);
164  vtkGetMacro(ClampToBounds,vtkTypeBool);
165  vtkBooleanMacro(ClampToBounds,vtkTypeBool);
167 
175  void GetPolyData(vtkPolyData *pd);
176 
178 
183  vtkGetObjectMacro(HandleProperty,vtkProperty);
184  vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
186 
188 
192  vtkGetObjectMacro(LineProperty,vtkProperty);
193  vtkGetObjectMacro(SelectedLineProperty,vtkProperty);
195 
196 protected:
197  vtkLineWidget();
198  ~vtkLineWidget() override;
199 
200  // Manage the state of the widget
201  friend class vtkPWCallback;
202 
203  int State;
205  {
206  Start=0,
210  Outside
211  };
212 
213  //handles the events
214  static void ProcessEvents(vtkObject* object,
215  unsigned long event,
216  void* clientdata,
217  void* calldata);
218 
219  // ProcessEvents() dispatches to these methods.
220  void OnLeftButtonDown();
221  void OnLeftButtonUp();
222  void OnMiddleButtonDown();
223  void OnMiddleButtonUp();
224  void OnRightButtonDown();
225  void OnRightButtonUp();
226  virtual void OnMouseMove();
227 
228  // controlling ivars
229  int Align;
230 
235  None
236  };
237 
238  // the line
242  void HighlightLine(int highlight);
243 
244  // glyphs representing hot spots (e.g., handles)
248 
249  void BuildRepresentation();
250  void SizeHandles() override;
251  void HandlesOn(double length);
252  void HandlesOff();
253  int HighlightHandle(vtkProp *prop); //returns cell id
254  void HighlightHandles(int highlight);
255 
256  // Do the picking
260  double LastPosition[3];
261  void SetLinePosition(double x[3]);
262 
263  // Register internal Pickers within PickingManager
264  void RegisterPickers() override;
265 
266  // Methods to manipulate the hexahedron.
267  void Scale(double *p1, double *p2, int X, int Y);
268 
269  // Initial bounds
271  void ClampPosition(double x[3]);
272  int InBounds(double x[3]);
273 
274  // Properties used to control the appearance of selected objects and
275  // the manipulator in general.
280  void CreateDefaultProperties();
281 
282  void GenerateLine();
283 
284  // Methods for managing the point widgets used to control the endpoints
288  vtkPWCallback *PWCallback;
289  vtkPW1Callback *PW1Callback;
290  vtkPW2Callback *PW2Callback;
292  void EnablePointWidget();
293  void DisablePointWidget();
294  int ForwardEvent(unsigned long event);
295 
296 private:
297  vtkLineWidget(const vtkLineWidget&) = delete;
298  void operator=(const vtkLineWidget&) = delete;
299 };
300 
301 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:46
double * GetPoint1()
vtkProperty * LineProperty
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:45
abstract base class for most VTK objects
Definition: vtkObject.h:53
void SetAlignToZAxis()
Force the line widget to be aligned with one of the x-y-z axes.
represent surface properties of a geometric object
Definition: vtkProperty.h:60
vtkLineSource * LineSource
vtkProperty * SelectedLineProperty
vtkActor * LineActor
static void ProcessEvents(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
Handles the char widget activation event.
virtual void SetEnabled(int)
Methods for turning the interactor observer on and off, and determining its state.
void GetPoint2(double xyz[3])
vtkPointWidget * PointWidget
vtkPWCallback * PWCallback
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
void SetAlignToXAxis()
Force the line widget to be aligned with one of the x-y-z axes.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPW2Callback * PW2Callback
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
int vtkTypeBool
Definition: vtkABI.h:69
create a polygonal sphere centered at the origin
void PlaceWidget() override
Methods that satisfy the superclass' API.
vtkPointWidget * PointWidget2
void GetPoint1(double xyz[3])
vtkPointWidget * PointWidget1
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkPW1Callback * PW1Callback
void SetPoint2(double x[3])
void SetAlignToYAxis()
Force the line widget to be aligned with one of the x-y-z axes.
vtkProperty * SelectedHandleProperty
3D widget for manipulating a line
Definition: vtkLineWidget.h:87
#define VTK_SIZEHINT(...)
void SetAlignToNone()
Force the line widget to be aligned with one of the x-y-z axes.
vtkPolyDataMapper ** HandleMapper
vtkActor * CurrentHandle
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Methods that satisfy the superclass' API.
create a line defined by two end points
Definition: vtkLineSource.h:36
map vtkPolyData to graphics primitives
position a point in 3D space
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:63
void SetResolution(int r)
Set/Get the resolution (number of subdivisions) of the line.
void SetPoint1(double x[3])
double * GetPoint2()
vtkCellPicker * LinePicker
vtkActor ** Handle
vtkSphereSource ** HandleGeometry
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkPolyDataMapper * LineMapper
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:67
virtual void SizeHandles()
Definition: vtk3DWidget.h:152
virtual void PlaceWidget()
This method is used to initially place the widget.
vtkCellPicker * HandlePicker
vtkProperty * HandleProperty
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkTypeBool ClampToBounds
vtkPointWidget * CurrentPointWidget