Main MRPT website > C++ reference
MRPT logo
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-2014, 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  using namespace mrpt::utils;
19  using namespace mrpt::math;
20 
22  /**
23  * Objects of this class represent a generic openGL object without specific geometric properties.
24  * \ingroup mrpt_opengl_grp
25  */
28  protected:
29  /**
30  * OpenGL identifier of the object type.
31  */
32  _GLENUM type;
33  /**
34  * Set of points in which consists this object.
35  */
36  std::vector<TPoint3D> vertices;
37  /**
38  * 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.
39  */
40  uint32_t chunkSize;
41  /**
42  * Set of openGL properties enabled in the rendering of this object.
43  */
44  std::vector<_GLENUM> enabled;
45  float normal[3];
46  public:
47  /**
48  * Render.
49  * \sa mrpt::opengl::CRenderizable
50  */
51  virtual void render_dl() const;
52  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
53  virtual void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const;
54  /**
55  * Ray Tracing. Will always return false, since objects of this class are not intended to have geometric properties.
56  * \sa mrpt::opengl::CRenderizable
57  */
58  virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
59  /**
60  * Creation of object from type, vertices, chunk size and a list of enabled openGL flags.
61  * \throw std::logic_error if the number of vertices is not an exact multiple of the chunk size.
62  */
63  static COpenGLStandardObjectPtr Create(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs=0,const std::vector<_GLENUM> &en=std::vector<_GLENUM>());
64 
65  /**
66  * Enable some openGL flag.
67  */
68  inline void enable(_GLENUM flag) {
69  if (find(enabled.begin(),enabled.end(),flag)==enabled.end()) enabled.push_back(flag);
71  }
72  /**
73  * Disable some openGL flag.
74  */
75  inline void disable(_GLENUM flag) {
76  std::remove(enabled.begin(),enabled.end(),flag);
78  }
79  /**
80  * Check whether an openGL will be enabled during the rendering of this object.
81  */
82  inline bool isEnabled(_GLENUM flag) const {
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 {
89  v=enabled;
90  }
91  /**
92  * Set the list of all openGL flags.
93  */
94  inline void setFlags(const std::vector<_GLENUM> &v) {
95  enabled=v;
97  }
98  /**
99  * Set the normal vector to this object.
100  */
101  inline void setNormal(const float (&n)[3]) {
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  for (size_t i=0;i<3;i++) n[i]=normal[i];
110  }
111  private:
112  /**
113  * Constructor with all the information.
114  */
115  COpenGLStandardObject(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs,const vector<_GLENUM> &en):type(t),vertices(v),chunkSize(cs),enabled(en) {
116  for (size_t i=0;i<3;i++) normal[i]=0.0;
117  }
118  /**
119  * Baic empty constructor, initializes to default.
120  */
121  COpenGLStandardObject():type(0),vertices(std::vector<TPoint3D>(0)),chunkSize(0),enabled(std::vector<_GLENUM>()) {
122  for (size_t i=0;i<3;i++) normal[i]=0.0;
123  }
124  /**
125  * Destructor.
126  */
128  };
129  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(COpenGLStandardObject,CRenderizableDisplayList, OPENGL_IMPEXP)
130  } // end namespace
131 } // End of namespace
132 #endif
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
void setFlags(const std::vector< _GLENUM > &v)
Set the list of all openGL flags.
EIGEN_STRONG_INLINE const AdjointReturnType t() const
Transpose.
COpenGLStandardObject()
Baic empty constructor, initializes to default.
void getNormal(float(&n)[3]) const
Gets the normal vector to this object.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
STL namespace.
A renderizable object suitable for rendering with OpenGL's display lists.
This base provides a set of functions for maths stuff.
Definition: CArray.h:18
void disable(_GLENUM flag)
Disable some openGL flag.
#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...
void setNormal(const float(&n)[3])
Set the normal vector to this object.
COpenGLStandardObject(_GLENUM t, const std::vector< TPoint3D > &v, uint32_t cs, const vector< _GLENUM > &en)
Constructor with all the information.
Definition: cs.h:25
bool BASE_IMPEXP traceRay(const vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
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:69
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...
Lightweight 3D point.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014