MIRA
Classes | Functions
Geometry Module


For detailed information see Geometry. More...

Collaboration diagram for Geometry Module:

Classes

class  BresenhamLineIterator
 Implements an iterator that is able to iterate over a Bresenham line point by point using the prefix ++operator and –operator. More...
 
class  GeneralBresenhamLineIterator< D, T, Drive, Res >
 This more general iterator basically follows the design of BresenhamLineIterator, but works on an arbitrary-dimensional line and handles real-valued start and end positions. More...
 
class  DistanceLUT
 This class creates a look up table (LUT) to calculate the minimum and maximum Euclidean distance between a point and cells that are arranged in a regular grid. More...
 
class  PointBase< T, D, Derived >
 The base template class of point, which covers the basic functionality of each point. More...
 
class  Point< T, D >
 General point class template. More...
 
class  Point< T, 2 >
 Specialization of Point for 2 dimensions with specialized constructors and converters. More...
 
class  Point< T, 3 >
 Specialization of Point for 3 dimensions with specialized constructors and converters. More...
 
class  RasterTransformation
 Map a rectangular area from one raster into another, with an arbitrary transformation (scale, translation, rotation) inbetween. More...
 
class  RectBase< T, D, Derived >
 The base class for rectangles. More...
 
class  Rect< T, D >
 Rect class for defining rectangles. More...
 
class  Rect< T, 2 >
 Specialization for 2D. More...
 
class  Rect< T, 3 >
 Specialization for 3D. More...
 
class  Size< T, D >
 Size class for defining sizes with different data types. More...
 
class  Size< T, 2 >
 Specialization for 2D with special members width() and height(). More...
 
class  Size< T, 3 >
 Specialization for 3D with special members width(),height() and depth(). More...
 

Functions

template<typename Visitor >
void bresenham (int x0, int y0, int x1, int y1, Visitor &&visitor)
 Rasterizes a Bresenham line point by point starting at coordinate (x0,y0) and ending in (x1,y1). More...
 
template<typename Visitor >
void bresenham (Point2i p0, Point2i p1, Visitor &&visitor)
 Different interface for standard Bresenham Algorithm. More...
 
template<typename Visitor >
void bresenhamRunSlice (int x0, int y0, int x1, int y1, Visitor &&visitor)
 Rasterizes a Bresenham line starting at coordinate (x0,y0) and ending in (x1,y1). More...
 
template<typename Visitor >
void bresenhamRunSlice (Point2i p0, Point2i p1, Visitor &&visitor)
 Different interface for Bresenham Run-Slice Algorithm. More...
 
template<typename PointType >
boost::geometry::model::ring< PointType > createTriangle (const PointType &p1, const PointType &p2, const PointType &p3)
 The polygon is essentially a sequence of points with an edge also connecting the first and last point. More...
 
template<class TransformationInRegion , class Visitor >
void rasterPolygon (const Polygon2f &polygon, const Rect2i &region, TransformationInRegion &&transformation, Visitor &&visitor)
 Function for rasterising a polygon. More...
 
template<class TransformationInRegion , class Visitor >
void rasterPolygon (const Polygon2f &polygon, const Rect2i &region, TransformationInRegion &&transformation, Visitor &&visitor, uint precision)
 Function for rasterising a polygon. More...
 
template<typename Visitor >
void rasterRect (int xl, int yl, int xr, int yr, Visitor &&visitor)
 Rasterizes an Rectangle (2D only). More...
 
template<typename Visitor >
void rasterRect (const Rect2i &rect, Visitor &&visitor)
 Rasters a rect (see description above), same as above, just additional interface. More...
 
template<typename Visitor >
void rasterTriangle (Point2i p0, Point2i p1, Point2i p2, Visitor &&visitor)
 Rasters a triangle scanline by scanline. More...
 
template<typename Visitor >
void rasterTriangle (const Polygon2i &polygon, Visitor &&visitor)
 Same function as above, but with a nicer interface. More...
 

Detailed Description


For detailed information see Geometry.

Function Documentation

◆ bresenham() [1/2]

void bresenham ( int  x0,
int  y0,
int  x1,
int  y1,
Visitor &&  visitor 
)
inline

Rasterizes a Bresenham line point by point starting at coordinate (x0,y0) and ending in (x1,y1).

