
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Sandbox: Sync access.hh/.cc with trunk. * jardonnet/virtual/access.hh: Sync with trunk. * jardonnet/virtual/access.cc: Sync with trunk. access.cc | 4 +-- access.hh | 66 +++++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 22 deletions(-) Index: jardonnet/virtual/access.hh --- jardonnet/virtual/access.hh (revision 2201) +++ jardonnet/virtual/access.hh (working copy) @@ -1,10 +1,12 @@ #ifndef _ACCESS_HH # define _ACCESS_HH -# include <mln/core/image1d.hh> -# include <mln/core/image2d.hh> +# include <mln/core/image/image1d.hh> +# include <mln/core/image/image2d.hh> # include <mln/metal/is.hh> # include <mln/core/concept/function.hh> +# include <mln/fun/internal/selector.hh> +# include <mln/convert/to.hh> namespace mln { @@ -14,37 +16,48 @@ template < typename I > struct nearest_neighbor - : public Function_x2x< nearest_neighbor<I> > + : public fun::internal::selector_<const algebra::vec<3,float>, + // 3,float is a dummy parameter (real is n,T) + mln_value(I), nearest_neighbor<I> >::ret { typedef mln_value(I) result; - template < typename V > + nearest_neighbor(const I& ima) : ima(ima) {} + + template < unsigned n, typename T > mln_value(I) - operator()(const I& img, const V& v) const + operator()(const I& img, const algebra::vec<n,T>& x) const { - mln_point(I) p = algebra::to_point<mln_point(I)>(v); + mln_psite(I) p = convert::to<mln_psite(I)>(x); return img(p); } + const I& ima; }; template < typename I > struct linear - : public Function_x2x< linear<I> > + : public fun::internal::selector_<const algebra::vec<1,float>, + // float is a dummy parameter (real is C) + mln_value(I), linear<I> >::ret { typedef mln_value(I) result; + linear(const I& ima) : ima(ima) {} + template <typename C> mln_value(I) operator()(const I& img, const algebra::vec<1,C>& v) const { + typedef mln_sum(mln_value(I)) vsum; + // looking for img(x); double x = v[0]; // p1 double xa = mln_point(I)::coord(v[0]); - double ya = img(point1d(xa)); + vsum ya = img(point1d(xa)); // x makes sens in img if (x == xa) @@ -52,23 +65,32 @@ // p2 double xb = mln_point(I)::coord(v[0] + 1); - double yb = img(point1d(xb)); + vsum yb = img(point1d(xb)); // Taylor-young - return ya + (x - xa) * (yb - ya) / (xb - xa); + return convert::to<mln_value(I)> + (ya + (x - xa) * (yb - ya) / (xb - xa)); } + + const I& ima; }; template < typename I > struct bilinear - : public Function_x2x< bilinear<I> > + : public fun::internal::selector_<const algebra::vec<3,float>, + // 3,float is a dummy parameter (real is n,T) + mln_value(I), linear<I> >::ret { typedef mln_value(I) result; - template <typename V> + bilinear(const I& ima) : ima(ima) {} + + template <unsigned n, typename T> mln_value(I) - operator()(const I& img, const V& v) const + operator()(const I& img, const algebra::vec<n,T>& v) const { + typedef mln_sum(mln_value(I)) vsum; + // q12----r2----q22 // | | | // | x | @@ -90,17 +112,20 @@ point2d q22 = point2d(x2, y2); // linear interpolation #1 - mln_value(I) img_r1 = img(q11) * (x2 - x) / (x2 - x1) + + vsum img_r1 = img(q11) * (x2 - x) / (x2 - x1) + img(q21) * (x - x1) / (x2 - x1); // linear interpolation #2 - mln_value(I) img_r2 = img(q12) * (x2 - x) / (x2 - x1) + + vsum img_r2 = img(q12) * (x2 - x) / (x2 - x1) + img(q22) * (x - x1) / (x2 - x1); // interpolating in y direction - return img_r1 * (y2 - y) / (y2 -y1) - + img_r2 * (y - y1) /(y2 - y1); + return convert::to<mln_value(I)> + (img_r1 * (y2 - y) / (y2 -y1) + + img_r2 * (y - y1) /(y2 - y1)); } + + const I& ima; }; } @@ -109,11 +134,12 @@ template <typename I, typename T, typename F> mln_value(I) - access(const I& img, const mln_point(I)& p, + access(const I& img, const point2d& p, const T& trans, const F& interp) { - mlc_is(typename T::invert, Bijection_x2x<typename T::invert>)::check(); - mlc_is(F, Function_x2x<F>)::check(); + mlc_is(typename T::invert, + Bijection_x2x<typename T::invert>)::check(); + mlc_is(F, Function<F>)::check(); return interp(img, (trans.inv())(p)); } Index: jardonnet/virtual/access.cc --- jardonnet/virtual/access.cc (revision 2201) +++ jardonnet/virtual/access.cc (working copy) @@ -1,7 +1,7 @@ #include <iostream> #include "access.hh" -#include <mln/core/image2d.hh> +#include <mln/core/image/image2d.hh> #include <mln/fun/x2x/all.hh> #include <mln/debug/iota.hh> #include <mln/algebra/vec.hh> @@ -13,7 +13,7 @@ point2d p(5,5); algebra::vec<2,float> v = make::vec(3,4); fun::x2x::translation<2,float> t(v); - interpolation::nearest_neighbor< image2d<int> > nn; + interpolation::nearest_neighbor< image2d<int> > nn(img); debug::iota(img);