VTK  9.4.20250203
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
52#include "vtkInteractionWidgetsModule.h" // For export macro
53#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 vtkPolyData;
66class vtkBox;
67class vtkCellPicker;
68
69#define VTK_MAX_ANNULUS_RESOLUTION 2048
70
71class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkImplicitAnnulusRepresentation
73{
74public:
75 // Manage the state of the widget
77 {
78 Outside = 0,
79 Moving, // Generic state set by the widget
86 TranslatingCenter
87 };
88
91 void PrintSelf(ostream& os, vtkIndent indent) override;
92
94
99 void SetCenter(double x, double y, double z);
100 void SetCenter(double x[3]);
101 double* GetCenter() const VTK_SIZEHINT(3);
102 void GetCenter(double xyz[3]) const;
104
106
111 void SetAxis(double x, double y, double z);
112 void SetAxis(double a[3]);
113 double* GetAxis() const VTK_SIZEHINT(3);
114 void GetAxis(double a[3]) const;
116
118
124 void SetInnerRadius(double r);
125 double GetInnerRadius() const;
127
129
135 void SetOuterRadius(double r);
136 double GetOuterRadius() const;
138
140
148 void SetAlongXAxis(bool);
149 vtkGetMacro(AlongXAxis, bool);
150 vtkBooleanMacro(AlongXAxis, bool);
151 void SetAlongYAxis(bool);
152 vtkGetMacro(AlongYAxis, bool);
153 vtkBooleanMacro(AlongYAxis, bool);
154 void SetAlongZAxis(bool);
155 vtkGetMacro(AlongZAxis, bool);
156 vtkBooleanMacro(AlongZAxis, bool);
158
160
166 void SetDrawAnnulus(bool draw);
167 vtkGetMacro(DrawAnnulus, bool);
168 vtkBooleanMacro(DrawAnnulus, bool);
170
172
179 vtkSetClampMacro(Resolution, int, 8, VTK_MAX_ANNULUS_RESOLUTION);
180 vtkGetMacro(Resolution, int);
182
184
190 vtkSetMacro(Tubing, bool);
191 vtkGetMacro(Tubing, bool);
192 vtkBooleanMacro(Tubing, bool);
194
196
200 vtkSetMacro(ScaleEnabled, bool);
201 vtkGetMacro(ScaleEnabled, bool);
202 vtkBooleanMacro(ScaleEnabled, bool);
204
209 void GetPolyData(vtkPolyData* pd);
210
215 void UpdatePlacement();
216
218
221 vtkGetObjectMacro(AxisProperty, vtkProperty);
222 vtkGetObjectMacro(SelectedAxisProperty, vtkProperty);
224
226
230 vtkGetObjectMacro(AnnulusProperty, vtkProperty);
231 vtkGetObjectMacro(SelectedAnnulusProperty, vtkProperty);
233
235
239 vtkGetObjectMacro(RadiusHandleProperty, vtkProperty);
240 vtkGetObjectMacro(SelectedRadiusHandleProperty, vtkProperty);
242
244
249 void SetInteractionColor(double, double, double);
250 void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
251 void SetHandleColor(double, double, double);
252 void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
253 void SetForegroundColor(double, double, double);
254 void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
256
258
261 int ComputeInteractionState(int X, int Y, int modify = 0) override;
262 void PlaceWidget(double bounds[6]) override;
263 void BuildRepresentation() override;
264 void StartWidgetInteraction(double eventPos[2]) override;
265 void WidgetInteraction(double newEventPos[2]) override;
266 void EndWidgetInteraction(double newEventPos[2]) override;
268
270
273 double* GetBounds() override;
274 void GetActors(vtkPropCollection* pc) override;
280
282
288 vtkSetClampMacro(BumpDistance, double, 0.000001, 1);
289 vtkGetMacro(BumpDistance, double);
291
299 void BumpAnnulus(int dir, double factor);
300
307 void PushAnnulus(double distance);
308
318 vtkSetClampMacro(InteractionState, InteractionStateType, InteractionStateType::Outside,
319 InteractionStateType::TranslatingCenter);
320
322
327 vtkGetMacro(RepresentationState, InteractionStateType);
329
330 /*
331 * Register internal Pickers within PickingManager
332 */
333 void RegisterPickers() override;
334
335 void GetAnnulus(vtkAnnulus* annulus) const;
336
337protected:
340
341private:
342 struct AxisHandleRepresentation
343 {
344 vtkNew<vtkLineSource> LineSource;
345 vtkNew<vtkPolyDataMapper> LineMapper;
346 vtkNew<vtkActor> LineActor;
347
348 vtkNew<vtkConeSource> ArrowSource;
349 vtkNew<vtkPolyDataMapper> ArrowMapper;
350 vtkNew<vtkActor> ArrowActor;
351 };
352
353 struct RadiusHandleRepresentation
354 {
355 vtkNew<vtkPolyData> PolyData;
358 vtkNew<vtkActor> Actor;
359 };
360
362 void operator=(const vtkImplicitAnnulusRepresentation&) = delete;
363
364 void HighlightAnnulus(bool highlight);
365 void HighlightCenterHandle(bool highlight);
366 void HighlightAxis(bool highlight);
367 void HighlightInnerRadiusHandle(bool highlight);
368 void HighlightOuterRadiusHandle(bool highlight);
369
370 // Methods to manipulate the annulus
371 void Rotate(
372 double X, double Y, const vtkVector3d& p1, const vtkVector3d& p2, const vtkVector3d& vpn);
373 void TranslateAnnulus(const vtkVector3d& p1, const vtkVector3d& p2);
374 void TranslateRepresentation(const vtkVector3d& motion) override;
375 void TranslateCenter(const vtkVector3d& p1, const vtkVector3d& p2);
376 void TranslateCenterOnAxis(const vtkVector3d& p1, const vtkVector3d& p2);
377 void ScaleRadii(const vtkVector3d& p1, const vtkVector3d& p2);
378 void AdjustOuterRadius(double x, double y, const vtkVector3d& point);
379 void AdjustInnerRadius(double x, double y, const vtkVector3d& point);
380 void Scale(const vtkVector3d& p1, const vtkVector3d& p2, double X, double Y);
381 void SizeHandles();
382
383 // Generate the annulus polydata, cropped by the bounding box
384 void BuildAnnulus();
385
386 // The actual annulus we're manipulating
387 vtkNew<vtkAnnulus> Annulus;
388
389 InteractionStateType RepresentationState = InteractionStateType::Outside;
390
391 // Keep track of event positions
392 vtkVector3d LastEventPosition;
393
394 // Controlling the push operation
395 double BumpDistance = 0.01;
396
397 // Controlling ivars
398 bool AlongXAxis = false;
399 bool AlongYAxis = false;
400 bool AlongZAxis = false;
401
402 // The facet resolution for rendering purposes.
403 int Resolution = 128;
404
405 bool ScaleEnabled = true; // whether the widget can be scaled
406
407 vtkNew<vtkPolyData> AnnulusPD;
408 vtkNew<vtkPolyDataMapper> AnnulusMapper;
409 vtkNew<vtkActor> AnnulusActor;
410 bool DrawAnnulus = true;
411
412 // Optional tubes are represented by extracting boundary edges and tubing
413 RadiusHandleRepresentation InnerRadiusRepresentation;
414 RadiusHandleRepresentation OuterRadiusRepresentation;
415 bool Tubing = true; // control whether tubing is on
416
417 // Axis representations
418 AxisHandleRepresentation LowerAxisRepresentation;
419 AxisHandleRepresentation UpperAxisRepresentation;
420
421 // Center positioning handle
422 vtkNew<vtkSphereSource> CenterHandleSource;
423 vtkNew<vtkPolyDataMapper> CenterHandleMapper;
424 vtkNew<vtkActor> CenterHandleActor;
425
426 // Do the picking
428 vtkNew<vtkCellPicker> AnnulusPicker;
429
430 // Properties used to control the appearance of selected objects and
431 // the manipulator in general.
432 vtkNew<vtkProperty> AxisProperty;
433 vtkNew<vtkProperty> SelectedAxisProperty;
434 vtkNew<vtkProperty> AnnulusProperty;
435 vtkNew<vtkProperty> SelectedAnnulusProperty;
436 vtkNew<vtkProperty> RadiusHandleProperty;
437 vtkNew<vtkProperty> SelectedRadiusHandleProperty;
438 vtkNew<vtkProperty> CenterHandleProperty;
439 vtkNew<vtkProperty> SelectedCenterHandleProperty;
440
441 vtkNew<vtkBox> BoundingBox;
442};
443
444VTK_ABI_NAMESPACE_END
445#endif
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
implicit function for a annulus
Definition vtkAnnulus.h:60
Extends the vtkWidgetRepresentation to help positioning widget in space and how it should be displaye...
virtual void TranslateRepresentation(const vtkVector3d &)
Translate the representation, to be implemented in derived class.
implicit function for a bounding box
Definition vtkBox.h:110
ray-cast cell picker for all kinds of Prop3Ds
generate polygonal cone
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 GetAnnulus(vtkAnnulus *annulus) const
void BuildRepresentation() override
Methods to interface with the vtkImplicitAnnulusWidget.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
void SetHandleColor(double c[3])
Set the color of all the widgets handles (edges, axis, selected annulus) and their color during inter...
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 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...
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 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
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
abstract specification for Viewports
Definition vtkViewport.h:65
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_MAX_ANNULUS_RESOLUTION
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO