Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef opengl_CSetOfTriangles_H
00029 #define opengl_CSetOfTriangles_H
00030
00031 #include <mrpt/opengl/CRenderizableDisplayList.h>
00032 #include <mrpt/math/geometry.h>
00033
00034 namespace mrpt
00035 {
00036 namespace opengl
00037 {
00038 class OPENGL_IMPEXP CSetOfTriangles;
00039
00040
00041 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSetOfTriangles, CRenderizableDisplayList, OPENGL_IMPEXP )
00042
00043
00044
00045
00046
00047
00048 class OPENGL_IMPEXP CSetOfTriangles : public CRenderizableDisplayList
00049 {
00050 DEFINE_SERIALIZABLE( CSetOfTriangles )
00051 public:
00052
00053
00054
00055 struct OPENGL_IMPEXP TTriangle
00056 {
00057 inline TTriangle() { }
00058 inline TTriangle(const mrpt::math::TPolygon3D &p) {
00059 ASSERT_(p.size()==3)
00060 for (size_t i=0;i<3;i++) {
00061 x[i]=p[i].x; y[i]=p[i].y; z[i]=p[i].z; r[i]=g[i]=b[i]=a[i]=1; }
00062 }
00063 float x[3],y[3],z[3];
00064 float r[3],g[3],b[3],a[3];
00065 };
00066
00067
00068
00069 typedef std::vector<TTriangle>::const_iterator const_iterator;
00070
00071
00072
00073 typedef std::vector<TTriangle>::const_reverse_iterator const_reverse_iterator;
00074 protected:
00075
00076
00077
00078
00079 std::vector<TTriangle> m_triangles;
00080
00081
00082
00083 bool m_enableTransparency;
00084
00085
00086
00087 mutable bool polygonsUpToDate;
00088
00089
00090
00091 mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolygons;
00092 public:
00093
00094
00095
00096 void updatePolygons() const;
00097
00098
00099
00100 inline void clearTriangles() { m_triangles.clear();polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
00101
00102
00103
00104 inline size_t getTrianglesCount() const { return m_triangles.size(); }
00105
00106
00107
00108 inline void getTriangle(size_t idx, TTriangle &t) const { ASSERT_(idx<m_triangles.size()); t=m_triangles[idx]; }
00109
00110
00111
00112 inline void insertTriangle( const TTriangle &t ) { m_triangles.push_back(t);polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
00113
00114
00115
00116
00117 template<class InputIterator> inline void insertTriangles(const InputIterator &begin,const InputIterator &end) {
00118 m_triangles.insert(m_triangles.end(),begin,end);
00119 polygonsUpToDate=false;
00120 CRenderizableDisplayList::notifyChange();
00121 }
00122
00123
00124
00125 inline void insertTriangles(const CSetOfTrianglesPtr &p) {
00126 reserve(m_triangles.size()+p->m_triangles.size());
00127 m_triangles.insert(m_triangles.end(),p->m_triangles.begin(),p->m_triangles.end());
00128 polygonsUpToDate=false;
00129 CRenderizableDisplayList::notifyChange();
00130 }
00131
00132
00133
00134 inline void reserve(size_t t) {
00135 m_triangles.reserve(t);
00136 CRenderizableDisplayList::notifyChange();
00137 }
00138
00139
00140 inline void enableTransparency( bool v ) { m_enableTransparency = v; CRenderizableDisplayList::notifyChange(); }
00141
00142 virtual CRenderizable& setColor_u8(const mrpt::utils::TColor &c);
00143 virtual CRenderizable& setColorR_u8(const uint8_t r);
00144 virtual CRenderizable& setColorG_u8(const uint8_t g);
00145 virtual CRenderizable& setColorB_u8(const uint8_t b);
00146 virtual CRenderizable& setColorA_u8(const uint8_t a);
00147
00148
00149
00150 void render_dl() const;
00151
00152
00153
00154 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00155
00156
00157
00158
00159
00160 void getPolygons(std::vector<mrpt::math::TPolygon3D> &polys) const;
00161
00162
00163
00164
00165
00166 template<class CONTAINER>
00167 inline void insertTriangles(const CONTAINER &c) {
00168 this->insertTriangles(c.begin(),c.end());
00169 CRenderizableDisplayList::notifyChange();
00170 }
00171
00172
00173
00174
00175 inline const_iterator begin() const {
00176 return m_triangles.begin();
00177 }
00178
00179
00180
00181 inline const_iterator end() const {
00182 return m_triangles.end();
00183 }
00184
00185
00186
00187 inline const_reverse_iterator rbegin() const {
00188 return m_triangles.rbegin();
00189 }
00190
00191
00192
00193 inline const_reverse_iterator rend() const {
00194 return m_triangles.rend();
00195 }
00196 private:
00197
00198
00199 CSetOfTriangles( bool enableTransparency = false ) :
00200 m_triangles(),
00201 m_enableTransparency(enableTransparency),
00202 polygonsUpToDate(false)
00203 {
00204 }
00205
00206
00207 virtual ~CSetOfTriangles() { }
00208 };
00209
00210
00211
00212 template<class T> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const T &t) {
00213 s->insertTriangles(t.begin(),t.end());
00214 return s;
00215 }
00216
00217
00218
00219 template<> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const CSetOfTriangles::TTriangle &t) {
00220 s->insertTriangle(t);
00221 return s;
00222 }
00223
00224 }
00225
00226 }
00227
00228
00229 #endif