VTK  9.3.1
vtkLineWidget.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
61 #ifndef vtkLineWidget_h
62 #define vtkLineWidget_h
63 
64 #include "vtk3DWidget.h"
65 #include "vtkInteractionWidgetsModule.h" // For export macro
66 #include "vtkLineSource.h" // For passing calls to it
67 
68 VTK_ABI_NAMESPACE_BEGIN
69 class vtkActor;
70 class vtkPolyDataMapper;
71 class vtkPoints;
72 class vtkPolyData;
73 class vtkProp;
74 class vtkProperty;
75 class vtkSphereSource;
76 class vtkCellPicker;
77 class vtkPointWidget;
78 class vtkPWCallback;
79 class vtkPW1Callback;
80 class vtkPW2Callback;
81 
82 class VTKINTERACTIONWIDGETS_EXPORT vtkLineWidget : public vtk3DWidget
83 {
84 public:
88  static vtkLineWidget* New();
89 
90  vtkTypeMacro(vtkLineWidget, vtk3DWidget);
91  void PrintSelf(ostream& os, vtkIndent indent) override;
92 
94 
97  void SetEnabled(int) override;
98  void PlaceWidget(double bounds[6]) override;
99  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
101  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
102  {
103  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
104  }
106 
110  void SetResolution(int r) { this->LineSource->SetResolution(r); }
111  int GetResolution() { return this->LineSource->GetResolution(); }
112 
116  void SetPoint1(double x, double y, double z);
117  void SetPoint1(double x[3]) { this->SetPoint1(x[0], x[1], x[2]); }
118  double* GetPoint1() VTK_SIZEHINT(3) { return this->LineSource->GetPoint1(); }
119  void GetPoint1(double xyz[3]) { this->LineSource->GetPoint1(xyz); }
120 
124  void SetPoint2(double x, double y, double z);
125  void SetPoint2(double x[3]) { this->SetPoint2(x[0], x[1], x[2]); }
126  double* GetPoint2() VTK_SIZEHINT(3) { return this->LineSource->GetPoint2(); }
127  void GetPoint2(double xyz[3]) { this->LineSource->GetPoint2(xyz); }
128 
130 
136  vtkSetClampMacro(Align, int, XAxis, None);
137  vtkGetMacro(Align, int);
138  void SetAlignToXAxis() { this->SetAlign(XAxis); }
139  void SetAlignToYAxis() { this->SetAlign(YAxis); }
140  void SetAlignToZAxis() { this->SetAlign(ZAxis); }
141  void SetAlignToNone() { this->SetAlign(None); }
143 
145 
151  vtkSetMacro(ClampToBounds, vtkTypeBool);
152  vtkGetMacro(ClampToBounds, vtkTypeBool);
153  vtkBooleanMacro(ClampToBounds, vtkTypeBool);
155 
163  void GetPolyData(vtkPolyData* pd);
164 
166 
171  vtkGetObjectMacro(HandleProperty, vtkProperty);
172  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
174 
176 
180  vtkGetObjectMacro(LineProperty, vtkProperty);
181  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
183 
184 protected:
185  vtkLineWidget();
186  ~vtkLineWidget() override;
187 
188  // Manage the state of the widget
189  friend class vtkPWCallback;
190 
191  int State;
193  {
194  Start = 0,
198  Outside
199  };
200 
201  // handles the events
202  static void ProcessEvents(
203  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
204 
205  // ProcessEvents() dispatches to these methods.
206  void OnLeftButtonDown();
207  void OnLeftButtonUp();
208  void OnMiddleButtonDown();
209  void OnMiddleButtonUp();
210  void OnRightButtonDown();
211  void OnRightButtonUp();
212  virtual void OnMouseMove();
213 
214  // controlling ivars
215  int Align;
216 
218  {
222  None
223  };
224 
225  // the line
229  void HighlightLine(int highlight);
230 
231  // glyphs representing hot spots (e.g., handles)
235 
236  void BuildRepresentation();
237  void SizeHandles() override;
238  void HandlesOn(double length);
239  void HandlesOff();
240  int HighlightHandle(vtkProp* prop); // returns cell id
241  void HighlightHandles(int highlight);
242 
243  // Do the picking
247  double LastPosition[3];
248  void SetLinePosition(double x[3]);
249 
250  // Register internal Pickers within PickingManager
251  void RegisterPickers() override;
252 
253  // Methods to manipulate the hexahedron.
254  void Scale(double* p1, double* p2, int X, int Y);
255 
256  // Initial bounds
258  void ClampPosition(double x[3]);
259  int InBounds(double x[3]);
260 
261  // Properties used to control the appearance of selected objects and
262  // the manipulator in general.
267  void CreateDefaultProperties();
268 
269  void GenerateLine();
270 
271  // Methods for managing the point widgets used to control the endpoints
275  vtkPWCallback* PWCallback;
276  vtkPW1Callback* PW1Callback;
277  vtkPW2Callback* PW2Callback;
279  void EnablePointWidget();
280  void DisablePointWidget();
281  int ForwardEvent(unsigned long event);
282 
283 private:
284  vtkLineWidget(const vtkLineWidget&) = delete;
285  void operator=(const vtkLineWidget&) = delete;
286 };
287 
288 VTK_ABI_NAMESPACE_END
289 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
double * GetPoint1()
vtkProperty * LineProperty
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:51
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:56
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:64
create a polygonal sphere centered at the origin
void PlaceWidget() override
Methods that satisfy the superclass' API.
Definition: vtkLineWidget.h:99
vtkPointWidget * PointWidget2
void GetPoint1(double xyz[3])
vtkPointWidget * PointWidget1
a simple class to control print indentation
Definition: vtkIndent.h:28
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:82
#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:52
map vtkPolyData to graphics primitives
position a point in 3D space
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:61
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:59
virtual void SizeHandles()
Definition: vtk3DWidget.h:144
virtual void PlaceWidget()
This method is used to initially place the widget.
vtkCellPicker * HandlePicker
vtkProperty * HandleProperty
represent and manipulate 3D points
Definition: vtkPoints.h:28
vtkTypeBool ClampToBounds
vtkPointWidget * CurrentPointWidget