VTK  9.2.6
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 =========================================================================*/
68 #ifndef vtkSphereWidget_h
69 #define vtkSphereWidget_h
70 
71 #include "vtk3DWidget.h"
72 #include "vtkInteractionWidgetsModule.h" // For export macro
73 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
74 
75 class vtkActor;
76 class vtkPolyDataMapper;
77 class vtkPoints;
78 class vtkPolyData;
79 class vtkSphereSource;
80 class vtkSphere;
81 class vtkCellPicker;
82 class vtkProperty;
83 
84 #define VTK_SPHERE_OFF 0
85 #define VTK_SPHERE_WIREFRAME 1
86 #define VTK_SPHERE_SURFACE 2
87 
88 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget
89 {
90 public:
94  static vtkSphereWidget* New();
95 
96  vtkTypeMacro(vtkSphereWidget, vtk3DWidget);
97  void PrintSelf(ostream& os, vtkIndent indent) override;
98 
100 
103  void SetEnabled(int) override;
104  void PlaceWidget(double bounds[6]) override;
105  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
107  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
108  {
109  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
110  }
112 
114 
119  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
120  vtkGetMacro(Representation, int);
121  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
122  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
123  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
125 
130  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
131  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
132 
137  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
138  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
139 
141 
144  void SetRadius(double r)
145  {
146  if (r <= 0)
147  {
148  r = .00001;
149  }
150  this->SphereSource->SetRadius(r);
151  }
152  double GetRadius() { return this->SphereSource->GetRadius(); }
154 
156 
159  void SetCenter(double x, double y, double z) { this->SphereSource->SetCenter(x, y, z); }
160  void SetCenter(double x[3]) { this->SetCenter(x[0], x[1], x[2]); }
161  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
162  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
164 
166 
170  vtkSetMacro(Translation, vtkTypeBool);
171  vtkGetMacro(Translation, vtkTypeBool);
172  vtkBooleanMacro(Translation, vtkTypeBool);
173  vtkSetMacro(Scale, vtkTypeBool);
174  vtkGetMacro(Scale, vtkTypeBool);
175  vtkBooleanMacro(Scale, vtkTypeBool);
177 
179 
185  vtkSetMacro(HandleVisibility, vtkTypeBool);
186  vtkGetMacro(HandleVisibility, vtkTypeBool);
187  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
189 
191 
196  vtkSetVector3Macro(HandleDirection, double);
197  vtkGetVector3Macro(HandleDirection, double);
199 
201 
204  vtkGetVector3Macro(HandlePosition, double);
206 
215 
222  void GetSphere(vtkSphere* sphere);
223 
225 
229  vtkGetObjectMacro(SphereProperty, vtkProperty);
230  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
232 
234 
239  vtkGetObjectMacro(HandleProperty, vtkProperty);
240  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
242 
243 protected:
245  ~vtkSphereWidget() override;
246 
247  // Manage the state of the widget
248  int State;
250  {
251  Start = 0,
255  Outside
256  };
257 
258  // handles the events
259  static void ProcessEvents(
260  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
261 
262  // ProcessEvents() dispatches to these methods.
267  void OnMouseMove();
268 
269  // the sphere
273  void HighlightSphere(int highlight);
275 
276  // The representation of the sphere
278 
279  // Do the picking
281 
282  // Register internal Pickers within PickingManager
283  void RegisterPickers() override;
284 
285  // Methods to manipulate the sphere widget
288  void Translate(double* p1, double* p2);
289  void ScaleSphere(double* p1, double* p2, int X, int Y);
290  void MoveHandle(double* p1, double* p2, int X, int Y);
291  void PlaceHandle(double* center, double radius);
292 
293  // Properties used to control the appearance of selected objects and
294  // the manipulator in general.
300 
301  // Managing the handle
305  void HighlightHandle(int);
307  double HandleDirection[3];
308  double HandlePosition[3];
309  void SizeHandles() override;
310 
311 private:
312  vtkSphereWidget(const vtkSphereWidget&) = delete;
313  void operator=(const vtkSphereWidget&) = delete;
314 };
315 
316 #endif
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:71
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:61
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:82
a simple class to control print indentation
Definition: vtkIndent.h:49
abstract base class for most VTK objects
Definition: vtkObject.h:72
represent and manipulate 3D points
Definition: vtkPoints.h:49
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:100
represent surface properties of a geometric object
Definition: vtkProperty.h:77
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:44
@ 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(...)