https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix registration. Clean up fun.
* mln/fun/x2x/interpol/bilinear.hh,
* mln/fun/x2x/interpol/linear.hh,
* mln/fun/x2x/interpol/nneighbor.hh: Move ...
* mln/fun/x2v/bilinear.hh,
* mln/fun/x2v/linear.hh,
* mln/fun/x2v/nneighbor.hh: ... here.
* mln/fun/x2x/geom/composed.hh,
* mln/fun/x2x/geom/translation.hh,
* mln/fun/x2x/geom/rotation.hh: Move ...
* mln/fun/x2x/composed.hh,
* mln/fun/x2x/translation.hh,
* mln/fun/x2x/rotation.hh: ... here.
* mln/fun/x2p: New.
* mln/fun/x2p/closest_point.hh: Add a functor that return the closest
point of a vector x in a given p_array.
* mln/registration/multiscale.hh: Fix use of p_array.
* mln/registration/registration.hh: Make use of fun::x2p::closest_point.
* mln/registration/icp.hh: Add buffers.
fun/x2p/closest_point.hh | 96 +++++++++++++++++++++++++++++++++++++++++++
fun/x2v/bilinear.hh | 14 +-----
fun/x2v/linear.hh | 12 +----
fun/x2v/nneighbor.hh | 13 +----
fun/x2x/composed.hh | 28 ++++--------
fun/x2x/rotation.hh | 6 --
fun/x2x/translation.hh | 6 --
registration/icp.hh | 43 ++++++++++++++++++-
registration/multiscale.hh | 19 +++++---
registration/registration.hh | 8 ++-
10 files changed, 176 insertions(+), 69 deletions(-)
Index: mln/fun/x2v/bilinear.hh
--- mln/fun/x2v/bilinear.hh (revision 0)
+++ mln/fun/x2v/bilinear.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_FUN_X2X_INTERPOL_BILINEAR_HH
-# define MLN_FUN_X2X_INTERPOL_BILINEAR_HH
+#ifndef MLN_FUN_X2X_BILINEAR_HH
+# define MLN_FUN_X2X_BILINEAR_HH
# include <mln/core/image/image2d.hh>
# include <mln/core/concept/function.hh>
@@ -34,7 +34,7 @@
# include <mln/convert/to.hh>
# include <mln/algebra/vec.hh>
-/*! \file mln/fun/x2x/interpol/bilinear.hh
+/*! \file mln/fun/x2x/bilinear.hh
*
* \brief Define a bilinear interpolation of values from an underlying image
*/
@@ -48,10 +48,6 @@
namespace x2x
{
- namespace interpol
- {
-
-
/*! \brief Represent a bilinear interolation of values from an underlying image
*
*/
@@ -129,8 +125,6 @@
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::fun::x2x::interpol
-
} // end of namespace mln::fun::x2x
} // end of namespace mln::fun
@@ -138,4 +132,4 @@
} // end of namespace mln
-#endif // ! MLN_FUN_X2X_INTERPOL_BILINEAR_HH
+#endif // ! MLN_FUN_X2X_BILINEAR_HH
Index: mln/fun/x2v/linear.hh
--- mln/fun/x2v/linear.hh (revision 0)
+++ mln/fun/x2v/linear.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_FUN_X2X_INTERPOL_LINEAR_HH
-# define MLN_FUN_X2X_INTERPOL_LINEAR_HH
+#ifndef MLN_FUN_X2X_LINEAR_HH
+# define MLN_FUN_X2X_LINEAR_HH
-/*! \file mln/fun/x2x/interpol/linear.hh
+/*! \file mln/fun/x2x/linear.hh
*
* \brief Define a linear interpolation of values from an underlying image
*/
@@ -48,10 +48,6 @@
namespace x2x
{
- namespace interpol
- {
-
-
/*! \brief Represent a linear interolation of values from an underlying image
*
*/
@@ -114,8 +110,6 @@
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::fun::x2x::interpol
-
} // end of namespace mln::fun::x2x
} // end of namespace mln::fun
Index: mln/fun/x2v/nneighbor.hh
--- mln/fun/x2v/nneighbor.hh (revision 0)
+++ mln/fun/x2v/nneighbor.hh (working copy)
@@ -25,15 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_FUN_X2X_INTERPOL_NNEIGHBOR_HH
-# define MLN_FUN_X2X_INTERPOL_NNEIGHBOR_HH
+#ifndef MLN_FUN_X2X_NNEIGHBOR_HH
+# define MLN_FUN_X2X_NNEIGHBOR_HH
# include <mln/core/concept/function.hh>
# include <mln/fun/internal/selector.hh>
# include <mln/algebra/vec.hh>
# include <mln/convert/to.hh>
-/*! \file mln/fun/x2x/interpol/nneighbor.hh
+/*! \file mln/fun/x2x/nneighbor.hh
*
* \brief Define a nneighbor interpolation of values from an underlying image
*/
@@ -47,9 +47,6 @@
namespace x2x
{
- namespace interpol
- {
-
template < typename I >
struct nneighbor
: public fun::internal::selector_<const algebra::vec<3,float>,
@@ -87,8 +84,6 @@
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::fun::x2x::interpol
-
} // end of namespace mln::fun::x2x
} // end of namespace mln::fun
@@ -96,4 +91,4 @@
} // end of namespace mln
-#endif // ! MLN_FUN_X2X_INTERPOL_NNEIGHBOR_HH
+#endif // ! MLN_FUN_X2X_NNEIGHBOR_HH
Index: mln/fun/x2x/composed.hh
--- mln/fun/x2x/composed.hh (revision 2536)
+++ mln/fun/x2x/composed.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_FUN_X2X_GEOM_COMPOSED_HH
-# define MLN_FUN_X2X_GEOM_COMPOSED_HH
+#ifndef MLN_FUN_X2X_COMPOSED_HH
+# define MLN_FUN_X2X_COMPOSED_HH
-/*! \file mln/fun/x2x/geom/composed.hh
+/*! \file mln/fun/x2x/composed.hh
*
* \brief Definition of a composed transformation.
*/
@@ -50,9 +50,6 @@
namespace x2x
{
- namespace geom
- {
-
// Fwd decl.
template <typename F, typename G>
struct composed;
@@ -124,7 +121,7 @@
G g_;
};
- } // end of namespace mln::fun::x2x::geom::internal
+ } // end of namespace mln::fun::x2x::internal
/*! \brief Represent a composition of two transformations.
@@ -151,8 +148,6 @@
}
};
- } // end of namespace mln::fun::x2x::geom
-
} // end of namespace mln::fun::x2x
} // end of namespace mln::fun
@@ -166,7 +161,7 @@
* \return The composed transformation fog.
*/
template <typename F, typename G>
- fun::x2x::geom::composed<F,G> compose(F f, G g);
+ fun::x2x::composed<F,G> compose(F f, G g);
# ifndef MLN_INCLUDE_ONLY
@@ -176,9 +171,6 @@
namespace x2x
{
- namespace geom
- {
-
namespace internal
{
@@ -259,9 +251,7 @@
this->m_ = this->f_.mat() * this->g_.mat();
}
- } // end of namespace mln::fun::x2x::geom::internal
-
- } // end of namespace mln::fun::x2x::geom
+ } // end of namespace mln::fun::x2x::internal
} // end of namespace mln::fun::x2x
@@ -269,10 +259,10 @@
template <typename F, typename G>
inline
- fun::x2x::geom::composed<F,G> compose(F f, G g)
+ fun::x2x::composed<F,G> compose(F f, G g)
{
trace::entering("fun::x2x::compose");
- fun::x2x::geom::composed<F,G> comp(f, g);
+ fun::x2x::composed<F,G> comp(f, g);
trace::exiting("fun::x2x::compose");
return comp;
}
@@ -282,4 +272,4 @@
} // end of namespace mln
-#endif // ! MLN_FUN_X2X_GEOM_COMPOSED_HH
+#endif // ! MLN_FUN_X2X_COMPOSED_HH
Index: mln/fun/x2x/translation.hh
--- mln/fun/x2x/translation.hh (revision 2536)
+++ mln/fun/x2x/translation.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef MLN_FUN_X2X_TRANSLATION_HH
# define MLN_FUN_X2X_TRANSLATION_HH
-/*! \file mln/fun/x2x/geom/translation.hh
+/*! \file mln/fun/x2x/translation.hh
*
* \brief Define a translation function.
*/
@@ -48,9 +48,6 @@
namespace x2x
{
- namespace geom
- {
-
/*! \brief Represent a translation function.
*
*/
@@ -140,7 +137,6 @@
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::fun::x2x::geom
} // end of namespace mln::fun::x2x
Index: mln/fun/x2x/rotation.hh
--- mln/fun/x2x/rotation.hh (revision 2536)
+++ mln/fun/x2x/rotation.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef MLN_FUN_X2X_ROTATION_HH
# define MLN_FUN_X2X_ROTATION_HH
-/*! \file mln/fun/x2x/geom/rotation.hh
+/*! \file mln/fun/x2x/rotation.hh
*
* \brief Define a rotation function.
*/
@@ -48,9 +48,6 @@
namespace x2x
{
- namespace geom
- {
-
namespace internal
{
template < unsigned n, typename C >
@@ -231,7 +228,6 @@
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::fun::x2x::geom
} // end of namespace mln::fun::x2x
Index: mln/fun/x2p/closest_point.hh
--- mln/fun/x2p/closest_point.hh (revision 0)
+++ mln/fun/x2p/closest_point.hh (revision 0)
@@ -0,0 +1,96 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_FUN_X2P_CLOSEST_POINT_HH
+# define MLN_FUN_X2P_CLOSEST_POINT_HH
+
+# include <mln/algebra/vec.hh>
+# include <mln/norm/l2.hh>
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace x2p
+ {
+
+ ///FIXME: doxygen + concept checking
+ template <typename P>
+ struct closest_point
+ {
+ typedef algebra::vec<P::dim, float> input;
+ typedef P result;
+
+ closest_point(const p_array<P>& X, const box<P>& box)
+ : X(X), box(box)
+ , log_functor_call(0)
+
+ { }
+
+ result
+ //inline
+ operator () (const input& Ck) const
+ {
+ ++log_functor_call;
+
+ 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.nsites(); ++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 convert::to<P>(best_x);
+ }
+
+ const box<P>& domain() const
+ {
+ return box;
+ }
+
+ const p_array<P>& X;
+ const box<P> box;
+
+ // log call to the functor
+ mutable unsigned log_functor_call;
+ };
+
+ } // end of namespace mln::fun::x2p
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+#endif // ! MLN_FUN_X2P_CLOSEST_POINT_HH
Index: mln/registration/multiscale.hh
--- mln/registration/multiscale.hh (revision 2536)
+++ mln/registration/multiscale.hh (working copy)
@@ -29,6 +29,7 @@
# define MLN_REGISTRATION_MULTISCALE_HH
# include <mln/registration/icp.hh>
+# include <mln/fun/x2p/closest_point.hh>
namespace mln
{
@@ -52,22 +53,25 @@
template <typename I, typename J>
inline
- composed< rotation<P::dim, float>, translation<P::dim, float> >
+ composed< rotation<I::site::dim, float>, translation<I::site::dim,
float> >
multiscale_(const Image<I>& cloud,
const Image<J>& surface,
const float q,
const unsigned nb_it)
{
+ p_array<mln_psite(I)> c = convert::to< p_array<mln_psite(I)>
>(cloud);
+ p_array<mln_psite(J)> x = convert::to< p_array<mln_psite(I)>
>(surface);
+
// Shuffle cloud
- shuffle(cloud);
+ shuffle(c);
//working box
const box<point2d> working_box =
enlarge(bigger(geom::bbox(c), geom::bbox(x)), 100);
//make a lazy_image map via function closest_point
- closest_point<mln_psite_(image2db)> fun(x, working_box); //FIXME: to port
- lazy_image<image2d<bool>, closest_point<mln_psite_(image2db)>,
box2d >
+ fun::x2p::closest_point<mln_psite(I)> fun(x, working_box);
+ lazy_image<I, fun::x2p::closest_point<mln_psite(I)>, box2d >
map(fun, fun.domain());
//init rigid transform qk
@@ -87,7 +91,7 @@
template <typename I, typename J>
inline
- composed< rotation<P::dim, float>, translation<P::dim, float> >
+ composed< rotation<I::site::dim, float>, translation<I::site::dim,
float> >
multiscale(const Image<I>& cloud,
const Image<J>& surface,
const float q,
@@ -95,9 +99,10 @@
{
trace::entering("registration::registration");
- mln_precondition(P::dim == 3 || P::dim == 2);
+ mln_precondition(I::site::dim == 3 || I::site::dim == 2);
- impl::multiscale_(cloud, surface, q, nb_it);
+ composed< rotation<I::site::dim, float>, translation<I::site::dim,
float> >
+ qk = impl::multiscale_(cloud, surface, q, nb_it);
trace::exiting("registration::registration");
Index: mln/registration/registration.hh
--- mln/registration/registration.hh (revision 2536)
+++ mln/registration/registration.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/registration/icp.hh>
+# include <mln/fun/x2p/closest_point.hh>
# include <mln/core/image/lazy_image.hh>
namespace mln
@@ -76,12 +77,13 @@
enlarge(bigger(geom::bbox(c), geom::bbox(x)), 100);
//make a lazy_image map via function closest_point
- closest_point<mln_psite(I)> fun(x, working_box); //FIXME: to port
- lazy_image<mln_ch_value(I,bool), closest_point<mln_psite(I)>, box2d
>
+ fun::x2p::closest_point<mln_psite(I)> fun(x, working_box);
+ lazy_image<I, fun::x2p::closest_point<mln_psite(I)>, box2d>
map(fun, fun.domain());
+
//run registration
- registration::icp(c, map, qk, l, 1e-3);
+ registration::icp(c, map, qk, c.nsites(), 1e-3);
}
Index: mln/registration/icp.hh
--- mln/registration/icp.hh (revision 2536)
+++ mln/registration/icp.hh (working copy)
@@ -38,6 +38,45 @@
namespace mln
{
+ namespace util
+ {
+
+ // FIXME: Remove use of this class
+ template <unsigned int n, typename T>
+ struct buffer
+ {
+ buffer()
+ : setted(0)
+ {
+ }
+
+ void store(T e)
+ {
+ for (unsigned i = 0; i < n-1; i++)
+ buf[i+1] = buf[i];
+ buf[0] = e;
+
+ setted++;
+ }
+
+ T& operator[](unsigned int i)
+ {
+ assert(i < n && i < setted);
+ return buf[i];
+ }
+
+ const T * get_array()
+ {
+ return buf;
+ }
+
+ private:
+ T buf[n];
+ unsigned int setted;
+ };
+
+ } // end of namespace mln::util
+
namespace registration
{
@@ -88,8 +127,8 @@
{
trace::entering("registration::impl::icp_");
- buffer<4,T> buf_qk;
- buffer<3,float> buf_dk;
+ util::buffer<4,T> buf_qk;
+ util::buffer<3,float> buf_dk;
float d_k = 10000;
p_array<P> Ck(c);