VTK  9.7.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 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
44 
45 VTK_ABI_NAMESPACE_BEGIN
46 class vtkActor;
47 class vtkPolyDataMapper;
48 class vtkSphere;
49 class vtkSphereSource;
50 class vtkCellPicker;
51 class vtkProperty;
52 class vtkPolyData;
53 class vtkPoints;
55 class vtkTransform;
56 class vtkDoubleArray;
57 class vtkMatrix4x4;
58 class vtkTextMapper;
59 class vtkActor2D;
60 class vtkTextProperty;
61 class vtkLineSource;
62 class vtkCursor3D;
63 
64 #define VTK_SPHERE_OFF 0
65 #define VTK_SPHERE_WIREFRAME 1
66 #define VTK_SPHERE_SURFACE 2
67 
68 class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkSphereRepresentation
70 {
71 public:
75  static vtkSphereRepresentation* New();
76 
78 
82  void PrintSelf(ostream& os, vtkIndent indent) override;
84 
85  // Used to manage the state of the widget
86  enum
87  {
88  Outside = 0,
92  Scaling
93  };
94 
96 
100  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
101  vtkGetMacro(Representation, int);
102  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
103  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
104  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
106 
110  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
111  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
112 
116  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
117  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
118 
124  void SetCenter(double c[3]);
125  void SetCenter(double x, double y, double z)
126  {
127  double c[3];
128  c[0] = x;
129  c[1] = y;
130  c[2] = z;
131  this->SetCenter(c);
132  }
133  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
134  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
135 
140  void SetRadius(double r);
141  double GetRadius() { return this->SphereSource->GetRadius(); }
142 
144 
150  vtkSetMacro(HandleVisibility, vtkTypeBool);
151  vtkGetMacro(HandleVisibility, vtkTypeBool);
152  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
154 
156 
160  void SetHandlePosition(double handle[3]);
161  void SetHandlePosition(double x, double y, double z)
162  {
163  double p[3];
164  p[0] = x;
165  p[1] = y;
166  p[2] = z;
167  this->SetHandlePosition(p);
168  }
169  vtkGetVector3Macro(HandlePosition, double);
171 
173 
178  void SetHandleDirection(double dir[3]);
179  void SetHandleDirection(double dx, double dy, double dz)
180  {
181  double d[3];
182  d[0] = dx;
183  d[1] = dy;
184  d[2] = dz;
185  this->SetHandleDirection(d);
186  }
187  vtkGetVector3Macro(HandleDirection, double);
189 
191 
198  vtkSetMacro(HandleText, vtkTypeBool);
199  vtkGetMacro(HandleText, vtkTypeBool);
200  vtkBooleanMacro(HandleText, vtkTypeBool);
202 
204 
208  vtkSetMacro(RadialLine, vtkTypeBool);
209  vtkGetMacro(RadialLine, vtkTypeBool);
210  vtkBooleanMacro(RadialLine, vtkTypeBool);
212 
214 
218  vtkSetMacro(CenterCursor, bool);
219  vtkGetMacro(CenterCursor, bool);
220  vtkBooleanMacro(CenterCursor, bool);
222 
230  void GetPolyData(vtkPolyData* pd);
231 
238  void GetSphere(vtkSphere* sphere);
239 
241 
245  vtkGetObjectMacro(SphereProperty, vtkProperty);
246  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
248 
250 
255  vtkGetObjectMacro(HandleProperty, vtkProperty);
256  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
258 
260 
264  vtkGetObjectMacro(HandleTextProperty, vtkTextProperty);
266 
268 
272  vtkGetObjectMacro(RadialLineProperty, vtkProperty);
274 
276 
280  void SetInteractionColor(double, double, double);
281  void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
282  void SetHandleColor(double, double, double);
283  void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
284  void SetForegroundColor(double, double, double);
285  void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
287 
297  void SetInteractionState(int state);
298 
300 
305  void PlaceWidget(double bounds[6]) override;
306  virtual void PlaceWidget(double center[3], double handlePosition[3]);
307  void BuildRepresentation() override;
308  int ComputeInteractionState(int X, int Y, int modify = 0) override;
309  void StartWidgetInteraction(double e[2]) override;
310  void WidgetInteraction(double e[2]) override;
311  double* GetBounds() override;
313 
315 
318  void ReleaseGraphicsResources(vtkWindow*) override;
319  int RenderOpaqueGeometry(vtkViewport*) override;
321  int RenderOverlay(vtkViewport*) override;
324 
325  /*
326  * Register internal Pickers within PickingManager
327  */
328  void RegisterPickers() override;
329 
331 
335  vtkGetMacro(TranslationAxis, int);
336  vtkSetClampMacro(TranslationAxis, int, -1, 2);
338 
340 
343  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
344  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
345  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
346  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
348 
350 
353  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
355 
356 protected:
358  ~vtkSphereRepresentation() override;
359 
360  // Manage how the representation appears
361  double LastEventPosition[3];
362 
364 
365  // the sphere
369  void HighlightSphere(int highlight);
370 
371  // The representation of the sphere
373 
374  // Do the picking
377  double LastPickPosition[3];
378 
379  // Methods to manipulate the sphere widget
380  void Translate(const double* p1, const double* p2);
381  void Scale(const double* p1, const double* p2, int X, int Y);
382  void PlaceHandle(const double* center, double radius);
383  virtual void SizeHandles();
384 
385  // Method to adapt the center cursor bounds
386  // so it always have the same pixel size on screen
387  virtual void AdaptCenterCursorBounds();
388 
389  // Properties used to control the appearance of selected objects and
390  // the manipulator in general.
395  void CreateDefaultProperties();
396 
397  // Managing the handle
401  void HighlightHandle(int);
403  double HandleDirection[3];
404  double HandlePosition[3];
405 
406  // Manage the handle label
411 
412  // Manage the radial line segment
418 
419  // Managing the center cursor
424 
425 private:
427  void operator=(const vtkSphereRepresentation&) = delete;
428 };
429 
430 VTK_ABI_NAMESPACE_END
431 #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:41
vtkPolyDataMapper * SphereMapper
virtual void PlaceWidget(double bounds[6])
The following is a suggested API for widget representations.
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:31
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:46
represent surface properties of a geometric object
Definition: vtkProperty.h:59
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:35
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:50
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:71
int RenderOpaqueGeometry(vtkViewport *viewport) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
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.
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override
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:41
create a polygonal sphere centered at the origin
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
int RenderOverlay(vtkViewport *viewport) override
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
#define VTK_SIZEHINT(...)
represent text properties.
void SetRepresentationToSurface()
Set the representation (i.e., appearance) of the sphere.
vtkTextProperty * HandleTextProperty
vtkPolyDataMapper * RadialLineMapper
create a line defined by two end points
Definition: vtkLineSource.h:53
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:62
#define VTK_MARSHALAUTO
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:30
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.