VTK  9.3.1
vtkSphereRepresentation.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
37 #ifndef vtkSphereRepresentation_h
38 #define vtkSphereRepresentation_h
39 
40 #include "vtkInteractionWidgetsModule.h" // For export macro
41 #include "vtkSphereSource.h" // Needed for fast access to the sphere source
43 
44 VTK_ABI_NAMESPACE_BEGIN
45 class vtkActor;
46 class vtkPolyDataMapper;
47 class vtkSphere;
48 class vtkSphereSource;
49 class vtkCellPicker;
50 class vtkProperty;
51 class vtkPolyData;
52 class vtkPoints;
54 class vtkTransform;
55 class vtkDoubleArray;
56 class vtkMatrix4x4;
57 class vtkTextMapper;
58 class vtkActor2D;
59 class vtkTextProperty;
60 class vtkLineSource;
61 class vtkCursor3D;
62 
63 #define VTK_SPHERE_OFF 0
64 #define VTK_SPHERE_WIREFRAME 1
65 #define VTK_SPHERE_SURFACE 2
66 
67 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereRepresentation : public vtkWidgetRepresentation
68 {
69 public:
73  static vtkSphereRepresentation* New();
74 
76 
80  void PrintSelf(ostream& os, vtkIndent indent) override;
82 
83  // Used to manage the state of the widget
84  enum
85  {
86  Outside = 0,
90  Scaling
91  };
92 
94 
98  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
99  vtkGetMacro(Representation, int);
100  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
101  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
102  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
104 
108  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
109  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
110 
114  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
115  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
116 
122  void SetCenter(double c[3]);
123  void SetCenter(double x, double y, double z)
124  {
125  double c[3];
126  c[0] = x;
127  c[1] = y;
128  c[2] = z;
129  this->SetCenter(c);
130  }
131  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
132  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
133 
138  void SetRadius(double r);
139  double GetRadius() { return this->SphereSource->GetRadius(); }
140 
142 
148  vtkSetMacro(HandleVisibility, vtkTypeBool);
149  vtkGetMacro(HandleVisibility, vtkTypeBool);
150  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
152 
154 
158  void SetHandlePosition(double handle[3]);
159  void SetHandlePosition(double x, double y, double z)
160  {
161  double p[3];
162  p[0] = x;
163  p[1] = y;
164  p[2] = z;
165  this->SetHandlePosition(p);
166  }
167  vtkGetVector3Macro(HandlePosition, double);
169 
171 
176  void SetHandleDirection(double dir[3]);
177  void SetHandleDirection(double dx, double dy, double dz)
178  {
179  double d[3];
180  d[0] = dx;
181  d[1] = dy;
182  d[2] = dz;
183  this->SetHandleDirection(d);
184  }
185  vtkGetVector3Macro(HandleDirection, double);
187 
189 
196  vtkSetMacro(HandleText, vtkTypeBool);
197  vtkGetMacro(HandleText, vtkTypeBool);
198  vtkBooleanMacro(HandleText, vtkTypeBool);
200 
202 
206  vtkSetMacro(RadialLine, vtkTypeBool);
207  vtkGetMacro(RadialLine, vtkTypeBool);
208  vtkBooleanMacro(RadialLine, vtkTypeBool);
210 
212 
216  vtkSetMacro(CenterCursor, bool);
217  vtkGetMacro(CenterCursor, bool);
218  vtkBooleanMacro(CenterCursor, bool);
220 
228  void GetPolyData(vtkPolyData* pd);
229 
236  void GetSphere(vtkSphere* sphere);
237 
239 
243  vtkGetObjectMacro(SphereProperty, vtkProperty);
244  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
246 
248 
253  vtkGetObjectMacro(HandleProperty, vtkProperty);
254  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
256 
258 
262  vtkGetObjectMacro(HandleTextProperty, vtkTextProperty);
264 
266 
270  vtkGetObjectMacro(RadialLineProperty, vtkProperty);
272 
274 
278  void SetInteractionColor(double, double, double);
279  void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
280  void SetHandleColor(double, double, double);
281  void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
282  void SetForegroundColor(double, double, double);
283  void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
285 
295  void SetInteractionState(int state);
296 
298 
303  void PlaceWidget(double bounds[6]) override;
304  virtual void PlaceWidget(double center[3], double handlePosition[3]);
305  void BuildRepresentation() override;
306  int ComputeInteractionState(int X, int Y, int modify = 0) override;
307  void StartWidgetInteraction(double e[2]) override;
308  void WidgetInteraction(double e[2]) override;
309  double* GetBounds() override;
311 
313 
316  void ReleaseGraphicsResources(vtkWindow*) override;
317  int RenderOpaqueGeometry(vtkViewport*) override;
319  int RenderOverlay(vtkViewport*) override;
322 
323  /*
324  * Register internal Pickers within PickingManager
325  */
326  void RegisterPickers() override;
327 
329 
333  vtkGetMacro(TranslationAxis, int);
334  vtkSetClampMacro(TranslationAxis, int, -1, 2);
336 
338 
341  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
342  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
343  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
344  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
346 
348 
351  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
353 
354 protected:
356  ~vtkSphereRepresentation() override;
357 
358  // Manage how the representation appears
359  double LastEventPosition[3];
360 
362 
363  // the sphere
367  void HighlightSphere(int highlight);
368 
369  // The representation of the sphere
371 
372  // Do the picking
375  double LastPickPosition[3];
376 
377  // Methods to manipulate the sphere widget
378  void Translate(const double* p1, const double* p2);
379  void Scale(const double* p1, const double* p2, int X, int Y);
380  void PlaceHandle(const double* center, double radius);
381  virtual void SizeHandles();
382 
383  // Method to adapt the center cursor bounds
384  // so it always have the same pixel size on screen
385  virtual void AdaptCenterCursorBounds();
386 
387  // Properties used to control the appearance of selected objects and
388  // the manipulator in general.
393  void CreateDefaultProperties();
394 
395  // Managing the handle
399  void HighlightHandle(int);
401  double HandleDirection[3];
402  double HandlePosition[3];
403 
404  // Manage the handle label
409 
410  // Manage the radial line segment
416 
417  // Managing the center cursor
422 
423 private:
425  void operator=(const vtkSphereRepresentation&) = delete;
426 };
427 
428 VTK_ABI_NAMESPACE_END
429 #endif
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
#define VTK_SPHERE_SURFACE
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:40
vtkPolyDataMapper * SphereMapper
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
virtual void PlaceWidget(double vtkNotUsed(bounds)[6])
The following is a suggested API for widget representations.
vtkPolyDataMapper * CenterMapper
virtual int ComputeInteractionState(int X, int Y, int modify=0)
void SetInteractionColor(double c[3])
Set the interaction color of sphere and handle.
abstract specification for Viewports
Definition: vtkViewport.h:44
represent surface properties of a geometric object
Definition: vtkProperty.h:56
void SetHandleDirection(double dx, double dy, double dz)
Set/Get the direction vector of the handle relative to the center of the sphere.
virtual void StartWidgetInteraction(double eventPos[2])
void SetCenter(double x, double y, double z)
a actor that draws 2D data
Definition: vtkActor2D.h:34
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
void SetRepresentationToOff()
Set the representation (i.e., appearance) of the sphere.
void SetPhiResolution(int r)
Set/Get the resolution of the sphere in the phi direction.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:49
void SetHandleColor(double c[3])
Set the interaction color of sphere and handle.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
bool IsTranslationConstrained()
Returns true if ConstrainedAxis.
abstract class defines interface between the widget and widget representation classes ...
virtual void BuildRepresentation()=0
Subclasses of vtkWidgetRepresentation must implement these methods.
2D text annotation
Definition: vtkTextMapper.h:39
void SetThetaResolution(int r)
Set/Get the resolution of the sphere in the theta direction.
double * GetBounds() override
Methods to make this class behave as a vtkProp.
dynamic, self-adjusting array of double
int vtkTypeBool
Definition: vtkABI.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:27
create a polygonal sphere centered at the origin
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override
implicit function for a sphere
Definition: vtkSphere.h:23
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
#define VTK_SPHERE_WIREFRAME
void SetHandlePosition(double x, double y, double z)
Set/Get the position of the handle.
void ReleaseGraphicsResources(vtkWindow *) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE Release any graphics resources that are being...
void SetRepresentationToWireframe()
Set the representation (i.e., appearance) of the sphere.
virtual void WidgetInteraction(double newEventPos[2])
#define VTK_SPHERE_OFF
int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport)) override
#define VTK_SIZEHINT(...)
represent text properties.
void SetRepresentationToSurface()
Set the representation (i.e., appearance) of the sphere.
vtkTextProperty * HandleTextProperty
vtkPolyDataMapper * RadialLineMapper
int RenderOverlay(vtkViewport *vtkNotUsed(viewport)) override
create a line defined by two end points
Definition: vtkLineSource.h:52
map vtkPolyData to graphics primitives
void SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
vtkTypeBool HasTranslucentPolygonalGeometry() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:61
generate a 3D cursor representation
Definition: vtkCursor3D.h:28
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
a class defining the representation for the vtkSphereWidget2
void SetForegroundColor(double c[3])
Set the interaction color of sphere and handle.
vtkPolyDataMapper * HandleMapper
represent and manipulate 3D points
Definition: vtkPoints.h:28
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.