Main MRPT website > C++ reference for MRPT 1.5.6
COpenGLStandardObject.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_COpenGLStandardObject_H
10 #define opengl_COpenGLStandardObject_H
11 
13 #include <mrpt/math/geometry.h>
14 
15 namespace mrpt {
16  namespace opengl {
17  typedef uint32_t _GLENUM;
18 
20  /**
21  * Objects of this class represent a generic openGL object without specific geometric properties.
22  * \ingroup mrpt_opengl_grp
23  */
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, and so on. Setting it to 0 will generate a single openGL object.
37  */
38  uint32_t chunkSize;
39  /**
40  * Set of openGL properties enabled in the rendering of this object.
41  */
42  std::vector<_GLENUM> enabled;
43  float normal[3];
44  public:
45  /**
46  * Render.
47  * \sa mrpt::opengl::CRenderizable
48  */
49  virtual void render_dl() const MRPT_OVERRIDE;
50  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
51  void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
52  /**
53  * Ray Tracing. Will always return false, since objects of this class are not intended to have geometric properties.
54  * \sa mrpt::opengl::CRenderizable
55  */
56  bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const MRPT_OVERRIDE;
57  /**
58  * Creation of object from type, vertices, chunk size and a list of enabled openGL flags.
59  * \throw std::logic_error if the number of vertices is not an exact multiple of the chunk size.
60  */
61  static COpenGLStandardObjectPtr Create(_GLENUM t,const std::vector<mrpt::math::TPoint3D> &v,uint32_t cs=0,const std::vector<_GLENUM> &en=std::vector<_GLENUM>());
62 
63  /**
64  * Enable some openGL flag.
65  */
66  inline void enable(_GLENUM flag) {
67  if (find(enabled.begin(),enabled.end(),flag)==enabled.end()) enabled.push_back(flag);
69  }
70  /**
71  * Disable some openGL flag.
72  */
73  void disable(_GLENUM flag);
74  /**
75  * Check whether an openGL will be enabled during the rendering of this object.
76  */
77  inline bool isEnabled(_GLENUM flag) const {
78  return find(enabled.begin(),enabled.end(),flag)!=enabled.end();
79  }
80  /**
81  * Get a list of all currently enabled openGL flags.
82  */
83  inline void getEnabledFlags(std::vector<_GLENUM> &v) const {
84  v=enabled;
85  }
86  /**
87  * Set the list of all openGL flags.
88  */
89  inline void setFlags(const std::vector<_GLENUM> &v) {
90  enabled=v;
92  }
93  /**
94  * Set the normal vector to this object.
95  */
96  inline void setNormal(const float (&n)[3]) {
97  for (size_t i=0;i<3;i++) normal[i]=n[i];
99  }
100  /**
101  * Gets the normal vector to this object.
102  */
103  inline void getNormal(float (&n)[3]) const {
104  for (size_t i=0;i<3;i++) n[i]=normal[i];
105  }
106  private:
107  /**
108  * Constructor with all the information.
109  */
110  COpenGLStandardObject(_GLENUM t,const std::vector<mrpt::math::TPoint3D> &v,uint32_t cs,const std::vector<_GLENUM> &en):type(t),vertices(v),chunkSize(cs),enabled(en) {
111  for (size_t i=0;i<3;i++) normal[i]=0.0;
112  }
113  /**
114  * Baic empty constructor, initializes to default.
115  */
116  COpenGLStandardObject():type(0),vertices(std::vector<mrpt::math::TPoint3D>(0)),chunkSize(0),enabled(std::vector<_GLENUM>()) {
117  for (size_t i=0;i<3;i++) normal[i]=0.0;
118  }
119  /**
120  * Destructor.
121  */
123  };
124  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(COpenGLStandardObject,CRenderizableDisplayList, OPENGL_IMPEXP)
125  } // end namespace
126 } // End of namespace
127 #endif
const GLdouble * v
Definition: glew.h:1296
void setFlags(const std::vector< _GLENUM > &v)
Set the list of all openGL flags.
COpenGLStandardObject(_GLENUM t, const std::vector< mrpt::math::TPoint3D > &v, uint32_t cs, const std::vector< _GLENUM > &en)
Constructor with all the information.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
Definition: geometry.cpp:1996
COpenGLStandardObject()
Baic empty constructor, initializes to default.
void getNormal(float(&n)[3]) const
Gets the normal vector to this object.
GLdouble GLdouble t
Definition: glew.h:1303
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
A renderizable object suitable for rendering with OpenGL's display lists.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
GLsizei n
Definition: glew.h:5051
void setNormal(const float(&n)[3])
Set the normal vector to this object.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const_iterator find(const KEY &key) const
Definition: ts_hash_map.h:139
bool isEnabled(_GLENUM flag) const
Check whether an openGL will be enabled during the rendering of this object.
void getEnabledFlags(std::vector< _GLENUM > &v) const
Get a list of all currently enabled openGL flags.
Objects of this class represent a generic openGL object without specific geometric properties...
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1167
unsigned __int32 uint32_t
Definition: rptypes.h:49
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018