VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkSphereRepresentation.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00048 #ifndef __vtkSphereRepresentation_h 00049 #define __vtkSphereRepresentation_h 00050 00051 #include "vtkInteractionWidgetsModule.h" // For export macro 00052 #include "vtkWidgetRepresentation.h" 00053 #include "vtkSphereSource.h" // Needed for fast access to the sphere source 00054 00055 class vtkActor; 00056 class vtkPolyDataMapper; 00057 class vtkSphere; 00058 class vtkSphereSource; 00059 class vtkCellPicker; 00060 class vtkProperty; 00061 class vtkPolyData; 00062 class vtkPoints; 00063 class vtkPolyDataAlgorithm; 00064 class vtkTransform; 00065 class vtkDoubleArray; 00066 class vtkMatrix4x4; 00067 class vtkTextMapper; 00068 class vtkActor2D; 00069 class vtkTextProperty; 00070 class vtkLineSource; 00071 00072 #define VTK_SPHERE_OFF 0 00073 #define VTK_SPHERE_WIREFRAME 1 00074 #define VTK_SPHERE_SURFACE 2 00075 00076 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereRepresentation : public vtkWidgetRepresentation 00077 { 00078 public: 00080 static vtkSphereRepresentation *New(); 00081 00083 00085 vtkTypeMacro(vtkSphereRepresentation,vtkWidgetRepresentation); 00086 void PrintSelf(ostream& os, vtkIndent indent); 00088 00089 //BTX - used to manage the state of the widget 00090 enum {Outside=0,MovingHandle,OnSphere,Translating,Scaling}; 00091 //ETX 00092 00094 00096 vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE); 00097 vtkGetMacro(Representation,int); 00098 void SetRepresentationToOff() 00099 { this->SetRepresentation(VTK_SPHERE_OFF);} 00100 void SetRepresentationToWireframe() 00101 { this->SetRepresentation(VTK_SPHERE_WIREFRAME);} 00102 void SetRepresentationToSurface() 00103 { this->SetRepresentation(VTK_SPHERE_SURFACE);} 00105 00107 00108 void SetThetaResolution(int r) 00109 { this->SphereSource->SetThetaResolution(r); } 00110 int GetThetaResolution() 00111 { return this->SphereSource->GetThetaResolution(); } 00113 00115 00116 void SetPhiResolution(int r) 00117 { this->SphereSource->SetPhiResolution(r); } 00118 int GetPhiResolution() 00119 { return this->SphereSource->GetPhiResolution(); } 00121 00123 00126 void SetCenter(double c[3]); 00127 void SetCenter(double x, double y, double z) 00128 {double c[3]; c[0]=x; c[1]=y; c[2]=z; this->SetCenter(c);} 00129 double* GetCenter() 00130 {return this->SphereSource->GetCenter();} 00131 void GetCenter(double xyz[3]) 00132 {this->SphereSource->GetCenter(xyz);} 00134 00136 00138 void SetRadius(double r); 00139 double GetRadius() 00140 { return this->SphereSource->GetRadius(); } 00142 00144 00148 vtkSetMacro(HandleVisibility,int); 00149 vtkGetMacro(HandleVisibility,int); 00150 vtkBooleanMacro(HandleVisibility,int); 00152 00154 00156 void SetHandlePosition(double handle[3]); 00157 void SetHandlePosition(double x, double y, double z) 00158 {double p[3]; p[0]=x; p[1]=y; p[2]=z; this->SetHandlePosition(p);} 00159 vtkGetVector3Macro(HandlePosition,double); 00161 00163 00166 void SetHandleDirection(double dir[3]); 00167 void SetHandleDirection(double dx, double dy, double dz) 00168 {double d[3]; d[0]=dx; d[1]=dy; d[2]=dz; this->SetHandleDirection(d);} 00169 vtkGetVector3Macro(HandleDirection,double); 00171 00173 00178 vtkSetMacro(HandleText,int); 00179 vtkGetMacro(HandleText,int); 00180 vtkBooleanMacro(HandleText,int); 00182 00184 00186 vtkSetMacro(RadialLine,int); 00187 vtkGetMacro(RadialLine,int); 00188 vtkBooleanMacro(RadialLine,int); 00190 00197 void GetPolyData(vtkPolyData *pd); 00198 00203 void GetSphere(vtkSphere *sphere); 00204 00206 00208 vtkGetObjectMacro(SphereProperty,vtkProperty); 00209 vtkGetObjectMacro(SelectedSphereProperty,vtkProperty); 00211 00213 00216 vtkGetObjectMacro(HandleProperty,vtkProperty); 00217 vtkGetObjectMacro(SelectedHandleProperty,vtkProperty); 00219 00221 00223 vtkGetObjectMacro(HandleTextProperty,vtkTextProperty); 00225 00227 00229 vtkGetObjectMacro(RadialLineProperty,vtkProperty); 00231 00239 void SetInteractionState(int state); 00240 00242 00245 virtual void PlaceWidget(double bounds[6]); 00246 virtual void PlaceWidget(double center[3], double handlePosition[3]); 00247 virtual void BuildRepresentation(); 00248 virtual int ComputeInteractionState(int X, int Y, int modify=0); 00249 virtual void StartWidgetInteraction(double e[2]); 00250 virtual void WidgetInteraction(double e[2]); 00251 virtual double *GetBounds(); 00253 00255 00256 virtual void ReleaseGraphicsResources(vtkWindow*); 00257 virtual int RenderOpaqueGeometry(vtkViewport*); 00258 virtual int RenderTranslucentPolygonalGeometry(vtkViewport*); 00259 virtual int RenderOverlay(vtkViewport*); 00260 virtual int HasTranslucentPolygonalGeometry(); 00262 00263 protected: 00264 vtkSphereRepresentation(); 00265 ~vtkSphereRepresentation(); 00266 00267 // Manage how the representation appears 00268 double LastEventPosition[3]; 00269 00270 // the sphere 00271 vtkActor *SphereActor; 00272 vtkPolyDataMapper *SphereMapper; 00273 vtkSphereSource *SphereSource; 00274 void HighlightSphere(int highlight); 00275 00276 // The representation of the sphere 00277 int Representation; 00278 00279 // Do the picking 00280 vtkCellPicker *HandlePicker; 00281 vtkCellPicker *SpherePicker; 00282 double LastPickPosition[3]; 00283 00284 // Register internal Pickers within PickingManager 00285 virtual void RegisterPickers(); 00286 00287 // Methods to manipulate the sphere widget 00288 void Translate(double *p1, double *p2); 00289 void Scale(double *p1, double *p2, int X, int Y); 00290 void PlaceHandle(double *center, double radius); 00291 virtual void SizeHandles(); 00292 00293 // Properties used to control the appearance of selected objects and 00294 // the manipulator in general. 00295 vtkProperty *SphereProperty; 00296 vtkProperty *SelectedSphereProperty; 00297 vtkProperty *HandleProperty; 00298 vtkProperty *SelectedHandleProperty; 00299 void CreateDefaultProperties(); 00300 00301 // Managing the handle 00302 vtkActor *HandleActor; 00303 vtkPolyDataMapper *HandleMapper; 00304 vtkSphereSource *HandleSource; 00305 void HighlightHandle(int); 00306 int HandleVisibility; 00307 double HandleDirection[3]; 00308 double HandlePosition[3]; 00309 00310 // Manage the handle label 00311 int HandleText; 00312 vtkTextProperty *HandleTextProperty; 00313 vtkTextMapper *HandleTextMapper; 00314 vtkActor2D *HandleTextActor; 00315 00316 // Manage the radial line segment 00317 int RadialLine; 00318 vtkProperty *RadialLineProperty; 00319 vtkLineSource *RadialLineSource; 00320 vtkPolyDataMapper *RadialLineMapper; 00321 vtkActor *RadialLineActor; 00322 00323 private: 00324 vtkSphereRepresentation(const vtkSphereRepresentation&); //Not implemented 00325 void operator=(const vtkSphereRepresentation&); //Not implemented 00326 }; 00327 00328 #endif