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 =========================================================================*/
59 #ifndef vtkSphereWidget_h
60 #define vtkSphereWidget_h
61 
62 #include "vtk3DWidget.h"
63 #include "vtkInteractionWidgetsModule.h" // For export macro
64 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
65 
66 class vtkActor;
67 class vtkPolyDataMapper;
68 class vtkPoints;
69 class vtkPolyData;
70 class vtkSphereSource;
71 class vtkSphere;
72 class vtkCellPicker;
73 class vtkProperty;
74 
75 #define VTK_SPHERE_OFF 0
76 #define VTK_SPHERE_WIREFRAME 1
77 #define VTK_SPHERE_SURFACE 2
78 
79 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget
80 {
81 public:
85  static vtkSphereWidget* New();
86 
87  vtkTypeMacro(vtkSphereWidget, vtk3DWidget);
88  void PrintSelf(ostream& os, vtkIndent indent) override;
89 
91 
94  void SetEnabled(int) override;
95  void PlaceWidget(double bounds[6]) override;
96  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
98  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
99  {
100  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
101  }
103 
105 
110  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
111  vtkGetMacro(Representation, int);
112  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
113  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
114  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
116 
121  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
122  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
123 
128  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
129  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
130 
132 
135  void SetRadius(double r)
136  {
137  if (r <= 0)
138  {
139  r = .00001;
140  }
141  this->SphereSource->SetRadius(r);
142  }
143  double GetRadius() { return this->SphereSource->GetRadius(); }
145 
147 
150  void SetCenter(double x, double y, double z) { this->SphereSource->SetCenter(x, y, z); }
151  void SetCenter(double x[3]) { this->SetCenter(x[0], x[1], x[2]); }
152  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
153  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
155 
157 
161  vtkSetMacro(Translation, vtkTypeBool);
162  vtkGetMacro(Translation, vtkTypeBool);
163  vtkBooleanMacro(Translation, vtkTypeBool);
164  vtkSetMacro(Scale, vtkTypeBool);
165  vtkGetMacro(Scale, vtkTypeBool);
166  vtkBooleanMacro(Scale, vtkTypeBool);
168 
170 
176  vtkSetMacro(HandleVisibility, vtkTypeBool);
177  vtkGetMacro(HandleVisibility, vtkTypeBool);
178  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
180 
182 
187  vtkSetVector3Macro(HandleDirection, double);
188  vtkGetVector3Macro(HandleDirection, double);
190 
192 
195  vtkGetVector3Macro(HandlePosition, double);
197 
205  void GetPolyData(vtkPolyData* pd);
206 
213  void GetSphere(vtkSphere* sphere);
214 
216 
220  vtkGetObjectMacro(SphereProperty, vtkProperty);
221  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
223 
225 
230  vtkGetObjectMacro(HandleProperty, vtkProperty);
231  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
233 
234 protected:
235  vtkSphereWidget();
236  ~vtkSphereWidget() override;
237 
238  // Manage the state of the widget
239  int State;
241  {
242  Start = 0,
246  Outside
247  };
248 
249  // handles the events
250  static void ProcessEvents(
251  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
252 
253  // ProcessEvents() dispatches to these methods.
254  void OnLeftButtonDown();
255  void OnLeftButtonUp();
256  void OnRightButtonDown();
257  void OnRightButtonUp();
258  void OnMouseMove();
259 
260  // the sphere
264  void HighlightSphere(int highlight);
265  void SelectRepresentation();
266 
267  // The representation of the sphere
269 
270  // Do the picking
272 
273  // Register internal Pickers within PickingManager
274  void RegisterPickers() override;
275 
276  // Methods to manipulate the sphere widget
279  void Translate(double* p1, double* p2);
280  void ScaleSphere(double* p1, double* p2, int X, int Y);
281  void MoveHandle(double* p1, double* p2, int X, int Y);
282  void PlaceHandle(double* center, double radius);
283 
284  // Properties used to control the appearance of selected objects and
285  // the manipulator in general.
290  void CreateDefaultProperties();
291 
292  // Managing the handle
296  void HighlightHandle(int);
298  double HandleDirection[3];
299  double HandlePosition[3];
300  void SizeHandles() override;
301 
302 private:
303  vtkSphereWidget(const vtkSphereWidget&) = delete;
304  void operator=(const vtkSphereWidget&) = delete;
305 };
306 
307 #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:51
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:67
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' 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' API.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:90
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:34
a simple class to control print indentation
Definition: vtkIndent.h:39
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:72
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:39