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/CRenderizable.h>
00032 #include <mrpt/math/geometry.h>
00033
00034 namespace mrpt
00035 {
00036 namespace opengl
00037 {
00038 class MRPTDLLIMPEXP CSetOfTriangles;
00039
00040
00041 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CSetOfTriangles, CRenderizable )
00042
00043
00044
00045
00046
00047 class MRPTDLLIMPEXP CSetOfTriangles : public CRenderizable
00048 {
00049 DEFINE_SERIALIZABLE( CSetOfTriangles )
00050 public:
00051
00052
00053
00054 struct MRPTDLLIMPEXP TTriangle
00055 {
00056 float x[3],y[3],z[3];
00057 float r[3],g[3],b[3],a[3];
00058 };
00059
00060
00061
00062 typedef std::vector<TTriangle>::const_iterator const_iterator;
00063
00064
00065
00066 typedef std::vector<TTriangle>::const_reverse_iterator const_reverse_iterator;
00067 protected:
00068
00069
00070
00071
00072 std::vector<TTriangle> m_triangles;
00073
00074
00075
00076 bool m_enableTransparency;
00077
00078
00079
00080 mutable bool polygonsUpToDate;
00081
00082
00083
00084 mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolygons;
00085 public:
00086
00087
00088
00089 void updatePolygons() const;
00090
00091
00092
00093 inline void clearTriangles() { m_triangles.clear();polygonsUpToDate=false; }
00094
00095
00096
00097 inline size_t getTrianglesCount() const { return m_triangles.size(); }
00098
00099
00100
00101 inline void getTriangle(size_t idx, TTriangle &t) const { ASSERT_(idx<m_triangles.size()); t=m_triangles[idx]; }
00102
00103
00104
00105 inline void insertTriangle( const TTriangle &t ) { m_triangles.push_back(t);polygonsUpToDate=false; }
00106
00107
00108
00109
00110 template<class InputIterator> inline void insertTriangles(const InputIterator &begin,const InputIterator &end) {
00111 m_triangles.insert(m_triangles.end(),begin,end);
00112 polygonsUpToDate=false;
00113 }
00114
00115
00116
00117 inline void insertTriangles(const CSetOfTrianglesPtr &p) {
00118 reserve(m_triangles.size()+p->m_triangles.size());
00119 m_triangles.insert(m_triangles.end(),p->m_triangles.begin(),p->m_triangles.end());
00120 polygonsUpToDate=false;
00121 }
00122
00123
00124
00125 inline void reserve(size_t t) {
00126 m_triangles.reserve(t);
00127 }
00128
00129
00130
00131
00132 inline void enableTransparency( bool v ) { m_enableTransparency = v; }
00133
00134
00135
00136 virtual void setColor(double R,double G,double B,double A);
00137
00138
00139
00140 virtual void setColor(const mrpt::utils::TColorf &c);
00141
00142
00143
00144 virtual void setColorR(const double r);
00145
00146
00147
00148 virtual void setColorG(const double g);
00149
00150
00151
00152 virtual void setColorB(const double b);
00153
00154
00155
00156 virtual void setColorA(const double a);
00157
00158
00159
00160 void render() const;
00161
00162
00163 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00164
00165
00166
00167
00168 void getPolygons(std::vector<mrpt::math::TPolygon3D> &polys) const;
00169
00170
00171
00172 inline const_iterator begin() const {
00173 return m_triangles.begin();
00174 }
00175
00176
00177
00178 inline const_iterator end() const {
00179 return m_triangles.end();
00180 }
00181
00182
00183
00184 inline const_reverse_iterator rbegin() const {
00185 return m_triangles.rbegin();
00186 }
00187
00188
00189
00190 inline const_reverse_iterator rend() const {
00191 return m_triangles.rend();
00192 }
00193 private:
00194
00195
00196 CSetOfTriangles( bool enableTransparency = false ) :
00197 m_triangles(),
00198 m_enableTransparency(enableTransparency),
00199 polygonsUpToDate(false)
00200 {
00201 }
00202
00203
00204 virtual ~CSetOfTriangles() { }
00205 };
00206
00207
00208
00209 template<class T> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const T &t) {
00210 s->insertTriangles(t.begin(),t.end());
00211 return s;
00212 }
00213
00214
00215
00216 template<> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const CSetOfTriangles::TTriangle &t) {
00217 s->insertTriangle(t);
00218 return s;
00219 }
00220
00221 }
00222
00223 }
00224
00225
00226 #endif