VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Interaction/Widgets/vtkSphereWidget.h
Go to the documentation of this file.
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 =========================================================================*/
00061 #ifndef vtkSphereWidget_h
00062 #define vtkSphereWidget_h
00063 
00064 #include "vtkInteractionWidgetsModule.h" // For export macro
00065 #include "vtk3DWidget.h"
00066 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
00067 
00068 class vtkActor;
00069 class vtkPolyDataMapper;
00070 class vtkPoints;
00071 class vtkPolyData;
00072 class vtkSphereSource;
00073 class vtkSphere;
00074 class vtkCellPicker;
00075 class vtkProperty;
00076 
00077 #define VTK_SPHERE_OFF 0
00078 #define VTK_SPHERE_WIREFRAME 1
00079 #define VTK_SPHERE_SURFACE 2
00080 
00081 class VTKINTERACTIONWIDGETS_EXPORT vtkSphereWidget : public vtk3DWidget
00082 {
00083 public:
00085   static vtkSphereWidget *New();
00086 
00087   vtkTypeMacro(vtkSphereWidget,vtk3DWidget);
00088   void PrintSelf(ostream& os, vtkIndent indent);
00089 
00091 
00092   virtual void SetEnabled(int);
00093   virtual void PlaceWidget(double bounds[6]);
00094   void PlaceWidget()
00095     {this->Superclass::PlaceWidget();}
00096   void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
00097                    double zmin, double zmax)
00098     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00100 
00102 
00105   vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE);
00106   vtkGetMacro(Representation,int);
00107   void SetRepresentationToOff()
00108     { this->SetRepresentation(VTK_SPHERE_OFF);}
00109   void SetRepresentationToWireframe()
00110     { this->SetRepresentation(VTK_SPHERE_WIREFRAME);}
00111   void SetRepresentationToSurface()
00112     { this->SetRepresentation(VTK_SPHERE_SURFACE);}
00114 
00116 
00118   void SetThetaResolution(int r)
00119     { this->SphereSource->SetThetaResolution(r); }
00120   int GetThetaResolution()
00121     { return this->SphereSource->GetThetaResolution(); }
00123 
00125 
00127   void SetPhiResolution(int r)
00128     { this->SphereSource->SetPhiResolution(r); }
00129   int GetPhiResolution()
00130     { return this->SphereSource->GetPhiResolution(); }
00132 
00134 
00135   void SetRadius(double r)
00136     {
00137     if ( r <= 0 )
00138       {
00139       r = .00001;
00140       }
00141     this->SphereSource->SetRadius(r);
00142     }
00143   double GetRadius()
00144     { return this->SphereSource->GetRadius(); }
00146 
00148 
00149   void SetCenter(double x, double y, double z)
00150     {
00151     this->SphereSource->SetCenter(x,y,z);
00152     }
00153   void SetCenter(double x[3])
00154     {
00155     this->SetCenter(x[0], x[1], x[2]);
00156     }
00157   double* GetCenter()
00158     {return this->SphereSource->GetCenter();}
00159   void GetCenter(double xyz[3])
00160     {this->SphereSource->GetCenter(xyz);}
00162 
00164 
00166   vtkSetMacro(Translation,int);
00167   vtkGetMacro(Translation,int);
00168   vtkBooleanMacro(Translation,int);
00169   vtkSetMacro(Scale,int);
00170   vtkGetMacro(Scale,int);
00171   vtkBooleanMacro(Scale,int);
00173 
00175 
00179   vtkSetMacro(HandleVisibility,int);
00180   vtkGetMacro(HandleVisibility,int);
00181   vtkBooleanMacro(HandleVisibility,int);
00183 
00185 
00188   vtkSetVector3Macro(HandleDirection,double);
00189   vtkGetVector3Macro(HandleDirection,double);
00191 
00193 
00194   vtkGetVector3Macro(HandlePosition,double);
00196 
00203   void GetPolyData(vtkPolyData *pd);
00204 
00209   void GetSphere(vtkSphere *sphere);
00210 
00212 
00214   vtkGetObjectMacro(SphereProperty,vtkProperty);
00215   vtkGetObjectMacro(SelectedSphereProperty,vtkProperty);
00217 
00219 
00222   vtkGetObjectMacro(HandleProperty,vtkProperty);
00223   vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
00225 
00226 protected:
00227   vtkSphereWidget();
00228   ~vtkSphereWidget();
00229 
00230 //BTX - manage the state of the widget
00231   int State;
00232   enum WidgetState
00233   {
00234     Start=0,
00235     Moving,
00236     Scaling,
00237     Positioning,
00238     Outside
00239   };
00240 //ETX
00241 
00242   //handles the events
00243   static void ProcessEvents(vtkObject* object,
00244                             unsigned long event,
00245                             void* clientdata,
00246                             void* calldata);
00247 
00248   // ProcessEvents() dispatches to these methods.
00249   void OnLeftButtonDown();
00250   void OnLeftButtonUp();
00251   void OnRightButtonDown();
00252   void OnRightButtonUp();
00253   void OnMouseMove();
00254 
00255   // the sphere
00256   vtkActor          *SphereActor;
00257   vtkPolyDataMapper *SphereMapper;
00258   vtkSphereSource     *SphereSource;
00259   void HighlightSphere(int highlight);
00260   void SelectRepresentation();
00261 
00262   // The representation of the sphere
00263   int Representation;
00264 
00265   // Do the picking
00266   vtkCellPicker *Picker;
00267 
00268   // Register internal Pickers within PickingManager
00269   virtual void RegisterPickers();
00270 
00271   // Methods to manipulate the sphere widget
00272   int Translation;
00273   int Scale;
00274   void Translate(double *p1, double *p2);
00275   void ScaleSphere(double *p1, double *p2, int X, int Y);
00276   void MoveHandle(double *p1, double *p2, int X, int Y);
00277   void PlaceHandle(double *center, double radius);
00278 
00279   // Properties used to control the appearance of selected objects and
00280   // the manipulator in general.
00281   vtkProperty *SphereProperty;
00282   vtkProperty *SelectedSphereProperty;
00283   vtkProperty *HandleProperty;
00284   vtkProperty *SelectedHandleProperty;
00285   void CreateDefaultProperties();
00286 
00287   // Managing the handle
00288   vtkActor          *HandleActor;
00289   vtkPolyDataMapper *HandleMapper;
00290   vtkSphereSource   *HandleSource;
00291   void HighlightHandle(int);
00292   int HandleVisibility;
00293   double HandleDirection[3];
00294   double HandlePosition[3];
00295   virtual void SizeHandles();
00296 
00297 private:
00298   vtkSphereWidget(const vtkSphereWidget&);  //Not implemented
00299   void operator=(const vtkSphereWidget&);  //Not implemented
00300 };
00301 
00302 #endif