VTK
dox/Widgets/vtkSphereRepresentation.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkSphereRepresentation.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 =========================================================================*/
00048 #ifndef __vtkSphereRepresentation_h
00049 #define __vtkSphereRepresentation_h
00050 
00051 #include "vtkWidgetRepresentation.h"
00052 #include "vtkSphereSource.h" // Needed for fast access to the sphere source
00053 
00054 class vtkActor;
00055 class vtkPolyDataMapper;
00056 class vtkSphere;
00057 class vtkSphereSource;
00058 class vtkCellPicker;
00059 class vtkProperty;
00060 class vtkPolyData;
00061 class vtkPoints;
00062 class vtkPolyDataAlgorithm;
00063 class vtkTransform;
00064 class vtkDoubleArray;
00065 class vtkMatrix4x4;
00066 class vtkTextMapper;
00067 class vtkActor2D;
00068 class vtkTextProperty;
00069 class vtkLineSource;
00070 
00071 #define VTK_SPHERE_OFF 0
00072 #define VTK_SPHERE_WIREFRAME 1
00073 #define VTK_SPHERE_SURFACE 2
00074 
00075 class VTK_WIDGETS_EXPORT vtkSphereRepresentation : public vtkWidgetRepresentation
00076 {
00077 public:
00079   static vtkSphereRepresentation *New();
00080 
00082 
00084   vtkTypeMacro(vtkSphereRepresentation,vtkWidgetRepresentation);
00085   void PrintSelf(ostream& os, vtkIndent indent);
00087 
00088 //BTX - used to manage the state of the widget
00089   enum {Outside=0,MovingHandle,OnSphere,Translating,Scaling};
00090 //ETX
00091 
00093 
00095   vtkSetClampMacro(Representation,int,VTK_SPHERE_OFF,VTK_SPHERE_SURFACE);
00096   vtkGetMacro(Representation,int);
00097   void SetRepresentationToOff()
00098     { this->SetRepresentation(VTK_SPHERE_OFF);}
00099   void SetRepresentationToWireframe()
00100     { this->SetRepresentation(VTK_SPHERE_WIREFRAME);}
00101   void SetRepresentationToSurface()
00102     { this->SetRepresentation(VTK_SPHERE_SURFACE);}
00104 
00106 
00107   void SetThetaResolution(int r)
00108     { this->SphereSource->SetThetaResolution(r); }
00109   int GetThetaResolution()
00110     { return this->SphereSource->GetThetaResolution(); }
00112 
00114 
00115   void SetPhiResolution(int r)
00116     { this->SphereSource->SetPhiResolution(r); }
00117   int GetPhiResolution()
00118     { return this->SphereSource->GetPhiResolution(); }
00120 
00122 
00125   void SetCenter(double c[3]);
00126   void SetCenter(double x, double y, double z)
00127     {double c[3]; c[0]=x; c[1]=y; c[2]=z; this->SetCenter(c);}
00128   double* GetCenter() 
00129     {return this->SphereSource->GetCenter();}
00130   void GetCenter(double xyz[3]) 
00131     {this->SphereSource->GetCenter(xyz);}
00133 
00135 
00137   void SetRadius(double r);
00138   double GetRadius()
00139     { return this->SphereSource->GetRadius(); }
00141 
00143 
00147   vtkSetMacro(HandleVisibility,int);
00148   vtkGetMacro(HandleVisibility,int);
00149   vtkBooleanMacro(HandleVisibility,int);
00151 
00153 
00155   void SetHandlePosition(double handle[3]);
00156   void SetHandlePosition(double x, double y, double z)
00157     {double p[3]; p[0]=x; p[1]=y; p[2]=z; this->SetHandlePosition(p);}
00158   vtkGetVector3Macro(HandlePosition,double);
00160   
00162 
00165   void SetHandleDirection(double dir[3]);
00166   void SetHandleDirection(double dx, double dy, double dz)
00167     {double d[3]; d[0]=dx; d[1]=dy; d[2]=dz; this->SetHandleDirection(d);}
00168   vtkGetVector3Macro(HandleDirection,double);
00170 
00172 
00177   vtkSetMacro(HandleText,int);
00178   vtkGetMacro(HandleText,int);
00179   vtkBooleanMacro(HandleText,int);
00181 
00183 
00185   vtkSetMacro(RadialLine,int);
00186   vtkGetMacro(RadialLine,int);
00187   vtkBooleanMacro(RadialLine,int);
00189 
00196   void GetPolyData(vtkPolyData *pd);
00197 
00202   void GetSphere(vtkSphere *sphere);
00203 
00205 
00207   vtkGetObjectMacro(SphereProperty,vtkProperty);
00208   vtkGetObjectMacro(SelectedSphereProperty,vtkProperty);
00210   
00212 
00215   vtkGetObjectMacro(HandleProperty,vtkProperty);
00216   vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
00218   
00220 
00222   vtkGetObjectMacro(HandleTextProperty,vtkTextProperty);
00224   
00226 
00228   vtkGetObjectMacro(RadialLineProperty,vtkProperty);
00230   
00238   void SetInteractionState(int state);
00239 
00241 
00244   virtual void PlaceWidget(double bounds[6]);
00245   virtual void PlaceWidget(double center[3], double handlePosition[3]);
00246   virtual void BuildRepresentation();
00247   virtual int ComputeInteractionState(int X, int Y, int modify=0);
00248   virtual void StartWidgetInteraction(double e[2]);
00249   virtual void WidgetInteraction(double e[2]);
00250   virtual double *GetBounds();
00252   
00254 
00255   virtual void ReleaseGraphicsResources(vtkWindow*);
00256   virtual int RenderOpaqueGeometry(vtkViewport*);
00257   virtual int RenderTranslucentPolygonalGeometry(vtkViewport*);
00258   virtual int RenderOverlay(vtkViewport*);
00259   virtual int HasTranslucentPolygonalGeometry();
00261   
00262 protected:
00263   vtkSphereRepresentation();
00264   ~vtkSphereRepresentation();
00265 
00266   // Manage how the representation appears
00267   double LastEventPosition[3];
00268   
00269   // the sphere
00270   vtkActor            *SphereActor;
00271   vtkPolyDataMapper   *SphereMapper;
00272   vtkSphereSource     *SphereSource;
00273   void HighlightSphere(int highlight);
00274 
00275   // The representation of the sphere
00276   int Representation;
00277 
00278   // Do the picking
00279   vtkCellPicker *HandlePicker;
00280   vtkCellPicker *SpherePicker;
00281   double LastPickPosition[3];
00282   
00283   // Methods to manipulate the sphere widget
00284   void Translate(double *p1, double *p2);
00285   void Scale(double *p1, double *p2, int X, int Y);
00286   void PlaceHandle(double *center, double radius);
00287   virtual void SizeHandles();
00288   
00289   // Properties used to control the appearance of selected objects and
00290   // the manipulator in general.
00291   vtkProperty *SphereProperty;
00292   vtkProperty *SelectedSphereProperty;
00293   vtkProperty *HandleProperty;
00294   vtkProperty *SelectedHandleProperty;
00295   void CreateDefaultProperties();
00296 
00297   // Managing the handle
00298   vtkActor          *HandleActor;
00299   vtkPolyDataMapper *HandleMapper;
00300   vtkSphereSource   *HandleSource;
00301   void HighlightHandle(int);
00302   int HandleVisibility;
00303   double HandleDirection[3];
00304   double HandlePosition[3];
00305 
00306   // Manage the handle label
00307   int              HandleText;
00308   vtkTextProperty *HandleTextProperty;
00309   vtkTextMapper   *HandleTextMapper;
00310   vtkActor2D      *HandleTextActor;
00311 
00312   // Manage the radial line segment
00313   int RadialLine;
00314   vtkProperty       *RadialLineProperty;
00315   vtkLineSource     *RadialLineSource;
00316   vtkPolyDataMapper *RadialLineMapper;
00317   vtkActor          *RadialLineActor;
00318   
00319 private:
00320   vtkSphereRepresentation(const vtkSphereRepresentation&);  //Not implemented
00321   void operator=(const vtkSphereRepresentation&);  //Not implemented
00322 };
00323 
00324 #endif