VTK  9.7.1
vtkImplicitAnnulusRepresentation.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
29 #ifndef vtkImplicitAnnulusRepresentation_h
30 #define vtkImplicitAnnulusRepresentation_h
31 
33 #include "vtkInteractionWidgetsModule.h" // For export macro
34 #include "vtkVector.h" // For vtkVector3d
35 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
36 
37 VTK_ABI_NAMESPACE_BEGIN
38 class vtkActor;
39 class vtkPolyDataMapper;
40 class vtkConeSource;
41 class vtkLineSource;
42 class vtkSphereSource;
43 class vtkTubeFilter;
44 class vtkAnnulus;
45 class vtkProperty;
46 class vtkPolyData;
47 class vtkBox;
48 class vtkCellPicker;
49 
50 #define VTK_MAX_ANNULUS_RESOLUTION 2048
51 
52 class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkImplicitAnnulusRepresentation
54 {
55 public:
56  // Manage the state of the widget
58  {
59  Outside = 0,
60  Moving, // Generic state set by the widget
67  TranslatingCenter
68  };
69 
72  void PrintSelf(ostream& os, vtkIndent indent) override;
73 
75 
80  void SetCenter(double x, double y, double z);
81  void SetCenter(double x[3]);
82  double* GetCenter() const VTK_SIZEHINT(3);
83  void GetCenter(double xyz[3]) const;
85 
87 
92  void SetAxis(double x, double y, double z);
93  void SetAxis(double a[3]);
94  double* GetAxis() const VTK_SIZEHINT(3);
95  void GetAxis(double a[3]) const;
97 
99 
105  void SetInnerRadius(double r);
106  double GetInnerRadius() const;
108 
110 
116  void SetOuterRadius(double r);
117  double GetOuterRadius() const;
119 
121 
129  void SetAlongXAxis(bool);
130  vtkGetMacro(AlongXAxis, bool);
131  vtkBooleanMacro(AlongXAxis, bool);
132  void SetAlongYAxis(bool);
133  vtkGetMacro(AlongYAxis, bool);
134  vtkBooleanMacro(AlongYAxis, bool);
135  void SetAlongZAxis(bool);
136  vtkGetMacro(AlongZAxis, bool);
137  vtkBooleanMacro(AlongZAxis, bool);
139 
141 
147  void SetDrawAnnulus(bool draw);
148  vtkGetMacro(DrawAnnulus, bool);
149  vtkBooleanMacro(DrawAnnulus, bool);
151 
153 
160  vtkSetClampMacro(Resolution, int, 8, VTK_MAX_ANNULUS_RESOLUTION);
161  vtkGetMacro(Resolution, int);
163 
165 
171  vtkSetMacro(Tubing, bool);
172  vtkGetMacro(Tubing, bool);
173  vtkBooleanMacro(Tubing, bool);
175 
177 
181  vtkSetMacro(ScaleEnabled, bool);
182  vtkGetMacro(ScaleEnabled, bool);
183  vtkBooleanMacro(ScaleEnabled, bool);
185 
190  void GetPolyData(vtkPolyData* pd);
191 
196  void UpdatePlacement();
197 
199 
202  vtkGetObjectMacro(AxisProperty, vtkProperty);
203  vtkGetObjectMacro(SelectedAxisProperty, vtkProperty);
205 
207 
211  vtkGetObjectMacro(AnnulusProperty, vtkProperty);
212  vtkGetObjectMacro(SelectedAnnulusProperty, vtkProperty);
214 
216 
220  vtkGetObjectMacro(RadiusHandleProperty, vtkProperty);
221  vtkGetObjectMacro(SelectedRadiusHandleProperty, vtkProperty);
223 
225 
230  void SetInteractionColor(double, double, double);
231  void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
232  void SetHandleColor(double, double, double);
233  void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
234  void SetForegroundColor(double, double, double);
235  void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
237 
239 
242  int ComputeInteractionState(int X, int Y, int modify = 0) override;
243  void PlaceWidget(double bounds[6]) override;
244  void BuildRepresentation() override;
245  void StartWidgetInteraction(double eventPos[2]) override;
246  void WidgetInteraction(double newEventPos[2]) override;
247  void EndWidgetInteraction(double newEventPos[2]) override;
249 
251 
254  double* GetBounds() override;
255  void GetActors(vtkPropCollection* pc) override;
256  void ReleaseGraphicsResources(vtkWindow*) override;
257  int RenderOpaqueGeometry(vtkViewport*) override;
261 
263 
269  vtkSetClampMacro(BumpDistance, double, 0.000001, 1);
270  vtkGetMacro(BumpDistance, double);
272 
280  void BumpAnnulus(int dir, double factor);
281 
288  void PushAnnulus(double distance);
289 
299  vtkSetClampMacro(InteractionState, InteractionStateType, InteractionStateType::Outside,
300  InteractionStateType::TranslatingCenter);
301 
303 
307  virtual void SetRepresentationState(InteractionStateType);
308  vtkGetMacro(RepresentationState, InteractionStateType);
310 
311  /*
312  * Register internal Pickers within PickingManager
313  */
314  void RegisterPickers() override;
315 
316  void GetAnnulus(vtkAnnulus* annulus) const;
317 
318 protected:
321 
322 private:
323  struct AxisHandleRepresentation
324  {
325  vtkNew<vtkLineSource> LineSource;
326  vtkNew<vtkPolyDataMapper> LineMapper;
327  vtkNew<vtkActor> LineActor;
328 
329  vtkNew<vtkConeSource> ArrowSource;
330  vtkNew<vtkPolyDataMapper> ArrowMapper;
331  vtkNew<vtkActor> ArrowActor;
332  };
333 
334  struct RadiusHandleRepresentation
335  {
336  vtkNew<vtkPolyData> PolyData;
337  vtkNew<vtkTubeFilter> Tuber;
339  vtkNew<vtkActor> Actor;
340  };
341 
343  void operator=(const vtkImplicitAnnulusRepresentation&) = delete;
344 
345  void HighlightAnnulus(bool highlight);
346  void HighlightCenterHandle(bool highlight);
347  void HighlightAxis(bool highlight);
348  void HighlightInnerRadiusHandle(bool highlight);
349  void HighlightOuterRadiusHandle(bool highlight);
350 
351  // Methods to manipulate the annulus
352  void Rotate(
353  double X, double Y, const vtkVector3d& p1, const vtkVector3d& p2, const vtkVector3d& vpn);
354  void TranslateAnnulus(const vtkVector3d& p1, const vtkVector3d& p2);
355  void TranslateRepresentation(const vtkVector3d& motion) override;
356  void TranslateCenter(const vtkVector3d& p1, const vtkVector3d& p2);
357  void TranslateCenterOnAxis(const vtkVector3d& p1, const vtkVector3d& p2);
358  void ScaleRadii(const vtkVector3d& p1, const vtkVector3d& p2);
359  void AdjustOuterRadius(double x, double y, const vtkVector3d& point);
360  void AdjustInnerRadius(double x, double y, const vtkVector3d& point);
361  void Scale(const vtkVector3d& p1, const vtkVector3d& p2, double X, double Y);
362  void SizeHandles();
363 
364  // Generate the annulus polydata, cropped by the bounding box
365  void BuildAnnulus();
366 
367  // The actual annulus we're manipulating
368  vtkNew<vtkAnnulus> Annulus;
369 
370  InteractionStateType RepresentationState = InteractionStateType::Outside;
371 
372  // Keep track of event positions
373  vtkVector3d LastEventPosition;
374 
375  // Controlling the push operation
376  double BumpDistance = 0.01;
377 
378  // Controlling ivars
379  bool AlongXAxis = false;
380  bool AlongYAxis = false;
381  bool AlongZAxis = false;
382 
383  // The facet resolution for rendering purposes.
384  int Resolution = 128;
385 
386  bool ScaleEnabled = true; // whether the widget can be scaled
387 
388  vtkNew<vtkPolyData> AnnulusPD;
389  vtkNew<vtkPolyDataMapper> AnnulusMapper;
390  vtkNew<vtkActor> AnnulusActor;
391  bool DrawAnnulus = true;
392 
393  // Optional tubes are represented by extracting boundary edges and tubing
394  RadiusHandleRepresentation InnerRadiusRepresentation;
395  RadiusHandleRepresentation OuterRadiusRepresentation;
396  bool Tubing = true; // control whether tubing is on
397 
398  // Axis representations
399  AxisHandleRepresentation LowerAxisRepresentation;
400  AxisHandleRepresentation UpperAxisRepresentation;
401 
402  // Center positioning handle
403  vtkNew<vtkSphereSource> CenterHandleSource;
404  vtkNew<vtkPolyDataMapper> CenterHandleMapper;
405  vtkNew<vtkActor> CenterHandleActor;
406 
407  // Do the picking
408  vtkNew<vtkCellPicker> Picker;
409  vtkNew<vtkCellPicker> AnnulusPicker;
410 
411  // Properties used to control the appearance of selected objects and
412  // the manipulator in general.
413  vtkNew<vtkProperty> AxisProperty;
414  vtkNew<vtkProperty> SelectedAxisProperty;
415  vtkNew<vtkProperty> AnnulusProperty;
416  vtkNew<vtkProperty> SelectedAnnulusProperty;
417  vtkNew<vtkProperty> RadiusHandleProperty;
418  vtkNew<vtkProperty> SelectedRadiusHandleProperty;
419  vtkNew<vtkProperty> CenterHandleProperty;
420  vtkNew<vtkProperty> SelectedCenterHandleProperty;
421 
422  vtkNew<vtkBox> BoundingBox;
423 };
424 
425 VTK_ABI_NAMESPACE_END
426 #endif
defining the representation for a vtkImplicitAnnulusWidget
virtual void EndWidgetInteraction(double newEventPos[2])
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
virtual void PlaceWidget(double bounds[6])
The following is a suggested API for widget representations.
virtual int ComputeInteractionState(int X, int Y, int modify=0)
abstract specification for Viewports
Definition: vtkViewport.h:46
represent surface properties of a geometric object
Definition: vtkProperty.h:59
virtual void StartWidgetInteraction(double eventPos[2])
generate polygonal cone
Definition: vtkConeSource.h:34
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
int RenderOpaqueGeometry(vtkViewport *viewport) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
virtual void BuildRepresentation()=0
Subclasses of vtkWidgetRepresentation must implement these methods.
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override
#define VTK_MAX_ANNULUS_RESOLUTION
double * GetBounds() override
Methods to make this class behave as a vtkProp.
an ordered list of Props
int vtkTypeBool
Definition: vtkABI.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
void SetForegroundColor(double c[3])
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
create a polygonal sphere centered at the origin
filter that generates tubes around lines
Definition: vtkTubeFilter.h:75
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
void ReleaseGraphicsResources(vtkWindow *) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE Release any graphics resources that are being...
virtual void TranslateRepresentation(const vtkVector3d &)
Translate the representation, to be implemented in derived class.
virtual void WidgetInteraction(double newEventPos[2])
#define VTK_SIZEHINT(...)
void SetHandleColor(double c[3])
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
create a line defined by two end points
Definition: vtkLineSource.h:53
map vtkPolyData to graphics primitives
Extends the vtkWidgetRepresentation to help positioning widget in space and how it should be displaye...
vtkTypeBool HasTranslucentPolygonalGeometry() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
void SetInteractionColor(double c[3])
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
#define VTK_MARSHALAUTO
void GetActors(vtkPropCollection *) override
For some exporters and other other operations we must be able to collect all the actors or volumes...
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
implicit function for a bounding box
Definition: vtkBox.h:30
implicit function for a annulus
Definition: vtkAnnulus.h:40