MRPT  1.9.9
CSetOfObjects.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://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::opengl
15 {
16 /** A set of object, which are referenced to the coordinates framework
17  *established in this object.
18  * It can be established a hierarchy of "CSetOfObjects", where the coordinates
19  *framework of each
20  * one will be referenced to the parent's one.
21  * The list of child objects is accessed directly as in the class
22  *"COpenGLScene"
23  * \sa opengl::COpenGLScene
24  * \ingroup mrpt_opengl_grp
25  */
27 {
29 
30  protected:
31  /** The list of child objects.
32  * Objects are automatically deleted when calling "clear" or in the
33  * destructor.
34  */
36 
37  public:
38  using const_iterator = CListOpenGLObjects::const_iterator;
39  using iterator = CListOpenGLObjects::iterator;
40 
41  inline const_iterator begin() const { return m_objects.begin(); }
42  inline const_iterator end() const { return m_objects.end(); }
43  inline iterator begin() { return m_objects.begin(); }
44  inline iterator end() { return m_objects.end(); }
45  /** Inserts a set of objects into the list.
46  */
47  template <class T>
48  inline void insertCollection(const T& objs)
49  {
50  insert(objs.begin(), objs.end());
51  }
52  /** Insert a new object to the list.
53  */
54  void insert(const CRenderizable::Ptr& newObject);
55 
56  /** Inserts a set of objects, bounded by iterators, into the list.
57  */
58  template <class T_it>
59  inline void insert(const T_it& begin, const T_it& end)
60  {
61  for (T_it it = begin; it != end; it++) insert(*it);
62  }
63 
64  /** Render child objects.
65  */
66  void render() const override;
67 
68  /** Clear the list of objects in the scene, deleting objects' memory.
69  */
70  void clear();
71 
72  /** Returns number of objects. */
73  size_t size() { return m_objects.size(); }
74  /** Returns true if there are no objects. */
75  inline bool empty() const { return m_objects.empty(); }
76  /** Initializes all textures in the scene (See
77  * opengl::CTexturedPlane::loadTextureInOpenGL)
78  */
79  void initializeAllTextures();
80 
81  /** Returns the first object with a given name, or a nullptr pointer if not
82  * found.
83  */
85 
86  /** Returns the i'th object of a given class (or of a descendant class), or
87  nullptr (an empty smart pointer) if not found.
88  * Example:
89  * \code
90  CSphere::Ptr obs = myscene.getByClass<CSphere>();
91  * \endcode
92  * By default (ith=0), the first observation is returned.
93  */
94  template <typename T>
95  typename T::Ptr getByClass(const size_t& ith = 0) const;
96 
97  /** Removes the given object from the scene (it also deletes the object to
98  * free its memory).
99  */
100  void removeObject(const CRenderizable::Ptr& obj);
101 
102  /** Retrieves a list of all objects in text form */
103  void dumpListOfObjects(std::vector<std::string>& lst);
104 
105  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
106 
107  CRenderizable& setColor_u8(const mrpt::img::TColor& c) override;
108  CRenderizable& setColorR_u8(const uint8_t r) override;
109  CRenderizable& setColorG_u8(const uint8_t g) override;
110  CRenderizable& setColorB_u8(const uint8_t b) override;
111  CRenderizable& setColorA_u8(const uint8_t a) override;
112  bool contains(const CRenderizable::Ptr& obj) const;
113  void getBoundingBox(
115  mrpt::math::TPoint3D& bb_max) const override;
116 
117  /** @name pose_pdf -> 3d objects auxiliary templates
118  @{ */
119  // The reason this code is here is to exploit C++'s "T::template function()"
120  // in order to
121  // define the members getAs3DObject() in several classes in mrpt-base with
122  // its argument
123  // being a class (CSetOfObjects) which is actually declared here, in
124  // mrpt-opengl.
125  // Implementations are in "pose_pdfs.cpp", not in "CSetOfObjects" (historic
126  // reasons...)
127 
128  /** Returns a representation of a the PDF - this is just an auxiliary
129  * function, it's more natural to call
130  * mrpt::poses::CPosePDF::getAs3DObject */
132 
133  /** Returns a representation of a the PDF - this is just an auxiliary
134  * function, it's more natural to call
135  * mrpt::poses::CPointPDF::getAs3DObject */
137 
138  /** Returns a representation of a the PDF - this is just an auxiliary
139  * function, it's more natural to call
140  * mrpt::poses::CPose3DPDF::getAs3DObject */
142 
143  /** Returns a representation of a the PDF - this is just an auxiliary
144  * function, it's more natural to call
145  * mrpt::poses::CPose3DQuatPDF::getAs3DObject */
147  const mrpt::poses::CPose3DQuatPDF& o);
148 
149  /** @} */
150 
151  /** Default constructor
152  */
153  CSetOfObjects();
154 
155  /** Private, virtual destructor: only can be deleted from smart pointers */
156  ~CSetOfObjects() override;
157 };
158 /** Inserts an object into the list. Allows call chaining.
159  * \sa mrpt::opengl::CSetOfObjects::insert
160  */
163 {
164  s->insert(r);
165  return s;
166 }
167 /** Inserts a set of objects into the list. Allows call chaining.
168  * \sa mrpt::opengl::CSetOfObjects::insert
169  */
170 template <class T>
172  CSetOfObjects::Ptr& o, const std::vector<T>& v)
173 {
174  o->insertCollection(v);
175  return o;
176 }
177 
178 // Implementation: (here because it needs the _POST macro defining the
179 // Smart::Ptr)
180 template <typename T>
181 typename T::Ptr CSetOfObjects::getByClass(const size_t& ith) const
182 {
183  MRPT_START
184  size_t foundCount = 0;
185  const auto class_ID = &T::GetRuntimeClassIdStatic();
186  for (const auto& o : m_objects)
187  if (o && o->GetRuntimeClass()->derivedFrom(class_ID))
188  if (foundCount++ == ith) return std::dynamic_pointer_cast<T>(o);
189 
190  // If not found directly, search recursively:
191  for (const auto& o : m_objects)
192  {
193  if (o && o->GetRuntimeClass() ==
195  {
196  typename T::Ptr obj = std::dynamic_pointer_cast<CSetOfObjects>(o)
197  ->template getByClass<T>(ith);
198  if (obj) return obj;
199  }
200  }
201 
202  return typename T::Ptr(); // Not found: return empty smart pointer
203  MRPT_END
204 }
205 } // namespace mrpt::opengl
void clear()
Clear the list of objects in the scene, deleting objects&#39; memory.
#define MRPT_START
Definition: exceptions.h:241
A set of object, which are referenced to the coordinates framework established in this object...
Definition: CSetOfObjects.h:26
CSetOfObjects()
Default constructor.
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:123
void insertCollection(const T &objs)
Inserts a set of objects into the list.
Definition: CSetOfObjects.h:48
CListOpenGLObjects::const_iterator const_iterator
Definition: CSetOfObjects.h:38
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:35
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:40
bool empty() const
Returns true if there are no objects.
Definition: CSetOfObjects.h:75
CRenderizable & setColorR_u8(const uint8_t r) override
Color components in the range [0,255].
GLdouble s
Definition: glext.h:3682
GLsizei GLsizei GLuint * obj
Definition: glext.h:4085
CRenderizable & setColorG_u8(const uint8_t g) override
Color components in the range [0,255].
unsigned char uint8_t
Definition: rptypes.h:44
void insert(const T_it &begin, const T_it &end)
Inserts a set of objects, bounded by iterators, into the list.
Definition: CSetOfObjects.h:59
const_iterator end() const
Definition: CSetOfObjects.h:42
size_t size()
Returns number of objects.
Definition: CSetOfObjects.h:73
CRenderizable & setColorA_u8(const uint8_t a) override
Color components in the range [0,255].
const GLubyte * c
Definition: glext.h:6406
~CSetOfObjects() override
Private, virtual destructor: only can be deleted from smart pointers.
GLuint GLuint end
Definition: glext.h:3532
GLubyte g
Definition: glext.h:6372
GLubyte GLubyte b
Definition: glext.h:6372
GLsizei const GLchar ** string
Definition: glext.h:4116
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:38
const_iterator begin() const
Definition: CSetOfObjects.h:41
CListOpenGLObjects::iterator iterator
Definition: CSetOfObjects.h:39
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:92
const GLdouble * v
Definition: glext.h:3684
#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:3711
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:84
#define MRPT_END
Definition: exceptions.h:245
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
const auto bb_min
A RGB color - 8bit.
Definition: TColor.h:20
void initializeAllTextures()
Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL) ...
Lightweight 3D point.
Definition: TPoint3D.h:90
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:36
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:6372
CRenderizable & setColorB_u8(const uint8_t b) override
Color components in the range [0,255].
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:39
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: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019