Main MRPT website > C++ reference for MRPT 1.3.2
List of all members | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Static Protected Member Functions | Protected Attributes
mrpt::opengl::COpenGLScene Class Reference

Detailed Description

This class allows the user to create, load, save, and render 3D scenes using OpenGL primitives.

The class can be understood as a program to be run over OpenGL, containing a sequence of viewport definitions, rendering primitives, etc...

It can contain from 1 up to any number of Viewports, each one associated a set of OpenGL objects and, optionally, a preferred camera position. Both orthogonal (2D/3D) and projection camera models can be used for each viewport independently, greatly increasing the possibilities of rendered scenes.

An object of COpenGLScene always contains at least one viewport (utils::COpenGLViewport), named "main". Optionally, any number of other viewports may exist. Viewports are referenced by their names, case-sensitive strings. Each viewport contains a different 3D scene (i.e. they render different objects), though a mechanism exist to share the same 3D scene by a number of viewports so memory is not wasted replicating the same objects (see COpenGLViewport::setCloneView ).

The main rendering method, COpenGLScene::render(), assumes a viewport has been set-up for the entire target window. That method will internally make the required calls to opengl for creating the additional viewports. Note that only the depth buffer is cleared by default for each (non-main) viewport, to allow transparencies. This can be disabled by the approppriate member in COpenGLViewport.

An object COpenGLScene can be saved to a ".3Dscene" file using CFileOutputStream, for posterior visualization from the standalone application SceneViewer. It can be also displayed in real-time using gui::CDisplayWindow3D.

Definition at line 49 of file COpenGLScene.h.

#include <mrpt/opengl/COpenGLScene.h>

Inheritance diagram for mrpt::opengl::COpenGLScene:
Inheritance graph

Public Member Functions

void * operator new (size_t size)
 
void * operator new[] (size_t size)
 
void operator delete (void *ptr) throw ()
 
void operator delete[] (void *ptr) throw ()
 
void operator delete (void *memory, void *ptr) throw ()
 
void * operator new (size_t size, const std::nothrow_t &) throw ()
 
void operator delete (void *ptr, const std::nothrow_t &) throw ()
 
 COpenGLScene ()
 Constructor. More...
 
virtual ~COpenGLScene ()
 Destructor: More...
 
COpenGLSceneoperator= (const COpenGLScene &obj)
 Copy operator: More...
 
 COpenGLScene (const COpenGLScene &obj)
 Copy constructor: More...
 
template<class T >
void insertCollection (const T &objs, const std::string &vpn=std::string("main"))
 Inserts a set of objects into the scene, in the given viewport ("main" by default). More...
 
void insert (const CRenderizablePtr &newObject, const std::string &viewportName=std::string("main"))
 Insert a new object into the scene, in the given viewport (by default, into the "main" viewport). More...
 
template<class T_it >
void insert (const T_it &begin, const T_it &end, const std::string &vpn=std::string("main"))
 Inserts a set of objects into the scene, in the given viewport ("main" by default). More...
 
COpenGLViewportPtr createViewport (const std::string &viewportName)
 Creates a new viewport, adding it to the scene and returning a pointer to the new object. More...
 
COpenGLViewportPtr getViewport (const std::string &viewportName=std::string("main")) const
 Returns the viewport with the given name, or NULL if it does not exist; note that the default viewport is named "main" and initially occupies the entire rendering area. More...
 
void render () const
 Render this scene. More...
 
size_t viewportsCount () const
 
void clear (bool createMainViewport=true)
 Clear the list of objects and viewports in the scene, deleting objects' memory, and leaving just the default viewport with the default values. More...
 
void enableFollowCamera (bool enabled)
 If disabled (default), the SceneViewer application will ignore the camera of the "main" viewport and keep the viewport selected by the user by hand; otherwise, the camera in the "main" viewport prevails. More...
 
bool followCamera () const
 Return the value of "followCamera". More...
 
