MRPT  1.9.9
COpenGLStandardObject.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 
11 #include <mrpt/math/geometry.h>
13 
14 namespace mrpt::opengl
15 {
16 using _GLENUM = uint32_t;
17 
18 /**
19  * Objects of this class represent a generic openGL object without specific
20  * geometric properties.
21  * \ingroup mrpt_opengl_grp
22  */
24 {
26  protected:
27  /**
28  * OpenGL identifier of the object type.
29  */
31  /**
32  * Set of points in which consists this object.
33  */
34  std::vector<mrpt::math::TPoint3D> vertices;
35  /**
36  * Granularity of the openGL elements. 3 for GL_TRIANGLES, 4 for GL_QUADS,
37  * and so on. Setting it to 0 will generate a single openGL object.
38  */
39  uint32_t chunkSize{0};
40  /**
41  * Set of openGL properties enabled in the rendering of this object.
42  */
43  std::vector<_GLENUM> enabled;
44  float normal[3];
45 
46  public:
47  /**
48  * Render.
49  * \sa mrpt::opengl::CRenderizable
50  */
51  void render_dl() const override;
52  /** Evaluates the bounding box of this object (including possible children)
53  * in the coordinate frame of the object parent. */
54  void getBoundingBox(
56  mrpt::math::TPoint3D& bb_max) const override;
57  /**
58  * Ray Tracing. Will always return false, since objects of this class are
59  * not intended to have geometric properties.
60  * \sa mrpt::opengl::CRenderizable
61  */
62  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
63 
64  /**
65  * Enable some openGL flag.
66  */
67  inline void enable(_GLENUM flag)
68  {
69  if (find(enabled.begin(), enabled.end(), flag) == enabled.end())
70  enabled.push_back(flag);
72  }
73  /**
74  * Disable some openGL flag.
75  */
76  void disable(_GLENUM flag);
77  /**
78  * Check whether an openGL will be enabled during the rendering of this
79  * object.
80  */
81  inline bool isEnabled(_GLENUM flag) const
82  {
83  return find(enabled.begin(), enabled.end(), flag) != enabled.end();
84  }
85  /**
86  * Get a list of all currently enabled openGL flags.
87  */
88  inline void getEnabledFlags(std::vector<_GLENUM>& v) const { v = enabled; }
89  /**
90  * Set the list of all openGL flags.
91  */
92  inline void setFlags(const std::vector<_GLENUM>& v)
93  {
94  enabled = v;
96  }
97  /**
98  * Set the normal vector to this object.
99  */
100  inline void setNormal(const float (&n)[3])
101  {
102  for (size_t i = 0; i < 3; i++) normal[i] = n[i];
104  }
105  /**
106  * Gets the normal vector to this object.
107  */
108  inline void getNormal(float (&n)[3]) const
109  {
110  for (size_t i = 0; i < 3; i++) n[i] = normal[i];
111  }
112  /**
113  * Creation of object from type, vertices, chunk size and a list of enabled
114  * openGL flags.
115  * \throw std::logic_error if the number of vertices is not an exact
116  * multiple of the chunk size.
117  */
119  _GLENUM t, const std::vector<mrpt::math::TPoint3D>& v, uint32_t cs,
120  const std::vector<_GLENUM>& en)
121  : type(t), vertices(v), chunkSize(cs), enabled(en)
122  {
123  for (float& i : normal) i = 0.0;
124  }
125  /**
126  * Baic empty constructor, initializes to default.
127  */
129  : vertices(std::vector<mrpt::math::TPoint3D>(0)),
130 
131  enabled(std::vector<_GLENUM>())
132  {
133  for (float& i : normal) i = 0.0;
134  }
135  /**
136  * Destructor.
137  */
138  ~COpenGLStandardObject() override = default;
139 };
140 } // namespace mrpt::opengl
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
GLdouble GLdouble t
Definition: glext.h:3695
void setFlags(const std::vector< _GLENUM > &v)
Set the list of all openGL flags.
const_iterator find(const KEY &key) const
Definition: ts_hash_map.h:223
COpenGLStandardObject(_GLENUM t, const std::vector< mrpt::math::TPoint3D > &v, uint32_t cs, const std::vector< _GLENUM > &en)
Creation of object from type, vertices, chunk size and a list of enabled openGL flags.
COpenGLStandardObject()
Baic empty constructor, initializes to default.
GLenum GLsizei n
Definition: glext.h:5136
std::vector< _GLENUM > enabled
Set of openGL properties enabled in the rendering of this object.
STL namespace.
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...
~COpenGLStandardObject() override=default
Destructor.
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
void setNormal(const float(&n)[3])
Set the normal vector to this object.
bool isEnabled(_GLENUM flag) const
Check whether an openGL will be enabled during the rendering of this object.
void getNormal(float(&n)[3]) const
Gets the normal vector to this object.
void getEnabledFlags(std::vector< _GLENUM > &v) const
Get a list of all currently enabled openGL flags.
void disable(_GLENUM flag)
Disable some openGL flag.
const GLdouble * v
Definition: glext.h:3684
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...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
std::vector< mrpt::math::TPoint3D > vertices
Set of points in which consists this object.
uint32_t chunkSize
Granularity of the openGL elements.
const auto bb_min
Objects of this class represent a generic openGL object without specific geometric properties...
Lightweight 3D point.
Definition: TPoint3D.h:90
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray Tracing.
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3532
void render_dl() const override
Render.
void enable(_GLENUM flag)
Enable some openGL flag.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: abb8b1a1e Fri Oct 18 14:19:12 2019 +0200 at vie oct 18 14:20:13 CEST 2019