VTK  9.0.1
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 =========================================================================*/
62 #ifndef vtkSphereWidget_h
63 #define vtkSphereWidget_h
64 
65 #include "vtk3DWidget.h"
66 #include "vtkInteractionWidgetsModule.h" // For export macro
67 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
68 
69 class vtkActor;
70 class vtkPolyDataMapper;
71 class vtkPoints;
72 class vtkPolyData;
73 class vtkSphereSource;
74 class vtkSphere;
75 class vtkCellPicker;
76 class vtkProperty;
77 
78 #define VTK_SPHERE_OFF 0
79 #define VTK_SPHERE_WIREFRAME 1
80 #define VTK_SPHERE_SURFACE 2
81 
82 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget
83 {
84 public:
88  static vtkSphereWidget* New();
89 
90  vtkTypeMacro(vtkSphereWidget, vtk3DWidget);
91  void PrintSelf(ostream& os, vtkIndent indent) override;
92 
94 
97  void SetEnabled(int) override;
98  void PlaceWidget(double bounds[6]) override;
99  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
101  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
102  {
103  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
104  }
106 
108 
113  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
114  vtkGetMacro(Representation, int);
115  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
116  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
117  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
119 
124  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
125  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
126 
131  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
132  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
133 
135 
138  void SetRadius(double r)
139  {
140  if (r <= 0)
141  {
142  r = .00001;
143  }
144  this->SphereSource->SetRadius(r);
145  }
146  double GetRadius() { return this->SphereSource->GetRadius(); }
148 
150 
153  void SetCenter(double x, double y, double z) { this->SphereSource->SetCenter(x, y, z); }
154  void SetCenter(double x[3]) { this->SetCenter(x[0], x[1], x[2]); }
155  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
156  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
158 
160 
164  vtkSetMacro(Translation, vtkTypeBool);
165  vtkGetMacro(Translation, vtkTypeBool);
166  vtkBooleanMacro(Translation, vtkTypeBool);
167  vtkSetMacro(Scale, vtkTypeBool);
168  vtkGetMacro(Scale, vtkTypeBool);
169  vtkBooleanMacro(Scale, vtkTypeBool);
171 
173 
179  vtkSetMacro(HandleVisibility, vtkTypeBool);
180  vtkGetMacro(HandleVisibility, vtkTypeBool);
181  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
183 
185 
190  vtkSetVector3Macro(HandleDirection, double);
191  vtkGetVector3Macro(HandleDirection, double);
193 
195 
198  vtkGetVector3Macro(HandlePosition, double);
200 
209 
216  void GetSphere(vtkSphere* sphere);
217 
219 
223  vtkGetObjectMacro(SphereProperty, vtkProperty);
224  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
226 
228 
233  vtkGetObjectMacro(HandleProperty, vtkProperty);
234  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
236 
237 protected:
239  ~vtkSphereWidget() override;
240 
241  // Manage the state of the widget
242  int State;
244  {
245  Start = 0,
249  Outside
250  };
251 
252  // handles the events
253  static void ProcessEvents(
254  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
255 
256  // ProcessEvents() dispatches to these methods.
261  void OnMouseMove();
262 
263  // the sphere
267  void HighlightSphere(int highlight);
269 
270  // The representation of the sphere
272 
273  // Do the picking
275 
276  // Register internal Pickers within PickingManager
277  void RegisterPickers() override;
278 
279  // Methods to manipulate the sphere widget
282  void Translate(double* p1, double* p2);
283  void ScaleSphere(double* p1, double* p2, int X, int Y);
284  void MoveHandle(double* p1, double* p2, int X, int Y);
285  void PlaceHandle(double* center, double radius);
286 
287  // Properties used to control the appearance of selected objects and
288  // the manipulator in general.
294 
295  // Managing the handle
299  void HighlightHandle(int);
301  double HandleDirection[3];
302  double HandlePosition[3];
303  void SizeHandles() override;
304 
305 private:
306  vtkSphereWidget(const vtkSphereWidget&) = delete;
307  void operator=(const vtkSphereWidget&) = delete;
308 };
309 
310 #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:85
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])
~vtkSphereWidget() override
void OnRightButtonUp()
vtkProperty * SelectedSphereProperty
vtkTypeBool Scale
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
void SizeHandles() override
static void ProcessEvents(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
void SelectRepresentation()
vtkPolyDataMapper * HandleMapper
void SetCenter(double x[3])
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
This method is used to initially place the widget.
double * GetCenter()
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()
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()
vtkSphereSource * SphereSource
void SetRepresentationToOff()
void OnRightButtonDown()
void PlaceWidget() override
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(...)