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 =========================================================================*/
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 class vtkActor;
64 class vtkPolyDataMapper;
65 class vtkPoints;
66 class vtkPolyData;
67 class vtkSphereSource;
68 class vtkSphere;
69 class vtkCellPicker;
70 class vtkProperty;
71 
72 #define VTK_SPHERE_OFF 0
73 #define VTK_SPHERE_WIREFRAME 1
74 #define VTK_SPHERE_SURFACE 2
75 
76 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget
77 {
78 public:
82  static vtkSphereWidget* New();
83 
84  vtkTypeMacro(vtkSphereWidget, vtk3DWidget);
85  void PrintSelf(ostream& os, vtkIndent indent) override;
86 
88 
91  void SetEnabled(int) override;
92  void PlaceWidget(double bounds[6]) override;
93  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
95  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
96  {
97  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
98  }
100 
102 
107  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
108  vtkGetMacro(Representation, int);
109  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
110  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
111  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
113 
118  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
119  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
120 
125  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
126  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
127 
129 
132  void SetRadius(double r)
133  {
134  if (r <= 0)
135  {
136  r = .00001;
137  }
138  this->SphereSource->SetRadius(r);
139  }
140  double GetRadius() { return this->SphereSource->GetRadius(); }
142 
144 
147  void SetCenter(double x, double y, double z) { this->SphereSource->SetCenter(x, y, z); }
148  void SetCenter(double x[3]) { this->SetCenter(x[0], x[1], x[2]); }
149  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
150  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
152 
154 
158  vtkSetMacro(Translation, vtkTypeBool);
159  vtkGetMacro(Translation, vtkTypeBool);
160  vtkBooleanMacro(Translation, vtkTypeBool);
161  vtkSetMacro(Scale, vtkTypeBool);
162  vtkGetMacro(Scale, vtkTypeBool);
163  vtkBooleanMacro(Scale, vtkTypeBool);
165 
167 
173  vtkSetMacro(HandleVisibility, vtkTypeBool);
174  vtkGetMacro(HandleVisibility, vtkTypeBool);
175  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
177 
179 
184  vtkSetVector3Macro(HandleDirection, double);
185  vtkGetVector3Macro(HandleDirection, double);
187 
189 
192  vtkGetVector3Macro(HandlePosition, double);
194 
202  void GetPolyData(vtkPolyData* pd);
203 
210  void GetSphere(vtkSphere* sphere);
211 
213 
217  vtkGetObjectMacro(SphereProperty, vtkProperty);
218  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
220 
222 
227  vtkGetObjectMacro(HandleProperty, vtkProperty);
228  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
230 
231 protected:
232  vtkSphereWidget();
233  ~vtkSphereWidget() override;
234 
235  // Manage the state of the widget
236  int State;
238  {
239  Start = 0,
243  Outside
244  };
245 
246  // handles the events
247  static void ProcessEvents(
248  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
249 
250  // ProcessEvents() dispatches to these methods.
251  void OnLeftButtonDown();
252  void OnLeftButtonUp();
253  void OnRightButtonDown();
254  void OnRightButtonUp();
255  void OnMouseMove();
256 
257  // the sphere
261  void HighlightSphere(int highlight);
262  void SelectRepresentation();
263 
264  // The representation of the sphere
266 
267  // Do the picking
269 
270  // Register internal Pickers within PickingManager
271  void RegisterPickers() override;
272 
273  // Methods to manipulate the sphere widget
276  void Translate(double* p1, double* p2);
277  void ScaleSphere(double* p1, double* p2, int X, int Y);
278  void MoveHandle(double* p1, double* p2, int X, int Y);
279  void PlaceHandle(double* center, double radius);
280 
281  // Properties used to control the appearance of selected objects and
282  // the manipulator in general.
287  void CreateDefaultProperties();
288 
289  // Managing the handle
293  void HighlightHandle(int);
295  double HandleDirection[3];
296  double HandlePosition[3];
297  void SizeHandles() override;
298 
299 private:
300  vtkSphereWidget(const vtkSphereWidget&) = delete;
301  void operator=(const vtkSphereWidget&) = delete;
302 };
303 
304 #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:56
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:70
virtual void SizeHandles()
Definition: vtk3DWidget.h:155
virtual void PlaceWidget()
This method is used to initially place the widget.
vtkProperty * SelectedSphereProperty
represent and manipulate 3D points
Definition: vtkPoints.h:33