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 =========================================================================*/
48 #ifndef __vtkSphereRepresentation_h
49 #define __vtkSphereRepresentation_h
50 
51 #include "vtkInteractionWidgetsModule.h" // For export macro
53 #include "vtkSphereSource.h" // Needed for fast access to the sphere source
54 
55 class vtkActor;
56 class vtkPolyDataMapper;
57 class vtkSphere;
58 class vtkSphereSource;
59 class vtkCellPicker;
60 class vtkProperty;
61 class vtkPolyData;
62 class vtkPoints;
64 class vtkTransform;
65 class vtkDoubleArray;
66 class vtkMatrix4x4;
67 class vtkTextMapper;
68 class vtkActor2D;
69 class vtkTextProperty;
70 class vtkLineSource;
71 
72 #define VTK_SPHERE_OFF 0
73 #define VTK_SPHERE_WIREFRAME 1
74 #define VTK_SPHERE_SURFACE 2
75 
76 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereRepresentation : public vtkWidgetRepresentation
77 {
78 public:
80  static vtkSphereRepresentation *New();
81 
83 
86  void PrintSelf(ostream& os, vtkIndent indent);
88 
89 //BTX - used to manage the state of the widget
90  enum {Outside=0,MovingHandle,OnSphere,Translating,Scaling};
91 //ETX
92 
94 
96  vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE);
97  vtkGetMacro(Representation,int);
98  void SetRepresentationToOff()
99  { this->SetRepresentation(VTK_SPHERE_OFF);}
100  void SetRepresentationToWireframe()
101  { this->SetRepresentation(VTK_SPHERE_WIREFRAME);}
102  void SetRepresentationToSurface()
103  { this->SetRepresentation(VTK_SPHERE_SURFACE);}
105 
107 
108  void SetThetaResolution(int r)
109  { this->SphereSource->SetThetaResolution(r); }
110  int GetThetaResolution()
111  { return this->SphereSource->GetThetaResolution(); }
113 
115 
116  void SetPhiResolution(int r)
117  { this->SphereSource->SetPhiResolution(r); }
118  int GetPhiResolution()
119  { return this->SphereSource->GetPhiResolution(); }
121 
123 
126  void SetCenter(double c[3]);
127  void SetCenter(double x, double y, double z)
128  {double c[3]; c[0]=x; c[1]=y; c[2]=z; this->SetCenter(c);}
129  double* GetCenter()
130  {return this->SphereSource->GetCenter();}
131  void GetCenter(double xyz[3])
132  {this->SphereSource->GetCenter(xyz);}
134 
136 
138  void SetRadius(double r);
139  double GetRadius()
140  { return this->SphereSource->GetRadius(); }
142 
144 
148  vtkSetMacro(HandleVisibility,int);
149  vtkGetMacro(HandleVisibility,int);
150  vtkBooleanMacro(HandleVisibility,int);
152 
154 
156  void SetHandlePosition(double handle[3]);
157  void SetHandlePosition(double x, double y, double z)
158  {double p[3]; p[0]=x; p[1]=y; p[2]=z; this->SetHandlePosition(p);}
159  vtkGetVector3Macro(HandlePosition,double);
161 
163 
166  void SetHandleDirection(double dir[3]);
167  void SetHandleDirection(double dx, double dy, double dz)
168  {double d[3]; d[0]=dx; d[1]=dy; d[2]=dz; this->SetHandleDirection(d);}
169  vtkGetVector3Macro(HandleDirection,double);
171 
173 
178  vtkSetMacro(HandleText,int);
179  vtkGetMacro(HandleText,int);
180  vtkBooleanMacro(HandleText,int);
182 
184 
186  vtkSetMacro(RadialLine,int);
187  vtkGetMacro(RadialLine,int);
188  vtkBooleanMacro(RadialLine,int);
190 
197  void GetPolyData(vtkPolyData *pd);
198 
203  void GetSphere(vtkSphere *sphere);
204 
206 
208  vtkGetObjectMacro(SphereProperty,vtkProperty);
209  vtkGetObjectMacro(SelectedSphereProperty,vtkProperty);
211 
213 
216  vtkGetObjectMacro(HandleProperty,vtkProperty);
217  vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
219 
221 
223  vtkGetObjectMacro(HandleTextProperty,vtkTextProperty);
225 
227 
229  vtkGetObjectMacro(RadialLineProperty,vtkProperty);
231 
239  void SetInteractionState(int state);
240 
242 
245  virtual void PlaceWidget(double bounds[6]);
246  virtual void PlaceWidget(double center[3], double handlePosition[3]);
247  virtual void BuildRepresentation();
248  virtual int ComputeInteractionState(int X, int Y, int modify=0);
249  virtual void StartWidgetInteraction(double e[2]);
250  virtual void WidgetInteraction(double e[2]);
251  virtual double *GetBounds();
253 
255 
256  virtual void ReleaseGraphicsResources(vtkWindow*);
257  virtual int RenderOpaqueGeometry(vtkViewport*);
259  virtual int RenderOverlay(vtkViewport*);
260  virtual int HasTranslucentPolygonalGeometry();
262 
263 protected:
266 
267  // Manage how the representation appears
268  double LastEventPosition[3];
269 
270  // the sphere
274  void HighlightSphere(int highlight);
275 
276  // The representation of the sphere
278 
279  // Do the picking
282  double LastPickPosition[3];
283 
284  // Methods to manipulate the sphere widget
285  void Translate(double *p1, double *p2);
286  void Scale(double *p1, double *p2, int X, int Y);
287  void PlaceHandle(double *center, double radius);
288  virtual void SizeHandles();
289 
290  // Properties used to control the appearance of selected objects and
291  // the manipulator in general.
296  void CreateDefaultProperties();
297 
298  // Managing the handle
302  void HighlightHandle(int);
304  double HandleDirection[3];
305  double HandlePosition[3];
306 
307  // Manage the handle label
312 
313  // Manage the radial line segment
319 
320 private:
321  vtkSphereRepresentation(const vtkSphereRepresentation&); //Not implemented
322  void operator=(const vtkSphereRepresentation&); //Not implemented
323 };
324 
325 #endif