MRPT  2.0.4
List of all members | Public Types | Public Member Functions | Protected Attributes
mrpt::img::CCanvas Class Referenceabstract

Detailed Description

This virtual class defines the interface of any object accepting drawing primitives on it.

A number of text fonts can be selected with CCanvas::selectTextFont(). These are the implemented font names:

For an example of each font check the corresponding wiki page.

See also
CImage

Definition at line 41 of file CCanvas.h.

#include <mrpt/img/CCanvas.h>

Inheritance diagram for mrpt::img::CCanvas:

Public Types

enum  TPenStyle {
  psSolid = 0, psDash, psDot, psDashDot,
  psDashDotDot
}
 Definition of pen styles. More...
 

Public Member Functions

 CCanvas ()=default
 
virtual ~CCanvas ()=default
 
virtual void setPixel (int x, int y, size_t color)=0
 Changes the value of the pixel (x,y). More...
 
virtual size_t getWidth () const =0
 Returns the width of the image in pixels. More...
 
virtual size_t getHeight () const =0
 Returns the height of the image in pixels. More...
 
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. More...
 
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) More...
 
void triangle (int x0, int y0, int size, const mrpt::img::TColor color, bool inferior=true, unsigned int width=1)
 Draws a triangle. More...
 
virtual void filledRectangle (int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
 Draws a filled rectangle. More...
 
virtual void textOut (int x0, int y0, const std::string &str, const mrpt::img::TColor color)
 Renders 2D text using bitmap fonts. More...
 
virtual void selectTextFont (const std::string &fontName)
 Select the current font used when drawing text. More...
 
virtual void drawImage (int x, int y, const mrpt::img::CImage &img)
 Draws an image as a bitmap at a given position. More...
 
void drawMark (int x0, int y0, const mrpt::img::TColor color, char type, int size=5, unsigned int width=1)
 Draw a mark. More...
 
virtual void drawImage (int x, int y, const mrpt::img::CImage &img, float rotation, float scale)
 Draws an image as a bitmap at a given position, with some custom scale and rotation changes. More...
 
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. More...
 
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. More...
 
template<class FEATURELIST >
void drawFeaturesSimple (const FEATURELIST &list, const TColor &color=TColor::red(), const int cross_size=5)
 Draws a set of marks onto the image, given a generic container of entities having just "x" and "y" fields. More...
 
template<class FEATURELIST >
void drawFeatures (const FEATURELIST &list, const TColor &color=TColor::red(), const bool showIDs=false, const bool showResponse=false, const bool showScale=false, const char marker='+')
 Draws a set of marks (or scaled circles for features with scale) onto the image, given a generic container of features. More...
 

Protected Attributes

std::string m_selectedFont {"9x15"}
 The selected font name. More...
 
const uint32_t * m_selectedFontBitmaps {nullptr}
 Direct access to character bitmaps. More...
 

Member Enumeration Documentation

◆ TPenStyle

Definition of pen styles.

Enumerator
psSolid 
psDash 
psDot 
psDashDot 
psDashDotDot 

Definition at line 55 of file CCanvas.h.

Constructor & Destructor Documentation

◆ CCanvas()

mrpt::img::CCanvas::CCanvas ( )
default

◆ ~CCanvas()

virtual mrpt::img::CCanvas::~CCanvas ( )
virtualdefault

Member Function Documentation

◆ drawCircle()

void CCanvas::drawCircle ( int  x,
int  y,
int  radius,
const mrpt::img::TColor color = mrpt::img::TColor(255, 255, 255),
unsigned int  width = 1 
)
virtual

Draws a circle of a given radius.

Parameters
xThe center - x coordinate in pixels.
yThe center - y coordinate in pixels.
radiusThe radius - in pixels.
colorThe color of the circle.
widthThe desired width of the line (this is IGNORED in this virtual class)

Reimplemented in mrpt::img::CImage.

Definition at line 338 of file CCanvas.cpp.

References M_2PI, and mrpt::round().

Referenced by drawFeatures().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawFeatures()

template<class FEATURELIST >
void mrpt::img::CCanvas::drawFeatures ( const FEATURELIST &  list,
const TColor color = TColor::red(),
const bool  showIDs = false,
const bool  showResponse = false,
const bool  showScale = false,
const char  marker = '+' 
)
inline

Draws a set of marks (or scaled circles for features with scale) onto the image, given a generic container of features.

The class of FEATURELIST can be:

See also
drawFeaturesSimple

Definition at line 280 of file CCanvas.h.

References drawCircle(), drawMark(), mrpt::format(), mrpt::img::TColor::red(), mrpt::round(), and textOut().

Referenced by mrpt::gui::CDisplayWindow::showImageAndPoints().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawFeaturesSimple()

template<class FEATURELIST >
void mrpt::img::CCanvas::drawFeaturesSimple ( const FEATURELIST &  list,
const TColor color = TColor::red(),
const int  cross_size = 5 
)
inline

Draws a set of marks onto the image, given a generic container of entities having just "x" and "y" fields.

The class of FEATURELIST can be, for example, std::vector<mrpt::math::TPoint2D>, std::vector<TPixelCoordsf> or mrpt::vision::CFeatureList

See also
drawFeatures

Definition at line 259 of file CCanvas.h.

References drawMark(), and mrpt::round().

Here is the call graph for this function:

◆ drawImage() [1/2]

void CCanvas::drawImage ( int  x,
int  y,
const mrpt::img::CImage img 
)
virtual

Draws an image as a bitmap at a given position.

Parameters
x0The top-left corner x coordinates on this canvas where the image is to be drawn
y0The top-left corner y coordinates on this canvas where the image is to be drawn
imgThe image to be drawn in this canvas This method may be redefined in some classes implementing this interface in a more appropiate manner.

Reimplemented in mrpt::img::CImage, and mrpt::img::CEnhancedMetaFile.

Definition at line 255 of file CCanvas.cpp.

References ASSERT_, mrpt::img::D8U, mrpt::img::CImage::getHeight(), mrpt::img::CImage::getPixelDepth(), mrpt::img::CImage::getWidth(), mrpt::img::CImage::isColor(), MRPT_END, and MRPT_START.

Referenced by mrpt::slam::CMetricMapBuilderRBPF::drawCurrentEstimationToImage(), and mrpt::img::CEnhancedMetaFile::drawImage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawImage() [2/2]

virtual void mrpt::img::CCanvas::drawImage ( int  x,
int  y,
const mrpt::img::CImage img,
float  rotation,
float  scale 
)
virtual

Draws an image as a bitmap at a given position, with some custom scale and rotation changes.

Parameters
x0The top-left corner x coordinates on this canvas where the image is to be drawn
y0The top-left corner y coordinates on this canvas where the image is to be drawn
rotationThe rotation in radians, positive values being anti-clockwise direction, 0 is the normal position.
scaleThe scale factor, e.g. 2 means twice the original size.
imgThe image to be drawn in this canvas This method may be redefined in some classes implementing this interface in a more appropiate manner.

Reimplemented in mrpt::img::CEnhancedMetaFile.

◆ drawMark()

void CCanvas::drawMark ( int  x0,
int  y0,
const mrpt::img::TColor  color,
char  type,
int  size = 5,
unsigned int  width = 1 
)

Draw a mark.

Parameters
x0The point x coordinate
y0The point y coordinate
colorThe color of the cross
sizeThe size of the cross
typeThe cross type. It could be: 'x', '+', ':'(like '+' but clear at the center dot), or 's' (square)
widthThe desired width of the cross (this is IGNORED yet)

Definition at line 304 of file CCanvas.cpp.

References mrpt::math::size(), and THROW_EXCEPTION.

Referenced by drawFeatures(), drawFeaturesSimple(), and mrpt::gui::CDisplayWindow::plot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ellipseGaussian()

void CCanvas::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.

Parameters
mean_xThe x coordinate of the center point of the ellipse.
mean_yThe y coordinate of the center point of the ellipse.
cov2DA 2x2 covariance matrix.
confIntervalStdsHow many "sigmas" for the confidence level (i.e. 2->95%, 3=99.97%,...)
colorThe color of the ellipse
widthThe desired width of the line (this is IGNORED in this virtual class)
nEllipsePointsThe number of points to generate to approximate the ellipse shape.
Exceptions
std::exceptionOn an invalid matrix.

Definition at line 452 of file CCanvas.cpp.

References mrpt::math::MatrixVectorBase< T, CMatrixFixed< T, ROWS, COLS > >::array(), mrpt::math::CMatrixFixed< T, ROWS, COLS >::asEigen(), mrpt::math::MatrixBase< T, CMatrixFixed< T, ROWS, COLS > >::eig(), M_2PI, MRPT_END_WITH_CLEAN_UP, MRPT_START, mrpt::round(), mrpt::math::MatrixBase< T, CMatrixFixed< T, ROWS, COLS > >::setDiagonal(), and mrpt::math::MatrixVectorBase< T, CMatrixFixed< T, ROWS, COLS > >::transpose().

Here is the call graph for this function:

◆ filledRectangle()

void CCanvas::filledRectangle ( int  x0,
int  y0,
int  x1,
int  y1,
const mrpt::img::TColor  color 
)
virtual

Draws a filled rectangle.

Parameters
x0The top-left x coordinate
y0The top-left y coordinate
x1The right-bottom x coordinate
y1The right-bottom y coordinate
colorThe color of the rectangle fill This method may be redefined in some classes implementing this interface in a more appropiate manner.
See also
rectangle

Definition at line 205 of file CCanvas.cpp.

References getHeight().

Referenced by mrpt::slam::CGridMapAligner::AlignPDF_robustMatch(), mrpt::img::CEnhancedMetaFile::CEnhancedMetaFile(), mrpt::opengl::CTexturedPlane::onUpdateBuffers_TexturedTriangles(), mrpt::gui::CDisplayWindow::plot(), and mrpt::maps::COccupancyGridMap2D::saveAsBitmapTwoMapsWithCorrespondences().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getHeight()

virtual size_t mrpt::img::CCanvas::getHeight ( ) const
pure virtual

Returns the height of the image in pixels.

Implemented in mrpt::img::CImage, and mrpt::img::CEnhancedMetaFile.

◆ getWidth()

virtual size_t mrpt::img::CCanvas::getWidth ( ) const
pure virtual

Returns the width of the image in pixels.

Implemented in mrpt::img::CImage, and mrpt::img::CEnhancedMetaFile.

◆ line()

void CCanvas::line ( int  x0,
int  y0,
int  x1,
int  y1,
const mrpt::img::TColor  color,
unsigned int  width = 1,
TPenStyle  penStyle = psSolid 
)
virtual

Draws a line.

Parameters
x0The starting point x coordinate
y0The starting point y coordinate
x1The end point x coordinate
y1The end point y coordinate
colorThe color of the line
widthThe desired width of the line (this is IGNORED in this virtual class) This method may be redefined in some classes implementing this interface in a more appropiate manner.

Reimplemented in mrpt::img::CImage, and mrpt::img::CEnhancedMetaFile.

Definition at line 125 of file CCanvas.cpp.

References getHeight(), and mrpt::square().

Referenced by mrpt::slam::CMetricMapBuilderRBPF::drawCurrentEstimationToImage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rectangle()

void CCanvas::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)

