VTK  9.0.1
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 "vtk3DWidget.h"
71 #include "vtkInteractionWidgetsModule.h" // For export macro
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 { this->Superclass::PlaceWidget(); }
106  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
107  {
108  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
109  }
111 
115  void SetResolution(int r) { this->LineSource->SetResolution(r); }
116  int GetResolution() { return this->LineSource->GetResolution(); }
117 
121  void SetPoint1(double x, double y, double z);
122  void SetPoint1(double x[3]) { this->SetPoint1(x[0], x[1], x[2]); }
123  double* GetPoint1() VTK_SIZEHINT(3) { return this->LineSource->GetPoint1(); }
124  void GetPoint1(double xyz[3]) { this->LineSource->GetPoint1(xyz); }
125 
129  void SetPoint2(double x, double y, double z);
130  void SetPoint2(double x[3]) { this->SetPoint2(x[0], x[1], x[2]); }
131  double* GetPoint2() VTK_SIZEHINT(3) { return this->LineSource->GetPoint2(); }
132  void GetPoint2(double xyz[3]) { this->LineSource->GetPoint2(xyz); }
133 
135 
141  vtkSetClampMacro(Align, int, XAxis, None);
142  vtkGetMacro(Align, int);
143  void SetAlignToXAxis() { this->SetAlign(XAxis); }
144  void SetAlignToYAxis() { this->SetAlign(YAxis); }
145  void SetAlignToZAxis() { this->SetAlign(ZAxis); }
146  void SetAlignToNone() { this->SetAlign(None); }
148 
150 
156  vtkSetMacro(ClampToBounds, vtkTypeBool);
157  vtkGetMacro(ClampToBounds, vtkTypeBool);
158  vtkBooleanMacro(ClampToBounds, vtkTypeBool);
160 
168  void GetPolyData(vtkPolyData* pd);
169 
171 
176  vtkGetObjectMacro(HandleProperty, vtkProperty);
177  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
179 
181 
185  vtkGetObjectMacro(LineProperty, vtkProperty);
186  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
188 
189 protected:
190  vtkLineWidget();
191  ~vtkLineWidget() override;
192 
193  // Manage the state of the widget
194  friend class vtkPWCallback;
195 
196  int State;
198  {
199  Start = 0,
203  Outside
204  };
205 
206  // handles the events
207  static void ProcessEvents(
208  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
209 
210  // ProcessEvents() dispatches to these methods.
211  void OnLeftButtonDown();
212  void OnLeftButtonUp();
213  void OnMiddleButtonDown();
214  void OnMiddleButtonUp();
215  void OnRightButtonDown();
216  void OnRightButtonUp();
217  virtual void OnMouseMove();
218 
219  // controlling ivars
220  int Align;
221 
223  {
227  None
228  };
229 
230  // the line
234  void HighlightLine(int highlight);
235 
236  // glyphs representing hot spots (e.g., handles)
240 
241  void BuildRepresentation();
242  void SizeHandles() override;
243  void HandlesOn(double length);
244  void HandlesOff();
245  int HighlightHandle(vtkProp* prop); // returns cell id
246  void HighlightHandles(int highlight);
247 
248  // Do the picking
252  double LastPosition[3];
253  void SetLinePosition(double x[3]);
254 
255  // Register internal Pickers within PickingManager
256  void RegisterPickers() override;
257 
258  // Methods to manipulate the hexahedron.
259  void Scale(double* p1, double* p2, int X, int Y);
260 
261  // Initial bounds
263  void ClampPosition(double x[3]);
264  int InBounds(double x[3]);
265 
266  // Properties used to control the appearance of selected objects and
267  // the manipulator in general.
272  void CreateDefaultProperties();
273 
274  void GenerateLine();
275 
276  // Methods for managing the point widgets used to control the endpoints
280  vtkPWCallback* PWCallback;
281  vtkPW1Callback* PW1Callback;
282  vtkPW2Callback* PW2Callback;
284  void EnablePointWidget();
285  void DisablePointWidget();
286  int ForwardEvent(unsigned long event);
287 
288 private:
289  vtkLineWidget(const vtkLineWidget&) = delete;
290  void operator=(const vtkLineWidget&) = delete;
291 };
292 
293 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:47
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:61
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:84
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:60
map vtkPolyData to graphics primitives
position a point in 3D space
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:66
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