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