A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
This class always contains internally an instance of opengl::COpenGLScene, which the objects, viewports, etc. to be rendered.
Images can be grabbed automatically to disk for easy creation of videos. See CDisplayWindow3D::grabImagesStart (and for creating videos, mrpt::utils::CVideoFileWriter).
Since the 3D rendering is performed in a detached thread, especial care must be taken when updating the 3D scene to be rendered. The process involves an internal critical section and it must always consist of these steps:
CDisplayWindow3D win("My window"); // Adquire the scene: opengl::COpenGLScenePtr &ptrScene = win.get3DSceneAndLock(); // Modify the scene: ptrScene->... // or replace by another scene: ptrScene = otherScene; // Unlock it, so the window can use it for redraw: win.unlockAccess3DScene(); // Update window, if required win.forceRepaint();
An alternative way of updating the scene is by creating, before locking the 3D window, a new object of class COpenGLScene, then locking the window only for replacing the smart pointer. This may be advantageous is generating the 3D scene takes a long time, since while the window is locked it will not be responsive to the user input or window redraw.
The window can also display a set of 2D text messages overlapped to the 3D scene. See CDisplayWindow3D::add2DTextMessage
For a list of supported events with the observer/observable pattern, see the discussion in mrpt::gui::CBaseGUIWindow.
Definition at line 85 of file CDisplayWindow3D.h.
#include <mrpt/gui/CDisplayWindow3D.h>
Public Member Functions | |
CDisplayWindow3D (const std::string &windowCaption=std::string(), unsigned int initialWindowWidth=400, unsigned int initialWindowHeight=300) | |
Constructor. | |
virtual | ~CDisplayWindow3D () |
Destructor. | |
opengl::COpenGLScenePtr & | get3DSceneAndLock () |
Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introduction in gui::CDisplayWindow3D before use!) This also locks the critical section for accesing the scene, thus the window will not be repainted until it is unlocked. | |
void | unlockAccess3DScene () |
Unlocks the access to the internal 3D scene. | |
void | forceRepaint () |
Repaints the window. | |
void | repaint () |
Repaints the window. | |
void | updateWindow () |
Repaints the window. | |
float | getFOV () const |
Return the camera field of view (in degrees) (used for gluPerspective). | |
void | setMinRange (float v) |
Changes the camera min range (z) (used for gluPerspective). | |
void | setMaxRange (float v) |
Changes the camera max range (z) (used for gluPerspective). | |
void | setFOV (float v) |
Changes the camera field of view (in degrees) (used for gluPerspective). | |
void | resize (unsigned int width, unsigned int height) |
Resizes the window, stretching the image to fit into the display area. | |
void | setPos (int x, int y) |
Changes the position of the window on the screen. | |
void | setWindowTitle (const std::string &str) |
Changes the window title. | |
void | setCameraElevationDeg (float deg) |
Changes the camera parameters programatically. | |
void | setCameraAzimuthDeg (float deg) |
Changes the camera parameters programatically. | |
void | setCameraPointingToPoint (float x, float y, float z) |
Changes the camera parameters programatically. | |
void | setCameraZoom (float zoom) |
Changes the camera parameters programatically. | |
void | setCameraProjective (bool isProjective) |
Sets the camera as projective, or orthogonal. | |
float | getCameraElevationDeg () const |
Get camera parameters programatically. | |
float | getCameraAzimuthDeg () const |
Get camera parameters programatically. | |
void | getCameraPointingToPoint (float &x, float &y, float &z) const |
Get camera parameters programatically. | |
float | getCameraZoom () const |
Get camera parameters programatically. | |
bool | isCameraProjective () const |
Sets the camera as projective, or orthogonal. | |
void | useCameraFromScene (bool useIt=true) |
If set to true (default = false), the mouse-based scene navigation will be disabled and the camera position will be determined by the opengl viewports in the 3D scene. | |
bool | getLastMousePositionRay (mrpt::math::TLine3D &ray) const |
Gets the 3D ray for the direction line of the pixel where the mouse cursor is at. | |
virtual bool | getLastMousePosition (int &x, int &y) const |
Gets the last x,y pixel coordinates of the mouse. | |
virtual void | setCursorCross (bool cursorIsCross) |
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) | |
void | grabImagesStart (const std::string &grab_imgs_prefix=std::string("video_")) |
Start to save rendered images to disk. | |
void | grabImagesStop () |
Stops image grabbing started by grabImagesStart. | |
void | captureImagesStart () |
Enables the grabbing of CImage objects from screenshots of the window. | |
void | captureImagesStop () |
Stop image grabbing. | |
void | getLastWindowImage (mrpt::utils::CImage &out_img) const |
Retrieve the last captured image from the window. | |
mrpt::utils::CImagePtr | getLastWindowImagePtr () const |
Retrieve the last captured image from the window, as a smart pointer. | |
std::string | grabImageGetNextFile () |
Increments by one the image counter and return the next image file name (Users normally don't want to call this method). | |
bool | isCapturingImgs () const |
void | addTextMessage (const double x, const double y, const std::string &text, const mrpt::utils::TColorf &color=mrpt::utils::TColorf(1.0, 1.0, 1.0), const size_t unique_index=0, const TOpenGLFont font=MRPT_GLUT_BITMAP_TIMES_ROMAN_24) |
Add 2D text messages overlapped to the 3D rendered scene. | |
void | clearTextMessages () |
Clear all text messages created with addTextMessage(). | |
void | setRenderingFPS (double FPS) |
Set the rendering FPS (users don't call this, the method is for internal MRPT objects only) | |
double | getRenderingFPS () const |
Get the average Frames Per Second (FPS) value from the last 250 rendering events. | |
Static Public Member Functions | |
static CDisplayWindow3DPtr | Create (const std::string &windowCaption=std::string(), unsigned int initialWindowWidth=400, unsigned int initialWindowHeight=300) |
Class factory returning a smart pointer. | |
Protected Member Functions | |
void | createOpenGLContext () |
Throws an exception on initialization error. | |
void | doRender () |
void | internalSetMinMaxRange () |
Protected Attributes | |
float | m_FOV |
opengl::COpenGLScenePtr | m_3Dscene |
Internal OpenGL object (see general discussion in about usage of this object) | |
synch::CCriticalSection | m_csAccess3DScene |
Critical section for accesing m_3Dscene. | |
void_ptr_noncopy | m_DisplayDeviceContext |
void_ptr_noncopy | m_GLRenderingContext |
std::string | m_grab_imgs_prefix |
unsigned int | m_grab_imgs_idx |
bool | m_is_capturing_imgs |
CImagePtr | m_last_captured_img |
synch::CCriticalSection | m_last_captured_img_cs |
mrpt::system::TTimeStamp | m_lastFullScreen |
double | m_last_FPS |
Friends | |
class | C3DWindowDialog |
class | CMyGLCanvas_DisplayWindow3D |
RTTI stuff | |
typedef CDisplayWindow3DPtr | SmartPtr |
static mrpt::utils::CLASSINIT | _init_CDisplayWindow3D |
static mrpt::utils::TRuntimeClassId | classCDisplayWindow3D |
static const mrpt::utils::TRuntimeClassId * | classinfo |
static const mrpt::utils::TRuntimeClassId * | _GetBaseClass () |
virtual const mrpt::utils::TRuntimeClassId * | GetRuntimeClass () const |
Returns information about the class of an object in runtime. | |
virtual mrpt::utils::CObject * | duplicate () const |
Returns a copy of the object, indepently of its class. | |
static mrpt::utils::CObject * | CreateObject () |
static CDisplayWindow3DPtr | Create () |
A typedef for the associated smart pointer
Definition at line 88 of file CDisplayWindow3D.h.
mrpt::gui::CDisplayWindow3D::CDisplayWindow3D | ( | const std::string & | windowCaption = std::string() , |
unsigned int | initialWindowWidth = 400 , |
||
unsigned int | initialWindowHeight = 300 |
||
) |
Constructor.
virtual mrpt::gui::CDisplayWindow3D::~CDisplayWindow3D | ( | ) | [virtual] |
Destructor.
static const mrpt::utils::TRuntimeClassId* mrpt::gui::CDisplayWindow3D::_GetBaseClass | ( | ) | [static, protected] |
Reimplemented from mrpt::gui::CBaseGUIWindow.
void mrpt::gui::CDisplayWindow3D::addTextMessage | ( | const double | x, |
const double | y, | ||
const std::string & | text, | ||
const mrpt::utils::TColorf & | color = mrpt::utils::TColorf(1.0, 1.0, 1.0) , |
||
const size_t | unique_index = 0 , |
||
const TOpenGLFont | font = MRPT_GLUT_BITMAP_TIMES_ROMAN_24 |
||
) |
Add 2D text messages overlapped to the 3D rendered scene.
The string will remain displayed in the 3D window until it's changed with subsequent calls to this same method, or all the texts are cleared with clearTextMessages().
x | The X position, interpreted as absolute pixels from the left if X>=1, absolute pixels from the left if X<0 or as a width factor if in the range [0,1[. |
y | The Y position, interpreted as absolute pixels from the bottom if Y>=1, absolute pixels from the top if Y<0 or as a height factor if in the range [0,1[. |
text | The text string to display. |
color | The text color. For example: TColorf(1.0,1.0,1.0) |
unique_index | An "index" for this text message, so that subsequent calls with the same index will overwrite this text message instead of creating new ones. |
You'll need to refresh the display manually with forceRepaint().
void mrpt::gui::CDisplayWindow3D::captureImagesStart | ( | ) |
Enables the grabbing of CImage objects from screenshots of the window.
void mrpt::gui::CDisplayWindow3D::captureImagesStop | ( | ) |
Stop image grabbing.
void mrpt::gui::CDisplayWindow3D::clearTextMessages | ( | ) |
Clear all text messages created with addTextMessage().
You'll need to refresh the display manually with forceRepaint().
static CDisplayWindow3DPtr mrpt::gui::CDisplayWindow3D::Create | ( | ) | [static] |
static CDisplayWindow3DPtr mrpt::gui::CDisplayWindow3D::Create | ( | const std::string & | windowCaption = std::string() , |
unsigned int | initialWindowWidth = 400 , |
||
unsigned int | initialWindowHeight = 300 |
||
) | [inline, static] |
Class factory returning a smart pointer.
Definition at line 137 of file CDisplayWindow3D.h.
static mrpt::utils::CObject* mrpt::gui::CDisplayWindow3D::CreateObject | ( | ) | [static] |
void mrpt::gui::CDisplayWindow3D::createOpenGLContext | ( | ) | [protected] |
Throws an exception on initialization error.
void mrpt::gui::CDisplayWindow3D::doRender | ( | ) | [protected] |
virtual mrpt::utils::CObject* mrpt::gui::CDisplayWindow3D::duplicate | ( | ) | const [virtual] |
Returns a copy of the object, indepently of its class.
Implements mrpt::utils::CObject.
void mrpt::gui::CDisplayWindow3D::forceRepaint | ( | ) |
Repaints the window.
forceRepaint, repaint and updateWindow are all aliases of the same method.
opengl::COpenGLScenePtr& mrpt::gui::CDisplayWindow3D::get3DSceneAndLock | ( | ) |
Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introduction in gui::CDisplayWindow3D before use!) This also locks the critical section for accesing the scene, thus the window will not be repainted until it is unlocked.
float mrpt::gui::CDisplayWindow3D::getCameraAzimuthDeg | ( | ) | const |
Get camera parameters programatically.
float mrpt::gui::CDisplayWindow3D::getCameraElevationDeg | ( | ) | const |
Get camera parameters programatically.
void mrpt::gui::CDisplayWindow3D::getCameraPointingToPoint | ( | float & | x, |
float & | y, | ||
float & | z | ||
) | const |
Get camera parameters programatically.
float mrpt::gui::CDisplayWindow3D::getCameraZoom | ( | ) | const |
Get camera parameters programatically.
float mrpt::gui::CDisplayWindow3D::getFOV | ( | ) | const [inline] |
Return the camera field of view (in degrees) (used for gluPerspective).
Definition at line 176 of file CDisplayWindow3D.h.
virtual bool mrpt::gui::CDisplayWindow3D::getLastMousePosition | ( | int & | x, |
int & | y | ||
) | const [virtual] |
Gets the last x,y pixel coordinates of the mouse.
Implements mrpt::gui::CBaseGUIWindow.
bool mrpt::gui::CDisplayWindow3D::getLastMousePositionRay | ( | mrpt::math::TLine3D & | ray ) | const |
Gets the 3D ray for the direction line of the pixel where the mouse cursor is at.
void mrpt::gui::CDisplayWindow3D::getLastWindowImage | ( | mrpt::utils::CImage & | out_img ) | const |
Retrieve the last captured image from the window.
You MUST CALL FIRST captureImagesStart to enable image grabbing.
mrpt::utils::CImagePtr mrpt::gui::CDisplayWindow3D::getLastWindowImagePtr | ( | ) | const |
Retrieve the last captured image from the window, as a smart pointer.
This method is more efficient than getLastWindowImage since only a copy of the pointer is performed, while getLastWindowImage would copy the entire image.
You MUST CALL FIRST captureImagesStart to enable image grabbing.
double mrpt::gui::CDisplayWindow3D::getRenderingFPS | ( | ) | const [inline] |
Get the average Frames Per Second (FPS) value from the last 250 rendering events.
Definition at line 335 of file CDisplayWindow3D.h.
virtual const mrpt::utils::TRuntimeClassId* mrpt::gui::CDisplayWindow3D::GetRuntimeClass | ( | ) | const [virtual] |
Returns information about the class of an object in runtime.
Reimplemented from mrpt::gui::CBaseGUIWindow.
std::string mrpt::gui::CDisplayWindow3D::grabImageGetNextFile | ( | ) |
Increments by one the image counter and return the next image file name (Users normally don't want to call this method).
void mrpt::gui::CDisplayWindow3D::grabImagesStart | ( | const std::string & | grab_imgs_prefix = std::string("video_") ) |
Start to save rendered images to disk.
Images will be saved independently as png files, depending on the template path passed to this method. For example:
path_prefix: "./video_"
Will generate "./video_000001.png", etc.
void mrpt::gui::CDisplayWindow3D::grabImagesStop | ( | ) |
Stops image grabbing started by grabImagesStart.
void mrpt::gui::CDisplayWindow3D::internalSetMinMaxRange | ( | ) | [protected] |
bool mrpt::gui::CDisplayWindow3D::isCameraProjective | ( | ) | const |
Sets the camera as projective, or orthogonal.
bool mrpt::gui::CDisplayWindow3D::isCapturingImgs | ( | ) | const [inline] |
Definition at line 300 of file CDisplayWindow3D.h.
void mrpt::gui::CDisplayWindow3D::repaint | ( | ) | [inline] |
Repaints the window.
forceRepaint, repaint and updateWindow are all aliases of the same method.
Definition at line 167 of file CDisplayWindow3D.h.
void mrpt::gui::CDisplayWindow3D::resize | ( | unsigned int | width, |
unsigned int | height | ||
) | [virtual] |
Resizes the window, stretching the image to fit into the display area.
Implements mrpt::gui::CBaseGUIWindow.
void mrpt::gui::CDisplayWindow3D::setCameraAzimuthDeg | ( | float | deg ) |
Changes the camera parameters programatically.
void mrpt::gui::CDisplayWindow3D::setCameraElevationDeg | ( | float | deg ) |
Changes the camera parameters programatically.
void mrpt::gui::CDisplayWindow3D::setCameraPointingToPoint | ( | float | x, |
float | y, | ||
float | z | ||
) |
Changes the camera parameters programatically.
void mrpt::gui::CDisplayWindow3D::setCameraProjective | ( | bool | isProjective ) |
Sets the camera as projective, or orthogonal.
void mrpt::gui::CDisplayWindow3D::setCameraZoom | ( | float | zoom ) |
Changes the camera parameters programatically.
virtual void mrpt::gui::CDisplayWindow3D::setCursorCross | ( | bool | cursorIsCross ) | [virtual] |
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true)
Implements mrpt::gui::CBaseGUIWindow.
void mrpt::gui::CDisplayWindow3D::setFOV | ( | float | v ) | [inline] |
Changes the camera field of view (in degrees) (used for gluPerspective).
The window is not updated with this method, call "forceRepaint" to update the 3D view.
Definition at line 191 of file CDisplayWindow3D.h.
void mrpt::gui::CDisplayWindow3D::setMaxRange | ( | float | v ) |
Changes the camera max range (z) (used for gluPerspective).
The window is not updated with this method, call "forceRepaint" to update the 3D view.
void mrpt::gui::CDisplayWindow3D::setMinRange | ( | float | v ) |
Changes the camera min range (z) (used for gluPerspective).
The window is not updated with this method, call "forceRepaint" to update the 3D view.
void mrpt::gui::CDisplayWindow3D::setPos | ( | int | x, |
int | y | ||
) | [virtual] |
Changes the position of the window on the screen.
Implements mrpt::gui::CBaseGUIWindow.
void mrpt::gui::CDisplayWindow3D::setRenderingFPS | ( | double | FPS ) |
Set the rendering FPS (users don't call this, the method is for internal MRPT objects only)
void mrpt::gui::CDisplayWindow3D::setWindowTitle | ( | const std::string & | str ) | [virtual] |
Changes the window title.
Implements mrpt::gui::CBaseGUIWindow.
void mrpt::gui::CDisplayWindow3D::unlockAccess3DScene | ( | ) |
Unlocks the access to the internal 3D scene.
Typically user will want to call forceRepaint after updating the scene.
void mrpt::gui::CDisplayWindow3D::updateWindow | ( | ) | [inline] |
Repaints the window.
forceRepaint, repaint and updateWindow are all aliases of the same method.
Definition at line 172 of file CDisplayWindow3D.h.
void mrpt::gui::CDisplayWindow3D::useCameraFromScene | ( | bool | useIt = true ) |
If set to true (default = false), the mouse-based scene navigation will be disabled and the camera position will be determined by the opengl viewports in the 3D scene.
friend class C3DWindowDialog [friend] |
Reimplemented from mrpt::gui::CBaseGUIWindow.
Definition at line 91 of file CDisplayWindow3D.h.
friend class CMyGLCanvas_DisplayWindow3D [friend] |
Definition at line 92 of file CDisplayWindow3D.h.
mrpt::utils::CLASSINIT mrpt::gui::CDisplayWindow3D::_init_CDisplayWindow3D [static, protected] |
Definition at line 88 of file CDisplayWindow3D.h.
Definition at line 88 of file CDisplayWindow3D.h.
const mrpt::utils::TRuntimeClassId* mrpt::gui::CDisplayWindow3D::classinfo [static] |
Definition at line 88 of file CDisplayWindow3D.h.
Internal OpenGL object (see general discussion in about usage of this object)
Definition at line 100 of file CDisplayWindow3D.h.
Critical section for accesing m_3Dscene.
Definition at line 104 of file CDisplayWindow3D.h.
Definition at line 110 of file CDisplayWindow3D.h.
float mrpt::gui::CDisplayWindow3D::m_FOV [protected] |
Definition at line 95 of file CDisplayWindow3D.h.
Definition at line 111 of file CDisplayWindow3D.h.
unsigned int mrpt::gui::CDisplayWindow3D::m_grab_imgs_idx [protected] |
Definition at line 114 of file CDisplayWindow3D.h.
std::string mrpt::gui::CDisplayWindow3D::m_grab_imgs_prefix [protected] |
Definition at line 113 of file CDisplayWindow3D.h.
bool mrpt::gui::CDisplayWindow3D::m_is_capturing_imgs [protected] |
Definition at line 116 of file CDisplayWindow3D.h.
Definition at line 117 of file CDisplayWindow3D.h.
Definition at line 118 of file CDisplayWindow3D.h.
double mrpt::gui::CDisplayWindow3D::m_last_FPS [protected] |
Definition at line 124 of file CDisplayWindow3D.h.
Definition at line 122 of file CDisplayWindow3D.h.
Page generated by Doxygen 1.7.2 for MRPT 0.9.4 SVN: at Mon Jan 10 22:46:17 UTC 2011 |