Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkSphereWidget.h

Go to the documentation of this file.
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 =========================================================================*/
00073 #ifndef __vtkSphereWidget_h
00074 #define __vtkSphereWidget_h
00075 
00076 #include "vtk3DWidget.h"
00077 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
00078 
00079 class vtkActor;
00080 class vtkPolyDataMapper;
00081 class vtkPoints;
00082 class vtkPolyData;
00083 class vtkSphereSource;
00084 class vtkSphere;
00085 class vtkCellPicker;
00086 class vtkProperty;
00087 
00088 #define VTK_SPHERE_OFF 0
00089 #define VTK_SPHERE_WIREFRAME 1
00090 #define VTK_SPHERE_SURFACE 2
00091 
00092 class VTK_HYBRID_EXPORT vtkSphereWidget : public vtk3DWidget
00093 {
00094 public:
00096   static vtkSphereWidget *New();
00097 
00098   vtkTypeRevisionMacro(vtkSphereWidget,vtk3DWidget);
00099   void PrintSelf(ostream& os, vtkIndent indent);
00100 
00102 
00103   virtual void SetEnabled(int);
00104   virtual void PlaceWidget(double bounds[6]);
00105   void PlaceWidget()
00106     {this->Superclass::PlaceWidget();}
00107   void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 
00108                    double zmin, double zmax)
00109     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00111 
00113 
00115   vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE);
00116   vtkGetMacro(Representation,int);
00117   void SetRepresentationToOff()
00118     { this->SetRepresentation(VTK_SPHERE_OFF);}
00119   void SetRepresentationToWireframe()
00120     { this->SetRepresentation(VTK_SPHERE_WIREFRAME);}
00121   void SetRepresentationToSurface()
00122     { this->SetRepresentation(VTK_SPHERE_SURFACE);}
00124 
00126 
00127   void SetThetaResolution(int r)
00128     { this->SphereSource->SetThetaResolution(r); }
00129   int GetThetaResolution()
00130     { return this->SphereSource->GetThetaResolution(); }
00132 
00134 
00135   void SetPhiResolution(int r)
00136     { this->SphereSource->SetPhiResolution(r); }
00137   int GetPhiResolution()
00138     { return this->SphereSource->GetPhiResolution(); }
00140 
00142 
00143   void SetRadius(double r)
00144     {
00145     if ( r <= 0 )
00146       {
00147       r = .00001;
00148       }
00149     this->SphereSource->SetRadius(r); 
00150     }
00151   double GetRadius()
00152     { return this->SphereSource->GetRadius(); }
00154 
00156 
00157   void SetCenter(double x, double y, double z) 
00158     {
00159     this->SphereSource->SetCenter(x,y,z); 
00160     }
00161   void SetCenter(double x[3]) 
00162     {
00163     this->SetCenter(x[0], x[1], x[2]);
00164     }
00165   double* GetCenter() 
00166     {return this->SphereSource->GetCenter();}
00167   void GetCenter(double xyz[3]) 
00168     {this->SphereSource->GetCenter(xyz);}
00170 
00172 
00174   vtkSetMacro(Translation,int);
00175   vtkGetMacro(Translation,int);
00176   vtkBooleanMacro(Translation,int);
00177   vtkSetMacro(Scale,int);
00178   vtkGetMacro(Scale,int);
00179   vtkBooleanMacro(Scale,int);
00181 
00183 
00187   vtkSetMacro(HandleVisibility,int);
00188   vtkGetMacro(HandleVisibility,int);
00189   vtkBooleanMacro(HandleVisibility,int);
00191 
00193 
00195   vtkSetVector3Macro(HandleDirection,double);
00196   vtkGetVector3Macro(HandleDirection,double);
00198 
00200 
00201   vtkGetVector3Macro(HandlePosition,double);
00203   
00210   void GetPolyData(vtkPolyData *pd);
00211 
00216   void GetSphere(vtkSphere *sphere);
00217 
00219 
00221   vtkGetObjectMacro(SphereProperty,vtkProperty);
00222   vtkGetObjectMacro(SelectedSphereProperty,vtkProperty);
00224   
00226 
00229   vtkGetObjectMacro(HandleProperty,vtkProperty);
00230   vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
00232   
00233 protected:
00234   vtkSphereWidget();
00235   ~vtkSphereWidget();
00236 
00237 //BTX - manage the state of the widget
00238   int State;
00239   enum WidgetState
00240   {
00241     Start=0,
00242     Moving,
00243     Scaling,
00244     Positioning,
00245     Outside
00246   };
00247 //ETX
00248     
00249   //handles the events
00250   static void ProcessEvents(vtkObject* object, 
00251                             unsigned long event,
00252                             void* clientdata, 
00253                             void* calldata);
00254 
00255   // ProcessEvents() dispatches to these methods.
00256   void OnLeftButtonDown();
00257   void OnLeftButtonUp();
00258   void OnRightButtonDown();
00259   void OnRightButtonUp();
00260   void OnMouseMove();
00261 
00262   // the sphere
00263   vtkActor          *SphereActor;
00264   vtkPolyDataMapper *SphereMapper;
00265   vtkSphereSource     *SphereSource;
00266   void HighlightSphere(int highlight);
00267   void SelectRepresentation();
00268 
00269   // The representation of the sphere
00270   int Representation;
00271 
00272   // Do the picking
00273   vtkCellPicker *Picker;
00274   
00275   // Methods to manipulate the sphere widget
00276   int Translation;
00277   int Scale;
00278   void Translate(double *p1, double *p2);
00279   void ScaleSphere(double *p1, double *p2, int X, int Y);
00280   void MoveHandle(double *p1, double *p2, int X, int Y);
00281   void PlaceHandle(double *center, double radius);
00282   
00283   // Properties used to control the appearance of selected objects and
00284   // the manipulator in general.
00285   vtkProperty *SphereProperty;
00286   vtkProperty *SelectedSphereProperty;
00287   vtkProperty *HandleProperty;
00288   vtkProperty *SelectedHandleProperty;
00289   void CreateDefaultProperties();
00290 
00291   // Managing the handle
00292   vtkActor          *HandleActor;
00293   vtkPolyDataMapper *HandleMapper;
00294   vtkSphereSource   *HandleSource;
00295   void HighlightHandle(int);
00296   int HandleVisibility;
00297   double HandleDirection[3];
00298   double HandlePosition[3];
00299   virtual void SizeHandles();
00300 
00301 private:
00302   vtkSphereWidget(const vtkSphereWidget&);  //Not implemented
00303   void operator=(const vtkSphereWidget&);  //Not implemented
00304 };
00305 
00306 #endif