VTK  9.4.20251007
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
28
29#ifndef vtkImplicitAnnulusRepresentation_h
30#define vtkImplicitAnnulusRepresentation_h
31
32#include "vtkInteractionWidgetsModule.h" // For export macro
33#include "vtkVector.h" // For vtkVector3d
35#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
36
37VTK_ABI_NAMESPACE_BEGIN
38class vtkActor;
40class vtkConeSource;
41class vtkLineSource;
42class vtkSphereSource;
43class vtkTubeFilter;
44class vtkAnnulus;
45class vtkProperty;
46class vtkImageData;
48class vtkPolyData;
49class vtkBox;
50class vtkCellPicker;
51
52#define VTK_MAX_ANNULUS_RESOLUTION 2048
53
54class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkImplicitAnnulusRepresentation
56{
57public:
58 // Manage the state of the widget
71
74 void PrintSelf(ostream& os, vtkIndent indent) override;
75
77
82 void SetCenter(double x, double y, double z);
83 void SetCenter(double x[3]);
84 double* GetCenter() const VTK_SIZEHINT(3);
85 void GetCenter(double xyz[3]) const;
87
89
94 void SetAxis(double x, double y, double z);
95 void SetAxis(double a[3]);
96 double* GetAxis() const VTK_SIZEHINT(3);
97 void GetAxis(double a[3]) const;
99
101
105 void SetInnerRadius(double r);
106 double GetInnerRadius() const;
108
110
114 void SetOuterRadius(double r);
115 double GetOuterRadius() const;
117
119
127 void SetAlongXAxis(bool);
128 vtkGetMacro(AlongXAxis, bool);
129 vtkBooleanMacro(AlongXAxis, bool);
130 void SetAlongYAxis(bool);
131 vtkGetMacro(AlongYAxis, bool);
132 vtkBooleanMacro(AlongYAxis, bool);
133 void SetAlongZAxis(bool);
134 vtkGetMacro(AlongZAxis, bool);
135 vtkBooleanMacro(AlongZAxis, bool);
137
139
145 void SetDrawAnnulus(bool draw);
146 vtkGetMacro(DrawAnnulus, bool);
147 vtkBooleanMacro(DrawAnnulus, bool);
149
151
158 vtkSetClampMacro(Resolution, int, 8, VTK_MAX_ANNULUS_RESOLUTION);
159 vtkGetMacro(Resolution, int);
161
163
169 vtkSetMacro(Tubing, bool);
170 vtkGetMacro(Tubing, bool);
171 vtkBooleanMacro(Tubing, bool);
173
175
180 vtkSetMacro(OutlineTranslation, bool);
181 vtkGetMacro(OutlineTranslation, bool);
182 vtkBooleanMacro(OutlineTranslation, bool);
184
186
191 vtkSetMacro(OutsideBounds, bool);
192 vtkGetMacro(OutsideBounds, bool);
193 vtkBooleanMacro(OutsideBounds, bool);
195
197
203 vtkSetVector6Macro(WidgetBounds, double);
206
208
215 vtkSetMacro(ConstrainToWidgetBounds, bool);
216 vtkGetMacro(ConstrainToWidgetBounds, bool);
217 vtkBooleanMacro(ConstrainToWidgetBounds, bool);
219
221
225 vtkSetMacro(ScaleEnabled, bool);
226 vtkGetMacro(ScaleEnabled, bool);
227 vtkBooleanMacro(ScaleEnabled, bool);
229
235
241
243
246 vtkGetObjectMacro(AxisProperty, vtkProperty);
247 vtkGetObjectMacro(SelectedAxisProperty, vtkProperty);
249
251
255 vtkGetObjectMacro(AnnulusProperty, vtkProperty);
256 vtkGetObjectMacro(SelectedAnnulusProperty, vtkProperty);
258
260
264 vtkGetObjectMacro(RadiusHandleProperty, vtkProperty);
265 vtkGetObjectMacro(SelectedRadiusHandleProperty, vtkProperty);
267
269
272 vtkGetObjectMacro(OutlineProperty, vtkProperty);
273 vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
275
277
282 void SetInteractionColor(double, double, double);
283 void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
284 void SetHandleColor(double, double, double);
285 void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
286 void SetForegroundColor(double, double, double);
287 void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
289
291
294 int ComputeInteractionState(int X, int Y, int modify = 0) override;
295 void PlaceWidget(double bounds[6]) override;
296 void BuildRepresentation() override;
297 void StartWidgetInteraction(double eventPos[2]) override;
298 void WidgetInteraction(double newEventPos[2]) override;
299 void EndWidgetInteraction(double newEventPos[2]) override;
301
303
306 double* GetBounds() override;
307 void GetActors(vtkPropCollection* pc) override;
313
315
321 vtkSetClampMacro(BumpDistance, double, 0.000001, 1);
322 vtkGetMacro(BumpDistance, double);
324
332 void BumpAnnulus(int dir, double factor);
333
340 void PushAnnulus(double distance);
341
353
355
360 vtkGetMacro(RepresentationState, InteractionStateType);
362
363 /*
364 * Register internal Pickers within PickingManager
365 */
366 void RegisterPickers() override;
367
369
373 vtkGetMacro(TranslationAxis, int);
374 vtkSetClampMacro(TranslationAxis, int, Axis::NONE, Axis::ZAxis);
376
378
381 void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
382 void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
383 void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
384 void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
386
390 bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
391
392 void GetAnnulus(vtkAnnulus* annulus) const;
393
394protected:
397
398private:
399 struct AxisHandleRepresentation
400 {
401 vtkNew<vtkLineSource> LineSource;
402 vtkNew<vtkPolyDataMapper> LineMapper;
403 vtkNew<vtkActor> LineActor;
404
405 vtkNew<vtkConeSource> ArrowSource;
406 vtkNew<vtkPolyDataMapper> ArrowMapper;
407 vtkNew<vtkActor> ArrowActor;
408 };
409
410 struct RadiusHandleRepresentation
411 {
412 vtkNew<vtkPolyData> PolyData;
415 vtkNew<vtkActor> Actor;
416 };
417
418 vtkImplicitAnnulusRepresentation(const vtkImplicitAnnulusRepresentation&) = delete;
419 void operator=(const vtkImplicitAnnulusRepresentation&) = delete;
420
421 void HighlightAnnulus(bool highlight);
422 void HighlightCenterHandle(bool highlight);
423 void HighlightAxis(bool highlight);
424 void HighlightOutline(bool highlight);
425 void HighlightInnerRadiusHandle(bool highlight);
426 void HighlightOuterRadiusHandle(bool highlight);
427
428 // Methods to manipulate the annulus
429 void Rotate(
430 double X, double Y, const vtkVector3d& p1, const vtkVector3d& p2, const vtkVector3d& vpn);
431 void TranslateAnnulus(const vtkVector3d& p1, const vtkVector3d& p2);
432 void TranslateOutline(const vtkVector3d& p1, const vtkVector3d& p2);
433 void TranslateCenter(const vtkVector3d& p1, const vtkVector3d& p2);
434 void TranslateCenterOnAxis(const vtkVector3d& p1, const vtkVector3d& p2);
435 void ScaleRadii(const vtkVector3d& p1, const vtkVector3d& p2);
436 void AdjustOuterRadius(double X, double Y, const vtkVector3d& p1, const vtkVector3d& p2);
437 void AdjustInnerRadius(double X, double Y, const vtkVector3d& p1, const vtkVector3d& p2);
438 void Scale(const vtkVector3d& p1, const vtkVector3d& p2, double X, double Y);
439 void SizeHandles();
440
441 // Generate the annulus polydata, cropped by the bounding box
442 void BuildAnnulus();
443
444 // The actual annulus we're manipulating
445 vtkNew<vtkAnnulus> Annulus;
446
447 InteractionStateType RepresentationState = InteractionStateType::Outside;
448 int TranslationAxis = Axis::NONE;
449
450 // Keep track of event positions
451 vtkVector3d LastEventPosition;
452
453 // Controlling the push operation
454 double BumpDistance = 0.01;
455
456 // Controlling ivars
457 bool AlongXAxis = false;
458 bool AlongYAxis = false;
459 bool AlongZAxis = false;
460
461 // The facet resolution for rendering purposes.
462 int Resolution = 128;
463
464 // The bounding box is represented by a single voxel image data
465 vtkNew<vtkImageData> Box;
466 vtkNew<vtkOutlineFilter> Outline;
467 vtkNew<vtkPolyDataMapper> OutlineMapper;
468 vtkNew<vtkActor> OutlineActor;
469 bool OutlineTranslation = true; // whether the outline can be moved
470 bool ScaleEnabled = true; // whether the widget can be scaled
471 bool OutsideBounds = true; // whether the widget can be moved outside input's bounds
472 vtkVector<double, 6> WidgetBounds;
473 bool ConstrainToWidgetBounds = true;
474
475 vtkNew<vtkPolyData> AnnulusPD;
476 vtkNew<vtkPolyDataMapper> AnnulusMapper;
477 vtkNew<vtkActor> AnnulusActor;
478 bool DrawAnnulus = true;
479
480 // Optional tubes are represented by extracting boundary edges and tubing
481 RadiusHandleRepresentation InnerRadiusRepresentation;
482 RadiusHandleRepresentation OuterRadiusRepresentation;
483 bool Tubing = true; // control whether tubing is on
484
485 // Axis representations
486 AxisHandleRepresentation LowerAxisRepresentation;
487 AxisHandleRepresentation UpperAxisRepresentation;
488
489 // Center positioning handle
490 vtkNew<vtkSphereSource> CenterHandleSource;
491 vtkNew<vtkPolyDataMapper> CenterHandleMapper;
492 vtkNew<vtkActor> CenterHandleActor;
493
494 // Do the picking
495 vtkNew<vtkCellPicker> Picker;
496 vtkNew<vtkCellPicker> AnnulusPicker;
497
498 // Properties used to control the appearance of selected objects and
499 // the manipulator in general.
500 vtkNew<vtkProperty> AxisProperty;
501 vtkNew<vtkProperty> SelectedAxisProperty;
502 vtkNew<vtkProperty> AnnulusProperty;
503 vtkNew<vtkProperty> SelectedAnnulusProperty;
504 vtkNew<vtkProperty> OutlineProperty;
505 vtkNew<vtkProperty> SelectedOutlineProperty;
506 vtkNew<vtkProperty> RadiusHandleProperty;
507 vtkNew<vtkProperty> SelectedRadiusHandleProperty;
508 vtkNew<vtkProperty> CenterHandleProperty;
509 vtkNew<vtkProperty> SelectedCenterHandleProperty;
510
511 vtkNew<vtkBox> BoundingBox;
512};
513
514VTK_ABI_NAMESPACE_END
515#endif
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:42
implicit function for a annulus
Definition vtkAnnulus.h:41
implicit function for a bounding box
Definition vtkBox.h:31
ray-cast cell picker for all kinds of Prop3Ds
generate polygonal cone
topologically and geometrically regular array of data
vtkTypeBool HasTranslucentPolygonalGeometry() override
Methods supporting the rendering process.
double * GetWidgetBounds()
Set/Get the bounds of the widget representation.
void SetAlongYAxis(bool)
Force the annulus widget to be aligned with one of the x-y-z axes.
void UpdatePlacement()
Satisfies the superclass API.
void PushAnnulus(double distance)
Push the annulus the distance specified along the view vector.
void PlaceWidget(double bounds[6]) override
Methods to interface with the vtkImplicitAnnulusWidget.
static vtkImplicitAnnulusRepresentation * New()
void SetDrawAnnulus(bool draw)
Enable/disable the drawing of the annulus.
double * GetBounds() override
Methods supporting the rendering process.
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
void GetAnnulus(vtkAnnulus *annulus) const
void BuildRepresentation() override
Methods to interface with the vtkImplicitAnnulusWidget.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetAlongZAxis(bool)
Force the annulus widget to be aligned with one of the x-y-z axes.
void SetOuterRadius(double r)
Set/Get the annulus outer radius.
void SetHandleColor(double c[3])
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
void SetInteractionColor(double c[3])
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
void SetForegroundColor(double, double, double)
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
void SetInteractionColor(double, double, double)
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
double * GetCenter() const
Get the center of the annulus representation.
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
double GetOuterRadius() const
Set/Get the annulus outer radius.
void BumpAnnulus(int dir, double factor)
Translate the annulus in the direction of the view vector by the specified BumpDistance.
void GetPolyData(vtkPolyData *pd)
Grab the polydata that defines the annulus.
void SetAxis(double x, double y, double z)
Set/Get the axis of rotation for the annulus.
void SetForegroundColor(double c[3])
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
double GetInnerRadius() const
Set/Get the annulus inner radius.
bool IsTranslationConstrained()
Returns true if ConstrainedAxis.
void ReleaseGraphicsResources(vtkWindow *) override
Methods supporting the rendering process.
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
int RenderTranslucentPolygonalGeometry(vtkViewport *) override
Methods supporting the rendering process.
int RenderOpaqueGeometry(vtkViewport *) override
Methods supporting the rendering process.
void SetCenter(double x[3])
Get the center of the annulus representation.
virtual void SetRepresentationState(InteractionStateType)
Sets the visual appearance of the representation based on the state it is in.
void SetAlongXAxis(bool)
Force the annulus widget to be aligned with one of the x-y-z axes.
void SetInnerRadius(double r)
Set/Get the annulus inner radius.
void SetCenter(double x, double y, double z)
Get the center of the annulus representation.
int ComputeInteractionState(int X, int Y, int modify=0) override
Methods to interface with the vtkImplicitAnnulusWidget.
void EndWidgetInteraction(double newEventPos[2]) override
Methods to interface with the vtkImplicitAnnulusWidget.
void WidgetInteraction(double newEventPos[2]) override
Methods to interface with the vtkImplicitAnnulusWidget.
void SetHandleColor(double, double, double)
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
void SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
void GetActors(vtkPropCollection *pc) override
Methods supporting the rendering process.
void StartWidgetInteraction(double eventPos[2]) override
Methods to interface with the vtkImplicitAnnulusWidget.
double * GetAxis() const
Set/Get the axis of rotation for the annulus.
a simple class to control print indentation
Definition vtkIndent.h:29
create a line defined by two end points
Allocate and hold a VTK object.
Definition vtkNew.h:58
create wireframe outline for an arbitrary data set or composite dataset
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:72
an ordered list of Props
represent surface properties of a geometric object
Definition vtkProperty.h:60
create a polygonal sphere centered at the origin
filter that generates tubes around lines
abstract specification for Viewports
Definition vtkViewport.h:46
window superclass for vtkRenderWindow
Definition vtkWindow.h:29
@ Box
Definition vtkX3D.h:65
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_MAX_ANNULUS_RESOLUTION
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO