https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Sandbox: Update metal::array.
* jardonnet/array/array.cc: Update Test.
* jardonnet/array/array.hh: Add stc/dyn getters.
* jardonnet/array/Makefile: New.
* jardonnet/test/icp.cc: .
* jardonnet/registration/tools.hh: .
array/Makefile | 2
array/array.cc | 12 ++++
array/array.hh | 121 +++++++++++++++++++++++++++++++++++++++++++++++++-
array/old/1d.hh | 4 -
registration/tools.hh | 58 ++++++-----------------
test/icp.cc | 1
6 files changed, 151 insertions(+), 47 deletions(-)
Index: jardonnet/test/icp.cc
--- jardonnet/test/icp.cc (revision 2161)
+++ jardonnet/test/icp.cc (working copy)
@@ -3,6 +3,7 @@
#include <mln/io/pbm/load.hh>
#include <mln/io/pbm/save.hh>
#include <mln/io/ppm/save.hh>
+#include <mln/convert/to_p_array.hh>
#include <mln/norm/l2.hh>
#include <sandbox/jardonnet/registration/icp.hh>
Index: jardonnet/registration/tools.hh
--- jardonnet/registration/tools.hh (revision 2161)
+++ jardonnet/registration/tools.hh (working copy)
@@ -193,23 +193,23 @@
namespace convert
{
- // to_p_array
- template <typename I>
- inline
- p_array<mln_point(I)>
- to_p_array(const Image<I>& img_)
- {
- const I& img = exact(img_);
-
- p_array<mln_point(I)> a;
-
- mln_piter(I) p(img.domain());
- for_all(p)
- if (img(p))
- a.append(p);
+// // to_p_array
+// template <typename I>
+// inline
+// p_array<mln_point(I)>
+// to_p_array(const Image<I>& img_)
+// {
+// const I& img = exact(img_);
+
+// p_array<mln_point(I)> a;
+
+// mln_piter(I) p(img.domain());
+// for_all(p)
+// if (img(p))
+// a.append(p);
- return a;
- }
+// return a;
+// }
template < typename P >
@@ -316,32 +316,6 @@
} // end of namespace convert
- namespace algebra
- {
-
- // transpose
- template<unsigned n, unsigned m, typename T>
- mat<m,n,T>
- trans(const mat<n,m,T>& matrice)
- {
- mat<m,n,T> tmp;
- for (unsigned i = 0; i < n; ++i)
- for (unsigned j = 0; j < m; ++j)
- tmp(j,i) = matrice(i,j);
- return tmp;
- }
-
- // trace
- template<unsigned n, typename T> inline
- float tr(const mat<n,n,T>& m)
- {
- float f = 0.f;
- for (unsigned i = 0; i < n; ++i)
- f += m(i,i);
- return f;
- }
-
- } // end of namespace algebra
} // end of namespace mln
Index: jardonnet/array/array.cc
--- jardonnet/array/array.cc (revision 2161)
+++ jardonnet/array/array.cc (working copy)
@@ -1,6 +1,6 @@
#include <iostream>
-#include <mln/metal/array.hh>
+#include "array.hh"
int main(int, char **)
{
@@ -9,4 +9,14 @@
mln::metal::array1d<int, 5> c;
c = a + b;
+
+ a.get<0>() = 0;
+ a.get<1>() = 1;
+ a.get<2>() = 2;
+ a.get<3>() = 3;
+
+ for (int i = 0 ; i < a.length; i++)
+ std::cout << a[i] << " ";
+
+ std::cout << std::endl;
}
Index: jardonnet/array/array.hh
--- jardonnet/array/array.hh (revision 2161)
+++ jardonnet/array/array.hh (working copy)
@@ -28,16 +28,47 @@
#ifndef MLN_METAL_ARRAY1D_HH
# define MLN_METAL_ARRAY1D_HH
+# include <mln/core/concept/object.hh>
+
# include <mln/trait/all.hh>
+# include <mln/trait/value_.hh>
+
+# include <mln/value/ops.hh>
namespace mln
{
+ // Fwd decls.
+ namespace metal {
+ template <typename T, unsigned Size> struct array1d;
+ }
+
+ namespace trait
+ {
+
+ template <typename T, unsigned Size>
+ struct value_< mln::metal::array1d<T,Size> >
+ {
+ typedef trait::value::nature::vectorial nature;
+ typedef trait::value::kind::data kind;
+
+ enum {
+ nbits = Size * mln_nbits(T),
+ card = Size * mln_card(T)
+ };
+ typedef mln_value_quant_from_(card) quant;
+
+ typedef metal::array1d<mln_sum(T),Size> sum;
+ };
+
+ } // end of namespace mln::trait
+
+
namespace metal
{
template <typename T, unsigned Size>
- struct array1d
+ struct array1d : public Object< array1d<T,Size> >
{
//
@@ -72,11 +103,99 @@
array1d<T, Size>&
operator-=(const array1d<T, Size>& rhs);
+
+ // dynamic accessors:
+
+ T operator[](unsigned i) const
+ {
+ mln_precondition(i < Size);
+ return buffer_[i];
+ }
+ T& operator[](unsigned i)
+ {
+ mln_precondition(i < Size);
+ return buffer_[i];
+ }
+
+ // static accessor
+
+ template<unsigned i>
+ T get() const {
+ return *(buffer_ + i);
+ }
+ template<unsigned i>
+ T& get() {
+ return *(buffer_ + i);
+ }
+
+ enum { length = Size };
protected:
T buffer_[Size];
};
+ }
+
+ namespace trait
+ {
+
+ // For unary traits.
+
+ template < template <class> class Name,
+ unsigned n, typename T >
+ struct set_precise_unary_< Name, metal::array1d<T, n> >
+ {
+ typedef mln_trait_unary(Name, T) V;
+ typedef metal::array1d<V, n> ret;
+ };
+
+ // For binary traits.
+
+ template < template <class, class> class Name,
+ unsigned n, typename T,
+ typename U >
+ struct set_precise_binary_< Name,
+ metal::array1d<T, n>, metal::array1d<U, n> >
+ {
+ typedef mln_trait_binary(Name, T, U) V;
+ typedef metal::array1d<V, n> ret;
+ };
+
+ template < unsigned n, typename T,
+ typename U >
+ struct set_precise_binary_< op::times,
+ metal::array1d<T, n>, metal::array1d<U, n> >
+ {
+ typedef mln_sum_x(T,U) ret;
+ };
+
+ template < template <class, class> class Name,
+ unsigned n, typename T,
+ typename S >
+ struct set_precise_binary_< Name,
+ metal::array1d<T, n>, mln::value::scalar_<S> >
+ {
+ typedef mln_trait_binary(Name, T, S) V;
+ typedef metal::array1d<V, n> ret;
+ };
+
+ template < template<class, class> class Name,
+ unsigned n, typename T,
+ typename S >
+ struct set_binary_< Name,
+ mln::Object, metal::array1d<T, n>,
+ mln::value::Scalar, S >
+ {
+ typedef mln_trait_binary(Name, T, S) V;
+ typedef metal::array1d<T, n> ret;
+ };
+
+ } // end of namespace mln::trait
+
+
+ namespace metal
+ {
+
//
// Constructors
//
Index: jardonnet/array/Makefile
--- jardonnet/array/Makefile (revision 0)
+++ jardonnet/array/Makefile (revision 0)
@@ -0,0 +1,2 @@
+all:
+ g++ array.cc -I../../..
\ No newline at end of file
Index: jardonnet/array/old/1d.hh
--- jardonnet/array/old/1d.hh (revision 2161)
+++ jardonnet/array/old/1d.hh (working copy)
@@ -236,9 +236,7 @@
template<int i>
T get_() const {
- lesseq<-Info_::center, i>::ensure();
- lesseq<i, Info_::card - Info_::center - 1>::ensure();
- return *(buffer_ + Info_::center + i);
+ return *(buffer_ + i);
}
protected: