MRPT logo

mrpt::opengl::COpenGLScene Class Reference

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

#include <mrpt/opengl/COpenGLScene.h>

Inheritance diagram for mrpt::opengl::COpenGLScene:

mrpt::utils::CSerializable

List of all members.

Public Member Functions

 COpenGLScene ()
 Constructor.
virtual ~COpenGLScene ()
 Destructor:.
COpenGLSceneoperator= (const COpenGLScene &obj)
 Copy operator:.
 COpenGLScene (const COpenGLScene &obj)
 Copy constructor:.
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).
COpenGLViewportPtr createViewport (const std::string &viewportName)
 Creates a new viewport, adding it to the scene and returning a pointer to the new object.
COpenGLViewportPtr getViewport (const std::string &viewportName)
 Returns the viewport with the given name, or NULL if it does not exist.
void render ()
 Render this scene.
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.
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.
bool followCamera () const
 Return the value of "followCamera".
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.
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.
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).
void initializeAllTextures ()
 Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL).
void dumpListOfObjects (utils::CStringList &lst)
 Retrieves a list of all objects in text form.

Protected Types

typedef std::vector
< COpenGLViewportPtr > 
TListViewports

Protected Attributes

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


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

In MRPT 0.5.5 this class has been re-structured to contain from 1 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 65 of file COpenGLScene.h.


Member Typedef Documentation

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

Definition at line 162 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

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.

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 ( utils::CStringList lst  ) 

Retrieves a list of all objects in text form.

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 115 of file COpenGLScene.h.

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

Return the value of "followCamera".

See also:
enableFollowCamera

Definition at line 120 of file COpenGLScene.h.

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 134 of file COpenGLScene.h.

References MRPT_TRY_END, and MRPT_TRY_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.

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

Returns the viewport with the given name, or NULL if it does not exist.

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

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

Copy operator:.

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

Render this scene.

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

Definition at line 106 of file COpenGLScene.h.


Member Data Documentation

Definition at line 160 of file COpenGLScene.h.

The list of viewports, indexed by name.

Definition at line 166 of file COpenGLScene.h.




Page generated by Doxygen 1.5.8 for MRPT 0.6.5 SVN:exported at Mon Jan 12 13:00:16 UTC 2009