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 class OPENGL_IMPEXP CSetOfTriangles : public CRenderizableDisplayList
00048 {
00049 DEFINE_SERIALIZABLE( CSetOfTriangles )
00050 public:
00051
00052
00053
00054 struct OPENGL_IMPEXP TTriangle
00055 {
00056 inline TTriangle() { }
00057 inline TTriangle(const mrpt::math::TPolygon3D &p) {
00058 ASSERT_(p.size()==3)
00059 for (size_t i=0;i<3;i++) {
00060 x[i]=p[i].x; y[i]=p[i].y; z[i]=p[i].z; r[i]=g[i]=b[i]=a[i]=1; }
00061 }
00062 float x[3],y[3],z[3];
00063 float r[3],g[3],b[3],a[3];
00064 };
00065
00066
00067
00068 typedef std::vector<TTriangle>::const_iterator const_iterator;
00069
00070
00071
00072 typedef std::vector<TTriangle>::const_reverse_iterator const_reverse_iterator;
00073 protected:
00074
00075
00076
00077
00078 std::vector<TTriangle> m_triangles;
00079
00080
00081
00082 bool m_enableTransparency;
00083
00084
00085
00086 mutable bool polygonsUpToDate;
00087
00088
00089
00090 mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolygons;
00091 public:
00092
00093
00094
00095 void updatePolygons() const;
00096
00097
00098
00099 inline void clearTriangles() { m_triangles.clear();polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
00100
00101
00102
00103 inline size_t getTrianglesCount() const { return m_triangles.size(); }
00104
00105
00106
00107 inline void getTriangle(size_t idx, TTriangle &t) const { ASSERT_(idx<m_triangles.size()); t=m_triangles[idx]; }
00108
00109
00110
00111 inline void insertTriangle( const TTriangle &t ) { m_triangles.push_back(t);polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
00112
00113
00114
00115
00116 template<class InputIterator> inline void insertTriangles(const InputIterator &begin,const InputIterator &end) {
00117 m_triangles.insert(m_triangles.end(),begin,end);
00118 polygonsUpToDate=false;
00119 CRenderizableDisplayList::notifyChange();
00120 }
00121
00122
00123
00124 inline void insertTriangles(const CSetOfTrianglesPtr &p) {
00125 reserve(m_triangles.size()+p->m_triangles.size());
00126 m_triangles.insert(m_triangles.end(),p->m_triangles.begin(),p->m_triangles.end());
00127 polygonsUpToDate=false;
00128 CRenderizableDisplayList::notifyChange();
00129 }
00130
00131
00132
00133 inline void reserve(size_t t) {
00134 m_triangles.reserve(t);
00135 CRenderizableDisplayList::notifyChange();
00136 }
00137
00138
00139 inline void enableTransparency( bool v ) { m_enableTransparency = v; CRenderizableDisplayList::notifyChange(); }
00140
00141 virtual CRenderizable& setColor(const mrpt::utils::TColorf &c);
00142 virtual CRenderizable& setColor(double r,double g,double b,double a=1);
00143 virtual CRenderizable& setColorR(const double r);
00144 virtual CRenderizable& setColorG(const double g);
00145 virtual CRenderizable& setColorB(const double b);
00146 virtual CRenderizable& setColorA(const double 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