QtGLViewer.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This program is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU General Public License as published by the Free  *
00007 * Software Foundation; either version 2 of the License, or (at your option)   *
00008 * any later version.                                                          *
00009 *                                                                             *
00010 * This program is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
00013 * more details.                                                               *
00014 *                                                                             *
00015 * You should have received a copy of the GNU General Public License along     *
00016 * with this program; if not, write to the Free Software Foundation, Inc., 51  *
00017 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.                   *
00018 *******************************************************************************
00019 *                            SOFA :: Applications                             *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_GUI_QGLVIEWER_QTVIEWER_H
00028 #define SOFA_GUI_QGLVIEWER_QTVIEWER_H
00029 
00030 #include <sofa/helper/system/gl.h>
00031 #include <qgl.h>
00032 #include <qtimer.h>
00033 #include <math.h>
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037 #include <fstream>
00038 
00039 #include <viewer/SofaViewer.h>
00040 #include <sofa/defaulttype/Vec.h>
00041 #include <sofa/defaulttype/Quat.h>
00042 #include <sofa/helper/gl/Transformation.h>
00043 #include <sofa/helper/gl/Trackball.h>
00044 #include <sofa/helper/gl/Texture.h>
00045 #include <sofa/helper/system/thread/CTime.h>
00046 #include <sofa/simulation/tree/xml/Element.h>
00047 
00048 
00049 
00050 #include <QGLViewer/qglviewer.h>
00051 
00052 namespace sofa
00053 {
00054 
00055   namespace gui
00056   {
00057 
00058     namespace qt
00059     {
00060       
00061       namespace viewer
00062       {
00063 
00064     namespace qgl
00065     {
00066       using namespace sofa::defaulttype;
00067       using namespace sofa::helper::gl;
00068       using namespace sofa::helper::system::thread;
00069       using namespace sofa::component::collision;
00070 
00071 
00072       class QtGLViewer :public QGLViewer,   public sofa::gui::qt::viewer::SofaViewer
00073         {
00074           typedef Vector3::value_type Real;
00075           Q_OBJECT
00076         private:
00077 
00078           QTimer* timerAnimate;
00079           int               _W, _H;
00080           int               _clearBuffer;
00081           bool          _lightModelTwoSides;
00082           float         _lightPosition[4];
00083     
00084 
00085           double lastProjectionMatrix[16];
00086           double lastModelviewMatrix[16];
00087           GLint lastViewport[4];
00088     
00089           
00090 
00091           //     float          _zoomSpeed;
00092           //     float          _panSpeed;
00093           //     Transformation _sceneTransform;
00094           //     Vector3            _previousEyePos;
00095           GLUquadricObj*    _arrow;
00096           GLUquadricObj*    _tube;
00097           GLUquadricObj*    _sphere;
00098           GLUquadricObj*    _disk;
00099           GLuint            _numOBJmodels;
00100           GLuint            _materialMode;
00101           GLboolean     _facetNormal;
00102           //     float          _zoom;
00103           int               _renderingMode;
00104           //GLuint          _logoTexture;
00105           Texture           *texLogo;
00106 
00107 
00108           ctime_t           _beginTime;
00109     
00110     
00111           bool _waitForRender;
00112 
00113           
00114           Vector3 sceneMinBBox;
00115           Vector3 sceneMaxBBox;
00116           
00117         public:
00118 
00122           static int EnableViewer();
00123 
00127           static int DisableViewer();
00128 
00129           QtGLViewer( QWidget* parent, const char* name="" );
00130           ~QtGLViewer();
00131 
00132           QWidget* getQWidget() { return this; }
00133 
00134         protected:
00135 
00136           //     void calcProjection();
00137           void init();
00138           virtual void draw();
00139           void viewAll();
00140           void resizeGL( int w, int h );
00141           void ApplyShadowMap();
00142           void CreateRenderTexture(GLuint& textureID, int sizeX, int sizeY, int channels, int type);
00143           void StoreLightMatrices();
00144 
00145         public:
00146 //        void setScene(sofa::simulation::tree::GNode* scene, const char* filename=NULL, bool keepParams=false);
00147 
00148 
00149           //void            reshape(int width, int height);
00150           int GetWidth()
00151           {
00152         return _W;
00153           };
00154           int GetHeight()
00155           {
00156         return _H;
00157           };
00158           bool ready(){return _waitForRender;};
00159           void wait(){_waitForRender = true;};
00160 
00161           void  UpdateOBJ(void);      
00162           
00163           void moveRayPickInteractor(int eventX, int eventY);
00164 
00165           //    static Quaternion _newQuat;
00166 
00167 
00168           QString helpString();
00169 
00170         private:
00171 
00172           void  InitGFX(void);
00173           void  PrintString(void* font, char* string);
00174           void  Display3DText(float x, float y, float z, char* string);
00175           void  DrawAxis(double xpos, double ypos, double zpos, double arrowSize);
00176           void  DrawBox(Real* minBBox, Real* maxBBox, Real r=0.0);
00177           void  DrawXYPlane(double zo, double xmin, double xmax, double ymin,
00178                     double ymax, double step);
00179           void  DrawYZPlane(double xo, double ymin, double ymax, double zmin,
00180                     double zmax, double step);
00181           void  DrawXZPlane(double yo, double xmin, double xmax, double zmin,
00182                     double zmax, double step);
00183           void  CreateOBJmodelDisplayList(int material_mode);
00184           //int     loadBMP(char *filename, TextureImage *texture);
00185           //void    LoadGLTexture(char *Filename);
00186           void  DrawLogo(void);
00187           void  DisplayOBJs(bool shadowPass = false);
00188           void  DisplayMenu(void);
00189           void  DrawScene();
00190 
00191 
00192           //int     handle(int event);  // required by FLTK
00193 
00194         protected:
00195           //virtual bool event ( QEvent * e );
00196           virtual void keyPressEvent ( QKeyEvent * e );
00197           virtual void keyReleaseEvent ( QKeyEvent * e );
00198           virtual void mousePressEvent ( QMouseEvent * e );
00199           virtual void mouseReleaseEvent ( QMouseEvent * e );
00200           virtual void mouseMoveEvent ( QMouseEvent * e );
00201           virtual void wheelEvent(QWheelEvent* e);
00202           bool mouseEvent( QMouseEvent * e );
00203 
00204 
00205 
00206     
00207           public slots:
00208           void resetView();
00209           void saveView();
00210           void setSizeW(int);
00211           void setSizeH(int);
00212             
00213         signals:
00214           void redrawn();
00215           void resizeW( int );
00216           void resizeH( int );
00217         };
00218 
00219     } // namespace qgl
00220 
00221       } // namespace viewer
00222 
00223     } //namespace qt
00224 
00225   } // namespace gui
00226 
00227 } // namespace sofa
00228 
00229 #endif
00230 
00231 

Generated on Sun Nov 23 02:28:37 2008 for Sofa by  doxygen 1.5.7.1