Main MRPT website > C++ reference
MRPT logo
COpenGLStandardObject.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef opengl_COpenGLStandardObject_H
29 #define opengl_COpenGLStandardObject_H
30 
32 #include <mrpt/math/geometry.h>
33 
35 
36 namespace mrpt {
37  namespace opengl {
38  typedef uint32_t _GLENUM;
39  using namespace mrpt::utils;
40  using namespace mrpt::math;
43  /**
44  * Objects of this class represent a generic openGL object without specific geometric properties.
45  * \ingroup mrpt_opengl_grp
46  */
49  protected:
50  /**
51  * OpenGL identifier of the object type.
52  */
53  _GLENUM type;
54  /**
55  * Set of points in which consists this object.
56  */
57  std::vector<TPoint3D> vertices;
58  /**
59  * 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.
60  */
61  uint32_t chunkSize;
62  /**
63  * Set of openGL properties enabled in the rendering of this object.
64  */
65  std::vector<_GLENUM> enabled;
66  float normal[3];
67  public:
68  /**
69  * Render.
70  * \sa mrpt::opengl::CRenderizable
71  */
72  virtual void render_dl() const;
73  /**
74  * Ray Tracing. Will always return false, since objects of this class are not intended to have geometric properties.
75  * \sa mrpt::opengl::CRenderizable
76  */
77  virtual bool traceRay(const mrpt::poses::CPose3D &o,float &dist) const;
78  /**
79  * Creation of object from type, vertices, chunk size and a list of enabled openGL flags.
80  * \throw std::logic_error if the number of vertices is not an exact multiple of the chunk size.
81  */
82  static COpenGLStandardObjectPtr Create(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs=0,const std::vector<_GLENUM> &en=std::vector<_GLENUM>()) {
83  if (cs!=0&&v.size()%cs!=0) throw std::logic_error("Vertices vector does not match chunk size");
84  return COpenGLStandardObjectPtr(new COpenGLStandardObject(t,v,cs,en));
85  }
86  /**
87  * Enable some openGL flag.
88  */
89  inline void enable(_GLENUM flag) {
90  if (find(enabled.begin(),enabled.end(),flag)==enabled.end()) enabled.push_back(flag);
92  }
93  /**
94  * Disable some openGL flag.
95  */
96  inline void disable(_GLENUM flag) {
97  std::remove(enabled.begin(),enabled.end(),flag);
99  }
100  /**
101  * Check whether an openGL will be enabled during the rendering of this object.
102  */
103  inline bool isEnabled(_GLENUM flag) const {
104  return find(enabled.begin(),enabled.end(),flag)!=enabled.end();
105  }
106  /**
107  * Get a list of all currently enabled openGL flags.
108  */
109  inline void getEnabledFlags(std::vector<_GLENUM> &v) const {
110  v=enabled;
111  }
112  /**
113  * Set the list of all openGL flags.
114  */
115  inline void setFlags(const std::vector<_GLENUM> &v) {
116  enabled=v;
118  }
119  /**
120  * Set the normal vector to this object.
121  */
122  inline void setNormal(const float (&n)[3]) {
123  for (size_t i=0;i<3;i++) normal[i]=n[i];
125  }
126  /**
127  * Gets the normal vector to this object.
128  */
129  inline void getNormal(float (&n)[3]) const {
130  for (size_t i=0;i<3;i++) n[i]=normal[i];
131  }
132  private:
133  /**
134  * Constructor with all the information.
135  */
136  COpenGLStandardObject(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs,const vector<_GLENUM> &en):type(t),vertices(v),chunkSize(cs),enabled(en) {
137  for (size_t i=0;i<3;i++) normal[i]=0.0;
138  }
139  /**
140  * Baic empty constructor, initializes to default.
141  */
142  COpenGLStandardObject():type(0),vertices(std::vector<TPoint3D>(0)),chunkSize(0),enabled(std::vector<_GLENUM>()) {
143  for (size_t i=0;i<3;i++) normal[i]=0.0;
144  }
145  /**
146  * Destructor.
147  */
149  };
150  } // end namespace
151 } // End of namespace
152 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013