Parameters
x0The top-left x coordinate
y0The top-left y coordinate
x1The right-bottom x coordinate
y1The right-bottom y coordinate
colorThe color of the line
widthThe desired width of the line.
See also
filledRectangle

Definition at line 161 of file CCanvas.cpp.

Referenced by mrpt::vision::addFeaturesToImage(), and mrpt::maps::COccupancyGridMap2D::saveAsBitmapTwoMapsWithCorrespondences().

Here is the caller graph for this function:

◆ selectTextFont()

void CCanvas::selectTextFont ( const std::string &  fontName)
virtual

Select the current font used when drawing text.

Parameters
fontNameThe name of the font

Valid font names:

  • 5x7
  • 6x13
  • 6x13B
  • 6x13O
  • 9x15 (Default at start-up)
  • 9x15B
  • 10x20
  • 18x18ja (Asian characters for UTF-8 strings - Only available if MRPT is built with MRPT_HAS_ASIAN_FONTS = true)

See also
textOut, The example in this page.

Definition at line 220 of file CCanvas.cpp.

References FontData::data, init_fonts_list(), list_registered_fonts, FontData::prepared_to_big_endian, and mrpt::reverseBytesInPlace().

Referenced by mrpt::img::CImage::drawChessboardCorners(), and mrpt::img::CEnhancedMetaFile::selectVectorTextFont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPixel()

