VTK  9.2.6
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 =========================================================================*/
73 #ifndef vtkLineWidget_h
74 #define vtkLineWidget_h
75 
76 #include "vtk3DWidget.h"
77 #include "vtkInteractionWidgetsModule.h" // For export macro
78 #include "vtkLineSource.h" // For passing calls to it
79 
80 class vtkActor;
81 class vtkPolyDataMapper;
82 class vtkPoints;
83 class vtkPolyData;
84 class vtkProp;
85 class vtkProperty;
86 class vtkSphereSource;
87 class vtkCellPicker;
88 class vtkPointWidget;
89 class vtkPWCallback;
90 class vtkPW1Callback;
91 class vtkPW2Callback;
92 
93 class VTKINTERACTIONWIDGETS_EXPORT vtkLineWidget : public vtk3DWidget
94 {
95 public:
99  static vtkLineWidget* New();
100 
101  vtkTypeMacro(vtkLineWidget, vtk3DWidget);
102  void PrintSelf(ostream& os, vtkIndent indent) override;
103 
105 
108  void SetEnabled(int) override;
109  void PlaceWidget(double bounds[6]) override;
110  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
112  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
113  {
114  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
115  }
117 
121  void SetResolution(int r) { this->LineSource->SetResolution(r); }
122  int GetResolution() { return this->LineSource->GetResolution(); }
123 
127  void SetPoint1(double x, double y, double z);
128  void SetPoint1(double x[3]) { this->SetPoint1(x[0], x[1], x[2]); }
129  double* GetPoint1() VTK_SIZEHINT(3) { return this->LineSource->GetPoint1(); }
130  void GetPoint1(double xyz[3]) { this->LineSource->GetPoint1(xyz); }
131 
135  void SetPoint2(double x, double y, double z);
136  void SetPoint2(double x[3]) { this->SetPoint2(x[0], x[1], x[2]); }
137  double* GetPoint2() VTK_SIZEHINT(3) { return this->LineSource->GetPoint2(); }
138  void GetPoint2(double xyz[3]) { this->LineSource->GetPoint2(xyz); }
139 
141 
147  vtkSetClampMacro(Align, int, XAxis, None);
148  vtkGetMacro(Align, int);
149  void SetAlignToXAxis() { this->SetAlign(XAxis); }
150  void SetAlignToYAxis() { this->SetAlign(YAxis); }
151  void SetAlignToZAxis() { this->SetAlign(ZAxis); }
152  void SetAlignToNone() { this->SetAlign(None); }
154 
156 
162  vtkSetMacro(ClampToBounds, vtkTypeBool);
163  vtkGetMacro(ClampToBounds, vtkTypeBool);
164  vtkBooleanMacro(ClampToBounds, vtkTypeBool);
166 
174  void GetPolyData(vtkPolyData* pd);
175 
177 
182  vtkGetObjectMacro(HandleProperty, vtkProperty);
183  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
185 
187 
191  vtkGetObjectMacro(LineProperty, vtkProperty);
192  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
194 
195 protected:
196  vtkLineWidget();
197  ~vtkLineWidget() override;
198 
199  // Manage the state of the widget
200  friend class vtkPWCallback;
201 
202  int State;
204  {
205  Start = 0,
209  Outside
210  };
211 
212  // handles the events
213  static void ProcessEvents(
214  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
215 
216  // ProcessEvents() dispatches to these methods.
217  void OnLeftButtonDown();
218  void OnLeftButtonUp();
219  void OnMiddleButtonDown();
220  void OnMiddleButtonUp();
221  void OnRightButtonDown();
222  void OnRightButtonUp();
223  virtual void OnMouseMove();
224 
225  // controlling ivars
226  int Align;
227 
229  {
233  None
234  };
235 
236  // the line
240  void HighlightLine(int highlight);
241 
242  // glyphs representing hot spots (e.g., handles)
246 
247  void BuildRepresentation();
248  void SizeHandles() override;
249  void HandlesOn(double length);
250  void HandlesOff();
251  int HighlightHandle(vtkProp* prop); // returns cell id
252  void HighlightHandles(int highlight);
253 
254  // Do the picking
258  double LastPosition[3];
259  void SetLinePosition(double x[3]);
260 
261  // Register internal Pickers within PickingManager
262  void RegisterPickers() override;
263 
264  // Methods to manipulate the hexahedron.
265  void Scale(double* p1, double* p2, int X, int Y);
266 
267  // Initial bounds
269  void ClampPosition(double x[3]);
270  int InBounds(double x[3]);
271 
272  // Properties used to control the appearance of selected objects and
273  // the manipulator in general.
278  void CreateDefaultProperties();
279 
280  void GenerateLine();
281 
282  // Methods for managing the point widgets used to control the endpoints
286  vtkPWCallback* PWCallback;
287  vtkPW1Callback* PW1Callback;
288  vtkPW2Callback* PW2Callback;
290  void EnablePointWidget();
291  void DisablePointWidget();
292  int ForwardEvent(unsigned long event);
293 
294 private:
295  vtkLineWidget(const vtkLineWidget&) = delete;
296  void operator=(const vtkLineWidget&) = delete;
297 };
298 
299 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:56
double * GetPoint1()
vtkProperty * LineProperty
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:51
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:67
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:90
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:39
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:93
#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:63
map vtkPolyData to graphics primitives
position a point in 3D space
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:72
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:39
vtkTypeBool ClampToBounds
vtkPointWidget * CurrentPointWidget