CRenderizablePtr getByName (const std::string &str, const std::string &viewportName=std::string("main"))
 Returns the first object with a given name, or NULL (an empty smart pointer) if not found. More...
 
template<typename T >
T::SmartPtr getByClass (const size_t &ith=0) const
 Returns the i'th object of a given class (or of a descendant class), or NULL (an empty smart pointer) if not found. More...
 
void removeObject (const CRenderizablePtr &obj, const std::string &viewportName=std::string("main"))
 Removes the given object from the scene (it also deletes the object to free its memory). More...
 
void initializeAllTextures ()
 Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL) More...
 
void dumpListOfObjects (mrpt::utils::CStringList &lst)
 Retrieves a list of all objects in text form. More...
 
bool saveToFile (const std::string &fil) const
 Saves the scene to a 3Dscene file, loadable by the application SceneViewer3D. More...
 
bool loadFromFile (const std::string &fil)
 Loads the scene from a 3Dscene file, the format used by the application SceneViewer3D. More...
 
bool traceRay (const mrpt::poses::CPose3D &o, double &dist) const
 Traces a ray. More...
 
void getBoundingBox (mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max, const std::string &vpn=std::string("main")) const
 Evaluates the bounding box of the scene in the given viewport (default: "main"). More...
 
template<typename FUNCTOR >
void visitAllObjects (FUNCTOR functor) const
 Recursive depth-first visit all objects in all viewports of the scene, calling the user-supplied function The passed function must accept only one argument of type "const mrpt::opengl::CRenderizablePtr &". More...
 
template<typename FUNCTOR , typename EXTRA_PARAM >
void visitAllObjects (FUNCTOR functor, const EXTRA_PARAM &userParam) const
 Recursive depth-first visit all objects in all viewports of the scene, calling the user-supplied function The passed function must accept a first argument of type "const mrpt::opengl::CRenderizablePtr &" and a second one of type EXTRA_PARAM. More...
 
virtual mxArraywriteToMatlab () const
 Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class. More...
 
mrpt::utils::CObjectPtr duplicateGetSmartPtr () const
 Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer). More...
 
CObject * clone () const
 Cloning interface for smart pointers. More...
 

Static Public Member Functions

static void * operator new (size_t size, void *ptr)
 

Static Public Attributes

static const mrpt::utils::TRuntimeClassId classCObject
 
RTTI stuff
static const mrpt::utils::TRuntimeClassId classCSerializable
 

Protected Types

typedef std::vector< COpenGLViewportPtr > TListViewports
 

Protected Member Functions

CSerializable virtual methods
void writeToStream (mrpt::utils::CStream &out, int *getVersion) const
 Introduces a pure virtual method responsible for writing to a CStream. More...
 
void readFromStream (mrpt::utils::CStream &in, int version)
 Introduces a pure virtual method responsible for loading from a CStream This can not be used directly be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori. More...
 

Static Protected Member Functions

template<typename FUNCTOR >
static void internal_visitAllObjects (FUNCTOR functor, const CRenderizablePtr &o)
 

Protected Attributes

bool m_followCamera
 
TListViewports m_viewports
 The list of viewports, indexed by name. More...
 

RTTI stuff

typedef COpenGLScenePtr SmartPtr
 
static mrpt::utils::CLASSINIT _init_COpenGLScene
 
static mrpt::utils::TRuntimeClassId classCOpenGLScene
 
static const mrpt::utils::TRuntimeClassIdclassinfo
 
static const mrpt::utils::TRuntimeClassId_GetBaseClass ()
 
virtual const mrpt::utils::TRuntimeClassIdGetRuntimeClass () const
 Returns information about the class of an object in runtime. More...
 
virtual mrpt::utils::CObjectduplicate () const
 Returns a copy of the object, indepently of its class. More...
 
static mrpt::utils::CObjectCreateObject ()
 
static COpenGLScenePtr Create ()
 

Member Typedef Documentation

typedef COpenGLScenePtr mrpt::opengl::COpenGLScene::SmartPtr

