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 
208  void GetPolyData(vtkPolyData* pd);
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:
238  vtkSphereWidget();
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.
257  void OnLeftButtonDown();
258  void OnLeftButtonUp();
259  void OnRightButtonDown();
260  void OnRightButtonUp();
261  void OnMouseMove();
262 
263  // the sphere
267  void HighlightSphere(int highlight);
268  void SelectRepresentation();
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.
293  void CreateDefaultProperties();
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
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:62
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