20 #include <Eigen/Dense> 33 #if MRPT_HAS_ASIAN_FONTS 48 map<string, std::vector<uint8_t>>
62 #define SAVE_COMPRESSED(ARR) \ 64 list_registered_fonts[#ARR].resize(sizeof(mrpt_font_##ARR)); \ 66 &list_registered_fonts[#ARR][0], mrpt_font_##ARR, \ 67 sizeof(mrpt_font_##ARR)); \ 68 cout << #ARR << " -> " << sizeof(mrpt_font_##ARR) << endl; \ 69 CFileGZOutputStream f( \ 70 string("mrpt_font_") + string(#ARR) + string(".gz")); \ 71 f.WriteBuffer(mrpt_font_##ARR, sizeof(mrpt_font_##ARR)); \ 83 #if MRPT_HAS_ASIAN_FONTS 89 #if 1 // Normal operation: Load fonts and uncompress them: 91 #define LOAD_FONT(FONTNAME) \ 93 std::vector<uint8_t> tmpBuf(sizeof(mrpt_font_gz_##FONTNAME)); \ 95 &tmpBuf[0], mrpt_font_gz_##FONTNAME, \ 96 sizeof(mrpt_font_gz_##FONTNAME)); \ 97 mrpt::io::zip::decompress_gz_data_block( \ 98 tmpBuf, list_registered_fonts[#FONTNAME]); \ 108 #if MRPT_HAS_ASIAN_FONTS 139 auto Ax = (float)(x1 - x0);
140 auto Ay = (float)(y1 - y0);
143 if (Ax == 0 && Ay == 0)
return;
144 if (x0 < 0 && x1 < 0)
return;
145 if (y0 < 0 && y1 < 0)
return;
146 if (x0 >= (
int)getWidth() && x1 >= (int)getWidth())
return;
150 int i, N = (int)ceil(dist);
158 for (i = 0; i < N; i++)
162 setPixel((
int)
x, (
int)
y,
color);
173 int w_min = (int)-ceil(((
float)
width) / 2);
174 int w_max = (int)floor(((
float)
width) / 2);
176 for (
int w = w_min;
w <= w_max;
w++)
178 line(x0 -
w, y0 -
w, x1 +
w, y0 -
w,
color);
179 line(x1 +
w, y0 -
w, x1 +
w, y1 +
w,
color);
180 line(x1 +
w, y1 +
w, x0 -
w, y1 +
w,
color);
181 line(x0 -
w, y1 +
w, x0 -
w, y0 -
w,
color);
216 int x_min = max(x0, 0);
217 int x_max =
min(x1, (
int)getWidth() - 1);
218 int y_min = max(y0, 0);
221 for (
int y = y_min;
y <= y_max;
y++)
222 for (
int x = x_min;
x <= x_max;
x++) setPixel(
x,
y,
color);
237 cerr <<
"[CCanvas::selectTextFont] Warning: Unknown font: " << fontName
243 m_selectedFontBitmaps =
244 reinterpret_cast<const uint32_t*
>(&it->second[0]);
245 m_selectedFont = fontName;
257 int img_lx =
img.getWidth();
258 int img_ly =
img.getHeight();
262 for (
int xx = 0; xx < img_lx; xx++)
263 for (
int yy = 0; yy < img_ly; yy++)
265 auto ptr =
img(xx, yy);
266 const int p = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
267 setPixel(
x + xx,
y + yy,
p);
274 for (
int xx = 0; xx < img_lx; xx++)
275 for (
int yy = 0; yy < img_ly; yy++)
277 c = *((
unsigned char*)
img(xx, yy));
278 col =
c | (
c << 8) | (
c << 16);
279 setPixel(
x + xx,
y + yy, col);
343 if (radius < 0) radius = -radius;
353 nSegments = int(
M_2PI * radius);
356 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
357 double ang, Aa =
M_2PI / (nSegments - 1);
360 for (i = 0, ang = 0; i < nSegments; i++, ang += Aa)
362 x2 =
round(
x + radius * cos(ang));
363 y2 =
round(
y + radius * sin(ang));
365 if (i > 0) line(x1, y1, x2, y2,
color,
width);
380 if (!m_selectedFontBitmaps)
381 this->selectTextFont(
"9x15");
384 bool y_axis_reversed =
false;
385 auto* im_image =
dynamic_cast<CImage*
>(
this);
389 std::vector<uint16_t> uniStr;
396 uint32_t char_w = m_selectedFontBitmaps[0];
397 uint32_t char_h = m_selectedFontBitmaps[1];
399 for (
unsigned short unichar : uniStr)
402 const uint32_t* table_ptr = m_selectedFontBitmaps + 2;
403 uint32_t charset_ini = table_ptr[0];
404 uint32_t charset_end = table_ptr[1];
409 if (unichar <= charset_end && unichar >= charset_ini)
412 unsigned pyy = y_axis_reversed ? (py + char_h - 1) : py;
416 table_ptr + 2 + char_h * (unichar - charset_ini);
418 for (
unsigned y = 0;
y < char_h;
419 y++, pyy += y_axis_reversed ? -1 : 1)
423 for (
unsigned x = 0;
x < char_w;
x++, pxx++)
424 if (
row & (1 <<
x)) setPixel(pxx, pyy,
color);
436 uint32_t n_chars = charset_end - charset_ini + 1;
437 table_ptr += 2 + n_chars * char_h;
440 charset_ini = table_ptr[0];
441 charset_end = table_ptr[1];
452 const double mean_y,
double confIntervalStds,
456 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
459 std::vector<double> eVals;
463 cov2D.
eig(eigVec, eVals);
472 for (i = 0, ang = 0; i < nEllipsePoints;
473 i++, ang += (
M_2PI / (nEllipsePoints - 1)))
475 double ccos = cos(ang);
476 double ssin = sin(ang);
479 mean_x + confIntervalStds * (ccos * M(0, 0) + ssin * M(1, 0)));
481 mean_y + confIntervalStds * (ccos * M(0, 1) + ssin * M(1, 1)));
483 if (i > 0) line(x1, y1, x2, y2,
color,
width);
491 << cov2D << std::endl;);
bool eig(CMatrixFixed< T, ROWS, COLS > &eVecs, std::vector< T > &eVals, bool sorted=true) const
Computes the eigenvectors and eigenvalues for a square, general matrix.
virtual void drawCircle(int x, int y, int radius, const mrpt::img::TColor &color=mrpt::img::TColor(255, 255, 255), unsigned int width=1)
Draws a circle of a given radius.
A compile-time fixed-size numeric matrix container.
TPenStyle
Definition of pen styles.
virtual void line(int x0, int y0, int x1, int y1, const mrpt::img::TColor color, unsigned int width=1, TPenStyle penStyle=psSolid)
Draws a line.
#define THROW_EXCEPTION(msg)
GLenum GLenum GLenum GLenum GLenum scale
void decodeUTF8(const std::string &strUTF8, std::vector< uint16_t > &out_uniStr)
Decodes a UTF-8 string into an UNICODE string.
#define MRPT_END_WITH_CLEAN_UP(stuff)
void triangle(int x0, int y0, int size, const mrpt::img::TColor color, bool inferior=true, unsigned int width=1)
Draws a triangle.
GLubyte GLubyte GLubyte GLubyte w
T square(const T x)
Inline function for the square of a number.
#define LOAD_FONT(FONTNAME)
#define ASSERT_(f)
Defines an assertion mechanism.
virtual void selectTextFont(const std::string &fontName)
Select the current font used when drawing text.
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
Draws a filled rectangle.
void rectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color, unsigned int width=1)
Draws a rectangle (an empty rectangle, without filling)
GLsizei const GLchar ** string
void ellipseGaussian(const mrpt::math::CMatrixFixed< double, 2, 2 > &cov2D, const double mean_x, const double mean_y, double confIntervalStds=2, const mrpt::img::TColor &color=mrpt::img::TColor(255, 255, 255), unsigned int width=1, int nEllipsePoints=20)
Draws an ellipse representing a given confidence interval of a 2D Gaussian distribution.
map< string, std::vector< uint8_t > > list_registered_fonts
void drawMark(int x0, int y0, const mrpt::img::TColor color, char type, int size=5, unsigned int width=1)
Draw a mark.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool isOriginTopLeft() const
Returns true (as of MRPT v2.0.0, it's fixed)
GLenum GLenum GLvoid * row
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
virtual void textOut(int x0, int y0, const std::string &str, const mrpt::img::TColor color)
Renders 2D text using bitmap fonts.
virtual void drawImage(int x, int y, const mrpt::img::CImage &img)
Draws an image as a bitmap at a given position.
double getHeight(const TPolygon3D &p, const TPoint3D &c)
unsigned __int32 uint32_t
GLuint GLuint GLsizei GLenum type
void setDiagonal(const std::size_t N, const T value)
Resize to NxN, set all entries to zero, except the main diagonal which is set to value ...
A class for storing images as grayscale or RGB bitmaps.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
int round(const T value)
Returns the closer integer (int) to x.