VTK  9.3.0
vtkImageTracerWidget.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
57 #ifndef vtkImageTracerWidget_h
58 #define vtkImageTracerWidget_h
59 
60 #include "vtk3DWidget.h"
61 #include "vtkInteractionWidgetsModule.h" // For export macro
62 
63 VTK_ABI_NAMESPACE_BEGIN
65 class vtkActor;
66 class vtkCellArray;
67 class vtkCellPicker;
68 class vtkFloatArray;
69 class vtkGlyphSource2D;
70 class vtkPoints;
71 class vtkPolyData;
72 class vtkProp;
73 class vtkProperty;
74 class vtkPropPicker;
75 class vtkTransform;
77 
78 #define VTK_ITW_PROJECTION_YZ 0
79 #define VTK_ITW_PROJECTION_XZ 1
80 #define VTK_ITW_PROJECTION_XY 2
81 #define VTK_ITW_SNAP_CELLS 0
82 #define VTK_ITW_SNAP_POINTS 1
83 
84 class VTKINTERACTIONWIDGETS_EXPORT vtkImageTracerWidget : public vtk3DWidget
85 {
86 public:
91 
93  void PrintSelf(ostream& os, vtkIndent indent) override;
94 
96 
99  void SetEnabled(int) override;
100  void PlaceWidget(double bounds[6]) override;
101  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
103  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
104  {
105  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
106  }
108 
110 
115  vtkGetObjectMacro(HandleProperty, vtkProperty);
117  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
119 
121 
125  virtual void SetLineProperty(vtkProperty*);
126  vtkGetObjectMacro(LineProperty, vtkProperty);
128  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
130 
134  void SetViewProp(vtkProp* prop);
135 
137 
140  vtkSetMacro(ProjectToPlane, vtkTypeBool);
141  vtkGetMacro(ProjectToPlane, vtkTypeBool);
142  vtkBooleanMacro(ProjectToPlane, vtkTypeBool);
144 
146 
152  vtkSetClampMacro(ProjectionNormal, int, VTK_ITW_PROJECTION_YZ, VTK_ITW_PROJECTION_XY);
153  vtkGetMacro(ProjectionNormal, int);
154  void SetProjectionNormalToXAxes() { this->SetProjectionNormal(0); }
155  void SetProjectionNormalToYAxes() { this->SetProjectionNormal(1); }
156  void SetProjectionNormalToZAxes() { this->SetProjectionNormal(2); }
158 
160 
168  vtkGetMacro(ProjectionPosition, double);
170 
172 
176  vtkGetMacro(SnapToImage, vtkTypeBool);
177  vtkBooleanMacro(SnapToImage, vtkTypeBool);
179 
181 
186  vtkSetMacro(AutoClose, vtkTypeBool);
187  vtkGetMacro(AutoClose, vtkTypeBool);
188  vtkBooleanMacro(AutoClose, vtkTypeBool);
190 
192 
198  vtkSetMacro(CaptureRadius, double);
199  vtkGetMacro(CaptureRadius, double);
201 
208  void GetPath(vtkPolyData* pd);
209 
213  vtkGlyphSource2D* GetGlyphSource() { return this->HandleGenerator; }
214 
216 
220  vtkSetClampMacro(ImageSnapType, int, VTK_ITW_SNAP_CELLS, VTK_ITW_SNAP_POINTS);
221  vtkGetMacro(ImageSnapType, int);
223 
225 
228  void SetHandlePosition(int handle, double xyz[3]);
229  void SetHandlePosition(int handle, double x, double y, double z);
230  void GetHandlePosition(int handle, double xyz[3]);
231  double* GetHandlePosition(int handle) VTK_SIZEHINT(3);
233 
235 
238  vtkGetMacro(NumberOfHandles, int);
240 
242 
245  void SetInteraction(vtkTypeBool interact);
246  vtkGetMacro(Interaction, vtkTypeBool);
247  vtkBooleanMacro(Interaction, vtkTypeBool);
249 
256 
260  int IsClosed();
261 
263 
266  vtkSetMacro(HandleLeftMouseButton, vtkTypeBool);
267  vtkGetMacro(HandleLeftMouseButton, vtkTypeBool);
268  vtkBooleanMacro(HandleLeftMouseButton, vtkTypeBool);
269  vtkSetMacro(HandleMiddleMouseButton, vtkTypeBool);
270  vtkGetMacro(HandleMiddleMouseButton, vtkTypeBool);
271  vtkBooleanMacro(HandleMiddleMouseButton, vtkTypeBool);
272  vtkSetMacro(HandleRightMouseButton, vtkTypeBool);
273  vtkGetMacro(HandleRightMouseButton, vtkTypeBool);
274  vtkBooleanMacro(HandleRightMouseButton, vtkTypeBool);
276 
277 protected:
280 
281  // Manage the state of the widget
282  int State;
284  {
285  Start = 0,
292  Outside
293  };
294 
295  // handles the events
296  static void ProcessEvents(
297  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
298 
299  // ProcessEvents() dispatches to these methods.
306  void OnMouseMove();
307 
308  void AddObservers();
309 
310  // Controlling ivars
317  double CaptureRadius; // tolerance for auto path close
320  int LastX;
321  int LastY;
322 
323  void Trace(int, int);
324  void Snap(double*);
325  void MovePoint(const double*, const double*);
326  void Translate(const double*, const double*);
327  void ClosePath();
328 
329  // 2D glyphs representing hot spots (e.g., handles)
333 
334  // Transforms required as 2D glyphs are generated in the x-y plane
338 
339  void AppendHandles(double*);
340  void ResetHandles();
341  void AllocateHandles(const int&);
342  void AdjustHandlePosition(const int&, double*);
343  int HighlightHandle(vtkProp*); // returns handle index or -1 on fail
344  void EraseHandle(const int&);
345  void SizeHandles() override;
346  void InsertHandleOnLine(double*);
347 
351 
352  vtkProp* ViewProp; // the prop we want to pick on
353  vtkPropPicker* PropPicker; // the prop's picker
354 
355  // Representation of the line
360  vtkIdType CurrentPoints[2];
361 
362  void HighlightLine(const int&);
364  void ResetLine(double*);
365  void AppendLine(double*);
367 
368  // Do the picking of the handles and the lines
372 
373  // Register internal Pickers within PickingManager
374  void RegisterPickers() override;
375 
376  // Properties used to control the appearance of selected objects and
377  // the manipulator in general.
383 
384  // Enable/Disable mouse button events
388 
389 private:
391  void operator=(const vtkImageTracerWidget&) = delete;
392 };
393 
394 VTK_ABI_NAMESPACE_END
395 #endif
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:60
abstract API for pickers that can pick an instance of vtkProp
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:50
object to represent cell connectivity
Definition: vtkCellArray.h:185
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:71
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:40
create 2D glyphs represented by vtkPolyData
3D widget for tracing on planar props.
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
void SetProjectionNormalToYAxes()
Set the projection normal.
vtkCellPicker * HandlePicker
void AppendLine(double *)
void InsertHandleOnLine(double *)
static vtkImageTracerWidget * New()
Instantiate the object.
void GetHandlePosition(int handle, double xyz[3])
Set/Get the handle position in terms of a zero-based array of handles.
virtual void SetSelectedLineProperty(vtkProperty *)
Set/Get the line properties.
void AppendHandles(double *)
void SetProjectionPosition(double position)
Set the position of the widgets' handles in terms of a plane's position.
void GetPath(vtkPolyData *pd)
Grab the points and lines that define the traced path.
~vtkImageTracerWidget() override
void ResetLine(double *)
void HighlightLine(const int &)
vtkTransformPolyDataFilter * TransformFilter
void PlaceWidget(double bounds[6]) override
Methods that satisfy the superclass' API.
virtual void SetSelectedHandleProperty(vtkProperty *)
Set/Get the handle properties (the 2D glyphs are the handles).
void SetProjectionNormalToZAxes()
Set the projection normal.
void SetEnabled(int) override
Methods that satisfy the superclass' API.
int HighlightHandle(vtkProp *)
void SetHandlePosition(int handle, double x, double y, double z)
Set/Get the handle position in terms of a zero-based array of handles.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetInteraction(vtkTypeBool interact)
Enable/disable mouse interaction when the widget is visible.
void SizeHandles() override
void EraseHandle(const int &)
vtkAbstractPropPicker * CurrentPicker
void InitializeHandles(vtkPoints *)
Initialize the widget with a set of points and generate lines between them.
void PlaceWidget() override
Methods that satisfy the superclass' API.
vtkFloatArray * TemporaryHandlePoints
void Translate(const double *, const double *)
void SetProjectionNormalToXAxes()
Set the projection normal.
static void ProcessEvents(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
vtkGlyphSource2D * HandleGenerator
void Snap(double *)
vtkGlyphSource2D * GetGlyphSource()
Get the handles' geometric representation via vtkGlyphSource2D.
void CreateDefaultProperties()
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Methods that satisfy the superclass' API.
void MovePoint(const double *, const double *)
virtual void SetHandleProperty(vtkProperty *)
Set/Get the handle properties (the 2D glyphs are the handles).
vtkProperty * SelectedHandleProperty
void SetSnapToImage(vtkTypeBool snap)
Force snapping to image data while tracing.
void SetHandlePosition(int handle, double xyz[3])
Set/Get the handle position in terms of a zero-based array of handles.
int IsClosed()
Is the path closed or open?
void AllocateHandles(const int &)
void Trace(int, int)
void AdjustHandlePosition(const int &, double *)
vtkProperty * SelectedLineProperty
double * GetHandlePosition(int handle)
Set/Get the handle position in terms of a zero-based array of handles.
void SetViewProp(vtkProp *prop)
Set the prop, usually a vtkImageActor, to trace over.
virtual void SetLineProperty(vtkProperty *)
Set/Get the line properties.
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
represent and manipulate 3D points
Definition: vtkPoints.h:38
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:89
pick an actor/prop using graphics hardware
Definition: vtkPropPicker.h:44
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:55
represent surface properties of a geometric object
Definition: vtkProperty.h:66
transform points and associated normals and vectors for polygonal dataset
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:59
@ position
Definition: vtkX3D.h:261
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_ITW_SNAP_CELLS
#define VTK_ITW_SNAP_POINTS
#define VTK_ITW_PROJECTION_YZ
#define VTK_ITW_PROJECTION_XY
int vtkIdType
Definition: vtkType.h:315
#define VTK_SIZEHINT(...)