VTK  9.2.6
vtkSphereRepresentation.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSphereRepresentation.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 =========================================================================*/
49 #ifndef vtkSphereRepresentation_h
50 #define vtkSphereRepresentation_h
51 
52 #include "vtkInteractionWidgetsModule.h" // For export macro
53 #include "vtkSphereSource.h" // Needed for fast access to the sphere source
55 
56 class vtkActor;
57 class vtkPolyDataMapper;
58 class vtkSphere;
59 class vtkSphereSource;
60 class vtkCellPicker;
61 class vtkProperty;
62 class vtkPolyData;
63 class vtkPoints;
65 class vtkTransform;
66 class vtkDoubleArray;
67 class vtkMatrix4x4;
68 class vtkTextMapper;
69 class vtkActor2D;
70 class vtkTextProperty;
71 class vtkLineSource;
72 class vtkCursor3D;
73 
74 #define VTK_SPHERE_OFF 0
75 #define VTK_SPHERE_WIREFRAME 1
76 #define VTK_SPHERE_SURFACE 2
77 
78 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereRepresentation : public vtkWidgetRepresentation
79 {
80 public:
84  static vtkSphereRepresentation* New();
85 
87 
91  void PrintSelf(ostream& os, vtkIndent indent) override;
93 
94  // Used to manage the state of the widget
95  enum
96  {
97  Outside = 0,
101  Scaling
102  };
103 
105 
109  vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
110  vtkGetMacro(Representation, int);
111  void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
112  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
113  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
115 
119  void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
120  int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
121 
125  void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
126  int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
127 
133  void SetCenter(double c[3]);
134  void SetCenter(double x, double y, double z)
135  {
136  double c[3];
137  c[0] = x;
138  c[1] = y;
139  c[2] = z;
140  this->SetCenter(c);
141  }
142  double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
143  void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
144 
149  void SetRadius(double r);
150  double GetRadius() { return this->SphereSource->GetRadius(); }
151 
153 
159  vtkSetMacro(HandleVisibility, vtkTypeBool);
160  vtkGetMacro(HandleVisibility, vtkTypeBool);
161  vtkBooleanMacro(HandleVisibility, vtkTypeBool);
163 
165 
169  void SetHandlePosition(double handle[3]);
170  void SetHandlePosition(double x, double y, double z)
171  {
172  double p[3];
173  p[0] = x;
174  p[1] = y;
175  p[2] = z;
176  this->SetHandlePosition(p);
177  }
178  vtkGetVector3Macro(HandlePosition, double);
180 
182 
187  void SetHandleDirection(double dir[3]);
188  void SetHandleDirection(double dx, double dy, double dz)
189  {
190  double d[3];
191  d[0] = dx;
192  d[1] = dy;
193  d[2] = dz;
194  this->SetHandleDirection(d);
195  }
196  vtkGetVector3Macro(HandleDirection, double);
198 
200 
207  vtkSetMacro(HandleText, vtkTypeBool);
208  vtkGetMacro(HandleText, vtkTypeBool);
209  vtkBooleanMacro(HandleText, vtkTypeBool);
211 
213 
217  vtkSetMacro(RadialLine, vtkTypeBool);
218  vtkGetMacro(RadialLine, vtkTypeBool);
219  vtkBooleanMacro(RadialLine, vtkTypeBool);
221 
223 
227  vtkSetMacro(CenterCursor, bool);
228  vtkGetMacro(CenterCursor, bool);
229  vtkBooleanMacro(CenterCursor, bool);
231 
239  void GetPolyData(vtkPolyData* pd);
240 
247  void GetSphere(vtkSphere* sphere);
248 
250 
254  vtkGetObjectMacro(SphereProperty, vtkProperty);
255  vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
257 
259 
264  vtkGetObjectMacro(HandleProperty, vtkProperty);
265  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
267 
269 
273  vtkGetObjectMacro(HandleTextProperty, vtkTextProperty);
275 
277 
281  vtkGetObjectMacro(RadialLineProperty, vtkProperty);
283 
293  void SetInteractionState(int state);
294 
296 
301  void PlaceWidget(double bounds[6]) override;
302  virtual void PlaceWidget(double center[3], double handlePosition[3]);
303  void BuildRepresentation() override;
304  int ComputeInteractionState(int X, int Y, int modify = 0) override;
305  void StartWidgetInteraction(double e[2]) override;
306  void WidgetInteraction(double e[2]) override;
307  double* GetBounds() override;
309 
311 
314  void ReleaseGraphicsResources(vtkWindow*) override;
315  int RenderOpaqueGeometry(vtkViewport*) override;
317  int RenderOverlay(vtkViewport*) override;
320 
321  /*
322  * Register internal Pickers within PickingManager
323  */
324  void RegisterPickers() override;
325 
327 
331  vtkGetMacro(TranslationAxis, int);
332  vtkSetClampMacro(TranslationAxis, int, -1, 2);
334 
336 
339  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
340  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
341  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
342  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
344 
346 
349  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
351 
352 protected:
354  ~vtkSphereRepresentation() override;
355 
356  // Manage how the representation appears
357  double LastEventPosition[3];
358 
360 
361  // the sphere
365  void HighlightSphere(int highlight);
366 
367  // The representation of the sphere
369 
370  // Do the picking
373  double LastPickPosition[3];
374 
375  // Methods to manipulate the sphere widget
376  void Translate(const double* p1, const double* p2);
377  void Scale(const double* p1, const double* p2, int X, int Y);
378  void PlaceHandle(const double* center, double radius);
379  virtual void SizeHandles();
380 
381  // Method to adapt the center cursor bounds
382  // so it always have the same pixel size on screen
383  virtual void AdaptCenterCursorBounds();
384 
385  // Properties used to control the appearance of selected objects and
386  // the manipulator in general.
391  void CreateDefaultProperties();
392 
393  // Managing the handle
397  void HighlightHandle(int);
399  double HandleDirection[3];
400  double HandlePosition[3];
401 
402  // Manage the handle label
407 
408  // Manage the radial line segment
414 
415  // Managing the center cursor
420 
421 private:
423  void operator=(const vtkSphereRepresentation&) = delete;
424 };
425 
426 #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:51
vtkPolyDataMapper * SphereMapper
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
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)
abstract specification for Viewports
Definition: vtkViewport.h:55
represent surface properties of a geometric object
Definition: vtkProperty.h:67
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:45
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:60
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:90
bool IsTranslationConstrained()
Returns true if ContrainedAxis.
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:50
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:69
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
create a polygonal sphere centered at the origin
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override
implicit function for a sphere
Definition: vtkSphere.h:34
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:39
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:63
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:72
generate a 3D cursor representation
Definition: vtkCursor3D.h:39
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
vtkPolyDataMapper * HandleMapper
represent and manipulate 3D points
Definition: vtkPoints.h:39
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.