MIRA
Classes | Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
RasterTransformation Class Reference

Map a rectangular area from one raster into another, with an arbitrary transformation (scale, translation, rotation) inbetween. More...

#include <geometry/RasterTransformation.h>

Classes

struct  Configuration
 
struct  Impl
 implementation details More...
 
class  iterator
 

Public Member Functions

 RasterTransformation (const Rect2i &srcArea=Rect2i(0, 0, 1, 1), const Rect2i &tgtArea=Rect2i(0, 0, 1, 1), const Point2d &srcRef=Point2d(0.0, 0.0), const Point2d &tgtRef=Point2d(0.0, 0.0), double scale=1.0, double rotate=0.0, bool dense=false)
 Constructor with default values. More...
 
 RasterTransformation (const RasterTransformation &other)
 
RasterTransformationoperator= (const RasterTransformation &other)
 
bool operator== (const RasterTransformation &other) const
 Comparison. More...
 
const iteratorbegin () const
 Iterator to begin of raster mapping (first coordinate pair) More...
 

Static Protected Member Functions

static bool clipLine (const Rect2i &area, Point3d &p1, Point3d &p2)
 

Protected Attributes

Configuration mConfig
 
Impl mImpl
 
iterator mBegin
 

Detailed Description

Map a rectangular area from one raster into another, with an arbitrary transformation (scale, translation, rotation) inbetween.

Can be used to scale/transform images or other pixel/cell-based structures (grid maps).

The transformation is initialized with the transformation parameters and provides an iterator over the mapping. The iterator iterates over all pairs of correspondent source/target cell pairs in the raster mapping. The cell coordinates in the source and target raster are returned by the iterator's methods.

Example code: scale image to half size and rotate around center

Img8U3 src;
// load source image
double scale = 0.5;
Img8U3 tgt(scale*src.size());
tgt = 0;
RasterTransformation rt(Rect2i(0,0,src.width(),src.height()),
Rect2i(0,0,tgt.width(),tgt.height()),
Point2d(src.width()/2,src.height()/2),
Point2d(tgt.width()/2,tgt.height()/2),
scale,
boost::math::constants::half_pi<double>(),
true);
// note that the result image is rotated but clipped, as the full
// width does not fit into its height
for(RasterTransformation::iterator it = rt.begin(); it.isValid(); ++it)
{
if (src(it.srcX(), it.srcY()) > tgt(it.tgtX(), it.tgtY()))
tgt(it.tgtX(), it.tgtY()) = src(it.srcX(), it.srcY());
}

The focus in the implementation is more on speed than on high precision, therefore there is no such thing as interpolation, and source/target cells returned are matching (overlapping), but are not necessarily the ones with the largest overlap.

Properties of the cell coordinates returned by the iterator:

Constructor & Destructor Documentation

◆ RasterTransformation() [1/2]

RasterTransformation ( const Rect2i srcArea = Rect2i(0,0,1,1),
const Rect2i tgtArea = Rect2i(0,0,1,1),
const Point2d srcRef = Point2d(0.0, 0.0),
const Point2d tgtRef = Point2d(0.0, 0.0),
double  scale = 1.0,
double  rotate = 0.0,
bool  dense = false 
)
inline

Constructor with default values.

◆ RasterTransformation() [2/2]

RasterTransformation ( const RasterTransformation other)
inline

Member Function Documentation

◆ operator=()

RasterTransformation & operator= ( const RasterTransformation other)
inline

◆ operator==()

bool operator== ( const RasterTransformation other) const
inline

Comparison.

◆ begin()

const iterator& begin ( ) const
inline

Iterator to begin of raster mapping (first coordinate pair)

◆ clipLine()

bool clipLine ( const Rect2i area,
Point3d p1,
Point3d p2 
)
inlinestaticprotected

Member Data Documentation

◆ mConfig

Configuration mConfig
protected

◆ mImpl

Impl mImpl
protected

◆ mBegin

iterator mBegin
protected

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