A typedef for the associated smart pointer

Definition at line 51 of file COpenGLScene.h.

typedef std::vector<COpenGLViewportPtr> mrpt::opengl::COpenGLScene::TListViewports
protected

Definition at line 202 of file COpenGLScene.h.

Constructor & Destructor Documentation

mrpt::opengl::COpenGLScene::COpenGLScene ( )

Constructor.

virtual mrpt::opengl::COpenGLScene::~COpenGLScene ( )
virtual

Destructor:

mrpt::opengl::COpenGLScene::COpenGLScene ( const COpenGLScene obj)

Copy constructor:

Member Function Documentation

static const mrpt::utils::TRuntimeClassId* mrpt::opengl::COpenGLScene::_GetBaseClass ( )
staticprotected
void mrpt::opengl::COpenGLScene::clear ( bool  createMainViewport = true)

Clear the list of objects and viewports in the scene, deleting objects' memory, and leaving just the default viewport with the default values.

CObject* mrpt::utils::CObject::clone ( ) const
inlineinherited

Cloning interface for smart pointers.

Definition at line 139 of file CObject.h.

static COpenGLScenePtr mrpt::opengl::COpenGLScene::Create ( )
static
static mrpt::utils::CObject* mrpt::opengl::COpenGLScene::CreateObject ( )
static
COpenGLViewportPtr mrpt::opengl::COpenGLScene::createViewport ( const std::string &  viewportName)

Creates a new viewport, adding it to the scene and returning a pointer to the new object.

Names (case-sensitive) cannot be duplicated: if the name provided coincides with an already existing viewport, a pointer to the existing object will be returned. The first, default viewport, is named "main".

void mrpt::opengl::COpenGLScene::dumpListOfObjects ( mrpt::utils::CStringList lst)

Retrieves a list of all objects in text form.

virtual mrpt::utils::CObject* mrpt::opengl::COpenGLScene::duplicate ( ) const
virtual

Returns a copy of the object, indepently of its class.

Implements mrpt::utils::CObject.

mrpt::utils::CObjectPtr mrpt::utils::CObject::duplicateGetSmartPtr ( ) const
inlineinherited

Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer).

Definition at line 136 of file CObject.h.

void mrpt::opengl::COpenGLScene::enableFollowCamera ( bool  enabled)
inline

If disabled (default), the SceneViewer application will ignore the camera of the "main" viewport and keep the viewport selected by the user by hand; otherwise, the camera in the "main" viewport prevails.

See also
followCamera

Definition at line 114 of file COpenGLScene.h.

bool mrpt::opengl::COpenGLScene::followCamera ( ) const
inline

Return the value of "followCamera".

See also
enableFollowCamera

Definition at line 119 of file COpenGLScene.h.

void mrpt::opengl::COpenGLScene::getBoundingBox ( mrpt::math::TPoint3D bb_min,
mrpt::math::TPoint3D bb_max,
const std::string &  vpn = std::string("main") 
) const

Evaluates the bounding box of the scene in the given viewport (default: "main").

template<typename T >
T::SmartPtr mrpt::opengl::COpenGLScene::getByClass ( const size_t &  ith = 0) const
inline

Returns the i'th object of a given class (or of a descendant class), or NULL (an empty smart pointer) if not found.

Example:

CSpherePtr obs = myscene.getByClass<CSphere>();

By default (ith=0), the first observation is returned.

Definition at line 133 of file COpenGLScene.h.

References MRPT_END, and MRPT_START.

CRenderizablePtr mrpt::opengl::COpenGLScene::getByName ( const std::string &  str,
const std::string &  viewportName = std::string("main") 
)

Returns the first object with a given name, or NULL (an empty smart pointer) if not found.

virtual const mrpt::utils::TRuntimeClassId* mrpt::opengl::COpenGLScene::GetRuntimeClass ( ) const
virtual

Returns information about the class of an object in runtime.

Reimplemented from mrpt::utils::CSerializable.

