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 =========================================================================*/
70 #ifndef vtkLineWidget_h
71 #define vtkLineWidget_h
72 
73 #include "vtk3DWidget.h"
74 #include "vtkInteractionWidgetsModule.h" // For export macro
75 #include "vtkLineSource.h" // For passing calls to it
76 
77 class vtkActor;
78 class vtkPolyDataMapper;
79 class vtkPoints;
80 class vtkPolyData;
81 class vtkProp;
82 class vtkProperty;
83 class vtkSphereSource;
84 class vtkCellPicker;
85 class vtkPointWidget;
86 class vtkPWCallback;
87 class vtkPW1Callback;
88 class vtkPW2Callback;
89 
90 class VTKINTERACTIONWIDGETS_EXPORT vtkLineWidget : public vtk3DWidget
91 {
92 public:
96  static vtkLineWidget* New();
97 
98  vtkTypeMacro(vtkLineWidget, vtk3DWidget);
99  void PrintSelf(ostream& os, vtkIndent indent) override;
100 
102 
105  void SetEnabled(int) override;
106  void PlaceWidget(double bounds[6]) override;
107  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
109  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
110  {
111  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
112  }
114 
118  void SetResolution(int r) { this->LineSource->SetResolution(r); }
119  int GetResolution() { return this->LineSource->GetResolution(); }
120 
124  void SetPoint1(double x, double y, double z);
125  void SetPoint1(double x[3]) { this->SetPoint1(x[0], x[1], x[2]); }
126  double* GetPoint1() VTK_SIZEHINT(3) { return this->LineSource->GetPoint1(); }
127  void GetPoint1(double xyz[3]) { this->LineSource->GetPoint1(xyz); }
128 
132  void SetPoint2(double x, double y, double z);
133  void SetPoint2(double x[3]) { this->SetPoint2(x[0], x[1], x[2]); }
134  double* GetPoint2() VTK_SIZEHINT(3) { return this->LineSource->GetPoint2(); }
135  void GetPoint2(double xyz[3]) { this->LineSource->GetPoint2(xyz); }
136 
138 
144  vtkSetClampMacro(Align, int, XAxis, None);
145  vtkGetMacro(Align, int);
146  void SetAlignToXAxis() { this->SetAlign(XAxis); }
147  void SetAlignToYAxis() { this->SetAlign(YAxis); }
148  void SetAlignToZAxis() { this->SetAlign(ZAxis); }
149  void SetAlignToNone() { this->SetAlign(None); }
151 
153 
159  vtkSetMacro(ClampToBounds, vtkTypeBool);
160  vtkGetMacro(ClampToBounds, vtkTypeBool);
161  vtkBooleanMacro(ClampToBounds, vtkTypeBool);
163 
171  void GetPolyData(vtkPolyData* pd);
172 
174 
179  vtkGetObjectMacro(HandleProperty, vtkProperty);
180  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
182 
184 
188  vtkGetObjectMacro(LineProperty, vtkProperty);
189  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
191 
192 protected:
193  vtkLineWidget();
194  ~vtkLineWidget() override;
195 
196  // Manage the state of the widget
197  friend class vtkPWCallback;
198 
199  int State;
201  {
202  Start = 0,
206  Outside
207  };
208 
209  // handles the events
210  static void ProcessEvents(
211  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
212 
213  // ProcessEvents() dispatches to these methods.
214  void OnLeftButtonDown();
215  void OnLeftButtonUp();
216  void OnMiddleButtonDown();
217  void OnMiddleButtonUp();
218  void OnRightButtonDown();
219  void OnRightButtonUp();
220  virtual void OnMouseMove();
221 
222  // controlling ivars
223  int Align;
224 
226  {
230  None
231  };
232 
233  // the line
237  void HighlightLine(int highlight);
238 
239  // glyphs representing hot spots (e.g., handles)
243 
244  void BuildRepresentation();
245  void SizeHandles() override;
246  void HandlesOn(double length);
247  void HandlesOff();
248  int HighlightHandle(vtkProp* prop); // returns cell id
249  void HighlightHandles(int highlight);
250 
251  // Do the picking
255  double LastPosition[3];
256  void SetLinePosition(double x[3]);
257 
258  // Register internal Pickers within PickingManager
259  void RegisterPickers() override;
260 
261  // Methods to manipulate the hexahedron.
262  void Scale(double* p1, double* p2, int X, int Y);
263 
264  // Initial bounds
266  void ClampPosition(double x[3]);
267  int InBounds(double x[3]);
268 
269  // Properties used to control the appearance of selected objects and
270  // the manipulator in general.
275  void CreateDefaultProperties();
276 
277  void GenerateLine();
278 
279  // Methods for managing the point widgets used to control the endpoints
283  vtkPWCallback* PWCallback;
284  vtkPW1Callback* PW1Callback;
285  vtkPW2Callback* PW2Callback;
287  void EnablePointWidget();
288  void DisablePointWidget();
289  int ForwardEvent(unsigned long event);
290 
291 private:
292  vtkLineWidget(const vtkLineWidget&) = delete;
293  void operator=(const vtkLineWidget&) = delete;
294 };
295 
296 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:50
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:56
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:90
#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