VTK
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 "vtkInteractionWidgetsModule.h" // For export macro
63 #include "vtk3DWidget.h"
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 
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
97  {this->Superclass::PlaceWidget();}
98  void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
99  double zmin, double zmax) override
100  {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
102 
104 
109  vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE);
110  vtkGetMacro(Representation,int);
112  { this->SetRepresentation(VTK_SPHERE_OFF);}
114  { this->SetRepresentation(VTK_SPHERE_WIREFRAME);}
116  { this->SetRepresentation(VTK_SPHERE_SURFACE);}
118 
123  void SetThetaResolution(int r)
124  { this->SphereSource->SetThetaResolution(r); }
126  { return this->SphereSource->GetThetaResolution(); }
127 
132  void SetPhiResolution(int r)
133  { this->SphereSource->SetPhiResolution(r); }
135  { return this->SphereSource->GetPhiResolution(); }
136 
138 
141  void SetRadius(double r)
142  {
143  if ( r <= 0 )
144  {
145  r = .00001;
146  }
147  this->SphereSource->SetRadius(r);
148  }
149  double GetRadius()
150  { return this->SphereSource->GetRadius(); }
152 
154 
157  void SetCenter(double x, double y, double z)
158  {
159  this->SphereSource->SetCenter(x,y,z);
160  }
161  void SetCenter(double x[3])
162  {
163  this->SetCenter(x[0], x[1], x[2]);
164  }
165  double* GetCenter() VTK_SIZEHINT(3)
166  {return this->SphereSource->GetCenter();}
167  void GetCenter(double xyz[3])
168  {this->SphereSource->GetCenter(xyz);}
170 
172 
176  vtkSetMacro(Translation,vtkTypeBool);
177  vtkGetMacro(Translation,vtkTypeBool);
178  vtkBooleanMacro(Translation,vtkTypeBool);
179  vtkSetMacro(Scale,vtkTypeBool);
180  vtkGetMacro(Scale,vtkTypeBool);
181  vtkBooleanMacro(Scale,vtkTypeBool);
183 
185 
191  vtkSetMacro(HandleVisibility,vtkTypeBool);
192  vtkGetMacro(HandleVisibility,vtkTypeBool);
193  vtkBooleanMacro(HandleVisibility,vtkTypeBool);
195 
197 
202  vtkSetVector3Macro(HandleDirection,double);
203  vtkGetVector3Macro(HandleDirection,double);
205 
207 
210  vtkGetVector3Macro(HandlePosition,double);
212 
220  void GetPolyData(vtkPolyData *pd);
221 
228  void GetSphere(vtkSphere *sphere);
229 
231 
235  vtkGetObjectMacro(SphereProperty,vtkProperty);
236  vtkGetObjectMacro(SelectedSphereProperty,vtkProperty);
238 
240 
245  vtkGetObjectMacro(HandleProperty,vtkProperty);
246  vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
248 
249 protected:
250  vtkSphereWidget();
251  ~vtkSphereWidget() override;
252 
253  // Manage the state of the widget
254  int State;
256  {
257  Start=0,
261  Outside
262  };
263 
264  //handles the events
265  static void ProcessEvents(vtkObject* object,
266  unsigned long event,
267  void* clientdata,
268  void* calldata);
269 
270  // ProcessEvents() dispatches to these methods.
271  void OnLeftButtonDown();
272  void OnLeftButtonUp();
273  void OnRightButtonDown();
274  void OnRightButtonUp();
275  void OnMouseMove();
276 
277  // the sphere
281  void HighlightSphere(int highlight);
282  void SelectRepresentation();
283 
284  // The representation of the sphere
286 
287  // Do the picking
289 
290  // Register internal Pickers within PickingManager
291  void RegisterPickers() override;
292 
293  // Methods to manipulate the sphere widget
296  void Translate(double *p1, double *p2);
297  void ScaleSphere(double *p1, double *p2, int X, int Y);
298  void MoveHandle(double *p1, double *p2, int X, int Y);
299  void PlaceHandle(double *center, double radius);
300 
301  // Properties used to control the appearance of selected objects and
302  // the manipulator in general.
307  void CreateDefaultProperties();
308 
309  // Managing the handle
313  void HighlightHandle(int);
315  double HandleDirection[3];
316  double HandlePosition[3];
317  void SizeHandles() override;
318 
319 private:
320  vtkSphereWidget(const vtkSphereWidget&) = delete;
321  void operator=(const vtkSphereWidget&) = delete;
322 };
323 
324 #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:59
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:66
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:85
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:37
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:69
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:39