Class CCanvas
Defined in File CCanvas.h
Inheritance Relationships
Derived Type
public mrpt::img::CImage(Class CImage)
Class Documentation
-
class CCanvas
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:
“6x13”
”6x13B” (bold)
”6x13O” (italic)
”9x15”
”9x15B” (bold)
”10x20”
”18x18ja” (Japanese, UNICODE character values)
For an example of each font check the corresponding wiki page.
See also
Subclassed by mrpt::img::CImage
Public Types
Public Functions
-
CCanvas() = default
-
virtual ~CCanvas() = default
-
virtual void setPixel(const TPixelCoord &pt, const mrpt::img::TColor &color) = 0
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.
-
virtual int32_t getWidth() const = 0
Returns the width of the image in pixels
-
virtual int32_t getHeight() const = 0
Returns the height of the image in pixels
-
virtual void line(const TPixelCoord &pt0, const TPixelCoord &pt1, const mrpt::img::TColor &color, int32_t width = 1, TPenStyle penStyle = psSolid)
Draws a line.
- Parameters:
pt0 – The starting point
pt1 – The end point
color – The color of the line
width – The 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 appropriate manner.
-
void rectangle(const TPixelCoord &pt0, const TPixelCoord &pt1, const mrpt::img::TColor &color, int32_t width = 1)
Draws a rectangle (an empty rectangle, without filling)
See also
- Parameters:
pt0 – The top-left point
pt1 – The right-bottom coordinate
color – The color of the line
width – The desired width of the line.
-
void triangle(const TPixelCoord &pt, int32_t size, mrpt::img::TColor color, bool inferior = true, int32_t width = 1)
Draws a triangle
See also
- Parameters:
pt – The triangle center
size – The size of the triangle
color – The color of the line
inferior – The position of the triangle
width – The desired width of the line.
-
virtual void filledRectangle(const TPixelCoord &pt0, const TPixelCoord &pt1, mrpt::img::TColor color)
Draws a filled rectangle.
See also
- Parameters:
pt0 – The top-left point
pt1 – The right-bottom point
color – The color of the rectangle fill This method may be redefined in some classes implementing this interface in a more appropriate manner.
-
virtual void textOut(const TPixelCoord &pt, const std::string &str, mrpt::img::TColor color)
Renders 2D text using bitmap fonts.
See also
- Parameters:
pt – The point where the text is to be drawn
str – The string to put. If using UNICODE characters, use UTF-8 encoding.
color – The text color
-
virtual void selectTextFont(const std::string &fontName)
Select the current font used when drawing text.
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)

- Parameters:
fontName – The name of the font
-
virtual void drawImage(const TPixelCoord &pt, const mrpt::img::CImage &img)
Draws an image as a bitmap at a given position.
- Parameters:
pt – The top-left corner on this canvas where the image is to be drawn
img – The image to be drawn in this canvas This method may be redefined in some classes implementing this interface in a more appropriate manner.
-
void drawMark(const TPixelCoord &pt, const mrpt::img::TColor &color, char type, int32_t size = 5, int32_t width = 1)
Draw a mark.
- Parameters:
pt – The point where the mark is to be drawn
color – The color of the cross
size – The size of the cross
type – The cross type. It could be: ‘x’, ‘+’, ‘:’(like ‘+’ but clear at the center dot), or ‘s’ (square)
width – The desired width of the cross (this is IGNORED yet)
-
virtual void drawCircle(const TPixelCoord ¢er, int32_t radius, const mrpt::img::TColor &color = mrpt::img::TColor(255, 255, 255), int32_t width = 1)
Draws a circle of a given radius.
- Parameters:
pt – The center coordinate
radius – The radius - in pixels.
color – The color of the circle.
width – The desired width of the line (this is IGNORED in this virtual class)
-
void ellipseGaussian(const mrpt::math::CMatrixFixed<double, 2, 2> &cov2D, double mean_x, double mean_y, double confIntervalStds = 2, const mrpt::img::TColor &color = mrpt::img::TColor(255, 255, 255), int32_t width = 1, int nEllipsePoints = 20)
Draws an ellipse representing a given confidence interval of a 2D Gaussian distribution.
- Parameters:
mean_x – The x coordinate of the center point of the ellipse.
mean_y – The y coordinate of the center point of the ellipse.
cov2D – A 2x2 covariance matrix.
confIntervalStds – How many “sigmas” for the confidence level (i.e. 2->95%, 3=99.97%,…)
color – The color of the ellipse
width – The desired width of the line (this is IGNORED in this virtual class)
nEllipsePoints – The number of points to generate to approximate the ellipse shape.
- Throws:
std::exception – On an invalid matrix.