VTK  9.3.20240328
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 
63 VTK_ABI_NAMESPACE_BEGIN
64 class vtkActor;
65 class vtkPolyDataMapper;
66 class vtkSphere;
67 class vtkSphereSource;
68 class vtkCellPicker;
69 class vtkProperty;
70 class vtkPolyData;
71 class vtkPoints;
73 class vtkTransform;
74 class vtkDoubleArray;
75 class vtkMatrix4x4;
76 class vtkTextMapper;
77 class vtkActor2D;
78 class vtkTextProperty;
79 class vtkLineSource;
80 class vtkCursor3D;
81 
82 #define VTK_SPHERE_OFF 0
83 #define VTK_SPHERE_WIREFRAME 1
84 #define VTK_SPHERE_SURFACE 2
85 
86 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereRepresentation : public vtkWidgetRepresentation
87 {
88 public:
93 
95 
99  void PrintSelf(ostream& os, vtkIndent indent) override;
101 
102  // Used to manage the state of the widget
103  enum
104  {
105  Outside = 0,
109  Scaling
110  };
111 
113 
117  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
118  vtkGetMacro(Representation, int);
119  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
120  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
121  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
123 
127  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
128  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
129 
133  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
134  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
135 
141  void SetCenter(double c[3]);
142  void SetCenter(double x, double y, double z)
143  {
144  double c[3];
145  c[0] = x;
146  c[1] = y;
147  c[2] = z;
148  this->SetCenter(c);
149  }
150  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
151  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
152 
157  void SetRadius(double r);
158  double GetRadius() { return this->SphereSource->GetRadius(); }
159 
161 
167  vtkSetMacro(HandleVisibility, vtkTypeBool);
168  vtkGetMacro(HandleVisibility, vtkTypeBool);
169  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
171 
173 
177  void SetHandlePosition(double handle[3]);
178  void SetHandlePosition(double x, double y, double z)
179  {
180  double p[3];
181  p[0] = x;
182  p[1] = y;
183  p[2] = z;
184  this->SetHandlePosition(p);
185  }
186  vtkGetVector3Macro(HandlePosition, double);
188 
190 
195  void SetHandleDirection(double dir[3]);
196  void SetHandleDirection(double dx, double dy, double dz)
197  {
198  double d[3];
199  d[0] = dx;
200  d[1] = dy;
201  d[2] = dz;
202  this->SetHandleDirection(d);
203  }
204  vtkGetVector3Macro(HandleDirection, double);
206 
208 
215  vtkSetMacro(HandleText, vtkTypeBool);
216  vtkGetMacro(HandleText, vtkTypeBool);
217  vtkBooleanMacro(HandleText, vtkTypeBool);
219 
221 
225  vtkSetMacro(RadialLine, vtkTypeBool);
226  vtkGetMacro(RadialLine, vtkTypeBool);
227  vtkBooleanMacro(RadialLine, vtkTypeBool);
229 
231 
235  vtkSetMacro(CenterCursor, bool);
236  vtkGetMacro(CenterCursor, bool);
237  vtkBooleanMacro(CenterCursor, bool);
239 
248 
255  void GetSphere(vtkSphere* sphere);
256 
258 
262  vtkGetObjectMacro(SphereProperty, vtkProperty);
263  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
265 
267 
272  vtkGetObjectMacro(HandleProperty, vtkProperty);
273  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
275 
277 
281  vtkGetObjectMacro(HandleTextProperty, vtkTextProperty);
283 
285 
289  vtkGetObjectMacro(RadialLineProperty, vtkProperty);
291 
293 
297  void SetInteractionColor(double, double, double);
298  void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
299  void SetHandleColor(double, double, double);
300  void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
301  void SetForegroundColor(double, double, double);
302  void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
304 
314  void SetInteractionState(int state);
315 
317 
322  void PlaceWidget(double bounds[6]) override;
323  virtual void PlaceWidget(double center[3], double handlePosition[3]);
324  void BuildRepresentation() override;
325  int ComputeInteractionState(int X, int Y, int modify = 0) override;
326  void StartWidgetInteraction(double e[2]) override;
327  void WidgetInteraction(double e[2]) override;
328  double* GetBounds() override;
330 
332 
338  int RenderOverlay(vtkViewport*) override;
341 
342  /*
343  * Register internal Pickers within PickingManager
344  */
345  void RegisterPickers() override;
346 
348 
352  vtkGetMacro(TranslationAxis, int);
353  vtkSetClampMacro(TranslationAxis, int, -1, 2);
355 
357 
360  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
361  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
362  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
363  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
365 
367 
370  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
372 
373 protected:
376 
377  // Manage how the representation appears
378  double LastEventPosition[3];
379 
381 
382  // the sphere
386  void HighlightSphere(int highlight);
387 
388  // The representation of the sphere
390 
391  // Do the picking
394  double LastPickPosition[3];
395 
396  // Methods to manipulate the sphere widget
397  void Translate(const double* p1, const double* p2);
398  void Scale(const double* p1, const double* p2, int X, int Y);
399  void PlaceHandle(const double* center, double radius);
400  virtual void SizeHandles();
401 
402  // Method to adapt the center cursor bounds
403  // so it always have the same pixel size on screen
404  virtual void AdaptCenterCursorBounds();
405 
406  // Properties used to control the appearance of selected objects and
407  // the manipulator in general.
413 
414  // Managing the handle
418  void HighlightHandle(int);
420  double HandleDirection[3];
421  double HandlePosition[3];
422 
423  // Manage the handle label
428 
429  // Manage the radial line segment
435 
436  // Managing the center cursor
441 
442 private:
444  void operator=(const vtkSphereRepresentation&) = delete;
445 };
446 
447 VTK_ABI_NAMESPACE_END
448 #endif
a actor that draws 2D data
Definition: vtkActor2D.h:144
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:150
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:91
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
Definition: vtkMatrix4x4.h:140
represent and manipulate 3D points
Definition: vtkPoints.h:138
Superclass for algorithms that produce only polydata as output.
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:180
represent surface properties of a geometric object
Definition: vtkProperty.h:166
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.
vtkPolyDataMapper * HandleMapper
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.
vtkPolyDataMapper * CenterMapper
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.
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.
vtkTextProperty * HandleTextProperty
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.
vtkPolyDataMapper * SphereMapper
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)
static vtkSphereRepresentation * New()
Instantiate the class.
void StartWidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation's API.
virtual void AdaptCenterCursorBounds()
double * GetBounds() override
These are methods that satisfy vtkWidgetRepresentation's API.
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
Definition: vtkTransform.h:159
abstract specification for Viewports
Definition: vtkViewport.h:64
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:47
@ dir
Definition: vtkX3D.h:324
@ center
Definition: vtkX3D.h:230
@ radius
Definition: vtkX3D.h:252
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_SPHERE_SURFACE
#define VTK_SPHERE_OFF
#define VTK_SPHERE_WIREFRAME
#define VTK_SIZEHINT(...)