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
00029 #ifndef opengl_CMesh_H
00030 #define opengl_CMesh_H
00031
00032 #include <mrpt/opengl/CRenderizable.h>
00033 #include <mrpt/math/CMatrix.h>
00034 #include <mrpt/utils/CImage.h>
00035 #include <mrpt/vision/utils.h>
00036 #include <mrpt/opengl/CSetOfTriangles.h>
00037
00038 namespace mrpt
00039 {
00040 namespace opengl
00041 {
00042 class MRPTDLLIMPEXP CMesh;
00043
00044
00045 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CMesh, CRenderizable )
00046
00047
00048
00049
00050
00051 class MRPTDLLIMPEXP CMesh : public CRenderizable
00052 {
00053 DEFINE_SERIALIZABLE( CMesh )
00054 protected:
00055 mrpt::utils::CImage m_textureImage;
00056
00057 bool m_enableTransparency;
00058 bool m_colorFromZ;
00059 bool m_isWireFrame;
00060
00061 math::CMatrix Z;
00062 math::CMatrix mask;
00063 math::CMatrix U, V;
00064 mutable math::CMatrix C;
00065
00066 mrpt::vision::TColormap m_colorMap;
00067
00068 mutable bool m_modified_Z;
00069
00070 void updateColorsMatrix() const;
00071 void updateTriangles() const;
00072 void updatePolygons() const;
00073
00074 float xMin,xMax,yMin,yMax;
00075 mutable std::vector<CSetOfTriangles::TTriangle> actualMesh;
00076 mutable bool trianglesUpToDate;
00077 mutable bool polygonsUpToDate;
00078 mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolys;
00079
00080 public:
00081 void setGridLimits(float xmin,float xmax, float ymin, float ymax)
00082 {
00083 xMin=xmin; xMax = xmax;
00084 yMin=ymin; yMax = ymax;
00085 }
00086
00087 void getGridLimits(float &xmin,float &xmax, float &ymin, float &ymax) const
00088 {
00089 xmin=xMin; xmax=xMax;
00090 ymin=yMin; ymax=yMax;
00091 }
00092
00093 void enableTransparency( bool v ) { m_enableTransparency = v; }
00094 void enableWireFrame( bool v ) { m_isWireFrame = v; }
00095 void enableColorFromZ( bool v, mrpt::vision::TColormap colorMap = mrpt::vision::cmJET )
00096 {
00097 m_colorFromZ = v;
00098 m_colorMap = colorMap;
00099 }
00100
00101
00102 void setZ( const mrpt::math::CMatrixTemplateNumeric<float> &in_Z );
00103
00104
00105
00106 inline void getZ(mrpt::math::CMatrixFloat &out) const {
00107
00108 out=Z;
00109 }
00110
00111
00112
00113 inline void getMask(mrpt::math::CMatrixFloat &out) const {
00114
00115 out=mask;
00116 }
00117
00118
00119 void setMask( const mrpt::math::CMatrixTemplateNumeric<float> &in_mask );
00120
00121
00122 void setUV( const mrpt::math::CMatrixTemplateNumeric<float> &in_U, const mrpt::math::CMatrixTemplateNumeric<float> &in_V);
00123
00124 inline float getXMin() const {
00125 return xMin;
00126 }
00127 inline float getXMax() const {
00128 return xMax;
00129 }
00130 inline float getYMin() const {
00131 return yMin;
00132 }
00133 inline float getYMax() const {
00134 return yMax;
00135 }
00136 inline void setXMin(const float &nxm) {
00137 xMin=nxm;
00138 trianglesUpToDate=false;
00139 }
00140 inline void setXMax(const float &nxm) {
00141 xMax=nxm;
00142 trianglesUpToDate=false;
00143 }
00144 inline void setYMin(const float &nym) {
00145 yMin=nym;
00146 trianglesUpToDate=false;
00147 }
00148 inline void setYMax(const float &nym) {
00149 yMax=nym;
00150 trianglesUpToDate=false;
00151 }
00152 inline void getXBounds(float &min,float &max) const {
00153 min=xMin;
00154 max=xMax;
00155 }
00156 inline void getYBounds(float &min,float &max) const {
00157 min=yMin;
00158 max=yMax;
00159 }
00160 inline void setXBounds(const float &min,const float &max) {
00161 xMin=min;
00162 xMax=max;
00163 trianglesUpToDate=false;
00164 }
00165 inline void setYBounds(const float &min,const float &max) {
00166 yMin=min;
00167 yMax=max;
00168 trianglesUpToDate=false;
00169 }
00170
00171
00172
00173 static CMeshPtr Create(bool enableTransparency, float xMin = 0.0f, float xMax = 0.0f, float yMin = 0.0f, float yMax = 0.0f )
00174 {
00175 return CMeshPtr( new CMesh( enableTransparency, xMin ,xMax , yMin ,yMax ) );
00176 }
00177
00178
00179
00180 void render() const;
00181
00182
00183
00184 void assignImage(
00185 const utils::CImage& img );
00186
00187
00188
00189 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00190
00191 private:
00192
00193
00194 CMesh( bool enableTransparency = false, float xMin = 0.0f, float xMax = 0.0f, float yMin = 0.0f, float yMax = 0.0f ) :
00195 m_textureImage(0,0),
00196 m_enableTransparency(enableTransparency),
00197 m_colorFromZ(false),
00198 m_isWireFrame(false),
00199 Z(0,0), mask(0,0), U(0,0), V(0,0), C(0,0),
00200 m_colorMap( mrpt::vision::cmJET ),
00201 m_modified_Z(true),
00202 xMin(xMin), xMax(xMax), yMin(yMin), yMax(yMax),
00203 trianglesUpToDate(false)
00204 {
00205 m_color_A = 1.0f;
00206 m_color_R = 0.0f;
00207 m_color_G = 0.0f;
00208 m_color_B = 0.6f;
00209 }
00210
00211 virtual ~CMesh() { }
00212
00213 };
00214
00215 }
00216
00217 }
00218
00219 #endif