VTK  9.3.0
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
46 #ifndef vtkSphereRepresentation_h
47 #define vtkSphereRepresentation_h
48 
49 #include "vtkInteractionWidgetsModule.h" // For export macro
50 #include "vtkSphereSource.h" // Needed for fast access to the sphere source
52 
53 VTK_ABI_NAMESPACE_BEGIN
54 class vtkActor;
55 class vtkPolyDataMapper;
56 class vtkSphere;
57 class vtkSphereSource;
58 class vtkCellPicker;
59 class vtkProperty;
60 class vtkPolyData;
61 class vtkPoints;
63 class vtkTransform;
64 class vtkDoubleArray;
65 class vtkMatrix4x4;
66 class vtkTextMapper;
67 class vtkActor2D;
68 class vtkTextProperty;
69 class vtkLineSource;
70 class vtkCursor3D;
71 
72 #define VTK_SPHERE_OFF 0
73 #define VTK_SPHERE_WIREFRAME 1
74 #define VTK_SPHERE_SURFACE 2
75 
76 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereRepresentation : public vtkWidgetRepresentation
77 {
78 public:
83 
85 
89  void PrintSelf(ostream& os, vtkIndent indent) override;
91 
92  // Used to manage the state of the widget
93  enum
94  {
95  Outside = 0,
99  Scaling
100  };
101 
103 
107  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
108  vtkGetMacro(Representation, int);
109  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
110  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
111  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
113 
117  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
118  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
119 
123  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
124  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
125 
131  void SetCenter(double c[3]);
132  void SetCenter(double x, double y, double z)
133  {
134  double c[3];
135  c[0] = x;
136  c[1] = y;
137  c[2] = z;
138  this->SetCenter(c);
139  }
140  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
141  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
142 
147  void SetRadius(double r);
148  double GetRadius() { return this->SphereSource->GetRadius(); }
149 
151 
157  vtkSetMacro(HandleVisibility, vtkTypeBool);
158  vtkGetMacro(HandleVisibility, vtkTypeBool);
159  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
161 
163 
167  void SetHandlePosition(double handle[3]);
168  void SetHandlePosition(double x, double y, double z)
169  {
170  double p[3];
171  p[0] = x;
172  p[1] = y;
173  p[2] = z;
174  this->SetHandlePosition(p);
175  }
176  vtkGetVector3Macro(HandlePosition, double);
178 
180 
185  void SetHandleDirection(double dir[3]);
186  void SetHandleDirection(double dx, double dy, double dz)
187  {
188  double d[3];
189  d[0] = dx;
190  d[1] = dy;
191  d[2] = dz;
192  this->SetHandleDirection(d);
193  }
194  vtkGetVector3Macro(HandleDirection, double);
196 
198 
205  vtkSetMacro(HandleText, vtkTypeBool);
206  vtkGetMacro(HandleText, vtkTypeBool);
207  vtkBooleanMacro(HandleText, vtkTypeBool);
209 
211 
215  vtkSetMacro(RadialLine, vtkTypeBool);
216  vtkGetMacro(RadialLine, vtkTypeBool);
217  vtkBooleanMacro(RadialLine, vtkTypeBool);
219 
221 
225  vtkSetMacro(CenterCursor, bool);
226  vtkGetMacro(CenterCursor, bool);
227  vtkBooleanMacro(CenterCursor, bool);
229 
238 
245  void GetSphere(vtkSphere* sphere);
246 
248 
252  vtkGetObjectMacro(SphereProperty, vtkProperty);
253  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
255 
257 
262  vtkGetObjectMacro(HandleProperty, vtkProperty);
263  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
265 
267 
271  vtkGetObjectMacro(HandleTextProperty, vtkTextProperty);
273 
275 
279  vtkGetObjectMacro(RadialLineProperty, vtkProperty);
281 
283 
287  void SetInteractionColor(double, double, double);
288  void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
289  void SetHandleColor(double, double, double);
290  void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
291  void SetForegroundColor(double, double, double);
292  void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
294 
304  void SetInteractionState(int state);
305 
307 
312  void PlaceWidget(double bounds[6]) override;
313  virtual void PlaceWidget(double center[3], double handlePosition[3]);
314  void BuildRepresentation() override;
315  int ComputeInteractionState(int X, int Y, int modify = 0) override;
316  void StartWidgetInteraction(double e[2]) override;
317  void WidgetInteraction(double e[2]) override;
318  double* GetBounds() override;
320 
322 
328  int RenderOverlay(vtkViewport*) override;
331 
332  /*
333  * Register internal Pickers within PickingManager
334  */
335  void RegisterPickers() override;
336 
338 
342  vtkGetMacro(TranslationAxis, int);
343  vtkSetClampMacro(TranslationAxis, int, -1, 2);
345 
347 
350  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
351  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
352  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
353  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
355 
357 
360  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
362 
363 protected:
366 
367  // Manage how the representation appears
368  double LastEventPosition[3];
369 
371 
372  // the sphere
376  void HighlightSphere(int highlight);
377 
378  // The representation of the sphere
380 
381  // Do the picking
384  double LastPickPosition[3];
385 
386  // Methods to manipulate the sphere widget
387  void Translate(const double* p1, const double* p2);
388  void Scale(const double* p1, const double* p2, int X, int Y);
389  void PlaceHandle(const double* center, double radius);
390  virtual void SizeHandles();
391 
392  // Method to adapt the center cursor bounds
393  // so it always have the same pixel size on screen
394  virtual void AdaptCenterCursorBounds();
395 
396  // Properties used to control the appearance of selected objects and
397  // the manipulator in general.
403 
404  // Managing the handle
408  void HighlightHandle(int);
410  double HandleDirection[3];
411  double HandlePosition[3];
412 
413  // Manage the handle label
418 
419  // Manage the radial line segment
425 
426  // Managing the center cursor
431 
432 private:
434  void operator=(const vtkSphereRepresentation&) = delete;
435 };
436 
437 VTK_ABI_NAMESPACE_END
438 #endif
a actor that draws 2D data
Definition: vtkActor2D.h:44
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:50
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:71
generate a 3D cursor representation
Definition: vtkCursor3D.h:38
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:38
create a line defined by two end points
Definition: vtkLineSource.h:62
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:40
represent and manipulate 3D points
Definition: vtkPoints.h:38
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:89
represent surface properties of a geometric object
Definition: vtkProperty.h:66
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:33
2D text annotation
Definition: vtkTextMapper.h:49
represent text properties.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:59
abstract specification for Viewports
Definition: vtkViewport.h:54
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
@ 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(...)