
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Sandbox: ICP: Improve lazy_image implementation. * sandbox/jardonnet/test/Makefile: Add rules for the lazy version. * sandbox/jardonnet/registration/icp_map.hh: New dedicated version to map. * sandbox/jardonnet/registration/icp_lazy.hh: Rename lazy_map as lazy_image. Improve implementation. * sandbox/jardonnet/registration/icp.hh (icp_): Refactoring. * sandbox/jardonnet/registration/projection.hh (memo): Make a projection using the new lazy_image interface. * sandbox/jardonnet/registration/tools.hh (c_point): Add functor. registration/icp_lazy.hh | 2 registration/projection.hh | 28 ------------ registration/tools.hh | 103 ++++++++++++++++++++++++++++++++++----------- test/Makefile | 7 +-- test/icp_lazy.cc | 27 +++++++++++ 5 files changed, 110 insertions(+), 57 deletions(-) Index: sandbox/jardonnet/test/icp_lazy.cc --- sandbox/jardonnet/test/icp_lazy.cc (revision 1840) +++ sandbox/jardonnet/test/icp_lazy.cc (working copy) @@ -5,6 +5,33 @@ #include <sandbox/jardonnet/registration/icp_lazy.hh> +template <typename I> +class fun +{ + typedef mln_point(I) result; + + const operator () (mln_point(I)& p) + { + algebra::vec<P::dim,float> Cki = Ck[i]; + algebra::vec<P::dim,float> best_x = X[0]; + best_d = norm::l2(Cki - best_x); + for (size_t j = 1; j < X.npoints(); ++j) + { + algebra::vec<P::dim,float> Xj = X[j]; + float d = norm::l2(Cki - Xj); + if (d < best_d) + { + best_d = d; + best_x = Xj; + } + } + Xk.hook_()[i] = algebra::to_point<P>(best_x); + map.map(Ck[i]) = Xk[i]; + map.known(Ck[i]) = true; + } +} + + int main(int, char* argv[]) { using namespace mln; Index: sandbox/jardonnet/test/Makefile --- sandbox/jardonnet/test/Makefile (revision 1840) +++ sandbox/jardonnet/test/Makefile (working copy) @@ -16,12 +16,11 @@ run: time ./+sub.exe . . ; time ./+gsub.exe . . - icp: - g++ icp.cc -I../../.. -g -o '+icp_map.exe' + g++ icp.cc -I../../.. -g -o '+icp.exe' -icp++: - g++ icp.cc -I../../.. -O3 -DNDEBUG -pg -o '+icp_map.exe' +icp_max++: + g++ icp_max.cc -I../../.. -O3 -DNDEBUG -pg -o '+icp_map.exe' icp_lazy++: g++ icp_lazy.cc -I../../.. -O3 -DNDEBUG -pg -o '+icp_lazy.exe' Index: sandbox/jardonnet/registration/icp_lazy.hh --- sandbox/jardonnet/registration/icp_lazy.hh (revision 1840) +++ sandbox/jardonnet/registration/icp_lazy.hh (working copy) @@ -89,8 +89,6 @@ k = 0; do { - //std::cout << "step 2" << std::endl; - //// step 2 projection::memo(Ck, X, Xk, map); Index: sandbox/jardonnet/registration/projection.hh --- sandbox/jardonnet/registration/projection.hh (revision 1840) +++ sandbox/jardonnet/registration/projection.hh (working copy) @@ -69,37 +69,13 @@ template <typename P, typename T> void memo(const p_array<P>& Ck, - const p_array<P>& X, p_array<P>& Xk, - lazy_map<T>& map) // first: closest points, second: is_computed + lazy_image<T>& map) // first: closest points, second: is_computed { assert(Ck.npoints() == Xk.npoints()); for (size_t i = 0; i < Ck.npoints(); ++i) - { - float best_d; - if (map.known(Ck[i]) == false) - { - algebra::vec<P::dim,float> Cki = Ck[i]; - algebra::vec<P::dim,float> best_x = X[0]; - best_d = norm::l2(Cki - best_x); - for (size_t j = 1; j < X.npoints(); ++j) - { - algebra::vec<P::dim,float> Xj = X[j]; - float d = norm::l2(Cki - Xj); - if (d < best_d) - { - best_d = d; - best_x = Xj; - } - } - Xk.hook_()[i] = algebra::to_point<P>(best_x); - map.map(Ck[i]) = Xk[i]; - map.known(Ck[i]) = true; - } - else - Xk.hook_()[i] = map.map(Ck[i]); - } + Xk.hook_()[i] = map(Ck[i]); } } // end of namespace projection Index: sandbox/jardonnet/registration/tools.hh --- sandbox/jardonnet/registration/tools.hh (revision 1840) +++ sandbox/jardonnet/registration/tools.hh (working copy) @@ -10,43 +10,96 @@ namespace mln { - - //FIXME: Shall we use something *really* lazy - template <typename I> - struct lazy_map - { template <typename P> - lazy_map(const box_<P>& domain) - : map(domain), known(domain) - { } + struct c_point + { + typedef P input; + typedef P result; - lazy_map(int nrows, int ncols, int bdr = 3) - : map(nrows, ncols, bdr), known(nrows,ncols,bdr) + c_point(const p_array<P>& X) + : X(X) { } - mln_ch_value(I, mln_point(I)) map; - mln_ch_value(I, bool) known; - }; + result + //inline + operator () (const P& Ck) + { + algebra::vec<P::dim,float> Cki = Ck; + algebra::vec<P::dim,float> best_x = X[0]; + float best_d = norm::l2(Cki - best_x); + for (size_t j = 1; j < X.npoints(); ++j) + { + algebra::vec<P::dim,float> Xj = X[j]; + float d = norm::l2(Cki - Xj); + if (d < best_d) + { + best_d = d; + best_x = Xj; + } + } + return algebra::to_point<P>(best_x); + } + const box_<P> domain() + { + return X.bbox(); + } - // Point + const p_array<P>& X; + }; - template <typename P> - P min(const P& a, const P& b) + + // FIXME: Should be a morpher ? + // we could acces domain of a lazy map, iterator etc... + template < typename F> + struct lazy_image + { + // Fun is potentially an image. + lazy_image(F& fun) + : value(fun.domain()), is_known(fun.domain()), functor(fun) { - if (a > b) - return b; - return a; } - template <typename P> - P max(const P& a, const P& b) - { - if (a < b) - return b; - return a; + // FIXME: remove this constructor + lazy_image(const F& fun, int nrows, int ncols) + : value(nrows, ncols), is_known(nrows,ncols), functor(fun) + { } + + const mln_result(F) + //inline + operator() (const typename F::input& p) + { + if (is_known(p)) + return value(p); + value(p) = functor(p); + return value(p); } + //FIXME: 3d -> //mln_dim(ml_input(input)) + image3d<mln_result(F)> value; + image3d<bool> is_known; + F& functor; + }; + + +// // Point + +// template <typename P> +// P min(const P& a, const P& b) +// { +// if (a > b) +// return b; +// return a; +// } + +// template <typename P> +// P max(const P& a, const P& b) +// { +// if (a < b) +// return b; +// return a; +// } + // Box