20 #include <Eigen/Dense> 34 #if MRPT_HAS_ASIAN_FONTS 51 bool prepared_to_big_endian =
false;
66 #define SAVE_COMPRESSED(ARR) \ 68 list_registered_fonts[#ARR].resize(sizeof(mrpt_font_##ARR)); \ 70 &list_registered_fonts[#ARR][0], mrpt_font_##ARR, \ 71 sizeof(mrpt_font_##ARR)); \ 72 cout << #ARR << " -> " << sizeof(mrpt_font_##ARR) << endl; \ 73 CFileGZOutputStream f( \ 74 string("mrpt_font_") + string(#ARR) + string(".gz")); \ 75 f.WriteBuffer(mrpt_font_##ARR, sizeof(mrpt_font_##ARR)); \ 87 #if MRPT_HAS_ASIAN_FONTS 93 #if 1 // Normal operation: Load fonts and uncompress them: 95 #define LOAD_FONT(FONTNAME) \ 97 std::vector<uint8_t> tmpBuf(sizeof(mrpt_font_gz_##FONTNAME)); \ 99 &tmpBuf[0], mrpt_font_gz_##FONTNAME, \ 100 sizeof(mrpt_font_gz_##FONTNAME)); \ 101 mrpt::io::zip::decompress_gz_data_block( \ 102 tmpBuf, list_registered_fonts[#FONTNAME].data); \ 112 #if MRPT_HAS_ASIAN_FONTS 143 auto Ax = (float)(x1 - x0);
144 auto Ay = (float)(y1 - y0);
147 if (Ax == 0 && Ay == 0)
return;
148 if (x0 < 0 && x1 < 0)
return;
149 if (y0 < 0 && y1 < 0)
return;
150 if (x0 >= (
int)getWidth() && x1 >= (int)getWidth())
return;
154 int i, N = (int)ceil(dist);
162 for (i = 0; i < N; i++)
166 setPixel((
int)x, (
int)y, color);
177 int w_min = (int)-ceil(((
float)width) / 2);
178 int w_max = (int)floor(((
float)width) / 2);
180 for (
int w = w_min; w <= w_max; w++)
182 line(x0 - w, y0 - w, x1 + w, y0 - w, color);
183 line(x1 + w, y0 - w, x1 + w, y1 + w, color);
184 line(x1 + w, y1 + w, x0 - w, y1 + w, color);
185 line(x0 - w, y1 + w, x0 - w, y0 - w, color);
201 line(x0, y0 +
size, x0 + ts, y0 - tc, color, width);
202 line(x0, y0 +
size, x0 - ts, y0 - tc, color, width);
203 line(x0 + ts, y0 - tc, x0 - ts, y0 - tc, color, width);
207 line(x0, y0 -
size, x0 + ts, y0 + tc, color, width);
208 line(x0, y0 -
size, x0 - ts, y0 + tc, color, width);
209 line(x0 + ts, y0 + tc, x0 - ts, y0 + tc, color, width);
220 int x_min = max(x0, 0);
221 int x_max = min(x1, (
int)getWidth() - 1);
222 int y_min = max(y0, 0);
223 int y_max = min(y1, (
int)
getHeight() - 1);
225 for (
int y = y_min; y <= y_max; y++)
226 for (
int x = x_min; x <= x_max; x++) setPixel(x, y, color);
241 cerr <<
"[CCanvas::selectTextFont] Warning: Unknown font: " << fontName
248 m_selectedFontBitmaps =
reinterpret_cast<const uint32_t*
>(&fd.
data[0]);
249 m_selectedFont = fontName;
251 #if MRPT_IS_BIG_ENDIAN 256 uint32_t* ptr =
reinterpret_cast<uint32_t*
>(&fd.
data[0]);
257 for (
size_t i = 0; i < fd.
data.size() /
sizeof(uint32_t); i++)
277 for (
int xx = 0; xx < img_lx; xx++)
278 for (
int yy = 0; yy < img_ly; yy++)
280 auto ptr = img(xx, yy);
281 const int p = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
282 setPixel(x + xx, y + yy, p);
289 for (
int xx = 0; xx < img_lx; xx++)
290 for (
int yy = 0; yy < img_ly; yy++)
292 c = *((
unsigned char*)img(xx, yy));
293 col = c | (c << 8) | (c << 16);
294 setPixel(x + xx, y + yy, col);
327 line(x0 -
size, y0, x0 +
size, y0, color, width);
328 line(x0, y0 -
size, x0, y0 +
size, color, width);
341 line(x0 -
size, y0, x0 - 2, y0, color, width);
342 line(x0 + 2, y0, x0 +
size, y0, color, width);
343 line(x0, y0 -
size, x0, y0 - 2, color, width);
344 line(x0, y0 + 2, x0, y0 +
size, color, width);
358 if (radius < 0) radius = -radius;
368 nSegments = int(
M_2PI * radius);
371 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
372 double ang, Aa =
M_2PI / (nSegments - 1);
375 for (i = 0, ang = 0; i < nSegments; i++, ang += Aa)
377 x2 =
round(x + radius * cos(ang));
378 y2 =
round(y + radius * sin(ang));
380 if (i > 0) line(x1, y1, x2, y2, color, width);
395 if (!m_selectedFontBitmaps)
396 this->selectTextFont(
"9x15");
399 bool y_axis_reversed =
false;
400 auto* im_image =
dynamic_cast<CImage*
>(
this);
404 std::vector<uint16_t> uniStr;
411 int char_w = m_selectedFontBitmaps[0];
412 int char_h = m_selectedFontBitmaps[1];
414 for (
unsigned short unichar : uniStr)
417 const uint32_t* table_ptr = m_selectedFontBitmaps + 2;
418 uint32_t charset_ini = table_ptr[0];
419 uint32_t charset_end = table_ptr[1];
424 if (unichar <= charset_end && unichar >= charset_ini)
427 int pyy = y_axis_reversed ? (py + char_h - 1) : py;
429 const uint32_t* char_bitmap =
430 table_ptr + 2 + char_h * (unichar - charset_ini);
432 for (
int y = 0; y < char_h;
433 y++, pyy += y_axis_reversed ? -1 : 1)
439 memcpy(&row, char_bitmap,
sizeof(row));
441 for (
int x = 0, pxx = px; x < char_w; x++, pxx++)
442 if (!!(row & (1 << x))) setPixel(pxx, pyy, color);
454 uint32_t n_chars = charset_end - charset_ini + 1;
455 table_ptr += 2 + n_chars * char_h;
458 charset_ini = table_ptr[0];
459 charset_end = table_ptr[1];
470 const double mean_y,
double confIntervalStds,
474 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
477 std::vector<double> eVals;
481 cov2D.
eig(eigVec, eVals);
490 for (i = 0, ang = 0; i < nEllipsePoints;
491 i++, ang += (
M_2PI / (nEllipsePoints - 1)))
493 double ccos = cos(ang);
494 double ssin = sin(ang);
497 mean_x + confIntervalStds * (ccos * M(0, 0) + ssin * M(1, 0)));
499 mean_y + confIntervalStds * (ccos * M(0, 1) + ssin * M(1, 1)));
501 if (i > 0) line(x1, y1, x2, y2, color, width);
509 << 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)
size_t size(const MATRIXLIKE &m, const int dim)
void decodeUTF8(const std::string &strUTF8, std::vector< uint16_t > &out_uniStr)
Decodes a UTF-8 string into an UNICODE string.
size_t getHeight() const override
Returns the height of the image in pixels.
#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.
void reverseBytesInPlace(bool &v_in_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
#define LOAD_FONT(FONTNAME)
#define ASSERT_(f)
Defines an assertion mechanism.
size_t getWidth() const override
Returns the width of the image in pixels.
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)
map< string, FontData > list_registered_fonts
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.
std::vector< uint8_t > data
void drawMark(int x0, int y0, const mrpt::img::TColor color, char type, int size=5, unsigned int width=1)
Draw a mark.
return_t square(const num_t x)
Inline function for the square of a number.
PixelDepth getPixelDepth() const
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
bool isOriginTopLeft() const
Returns true (as of MRPT v2.0.0, it's fixed)
bool prepared_to_big_endian
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)
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.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
#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.