Main MRPT website > C++ reference for MRPT 1.9.9
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-2018, 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 #pragma once
10 
12 #include <mrpt/poses/poses_frwds.h> // All these are needed for the auxiliary methods posePDF2opengl()
13 
14 namespace mrpt
15 {
16 namespace opengl
17 {
18 /** A set of object, which are referenced to the coordinates framework
19  *established in this object.
20  * It can be established a hierarchy of "CSetOfObjects", where the coordinates
21  *framework of each
22  * one will be referenced to the parent's one.
23  * The list of child objects is accessed directly as in the class
24  *"COpenGLScene"
25  * \sa opengl::COpenGLScene
26  * \ingroup mrpt_opengl_grp
27  */
29 {
31 
32  protected:
33  /** The list of child objects.
34  * Objects are automatically deleted when calling "clear" or in the
35  * destructor.
36  */
38 
39  public:
42 
43  inline const_iterator begin() const { return m_objects.begin(); }
44  inline const_iterator end() const { return m_objects.end(); }
45  inline iterator begin() { return m_objects.begin(); }
46  inline iterator end() { return m_objects.end(); }
47  /** Inserts a set of objects into the list.
48  */
49  template <class T>
50  inline void insertCollection(const T& objs)
51  {
52  insert(objs.begin(), objs.end());
53  }
54  /** Insert a new object to the list.
55  */
56  void insert(const CRenderizable::Ptr& newObject);
57 
58  /** Inserts a set of objects, bounded by iterators, into the list.
59  */
60  template <class T_it>
61  inline void insert(const T_it& begin, const T_it& end)
62  {
63  for (T_it it = begin; it != end; it++) insert(*it);
64  }
65 
66  /** Render child objects.
67  */
68  void render() const override;
69 
70  /** Clear the list of objects in the scene, deleting objects' memory.
71  */
72  void clear();
73 
74  /** Returns number of objects. */
75  size_t size() { return m_objects.size(); }
76  /** Returns true if there are no objects. */
77  inline bool empty() const { return m_objects.empty(); }
78  /** Initializes all textures in the scene (See
79  * opengl::CTexturedPlane::loadTextureInOpenGL)
80  */
81  void initializeAllTextures();
82 
83  /** Returns the first object with a given name, or a nullptr pointer if not
84  * found.
85  */
87 
88  /** Returns the i'th object of a given class (or of a descendant class), or
89  nullptr (an empty smart pointer) if not found.
90  * Example:
91  * \code
92  CSphere::Ptr 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
100  * free its memory).
101  */
102  void removeObject(const CRenderizable::Ptr& obj);
103 
104  /** Retrieves a list of all objects in text form */
105  void dumpListOfObjects(std::vector<std::string>& lst);
106 
107  virtual bool traceRay(
108  const mrpt::poses::CPose3D& o, double& dist) const override;
109 
110  virtual CRenderizable& setColor_u8(const mrpt::img::TColor& c) override;
111  virtual CRenderizable& setColorR_u8(const uint8_t r) override;
112  virtual CRenderizable& setColorG_u8(const uint8_t g) override;
113  virtual CRenderizable& setColorB_u8(const uint8_t b) override;
114  virtual CRenderizable& setColorA_u8(const uint8_t a) override;
115  bool contains(const CRenderizable::Ptr& obj) const;
116  virtual void getBoundingBox(
117  mrpt::math::TPoint3D& bb_min,
118  mrpt::math::TPoint3D& bb_max) const override;
119 
120  /** @name pose_pdf -> 3d objects auxiliary templates
121  @{ */
122  // The reason this code is here is to exploit C++'s "T::template function()"
123  // in order to
124  // define the members getAs3DObject() in several classes in mrpt-base with
125  // its argument
126  // being a class (CSetOfObjects) which is actually declared here, in
127  // mrpt-opengl.
128  // Implementations are in "pose_pdfs.cpp", not in "CSetOfObjects" (historic
129  // reasons...)
130 
131  /** Returns a representation of a the PDF - this is just an auxiliary
132  * function, it's more natural to call
133  * mrpt::poses::CPosePDF::getAs3DObject */
135 
136  /** Returns a representation of a the PDF - this is just an auxiliary
137  * function, it's more natural to call
138  * mrpt::poses::CPointPDF::getAs3DObject */
140 
141  /** Returns a representation of a the PDF - this is just an auxiliary
142  * function, it's more natural to call
143  * mrpt::poses::CPose3DPDF::getAs3DObject */
145 
146  /** Returns a representation of a the PDF - this is just an auxiliary
147  * function, it's more natural to call
148  * mrpt::poses::CPose3DQuatPDF::getAs3DObject */
150  const mrpt::poses::CPose3DQuatPDF& o);
151 
152  /** @} */
153 
154  /** Default constructor
155  */
156  CSetOfObjects();
157 
158  /** Private, virtual destructor: only can be deleted from smart pointers */
159  virtual ~CSetOfObjects();
160 };
161 /** Inserts an object into the list. Allows call chaining.
162  * \sa mrpt::opengl::CSetOfObjects::insert
163  */
166 {
167  s->insert(r);
168  return s;
169 }
170 /** Inserts a set of objects into the list. Allows call chaining.
171  * \sa mrpt::opengl::CSetOfObjects::insert
172  */
173 template <class T>
175  CSetOfObjects::Ptr& o, const std::vector<T>& v)
176 {
177  o->insertCollection(v);
178  return o;
179 }
180 
181 // Implementation: (here because it needs the _POST macro defining the
182 // Smart::Ptr)
183 template <typename T>
184 typename T::Ptr CSetOfObjects::getByClass(const size_t& ith) const
185 {
186  MRPT_START
187  size_t foundCount = 0;
188  const auto class_ID = &T::GetRuntimeClassIdStatic();
189  for (const auto& o : m_objects)
190  if (o && o->GetRuntimeClass()->derivedFrom(class_ID))
191  if (foundCount++ == ith) return std::dynamic_pointer_cast<T>(o);
192 
193  // If not found directly, search recursively:
194  for (const auto& o : m_objects)
195  {
196  if (o &&
197  o->GetRuntimeClass() ==
199  {
200  typename T::Ptr obj = std::dynamic_pointer_cast<CSetOfObjects>(o)
201  ->template getByClass<T>(ith);
202  if (obj) return obj;
203  }
204  }
205 
206  return typename T::Ptr(); // Not found: return empty smart pointer
207  MRPT_END
208 }
209 
210 } // namespace opengl
211 
212 } // namespace mrpt
void clear()
Clear the list of objects in the scene, deleting objects&#39; memory.
Scalar * iterator
Definition: eigen_plugins.h:26
#define MRPT_START
Definition: exceptions.h:262
A set of object, which are referenced to the coordinates framework established in this object...
Definition: CSetOfObjects.h:28
CSetOfObjects()
Default constructor.
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:130
void insertCollection(const T &objs)
Inserts a set of objects into the list.
Definition: CSetOfObjects.h:50
virtual ~CSetOfObjects()
Private, virtual destructor: only can be deleted from smart pointers.
CListOpenGLObjects::const_iterator const_iterator
Definition: CSetOfObjects.h:40
std::deque< CRenderizable::Ptr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
bool contains(const CRenderizable::Ptr &obj) const
void render() const override
Render child objects.
CListOpenGLObjects m_objects
The list of child objects.
Definition: CSetOfObjects.h:37
virtual bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:43
bool empty() const
Returns true if there are no objects.
Definition: CSetOfObjects.h:77
virtual CRenderizable & setColorR_u8(const uint8_t r) override
Color components in the range [0,255].
GLdouble s
Definition: glext.h:3676
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
virtual CRenderizable & setColorG_u8(const uint8_t g) override
Color components in the range [0,255].
unsigned char uint8_t
Definition: rptypes.h:41
void insert(const T_it &begin, const T_it &end)
Inserts a set of objects, bounded by iterators, into the list.
Definition: CSetOfObjects.h:61
const_iterator end() const
Definition: CSetOfObjects.h:44
size_t size()
Returns number of objects.
Definition: CSetOfObjects.h:75
virtual CRenderizable & setColorA_u8(const uint8_t a) override
Color components in the range [0,255].
const GLubyte * c
Definition: glext.h:6313
GLuint GLuint end
Definition: glext.h:3528
GLubyte g
Definition: glext.h:6279
GLubyte GLubyte b
Definition: glext.h:6279
GLsizei const GLchar ** string
Definition: glext.h:4101
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:43
CListOpenGLObjects::iterator iterator
Definition: CSetOfObjects.h:41
void removeObject(const CRenderizable::Ptr &obj)
Removes the given object from the scene (it also deletes the object to free its memory).
#define CLASS_ID_NAMESPACE(class_name, namespaceName)
Definition: CObject.h:88
const GLdouble * v
Definition: glext.h:3678
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...
static CSetOfObjects::Ptr posePDF2opengl(const mrpt::poses::CPosePDF &o)
Returns a representation of a the PDF - this is just an auxiliary function, it&#39;s more natural to call...
Definition: pose_pdfs.cpp:43
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
void dumpListOfObjects(std::vector< std::string > &lst)
Retrieves a list of all objects in text form.
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:88
#define MRPT_END
Definition: exceptions.h:266
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
A RGB color - 8bit.
Definition: TColor.h:22
void initializeAllTextures()
Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL) ...
Lightweight 3D point.
virtual CRenderizable & setColor_u8(const mrpt::img::TColor &c) override
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
Definition: CPointPDF.h:39
CRenderizable::Ptr getByName(const std::string &str)
Returns the first object with a given name, or a nullptr pointer if not found.
void insert(const CRenderizable::Ptr &newObject)
Insert a new object to the list.
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
virtual CRenderizable & setColorB_u8(const uint8_t b) override
Color components in the range [0,255].
const Scalar * const_iterator
Definition: eigen_plugins.h:27
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:42
virtual void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
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 nullptr (an empty smart point...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019