VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkSphereWidget.h,v $ 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 =========================================================================*/ 00059 #ifndef __vtkSphereWidget_h 00060 #define __vtkSphereWidget_h 00061 00062 #include "vtk3DWidget.h" 00063 #include "vtkSphereSource.h" // Needed for faster access to the sphere source 00064 00065 class vtkActor; 00066 class vtkPolyDataMapper; 00067 class vtkPoints; 00068 class vtkPolyData; 00069 class vtkSphereSource; 00070 class vtkSphere; 00071 class vtkCellPicker; 00072 class vtkProperty; 00073 00074 #define VTK_SPHERE_OFF 0 00075 #define VTK_SPHERE_WIREFRAME 1 00076 #define VTK_SPHERE_SURFACE 2 00077 00078 class VTK_WIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget 00079 { 00080 public: 00082 static vtkSphereWidget *New(); 00083 00084 vtkTypeRevisionMacro(vtkSphereWidget,vtk3DWidget); 00085 void PrintSelf(ostream& os, vtkIndent indent); 00086 00088 00089 virtual void SetEnabled(int); 00090 virtual void PlaceWidget(double bounds[6]); 00091 void PlaceWidget() 00092 {this->Superclass::PlaceWidget();} 00093 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00094 double zmin, double zmax) 00095 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00097 00099 00101 vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE); 00102 vtkGetMacro(Representation,int); 00103 void SetRepresentationToOff() 00104 { this->SetRepresentation(VTK_SPHERE_OFF);} 00105 void SetRepresentationToWireframe() 00106 { this->SetRepresentation(VTK_SPHERE_WIREFRAME);} 00107 void SetRepresentationToSurface() 00108 { this->SetRepresentation(VTK_SPHERE_SURFACE);} 00110 00112 00113 void SetThetaResolution(int r) 00114 { this->SphereSource->SetThetaResolution(r); } 00115 int GetThetaResolution() 00116 { return this->SphereSource->GetThetaResolution(); } 00118 00120 00121 void SetPhiResolution(int r) 00122 { this->SphereSource->SetPhiResolution(r); } 00123 int GetPhiResolution() 00124 { return this->SphereSource->GetPhiResolution(); } 00126 00128 00129 void SetRadius(double r) 00130 { 00131 if ( r <= 0 ) 00132 { 00133 r = .00001; 00134 } 00135 this->SphereSource->SetRadius(r); 00136 } 00137 double GetRadius() 00138 { return this->SphereSource->GetRadius(); } 00140 00142 00143 void SetCenter(double x, double y, double z) 00144 { 00145 this->SphereSource->SetCenter(x,y,z); 00146 } 00147 void SetCenter(double x[3]) 00148 { 00149 this->SetCenter(x[0], x[1], x[2]); 00150 } 00151 double* GetCenter() 00152 {return this->SphereSource->GetCenter();} 00153 void GetCenter(double xyz[3]) 00154 {this->SphereSource->GetCenter(xyz);} 00156 00158 00160 vtkSetMacro(Translation,int); 00161 vtkGetMacro(Translation,int); 00162 vtkBooleanMacro(Translation,int); 00163 vtkSetMacro(Scale,int); 00164 vtkGetMacro(Scale,int); 00165 vtkBooleanMacro(Scale,int); 00167 00169 00173 vtkSetMacro(HandleVisibility,int); 00174 vtkGetMacro(HandleVisibility,int); 00175 vtkBooleanMacro(HandleVisibility,int); 00177 00179 00182 vtkSetVector3Macro(HandleDirection,double); 00183 vtkGetVector3Macro(HandleDirection,double); 00185 00187 00188 vtkGetVector3Macro(HandlePosition,double); 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 00220 protected: 00221 vtkSphereWidget(); 00222 ~vtkSphereWidget(); 00223 00224 //BTX - manage the state of the widget 00225 int State; 00226 enum WidgetState 00227 { 00228 Start=0, 00229 Moving, 00230 Scaling, 00231 Positioning, 00232 Outside 00233 }; 00234 //ETX 00235 00236 //handles the events 00237 static void ProcessEvents(vtkObject* object, 00238 unsigned long event, 00239 void* clientdata, 00240 void* calldata); 00241 00242 // ProcessEvents() dispatches to these methods. 00243 void OnLeftButtonDown(); 00244 void OnLeftButtonUp(); 00245 void OnRightButtonDown(); 00246 void OnRightButtonUp(); 00247 void OnMouseMove(); 00248 00249 // the sphere 00250 vtkActor *SphereActor; 00251 vtkPolyDataMapper *SphereMapper; 00252 vtkSphereSource *SphereSource; 00253 void HighlightSphere(int highlight); 00254 void SelectRepresentation(); 00255 00256 // The representation of the sphere 00257 int Representation; 00258 00259 // Do the picking 00260 vtkCellPicker *Picker; 00261 00262 // Methods to manipulate the sphere widget 00263 int Translation; 00264 int Scale; 00265 void Translate(double *p1, double *p2); 00266 void ScaleSphere(double *p1, double *p2, int X, int Y); 00267 void MoveHandle(double *p1, double *p2, int X, int Y); 00268 void PlaceHandle(double *center, double radius); 00269 00270 // Properties used to control the appearance of selected objects and 00271 // the manipulator in general. 00272 vtkProperty *SphereProperty; 00273 vtkProperty *SelectedSphereProperty; 00274 vtkProperty *HandleProperty; 00275 vtkProperty *SelectedHandleProperty; 00276 void CreateDefaultProperties(); 00277 00278 // Managing the handle 00279 vtkActor *HandleActor; 00280 vtkPolyDataMapper *HandleMapper; 00281 vtkSphereSource *HandleSource; 00282 void HighlightHandle(int); 00283 int HandleVisibility; 00284 double HandleDirection[3]; 00285 double HandlePosition[3]; 00286 virtual void SizeHandles(); 00287 00288 private: 00289 vtkSphereWidget(const vtkSphereWidget&); //Not implemented 00290 void operator=(const vtkSphereWidget&); //Not implemented 00291 }; 00292 00293 #endif