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

Rendering/vtkInteractorStyleUnicam.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkInteractorStyleUnicam.h,v $
00005   Language:  C++
00006 
00007 =========================================================================*/
00008 
00009 /*
00010  * This work (vtkInteractorStyleUnicam.h) was produced under a grant from
00011  * the Department of Energy to Brown University.  Neither Brown University
00012  * nor the authors assert any copyright with respect to this work and it may
00013  * be used, reproduced, and distributed without permission.  
00014  */
00015 
00075 #ifndef __vtkInteractorStyleUnicam_h
00076 #define __vtkInteractorStyleUnicam_h
00077 
00078 #include "vtkInteractorStyle.h"
00079 #include "vtkRenderer.h"
00080 class vtkWorldPointPicker;
00081 
00082 // define 'TheTime()' function-- returns time in elapsed seconds
00083 #if defined(_WIN32) || defined(WIN32)
00084 #include <winbase.h>
00085 
00086 inline double TheTime() 
00087   {return double(GetTickCount())/1000.0;}
00088 #else
00089 #include <sys/time.h>
00090 
00091 inline double TheTime() 
00092 {
00093   struct timeval ts; struct timezone tz;
00094   gettimeofday(&ts, &tz);
00095   return (double)(ts.tv_sec + ts.tv_usec/1e6);
00096 }
00097 #endif
00098 
00099 
00100 // 
00101 // XXX - would have preferred to make these enumerations within the class,
00102 //    enum { NONE=0, BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT };
00103 //    enum {CAM_INT_ROT, CAM_INT_CHOOSE, CAM_INT_PAN, CAM_INT_DOLLY};
00104 // but vtkWrapTcl signaled a "syntax error" when it parsed the 'enum' line.
00105 // So, am making them defines which is what the other classes that want
00106 // to have constants appear to do.
00107 // 
00108 // buttons pressed
00109 #define VTK_UNICAM_NONE           0
00110 #define VTK_UNICAM_BUTTON_LEFT    1
00111 #define VTK_UNICAM_BUTTON_MIDDLE  2
00112 #define VTK_UNICAM_BUTTON_RIGHT   3
00113 // 
00114 // camera modes
00115 #define VTK_UNICAM_CAM_INT_ROT    0
00116 #define VTK_UNICAM_CAM_INT_CHOOSE 1
00117 #define VTK_UNICAM_CAM_INT_PAN    2
00118 #define VTK_UNICAM_CAM_INT_DOLLY  3
00119 
00120 class VTK_RENDERING_EXPORT vtkInteractorStyleUnicam : public vtkInteractorStyle 
00121 {
00122 public:
00123   static vtkInteractorStyleUnicam *New();
00124   vtkTypeMacro(vtkInteractorStyleUnicam,vtkInteractorStyle);
00125   void PrintSelf(ostream& os, vtkIndent indent);
00126   
00128 
00129   virtual   void OnLeftButtonDown(int ctrl, int shift, int X, int Y);
00130   virtual   void OnLeftButtonUp  (int ctrl, int shift, int X, int Y);
00131   virtual   void OnMouseMove(int ctrl, int shift, int X, int Y);
00133   
00134   virtual   void OnLeftButtonMove  (int ctrl, int shift, int X, int Y);
00135   virtual   void OnMiddleButtonMove(int , int , int , int) {}
00136   virtual   void OnRightButtonMove (int , int , int , int) {}
00137 
00140   virtual void OnTimer(void);
00141 
00142   void SetWorldUpVector(double a[3]) {this->SetWorldUpVector(a[0],a[1],a[2]);}
00143   void SetWorldUpVector(float  a[3]) {this->SetWorldUpVector(a[0],a[1],a[2]);}
00144   void SetWorldUpVector(float x, float y, float z);
00145   vtkGetVectorMacro(WorldUpVector, float, 3);
00146 
00147 protected:
00148   vtkInteractorStyleUnicam();
00149   virtual ~vtkInteractorStyleUnicam();
00150 
00151   vtkWorldPointPicker *InteractionPicker;
00152   
00153   int      ButtonDown;   // which button is down
00154   double   DTime;        // time mouse button was pressed
00155   double   Dist;         // distance the mouse has moved since button press
00156   float    StartPix[2]; // pixel mouse movement started at
00157   float    LastPos[2];  // normalized position of mouse last frame
00158   float    LastPix[2];  // pixel position of mouse last frame
00159   float    DownPt[3];   // 3D point under cursor when mouse button pressed
00160   float    Center [3];   // center of camera rotation
00161 
00162   float    WorldUpVector[3]; // what the world thinks the 'up' vector is
00163 
00164   vtkActor    *FocusSphere; // geometry for indicating center of rotation
00165   int          IsDot;       // flag-- is the FocusSphere being displayed?
00166   vtkRenderer *FocusSphereRenderer;  // renderer for 'FocusSphere'
00167 
00168   int state;                 // which navigation mode was selected?
00169 
00170   void Choose( int X, int Y );  // method for choosing type of navigation
00171   void Rotate( int X, int Y );  // method for rotating
00172   void Dolly ( int X, int Y );  // method for dollying
00173   void Pan   ( int X, int Y );  // method for panning
00174 
00175   // conveinence methods for translating & rotating the camera
00176   void  MyTranslateCamera(float v[3]);
00177   void  MyRotateCamera(float cx, float cy, float cz,
00178                        float ax, float ay, float az,
00179                        float angle);
00180 
00181   // Given a 3D point & a vtkCamera, compute the vectors that extend
00182   // from the projection of the center of projection to the center of
00183   // the right-edge and the center of the top-edge onto the plane
00184   // containing the 3D point & with normal parallel to the camera's
00185   // projection plane.
00186   void  GetRightVandUpV(float *p, vtkCamera *cam,
00187                         float *rightV, float *upV);
00188 
00189   // takes in pixels, returns normalized window coordinates
00190   void  NormalizeMouseXY(int X, int Y, float *NX, float *NY);
00191 
00192   // return the aspect ratio of the current window
00193   float WindowAspect();
00194 private:
00195   vtkInteractorStyleUnicam(const vtkInteractorStyleUnicam&);  // Not implemented.
00196   void operator=(const vtkInteractorStyleUnicam&);  // Not implemented.
00197 };
00198 
00199 #endif  // __vtkInteractorStyleUnicam_h
00200 
00201 
00202 

Generated on Thu Mar 28 14:19:32 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001