00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CDisplayWindow3D_H 00029 #define CDisplayWindow3D_H 00030 00031 #include <mrpt/gui/CBaseGUIWindow.h> 00032 #include <mrpt/opengl.h> 00033 #include <mrpt/utils/CImage.h> 00034 00035 /*--------------------------------------------------------------- 00036 Class 00037 ---------------------------------------------------------------*/ 00038 namespace mrpt 00039 { 00040 namespace utils 00041 { 00042 class CImage; 00043 class CImageFloat; 00044 } 00045 00046 namespace gui 00047 { 00048 using namespace mrpt::utils; 00049 00050 class C3DWindowDialog; 00051 class CMyGLCanvas_DisplayWindow3D; 00052 00053 DEFINE_SERIALIZABLE_PRE(CDisplayWindow3D) 00054 00055 /** A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time. 00056 * This class always contains internally an instance of opengl::COpenGLScene, which 00057 * the objects, viewports, etc. to be rendered. 00058 * 00059 * Since MRPT 0.6.2, images can be grabbed automatically to disk for easy creation of videos. 00060 * See CDisplayWindow3D::grabImagesStart 00061 * 00062 * 00063 * Since the 3D rendering is performed in a detached thread, especial care must be taken 00064 * when updating the 3D scene to be rendered. The process involves an internal critical section 00065 * and it must always consist of these steps: 00066 * 00067 \code 00068 CDisplayWindow3D win("My window"); 00069 00070 // Adquire the scene: 00071 opengl::COpenGLScenePtr &ptrScene = win.get3DSceneAndLock(); 00072 00073 // Modify the scene: 00074 ptrScene->... 00075 // or replace by another scene: 00076 ptrScene = otherScene; 00077 00078 // Unlock it, so the window can use it for redraw: 00079 win.unlockAccess3DScene(); 00080 00081 // Update window, if required 00082 win.forceRepaint(); 00083 \endcode 00084 * 00085 * An alternative way of updating the scene is by creating, before locking the 3D window, a new object 00086 * of class COpenGLScene, then locking the window only for replacing the smart pointer. This may be 00087 * advantageous is generating the 3D scene takes a long time, since while the window 00088 * is locked it will not be responsive to the user input or window redraw. 00089 * 00090 * \sa The example /samples/display3D, the <a href="http://babel.isa.uma.es/mrpt/index.php/Tutorial_3D_Scenes">tutorial on the wiki</a>. 00091 */ 00092 class MRPTDLLIMPEXP CDisplayWindow3D : public mrpt::utils::CSerializable, public mrpt::gui::CBaseGUIWindow 00093 { 00094 // This must be added to any CSerializable derived class: 00095 DEFINE_SERIALIZABLE( CDisplayWindow3D ) 00096 00097 friend class C3DWindowDialog; 00098 friend class CMyGLCanvas_DisplayWindow3D; 00099 00100 00101 float m_minRange,m_maxRange,m_FOV; 00102 00103 00104 /** Internal OpenGL object (see general discussion in about usage of this object) 00105 */ 00106 opengl::COpenGLScenePtr m_3Dscene; 00107 00108 /** Critical section for accesing m_3Dscene 00109 */ 00110 synch::CCriticalSection m_csAccess3DScene; 00111 00112 /** Throws an exception on initialization error 00113 */ 00114 void createOpenGLContext(); 00115 00116 void_ptr_noncopy m_DisplayDeviceContext; 00117 void_ptr_noncopy m_GLRenderingContext; 00118 00119 std::string m_grab_imgs_prefix; 00120 unsigned int m_grab_imgs_idx; 00121 00122 bool m_is_capturing_imgs; 00123 CImagePtr m_last_captured_img; 00124 synch::CCriticalSection m_last_captured_img_cs; 00125 00126 void doRender(); 00127 00128 public: 00129 /** Constructor 00130 */ 00131 CDisplayWindow3D( 00132 const std::string &windowCaption = std::string(), 00133 unsigned int initialWindowWidth = 400, 00134 unsigned int initialWindowHeight = 300 ); 00135 00136 /** Destructor 00137 */ 00138 virtual ~CDisplayWindow3D(); 00139 00140 /** Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introduction in gui::CDisplayWindow3D before use!) 00141 * This also locks the critical section for accesing the scene, thus the window will not be repainted until it is unlocked. 00142 */ 00143 opengl::COpenGLScenePtr & get3DSceneAndLock( ); 00144 00145 /** Unlocks the access to the internal 3D scene. 00146 * Typically user will want to call forceRepaint after updating the scene. 00147 */ 00148 void unlockAccess3DScene(); 00149 00150 /** Repaints the window. 00151 * forceRepaint, repaint and updateWindow are all aliases of the same method. 00152 */ 00153 void forceRepaint(); 00154 00155 /** Repaints the window. 00156 * forceRepaint, repaint and updateWindow are all aliases of the same method. 00157 */ 00158 void repaint() { forceRepaint(); } 00159 00160 /** Repaints the window. 00161 * forceRepaint, repaint and updateWindow are all aliases of the same method. 00162 */ 00163 void updateWindow() { forceRepaint(); } 00164 00165 /** Return the camera min range (z) (used for gluPerspective). 00166 */ 00167 float getMinRange() const { return m_minRange; }; 00168 00169 /** Return the camera max range (z) (used for gluPerspective). 00170 */ 00171 float getMaxRange() const { return m_maxRange; }; 00172 00173 /** Return the camera field of view (in degrees) (used for gluPerspective). 00174 */ 00175 float getFOV() const { return m_FOV; }; 00176 00177 /** Changes the camera min range (z) (used for gluPerspective). 00178 * The window is not updated with this method, call "forceRepaint" to update the 3D view. 00179 */ 00180 void setMinRange(float v) { m_minRange=v; }; 00181 00182 /** Changes the camera max range (z) (used for gluPerspective). 00183 * The window is not updated with this method, call "forceRepaint" to update the 3D view. 00184 */ 00185 void setMaxRange(float v) { m_maxRange=v; }; 00186 00187 /** Changes the camera field of view (in degrees) (used for gluPerspective). 00188 * The window is not updated with this method, call "forceRepaint" to update the 3D view. 00189 */ 00190 void setFOV(float v) { m_FOV=v; }; 00191 00192 /** Resizes the window, stretching the image to fit into the display area. 00193 */ 00194 void resize( unsigned int width, unsigned int height ); 00195 00196 /** Changes the position of the window on the screen. 00197 */ 00198 void setPos( int x, int y ); 00199 00200 /** Changes the window title. 00201 */ 00202 void setWindowTitle( const std::string &str ); 00203 00204 /** Changes the camera parameters programatically 00205 */ 00206 void setCameraElevationDeg( float deg ); 00207 00208 /** Changes the camera parameters programatically 00209 */ 00210 void setCameraAzimuthDeg( float deg ); 00211 00212 /** Changes the camera parameters programatically 00213 */ 00214 void setCameraPointingToPoint( float x,float y, float z ); 00215 00216 /** Changes the camera parameters programatically 00217 */ 00218 void setCameraZoom( float zoom ); 00219 00220 /** Sets the camera as projective, or orthogonal. */ 00221 void setCameraProjective( bool isProjective ); 00222 00223 00224 /** Get camera parameters programatically */ 00225 float getCameraElevationDeg() const; 00226 00227 /** Get camera parameters programatically */ 00228 float getCameraAzimuthDeg() const; 00229 00230 /** Get camera parameters programatically */ 00231 void getCameraPointingToPoint( float &x,float &y, float &z ) const; 00232 00233 /** Get camera parameters programatically */ 00234 float getCameraZoom() const; 00235 00236 /** Sets the camera as projective, or orthogonal. */ 00237 bool isCameraProjective() const; 00238 00239 00240 /** Start to save rendered images to disk. 00241 * Images will be saved independently as png files, depending on 00242 * the template path passed to this method. For example: 00243 * 00244 * path_prefix: "./video_" 00245 * 00246 * Will generate "./video_000001.png", etc. 00247 * 00248 * \sa grabImagesStop 00249 */ 00250 void grabImagesStart( const std::string &grab_imgs_prefix = std::string("video_") ); 00251 00252 /** Stops image grabbing started by grabImagesStart 00253 * \sa grabImagesStart 00254 */ 00255 void grabImagesStop(); 00256 00257 /** Enables the grabbing of CImage objects from screenshots of the window. 00258 * \sa getLastWindowImage 00259 */ 00260 void captureImagesStart(); 00261 00262 /** Stop image grabbing 00263 * \sa captureImagesStart 00264 */ 00265 void captureImagesStop(); 00266 00267 /** Retrieve the last captured image from the window. 00268 * You MUST CALL FIRST captureImagesStart to enable image grabbing. 00269 * \sa captureImagesStart, getLastWindowImagePtr 00270 */ 00271 void getLastWindowImage( mrpt::utils::CImage &out_img) const; 00272 00273 /** Retrieve the last captured image from the window, as a smart pointer. 00274 * This method is more efficient than getLastWindowImage since only a copy of the pointer is performed, while 00275 * getLastWindowImage would copy the entire image. 00276 * 00277 * You MUST CALL FIRST captureImagesStart to enable image grabbing. 00278 * \sa captureImagesStart, getLastWindowImage 00279 */ 00280 mrpt::utils::CImagePtr getLastWindowImagePtr() const; 00281 00282 /** Increments by one the image counter and return the next image file name (Users normally don't want to call this method). 00283 * \sa grabImagesStart 00284 */ 00285 std::string grabImageGetNextFile(); 00286 00287 bool isCapturingImgs() const { return m_is_capturing_imgs; } 00288 00289 }; // End of class def. 00290 } // End of namespace 00291 } // End of namespace 00292 00293 #endif
Page generated by Doxygen 1.5.7.1 for MRPT 0.7.1 SVN: at Mon Aug 17 23:02:22 EDT 2009 |