/* Copyright 2005-2007 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef GIL_AFFINE_HPP #define GIL_AFFINE_HPP #include // point2 //////////////////////////////////////////////////////////////////////////////////////// /// \file /// \brief support for affine transformations /// \author Lubomir Bourdev and Hailin Jin \n /// Adobe Systems Incorporated /// \date 2005-2007 \n September 21, 2006 /// //////////////////////////////////////////////////////////////////////////////////////// namespace boost { namespace gil { //////////////////////////////////////////////////////////////////////////////////////// /// /// Simple matrix to do 2D affine transformations. It is actually 3x3 but the last column is [0 0 1] /// //////////////////////////////////////////////////////////////////////////////////////// template class matrix3x2 { public: matrix3x2() : a(1), b(0), c(0), d(1), e(0), f(0) {} matrix3x2(T A, T B, T C, T D, T E, T F) : a(A),b(B),c(C),d(D),e(E),f(F) {} matrix3x2(const matrix3x2& mat) : a(mat.a), b(mat.b), c(mat.c), d(mat.d), e(mat.e), f(mat.f) {} matrix3x2& operator=(const matrix3x2& m) { a=m.a; b=m.b; c=m.c; d=m.d; e=m.e; f=m.f; return *this; } matrix3x2& operator*=(const matrix3x2& m) { (*this) = (*this)*m; return *this; } static matrix3x2 get_rotate(T rads) { T c=std::cos(rads); T s=std::sin(rads); return matrix3x2(c,s,-s,c,0,0); } static matrix3x2 get_translate(const point2& t) { return matrix3x2(1 ,0,0,1 ,t.x,t.y); } static matrix3x2 get_translate(T x, T y) { return matrix3x2(1 ,0,0,1 ,x, y ); } static matrix3x2 get_scale (const point2& s) { return matrix3x2(s.x,0,0,s.y,0 ,0 ); } static matrix3x2 get_scale (T x, T y) { return matrix3x2(x, 0,0,y, 0 ,0 ); } static matrix3x2 get_scale (T s) { return matrix3x2(s ,0,0,s ,0 ,0 ); } T a,b,c,d,e,f; }; template GIL_FORCEINLINE matrix3x2 operator*(const matrix3x2& m1, const matrix3x2& m2) { return matrix3x2( m1.a * m2.a + m1.b * m2.c, m1.a * m2.b + m1.b * m2.d, m1.c * m2.a + m1.d * m2.c, m1.c * m2.b + m1.d * m2.d, m1.e * m2.a + m1.f * m2.c + m2.e, m1.e * m2.b + m1.f * m2.d + m2.f ); } template GIL_FORCEINLINE point2 operator*(const point2& p, const matrix3x2& m) { return point2(m.a*p.x + m.c*p.y + m.e, m.b*p.x + m.d*p.y + m.f); } //////////////////////////////////////////////////////////////////////////////////////// /// Define affine mapping that transforms the source coordinates by the affine transformation //////////////////////////////////////////////////////////////////////////////////////// /* template concept MappingFunctionConcept { typename mapping_traits::result_type; where PointNDConcept; template { where PointNDConcept } result_type transform(MapFn&, const Domain& src); }; */ template struct mapping_traits; template struct mapping_traits > { typedef point2 result_type; }; template GIL_FORCEINLINE point2 transform(const matrix3x2& mat, const point2& src) { return src * mat; } } } // namespace boost::gil #endif