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



Page generated by Doxygen 1.8.14 for MRPT 1.1.0 SVN: at lun oct 28 00:54:49 CET 2019 Hosted on:
SourceForge.net Logo