VTK  9.4.2
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
48#ifndef vtkImplicitAnnulusRepresentation_h
49#define vtkImplicitAnnulusRepresentation_h
50
51#include "vtkInteractionWidgetsModule.h" // For export macro
52#include "vtkVector.h" // For vtkVector3d
54#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
55
56VTK_ABI_NAMESPACE_BEGIN
57class vtkActor;
59class vtkConeSource;
60class vtkLineSource;
61class vtkSphereSource;
62class vtkTubeFilter;
63class vtkAnnulus;
64class vtkProperty;
65class vtkImageData;
67class vtkPolyData;
68class vtkBox;
69class vtkCellPicker;
70
71#define VTK_MAX_ANNULUS_RESOLUTION 2048
72
73class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkImplicitAnnulusRepresentation
75{
76public:
77 // Manage the state of the widget
79 {
80 Outside = 0,
81 Moving, // Generic state set by the widget
88 TranslatingCenter
89 };
90
93 void PrintSelf(ostream& os, vtkIndent indent) override;
94
96
101 void SetCenter(double x, double y, double z);
102 void SetCenter(double x[3]);
103 double* GetCenter() const VTK_SIZEHINT(3);
104 void GetCenter(double xyz[3]) const;
106
108
113 void SetAxis(double x, double y, double z);
114 void SetAxis(double a[3]);
115 double* GetAxis() const VTK_SIZEHINT(3);
116 void GetAxis(double a[3]) const;
118
120
124 void SetInnerRadius(double r);
125 double GetInnerRadius() const;
127
129
133 void SetOuterRadius(double r);
134 double GetOuterRadius() const;
136
138
146 void SetAlongXAxis(bool);
147 vtkGetMacro(AlongXAxis, bool);
148 vtkBooleanMacro(AlongXAxis, bool);
149 void SetAlongYAxis(bool);
150 vtkGetMacro(AlongYAxis, bool);
151 vtkBooleanMacro(AlongYAxis, bool);
152 void SetAlongZAxis(bool);
153 vtkGetMacro(AlongZAxis, bool);
154 vtkBooleanMacro(AlongZAxis, bool);
156
158
164 void SetDrawAnnulus(bool draw);
165 vtkGetMacro(DrawAnnulus, bool);
166 vtkBooleanMacro(DrawAnnulus, bool);
168
170
177 vtkSetClampMacro(Resolution, int, 8, VTK_MAX_ANNULUS_RESOLUTION);
178 vtkGetMacro(Resolution, int);
180
182
188 vtkSetMacro(Tubing, bool);
189 vtkGetMacro(Tubing, bool);
190 vtkBooleanMacro(Tubing, bool);
192
194
199 vtkSetMacro(OutlineTranslation, bool);
200 vtkGetMacro(OutlineTranslation, bool);
201 vtkBooleanMacro(OutlineTranslation, bool);
203
205
210 vtkSetMacro(OutsideBounds, bool);
211 vtkGetMacro(OutsideBounds, bool);
212 vtkBooleanMacro(OutsideBounds, bool);
214
216
222 vtkSetVector6Macro(WidgetBounds, double);
223 double* GetWidgetBounds();
225
227
234 vtkSetMacro(ConstrainToWidgetBounds, bool);
235 vtkGetMacro(ConstrainToWidgetBounds, bool);
236 vtkBooleanMacro(ConstrainToWidgetBounds, bool);
238
240
244 vtkSetMacro(ScaleEnabled, bool);
245 vtkGetMacro(ScaleEnabled, bool);
246 vtkBooleanMacro(ScaleEnabled, bool);
248
253 void GetPolyData(vtkPolyData* pd);
254
259 void UpdatePlacement();
260
262
265 vtkGetObjectMacro(AxisProperty, vtkProperty);
266 vtkGetObjectMacro(SelectedAxisProperty, vtkProperty);
268
270
274 vtkGetObjectMacro(AnnulusProperty, vtkProperty);
275 vtkGetObjectMacro(SelectedAnnulusProperty, vtkProperty);
277
279
283 vtkGetObjectMacro(RadiusHandleProperty, vtkProperty);
284 vtkGetObjectMacro(SelectedRadiusHandleProperty, vtkProperty);
286
288
291 vtkGetObjectMacro(OutlineProperty, vtkProperty);
292 vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
294
296
301 void SetInteractionColor(double, double, double);
302 void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
303 void SetHandleColor(double, double, double);
304 void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
305 void SetForegroundColor(double, double, double);
306 void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
308
310
313 int ComputeInteractionState(int X, int Y, int modify = 0) override;
314 void PlaceWidget(double bounds[6]) override;
315 void BuildRepresentation() override;
316 void StartWidgetInteraction(double eventPos[2]) override;
317 void WidgetInteraction(double newEventPos[2]) override;
318 void EndWidgetInteraction(double newEventPos[2]) override;
320
322
325 double* GetBounds() override;
326 void GetActors(vtkPropCollection* pc) override;
332
334
340 vtkSetClampMacro(BumpDistance, double, 0.000001, 1);
341 vtkGetMacro(BumpDistance, double);
343
351 void BumpAnnulus(int dir, double factor);
352
359 void PushAnnulus(double distance);
360
370 vtkSetClampMacro(InteractionState, InteractionStateType, InteractionStateType::Outside,
371 InteractionStateType::TranslatingCenter);
372
374
379 vtkGetMacro(RepresentationState, InteractionStateType);
381
382 /*
383 * Register internal Pickers within PickingManager
384 */
385 void RegisterPickers() override;
386
388
392 vtkGetMacro(TranslationAxis, int);
393 vtkSetClampMacro(TranslationAxis, int, Axis::NONE, Axis::ZAxis);
395
397
400 void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
401 void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
402 void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
403 void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
405
409 bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
410
411 void GetAnnulus(vtkAnnulus* annulus) const;
412
413protected:
416
417private:
418 struct AxisHandleRepresentation
419 {
420 vtkNew<vtkLineSource> LineSource;
421 vtkNew<vtkPolyDataMapper> LineMapper;
422 vtkNew<vtkActor> LineActor;
423
424 vtkNew<vtkConeSource> ArrowSource;
425 vtkNew<vtkPolyDataMapper> ArrowMapper;
426 vtkNew<vtkActor> ArrowActor;
427 };
428
429 struct RadiusHandleRepresentation
430 {
431 vtkNew<vtkPolyData> PolyData;
434 vtkNew<vtkActor> Actor;
435 };
436
438 void operator=(const vtkImplicitAnnulusRepresentation&) = delete;
439
440 void HighlightAnnulus(bool highlight);
441 void HighlightCenterHandle(bool highlight);
442 void HighlightAxis(bool highlight);
443 void HighlightOutline(bool highlight);
444 void HighlightInnerRadiusHandle(bool highlight);
445 void HighlightOuterRadiusHandle(bool highlight);
446
447 // Methods to manipulate the annulus
448 void Rotate(
449 double X, double Y, const vtkVector3d& p1, const vtkVector3d& p2, const vtkVector3d& vpn);
450 void TranslateAnnulus(const vtkVector3d& p1, const vtkVector3d& p2);
451 void TranslateOutline(const vtkVector3d& p1, const vtkVector3d& p2);
452 void TranslateCenter(const vtkVector3d& p1, const vtkVector3d& p2);
453 void TranslateCenterOnAxis(const vtkVector3d& p1, const vtkVector3d& p2);
454 void ScaleRadii(const vtkVector3d& p1, const vtkVector3d& p2);
455 void AdjustOuterRadius(double X, double Y, const vtkVector3d& p1, const vtkVector3d& p2);
456 void AdjustInnerRadius(double X, double Y, const vtkVector3d& p1, const vtkVector3d& p2);
457 void Scale(const vtkVector3d& p1, const vtkVector3d& p2, double X, double Y);
458 void SizeHandles();
459
460 // Generate the annulus polydata, cropped by the bounding box
461 void BuildAnnulus();
462
463 // The actual annulus we're manipulating
464 vtkNew<vtkAnnulus> Annulus;
465
466 InteractionStateType RepresentationState = InteractionStateType::Outside;
467 int TranslationAxis = Axis::NONE;
468
469 // Keep track of event positions
470 vtkVector3d LastEventPosition;
471
472 // Controlling the push operation
473 double BumpDistance = 0.01;
474
475 // Controlling ivars
476 bool AlongXAxis = false;
477 bool AlongYAxis = false;
478 bool AlongZAxis = false;
479
480 // The facet resolution for rendering purposes.
481 int Resolution = 128;
482
483 // The bounding box is represented by a single voxel image data
486 vtkNew<vtkPolyDataMapper> OutlineMapper;
487 vtkNew<vtkActor> OutlineActor;
488 bool OutlineTranslation = true; // whether the outline can be moved
489 bool ScaleEnabled = true; // whether the widget can be scaled
490 bool OutsideBounds = true; // whether the widget can be moved outside input's bounds
491 vtkVector<double, 6> WidgetBounds;
492 bool ConstrainToWidgetBounds = true;
493
494 vtkNew<vtkPolyData> AnnulusPD;
495 vtkNew<vtkPolyDataMapper> AnnulusMapper;
496 vtkNew<vtkActor> AnnulusActor;
497 bool DrawAnnulus = true;
498
499 // Optional tubes are represented by extracting boundary edges and tubing
500 RadiusHandleRepresentation InnerRadiusRepresentation;
501 RadiusHandleRepresentation OuterRadiusRepresentation;
502 bool Tubing = true; // control whether tubing is on
503
504 // Axis representations
505 AxisHandleRepresentation LowerAxisRepresentation;
506 AxisHandleRepresentation UpperAxisRepresentation;
507
508 // Center positioning handle
509 vtkNew<vtkSphereSource> CenterHandleSource;
510 vtkNew<vtkPolyDataMapper> CenterHandleMapper;
511 vtkNew<vtkActor> CenterHandleActor;
512
513 // Do the picking
515 vtkNew<vtkCellPicker> AnnulusPicker;
516
517 // Properties used to control the appearance of selected objects and
518 // the manipulator in general.
519 vtkNew<vtkProperty> AxisProperty;
520 vtkNew<vtkProperty> SelectedAxisProperty;
521 vtkNew<vtkProperty> AnnulusProperty;
522 vtkNew<vtkProperty> SelectedAnnulusProperty;
523 vtkNew<vtkProperty> OutlineProperty;
524 vtkNew<vtkProperty> SelectedOutlineProperty;
525 vtkNew<vtkProperty> RadiusHandleProperty;
526 vtkNew<vtkProperty> SelectedRadiusHandleProperty;
527 vtkNew<vtkProperty> CenterHandleProperty;
528 vtkNew<vtkProperty> SelectedCenterHandleProperty;
529
530 vtkNew<vtkBox> BoundingBox;
531};
532
533VTK_ABI_NAMESPACE_END
534#endif
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
implicit function for a annulus
Definition vtkAnnulus.h:60
implicit function for a bounding box
Definition vtkBox.h:110
ray-cast cell picker for all kinds of Prop3Ds
generate polygonal cone
topologically and geometrically regular array of data
defining the representation for a vtkImplicitAnnulusWidget
vtkTypeBool HasTranslucentPolygonalGeometry() override
Methods supporting the rendering process.
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()
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 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...
double * GetCenter() const
Get the center of the annulus representation.
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
void BumpAnnulus(int dir, double factor)
Translate the annulus in the direction of the view vector by the specified BumpDistance.
void SetForegroundColor(double c[3])
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
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 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.
a simple class to control print indentation
Definition vtkIndent.h:108
create a line defined by two end points
Allocate and hold a VTK object.
Definition vtkNew.h:167
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
an ordered list of Props
represent surface properties of a geometric object
create a polygonal sphere centered at the origin
filter that generates tubes around lines
templated base type for storage of vectors.
Definition vtkVector.h:59
abstract specification for Viewports
Definition vtkViewport.h:65
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
@ Box
Definition vtkX3D.h:65
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_MAX_ANNULUS_RESOLUTION
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO