36#ifndef VIGRA_AFFINEGEOMETRY_HXX
37#define VIGRA_AFFINEGEOMETRY_HXX
39#include "mathutil.hxx"
41#include "tinyvector.hxx"
42#include "splineimageview.hxx"
43#include "multi_shape.hxx"
80 ret(0,0) = scalingFactor;
81 ret(1,1) = scalingFactor;
119 double s = std::sin(angle);
120 double c = std::cos(angle);
165template <
int ORDER,
class T,
166 class DestIterator,
class DestAccessor>
167void rotateImage(SplineImageView<ORDER, T>
const & src,
168 DestIterator
id, DestAccessor dest,
169 double angleInDegree, TinyVector<double, 2>
const & center)
172 int h = src.height();
174 double angle = angleInDegree/180.0;
178 for(
int y = 0; y < h; ++y, ++
id.y)
180 typename DestIterator::row_iterator rd =
id.rowIterator();
181 double sy = (y - center[1])*c - center[0]*s + center[1];
182 double sx = -(y - center[1])*s - center[0]*c + center[0];
183 for(
int x=0; x < w; ++x, ++rd, sx += c, sy += s)
185 if(src.isInside(sx, sy))
186 dest.set(src(sx, sy), rd);
191template <
int ORDER,
class T,
192 class DestIterator,
class DestAccessor>
195 pair<DestIterator, DestAccessor> dest,
198 rotateImage(src, dest.first, dest.second, angleInDegree, center);
201template <
int ORDER,
class T,
202 class DestIterator,
class DestAccessor>
205 DestIterator
id, DestAccessor dest,
206 double angleInDegree)
209 rotateImage(src,
id, dest, angleInDegree, center);
212template <
int ORDER,
class T,
213 class DestIterator,
class DestAccessor>
216 pair<DestIterator, DestAccessor> dest,
217 double angleInDegree)
220 rotateImage(src, dest.first, dest.second, angleInDegree, center);
223template <
int ORDER,
class T,
230 rotateImage(src, destImage(dest), angleInDegree, center);
233template <
int ORDER,
class T,
238 double angleInDegree)
241 rotateImage(src, destImage(dest), angleInDegree, center);
365template <
int ORDER,
class T,
366 class DestIterator,
class DestAccessor,
369 DestIterator dul, DestIterator dlr, DestAccessor dest,
373 affineMatrix(2,0) == 0.0 && affineMatrix(2,1) == 0.0 && affineMatrix(2,2) == 1.0,
374 "affineWarpImage(): matrix doesn't represent an affine transformation with homogeneous 2D coordinates.");
377 double w = dlr.x - dul.x;
378 double h = dlr.y - dul.y;
380 for(
double y = 0.0; y < h; ++y, ++dul.y)
382 typename DestIterator::row_iterator rd = dul.rowIterator();
383 for(
double x=0.0; x < w; ++x, ++rd)
385 double sx = x*affineMatrix(0,0) + y*affineMatrix(0,1) + affineMatrix(0,2);
386 double sy = x*affineMatrix(1,0) + y*affineMatrix(1,1) + affineMatrix(1,2);
388 dest.set(src(sx, sy), rd);
393template <
int ORDER,
class T,
394 class DestIterator,
class DestAccessor,
398 triple<DestIterator, DestIterator, DestAccessor> dest,
399 MultiArrayView<2, double, C>
const & affineMatrix)
401 affineWarpImage(src, dest.first, dest.second, dest.third, affineMatrix);
404template <
int ORDER,
class T,
Base class for, and view to, MultiArray.
Definition multi_array.hxx:705
Create a continuous view onto a discrete image using splines.
Definition splineimageview.hxx:100
bool isInside(double x, double y) const
Definition splineimageview.hxx:488
Class for fixed size vectors.
Definition tinyvector.hxx:1008
void identityMatrix(MultiArrayView< 2, T, C > &r)
Definition matrix.hxx:845
MultiArrayIndex columnCount(const MultiArrayView< 2, T, C > &x)
Definition matrix.hxx:684
linalg::TemporaryMatrix< double > scalingMatrix2D(double scalingFactor)
Create homogeneous matrix representing a 2D uniform scaling about the coordinate origin.
Definition affinegeometry.hxx:77
linalg::TemporaryMatrix< double > rotationMatrix2DDegrees(double angle)
Create homogeneous matrix representing a 2D rotation about the coordinate origin.
Definition affinegeometry.hxx:133
REAL cos_pi(REAL x)
cos(pi*x).
Definition mathutil.hxx:1242
REAL sin_pi(REAL x)
sin(pi*x).
Definition mathutil.hxx:1204
linalg::TemporaryMatrix< double > rotationMatrix2DRadians(double angle)
Create homogeneous matrix representing a 2D rotation about the coordinate origin.
Definition affinegeometry.hxx:116
linalg::TemporaryMatrix< double > shearMatrix2D(double s01, double s10)
Create homogeneous matrix representing a 2D shearing.
Definition affinegeometry.hxx:103
linalg::TemporaryMatrix< double > translationMatrix2D(TinyVector< double, 2 > const &shift)
Create homogeneous matrix representing a 2D translation.
Definition affinegeometry.hxx:64
MultiArrayIndex rowCount(const MultiArrayView< 2, T, C > &x)
Definition matrix.hxx:671
void affineWarpImage(...)
Warp an image according to an affine transformation.