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 127 [[maybe_unused]]
unsigned int width, [[maybe_unused]]
TPenStyle penStyle)
131 auto Ax = (float)(x1 - x0);
132 auto Ay = (float)(y1 - y0);
135 if (Ax == 0 && Ay == 0)
return;
136 if (x0 < 0 && x1 < 0)
return;
137 if (y0 < 0 && y1 < 0)
return;
138 if (x0 >= (
int)getWidth() && x1 >= (int)getWidth())
return;
142 int i, N = (int)ceil(dist);
150 for (i = 0; i < N; i++)
154 setPixel((
int)x, (
int)y, color);
165 int w_min = (int)-ceil(((
float)width) / 2);
166 int w_max = (int)floor(((
float)width) / 2);
168 for (
int w = w_min; w <= w_max; w++)
170 line(x0 - w, y0 - w, x1 + w, y0 - w, color);
171 line(x1 + w, y0 - w, x1 + w, y1 + w, color);
172 line(x1 + w, y1 + w, x0 - w, y1 + w, color);
173 line(x0 - w, y1 + w, x0 - w, y0 - w, color);
189 line(x0, y0 +
size, x0 + ts, y0 - tc, color, width);
190 line(x0, y0 +
size, x0 - ts, y0 - tc, color, width);
191 line(x0 + ts, y0 - tc, x0 - ts, y0 - tc, color, width);
195 line(x0, y0 -
size, x0 + ts, y0 + tc, color, width);
196 line(x0, y0 -
size, x0 - ts, y0 + tc, color, width);
197 line(x0 + ts, y0 + tc, x0 - ts, y0 + tc, color, width);
208 int x_min = max(x0, 0);
209 int x_max = min(x1, (
int)getWidth() - 1);
210 int y_min = max(y0, 0);
211 int y_max = min(y1, (
int)
getHeight() - 1);
213 for (
int y = y_min; y <= y_max; y++)
214 for (
int x = x_min; x <= x_max; x++) setPixel(x, y, color);
229 cerr <<
"[CCanvas::selectTextFont] Warning: Unknown font: " << fontName
236 m_selectedFontBitmaps =
reinterpret_cast<const uint32_t*
>(&fd.
data[0]);
237 m_selectedFont = fontName;
239 #if MRPT_IS_BIG_ENDIAN 244 uint32_t* ptr =
reinterpret_cast<uint32_t*
>(&fd.
data[0]);
245 for (
size_t i = 0; i < fd.
data.size() /
sizeof(uint32_t); i++)
265 for (
int xx = 0; xx < img_lx; xx++)
266 for (
int yy = 0; yy < img_ly; yy++)
268 auto ptr = img(xx, yy);
269 const int p = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
270 setPixel(x + xx, y + yy, p);
277 for (
int xx = 0; xx < img_lx; xx++)
278 for (
int yy = 0; yy < img_ly; yy++)
280 c = *((
unsigned char*)img(xx, yy));
281 col = c | (c << 8) | (c << 16);
282 setPixel(x + xx, y + yy, col);
293 [[maybe_unused]]
int x, [[maybe_unused]]
int y,
295 [[maybe_unused]]
float rotation, [[maybe_unused]]
float scale)
311 line(x0 -
size, y0, x0 +
size, y0, color, width);
312 line(x0, y0 -
size, x0, y0 +
size, color, width);
325 line(x0 -
size, y0, x0 - 2, y0, color, width);
326 line(x0 + 2, y0, x0 +
size, y0, color, width);
327 line(x0, y0 -
size, x0, y0 - 2, color, width);
328 line(x0, y0 + 2, x0, y0 +
size, color, width);
342 if (radius < 0) radius = -radius;
352 nSegments = int(
M_2PI * radius);
355 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
356 double ang, Aa =
M_2PI / (nSegments - 1);
359 for (i = 0, ang = 0; i < nSegments; i++, ang += Aa)
361 x2 =
round(x + radius * cos(ang));
362 y2 =
round(y + radius * sin(ang));
364 if (i > 0) line(x1, y1, x2, y2, color, width);
379 if (!m_selectedFontBitmaps)
380 this->selectTextFont(
"9x15");
383 bool y_axis_reversed =
false;
384 auto* im_image =
dynamic_cast<CImage*
>(
this);
388 std::vector<uint16_t> uniStr;
395 int char_w = m_selectedFontBitmaps[0];
396 int char_h = m_selectedFontBitmaps[1];
398 for (
unsigned short unichar : uniStr)
401 const uint32_t* table_ptr = m_selectedFontBitmaps + 2;
402 uint32_t charset_ini = table_ptr[0];
403 uint32_t charset_end = table_ptr[1];
408 if (unichar <= charset_end && unichar >= charset_ini)
411 int pyy = y_axis_reversed ? (py + char_h - 1) : py;
413 const uint32_t* char_bitmap =
414 table_ptr + 2 + char_h * (unichar - charset_ini);
416 for (
int y = 0; y < char_h;
417 y++, pyy += y_axis_reversed ? -1 : 1)
423 memcpy(&row, char_bitmap,
sizeof(row));
425 for (
int x = 0, pxx = px; x < char_w; x++, pxx++)
426 if (!!(row & (1 << x))) setPixel(pxx, pyy, color);
438 uint32_t n_chars = charset_end - charset_ini + 1;
439 table_ptr += 2 + n_chars * char_h;
442 charset_ini = table_ptr[0];
443 charset_end = table_ptr[1];
454 const double mean_y,
double confIntervalStds,
458 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
461 std::vector<double> eVals;
465 cov2D.
eig(eigVec, eVals);
474 for (i = 0, ang = 0; i < nEllipsePoints;
475 i++, ang += (
M_2PI / (nEllipsePoints - 1)))
477 double ccos = cos(ang);
478 double ssin = sin(ang);
481 mean_x + confIntervalStds * (ccos * M(0, 0) + ssin * M(1, 0)));
483 mean_y + confIntervalStds * (ccos * M(0, 1) + ssin * M(1, 1)));
485 if (i > 0) line(x1, y1, x2, y2, color, width);
493 << 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".
int round(const T value)
Returns the closer integer (int) to x.