MIRA
Classes | Public 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

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...
 
bool operator== (const RasterTransformation &other) const
 Comparison. More...
 
bool operator!= (const RasterTransformation &other) const
 Comparison. More...
 
const iteratorbegin () const
 Iterator to begin of raster mapping (first coordinate pair) More...
 

Protected Attributes

Rect2i mSrcArea
 
Rect2i mTgtArea
 
Rect2d mSrcAreaF
 
Point2d mSrcRef
 
Point2d mTgtRef
 
double mScale
 
double mRotate
 
bool mDense
 
iterator mBegin
 
double mSinRot
 implementation details More...
 
double mCosRot
 
double mDxStart
 
double mDxEnd
 
double mLineStep
 
Point3d mRasterStep
 

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()

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.

Member Function Documentation

◆ operator==()

bool operator== ( const RasterTransformation other) const
inline

Comparison.

◆ operator!=()

bool operator!= ( const RasterTransformation other) const
inline

Comparison.

◆ begin()

const iterator& begin ( ) const
inline

Iterator to begin of raster mapping (first coordinate pair)

Member Data Documentation

◆ mSrcArea

Rect2i mSrcArea
protected

◆ mTgtArea

Rect2i mTgtArea
protected

◆ mSrcAreaF

Rect2d mSrcAreaF
protected

◆ mSrcRef

Point2d mSrcRef
protected

◆ mTgtRef

Point2d mTgtRef
protected

◆ mScale

double mScale
protected

◆ mRotate

double mRotate
protected

◆ mDense

bool mDense
protected

◆ mBegin

iterator mBegin
protected

◆ mSinRot

double mSinRot
protected

implementation details

◆ mCosRot

double mCosRot
protected

◆ mDxStart

double mDxStart
protected

◆ mDxEnd

double mDxEnd
protected

◆ mLineStep

double mLineStep
protected

◆ mRasterStep

Point3d mRasterStep
protected

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