For each point on the line the visitors operator()(int x, int y) is called with the two parameters x,y that specify the coordinate of that point/pixel.

Therefore, the visitor must implement the following concept:

concept BresenhamVisitor
{
void operator()(int x, int y);
};
Parameters
[in]x0x coordinate of start point
[in]y0y coordinate of start point
[in]x1x coordinate of end point
[in]y1y coordinate of end point
[in,out]visitorthe visitor which implements the functionality, what to do with iterated points
Note
For optimal performance the visitor must be implemented inline!
See also
Geometry

◆ bresenham() [2/2]

void mira::bresenham ( Point2i  p0,
Point2i  p1,
Visitor &&  visitor 
)

Different interface for standard Bresenham Algorithm.

(Detailed description see bresenham.)

Parameters
[in]p0start point
[in]p1end point
[in,out]visitorthe visitor which implements the functionality, what to do with iterated points

◆ bresenhamRunSlice() [1/2]

void bresenhamRunSlice ( int  x0,
int  y0,
int  x1,
int  y1,
Visitor &&  visitor 
)
inline

Rasterizes a Bresenham line starting at coordinate (x0,y0) and ending in (x1,y1).

Detailed information on Bresenhams run-slice algorithm and source code can be found here: http://www.phatcode.net/res/224/files/html/ch36/36-01.html.

In contrast to the above method this method uses the Bresenham run-slice algorithm which is significantly faster for lines that mainly move along the x-axis (with small slope). Instead of rastering the line pixel by pixel the line is rastered segment by segment scanline by scanline from top to bottom. For each segment the visitor's operator()(int x, int y, int length) is called with the parameters x,y,length that specify the coordinate starting position of the segment and its length.

Therefore, the visitor must implement the following concept:

concept BresenhamVisitor
{
void operator()(int x, int y, int length);
};

Example:

1 2 3 4 5 6 7 8
1
2 x x
3 x x x
4 x x
5

In this example the visitor would be called three times with the segments (1,2,2), (3,3,3) and (6,4,2).

Detailed information on Bresenhams Run-Slice Algorithm and source code can be found here: http://www.phatcode.net/res/224/files/html/ch36/36-01.html

Parameters
[in]x0x coordinate of start point
[in]y0y coordinate of start point
[in]x1x coordinate of end point
[in]y1y coordinate of end point
[in,out]visitorthe visitor which implements the functionality, what to do with iterated points
Note
For lines with large slope (major y-axis) the standard Bresenham Algorithm is used, hence there is no advantage for those lines.
For optimal performance the visitor must be implemented inline!
See also
Geometry
Parameters
[in]x0: the x-coordinate of the first point
[in]y0: the y-coordinate of the first point
[in]x1: the x-coordinate of the second point
[in]y1: the y-coordinate of the second point
[in]visitor: the visitor which has to provide the slice concept

◆ bresenhamRunSlice() [2/2]

void mira::bresenhamRunSlice ( Point2i  p0,
Point2i  p1,
Visitor &&  visitor 
)

Different interface for Bresenham Run-Slice Algorithm.

Description see bresenhamRunSlice.

Parameters
[in]p0start point
[in]p1end point
[in,out]visitorthe visitor which implements the functionality, what to do with iterated points

◆ createTriangle()

boost::geometry::model::ring<PointType> mira::createTriangle ( const PointType &  p1,
const PointType &  p2,
const PointType &  p3 
)
inline

The polygon is essentially a sequence of points with an edge also connecting the first and last point.

Since Eigen could not deal with polygons, we switch to support boost geometry more.

An example with 3D points

|P1.x| |P2.x| |P3.x| |P4.x|
|P1.y|...|P2.y|...|P3.y|...|P4.y|...
|P1.z| |P2.z| |P3.z| |P4.z|

Boost::geometry polygons support so called "inner" and "outer" rings. The outer ring defines the outer bound, where the polygon begins. The inner rings define holes inside the polygon. There is only one outer ring but multiple inner rings are possible.

However in MIRA we only use polygons that have no inner rings. There we use boost::geometry::model::ring instead of boost::geometry::polygon!

NOTE: Intersections of polygons and rasterization can only be established on 2D polygons. More dimensions for intersection are not supported in boost::geometry and a 3D rasterization needs a triangulation before.

