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 =========================================================================*/
00066 #ifndef __vtkSphereWidget_h
00067 #define __vtkSphereWidget_h
00068 
00069 #include "vtk3DWidget.h"
00070 #include "vtkSphereSource.h" // Needed for faster access to the sphere source
00071 
00072 class vtkActor;
00073 class vtkPolyDataMapper;
00074 class vtkPoints;
00075 class vtkPolyData;
00076 class vtkSphereSource;
00077 class vtkSphere;
00078 class vtkCellPicker;
00079 class vtkProperty;
00080 
00081 #define VTK_SPHERE_OFF 0
00082 #define VTK_SPHERE_WIREFRAME 1
00083 #define VTK_SPHERE_SURFACE 2
00084 
00085 class VTK_HYBRID_EXPORT vtkSphereWidget : public vtk3DWidget
00086 {
00087 public:
00089   static vtkSphereWidget *New();
00090 
00091   vtkTypeRevisionMacro(vtkSphereWidget,vtk3DWidget);
00092   void PrintSelf(ostream& os, vtkIndent indent);
00093 
00095 
00096   virtual void SetEnabled(int);
00097   virtual void PlaceWidget(float bounds[6]);
00098   void PlaceWidget()
00099     {this->Superclass::PlaceWidget();}
00100   void PlaceWidget(float xmin, float xmax, float ymin, float ymax, 
00101                    float zmin, float zmax)
00102     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00104 
00106 
00108   vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE);
00109   vtkGetMacro(Representation,int);
00110   void SetRepresentationToOff()
00111     { this->SetRepresentation(VTK_SPHERE_OFF);}
00112   void SetRepresentationToWireframe()
00113     { this->SetRepresentation(VTK_SPHERE_WIREFRAME);}
00114   void SetRepresentationToSurface()
00115     { this->SetRepresentation(VTK_SPHERE_SURFACE);}
00117 
00119 
00120   void SetThetaResolution(int r)
00121     { this->SphereSource->SetThetaResolution(r); }
00122   int GetThetaResolution()
00123     { return this->SphereSource->GetThetaResolution(); }
00125 
00127 
00128   void SetPhiResolution(int r)
00129     { this->SphereSource->SetPhiResolution(r); }
00130   int GetPhiResolution()
00131     { return this->SphereSource->GetPhiResolution(); }
00133 
00135 
00136   void SetRadius(float r)
00137     {
00138     if ( r <= 0 )
00139       {
00140       r = .00001;
00141       }
00142     this->SphereSource->SetRadius(r); 
00143     }
00144   float GetRadius()
00145     { return this->SphereSource->GetRadius(); }
00147 
00149 
00150   void SetCenter(float x, float y, float z) 
00151     {
00152     this->SphereSource->SetCenter(x,y,z); 
00153     }
00154   void SetCenter(float x[3]) 
00155     {
00156     this->SetCenter(x[0], x[1], x[2]);
00157     }
00158   float* GetCenter() 
00159     {return this->SphereSource->GetCenter();}
00160   void GetCenter(float xyz[3]) 
00161     {this->SphereSource->GetCenter(xyz);}
00163 
00165 
00167   vtkSetMacro(Translation,int);
00168   vtkGetMacro(Translation,int);
00169   vtkBooleanMacro(Translation,int);
00170   vtkSetMacro(Scale,int);
00171   vtkGetMacro(Scale,int);
00172   vtkBooleanMacro(Scale,int);
00174 
00176 
00180   vtkSetMacro(HandleVisibility,int);
00181   vtkGetMacro(HandleVisibility,int);
00182   vtkBooleanMacro(HandleVisibility,int);
00184 
00186 
00188   vtkSetVector3Macro(HandleDirection,float);
00189   vtkGetVector3Macro(HandleDirection,float);
00191 
00193 
00194   vtkGetVector3Macro(HandlePosition,float);
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   // 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(float *center, float 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   float HandleDirection[3];
00291   float 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