VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkSphereWidget.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 =========================================================================*/ 00058 #ifndef __vtkSphereWidget_h 00059 #define __vtkSphereWidget_h 00060 00061 #include "vtkInteractionWidgetsModule.h" // For export macro 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 VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget 00079 { 00080 public: 00082 static vtkSphereWidget *New(); 00083 00084 vtkTypeMacro(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 00102 vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE); 00103 vtkGetMacro(Representation,int); 00104 void SetRepresentationToOff() 00105 { this->SetRepresentation(VTK_SPHERE_OFF);} 00106 void SetRepresentationToWireframe() 00107 { this->SetRepresentation(VTK_SPHERE_WIREFRAME);} 00108 void SetRepresentationToSurface() 00109 { this->SetRepresentation(VTK_SPHERE_SURFACE);} 00111 00113 00115 void SetThetaResolution(int r) 00116 { this->SphereSource->SetThetaResolution(r); } 00117 int GetThetaResolution() 00118 { return this->SphereSource->GetThetaResolution(); } 00120 00122 00124 void SetPhiResolution(int r) 00125 { this->SphereSource->SetPhiResolution(r); } 00126 int GetPhiResolution() 00127 { return this->SphereSource->GetPhiResolution(); } 00129 00131 00132 void SetRadius(double r) 00133 { 00134 if ( r <= 0 ) 00135 { 00136 r = .00001; 00137 } 00138 this->SphereSource->SetRadius(r); 00139 } 00140 double GetRadius() 00141 { return this->SphereSource->GetRadius(); } 00143 00145 00146 void SetCenter(double x, double y, double z) 00147 { 00148 this->SphereSource->SetCenter(x,y,z); 00149 } 00150 void SetCenter(double x[3]) 00151 { 00152 this->SetCenter(x[0], x[1], x[2]); 00153 } 00154 double* GetCenter() 00155 {return this->SphereSource->GetCenter();} 00156 void GetCenter(double xyz[3]) 00157 {this->SphereSource->GetCenter(xyz);} 00159 00161 00163 vtkSetMacro(Translation,int); 00164 vtkGetMacro(Translation,int); 00165 vtkBooleanMacro(Translation,int); 00166 vtkSetMacro(Scale,int); 00167 vtkGetMacro(Scale,int); 00168 vtkBooleanMacro(Scale,int); 00170 00172 00176 vtkSetMacro(HandleVisibility,int); 00177 vtkGetMacro(HandleVisibility,int); 00178 vtkBooleanMacro(HandleVisibility,int); 00180 00182 00185 vtkSetVector3Macro(HandleDirection,double); 00186 vtkGetVector3Macro(HandleDirection,double); 00188 00190 00191 vtkGetVector3Macro(HandlePosition,double); 00193 00200 void GetPolyData(vtkPolyData *pd); 00201 00206 void GetSphere(vtkSphere *sphere); 00207 00209 00211 vtkGetObjectMacro(SphereProperty,vtkProperty); 00212 vtkGetObjectMacro(SelectedSphereProperty,vtkProperty); 00214 00216 00219 vtkGetObjectMacro(HandleProperty,vtkProperty); 00220 vtkGetObjectMacro(SelectedHandleProperty,vtkProperty); 00222 00223 protected: 00224 vtkSphereWidget(); 00225 ~vtkSphereWidget(); 00226 00227 //BTX - manage the state of the widget 00228 int State; 00229 enum WidgetState 00230 { 00231 Start=0, 00232 Moving, 00233 Scaling, 00234 Positioning, 00235 Outside 00236 }; 00237 //ETX 00238 00239 //handles the events 00240 static void ProcessEvents(vtkObject* object, 00241 unsigned long event, 00242 void* clientdata, 00243 void* calldata); 00244 00245 // ProcessEvents() dispatches to these methods. 00246 void OnLeftButtonDown(); 00247 void OnLeftButtonUp(); 00248 void OnRightButtonDown(); 00249 void OnRightButtonUp(); 00250 void OnMouseMove(); 00251 00252 // the sphere 00253 vtkActor *SphereActor; 00254 vtkPolyDataMapper *SphereMapper; 00255 vtkSphereSource *SphereSource; 00256 void HighlightSphere(int highlight); 00257 void SelectRepresentation(); 00258 00259 // The representation of the sphere 00260 int Representation; 00261 00262 // Do the picking 00263 vtkCellPicker *Picker; 00264 00265 // Register internal Pickers within PickingManager 00266 virtual void RegisterPickers(); 00267 00268 // Methods to manipulate the sphere widget 00269 int Translation; 00270 int Scale; 00271 void Translate(double *p1, double *p2); 00272 void ScaleSphere(double *p1, double *p2, int X, int Y); 00273 void MoveHandle(double *p1, double *p2, int X, int Y); 00274 void PlaceHandle(double *center, double radius); 00275 00276 // Properties used to control the appearance of selected objects and 00277 // the manipulator in general. 00278 vtkProperty *SphereProperty; 00279 vtkProperty *SelectedSphereProperty; 00280 vtkProperty *HandleProperty; 00281 vtkProperty *SelectedHandleProperty; 00282 void CreateDefaultProperties(); 00283 00284 // Managing the handle 00285 vtkActor *HandleActor; 00286 vtkPolyDataMapper *HandleMapper; 00287 vtkSphereSource *HandleSource; 00288 void HighlightHandle(int); 00289 int HandleVisibility; 00290 double HandleDirection[3]; 00291 double HandlePosition[3]; 00292 virtual void SizeHandles(); 00293 00294 private: 00295 vtkSphereWidget(const vtkSphereWidget&); //Not implemented 00296 void operator=(const vtkSphereWidget&); //Not implemented 00297 }; 00298 00299 #endif