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 =========================================================================*/
76 #ifndef vtkLineWidget_h
77 #define vtkLineWidget_h
78 
79 #include "vtk3DWidget.h"
80 #include "vtkInteractionWidgetsModule.h" // For export macro
81 #include "vtkLineSource.h" // For passing calls to it
82 
83 class vtkActor;
84 class vtkPolyDataMapper;
85 class vtkPoints;
86 class vtkPolyData;
87 class vtkProp;
88 class vtkProperty;
89 class vtkSphereSource;
90 class vtkCellPicker;
91 class vtkPointWidget;
92 class vtkPWCallback;
93 class vtkPW1Callback;
94 class vtkPW2Callback;
95 
96 class VTKINTERACTIONWIDGETS_EXPORT vtkLineWidget : public vtk3DWidget
97 {
98 public:
102  static vtkLineWidget* New();
103 
104  vtkTypeMacro(vtkLineWidget, vtk3DWidget);
105  void PrintSelf(ostream& os, vtkIndent indent) override;
106 
108 
111  void SetEnabled(int) override;
112  void PlaceWidget(double bounds[6]) override;
113  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
115  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
116  {
117  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
118  }
120 
124  void SetResolution(int r) { this->LineSource->SetResolution(r); }
125  int GetResolution() { return this->LineSource->GetResolution(); }
126 
130  void SetPoint1(double x, double y, double z);
131  void SetPoint1(double x[3]) { this->SetPoint1(x[0], x[1], x[2]); }
132  double* GetPoint1() VTK_SIZEHINT(3) { return this->LineSource->GetPoint1(); }
133  void GetPoint1(double xyz[3]) { this->LineSource->GetPoint1(xyz); }
134 
138  void SetPoint2(double x, double y, double z);
139  void SetPoint2(double x[3]) { this->SetPoint2(x[0], x[1], x[2]); }
140  double* GetPoint2() VTK_SIZEHINT(3) { return this->LineSource->GetPoint2(); }
141  void GetPoint2(double xyz[3]) { this->LineSource->GetPoint2(xyz); }
142 
144 
150  vtkSetClampMacro(Align, int, XAxis, None);
151  vtkGetMacro(Align, int);
152  void SetAlignToXAxis() { this->SetAlign(XAxis); }
153  void SetAlignToYAxis() { this->SetAlign(YAxis); }
154  void SetAlignToZAxis() { this->SetAlign(ZAxis); }
155  void SetAlignToNone() { this->SetAlign(None); }
157 
159 
165  vtkSetMacro(ClampToBounds, vtkTypeBool);
166  vtkGetMacro(ClampToBounds, vtkTypeBool);
167  vtkBooleanMacro(ClampToBounds, vtkTypeBool);
169 
177  void GetPolyData(vtkPolyData* pd);
178 
180 
185  vtkGetObjectMacro(HandleProperty, vtkProperty);
186  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
188 
190 
194  vtkGetObjectMacro(LineProperty, vtkProperty);
195  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
197 
198 protected:
199  vtkLineWidget();
200  ~vtkLineWidget() override;
201 
202  // Manage the state of the widget
203  friend class vtkPWCallback;
204 
205  int State;
207  {
208  Start = 0,
212  Outside
213  };
214 
215  // handles the events
216  static void ProcessEvents(
217  vtkObject* object, unsigned long event, void* clientdata, 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 
232  {
236  None
237  };
238 
239  // the line
243  void HighlightLine(int highlight);
244 
245  // glyphs representing hot spots (e.g., handles)
249 
250  void BuildRepresentation();
251  void SizeHandles() override;
252  void HandlesOn(double length);
253  void HandlesOff();
254  int HighlightHandle(vtkProp* prop); // returns cell id
255  void HighlightHandles(int highlight);
256 
257  // Do the picking
261  double LastPosition[3];
262  void SetLinePosition(double x[3]);
263 
264  // Register internal Pickers within PickingManager
265  void RegisterPickers() override;
266 
267  // Methods to manipulate the hexahedron.
268  void Scale(double* p1, double* p2, int X, int Y);
269 
270  // Initial bounds
272  void ClampPosition(double x[3]);
273  int InBounds(double x[3]);
274 
275  // Properties used to control the appearance of selected objects and
276  // the manipulator in general.
281  void CreateDefaultProperties();
282 
283  void GenerateLine();
284 
285  // Methods for managing the point widgets used to control the endpoints
289  vtkPWCallback* PWCallback;
290  vtkPW1Callback* PW1Callback;
291  vtkPW2Callback* PW2Callback;
293  void EnablePointWidget();
294  void DisablePointWidget();
295  int ForwardEvent(unsigned long event);
296 
297 private:
298  vtkLineWidget(const vtkLineWidget&) = delete;
299  void operator=(const vtkLineWidget&) = delete;
300 };
301 
302 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:53
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:62
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:96
#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:70
virtual void SizeHandles()
Definition: vtk3DWidget.h:155
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