QtOgreViewer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __sofaOgreWidget_H__
00028 #define __sofaOgreWidget_H__
00029
00030 #include <stdlib.h>
00031
00032 #include <viewer/qtogre/DotSceneLoader.h>
00033
00034 #include <viewer/SofaViewer.h>
00035 #include <sofa/helper/gl/Capture.h>
00036 #include <sofa/helper/system/FileRepository.h>
00037 #include <sofa/helper/system/SetDirectory.h>
00038 #include <sofa/core/ObjectFactory.h>
00039 #include <sofa/simulation/tree/Simulation.h>
00040
00041
00042 #ifdef SOFA_QT4
00043 #include <QPaintEvent>
00044 #include <QWidget>
00045 #else
00046 #include <qlayout.h>
00047 #endif
00048
00049 #include <Ogre.h>
00050
00051
00052
00053 using namespace sofa::helper::system::thread;
00054 using namespace sofa::simulation::tree;
00055
00056 #if defined(SOFA_GPU_CUDA)
00057 #include <sofa/gpu/cuda/mycuda.h>
00058 using namespace sofa::gpu::cuda;
00059 #endif
00060
00061
00062 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
00063 std::string macBundlePath();
00064 #endif
00065
00066
00067
00068
00069
00070
00071 namespace sofa
00072 {
00073
00074 namespace gui
00075 {
00076
00077 namespace qt
00078 {
00079
00080 namespace viewer
00081 {
00082
00083 namespace qtogre
00084 {
00085
00086 class QtOgreViewer : public QWidget, public sofa::gui::qt::viewer::SofaViewer
00087 {
00088 Q_OBJECT
00089 public:
00090
00091 std::string sceneName;
00092
00093
00097 static int EnableViewer();
00098
00102 static int DisableViewer();
00103
00104 QtOgreViewer( QWidget *parent=0, const char *name=0 );
00105 ~QtOgreViewer()
00106 {
00107
00108 if(mRoot != NULL){
00109 delete mRoot;
00110 mRoot = NULL;
00111 }
00112 };
00113
00114 QWidget* getQWidget() { return this; }
00115
00116 bool ready(){return _waitForRender;};
00117 void wait(){_waitForRender = true;};
00118
00119 void showEntireScene(void);
00120
00121
00122 void setScene(sofa::simulation::tree::GNode* scene, const char* filename, bool keepParams=false);
00123
00124 void setup(void);
00125 void setupView(void);
00126 QString helpString();
00127
00128 void moveRayPickInteractor(int eventX, int eventY);
00129
00130 private:
00131
00132 Ogre::String mResourcePath;
00133
00134
00135 Ogre::RenderWindow* mRenderWindow;
00136 Ogre::SceneManager* mSceneMgr;
00137
00138 Ogre::Camera* mCamera;
00139 Ogre::Viewport* mVp;
00140 Ogre::Root* mRoot;
00141 Ogre::ShadowTechnique shadow;
00143 bool _mouseInteractorMoving;
00144 int _mouseInteractorSavedPosX;
00145 int _mouseInteractorSavedPosY;
00146 unsigned int number_visualModels;
00147
00148
00149 void setupResources(void);
00150
00151 void setupConfiguration(void);
00152
00153
00154 void loadResources(void)
00155 {
00156
00157 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
00158 }
00159
00160 void createScene(void);
00161
00162
00163 virtual bool configure(void)
00164 {
00165
00166
00167
00168 std::cerr<<"Show Dialog " << mRoot<<"\n";
00169 if(mRoot->showConfigDialog())
00170 {
00171
00172
00173
00174 Ogre::ConfigOptionMap& optMap = mRoot->getRenderSystem()->getConfigOptions();
00175 Ogre::ConfigOptionMap::iterator i = optMap.find("Floating-point mode");
00176 if (i != optMap.end())
00177 {
00178 if (i->second.currentValue != "Consistent")
00179 {
00180 i->second.currentValue = "Consistent";
00181 Ogre::LogManager::getSingleton().logMessage("ExampleApplication: overriding "
00182 "D3D floating point mode to 'Consistent' to ensure precision "
00183 "for numerical computations");
00184 }
00185 }
00186
00187
00188 mRoot->initialise(false, "SOFA - OGRE");
00189 return true;
00190 }
00191 else
00192 {
00193 return false;
00194 }
00195 }
00196
00197 void update();
00198
00199 protected:
00200
00201 ctime_t _beginTime;
00202
00203 bool m_mouseLeftPressed;
00204 bool m_mouseRightPressed;
00205 bool m_mouseMiddlePressed;
00206 QPoint m_mousePressPos;
00207 QPoint m_mousePos;
00208 bool m_background;
00209 bool pickDone;
00210
00211 Ogre::Vector3 m_mTranslateVector;
00212 Ogre::Radian m_mRotX, m_mRotY;
00213 Ogre::Real m_mMoveSpeed;
00214 Ogre::Degree m_mRotateSpeed;
00215 Ogre::SceneNode* zeroNode;
00216 Ogre::SceneNode* camNode;
00217 bool _waitForRender;
00218
00219
00220 Ogre::AxisAlignedBox world_BB;
00221
00222 void resize()
00223 {
00224 if (mRenderWindow != NULL)
00225 {
00226 emit(resizeW(width()));
00227 emit(resizeH(height()));
00228 mRenderWindow->windowMovedOrResized();
00229 mRenderWindow->resize(width(), height());
00230 mVp->setDimensions(0,0, 1.0, 1.0);
00231 mCamera->setAspectRatio(Ogre::Real(mVp->getActualWidth()) / Ogre::Real(mVp->getActualHeight()));
00232 update();
00233 }
00234 }
00235
00236 bool updateInteractor( QMouseEvent * e );
00237
00238 virtual void paintEvent(QPaintEvent*);
00239 virtual void resizeEvent(QResizeEvent*);
00240 virtual void timerEvent(QTimerEvent * event){Q_UNUSED(event);update();}
00241
00242 virtual void keyPressEvent ( QKeyEvent * e );
00243 virtual void mousePressEvent(QMouseEvent* evt);
00244 virtual void mouseReleaseEvent(QMouseEvent* evt);
00245 virtual void mouseMoveEvent(QMouseEvent* evt);
00246 virtual void wheelEvent(QWheelEvent* evt);
00247
00248 void moveCamera(void)
00249 {
00250
00251 mCamera->yaw(m_mRotX);
00252 mCamera->pitch(m_mRotY);
00253
00254
00255 m_mRotX = m_mRotY = Ogre::Degree(0);
00256 m_mTranslateVector = Ogre::Vector3::ZERO;
00257 }
00258
00259
00260 public slots:
00261 virtual void resetView();
00262 virtual void saveView();
00263 virtual void setSizeW(int);
00264 virtual void setSizeH(int);
00265
00266 signals:
00267 void redrawn();
00268 void resizeW( int );
00269 void resizeH( int );
00270
00271
00272 };
00273 }
00274 }
00275 }
00276 }
00277 }
00278
00279
00280 #endif
00281