VTK  9.3.1
vtkSphereWidget.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
47 #ifndef vtkSphereWidget_h
48 #define vtkSphereWidget_h
49 
50 #include "vtk3DWidget.h"
51 #include "vtkInteractionWidgetsModule.h" // For export macro
52 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
53 
54 VTK_ABI_NAMESPACE_BEGIN
55 class vtkActor;
56 class vtkPolyDataMapper;
57 class vtkPoints;
58 class vtkPolyData;
59 class vtkSphereSource;
60 class vtkSphere;
61 class vtkCellPicker;
62 class vtkProperty;
63 
64 #define VTK_SPHERE_OFF 0
65 #define VTK_SPHERE_WIREFRAME 1
66 #define VTK_SPHERE_SURFACE 2
67 
68 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget
69 {
70 public:
74  static vtkSphereWidget* New();
75 
76  vtkTypeMacro(vtkSphereWidget, vtk3DWidget);
77  void PrintSelf(ostream& os, vtkIndent indent) override;
78 
80 
83  void SetEnabled(int) override;
84  void PlaceWidget(double bounds[6]) override;
85  void PlaceWidget() override { this->Superclass::PlaceWidget(); }
87  double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) override
88  {
89  this->Superclass::PlaceWidget(xmin, xmax, ymin, ymax, zmin, zmax);
90  }
92 
94 
99  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
100  vtkGetMacro(Representation, int);
101  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
102  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
103  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
105 
110  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
111  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
112 
117  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
118  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
119 
121 
124  void SetRadius(double r)
125  {
126  if (r <= 0)
127  {
128  r = .00001;
129  }
130  this->SphereSource->SetRadius(r);
131  }
132  double GetRadius() { return this->SphereSource->GetRadius(); }
134 
136 
139  void SetCenter(double x, double y, double z) { this->SphereSource->SetCenter(x, y, z); }
140  void SetCenter(double x[3]) { this->SetCenter(x[0], x[1], x[2]); }
141  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
142  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
144 
146 
150  vtkSetMacro(Translation, vtkTypeBool);
151  vtkGetMacro(Translation, vtkTypeBool);
152  vtkBooleanMacro(Translation, vtkTypeBool);
153  vtkSetMacro(Scale, vtkTypeBool);
154  vtkGetMacro(Scale, vtkTypeBool);
155  vtkBooleanMacro(Scale, vtkTypeBool);
157 
159 
165  vtkSetMacro(HandleVisibility, vtkTypeBool);
166  vtkGetMacro(HandleVisibility, vtkTypeBool);
167  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
169 
171 
176  vtkSetVector3Macro(HandleDirection, double);
177  vtkGetVector3Macro(HandleDirection, double);
179 
181 
184  vtkGetVector3Macro(HandlePosition, double);
186 
194  void GetPolyData(vtkPolyData* pd);
195 
202  void GetSphere(vtkSphere* sphere);
203 
205 
209  vtkGetObjectMacro(SphereProperty, vtkProperty);
210  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
212 
214 
219  vtkGetObjectMacro(HandleProperty, vtkProperty);
220  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
222 
223 protected:
224  vtkSphereWidget();
225  ~vtkSphereWidget() override;
226 
227  // Manage the state of the widget
228  int State;
230  {
231  Start = 0,
235  Outside
236  };
237 
238  // handles the events
239  static void ProcessEvents(
240  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
241 
242  // ProcessEvents() dispatches to these methods.
243  void OnLeftButtonDown();
244  void OnLeftButtonUp();
245  void OnRightButtonDown();
246  void OnRightButtonUp();
247  void OnMouseMove();
248 
249  // the sphere
253  void HighlightSphere(int highlight);
254  void SelectRepresentation();
255 
256  // The representation of the sphere
258 
259  // Do the picking
261 
262  // Register internal Pickers within PickingManager
263  void RegisterPickers() override;
264 
265  // Methods to manipulate the sphere widget
268  void Translate(double* p1, double* p2);
269  void ScaleSphere(double* p1, double* p2, int X, int Y);
270  void MoveHandle(double* p1, double* p2, int X, int Y);
271  void PlaceHandle(double* center, double radius);
272 
273  // Properties used to control the appearance of selected objects and
274  // the manipulator in general.
279  void CreateDefaultProperties();
280 
281  // Managing the handle
285  void HighlightHandle(int);
287  double HandleDirection[3];
288  double HandlePosition[3];
289  void SizeHandles() override;
290 
291 private:
292  vtkSphereWidget(const vtkSphereWidget&) = delete;
293  void operator=(const vtkSphereWidget&) = delete;
294 };
295 
296 VTK_ABI_NAMESPACE_END
297 #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:40
abstract base class for most VTK objects
Definition: vtkObject.h:51
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:56
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:79
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:64
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:23
a simple class to control print indentation
Definition: vtkIndent.h:28
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:61
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:59
virtual void SizeHandles()
Definition: vtk3DWidget.h:144
virtual void PlaceWidget()
This method is used to initially place the widget.
vtkProperty * SelectedSphereProperty
represent and manipulate 3D points
Definition: vtkPoints.h:28