* mln/core/concept/gdpoint.hh,
* mln/core/concept/gpoint.hh: make to_vec return a new object.
* mln/core/dpoint.hh,
* mln/core/point.hh: make to_vec return a vector of float with
coordinates ordered as a user would expect, (x,y,z...).
* mln/fun/x2v/bilinear.hh,
* mln/fun/x2v/trilinear.hh: get the coordinates in the proper vector
index.
* mln/fun/x2x/rotation.hh: normalize the axis.
* tests/algebra/h_vec.cc,
* tests/core/alias/dpoint3d.cc,
* tests/core/alias/point1d.cc: fix tests according these changes.
---
milena/ChangeLog | 21 +++++++
milena/mln/core/concept/gdpoint.hh | 2 +-
milena/mln/core/concept/gpoint.hh | 2 +-
milena/mln/core/dpoint.hh | 34 +++++++++--
milena/mln/core/point.hh | 113 +++++++++++++++++++----------------
milena/mln/fun/x2v/bilinear.hh | 8 +-
milena/mln/fun/x2v/trilinear.hh | 6 +-
milena/mln/fun/x2x/rotation.hh | 6 +-
milena/tests/algebra/h_vec.cc | 14 ++--
milena/tests/core/alias/dpoint3d.cc | 2 +-
milena/tests/core/alias/point1d.cc | 12 ++--
11 files changed, 137 insertions(+), 83 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 401a2a6..ce02eb9 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,26 @@
2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Reorder data in the vector returned by to_vec().
+
+ * mln/core/concept/gdpoint.hh,
+ * mln/core/concept/gpoint.hh: make to_vec return a new object.
+
+ * mln/core/dpoint.hh,
+ * mln/core/point.hh: make to_vec return a vector of float with
+ coordinates ordered as a user would expect, (x,y,z...).
+
+ * mln/fun/x2v/bilinear.hh,
+ * mln/fun/x2v/trilinear.hh: get the coordinates in the proper vector
+ index.
+
+ * mln/fun/x2x/rotation.hh: normalize the axis.
+
+ * tests/algebra/h_vec.cc,
+ * tests/core/alias/dpoint3d.cc,
+ * tests/core/alias/point1d.cc: fix tests according these changes.
+
+2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Revert patch #3397.
* mln/algebra/quat.hh,
diff --git a/milena/mln/core/concept/gdpoint.hh b/milena/mln/core/concept/gdpoint.hh
index 5a5695e..62408e1 100644
--- a/milena/mln/core/concept/gdpoint.hh
+++ b/milena/mln/core/concept/gdpoint.hh
@@ -166,7 +166,7 @@ namespace mln
{
typedef mln_grid(E) grid;
typedef mln_vec(E) vec;
- const vec& (E::*m)() const = & E::to_vec;
+ vec (E::*m)() const = & E::to_vec;
m = 0;
}
diff --git a/milena/mln/core/concept/gpoint.hh b/milena/mln/core/concept/gpoint.hh
index 12f1b38..40a2420 100644
--- a/milena/mln/core/concept/gpoint.hh
+++ b/milena/mln/core/concept/gpoint.hh
@@ -281,7 +281,7 @@ namespace mln
typedef mln_grid(E) grid;
typedef mln_delta(E) delta;
typedef mln_vec(E) vec;
- const vec& (E::*m)() const = & E::to_vec;
+ vec (E::*m)() const = & E::to_vec;
m = 0;
}
diff --git a/milena/mln/core/dpoint.hh b/milena/mln/core/dpoint.hh
index 17245c5..358013c 100644
--- a/milena/mln/core/dpoint.hh
+++ b/milena/mln/core/dpoint.hh
@@ -125,7 +125,7 @@ namespace mln
operator mln::algebra::vec<dpoint<G,C>::dim, Q>() const;
/// Explicit conversion.
- const vec& to_vec() const;
+ vec to_vec() const;
protected:
mln::algebra::vec<G::dim, C> coord_;
@@ -161,7 +161,17 @@ namespace mln
inline
dpoint<G,C>::dpoint(const algebra::vec<dim,C2>& v)
{
- coord_ = v;
+ // FIXME: to be improved.
+ if (dim < 3)
+ coord_ = v;
+ else
+ {
+ unsigned j = 0;
+ for (unsigned i = dim - 2; i < dim; ++i)
+ coord_[i] = v[j++];
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ coord_[i-j] = v[j];
+ }
}
template <typename G, typename C>
@@ -249,15 +259,29 @@ namespace mln
inline
dpoint<G,C>::operator mln::algebra::vec<dpoint<G,C>::dim, Q> ()
const
{
- return coord_;
+ return to_vec();
}
template <typename G, typename C>
inline
- const typename dpoint<G,C>::vec&
+ typename dpoint<G,C>::vec
dpoint<G,C>::to_vec() const
{
- return coord_;
+ algebra::vec<G::dim, float> tmp;
+
+ // FIXME: to be improved.
+ if (dim == 1)
+ tmp[0] = coord_[0];
+ else
+ {
+ unsigned j = 0;
+ for (unsigned i = dim - 2; i < dim; ++i)
+ tmp[j++] = coord_[i];
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ tmp[j] = coord_[i-j];
+ }
+
+ return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/core/point.hh b/milena/mln/core/point.hh
index a661fe5..755f50c 100644
--- a/milena/mln/core/point.hh
+++ b/milena/mln/core/point.hh
@@ -61,22 +61,6 @@ namespace mln
/// \}
- namespace internal
- {
-
- // Helper point_to_.
-
- template <typename G, typename C>
- struct point_to_
- {
- typedef algebra::vec<G::dim, C> metal_vec;
- typedef mln::algebra::h_vec<G::dim, C> h_vec;
- };
-
- } // end of namespace mln::internal
-
-
-
/// Generic point class.
///
/// Parameters are \c n the dimension of the space and \c C the
@@ -108,10 +92,10 @@ namespace mln
typedef C coord;
/// Algebra vector (vec) associated type.
- typedef algebra::vec<G::dim, C> vec;
+ typedef algebra::vec<G::dim, float> vec;
/// Algebra hexagonal vector (hvec) associated type.
- typedef algebra::h_vec<G::dim, C> h_vec;
+ typedef algebra::h_vec<G::dim, float> h_vec;
/// Read-only access to the \p i-th coordinate value.
/// \param[in] i The coordinate index.
@@ -171,23 +155,16 @@ namespace mln
/// Shifting by \p the inverse of dp.
point<G,C>& operator-=(const delta& dp);
- /// Hook to coordinates.
- operator typename internal::point_to_<G, C>::metal_vec () const;
- /* FIXME: Seems highly non-generic! Moreover, causes
- overloading/duplicate errors with the previous operator when
- C == float. Disable it for the moment.
-
+ /* FIXME: Seems highly non-generic!
This (non documented change, even in ChangeLog) change was
introduce by revision 1224, see
https://trac.lrde.org/olena/changeset/1224#file2
https://www.lrde.epita.fr/pipermail/olena-patches/2007-October/001592.html
*/
-#if 0
operator algebra::vec<G::dim, float> () const;
-#endif
/// Explicit conversion towards mln::algebra::vec.
- const vec& to_vec() const;
+ vec to_vec() const;
/// Transform to point in homogene coordinate system.
h_vec to_h_vec() const;
@@ -214,7 +191,8 @@ namespace mln
template <typename G, typename C, typename E>
struct subject_point_impl< point<G,C>, E >
{
- const typename point<G,C>::vec& to_vec() const;
+ typename point<G,C>::vec to_vec() const;
+ operator algebra::vec<G::dim, float>() const;
private:
const E& exact_() const;
@@ -281,7 +259,17 @@ namespace mln
inline
point<G,C>::point(const algebra::vec<dim,C2>& v)
{
- coord_ = v;
+ unsigned j = 0;
+ //FIXME: to be improved.
+ if (dim < 3)
+ coord_ = v;
+ else
+ {
+ for (unsigned i = dim - 2; i < dim; ++i)
+ coord_[i] = v[j++];
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ coord_[i-j] = v[j];
+ }
}
template <typename G, typename C>
@@ -406,29 +394,29 @@ namespace mln
template <typename G, typename C>
inline
- point<G,C>::operator typename internal::point_to_<G, C>::metal_vec ()
const
- {
- return coord_; // FIXME: Is it OK?
- }
-
- // FIXME: See declaration of this member above.
-#if 0
- template <typename G, typename C>
- inline
point<G,C>::operator algebra::vec<G::dim, float> () const
{
- algebra::vec<dim, float> tmp;
- for (unsigned int i = 0; i < dim; ++i)
- tmp[i] = coord_[i];
- return tmp;
+ return to_vec();
}
-#endif
template <typename G, typename C>
inline
- const typename point<G,C>::vec&
+ typename point<G,C>::vec
point<G,C>::to_vec() const
{
+ //FIXME: to be improved.
+ if (dim > 2)
+ {
+ algebra::vec<G::dim, float> tmp;
+ unsigned j = 0;
+ for (unsigned i = dim - 2; i < dim; ++i)
+ tmp[j++] = coord_[i];
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ tmp[j] = coord_[i-j];
+
+ return tmp;
+ }
+
return coord_;
}
@@ -437,10 +425,23 @@ namespace mln
typename point<G,C>::h_vec
point<G,C>::to_h_vec() const
{
- algebra::h_vec<G::dim, C> tmp;
- for (unsigned i = 0; i < dim; ++i)
- tmp[i] = coord_[i];
- tmp[G::dim] = 1;
+ algebra::h_vec<G::dim, float> tmp;
+
+ //FIXME: to be improved.
+ if (dim == 1)
+ tmp[0] = coord_[0];
+ else
+ {
+ unsigned j = 0;
+ for (unsigned i = dim - 2; i < dim; ++i)
+ tmp[j++] = coord_[i];
+
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ tmp[j] = coord_[i-j];
+
+ tmp[G::dim] = 1;
+ }
+
return tmp;
}
@@ -476,20 +477,27 @@ namespace mln
template <typename G, typename C, typename E>
inline
- const typename point<G,C>::vec&
+ typename point<G,C>::vec
subject_point_impl< point<G,C>, E >::to_vec() const
{
return exact_().get_subject().to_vec();
}
+ template <typename G, typename C, typename E>
+ inline
+ subject_point_impl< point<G,C>, E >::operator algebra::vec<G::dim,
float>() const
+ {
+ return exact_().get_subject();
+ }
+
} // end of namespace mln::internal
template <typename G, typename C>
inline
- const algebra::vec<point<G,C>::dim - 1, C>&
+ algebra::vec<point<G,C>::dim - 1, C>
cut_(const point<G,C>& p)
{
- return *(const algebra::vec<point<G,C>::dim - 1, C>*)(& p.to_vec());
+ return *(algebra::vec<point<G,C>::dim - 1, C>*)(& p.to_vec());
}
template <typename C>
@@ -502,7 +510,8 @@ namespace mln
}
# endif // ! MLN_INCLUDE_ONLY
-
+
+
} // end of namespace mln
diff --git a/milena/mln/fun/x2v/bilinear.hh b/milena/mln/fun/x2v/bilinear.hh
index e264462..1daefa8 100644
--- a/milena/mln/fun/x2v/bilinear.hh
+++ b/milena/mln/fun/x2v/bilinear.hh
@@ -79,7 +79,7 @@ namespace mln
template <typename I>
bilinear<I>::bilinear(const I& ima) : ima(ima)
{
- //mlc_bool(I::psite::dim == 2)::check();
+ mlc_or(mlc_bool(I::psite::dim == 2), mlc_bool(I::psite::dim == 3))::check();
}
template <typename I>
@@ -141,14 +141,14 @@ namespace mln
// | | |
// q11----r1----q21
- double x = v[1];
- double y = v[2];
+ double x = v[0];
+ double y = v[1];
double x1 = std::floor(x);
double x2 = std::floor(x) + 1;
double y1 = std::floor(y);
double y2 = std::floor(y) + 1;
- def::coord z = math::round<float>()(v[0]);
+ def::coord z = math::round<float>()(v[3]);
//Following access are supposed valid.
vsum q11 = ima(point3d(z, static_cast<unsigned>(x1),
static_cast<unsigned>(y1)));
diff --git a/milena/mln/fun/x2v/trilinear.hh b/milena/mln/fun/x2v/trilinear.hh
index 3015502..2a1d594 100644
--- a/milena/mln/fun/x2v/trilinear.hh
+++ b/milena/mln/fun/x2v/trilinear.hh
@@ -86,9 +86,9 @@ namespace mln
{
typedef mln_sum(mln_value(I)) vsum;
- double x = v[1]; // row
- double y = v[2]; // col
- double z = v[0]; // sli
+ double x = v[0]; // row
+ double y = v[1]; // col
+ double z = v[2]; // sli
math::round<double> f;
unsigned x1 = f(std::floor(x));
diff --git a/milena/mln/fun/x2x/rotation.hh b/milena/mln/fun/x2x/rotation.hh
index 9addb50..cbe1dd2 100644
--- a/milena/mln/fun/x2x/rotation.hh
+++ b/milena/mln/fun/x2x/rotation.hh
@@ -197,10 +197,9 @@ namespace mln
inline
rotation<n,C>::rotation(const algebra::quat& q)
{
- mln_precondition(q.is_unit());
-
// FIXME: Should also work for 2d.
- mln_precondition(n == 3);
+ mlc_bool(n == 3)::check();
+ mln_precondition(q.is_unit());
float
w = q.to_vec()[0],
@@ -221,6 +220,7 @@ namespace mln
axis_[0] = x;
axis_[1] = y;
axis_[2] = z;
+ axis_.normalize();
}
diff --git a/milena/tests/algebra/h_vec.cc b/milena/tests/algebra/h_vec.cc
index e4bffa6..27448e3 100644
--- a/milena/tests/algebra/h_vec.cc
+++ b/milena/tests/algebra/h_vec.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,10 +26,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/algebra/h_vec.cc
- *
- * \brief Tests on mln::algebra::h_vec.
- */
+/// \file tests/algebra/h_vec.cc
+///
+/// Tests on mln::algebra::h_vec.
#include <mln/algebra/h_vec.hh>
#include <mln/core/alias/point3d.hh>
@@ -36,11 +36,11 @@
using namespace mln;
-void run_in_3d(const algebra::vec<3, def::coord>&)
+void run_in_3d(const algebra::vec<3, float>&)
{
}
-void run_in_3d_h(const algebra::h_vec<3, def::coord>&)
+void run_in_3d_h(const algebra::h_vec<3, float>&)
{
}
diff --git a/milena/tests/core/alias/dpoint3d.cc b/milena/tests/core/alias/dpoint3d.cc
index 20bcbaf..d538f1b 100644
--- a/milena/tests/core/alias/dpoint3d.cc
+++ b/milena/tests/core/alias/dpoint3d.cc
@@ -49,5 +49,5 @@ int main()
mln_assertion(q == p + dp);
algebra::vec<3, float> v = dp;
- mln_assertion(v[1] == 6);
+ mln_assertion(v[0] == 6);
}
diff --git a/milena/tests/core/alias/point1d.cc b/milena/tests/core/alias/point1d.cc
index fbe8e72..cbcda23 100644
--- a/milena/tests/core/alias/point1d.cc
+++ b/milena/tests/core/alias/point1d.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,10 +26,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/core/alias/point1d.cc
- *
- * \brief Tests on mln::point1d.
- */
+/// \file tests/core/alias/point1d.cc
+///
+/// Tests on mln::point1d.
#include <mln/core/alias/point1d.hh>
@@ -43,7 +43,7 @@ int main()
// assignment
p[0] = 4;
- algebra::vec<1,def::coord> v = p;
+ algebra::vec<1,float> v = p;
p.ind() += 1;
mln_assertion(p.ind() == 5 && p[0] == 5);
--
1.5.6.5