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::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:
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  virtual bool traceRay(
106  const mrpt::poses::CPose3D& o, double& dist) const override;
107 
108  virtual CRenderizable& setColor_u8(const mrpt::img::TColor& c) override;
109  virtual CRenderizable& setColorR_u8(const uint8_t r) override;
110  virtual CRenderizable& setColorG_u8(const uint8_t g) override;
111  virtual CRenderizable& setColorB_u8(const uint8_t b) override;
112  virtual CRenderizable& setColorA_u8(const uint8_t a) override;
113  bool contains(const CRenderizable::Ptr& obj) const;
114  virtual void getBoundingBox(
115  mrpt::math::TPoint3D& bb_min,
116  mrpt::math::TPoint3D& bb_max) const override;
117 
118  /** @name pose_pdf -> 3d objects auxiliary templates
119  @{ */
120  // The reason this code is here is to exploit C++'s "T::template function()"
121  // in order to
122  // define the members getAs3DObject() in several classes in mrpt-base with
123  // its argument
124  // being a class (CSetOfObjects) which is actually declared here, in
125  // mrpt-opengl.
126  // Implementations are in "pose_pdfs.cpp", not in "CSetOfObjects" (historic
127  // reasons...)
128 
129  /** Returns a representation of a the PDF - this is just an auxiliary
130  * function, it's more natural to call
131  * mrpt::poses::CPosePDF::getAs3DObject */
133 
134  /** Returns a representation of a the PDF - this is just an auxiliary
135  * function, it's more natural to call
136  * mrpt::poses::CPointPDF::getAs3DObject */
138 
139  /** Returns a representation of a the PDF - this is just an auxiliary
140  * function, it's more natural to call
141  * mrpt::poses::CPose3DPDF::getAs3DObject */
143 
144  /** Returns a representation of a the PDF - this is just an auxiliary
145  * function, it's more natural to call
146  * mrpt::poses::CPose3DQuatPDF::getAs3DObject */
148  const mrpt::poses::CPose3DQuatPDF& o);
149 
150  /** @} */
151 
152  /** Default constructor
153  */
154  CSetOfObjects();
155 
156  /** Private, virtual destructor: only can be deleted from smart pointers */
157  virtual ~CSetOfObjects();
158 };
159 /** Inserts an object into the list. Allows call chaining.
160  * \sa mrpt::opengl::CSetOfObjects::insert
161  */
164 {
165  s->insert(r);
166  return s;
167 }
168 /** Inserts a set of objects into the list. Allows call chaining.
169  * \sa mrpt::opengl::CSetOfObjects::insert
170  */
171 template <class T>
173  CSetOfObjects::Ptr& o, const std::vector<T>& v)
174 {
175  o->insertCollection(v);
176  return o;
177 }
178 
179 // Implementation: (here because it needs the _POST macro defining the
180 // Smart::Ptr)
181 template <typename T>
182 typename T::Ptr CSetOfObjects::getByClass(const size_t& ith) const
183 {
184  MRPT_START
185  size_t foundCount = 0;
186  const auto class_ID = &T::GetRuntimeClassIdStatic();
187  for (const auto& o : m_objects)
188  if (o && o->GetRuntimeClass()->derivedFrom(class_ID))
189  if (foundCount++ == ith) return std::dynamic_pointer_cast<T>(o);
190 
191  // If not found directly, search recursively:
192  for (const auto& o : m_objects)
193  {
194  if (o &&
195  o->GetRuntimeClass() ==
197  {
198  typename T::Ptr obj = std::dynamic_pointer_cast<CSetOfObjects>(o)
199  ->template getByClass<T>(ith);
200  if (obj) return obj;
201  }
202  }
203 
204  return typename T::Ptr(); // Not found: return empty smart pointer
205  MRPT_END
206 }
207 } // namespace mrpt
208 
209 
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:26
CSetOfObjects()
Default constructor.
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:128
void insertCollection(const T &objs)
Inserts a set of objects into the list.
Definition: CSetOfObjects.h:48
virtual ~CSetOfObjects()
Private, virtual destructor: only can be deleted from smart pointers.
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
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:41
bool empty() const
Returns true if there are no objects.
Definition: CSetOfObjects.h:75
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:59
const_iterator end() const
Definition: CSetOfObjects.h:42
size_t size()
Returns number of objects.
Definition: CSetOfObjects.h:73
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:39
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:87
const GLdouble * v
Definition: glext.h:3678
#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:86
#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:20
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:37
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:40
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020