VTK
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 =========================================================================*/
46 #ifndef vtkSphereRepresentation_h
47 #define vtkSphereRepresentation_h
48 
49 #include "vtkInteractionWidgetsModule.h" // For export macro
51 #include "vtkSphereSource.h" // Needed for fast access to the sphere source
52 
53 class vtkActor;
54 class vtkPolyDataMapper;
55 class vtkSphere;
56 class vtkSphereSource;
57 class vtkCellPicker;
58 class vtkProperty;
59 class vtkPolyData;
60 class vtkPoints;
62 class vtkTransform;
63 class vtkDoubleArray;
64 class vtkMatrix4x4;
65 class vtkTextMapper;
66 class vtkActor2D;
67 class vtkTextProperty;
68 class vtkLineSource;
69 class vtkCursor3D;
70 
71 #define VTK_SPHERE_OFF 0
72 #define VTK_SPHERE_WIREFRAME 1
73 #define VTK_SPHERE_SURFACE 2
74 
75 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereRepresentation : public vtkWidgetRepresentation
76 {
77 public:
81  static vtkSphereRepresentation *New();
82 
84 
88  void PrintSelf(ostream& os, vtkIndent indent) override;
90 
91  // Used to manage the state of the widget
92  enum {Outside=0,MovingHandle,OnSphere,Translating,Scaling};
93 
95 
99  vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE);
100  vtkGetMacro(Representation,int);
102  { this->SetRepresentation(VTK_SPHERE_OFF);}
104  { this->SetRepresentation(VTK_SPHERE_WIREFRAME);}
106  { this->SetRepresentation(VTK_SPHERE_SURFACE);}
108 
112  void SetThetaResolution(int r)
113  { this->SphereSource->SetThetaResolution(r); }
115  { return this->SphereSource->GetThetaResolution(); }
116 
120  void SetPhiResolution(int r)
121  { this->SphereSource->SetPhiResolution(r); }
123  { return this->SphereSource->GetPhiResolution(); }
124 
130  void SetCenter(double c[3]);
131  void SetCenter(double x, double y, double z)
132  {double c[3]; c[0]=x; c[1]=y; c[2]=z; this->SetCenter(c);}
133  double* GetCenter() VTK_SIZEHINT(3)
134  {return this->SphereSource->GetCenter();}
135  void GetCenter(double xyz[3])
136  {this->SphereSource->GetCenter(xyz);}
137 
142  void SetRadius(double r);
143  double GetRadius()
144  { return this->SphereSource->GetRadius(); }
145 
147 
153  vtkSetMacro(HandleVisibility,vtkTypeBool);
154  vtkGetMacro(HandleVisibility,vtkTypeBool);
155  vtkBooleanMacro(HandleVisibility,vtkTypeBool);
157 
159 
163  void SetHandlePosition(double handle[3]);
164  void SetHandlePosition(double x, double y, double z)
165  {double p[3]; p[0]=x; p[1]=y; p[2]=z; this->SetHandlePosition(p);}
166  vtkGetVector3Macro(HandlePosition,double);
168 
170 
175  void SetHandleDirection(double dir[3]);
176  void SetHandleDirection(double dx, double dy, double dz)
177  {double d[3]; d[0]=dx; d[1]=dy; d[2]=dz; this->SetHandleDirection(d);}
178  vtkGetVector3Macro(HandleDirection,double);
180 
182 
189  vtkSetMacro(HandleText,vtkTypeBool);
190  vtkGetMacro(HandleText,vtkTypeBool);
191  vtkBooleanMacro(HandleText,vtkTypeBool);
193 
195 
199  vtkSetMacro(RadialLine,vtkTypeBool);
200  vtkGetMacro(RadialLine,vtkTypeBool);
201  vtkBooleanMacro(RadialLine,vtkTypeBool);
203 
205 
209  vtkSetMacro(CenterCursor, bool);
210  vtkGetMacro(CenterCursor, bool);
211  vtkBooleanMacro(CenterCursor, bool);
213 
221  void GetPolyData(vtkPolyData *pd);
222 
229  void GetSphere(vtkSphere *sphere);
230 
232 
236  vtkGetObjectMacro(SphereProperty,vtkProperty);
237  vtkGetObjectMacro(SelectedSphereProperty,vtkProperty);
239 
241 
246  vtkGetObjectMacro(HandleProperty,vtkProperty);
247  vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
249 
251 
255  vtkGetObjectMacro(HandleTextProperty,vtkTextProperty);
257 
259 
263  vtkGetObjectMacro(RadialLineProperty,vtkProperty);
265 
275  void SetInteractionState(int state);
276 
278 
283  void PlaceWidget(double bounds[6]) override;
284  virtual void PlaceWidget(double center[3], double handlePosition[3]);
285  void BuildRepresentation() override;
286  int ComputeInteractionState(int X, int Y, int modify=0) override;
287  void StartWidgetInteraction(double e[2]) override;
288  void WidgetInteraction(double e[2]) override;
289  double *GetBounds() override;
291 
293 
296  void ReleaseGraphicsResources(vtkWindow*) override;
297  int RenderOpaqueGeometry(vtkViewport*) override;
299  int RenderOverlay(vtkViewport*) override;
300  int HasTranslucentPolygonalGeometry() override;
302 
303 protected:
305  ~vtkSphereRepresentation() override;
306 
307  // Manage how the representation appears
308  double LastEventPosition[3];
309 
310  // the sphere
314  void HighlightSphere(int highlight);
315 
316  // The representation of the sphere
318 
319  // Do the picking
322  double LastPickPosition[3];
323 
324  // Register internal Pickers within PickingManager
325  void RegisterPickers() override;
326 
327  // Methods to manipulate the sphere widget
328  void Translate(double *p1, double *p2);
329  void Scale(double *p1, double *p2, int X, int Y);
330  void PlaceHandle(double *center, double radius);
331  virtual void SizeHandles();
332 
333  // Method to adapt the center cursor bounds
334  // so it always have the same pixel size on screen
335  virtual void AdaptCenterCursorBounds();
336 
337  // Properties used to control the appearance of selected objects and
338  // the manipulator in general.
343  void CreateDefaultProperties();
344 
345  // Managing the handle
349  void HighlightHandle(int);
351  double HandleDirection[3];
352  double HandlePosition[3];
353 
354  // Manage the handle label
359 
360  // Manage the radial line segment
366 
367  // Managing the center cursor
372 
373 private:
375  void operator=(const vtkSphereRepresentation&) = delete;
376 };
377 
378 #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:45
vtkPolyDataMapper * SphereMapper
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
vtkPolyDataMapper * CenterMapper
virtual int ComputeInteractionState(int X, int Y, int modify=0)
abstract specification for Viewports
Definition: vtkViewport.h:44
represent surface properties of a geometric object
Definition: vtkProperty.h:60
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:39
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:54
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
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:47
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:34
create a polygonal sphere centered at the origin
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override
implicit function for a sphere
Definition: vtkSphere.h:31
Superclass for algorithms that produce only polydata as output.
int HasTranslucentPolygonalGeometry() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
a simple class to control print indentation
Definition: vtkIndent.h:33
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:36
map vtkPolyData to graphics primitives
virtual void PlaceWidget(double *vtkNotUsed(bounds[6]))
The following is a suggested API for widget representations.
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:63
generate a 3D cursor representation
Definition: vtkCursor3D.h:36
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:33