VTK  9.1.0
vtkSphereWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSphereWidget.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
59 #ifndef vtkSphereWidget_h
60 #define vtkSphereWidget_h
61 
62 #include "vtk3DWidget.h"
63 #include "vtkInteractionWidgetsModule.h" // For export macro
64 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
65 
66 class vtkActor;
67 class vtkPolyDataMapper;
68 class vtkPoints;
69 class vtkPolyData;
70 class vtkSphereSource;
71 class vtkSphere;
72 class vtkCellPicker;
73 class vtkProperty;
74 
75 #define VTK_SPHERE_OFF 0
76 #define VTK_SPHERE_WIREFRAME 1
77 #define VTK_SPHERE_SURFACE 2
78 
79 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget
80 {
81 public:
85  static vtkSphereWidget* New();
86 
87  vtkTypeMacro(vtkSphereWidget, vtk3DWidget);
88  void PrintSelf(ostream& os, vtkIndent indent) override;
89 
91 
94  void SetEnabled(int) override;
95  void PlaceWidget(double bounds[6]) override;
96  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
98  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
99  {
100  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
101  }
103 
105 
110  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
111  vtkGetMacro(Representation, int);
112  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
113  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
114  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
116 
121  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
122  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
123 
128  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
129  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
130 
132 
135  void SetRadius(double r)
136  {
137  if (r <= 0)
138  {
139  r = .00001;
140  }
141  this->SphereSource->SetRadius(r);
142  }
143  double GetRadius() { return this->SphereSource->GetRadius(); }
145 
147 
150  void SetCenter(double x, double y, double z) { this->SphereSource->SetCenter(x, y, z); }
151  void SetCenter(double x[3]) { this->SetCenter(x[0], x[1], x[2]); }
152  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
153  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
155 
157 
161  vtkSetMacro(Translation, vtkTypeBool);
162  vtkGetMacro(Translation, vtkTypeBool);
163  vtkBooleanMacro(Translation, vtkTypeBool);
164  vtkSetMacro(Scale, vtkTypeBool);
165  vtkGetMacro(Scale, vtkTypeBool);
166  vtkBooleanMacro(Scale, vtkTypeBool);
168 
170 
176  vtkSetMacro(HandleVisibility, vtkTypeBool);
177  vtkGetMacro(HandleVisibility, vtkTypeBool);
178  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
180 
182 
187  vtkSetVector3Macro(HandleDirection, double);
188  vtkGetVector3Macro(HandleDirection, double);
190 
192 
195  vtkGetVector3Macro(HandlePosition, double);
197 
206 
213  void GetSphere(vtkSphere* sphere);
214 
216 
220  vtkGetObjectMacro(SphereProperty, vtkProperty);
221  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
223 
225 
230  vtkGetObjectMacro(HandleProperty, vtkProperty);
231  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
233 
234 protected:
236  ~vtkSphereWidget() override;
237 
238  // Manage the state of the widget
239  int State;
241  {
242  Start = 0,
246  Outside
247  };
248 
249  // handles the events
250  static void ProcessEvents(
251  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
252 
253  // ProcessEvents() dispatches to these methods.
258  void OnMouseMove();
259 
260  // the sphere
264  void HighlightSphere(int highlight);
266 
267  // The representation of the sphere
269 
270  // Do the picking
272 
273  // Register internal Pickers within PickingManager
274  void RegisterPickers() override;
275 
276  // Methods to manipulate the sphere widget
279  void Translate(double* p1, double* p2);
280  void ScaleSphere(double* p1, double* p2, int X, int Y);
281  void MoveHandle(double* p1, double* p2, int X, int Y);
282  void PlaceHandle(double* center, double radius);
283 
284  // Properties used to control the appearance of selected objects and
285  // the manipulator in general.
291 
292  // Managing the handle
296  void HighlightHandle(int);
298  double HandleDirection[3];
299  double HandlePosition[3];
300  void SizeHandles() override;
301 
302 private:
303  vtkSphereWidget(const vtkSphereWidget&) = delete;
304  void operator=(const vtkSphereWidget&) = delete;
305 };
306 
307 #endif
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:71
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:46
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:67
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
represent and manipulate 3D points
Definition: vtkPoints.h:34
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:86
represent surface properties of a geometric object
Definition: vtkProperty.h:62
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:32
@ center
Definition: vtkX3D.h:236
@ radius
Definition: vtkX3D.h:258
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_SPHERE_SURFACE
#define VTK_SPHERE_OFF
#define VTK_SPHERE_WIREFRAME
#define VTK_SIZEHINT(...)