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"
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;
175 double c = cos_pi(angle);
176 double s = sin_pi(angle);
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>
194rotateImage(SplineImageView<ORDER, T>
const & src,
195 pair<DestIterator, DestAccessor> dest,
196 double angleInDegree, TinyVector<double, 2>
const & center)
198 rotateImage(src, dest.first, dest.second, angleInDegree, center);
201template <
int ORDER,
class T,
202 class DestIterator,
class DestAccessor>
204rotateImage(SplineImageView<ORDER, T>
const & src,
205 DestIterator
id, DestAccessor dest,
206 double angleInDegree)
208 TinyVector<double, 2> center((src.width()-1.0) / 2.0, (src.height()-1.0) / 2.0);
209 rotateImage(src,
id, dest, angleInDegree, center);
212template <
int ORDER,
class T,
213 class DestIterator,
class DestAccessor>
215rotateImage(SplineImageView<ORDER, T>
const & src,
216 pair<DestIterator, DestAccessor> dest,
217 double angleInDegree)
219 TinyVector<double, 2> center((src.width()-1.0) / 2.0, (src.height()-1.0) / 2.0);
220 rotateImage(src, dest.first, dest.second, angleInDegree, center);
223template <
int ORDER,
class T,
226rotateImage(SplineImageView<ORDER, T>
const & src,
227 MultiArrayView<2, T2, S2> dest,
228 double angleInDegree, TinyVector<double, 2>
const & center)
230 rotateImage(src, destImage(dest), angleInDegree, center);
233template <
int ORDER,
class T,
236rotateImage(SplineImageView<ORDER, T>
const & src,
237 MultiArrayView<2, T2, S2> dest,
238 double angleInDegree)
240 TinyVector<double, 2> center((src.width()-1.0) / 2.0, (src.height()-1.0) / 2.0);
241 rotateImage(src, destImage(dest), angleInDegree, center);
365template <
int ORDER,
class T,
374 "affineWarpImage(): matrix doesn't represent an affine transformation with homogeneous 2D coordinates.");
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)
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,
409 MultiArrayView<2, T2, S2> dest,
410 MultiArrayView<2, double, C>
const & affineMatrix)
Class for a single RGB value.
Definition rgbvalue.hxx:128
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
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
void affineWarpImage(...)
Warp an image according to an affine transformation.