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 =========================================================================*/
53 #ifndef vtkSphereWidget_h
54 #define vtkSphereWidget_h
55 
56 #include "vtk3DWidget.h"
57 #include "vtkInteractionWidgetsModule.h" // For export macro
58 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
59 
60 class vtkActor;
61 class vtkPolyDataMapper;
62 class vtkPoints;
63 class vtkPolyData;
64 class vtkSphereSource;
65 class vtkSphere;
66 class vtkCellPicker;
67 class vtkProperty;
68 
69 #define VTK_SPHERE_OFF 0
70 #define VTK_SPHERE_WIREFRAME 1
71 #define VTK_SPHERE_SURFACE 2
72 
73 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget
74 {
75 public:
79  static vtkSphereWidget* New();
80 
81  vtkTypeMacro(vtkSphereWidget, vtk3DWidget);
82  void PrintSelf(ostream& os, vtkIndent indent) override;
83 
85 
88  void SetEnabled(int) override;
89  void PlaceWidget(double bounds[6]) override;
90  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
92  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
93  {
94  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
95  }
97 
99 
104  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
105  vtkGetMacro(Representation, int);
106  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
107  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
108  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
110 
115  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
116  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
117 
122  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
123  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
124 
126 
129  void SetRadius(double r)
130  {
131  if (r <= 0)
132  {
133  r = .00001;
134  }
135  this->SphereSource->SetRadius(r);
136  }
137  double GetRadius() { return this->SphereSource->GetRadius(); }
139 
141 
144  void SetCenter(double x, double y, double z) { this->SphereSource->SetCenter(x, y, z); }
145  void SetCenter(double x[3]) { this->SetCenter(x[0], x[1], x[2]); }
146  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
147  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
149 
151 
155  vtkSetMacro(Translation, vtkTypeBool);
156  vtkGetMacro(Translation, vtkTypeBool);
157  vtkBooleanMacro(Translation, vtkTypeBool);
158  vtkSetMacro(Scale, vtkTypeBool);
159  vtkGetMacro(Scale, vtkTypeBool);
160  vtkBooleanMacro(Scale, vtkTypeBool);
162 
164 
170  vtkSetMacro(HandleVisibility, vtkTypeBool);
171  vtkGetMacro(HandleVisibility, vtkTypeBool);
172  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
174 
176 
181  vtkSetVector3Macro(HandleDirection, double);
182  vtkGetVector3Macro(HandleDirection, double);
184 
186 
189  vtkGetVector3Macro(HandlePosition, double);
191 
199  void GetPolyData(vtkPolyData* pd);
200 
207  void GetSphere(vtkSphere* sphere);
208 
210 
214  vtkGetObjectMacro(SphereProperty, vtkProperty);
215  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
217 
219 
224  vtkGetObjectMacro(HandleProperty, vtkProperty);
225  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
227 
228 protected:
229  vtkSphereWidget();
230  ~vtkSphereWidget() override;
231 
232  // Manage the state of the widget
233  int State;
235  {
236  Start = 0,
240  Outside
241  };
242 
243  // handles the events
244  static void ProcessEvents(
245  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
246 
247  // ProcessEvents() dispatches to these methods.
248  void OnLeftButtonDown();
249  void OnLeftButtonUp();
250  void OnRightButtonDown();
251  void OnRightButtonUp();
252  void OnMouseMove();
253 
254  // the sphere
258  void HighlightSphere(int highlight);
259  void SelectRepresentation();
260 
261  // The representation of the sphere
263 
264  // Do the picking
266 
267  // Register internal Pickers within PickingManager
268  void RegisterPickers() override;
269 
270  // Methods to manipulate the sphere widget
273  void Translate(double* p1, double* p2);
274  void ScaleSphere(double* p1, double* p2, int X, int Y);
275  void MoveHandle(double* p1, double* p2, int X, int Y);
276  void PlaceHandle(double* center, double radius);
277 
278  // Properties used to control the appearance of selected objects and
279  // the manipulator in general.
284  void CreateDefaultProperties();
285 
286  // Managing the handle
290  void HighlightHandle(int);
292  double HandleDirection[3];
293  double HandlePosition[3];
294  void SizeHandles() override;
295 
296 private:
297  vtkSphereWidget(const vtkSphereWidget&) = delete;
298  void operator=(const vtkSphereWidget&) = delete;
299 };
300 
301 #endif
void SetRadius(double r)
Set/Get the radius of sphere.
vtkSphereSource * HandleSource
void SetRepresentationToWireframe()
Set the representation of the sphere.
void SetPhiResolution(int r)
Set/Get the resolution of the sphere in the Phi direction.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:45
abstract base class for most VTK objects
Definition: vtkObject.h:53
void SetThetaResolution(int r)
Set/Get the resolution of the sphere in the Theta direction.
vtkSphereSource * SphereSource
represent surface properties of a geometric object
Definition: vtkProperty.h:61
static void ProcessEvents(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
Handles the char widget activation event.
void PlaceWidget() override
Methods that satisfy the superclass&#39; API.
vtkTypeBool HandleVisibility
virtual void SetEnabled(int)
Methods for turning the interactor observer on and off, and determining its state.
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Methods that satisfy the superclass&#39; API.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
#define VTK_SPHERE_OFF
vtkActor * SphereActor
#define VTK_SPHERE_SURFACE
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
vtkProperty * SphereProperty
vtkPolyDataMapper * HandleMapper
int vtkTypeBool
Definition: vtkABI.h:69
vtkCellPicker * Picker
void SetRepresentationToSurface()
Set the representation of the sphere.
create a polygonal sphere centered at the origin
implicit function for a sphere
Definition: vtkSphere.h:31
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkActor * HandleActor
vtkProperty * SelectedHandleProperty
double * GetCenter()
Set/Get the center of the sphere.
#define VTK_SIZEHINT(...)
#define VTK_SPHERE_WIREFRAME
void SetCenter(double x, double y, double z)
Set/Get the center of the sphere.
map vtkPolyData to graphics primitives
vtkProperty * HandleProperty
double GetRadius()
Set/Get the radius of sphere.
vtkTypeBool Scale
vtkTypeBool Translation
vtkPolyDataMapper * SphereMapper
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:66
void GetCenter(double xyz[3])
Set/Get the center of the sphere.
void SetCenter(double x[3])
Set/Get the center of the sphere.
3D widget for manipulating a sphere
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void SetRepresentationToOff()
Set the representation of the sphere.
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:67
virtual void SizeHandles()
Definition: vtk3DWidget.h:152
virtual void PlaceWidget()
This method is used to initially place the widget.
vtkProperty * SelectedSphereProperty
represent and manipulate 3D points
Definition: vtkPoints.h:33