Function to create a triangle from three given points. The function returns a boost::geometry::ring.

Parameters
[in]p1: first point of the triangle
[in]p2: second point of the triangle
[in]p3: third point of the triangle

◆ rasterPolygon() [1/2]

void mira::rasterPolygon ( const Polygon2f polygon,
const Rect2i region,
TransformationInRegion &&  transformation,
Visitor &&  visitor 
)

Function for rasterising a polygon.

The algorithm determines the intersection with the lines y = n + 0.5, where n is a natural number. These intersections are sorted and grouped in pairs to determine intervals. These intervals are visited by the visitor.

Parameters
[in]polygon: polygon to be rasterised
[in]region: region in which the converted polygon is rasterised
[in]transformation: transformation of the given polygon to another coordinate system (e.g. world to image coordinates). This functor is required to take a Point2f as its argument and to return a Point2f.
[in]visitorFunction that takes (x,y) for a visited pixel/cell as two int values and returns a bool value, indicating whether the function should stop iterating here.

◆ rasterPolygon() [2/2]

void mira::rasterPolygon ( const Polygon2f polygon,
const Rect2i region,
TransformationInRegion &&  transformation,
Visitor &&  visitor,
uint  precision 
)

Function for rasterising a polygon.

The algorithm determines the intersection with the lines y = (n + 0.5)/p, where n is a natural number and p is a precision. These intersections are sorted and grouped in pairs to determine intervals. Intervals with the same |_y_| are merged. These intervals are visited by the visitor.

Parameters
[in]polygon: polygon to be rasterised
[in]region: region in which the converted polygon is rasterised
[in]transformation: transformation of the given polygon to another coordinate system (e.g. world to image coordinates). This functor is required to take a Point2f as its argument and to return a Point2f.
[in]visitorFunction that takes (x,y) for a visited pixel/cell as two int values and returns a bool value, indicating whether the function should stop iterating here.
[in]precisionDetermines how many intersections are calculated between n and n+1.

◆ rasterRect() [1/2]

void mira::rasterRect ( int  xl,
int  yl,
int  xr,
int  yr,
Visitor &&  visitor 
)
inline

Rasterizes an Rectangle (2D only).

Instead of rastering the line pixel by pixel the rectangle is rastered scanline by scanline from top to bottom. For each segment the visitor's operator()(int x, int y, int length) is called with the parameters x, y, and length that specify the coordinate starting position of the segment and its length.

Therefore, the visitor must implement the following concept:

concept RectVisitor
{
void operator()(int x, int y, int length);
};
See also
Geometry
Parameters
[in]xl: the x-coordinate of the lower left corner
[in]yl: the y-coordinate of the lower left corner
[in]xr: the x-coordinate of the upper right corner
[in]yr: the y-coordinate of the upper right corner
[in]visitor: the visitor to execute scanline computations

◆ rasterRect() [2/2]

void mira::rasterRect ( const Rect2i rect,
Visitor &&  visitor 
)
inline

Rasters a rect (see description above), same as above, just additional interface.

◆ rasterTriangle() [1/2]

void mira::rasterTriangle ( Point2i  p0,
Point2i  p1,
Point2i  p2,
Visitor &&  visitor 
)
inline

Rasters a triangle scanline by scanline.

For each scanline the visitors operator()(int xl, int xr, int y) is called, where the parameters xl and xr specify the the x-coordinates of the left and right triangle boundary in the scanline y. For filling a triangle e.g. the pixels between xl and xr (including xl and xr) in line y must be filled.

Therefore, the visitor must implement the following concept:

concept TriangleVisitor
{
void operator()(int xl, int xr, int y);
};
Parameters
[in]p0: the first triangle point
[in]p1: the second triangle point
[in]p2: the third triangle point
[in]visitor: the visitor to execute scanline computations (see description above)
See also
Geometry

◆ rasterTriangle() [2/2]

void mira::rasterTriangle ( const Polygon2i polygon,
Visitor &&  visitor 
)
inline

Same function as above, but with a nicer interface.

For full description see

See also
rasterTriangle.
Parameters
[in]polygona polygon with three points OR a polygon with 4 points, where the first and last point are equal
[in,out]visitorthe visitor to execute scanline computations