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