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

Hybrid/vtkSphereWidget.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkSphereWidget.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00077 #ifndef __vtkSphereWidget_h
00078 #define __vtkSphereWidget_h
00079 
00080 #include "vtk3DWidget.h"
00081 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
00082 
00083 class vtkActor;
00084 class vtkPolyDataMapper;
00085 class vtkPoints;
00086 class vtkPolyData;
00087 class vtkSphereSource;
00088 class vtkSphere;
00089 class vtkCellPicker;
00090 class vtkProperty;
00091 
00092 #define VTK_SPHERE_OFF 0
00093 #define VTK_SPHERE_WIREFRAME 1
00094 #define VTK_SPHERE_SURFACE 2
00095 
00096 class VTK_HYBRID_EXPORT vtkSphereWidget : public vtk3DWidget
00097 {
00098 public:
00100   static vtkSphereWidget *New();
00101 
00102   vtkTypeRevisionMacro(vtkSphereWidget,vtk3DWidget);
00103   void PrintSelf(ostream& os, vtkIndent indent);
00104 
00106 
00107   virtual void SetEnabled(int);
00108   virtual void PlaceWidget(float bounds[6]);
00109   void PlaceWidget()
00110     {this->Superclass::PlaceWidget();}
00111   void PlaceWidget(float xmin, float xmax, float ymin, float ymax, 
00112                    float zmin, float zmax)
00113     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00115 
00117 
00119   vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE);
00120   vtkGetMacro(Representation,int);
00121   void SetRepresentationToOff()
00122     { this->SetRepresentation(VTK_SPHERE_OFF);}
00123   void SetRepresentationToWireframe()
00124     { this->SetRepresentation(VTK_SPHERE_WIREFRAME);}
00125   void SetRepresentationToSurface()
00126     { this->SetRepresentation(VTK_SPHERE_SURFACE);}
00128 
00130 
00131   void SetThetaResolution(int r)
00132     { this->SphereSource->SetThetaResolution(r); }
00133   int GetThetaResolution()
00134     { return this->SphereSource->GetThetaResolution(); }
00136 
00138 
00139   void SetPhiResolution(int r)
00140     { this->SphereSource->SetPhiResolution(r); }
00141   int GetPhiResolution()
00142     { return this->SphereSource->GetPhiResolution(); }
00144 
00146 
00147   void SetRadius(float r)
00148     {
00149     if ( r <= 0 )
00150       {
00151       r = .00001;
00152       }
00153     this->SphereSource->SetRadius(r); 
00154     }
00155   float GetRadius()
00156     { return this->SphereSource->GetRadius(); }
00158 
00160 
00161   void SetCenter(float x, float y, float z) 
00162     {
00163     this->SphereSource->SetCenter(x,y,z); 
00164     }
00165   void SetCenter(float x[3]) 
00166     {
00167     this->SetCenter(x[0], x[1], x[2]);
00168     }
00169   float* GetCenter() 
00170     {return this->SphereSource->GetCenter();}
00171   void GetCenter(float xyz[3]) 
00172     {this->SphereSource->GetCenter(xyz);}
00174 
00176 
00178   vtkSetMacro(Translation,int);
00179   vtkGetMacro(Translation,int);
00180   vtkBooleanMacro(Translation,int);
00181   vtkSetMacro(Scale,int);
00182   vtkGetMacro(Scale,int);
00183   vtkBooleanMacro(Scale,int);
00185 
00187 
00191   vtkSetMacro(HandleVisibility,int);
00192   vtkGetMacro(HandleVisibility,int);
00193   vtkBooleanMacro(HandleVisibility,int);
00195 
00197 
00199   vtkSetVector3Macro(HandleDirection,float);
00200   vtkGetVector3Macro(HandleDirection,float);
00202 
00204 
00205   vtkGetVector3Macro(HandlePosition,float);
00207   
00214   void GetPolyData(vtkPolyData *pd);
00215 
00220   void GetSphere(vtkSphere *sphere);
00221 
00223 
00225   vtkGetObjectMacro(SphereProperty,vtkProperty);
00226   vtkGetObjectMacro(SelectedSphereProperty,vtkProperty);
00228   
00230 
00233   vtkGetObjectMacro(HandleProperty,vtkProperty);
00234   vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
00236   
00237 protected:
00238   vtkSphereWidget();
00239   ~vtkSphereWidget();
00240 
00241 //BTX - manage the state of the widget
00242   int State;
00243   enum WidgetState
00244   {
00245     Start=0,
00246     Moving,
00247     Scaling,
00248     Positioning,
00249     Outside
00250   };
00251 //ETX
00252     
00253   //handles the events
00254   static void ProcessEvents(vtkObject* object, 
00255                             unsigned long event,
00256                             void* clientdata, 
00257                             void* calldata);
00258 
00259   // ProcessEvents() dispatches to these methods.
00260   void OnLeftButtonDown();
00261   void OnLeftButtonUp();
00262   void OnRightButtonDown();
00263   void OnRightButtonUp();
00264   void OnMouseMove();
00265 
00266   // the sphere
00267   vtkActor          *SphereActor;
00268   vtkPolyDataMapper *SphereMapper;
00269   vtkSphereSource     *SphereSource;
00270   void HighlightSphere(int highlight);
00271   void SelectRepresentation();
00272 
00273   // The representation of the sphere
00274   int Representation;
00275 
00276   // Do the picking
00277   vtkCellPicker *Picker;
00278   
00279   // Methods to manipulate the sphere widget
00280   int Translation;
00281   int Scale;
00282   void Translate(double *p1, double *p2);
00283   void ScaleSphere(double *p1, double *p2, int X, int Y);
00284   void MoveHandle(double *p1, double *p2, int X, int Y);
00285   void PlaceHandle(float *center, float radius);
00286   
00287   // Properties used to control the appearance of selected objects and
00288   // the manipulator in general.
00289   vtkProperty *SphereProperty;
00290   vtkProperty *SelectedSphereProperty;
00291   vtkProperty *HandleProperty;
00292   vtkProperty *SelectedHandleProperty;
00293   void CreateDefaultProperties();
00294 
00295   // Managing the handle
00296   vtkActor          *HandleActor;
00297   vtkPolyDataMapper *HandleMapper;
00298   vtkSphereSource   *HandleSource;
00299   void HighlightHandle(int);
00300   int HandleVisibility;
00301   float HandleDirection[3];
00302   float HandlePosition[3];
00303   virtual void SizeHandles();
00304 
00305 private:
00306   vtkSphereWidget(const vtkSphereWidget&);  //Not implemented
00307   void operator=(const vtkSphereWidget&);  //Not implemented
00308 };
00309 
00310 #endif