Main MRPT website > C++ reference
MRPT logo
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends

mrpt::gui::CDisplayWindow3D Class Reference


Detailed Description

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.

See also:
The example /samples/display3D, the tutorial only.

Definition at line 95 of file CDisplayWindow3D.h.

#include <mrpt/gui/CDisplayWindow3D.h>

Inheritance diagram for mrpt::gui::CDisplayWindow3D:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CDisplayWindow3D (const std::string &windowCaption=std::string(), unsigned int initialWindowWidth=400, unsigned int initialWindowHeight=300)
 Constructor.
virtual ~CDisplayWindow3D ()
 Destructor.
opengl::COpenGLScenePtrget3DSceneAndLock ()
 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::CObjectduplicate () const
 Returns a copy of the object, indepently of its class.
static mrpt::utils::CObjectCreateObject ()
static CDisplayWindow3DPtr Create ()

Member Typedef Documentation

A typedef for the associated smart pointer

Definition at line 98 of file CDisplayWindow3D.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

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().

Parameters:
xThe 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[.
yThe 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[.
textThe text string to display.
colorThe text color. For example: TColorf(1.0,1.0,1.0)
unique_indexAn "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().

See also:
clearTextMessages
void mrpt::gui::CDisplayWindow3D::captureImagesStart ( )

Enables the grabbing of CImage objects from screenshots of the window.

See also:
getLastWindowImage
void mrpt::gui::CDisplayWindow3D::captureImagesStop ( )

Stop image grabbing.

See also:
captureImagesStart
void mrpt::gui::CDisplayWindow3D::clearTextMessages ( )

Clear all text messages created with addTextMessage().

You'll need to refresh the display manually with forceRepaint().

See also:
addTextMessage
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 147 of file CDisplayWindow3D.h.

References mrpt::gui::CDisplayWindow3D.

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 186 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.

Returns:
False if the window is closed.
See also:
getLastMousePositionRay

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.

Returns:
False if the window is closed.
See also:
getLastMousePosition
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.

See also:
captureImagesStart, getLastWindowImagePtr
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.

See also:
captureImagesStart, getLastWindowImage
double mrpt::gui::CDisplayWindow3D::getRenderingFPS ( ) const [inline]

Get the average Frames Per Second (FPS) value from the last 250 rendering events.

Definition at line 345 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).

See also:
grabImagesStart
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.

See also:
grabImagesStop
void mrpt::gui::CDisplayWindow3D::grabImagesStop ( )

Stops image grabbing started by grabImagesStart.

See also:
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 310 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 177 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)

See also:
getLastMousePositionRay

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 201 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)

See also:
getRenderingFPS
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 182 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.


Friends And Related Function Documentation

friend class C3DWindowDialog [friend]

Reimplemented from mrpt::gui::CBaseGUIWindow.

Definition at line 101 of file CDisplayWindow3D.h.

friend class CMyGLCanvas_DisplayWindow3D [friend]

Definition at line 102 of file CDisplayWindow3D.h.


Member Data Documentation

Definition at line 98 of file CDisplayWindow3D.h.

Definition at line 98 of file CDisplayWindow3D.h.

Definition at line 98 of file CDisplayWindow3D.h.

Internal OpenGL object (see general discussion in about usage of this object)

Definition at line 110 of file CDisplayWindow3D.h.

Critical section for accesing m_3Dscene.

Definition at line 114 of file CDisplayWindow3D.h.

Definition at line 120 of file CDisplayWindow3D.h.

Definition at line 105 of file CDisplayWindow3D.h.

Definition at line 121 of file CDisplayWindow3D.h.

Definition at line 124 of file CDisplayWindow3D.h.

Definition at line 123 of file CDisplayWindow3D.h.

Definition at line 126 of file CDisplayWindow3D.h.

Definition at line 127 of file CDisplayWindow3D.h.

Definition at line 128 of file CDisplayWindow3D.h.

See also:
getRenderingFPS

Definition at line 134 of file CDisplayWindow3D.h.

Definition at line 132 of file CDisplayWindow3D.h.




Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011