VTK  9.0.20201028
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
vtkPolyDataMapper
map vtkPolyData to graphics primitives
Definition: vtkPolyDataMapper.h:36
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkSphereWidget::SphereSource
vtkSphereSource * SphereSource
Definition: vtkSphereWidget.h:266
vtkSphereWidget::Picker
vtkCellPicker * Picker
Definition: vtkSphereWidget.h:274
vtkSphereWidget::SetRadius
void SetRadius(double r)
Set/Get the radius of sphere.
Definition: vtkSphereWidget.h:138
vtkSphereWidget::GetCenter
double * GetCenter()
Definition: vtkSphereWidget.h:155
vtkSphereWidget::Translation
vtkTypeBool Translation
Definition: vtkSphereWidget.h:280
vtkSphereWidget::SetThetaResolution
void SetThetaResolution(int r)
Set/Get the resolution of the sphere in the Theta direction.
Definition: vtkSphereWidget.h:124
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkSphereWidget::WidgetState
WidgetState
Definition: vtkSphereWidget.h:243
vtkSphereWidget::Moving
Definition: vtkSphereWidget.h:246
VTK_SPHERE_OFF
#define VTK_SPHERE_OFF
Definition: vtkSphereWidget.h:78
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkSphereWidget::SelectedHandleProperty
vtkProperty * SelectedHandleProperty
Definition: vtkSphereWidget.h:292
VTK_SPHERE_WIREFRAME
#define VTK_SPHERE_WIREFRAME
Definition: vtkSphereWidget.h:79
vtkSphereWidget::HandleMapper
vtkPolyDataMapper * HandleMapper
Definition: vtkSphereWidget.h:297
vtk3DWidget::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkX3D::center
Definition: vtkX3D.h:236
vtkSphereWidget::HandleProperty
vtkProperty * HandleProperty
Definition: vtkSphereWidget.h:291
vtkSphere
implicit function for a sphere
Definition: vtkSphere.h:31
vtkSphereWidget::Representation
int Representation
Definition: vtkSphereWidget.h:271
vtkSphereWidget::Scale
vtkTypeBool Scale
Definition: vtkSphereWidget.h:281
vtkSphereWidget::PlaceWidget
void PlaceWidget() override
Definition: vtkSphereWidget.h:99
vtkSphereWidget::HandleVisibility
vtkTypeBool HandleVisibility
Definition: vtkSphereWidget.h:300
vtkSphereWidget::GetThetaResolution
int GetThetaResolution()
Definition: vtkSphereWidget.h:125
vtkSphereWidget::SphereProperty
vtkProperty * SphereProperty
Definition: vtkSphereWidget.h:289
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
vtkSphereWidget::SelectedSphereProperty
vtkProperty * SelectedSphereProperty
Definition: vtkSphereWidget.h:290
vtkSphereSource
create a polygonal sphere centered at the origin
Definition: vtkSphereSource.h:41
vtkInteractorObserver::ProcessEvents
static void ProcessEvents(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
Handles the char widget activation event.
vtkSphereWidget::GetCenter
void GetCenter(double xyz[3])
Definition: vtkSphereWidget.h:156
vtkActor
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:45
vtkInteractorObserver::SetEnabled
virtual void SetEnabled(int)
Methods for turning the interactor observer on and off, and determining its state.
Definition: vtkInteractorObserver.h:79
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkSphereWidget::Scaling
Definition: vtkSphereWidget.h:247
VTK_SPHERE_SURFACE
#define VTK_SPHERE_SURFACE
Definition: vtkSphereWidget.h:80
vtkSphereWidget::SetPhiResolution
void SetPhiResolution(int r)
Set/Get the resolution of the sphere in the Phi direction.
Definition: vtkSphereWidget.h:131
vtk3DWidget
an abstract superclass for 3D widgets
Definition: vtk3DWidget.h:70
vtkSphereWidget::SphereActor
vtkActor * SphereActor
Definition: vtkSphereWidget.h:264
vtkSphereSource.h
vtkSphereWidget::GetRadius
double GetRadius()
Definition: vtkSphereWidget.h:146
vtkInteractorObserver::RegisterPickers
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
vtk3DWidget::SizeHandles
virtual void SizeHandles()
Definition: vtk3DWidget.h:155
vtk3DWidget::PlaceWidget
virtual void PlaceWidget()
vtkSphereWidget::State
int State
Definition: vtkSphereWidget.h:242
vtkSphereWidget::SetCenter
void SetCenter(double x[3])
Definition: vtkSphereWidget.h:154
vtkSphereWidget::SetRepresentationToWireframe
void SetRepresentationToWireframe()
Definition: vtkSphereWidget.h:116
vtkSphereWidget::PlaceWidget
void PlaceWidget(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
Definition: vtkSphereWidget.h:100
vtkSphereWidget::SetRepresentationToSurface
void SetRepresentationToSurface()
Definition: vtkSphereWidget.h:117
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkSphereWidget
3D widget for manipulating a sphere
Definition: vtkSphereWidget.h:82
vtkSphereWidget::SetRepresentationToOff
void SetRepresentationToOff()
Definition: vtkSphereWidget.h:115
vtkSphereWidget::GetPhiResolution
int GetPhiResolution()
Definition: vtkSphereWidget.h:132
vtkSphereWidget::SetCenter
void SetCenter(double x, double y, double z)
Set/Get the center of the sphere.
Definition: vtkSphereWidget.h:153
vtkSphereWidget::HandleActor
vtkActor * HandleActor
Definition: vtkSphereWidget.h:296
vtkSphereWidget::SphereMapper
vtkPolyDataMapper * SphereMapper
Definition: vtkSphereWidget.h:265
vtk3DWidget.h
vtkProperty
represent surface properties of a geometric object
Definition: vtkProperty.h:61
vtkX3D::radius
Definition: vtkX3D.h:258
vtkCellPicker
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:66
vtkSphereWidget::Positioning
Definition: vtkSphereWidget.h:248
vtkSphereWidget::HandleSource
vtkSphereSource * HandleSource
Definition: vtkSphereWidget.h:298
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69