COpenGLViewportPtr mrpt::opengl::COpenGLScene::getViewport ( const std::string &  viewportName = std::string("main")) const

Returns the viewport with the given name, or NULL if it does not exist; note that the default viewport is named "main" and initially occupies the entire rendering area.

void mrpt::opengl::COpenGLScene::initializeAllTextures ( )

Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL)

void mrpt::opengl::COpenGLScene::insert ( const CRenderizablePtr &  newObject,
const std::string &  viewportName = std::string("main") 
)

Insert a new object into the scene, in the given viewport (by default, into the "main" viewport).

The viewport must be created previously, an exception will be raised if the given name does not correspond to an existing viewport.

See also
createViewport, getViewport

Referenced by mrpt::maps::COctoMapBase< OCTREE, OCTREE_NODE >::saveMetricMapRepresentationToFile().

template<class T_it >
void mrpt::opengl::COpenGLScene::insert ( const T_it &  begin,
const T_it &  end,
const std::string &  vpn = std::string("main") 
)
inline

Inserts a set of objects into the scene, in the given viewport ("main" by default).

See also
createViewport,getViewport

Definition at line 87 of file COpenGLScene.h.

References end().

template<class T >
void mrpt::opengl::COpenGLScene::insertCollection ( const T &  objs,
const std::string &  vpn = std::string("main") 
)
inline

Inserts a set of objects into the scene, in the given viewport ("main" by default).

Any iterable object will be accepted.

See also
createViewport,getViewport

Definition at line 73 of file COpenGLScene.h.

template<typename FUNCTOR >
static void mrpt::opengl::COpenGLScene::internal_visitAllObjects ( FUNCTOR  functor,
const CRenderizablePtr &  o 
)
inlinestaticprotected

Definition at line 208 of file COpenGLScene.h.

References IS_CLASS.

bool mrpt::opengl::COpenGLScene::loadFromFile ( const std::string &  fil)

Loads the scene from a 3Dscene file, the format used by the application SceneViewer3D.

See also
saveToFile
Returns
false on any error.
void mrpt::opengl::COpenGLScene::operator delete ( void *  ptr)
throw (
)
inline

Definition at line 51 of file COpenGLScene.h.

void mrpt::opengl::COpenGLScene::operator delete ( void *  memory,
void *  ptr 
)
throw (
)
inline

Definition at line 51 of file COpenGLScene.h.

void mrpt::opengl::COpenGLScene::operator delete ( void *  ptr,
const std::nothrow_t &   
)
throw (
)
inline

Definition at line 51 of file COpenGLScene.h.

void mrpt::opengl::COpenGLScene::operator delete[] ( void *  ptr)
throw (
)
inline

Definition at line 51 of file COpenGLScene.h.

static void* mrpt::opengl::COpenGLScene::operator new ( size_t  size,
void *  ptr 
)
inlinestatic

Definition at line 51 of file COpenGLScene.h.

void* mrpt::opengl::COpenGLScene::operator new ( size_t  size,
const std::nothrow_t &   
)
throw (
)
inline

Definition at line 51 of file COpenGLScene.h.

void* mrpt::opengl::COpenGLScene::operator new ( size_t  size)
inline

Definition at line 51 of file COpenGLScene.h.

void* mrpt::opengl::COpenGLScene::operator new[] ( size_t  size)
inline

Definition at line 51 of file COpenGLScene.h.

COpenGLScene& mrpt::opengl::COpenGLScene::operator= ( const COpenGLScene obj)

Copy operator:

void mrpt::opengl::COpenGLScene::readFromStream ( mrpt::utils::CStream in,
int  version 
)
protectedvirtual

Introduces a pure virtual method responsible for loading from a CStream This can not be used directly be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori.

Parameters
inThe input binary stream where the object data must read from.
versionThe version of the object stored in the stream: use this version number in your code to know how to read the incoming data.
Exceptions
std::exceptionOn any error, see CStream::ReadBuffer
See also
CStream

Implements mrpt::utils::CSerializable.

