VTK  9.3.0
vtkSphereWidget.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 vtkSphereWidget_h
57 #define vtkSphereWidget_h
58 
59 #include "vtk3DWidget.h"
60 #include "vtkInteractionWidgetsModule.h" // For export macro
61 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
62 
63 VTK_ABI_NAMESPACE_BEGIN
64 class vtkActor;
65 class vtkPolyDataMapper;
66 class vtkPoints;
67 class vtkPolyData;
68 class vtkSphereSource;
69 class vtkSphere;
70 class vtkCellPicker;
71 class vtkProperty;
72 
73 #define VTK_SPHERE_OFF 0
74 #define VTK_SPHERE_WIREFRAME 1
75 #define VTK_SPHERE_SURFACE 2
76 
77 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget
78 {
79 public:
83  static vtkSphereWidget* New();
84 
85  vtkTypeMacro(vtkSphereWidget, vtk3DWidget);
86  void PrintSelf(ostream& os, vtkIndent indent) override;
87 
89 
92  void SetEnabled(int) override;
93  void PlaceWidget(double bounds[6]) override;
94  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
96  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
97  {
98  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
99  }
101 
103 
108  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
109  vtkGetMacro(Representation, int);
110  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
111  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
112  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
114 
119  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
120  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
121 
126  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
127  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
128 
130 
133  void SetRadius(double r)
134  {
135  if (r <= 0)
136  {
137  r = .00001;
138  }
139  this->SphereSource->SetRadius(r);
140  }
141  double GetRadius() { return this->SphereSource->GetRadius(); }
143 
145 
148  void SetCenter(double x, double y, double z) { this->SphereSource->SetCenter(x, y, z); }
149  void SetCenter(double x[3]) { this->SetCenter(x[0], x[1], x[2]); }
150  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
151  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
153 
155 
159  vtkSetMacro(Translation, vtkTypeBool);
160  vtkGetMacro(Translation, vtkTypeBool);
161  vtkBooleanMacro(Translation, vtkTypeBool);
162  vtkSetMacro(Scale, vtkTypeBool);
163  vtkGetMacro(Scale, vtkTypeBool);
164  vtkBooleanMacro(Scale, vtkTypeBool);
166 
168 
174  vtkSetMacro(HandleVisibility, vtkTypeBool);
175  vtkGetMacro(HandleVisibility, vtkTypeBool);
176  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
178 
180 
185  vtkSetVector3Macro(HandleDirection, double);
186  vtkGetVector3Macro(HandleDirection, double);
188 
190 
193  vtkGetVector3Macro(HandlePosition, double);
195 
204 
211  void GetSphere(vtkSphere* sphere);
212 
214 
218  vtkGetObjectMacro(SphereProperty, vtkProperty);
219  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
221 
223 
228  vtkGetObjectMacro(HandleProperty, vtkProperty);
229  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
231 
232 protected:
234  ~vtkSphereWidget() override;
235 
236  // Manage the state of the widget
237  int State;
239  {
240  Start = 0,
244  Outside
245  };
246 
247  // handles the events
248  static void ProcessEvents(
249  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
250 
251  // ProcessEvents() dispatches to these methods.
256  void OnMouseMove();
257 
258  // the sphere
262  void HighlightSphere(int highlight);
264 
265  // The representation of the sphere
267 
268  // Do the picking
270 
271  // Register internal Pickers within PickingManager
272  void RegisterPickers() override;
273 
274  // Methods to manipulate the sphere widget
277  void Translate(double* p1, double* p2);
278  void ScaleSphere(double* p1, double* p2, int X, int Y);
279  void MoveHandle(double* p1, double* p2, int X, int Y);
280  void PlaceHandle(double* center, double radius);
281 
282  // Properties used to control the appearance of selected objects and
283  // the manipulator in general.
289 
290  // Managing the handle
294  void HighlightHandle(int);
296  double HandleDirection[3];
297  double HandlePosition[3];
298  void SizeHandles() override;
299 
300 private:
301  vtkSphereWidget(const vtkSphereWidget&) = delete;
302  void operator=(const vtkSphereWidget&) = delete;
303 };
304 
305 VTK_ABI_NAMESPACE_END
306 #endif
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:60
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
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
represent and manipulate 3D points
Definition: vtkPoints.h:38
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
create a polygonal sphere centered at the origin
3D widget for manipulating a sphere
vtkCellPicker * Picker
void GetCenter(double xyz[3])
Set/Get the center of the sphere.
~vtkSphereWidget() override
void OnRightButtonUp()
vtkProperty * SelectedSphereProperty
vtkTypeBool Scale
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Methods that satisfy the superclass' API.
void SizeHandles() override
static void ProcessEvents(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
void SelectRepresentation()
vtkPolyDataMapper * HandleMapper
void SetCenter(double x[3])
Set/Get the center of the sphere.
double GetRadius()
Set/Get the radius of sphere.
void HighlightHandle(int)
void SetCenter(double x, double y, double z)
Set/Get the center of the sphere.
void CreateDefaultProperties()
void SetEnabled(int) override
Methods that satisfy the superclass' API.
void GetPolyData(vtkPolyData *pd)
Grab the polydata (including points) that defines the sphere.
void SetRadius(double r)
Set/Get the radius of sphere.
vtkSphereSource * HandleSource
void PlaceWidget(double bounds[6]) override
Methods that satisfy the superclass' API.
double * GetCenter()
Set/Get the center of the sphere.
vtkTypeBool HandleVisibility
void SetThetaResolution(int r)
Set/Get the resolution of the sphere in the Theta direction.
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
void OnLeftButtonUp()
vtkPolyDataMapper * SphereMapper
vtkProperty * SphereProperty
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void OnLeftButtonDown()
void Translate(double *p1, double *p2)
vtkActor * HandleActor
void HighlightSphere(int highlight)
void MoveHandle(double *p1, double *p2, int X, int Y)
vtkTypeBool Translation
void SetRepresentationToSurface()
Set the representation of the sphere.
void SetPhiResolution(int r)
Set/Get the resolution of the sphere in the Phi direction.
vtkProperty * HandleProperty
void GetSphere(vtkSphere *sphere)
Get the spherical implicit function defined by this widget.
vtkActor * SphereActor
void SetRepresentationToWireframe()
Set the representation of the sphere.
vtkSphereSource * SphereSource
void SetRepresentationToOff()
Set the representation of the sphere.
void OnRightButtonDown()
void PlaceWidget() override
Methods that satisfy the superclass' API.
void ScaleSphere(double *p1, double *p2, int X, int Y)
static vtkSphereWidget * New()
Instantiate the object.
vtkProperty * SelectedHandleProperty
void PlaceHandle(double *center, double radius)
implicit function for a sphere
Definition: vtkSphere.h:33
@ 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(...)