Main MRPT website > C++ reference for MRPT 1.5.7
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-2017, 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()
14 #include <mrpt/utils/CStringList.h>
15 
16 namespace mrpt
17 {
18  namespace opengl
19  {
20 
21 
22  // This must be added to any CSerializable derived class:
23  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSetOfObjects, CRenderizable, OPENGL_IMPEXP )
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 
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  */
83  void initializeAllTextures();
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::Ptr 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 */
104  void dumpListOfObjects( mrpt::utils::CStringList &lst );
105 
106  virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const MRPT_OVERRIDE;
107 
108  virtual CRenderizable& setColor_u8(const mrpt::utils::TColor &c) MRPT_OVERRIDE;
109  virtual CRenderizable& setColorR_u8(const uint8_t r) MRPT_OVERRIDE;
110  virtual CRenderizable& setColorG_u8(const uint8_t g) MRPT_OVERRIDE;
111  virtual CRenderizable& setColorB_u8(const uint8_t b) MRPT_OVERRIDE;
112  virtual CRenderizable& setColorA_u8(const uint8_t a) MRPT_OVERRIDE;
113  bool contains(const CRenderizablePtr &obj) const;
114  virtual void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
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 */
125  static CSetOfObjectsPtr posePDF2opengl(const mrpt::poses::CPosePDF &o);
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 */
129  static CSetOfObjectsPtr posePDF2opengl(const mrpt::poses::CPointPDF &o);
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 */
133  static CSetOfObjectsPtr posePDF2opengl(const mrpt::poses::CPose3DPDF &o);
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 */
137  static CSetOfObjectsPtr posePDF2opengl(const mrpt::poses::CPose3DQuatPDF &o);
138 
139  /** @} */
140 
141  private:
142  /** Default constructor
143  */
144  CSetOfObjects( );
145 
146  /** Private, virtual destructor: only can be deleted from smart pointers */
147  virtual ~CSetOfObjects();
148  };
149  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CSetOfObjects, CRenderizable, OPENGL_IMPEXP )
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 Ptr)
166  template <typename T>
167  typename T::Ptr CSetOfObjects::getByClass( const size_t &ith ) const
168  {
169  MRPT_START
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::Ptr(*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::Ptr o = CSetOfObjectsPtr(*it)->getByClass<T>(ith);
183  if (o) return o;
184  }
185  }
186 
187  return typename T::Ptr(); // Not found: return empty smart pointer
188  MRPT_END
189  }
190 
191  } // end namespace
192 
193 } // End of namespace
194 
195 
196 #endif
A set of object, which are referenced to the coordinates framework established in this object...
Definition: CSetOfObjects.h:32
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
void insertCollection(const T &objs)
Inserts a set of objects into the list.
Definition: CSetOfObjects.h:54
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons&#39; properties.
Definition: geometry.cpp:1989
CListOpenGLObjects m_objects
The list of child objects.
Definition: CSetOfObjects.h:40
Scalar * iterator
Definition: eigen_plugins.h:23
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:44
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
bool empty() const
Returns true if there are no objects.
Definition: CSetOfObjects.h:79
std::deque< CRenderizablePtr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
Definition: CRenderizable.h:33
const Scalar * const_iterator
Definition: eigen_plugins.h:24
GLdouble s
Definition: glext.h:3602
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:113
unsigned char uint8_t
Definition: rptypes.h:43
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
A class for storing a list of text lines.
Definition: CStringList.h:32
const_iterator end() const
Definition: CSetOfObjects.h:48
#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...
#define MRPT_END
const GLubyte * c
Definition: glext.h:5590
GLuint GLuint end
Definition: glext.h:3512
GLubyte g
Definition: glext.h:5575
A RGB color - 8bit.
Definition: TColor.h:26
GLubyte GLubyte b
Definition: glext.h:5575
GLsizei const GLchar ** string
Definition: glext.h:3919
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:39
const_iterator begin() const
Definition: CSetOfObjects.h:47
#define CLASS_ID_NAMESPACE(class_name, namespaceName)
Access to runtime class ID for a defined class name.
Definition: CObject.h:86
#define MRPT_START
const GLdouble * v
Definition: glext.h:3603
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...
GLdouble GLdouble GLdouble r
Definition: glext.h:3618
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:72
CListOpenGLObjects::const_iterator const_iterator
Definition: CSetOfObjects.h:44
The namespace for 3D scene representation and rendering.
CListOpenGLObjects::iterator iterator
Definition: CSetOfObjects.h:45
GLsizeiptr size
Definition: glext.h:3779
A structure that holds runtime class type information.
Definition: CObject.h:36
Lightweight 3D point.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
Definition: CPointPDF.h:38
GLubyte GLubyte GLubyte a
Definition: glext.h:5575
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:40
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
T::Ptr 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)...



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019