void mrpt::opengl::COpenGLScene::removeObject ( const CRenderizablePtr &  obj,
const std::string &  viewportName = std::string("main") 
)

Removes the given object from the scene (it also deletes the object to free its memory).

void mrpt::opengl::COpenGLScene::render ( ) const

Render this scene.

bool mrpt::opengl::COpenGLScene::saveToFile ( const std::string &  fil) const

Saves the scene to a 3Dscene file, loadable by the application SceneViewer3D.

See also
loadFromFile
Returns
false on any error.
bool mrpt::opengl::COpenGLScene::traceRay ( const mrpt::poses::CPose3D o,
double &  dist 
) const

Traces a ray.

size_t mrpt::opengl::COpenGLScene::viewportsCount ( ) const
inline

Definition at line 105 of file COpenGLScene.h.

template<typename FUNCTOR >
void mrpt::opengl::COpenGLScene::visitAllObjects ( FUNCTOR  functor) const
inline

Recursive depth-first visit all objects in all viewports of the scene, calling the user-supplied function The passed function must accept only one argument of type "const mrpt::opengl::CRenderizablePtr &".

Definition at line 181 of file COpenGLScene.h.

References MRPT_END, and MRPT_START.

template<typename FUNCTOR , typename EXTRA_PARAM >
void mrpt::opengl::COpenGLScene::visitAllObjects ( FUNCTOR  functor,
const EXTRA_PARAM &  userParam 
) const
inline

Recursive depth-first visit all objects in all viewports of the scene, calling the user-supplied function The passed function must accept a first argument of type "const mrpt::opengl::CRenderizablePtr &" and a second one of type EXTRA_PARAM.

Definition at line 195 of file COpenGLScene.h.

virtual mxArray* mrpt::utils::CSerializable::writeToMatlab ( ) const
inlinevirtualinherited

Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class.

Returns
A new mxArray (caller is responsible of memory freeing) or NULL is class does not support conversion to MATLAB.

Definition at line 79 of file CSerializable.h.

void mrpt::opengl::COpenGLScene::writeToStream ( mrpt::utils::CStream out,
int *  getVersion 
) const
protectedvirtual

Introduces a pure virtual method responsible for writing to a CStream.

This can not be used directly be users, instead use "stream << object;" for writing it to a stream.

Parameters
outThe output binary stream where object must be dumped.
getVersionIf NULL, the object must be dumped. If not, only the version of the object dump must be returned in this pointer. This enables the versioning of objects dumping and backward compatibility with previously stored data.
Exceptions
std::exceptionOn any error, see CStream::WriteBuffer
See also
CStream

Implements mrpt::utils::CSerializable.

Member Data Documentation

mrpt::utils::CLASSINIT mrpt::opengl::COpenGLScene::_init_COpenGLScene
staticprotected

Definition at line 51 of file COpenGLScene.h.

const mrpt::utils::TRuntimeClassId mrpt::utils::CObject::classCObject
staticinherited

Definition at line 124 of file CObject.h.

mrpt::utils::TRuntimeClassId mrpt::opengl::COpenGLScene::classCOpenGLScene
static

Definition at line 51 of file COpenGLScene.h.

const mrpt::utils::TRuntimeClassId mrpt::utils::CSerializable::classCSerializable
staticinherited

Definition at line 42 of file CSerializable.h.

const mrpt::utils::TRuntimeClassId* mrpt::opengl::COpenGLScene::classinfo
static

Definition at line 51 of file COpenGLScene.h.

bool mrpt::opengl::COpenGLScene::m_followCamera
protected

Definition at line 200 of file COpenGLScene.h.

TListViewports mrpt::opengl::COpenGLScene::m_viewports
protected

The list of viewports, indexed by name.

Definition at line 204 of file COpenGLScene.h.




Page generated by Doxygen 1.8.9.1 for MRPT 1.3.2 SVN:Unversioned directory at Tue Dec 8 09:49:21 UTC 2015