virtual void mrpt::img::CCanvas::setPixel ( int  x,
int  y,
size_t  color 
)
pure virtual

Changes the value of the pixel (x,y).

Pixel coordinates starts at the left-top corner of the image, and start in (0,0). The meaning of the parameter "color" depends on the implementation: it will usually be a 24bit RGB value (0x00RRGGBB), but it can also be just a 8bit gray level.

You can also use a TColor() type as input and it will be automatically converted to size_t.

This method must support (x,y) values OUT of the actual image size without neither raising exceptions, nor leading to memory access errors.

Implemented in mrpt::img::CImage, and mrpt::img::CEnhancedMetaFile.

◆ textOut()

void CCanvas::textOut ( int  x0,
int  y0,
const std::string &  str,
const mrpt::img::TColor  color 
)
virtual

Renders 2D text using bitmap fonts.

Parameters
x0The x coordinates
y0The y coordinates
strThe string to put. If using UNICODE characters, use UTF-8 encoding.
colorThe text color
See also
selectTextFont

Reimplemented in mrpt::img::CEnhancedMetaFile.

Definition at line 374 of file CCanvas.cpp.

References mrpt::system::decodeUTF8(), mrpt::img::CImage::isOriginTopLeft(), mrpt::system::os::memcpy(), MRPT_END, and MRPT_START.

Referenced by mrpt::img::CImage::drawChessboardCorners(), drawFeatures(), and mrpt::gui::CDisplayWindow::plot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ triangle()

void CCanvas::triangle ( int  x0,
int  y0,
int  size,
const mrpt::img::TColor  color,
bool  inferior = true,
unsigned int  width = 1 
)

Draws a triangle.

Parameters
x0The triangle center x coordinate
y0The triangle center y coordinate
sizeThe size of the triangle
colorThe color of the line
inferiorThe position of the triangle
widthThe desired width of the line.
See also
triangle

Definition at line 181 of file CCanvas.cpp.

References mrpt::round(), and mrpt::math::size().

Here is the call graph for this function:

Member Data Documentation

◆ m_selectedFont

std::string mrpt::img::CCanvas::m_selectedFont {"9x15"}
protected

The selected font name.

Definition at line 45 of file CCanvas.h.

◆ m_selectedFontBitmaps

const uint32_t* mrpt::img::CCanvas::m_selectedFontBitmaps {nullptr}
protected

Direct access to character bitmaps.

Definition at line 48 of file CCanvas.h.




Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020