Main MRPT website > C++ reference for MRPT 1.4.0
CSetOfObjects.h
Go to the documentation of this file.
1/* +---------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | http://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6 | See: http://www.mrpt.org/Authors - All rights reserved. |
7 | Released under BSD License. See details in http://www.mrpt.org/License |
8 +---------------------------------------------------------------------------+ */
9#ifndef opengl_CSetOfObjects_H
10#define opengl_CSetOfObjects_H
11
13#include <mrpt/poses/poses_frwds.h> // All these are needed for the auxiliary methods posePDF2opengl()
15
16namespace mrpt
17{
18 namespace opengl
19 {
20
21
22 // This must be added to any CSerializable derived class:
24
25 /** A set of object, which are referenced to the coordinates framework established in this object.
26 * It can be established a hierarchy of "CSetOfObjects", where the coordinates framework of each
27 * one will be referenced to the parent's one.
28 * The list of child objects is accessed directly as in the class "COpenGLScene"
29 * \sa opengl::COpenGLScene
30 * \ingroup mrpt_opengl_grp
31 */
33 {
35
36 protected:
37 /** The list of child objects.
38 * Objects are automatically deleted when calling "clear" or in the destructor.
39 */
41
42 public:
43
44 typedef CListOpenGLObjects::const_iterator const_iterator;
45 typedef CListOpenGLObjects::iterator iterator;
46
47 inline const_iterator begin() const { return m_objects.begin(); }
48 inline const_iterator end() const { return m_objects.end(); }
49 inline iterator begin() { return m_objects.begin(); }
50 inline iterator end() { return m_objects.end(); }
51
52 /** Inserts a set of objects into the list.
53 */
54 template<class T> inline void insertCollection(const T &objs) {
55 insert(objs.begin(),objs.end());
56 }
57 /** Insert a new object to the list.
58 */
59 void insert( const CRenderizablePtr &newObject );
60
61 /** Inserts a set of objects, bounded by iterators, into the list.
62 */
63 template<class T_it> inline void insert(const T_it &begin,const T_it &end) {
64 for (T_it it=begin;it!=end;it++) insert(*it);
65 }
66
67 /** Render child objects.
68 */
69 void render() const MRPT_OVERRIDE;
70
71 /** Clear the list of objects in the scene, deleting objects' memory.
72 */
73 void clear();
74
75 /** Returns number of objects. */
76 size_t size() { return m_objects.size(); }
77
78 /** Returns true if there are no objects. */
79 inline bool empty() const { return m_objects.empty(); }
80
81 /** Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL)
82 */
84
85 /** Returns the first object with a given name, or a NULL pointer if not found.
86 */
87 CRenderizablePtr getByName( const std::string &str );
88
89 /** Returns the i'th object of a given class (or of a descendant class), or NULL (an empty smart pointer) if not found.
90 * Example:
91 * \code
92 CSpherePtr obs = myscene.getByClass<CSphere>();
93 * \endcode
94 * By default (ith=0), the first observation is returned.
95 */
96 template <typename T>
97 typename T::SmartPtr getByClass( const size_t &ith = 0 ) const;
98
99 /** Removes the given object from the scene (it also deletes the object to free its memory).
100 */
101 void removeObject( const CRenderizablePtr &obj );
102
103 /** Retrieves a list of all objects in text form */
105
106 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const MRPT_OVERRIDE;
107
113 bool contains(const CRenderizablePtr &obj) const;
115
116 /** @name pose_pdf -> 3d objects auxiliary templates
117 @{ */
118 // The reason this code is here is to exploit C++'s "T::template function()" in order to
119 // define the members getAs3DObject() in several classes in mrpt-base with its argument
120 // being a class (CSetOfObjects) which is actually declared here, in mrpt-opengl.
121 // Implementations are in "pose_pdfs.cpp", not in "CSetOfObjects" (historic reasons...)
122
123 /** Returns a representation of a the PDF - this is just an auxiliary function, it's more natural to call
124 * mrpt::poses::CPosePDF::getAs3DObject */
126
127 /** Returns a representation of a the PDF - this is just an auxiliary function, it's more natural to call
128 * mrpt::poses::CPointPDF::getAs3DObject */
130
131 /** Returns a representation of a the PDF - this is just an auxiliary function, it's more natural to call
132 * mrpt::poses::CPose3DPDF::getAs3DObject */
134
135 /** Returns a representation of a the PDF - this is just an auxiliary function, it's more natural to call
136 * mrpt::poses::CPose3DQuatPDF::getAs3DObject */
138
139 /** @} */
140
141 private:
142 /** Default constructor
143 */
145
146 /** Private, virtual destructor: only can be deleted from smart pointers */
147 virtual ~CSetOfObjects();
148 };
150 /** Inserts an object into the list. Allows call chaining.
151 * \sa mrpt::opengl::CSetOfObjects::insert
152 */
153 inline CSetOfObjectsPtr &operator<<(CSetOfObjectsPtr &s,const CRenderizablePtr &r) {
154 s->insert(r);
155 return s;
156 }
157 /** Inserts a set of objects into the list. Allows call chaining.
158 * \sa mrpt::opengl::CSetOfObjects::insert
159 */
160 template<class T> inline CSetOfObjectsPtr &operator<<(CSetOfObjectsPtr &o,const std::vector<T> &v) {
161 o->insertCollection(v);
162 return o;
163 }
164
165 // Implementation: (here because it needs the _POST macro defining the SmartPtr)
166 template <typename T>
167 typename T::SmartPtr CSetOfObjects::getByClass( const size_t &ith ) const
168 {
170 size_t foundCount = 0;
171 const mrpt::utils::TRuntimeClassId* class_ID = T::classinfo;
172 for (CListOpenGLObjects::const_iterator it = m_objects.begin();it!=m_objects.end();++it)
173 if ( (*it).present() && (*it)->GetRuntimeClass()->derivedFrom( class_ID ) )
174 if (foundCount++ == ith)
175 return typename T::SmartPtr(*it);
176
177 // If not found directly, search recursively:
178 for (CListOpenGLObjects::const_iterator it=m_objects.begin();it!=m_objects.end();++it)
179 {
180 if ( (*it).present() && (*it)->GetRuntimeClass() == CLASS_ID_NAMESPACE(CSetOfObjects,mrpt::opengl))
181 {
182 typename T::SmartPtr o = CSetOfObjectsPtr(*it)->getByClass<T>(ith);
183 if (o) return o;
184 }
185 }
186
187 return typename T::SmartPtr(); // Not found: return empty smart pointer
189 }
190
191 } // end namespace
192
193} // End of namespace
194
195
196#endif
#define CLASS_ID_NAMESPACE(class_name, namespaceName)
Access to runtime class ID for a defined class name.
Definition: CObject.h:92
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:45
A set of object, which are referenced to the coordinates framework established in this object.
Definition: CSetOfObjects.h:33
void initializeAllTextures()
Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL)
virtual void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
CSetOfObjects()
Default constructor.
virtual CRenderizable & setColorA_u8(const uint8_t a) MRPT_OVERRIDE
Color components in the range [0,255].
void dumpListOfObjects(mrpt::utils::CStringList &lst)
Retrieves a list of all objects in text form
virtual CRenderizable & setColorG_u8(const uint8_t g) MRPT_OVERRIDE
Color components in the range [0,255].
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)...
CRenderizablePtr getByName(const std::string &str)
Returns the first object with a given name, or a NULL pointer if not found.
bool empty() const
Returns true if there are no objects.
Definition: CSetOfObjects.h:79
CListOpenGLObjects::iterator iterator
Definition: CSetOfObjects.h:45
void removeObject(const CRenderizablePtr &obj)
Removes the given object from the scene (it also deletes the object to free its memory).
void insert(const T_it &begin, const T_it &end)
Inserts a set of objects, bounded by iterators, into the list.
Definition: CSetOfObjects.h:63
const_iterator begin() const
Definition: CSetOfObjects.h:47
void insertCollection(const T &objs)
Inserts a set of objects into the list.
Definition: CSetOfObjects.h:54
static CSetOfObjectsPtr posePDF2opengl(const mrpt::poses::CPosePDF &o)
Returns a representation of a the PDF - this is just an auxiliary function, it's more natural to call...
static CSetOfObjectsPtr posePDF2opengl(const mrpt::poses::CPointPDF &o)
Returns a representation of a the PDF - this is just an auxiliary function, it's more natural to call...
CListOpenGLObjects m_objects
The list of child objects.
Definition: CSetOfObjects.h:40
virtual CRenderizable & setColor_u8(const mrpt::utils::TColor &c) MRPT_OVERRIDE
CListOpenGLObjects::const_iterator const_iterator
Definition: CSetOfObjects.h:44
void render() const MRPT_OVERRIDE
Render child objects.
bool contains(const CRenderizablePtr &obj) const
virtual bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const MRPT_OVERRIDE
Simulation of ray-trace, given a pose.
static CSetOfObjectsPtr posePDF2opengl(const mrpt::poses::CPose3DPDF &o)
Returns a representation of a the PDF - this is just an auxiliary function, it's more natural to call...
virtual ~CSetOfObjects()
Private, virtual destructor: only can be deleted from smart pointers.
static CSetOfObjectsPtr posePDF2opengl(const mrpt::poses::CPose3DQuatPDF &o)
Returns a representation of a the PDF - this is just an auxiliary function, it's more natural to call...
virtual CRenderizable & setColorB_u8(const uint8_t b) MRPT_OVERRIDE
Color components in the range [0,255].
const_iterator end() const
Definition: CSetOfObjects.h:48
void insert(const CRenderizablePtr &newObject)
Insert a new object to the list.
virtual CRenderizable & setColorR_u8(const uint8_t r) MRPT_OVERRIDE
Color components in the range [0,255].
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x,...
Definition: CPointPDF.h:39
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:73
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually).
Definition: CPose3DPDF.h:41
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually),...
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
Definition: CPosePDF.h:40
A class for storing a list of text lines.
Definition: CStringList.h:33
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:27
#define MRPT_START
Definition: mrpt_macros.h:349
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
#define MRPT_END
Definition: mrpt_macros.h:353
The namespace for 3D scene representation and rendering.
std::deque< CRenderizablePtr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
Definition: CRenderizable.h:33
struct OPENGL_IMPEXP CRenderizablePtr
Definition: CRenderizable.h:30
struct OPENGL_IMPEXP CSetOfObjectsPtr
Definition: CSetOfObjects.h:23
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned char uint8_t
Definition: pstdint.h:143
Lightweight 3D point.
A RGB color - 8bit.
Definition: TColor.h:26
A structure that holds runtime class type information.
Definition: CObject.h:47



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Fri Jan 20 00:13:14 UTC 2023