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>
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... | |
COpenGLScene & | operator= (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::Ptr | 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 mxArray * | writeToMatlab () 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... | |
CObject * | clone () const |
Cloning interface for smart pointers. More... | |
RTTI classes and functions | |
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... | |
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 | Ptr |
typedef COpenGLScenePtr | ConstPtr |
static mrpt::utils::CLASSINIT | _init_COpenGLScene |
static mrpt::utils::TRuntimeClassId | classCOpenGLScene |
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. More... | |
virtual mrpt::utils::CObject * | duplicate () const |
Returns a copy of the object, indepently of its class. More... | |
static mrpt::utils::CObject * | CreateObject () |
static COpenGLScenePtr | Create () |
typedef COpenGLScenePtr mrpt::opengl::COpenGLScene::ConstPtr |
Definition at line 51 of file COpenGLScene.h.
typedef COpenGLScenePtr mrpt::opengl::COpenGLScene::Ptr |
A typedef for the associated smart pointer
Definition at line 51 of file COpenGLScene.h.
|
protected |
Definition at line 201 of file COpenGLScene.h.
COpenGLScene::COpenGLScene | ( | ) |
Constructor.
Definition at line 49 of file COpenGLScene.cpp.
|
virtual |
COpenGLScene::COpenGLScene | ( | const COpenGLScene & | obj | ) |
Copy constructor:
Definition at line 58 of file COpenGLScene.cpp.
|
staticprotected |
void 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.
Definition at line 75 of file COpenGLScene.cpp.
References createViewport(), and m_viewports.
Referenced by mrpt::hmtslam::CHierarchicalMapMHPartition::getAs3DScene(), operator=(), readFromStream(), and ~COpenGLScene().
|
inlineinherited |
|
static |
|
static |
COpenGLViewportPtr 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".
Definition at line 252 of file COpenGLScene.cpp.
References getViewport(), m_viewports, MRPT_END, and MRPT_START.
Referenced by clear().
void COpenGLScene::dumpListOfObjects | ( | mrpt::utils::CStringList & | lst | ) |
Retrieves a list of all objects in text form.
Definition at line 235 of file COpenGLScene.cpp.
References mrpt::utils::CStringList::add(), mrpt::utils::CStringList::clear(), and m_viewports.
|
virtual |
Returns a copy of the object, indepently of its class.
Implements mrpt::utils::CObject.
|
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 162 of file CObject.h.
References mrpt::utils::CObjectPtr.
Referenced by mrpt::obs::CRawlog::addActions(), mrpt::slam::CIncrementalMapPartitioner::addMapFrame(), and mrpt::obs::CRawlog::addObservations().
|
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.
Definition at line 113 of file COpenGLScene.h.
Referenced by mrpt::hmtslam::CHMTSLAM::LSLAM_process_message_from_AA().
|
inline |
Return the value of "followCamera".
Definition at line 118 of file COpenGLScene.h.
void 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").
Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent.
Definition at line 331 of file COpenGLScene.cpp.
References ASSERTMSG_, and getViewport().
|
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:
By default (ith=0), the first observation is returned.
Definition at line 132 of file COpenGLScene.h.
References MRPT_END, and MRPT_START.
CRenderizablePtr 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.
Definition at line 213 of file COpenGLScene.cpp.
References m_viewports, and MRPT_UNUSED_PARAM.
|
virtual |
Returns information about the class of an object in runtime.
Reimplemented from mrpt::utils::CSerializable.
COpenGLViewportPtr 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.
Definition at line 270 of file COpenGLScene.cpp.
References m_viewports, MRPT_END, and MRPT_START.
Referenced by createViewport(), getBoundingBox(), mrpt::opengl::CFBORender::getCamera(), removeObject(), and mrpt::opengl::CFBORender::setCamera().
void COpenGLScene::initializeAllTextures | ( | ) |
Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL)
Definition at line 226 of file COpenGLScene.cpp.
References m_viewports.
void 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.
Definition at line 195 of file COpenGLScene.cpp.
References m_viewports, MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.
Referenced by mrpt::hmtslam::CHierarchicalMapMHPartition::getAs3DScene(), mrpt::hmtslam::CHMTSLAM::LSLAM_process_message_from_AA(), mrpt::nav::PlannerTPS_VirtualBase::renderMoveTree(), mrpt::maps::COctoMapBase< octomap::OcTree, octomap::OcTreeNode >::saveMetricMapRepresentationToFile(), mrpt::maps::CBeaconMap::saveMetricMapRepresentationToFile(), and mrpt::maps::CLandmarksMap::saveMetricMapRepresentationToFile().
|
inline |
Inserts a set of objects into the scene, in the given viewport ("main" by default).
Definition at line 87 of file COpenGLScene.h.
References begin().
|
inline |
Inserts a set of objects into the scene, in the given viewport ("main" by default).
Any iterable object will be accepted.
Definition at line 73 of file COpenGLScene.h.
|
inlinestaticprotected |
Definition at line 207 of file COpenGLScene.h.
References IS_CLASS.
bool COpenGLScene::loadFromFile | ( | const std::string & | fil | ) |
Loads the scene from a 3Dscene file, the format used by the application SceneViewer3D.
Definition at line 320 of file COpenGLScene.cpp.
Definition at line 51 of file COpenGLScene.h.
Definition at line 51 of file COpenGLScene.h.
|
inline |
Definition at line 51 of file COpenGLScene.h.
Definition at line 51 of file COpenGLScene.h.
Definition at line 51 of file COpenGLScene.h.
|
inline |
Definition at line 51 of file COpenGLScene.h.
|
inline |
Definition at line 51 of file COpenGLScene.h.
|
inline |
Definition at line 51 of file COpenGLScene.h.
COpenGLScene & COpenGLScene::operator= | ( | const COpenGLScene & | obj | ) |
Copy operator:
Definition at line 86 of file COpenGLScene.cpp.
References clear(), m_followCamera, and m_viewports.
|
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.
in | The input binary stream where the object data must read from. |
version | The version of the object stored in the stream: use this version number in your code to know how to read the incoming data. |
std::exception | On any error, see CStream::ReadBuffer |
Implements mrpt::utils::CSerializable.
Definition at line 147 of file COpenGLScene.cpp.
References clear(), m_followCamera, m_viewports, MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION, and version.
void 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).
Definition at line 284 of file COpenGLScene.cpp.
References ASSERT_, getViewport(), MRPT_END, and MRPT_START.
void COpenGLScene::render | ( | ) | const |
Render this scene.
Definition at line 102 of file COpenGLScene.cpp.
References GL_VIEWPORT, glGetIntegerv(), glViewport(), m_viewports, MRPT_END, MRPT_START, and THROW_EXCEPTION.
Referenced by mrpt::opengl::CFBORender::getFrame2().
bool COpenGLScene::saveToFile | ( | const std::string & | fil | ) | const |
Saves the scene to a 3Dscene file, loadable by the application SceneViewer3D.
Definition at line 311 of file COpenGLScene.cpp.
References CFileGZOutputStream.
Referenced by mrpt::nav::PlannerRRT_SE2_TPS::solve().
bool COpenGLScene::traceRay | ( | const mrpt::poses::CPose3D & | o, |
double & | dist | ||
) | const |
|
inline |
Definition at line 104 of file COpenGLScene.h.
|
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 180 of file COpenGLScene.h.
References MRPT_END, and MRPT_START.
|
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 194 of file COpenGLScene.h.
|
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.
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.
|
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.
out | The output binary stream where object must be dumped. |
getVersion | If 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. |
std::exception | On any error, see CStream::WriteBuffer |
Implements mrpt::utils::CSerializable.
Definition at line 127 of file COpenGLScene.cpp.
References m_followCamera, m_viewports, and version.
|
staticprotected |
Definition at line 51 of file COpenGLScene.h.
|
staticinherited |
|
static |
Definition at line 51 of file COpenGLScene.h.
|
staticinherited |
Definition at line 42 of file CSerializable.h.
|
static |
Definition at line 51 of file COpenGLScene.h.
|
protected |
Definition at line 199 of file COpenGLScene.h.
Referenced by operator=(), readFromStream(), and writeToStream().
|
protected |
The list of viewports, indexed by name.
Definition at line 203 of file COpenGLScene.h.
Referenced by clear(), createViewport(), dumpListOfObjects(), getByName(), getViewport(), initializeAllTextures(), insert(), operator=(), readFromStream(), render(), traceRay(), and writeToStream().
Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020 |