VTK
dox/Interaction/Style/vtkInteractorStyleUnicam.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkInteractorStyleUnicam.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 =========================================================================*/
00015 
00016 /*
00017  * This work (vtkInteractorStyleUnicam.h) was produced under a grant from
00018  * the Department of Energy to Brown University.  Neither Brown University
00019  * nor the authors assert any copyright with respect to this work and it may
00020  * be used, reproduced, and distributed without permission.
00021  */
00022 
00079 #ifndef __vtkInteractorStyleUnicam_h
00080 #define __vtkInteractorStyleUnicam_h
00081 
00082 #include "vtkInteractionStyleModule.h" // For export macro
00083 #include "vtkInteractorStyle.h"
00084 
00085 class vtkCamera;
00086 class vtkWorldPointPicker;
00087 
00088 //
00089 // XXX - would have preferred to make these enumerations within the class,
00090 //    enum { NONE=0, BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT };
00091 //    enum {CAM_INT_ROT, CAM_INT_CHOOSE, CAM_INT_PAN, CAM_INT_DOLLY};
00092 // but vtkWrapTcl signaled a "syntax error" when it parsed the 'enum' line.
00093 // So, am making them defines which is what the other classes that want
00094 // to have constants appear to do.
00095 //
00096 // buttons pressed
00097 #define VTK_UNICAM_NONE           0
00098 #define VTK_UNICAM_BUTTON_LEFT    1
00099 #define VTK_UNICAM_BUTTON_MIDDLE  2
00100 #define VTK_UNICAM_BUTTON_RIGHT   3
00101 //
00102 // camera modes
00103 #define VTK_UNICAM_CAM_INT_ROT    0
00104 #define VTK_UNICAM_CAM_INT_CHOOSE 1
00105 #define VTK_UNICAM_CAM_INT_PAN    2
00106 #define VTK_UNICAM_CAM_INT_DOLLY  3
00107 
00108 class VTKINTERACTIONSTYLE_EXPORT vtkInteractorStyleUnicam : public vtkInteractorStyle
00109 {
00110 public:
00111   static vtkInteractorStyleUnicam *New();
00112   vtkTypeMacro(vtkInteractorStyleUnicam,vtkInteractorStyle);
00113   void PrintSelf(ostream& os, vtkIndent indent);
00114 
00115   void SetWorldUpVector(double a[3]) {this->SetWorldUpVector(a[0],a[1],a[2]);}
00116   void SetWorldUpVector(double x, double y, double z);
00117   vtkGetVectorMacro(WorldUpVector, double, 3);
00118 
00120 
00121   virtual void OnMouseMove();
00122   virtual void OnLeftButtonDown();
00123   virtual void OnLeftButtonUp();
00124   virtual void OnLeftButtonMove();
00126 
00129   virtual void OnTimer();
00130 
00131 protected:
00132   vtkInteractorStyleUnicam();
00133   virtual ~vtkInteractorStyleUnicam();
00134 
00135   vtkWorldPointPicker *InteractionPicker;
00136 
00137   int      ButtonDown;   // which button is down
00138   double   DTime;        // time mouse button was pressed
00139   double   Dist;         // distance the mouse has moved since button press
00140   double    StartPix[2]; // pixel mouse movement started at
00141   double    LastPos[2];  // normalized position of mouse last frame
00142   double    LastPix[2];  // pixel position of mouse last frame
00143   double    DownPt[3];   // 3D point under cursor when mouse button pressed
00144   double    Center [3];   // center of camera rotation
00145 
00146   double    WorldUpVector[3]; // what the world thinks the 'up' vector is
00147 
00148   vtkActor    *FocusSphere; // geometry for indicating center of rotation
00149   int          IsDot;       // flag-- is the FocusSphere being displayed?
00150   vtkRenderer *FocusSphereRenderer;  // renderer for 'FocusSphere'
00151 
00152   int state;                 // which navigation mode was selected?
00153 
00154   void ChooseXY( int X, int Y );  // method for choosing type of navigation
00155   void RotateXY( int X, int Y );  // method for rotating
00156   void DollyXY( int X, int Y );  // method for dollying
00157   void PanXY( int X, int Y );  // method for panning
00158 
00159   // conveinence methods for translating & rotating the camera
00160   void  MyTranslateCamera(double v[3]);
00161   void  MyRotateCamera(double cx, double cy, double cz,
00162                        double ax, double ay, double az,
00163                        double angle);
00164 
00165   // Given a 3D point & a vtkCamera, compute the vectors that extend
00166   // from the projection of the center of projection to the center of
00167   // the right-edge and the center of the top-edge onto the plane
00168   // containing the 3D point & with normal parallel to the camera's
00169   // projection plane.
00170   void  GetRightVandUpV(double *p, vtkCamera *cam,
00171                         double *rightV, double *upV);
00172 
00173   // takes in pixels, returns normalized window coordinates
00174   void  NormalizeMouseXY(int X, int Y, double *NX, double *NY);
00175 
00176   // return the aspect ratio of the current window
00177   double WindowAspect();
00178 private:
00179   vtkInteractorStyleUnicam(const vtkInteractorStyleUnicam&);  // Not implemented.
00180   void operator=(const vtkInteractorStyleUnicam&);  // Not implemented.
00181 };
00182 
00183 #endif  // __vtkInteractorStyleUnicam_h
00184 
00185 
00186