https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Sandbox: Update access.hh.
After Theo:
* jardonnet/virtual/access.hh: Concept check, Type sum ...
* jardonnet/virtual/access.cc: Update testes.
access.cc | 2 +-
access.hh | 60 +++++++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 44 insertions(+), 18 deletions(-)
Index: jardonnet/virtual/access.hh
--- jardonnet/virtual/access.hh (revision 2187)
+++ jardonnet/virtual/access.hh (working copy)
@@ -5,6 +5,8 @@
# include <mln/core/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_point(I) p = convert::to<mln_point(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;
};
}
@@ -112,8 +137,9 @@
access(const I& img, const mln_point(I)& 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 2187)
+++ jardonnet/virtual/access.cc (working copy)
@@ -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);