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
mrpt::poses::CPose3DQuatPDF
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually),...
Definition: CPose3DQuatPDF.h:46
mrpt::opengl::CSetOfObjects::m_objects
CListOpenGLObjects m_objects
The list of child objects.
Definition: CSetOfObjects.h:37
mrpt::opengl::CSetOfObjects::dumpListOfObjects
void dumpListOfObjects(std::vector< std::string > &lst)
Retrieves a list of all objects in text form
Definition: CSetOfObjects.cpp:118
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
s
GLdouble s
Definition: glext.h:3676
mrpt::opengl::CSetOfObjects::contains
bool contains(const CRenderizable::Ptr &obj) const
Definition: CSetOfObjects.cpp:202
mrpt::opengl::CSetOfObjects::removeObject
void removeObject(const CRenderizable::Ptr &obj)
Removes the given object from the scene (it also deletes the object to free its memory).
Definition: CSetOfObjects.cpp:145
mrpt::opengl::CRenderizable
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:43
c
const GLubyte * c
Definition: glext.h:6313
end
GLuint GLuint end
Definition: glext.h:3528
mrpt::poses::CPose3DPDF
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually).
Definition: CPose3DPDF.h:42
obj
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
mrpt::opengl::CSetOfObjects::setColorG_u8
virtual CRenderizable & setColorG_u8(const uint8_t g) override
Color components in the range [0,255].
Definition: CSetOfObjects.cpp:215
mrpt::opengl::CSetOfObjects::getByName
CRenderizable::Ptr getByName(const std::string &str)
Returns the first object with a given name, or a nullptr pointer if not found.
Definition: CSetOfObjects.cpp:242
mrpt::opengl::CSetOfObjects::insert
void insert(const CRenderizable::Ptr &newObject)
Insert a new object to the list.
Definition: CSetOfObjects.cpp:107
mrpt::opengl::CRenderizable::Ptr
std::shared_ptr< CRenderizable > Ptr
Definition: CRenderizable.h:45
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
g
GLubyte g
Definition: glext.h:6279
mrpt::opengl::CSetOfObjects::const_iterator
CListOpenGLObjects::const_iterator const_iterator
Definition: CSetOfObjects.h:40
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::opengl::CSetOfObjects::setColorB_u8
virtual CRenderizable & setColorB_u8(const uint8_t b) override
Color components in the range [0,255].
Definition: CSetOfObjects.cpp:223
mrpt::opengl::CSetOfObjects::getBoundingBox
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...
Definition: CSetOfObjects.cpp:263
mrpt::opengl::CSetOfObjects::getByClass
T::Ptr getByClass(const size_t &ith=0) const
Returns the i'th object of a given class (or of a descendant class), or nullptr (an empty smart point...
Definition: CSetOfObjects.h:184
v
const GLdouble * v
Definition: glext.h:3678
mrpt::opengl::CSetOfObjects::insert
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
r
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
mrpt::opengl::CSetOfObjects
A set of object, which are referenced to the coordinates framework established in this object.
Definition: CSetOfObjects.h:28
mrpt::opengl::CSetOfObjects::setColorA_u8
virtual CRenderizable & setColorA_u8(const uint8_t a) override
Color components in the range [0,255].
Definition: CSetOfObjects.cpp:231
mrpt::opengl::CSetOfObjects::posePDF2opengl
static CSetOfObjects::Ptr posePDF2opengl(const mrpt::poses::CPosePDF &o)
Returns a representation of a the PDF - this is just an auxiliary function, it's more natural to call...
Definition: pose_pdfs.cpp:43
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
b
GLubyte GLubyte b
Definition: glext.h:6279
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:22
CLASS_ID_NAMESPACE
#define CLASS_ID_NAMESPACE(class_name, namespaceName)
Definition: CObject.h:88
CRenderizable.h
mrpt::opengl::CSetOfObjects::begin
const_iterator begin() const
Definition: CSetOfObjects.h:43
mrpt::opengl::CSetOfObjects::clear
void clear()
Clear the list of objects in the scene, deleting objects' memory.
Definition: CSetOfObjects.cpp:35
mrpt::opengl::CSetOfObjects::Ptr
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:30
mrpt::opengl::CSetOfObjects::begin
iterator begin()
Definition: CSetOfObjects.h:45
mrpt::opengl::CSetOfObjects::traceRay
virtual bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
Definition: CSetOfObjects.cpp:160
mrpt::opengl::operator<<
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:130
mrpt::opengl::CSetOfObjects::render
void render() const override
Render child objects.
Definition: CSetOfObjects.cpp:44
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::opengl::CSetOfObjects::insertCollection
void insertCollection(const T &objs)
Inserts a set of objects into the list.
Definition: CSetOfObjects.h:50
mrpt::poses::CPosePDF
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
Definition: CPosePDF.h:41
mrpt::opengl::CSetOfObjects::empty
bool empty() const
Returns true if there are no objects.
Definition: CSetOfObjects.h:77
poses_frwds.h
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
mrpt::opengl::CSetOfObjects::~CSetOfObjects
virtual ~CSetOfObjects()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CSetOfObjects.cpp:106
mrpt::opengl::CListOpenGLObjects
std::deque< CRenderizable::Ptr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
Definition: CRenderizable.h:332
mrpt::opengl::CSetOfObjects::initializeAllTextures
void initializeAllTextures()
Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL)
Definition: CSetOfObjects.cpp:91
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::opengl::CSetOfObjects::end
iterator end()
Definition: CSetOfObjects.h:46
iterator
Scalar * iterator
Definition: eigen_plugins.h:26
mrpt::opengl::CSetOfObjects::end
const_iterator end() const
Definition: CSetOfObjects.h:44
mrpt::poses::CPointPDF
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x,...
Definition: CPointPDF.h:39
mrpt::opengl::CSetOfObjects::size
size_t size()
Returns number of objects.
Definition: CSetOfObjects.h:75
mrpt::opengl::CSetOfObjects::setColorR_u8
virtual CRenderizable & setColorR_u8(const uint8_t r) override
Color components in the range [0,255].
Definition: CSetOfObjects.cpp:207
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
mrpt::opengl::CSetOfObjects::iterator
CListOpenGLObjects::iterator iterator
Definition: CSetOfObjects.h:41
mrpt::opengl::CSetOfObjects::setColor_u8
virtual CRenderizable & setColor_u8(const mrpt::img::TColor &c) override
Definition: CSetOfObjects.cpp:192
mrpt::opengl::CSetOfObjects::CSetOfObjects
CSetOfObjects()
Default constructor.
Definition: CSetOfObjects.cpp:105
a
GLubyte GLubyte GLubyte a
Definition: glext.h:6279



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST