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