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 CMRPTCanvas_H
00029 #define CMRPTCanvas_H
00030
00031 #include <mrpt/utils/utils_defs.h>
00032 #include <mrpt/math/CMatrixTemplateNumeric.h>
00033
00034 namespace mrpt
00035 {
00036 namespace math
00037 {
00038 class CMatrix;
00039 class CMatrixD;
00040 }
00041 namespace utils
00042 {
00043 class CMRPTImage;
00044 class CMRPTImageFloat;
00045
00063 class MRPTDLLIMPEXP CMRPTCanvas
00064 {
00065 protected:
00066 std::string m_selectedFont;
00067
00068 const uint32_t *m_selectedFontBitmaps;
00069
00070 public:
00071
00072 CMRPTCanvas();
00073
00076 enum TPenStyle
00077 {
00078 psSolid = 0,
00079 psDash,
00080 psDot,
00081 psDashDot,
00082 psDashDotDot
00083 };
00084
00087 virtual ~CMRPTCanvas()
00088 {
00089 }
00090
00098 virtual void setPixel( int x, int y, size_t color) =0;
00099
00102 virtual size_t getWidth() const = 0;
00103
00106 virtual size_t getHeight() const = 0;
00107
00117 virtual void line(
00118 int x0,
00119 int y0,
00120 int x1,
00121 int y1,
00122 unsigned int color,
00123 unsigned int width = 1,
00124 TPenStyle penStyle = psSolid);
00125
00135 void rectangle(
00136 int x0,
00137 int y0,
00138 int x1,
00139 int y1,
00140 unsigned int color,
00141 unsigned int width = 1 );
00142
00143
00153 void triangle(
00154 int x0,
00155 int y0,
00156 int size,
00157 unsigned int color,
00158 bool inferior = true,
00159 unsigned int width = 1 );
00160
00161
00171 virtual void filledRectangle(
00172 int x0,
00173 int y0,
00174 int x1,
00175 int y1,
00176 unsigned int color
00177 );
00178
00187 virtual void textOut(
00188 int x0,
00189 int y0,
00190 const std::string &str,
00191 unsigned int color
00192 );
00193
00199 virtual void selectTextFont( const std::string &fontName );
00200
00207 virtual void drawImage(
00208 int x,
00209 int y,
00210 const utils::CMRPTImage &img );
00211
00220 void cross (int x0,int y0, unsigned int color,char type, unsigned int size=5, unsigned int width = 1);
00221
00230 virtual void drawImage(
00231 int x,
00232 int y,
00233 const utils::CMRPTImage &img,
00234 float rotation,
00235 float scale );
00236
00243 void drawImage(
00244 int x,
00245 int y,
00246 const utils::CMRPTImageFloat &img );
00247
00256 void drawImage(
00257 int x,
00258 int y,
00259 const utils::CMRPTImageFloat &img,
00260 float rotation,
00261 float scale );
00262
00270 void drawCircle(
00271 int x,
00272 int y,
00273 int radius,
00274 unsigned int color = 0xFFFFFF,
00275 unsigned int width = 1 );
00276
00287 template <class T>
00288 void ellipseGaussian(
00289 math::CMatrixTemplateNumeric<T> *cov2D,
00290 T mean_x,
00291 T mean_y,
00292 float confIntervalStds = 2,
00293 unsigned int color = 0xFFFFFF,
00294 unsigned int width = 1,
00295 int nEllipsePoints = 20
00296 )
00297 {
00298 MRPT_TRY_START;
00299 int x1=0,y1=0,x2=0,y2=0;
00300 double ang;
00301 math::CMatrixTemplateNumeric<T> eigVal,eigVec;
00302 int i;
00303
00304
00305 cov2D->eigenVectors(eigVec,eigVal);
00306
00307 eigVal.Sqrt();
00308 math::CMatrixTemplateNumeric<T> M( eigVal * (~eigVec) );
00309
00310
00311 for (i=0,ang=0;i<nEllipsePoints;i++,ang+= (M_2PI/(nEllipsePoints-1)))
00312 {
00313 double ccos = cos(ang);
00314 double ssin = sin(ang);
00315
00316 x2 = round( mean_x + confIntervalStds * (ccos * M(0,0) + ssin * M(1,0)) );
00317 y2 = round( mean_y + confIntervalStds * (ccos * M(0,1) + ssin * M(1,1)) );
00318
00319 if (i>0)
00320 line( x1, y1,x2, y2,color,width );
00321
00322 x1 = x2;
00323 y1 = y2;
00324 }
00325
00326 MRPT_TRY_END_WITH_CLEAN_UP( \
00327 std::cout << "Covariance matrix leading to error is:" << std::endl << *cov2D << std::endl; \
00328 );
00329 }
00330
00331 };
00332
00333 }
00334
00335 }
00336
00337 #endif