Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GEO::ImageRasterizer Class Reference

Draws triangles in an image. More...

#include <geogram/image/image_rasterizer.h>

Public Member Functions

 ImageRasterizer (Image *image)
 ImageRasterizer constructor. More...
 
void clear ()
 Clears the target image.
 
void triangle (const vec2i &P1, const Color &c1, const vec2i &P2, const Color &c2, const vec2i &P3, const Color &c3)
 Draws a triangle in the target image. More...
 
void triangle (const vec2 &p1, const Color &c1, const vec2 &p2, const Color &c2, const vec2 &p3, const Color &c3)
 Draws a triangle in the target image. More...
 
void segment (const vec2i &P1, const vec2i &P2, const Color &c)
 Draws a segment in the target image. More...
 
void segment (const vec2 &p1, const vec2 &p2, const Color &c)
 Draws a segment in the target image. More...
 
void fillcircle (const vec2i &C, int radius, const Color &c)
 Fills a circle in the target image. More...
 
void fillcircle (const vec2 &C, double radius, const Color &c)
 Fills a circle in the target image. More...
 
void flood_fill (int x, int y, const Color &c)
 Flood-fill from a given pixel. More...
 
void set_pixel (int x, int y, const Color &c)
 Sets a pixel of the image. More...
 
bool pixel_is_black (int x, int y) const
 Tests whether a given pixel is black. More...
 

Protected Member Functions

vec2i transform (const vec2 &p) const
 Transforms a 2d point from world space to pixel coordinates. More...
 
void interpolate_color (const Color &c1, const Color &c2, const Color &c3, double l1, double l2, double l3, Color &c) const
 Computes the linear interpolation between three colors. More...
 

Detailed Description

Draws triangles in an image.

Definition at line 56 of file image_rasterizer.h.

Constructor & Destructor Documentation

◆ ImageRasterizer()

GEO::ImageRasterizer::ImageRasterizer ( Image image)

ImageRasterizer constructor.

Parameters
[in]imagea pointer to the target image.

Member Function Documentation

◆ fillcircle() [1/2]

void GEO::ImageRasterizer::fillcircle ( const vec2 C,
double  radius,
const Color c 
)
inline

Fills a circle in the target image.

The circle is clipped to the image

Parameters
[in]Cthe center of the circle, coordinates are between 0.0 and 1.0.
[in]radiusthe radius of the circle. A value of 1.0 corresponds to the width of the image.
[in]cthe color of the pixels

Definition at line 151 of file image_rasterizer.h.

◆ fillcircle() [2/2]

void GEO::ImageRasterizer::fillcircle ( const vec2i C,
int  radius,
const Color c 
)

Fills a circle in the target image.

The circle is clipped to the image

Parameters
[in]Cthe center of the circle, integer coordinates are in [0..width-1]x[0..height-1], where width and height are the sizes of the target image.
[in]radiusthe radius of the circle (in pixels).
[in]cthe color of the pixels

◆ flood_fill()

void GEO::ImageRasterizer::flood_fill ( int  x,
int  y,
const Color c 
)

Flood-fill from a given pixel.

Fills the connected component of black (zero) pixels incident to x,y

◆ interpolate_color()

void GEO::ImageRasterizer::interpolate_color ( const Color c1,
const Color c2,
const Color c3,
double  l1,
double  l2,
double  l3,
Color c 
) const
inlineprotected

Computes the linear interpolation between three colors.

Parameters
[in]c1,c2,c3the three colors to be interpolated.
[in]l1,l2,l3the coefficients of the interpolation.
[out]cthe interpolated color.

Definition at line 250 of file image_rasterizer.h.

◆ pixel_is_black()

bool GEO::ImageRasterizer::pixel_is_black ( int  x,
int  y 
) const
inline

Tests whether a given pixel is black.

Only implemented for BYTE component encoding

Parameters
[in]x,ythe integer coordinates of the pixel
Return values
trueif the pixel is black
falseotherwise

Definition at line 219 of file image_rasterizer.h.

◆ segment() [1/2]

void GEO::ImageRasterizer::segment ( const vec2 p1,
const vec2 p2,
const Color c 
)
inline

Draws a segment in the target image.

No clipping is done. It is the responsibility of the caller to give valid coordinates.

Parameters
[in]p1,p2the two extremities of the segment. coordinates are in the [0,1]x[0,1] square.
[in]cthe color

Definition at line 127 of file image_rasterizer.h.

◆ segment() [2/2]

void GEO::ImageRasterizer::segment ( const vec2i P1,
const vec2i P2,
const Color c 
)

Draws a segment in the target image.

No clipping is done. It is the responsibility of the caller to give valid coordinates.

Parameters
[in]P1,P2the two extremities of the segment. integer coordinates are in [0..width-1]x[0..height-1], where width and height are the sizes of the target image.
[in]cthe color

◆ set_pixel()

void GEO::ImageRasterizer::set_pixel ( int  x,
int  y,
const Color c 
)
inline

Sets a pixel of the image.

Only BYTE, FLOAT32 and FLOAT64 component encoding are supported. If the image has less than 4 channels, the extra channels in c are ignored.

Parameters
[in]x,ythe integer pixel coordinates
[in]cthe color of the pixel

Definition at line 174 of file image_rasterizer.h.

◆ transform()

vec2i GEO::ImageRasterizer::transform ( const vec2 p) const
inlineprotected

Transforms a 2d point from world space to pixel coordinates.

Parameters
[in]pcoordinates of the points, in [0,1]x[0,1]
Returns
transformed the pixel coordinates of the point.

Definition at line 237 of file image_rasterizer.h.

◆ triangle() [1/2]

void GEO::ImageRasterizer::triangle ( const vec2 p1,
const Color c1,
const vec2 p2,
const Color c2,
const vec2 p3,
const Color c3 
)
inline

Draws a triangle in the target image.

Colors are linearly interpolated (Gouraud shading). No clipping is done. It is the responsibility of the caller to give coordinates in the viewport.

Parameters
[in]p1,p2,p3the three vertices of the triangle, coordinates are in the [0,1]x[0,1] square.
[in]c1,c2,c3the three colors of the vertices.

Definition at line 96 of file image_rasterizer.h.

◆ triangle() [2/2]

void GEO::ImageRasterizer::triangle ( const vec2i P1,
const Color c1,
const vec2i P2,
const Color c2,
const vec2i P3,
const Color c3 
)

Draws a triangle in the target image.

Colors are linearly interpolated (Gouraud shading). No clipping is done. It is the responsibility of the caller to give coordinates in the viewport.

Parameters
[in]P1,P2,P3the three vertices of the triangle, integer coordinates are in [0..width-1]x[0..height-1], where width and height are the sizes of the target image.
[in]c1,c2,c3the three colors of the vertices.

The documentation for this class was generated from the following file: