VTK  9.4.20241221
vtkSphereRepresentation.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
56#ifndef vtkSphereRepresentation_h
57#define vtkSphereRepresentation_h
58
59#include "vtkInteractionWidgetsModule.h" // For export macro
60#include "vtkSphereSource.h" // Needed for fast access to the sphere source
62#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
63
64VTK_ABI_NAMESPACE_BEGIN
65class vtkActor;
67class vtkSphere;
68class vtkSphereSource;
69class vtkCellPicker;
70class vtkProperty;
71class vtkPolyData;
72class vtkPoints;
74class vtkTransform;
75class vtkDoubleArray;
76class vtkMatrix4x4;
77class vtkTextMapper;
78class vtkActor2D;
79class vtkTextProperty;
80class vtkLineSource;
81class vtkCursor3D;
82
83#define VTK_SPHERE_OFF 0
84#define VTK_SPHERE_WIREFRAME 1
85#define VTK_SPHERE_SURFACE 2
86
87class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkSphereRepresentation
89{
90public:
95
97
101 void PrintSelf(ostream& os, vtkIndent indent) override;
103
104 // Used to manage the state of the widget
105 enum
106 {
107 Outside = 0,
111 Scaling
112 };
113
115
119 vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
120 vtkGetMacro(Representation, int);
121 void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
122 void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
123 void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
125
129 void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
130 int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
131
135 void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
136 int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
137
143 void SetCenter(double c[3]);
144 void SetCenter(double x, double y, double z)
145 {
146 double c[3];
147 c[0] = x;
148 c[1] = y;
149 c[2] = z;
150 this->SetCenter(c);
151 }
152 double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
153 void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
154
159 void SetRadius(double r);
160 double GetRadius() { return this->SphereSource->GetRadius(); }
161
163
169 vtkSetMacro(HandleVisibility, vtkTypeBool);
170 vtkGetMacro(HandleVisibility, vtkTypeBool);
171 vtkBooleanMacro(HandleVisibility, vtkTypeBool);
173
175
179 void SetHandlePosition(double handle[3]);
180 void SetHandlePosition(double x, double y, double z)
181 {
182 double p[3];
183 p[0] = x;
184 p[1] = y;
185 p[2] = z;
186 this->SetHandlePosition(p);
187 }
188 vtkGetVector3Macro(HandlePosition, double);
190
192
197 void SetHandleDirection(double dir[3]);
198 void SetHandleDirection(double dx, double dy, double dz)
199 {
200 double d[3];
201 d[0] = dx;
202 d[1] = dy;
203 d[2] = dz;
204 this->SetHandleDirection(d);
205 }
206 vtkGetVector3Macro(HandleDirection, double);
208
210
217 vtkSetMacro(HandleText, vtkTypeBool);
218 vtkGetMacro(HandleText, vtkTypeBool);
219 vtkBooleanMacro(HandleText, vtkTypeBool);
221
223
227 vtkSetMacro(RadialLine, vtkTypeBool);
228 vtkGetMacro(RadialLine, vtkTypeBool);
229 vtkBooleanMacro(RadialLine, vtkTypeBool);
231
233
237 vtkSetMacro(CenterCursor, bool);
238 vtkGetMacro(CenterCursor, bool);
239 vtkBooleanMacro(CenterCursor, bool);
241
250
257 void GetSphere(vtkSphere* sphere);
258
260
264 vtkGetObjectMacro(SphereProperty, vtkProperty);
265 vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
267
269
274 vtkGetObjectMacro(HandleProperty, vtkProperty);
275 vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
277
279
283 vtkGetObjectMacro(HandleTextProperty, vtkTextProperty);
285
287
291 vtkGetObjectMacro(RadialLineProperty, vtkProperty);
293
295
299 void SetInteractionColor(double, double, double);
300 void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
301 void SetHandleColor(double, double, double);
302 void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
303 void SetForegroundColor(double, double, double);
304 void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
306
316 void SetInteractionState(int state);
317
319
324 void PlaceWidget(double bounds[6]) override;
325 virtual void PlaceWidget(double center[3], double handlePosition[3]);
326 void BuildRepresentation() override;
327 int ComputeInteractionState(int X, int Y, int modify = 0) override;
328 void StartWidgetInteraction(double e[2]) override;
329 void WidgetInteraction(double e[2]) override;
330 double* GetBounds() override;
332
334
343
344 /*
345 * Register internal Pickers within PickingManager
346 */
347 void RegisterPickers() override;
348
350
354 vtkGetMacro(TranslationAxis, int);
355 vtkSetClampMacro(TranslationAxis, int, -1, 2);
357
359
362 void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
363 void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
364 void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
365 void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
367
369
372 bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
374
375protected:
378
379 // Manage how the representation appears
380 double LastEventPosition[3];
381
383
384 // the sphere
388 void HighlightSphere(int highlight);
389
390 // The representation of the sphere
392
393 // Do the picking
396 double LastPickPosition[3];
397
398 // Methods to manipulate the sphere widget
399 void Translate(const double* p1, const double* p2);
400 void Scale(const double* p1, const double* p2, int X, int Y);
401 void PlaceHandle(const double* center, double radius);
402 virtual void SizeHandles();
403
404 // Method to adapt the center cursor bounds
405 // so it always have the same pixel size on screen
407
408 // Properties used to control the appearance of selected objects and
409 // the manipulator in general.
415
416 // Managing the handle
422 double HandleDirection[3];
423 double HandlePosition[3];
424
425 // Manage the handle label
430
431 // Manage the radial line segment
437
438 // Managing the center cursor
443
444private:
446 void operator=(const vtkSphereRepresentation&) = delete;
447};
448
449VTK_ABI_NAMESPACE_END
450#endif
a actor that draws 2D data
Definition vtkActor2D.h:145
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
ray-cast cell picker for all kinds of Prop3Ds
generate a 3D cursor representation
Definition vtkCursor3D.h:48
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition vtkIndent.h:108
create a line defined by two end points
represent and manipulate 4x4 transformation matrices
represent and manipulate 3D points
Definition vtkPoints.h:139
Superclass for algorithms that produce only polydata as output.
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
represent surface properties of a geometric object
a class defining the representation for the vtkSphereWidget2
void SetHandleDirection(double dx, double dy, double dz)
Set/Get the direction vector of the handle relative to the center of the sphere.
void SetPhiResolution(int r)
Set/Get the resolution of the sphere in the phi direction.
void SetRepresentationToWireframe()
Set the representation (i.e., appearance) of the sphere.
void BuildRepresentation() override
These are methods that satisfy vtkWidgetRepresentation's API.
void GetPolyData(vtkPolyData *pd)
Grab the polydata (including points) that defines the sphere.
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for type information and to print out the contents of the class.
void SetForegroundColor(double, double, double)
Set the interaction color of sphere and handle.
void SetHandleDirection(double dir[3])
Set/Get the direction vector of the handle relative to the center of the sphere.
bool IsTranslationConstrained()
Returns true if ConstrainedAxis.
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
void SetCenter(double x, double y, double z)
int ComputeInteractionState(int X, int Y, int modify=0) override
These are methods that satisfy vtkWidgetRepresentation's API.
static vtkSphereRepresentation * New()
Instantiate the class.
double * GetBounds() override
These are methods that satisfy vtkWidgetRepresentation's API.
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
void SetForegroundColor(double c[3])
Set the interaction color of sphere and handle.
void SetHandleColor(double, double, double)
Set the interaction color of sphere and handle.
void SetInteractionColor(double c[3])
Set the interaction color of sphere and handle.
void SetRepresentationToOff()
Set the representation (i.e., appearance) of the sphere.
virtual void PlaceWidget(double center[3], double handlePosition[3])
These are methods that satisfy vtkWidgetRepresentation's API.
void SetCenter(double c[3])
Set/Get the center position of the sphere.
void PlaceHandle(const double *center, double radius)
vtkPolyDataMapper * RadialLineMapper
int RenderOpaqueGeometry(vtkViewport *) override
Methods supporting, and required by, the rendering process.
void SetThetaResolution(int r)
Set/Get the resolution of the sphere in the theta direction.
void SetHandleColor(double c[3])
Set the interaction color of sphere and handle.
void SetInteractionState(int state)
The interaction state may be set from a widget (e.g., vtkSphereWidget2) or other object.
void SetInteractionColor(double, double, double)
Set the interaction color of sphere and handle.
void GetSphere(vtkSphere *sphere)
Get the spherical implicit function defined by this widget.
void HighlightSphere(int highlight)
void SetRadius(double r)
Set/Get the radius of sphere.
void PlaceWidget(double bounds[6]) override
These are methods that satisfy vtkWidgetRepresentation's API.
int RenderTranslucentPolygonalGeometry(vtkViewport *) override
Methods supporting, and required by, the rendering process.
void SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
void WidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation's API.
~vtkSphereRepresentation() override
void SetHandlePosition(double x, double y, double z)
Set/Get the position of the handle.
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
int RenderOverlay(vtkViewport *) override
Methods supporting, and required by, the rendering process.
void SetRepresentationToSurface()
Set the representation (i.e., appearance) of the sphere.
void SetHandlePosition(double handle[3])
Set/Get the position of the handle.
virtual void SizeHandles()
void ReleaseGraphicsResources(vtkWindow *) override
Methods supporting, and required by, the rendering process.
void Scale(const double *p1, const double *p2, int X, int Y)
void StartWidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation's API.
virtual void AdaptCenterCursorBounds()
vtkTypeBool HasTranslucentPolygonalGeometry() override
Methods supporting, and required by, the rendering process.
void Translate(const double *p1, const double *p2)
create a polygonal sphere centered at the origin
implicit function for a sphere
Definition vtkSphere.h:133
2D text annotation
represent text properties.
describes linear transformations via a 4x4 matrix
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
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_SPHERE_SURFACE
#define VTK_SPHERE_OFF
#define VTK_SPHERE_WIREFRAME
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO