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-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 /** A set of object, which are referenced to the coordinates framework
21  *established in this object.
22  * It can be established a hierarchy of "CSetOfObjects", where the coordinates
23  *framework of each
24  * one will be referenced to the parent's one.
25  * The list of child objects is accessed directly as in the class
26  *"COpenGLScene"
27  * \sa opengl::COpenGLScene
28  * \ingroup mrpt_opengl_grp
29  */
31 {
33 
34  protected:
35  /** The list of child objects.
36  * Objects are automatically deleted when calling "clear" or in the
37  * destructor.
38  */
40 
41  public:
44 
45  inline const_iterator begin() const { return m_objects.begin(); }
46  inline const_iterator end() const { return m_objects.end(); }
47  inline iterator begin() { return m_objects.begin(); }
48  inline iterator end() { return m_objects.end(); }
49  /** Inserts a set of objects into the list.
50  */
51  template <class T>
52  inline void insertCollection(const T& objs)
53  {
54  insert(objs.begin(), objs.end());
55  }
56  /** Insert a new object to the list.
57  */
58  void insert(const CRenderizable::Ptr& newObject);
59 
60  /** Inserts a set of objects, bounded by iterators, into the list.
61  */
62  template <class T_it>
63  inline void insert(const T_it& begin, const T_it& end)
64  {
65  for (T_it it = begin; it != end; it++) insert(*it);
66  }
67 
68  /** Render child objects.
69  */
70  void render() const override;
71 
72  /** Clear the list of objects in the scene, deleting objects' memory.
73  */
74  void clear();
75 
76  /** Returns number of objects. */
77  size_t size() { return m_objects.size(); }
78  /** Returns true if there are no objects. */
79  inline bool empty() const { return m_objects.empty(); }
80  /** Initializes all textures in the scene (See
81  * opengl::CTexturedPlane::loadTextureInOpenGL)
82  */
83  void initializeAllTextures();
84 
85  /** Returns the first object with a given name, or a nullptr pointer if not
86  * found.
87  */
89 
90  /** Returns the i'th object of a given class (or of a descendant class), or
91  nullptr (an empty smart pointer) if not found.
92  * Example:
93  * \code
94  CSphere::Ptr obs = myscene.getByClass<CSphere>();
95  * \endcode
96  * By default (ith=0), the first observation is returned.
97  */
98  template <typename T>
99  typename T::Ptr getByClass(const size_t& ith = 0) const;
100 
101  /** Removes the given object from the scene (it also deletes the object to
102  * free its memory).
103  */
104  void removeObject(const CRenderizable::Ptr& obj);
105 
106  /** Retrieves a list of all objects in text form */
108 
109  virtual bool traceRay(
110  const mrpt::poses::CPose3D& o, double& dist) const override;
111 
112  virtual CRenderizable& setColor_u8(const mrpt::utils::TColor& c) override;
113  virtual CRenderizable& setColorR_u8(const uint8_t r) override;
114  virtual CRenderizable& setColorG_u8(const uint8_t g) override;
115  virtual CRenderizable& setColorB_u8(const uint8_t b) override;
116  virtual CRenderizable& setColorA_u8(const uint8_t a) override;
117  bool contains(const CRenderizable::Ptr& obj) const;
118  virtual void getBoundingBox(
119  mrpt::math::TPoint3D& bb_min,
120  mrpt::math::TPoint3D& bb_max) const override;
121 
122  /** @name pose_pdf -> 3d objects auxiliary templates
123  @{ */
124  // The reason this code is here is to exploit C++'s "T::template function()"
125  // in order to
126  // define the members getAs3DObject() in several classes in mrpt-base with
127  // its argument
128  // being a class (CSetOfObjects) which is actually declared here, in
129  // mrpt-opengl.
130  // Implementations are in "pose_pdfs.cpp", not in "CSetOfObjects" (historic
131  // reasons...)
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::CPosePDF::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::CPointPDF::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::CPose3DPDF::getAs3DObject */
147 
148  /** Returns a representation of a the PDF - this is just an auxiliary
149  * function, it's more natural to call
150  * mrpt::poses::CPose3DQuatPDF::getAs3DObject */
152  const mrpt::poses::CPose3DQuatPDF& o);
153 
154  /** @} */
155 
156  /** Default constructor
157  */
158  CSetOfObjects();
159 
160  /** Private, virtual destructor: only can be deleted from smart pointers */
161  virtual ~CSetOfObjects();
162 };
163 /** Inserts an object into the list. Allows call chaining.
164  * \sa mrpt::opengl::CSetOfObjects::insert
165  */
168 {
169  s->insert(r);
170  return s;
171 }
172 /** Inserts a set of objects into the list. Allows call chaining.
173  * \sa mrpt::opengl::CSetOfObjects::insert
174  */
175 template <class T>
177  CSetOfObjects::Ptr& o, const std::vector<T>& v)
178 {
179  o->insertCollection(v);
180  return o;
181 }
182 
183 // Implementation: (here because it needs the _POST macro defining the
184 // Smart::Ptr)
185 template <typename T>
186 typename T::Ptr CSetOfObjects::getByClass(const size_t& ith) const
187 {
188  MRPT_START
189  size_t foundCount = 0;
190  const mrpt::utils::TRuntimeClassId* class_ID = &T::GetRuntimeClassIdStatic();
192  it != m_objects.end(); ++it)
193  if (*it && (*it)->GetRuntimeClass()->derivedFrom(class_ID))
194  if (foundCount++ == ith) return std::dynamic_pointer_cast<T>(*it);
195 
196  // If not found directly, search recursively:
198  it != m_objects.end(); ++it)
199  {
200  if (*it &&
201  (*it)->GetRuntimeClass() ==
203  {
204  typename T::Ptr o =
205  std::dynamic_pointer_cast<CSetOfObjects>(*it)->getByClass<T>(
206  ith);
207  if (o) return o;
208  }
209  }
210 
211  return typename T::Ptr(); // Not found: return empty smart pointer
212  MRPT_END
213 }
214 
215 } // end namespace
216 
217 } // End of namespace
218 
219 #endif
void clear()
Clear the list of objects in the scene, deleting objects&#39; memory.
mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:132
A set of object, which are referenced to the coordinates framework established in this object...
Definition: CSetOfObjects.h:30
CSetOfObjects()
Default constructor.
void insertCollection(const T &objs)
Inserts a set of objects into the list.
Definition: CSetOfObjects.h:52
virtual ~CSetOfObjects()
Private, virtual destructor: only can be deleted from smart pointers.
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:39
Scalar * iterator
Definition: eigen_plugins.h:26
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:79
std::shared_ptr< CRenderizable > Ptr
Definition: CRenderizable.h:45
const Scalar * const_iterator
Definition: eigen_plugins.h:27
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:63
A class for storing a list of text lines.
Definition: CStringList.h:32
const_iterator end() const
Definition: CSetOfObjects.h:46
size_t size()
Returns number of objects.
Definition: CSetOfObjects.h:77
virtual CRenderizable & setColorA_u8(const uint8_t a) override
Color components in the range [0,255].
#define MRPT_END
void dumpListOfObjects(mrpt::utils::CStringList &lst)
Retrieves a list of all objects in text form.
const GLubyte * c
Definition: glext.h:6313
GLuint GLuint end
Definition: glext.h:3528
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:32
GLubyte g
Definition: glext.h:6279
A RGB color - 8bit.
Definition: TColor.h:25
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:45
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
#define MRPT_START
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:37
virtual CRenderizable & setColor_u8(const mrpt::utils::TColor &c) override
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
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
CListOpenGLObjects::const_iterator const_iterator
Definition: CSetOfObjects.h:42
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
CListOpenGLObjects::iterator iterator
Definition: CSetOfObjects.h:43
A structure that holds runtime class type information.
Definition: CObject.h:31
void initializeAllTextures()
Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL) ...
Lightweight 3D point.
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].
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: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019