
* mln/algebra/quat.hh, * mln/core/concept/gpoint.hh, * mln/core/point.hh, * mln/fun/x2v/bilinear.hh, * mln/fun/x2v/trilinear.hh, * mln/fun/x2x/rotation.hh, * mln/registration/icp.hh: undo changes. --- milena/ChangeLog | 13 +++++ milena/mln/algebra/quat.hh | 25 ---------- milena/mln/core/concept/gpoint.hh | 2 +- milena/mln/core/point.hh | 96 ++++++++++++++++++------------------ milena/mln/fun/x2v/bilinear.hh | 8 ++-- milena/mln/fun/x2v/trilinear.hh | 6 +- milena/mln/fun/x2x/rotation.hh | 6 +- milena/mln/registration/icp.hh | 42 ++++++++-------- 8 files changed, 94 insertions(+), 104 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 9402dbe..401a2a6 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,18 @@ 2009-02-20 Guillaume Lazzara <z@lrde.epita.fr> + Revert patch #3397. + + * mln/algebra/quat.hh, + * mln/core/concept/gpoint.hh, + * mln/core/point.hh, + * mln/fun/x2v/bilinear.hh, + * mln/fun/x2v/trilinear.hh, + * mln/fun/x2x/rotation.hh, + * mln/registration/icp.hh: undo changes. + + +2009-02-20 Guillaume Lazzara <z@lrde.epita.fr> + Fix tests. * generate_dist_headers.sh: add only .hh and .hxx to headers.mk. diff --git a/milena/mln/algebra/quat.hh b/milena/mln/algebra/quat.hh index 8784883..33e7d07 100644 --- a/milena/mln/algebra/quat.hh +++ b/milena/mln/algebra/quat.hh @@ -162,11 +162,6 @@ namespace mln /// Explicit conversion to a 4D algebra::vec. const algebra::vec<4,float>& to_vec() const; - /// Implicit conversion to a 4D algebra::vec. - operator const algebra::vec<4,float>&() const; - operator const algebra::vec<4,float>&(); - operator algebra::vec<4,float>() const; - operator algebra::vec<4,float>(); /// Give the scalar part. float s() const; @@ -345,26 +340,6 @@ namespace mln } inline - quat::operator const algebra::vec<4,float>&() const - { - return this->v_; - } - - inline - quat::operator const algebra::vec<4,float>&() - { - return this->v_; - } - - inline - quat::operator algebra::vec<4,float>() - { - return this->v_; - } - - - - inline float quat::s() const { diff --git a/milena/mln/core/concept/gpoint.hh b/milena/mln/core/concept/gpoint.hh index 40a2420..12f1b38 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; - vec (E::*m)() const = & E::to_vec; + const vec& (E::*m)() const = & E::to_vec; m = 0; } diff --git a/milena/mln/core/point.hh b/milena/mln/core/point.hh index 1d618cc..a661fe5 100644 --- a/milena/mln/core/point.hh +++ b/milena/mln/core/point.hh @@ -61,6 +61,22 @@ 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 @@ -92,10 +108,10 @@ namespace mln typedef C coord; /// Algebra vector (vec) associated type. - typedef algebra::vec<G::dim, float> vec; + typedef algebra::vec<G::dim, C> vec; /// Algebra hexagonal vector (hvec) associated type. - typedef algebra::h_vec<G::dim, float> h_vec; + typedef algebra::h_vec<G::dim, C> h_vec; /// Read-only access to the \p i-th coordinate value. /// \param[in] i The coordinate index. @@ -155,17 +171,23 @@ namespace mln /// Shifting by \p the inverse of dp. point<G,C>& operator-=(const delta& dp); - /* FIXME: Seems highly non-generic! + /// 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. + 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; - operator algebra::vec<G::dim, float> (); +#endif /// Explicit conversion towards mln::algebra::vec. - vec to_vec() const; + const vec& to_vec() const; /// Transform to point in homogene coordinate system. h_vec to_h_vec() const; @@ -192,8 +214,7 @@ namespace mln template <typename G, typename C, typename E> struct subject_point_impl< point<G,C>, E > { - typename point<G,C>::vec to_vec() const; - operator algebra::vec<G::dim, float>() const; + const typename point<G,C>::vec& to_vec() const; private: const E& exact_() const; @@ -260,11 +281,7 @@ namespace mln inline point<G,C>::point(const algebra::vec<dim,C2>& v) { - 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]; + coord_ = v; } template <typename G, typename C> @@ -389,33 +406,30 @@ namespace mln template <typename G, typename C> inline - point<G,C>::operator algebra::vec<G::dim,float> () const + point<G,C>::operator typename internal::point_to_<G, C>::metal_vec () const { - return to_vec(); + 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> () + point<G,C>::operator algebra::vec<G::dim, float> () const { - return to_vec(); + algebra::vec<dim, float> tmp; + for (unsigned int i = 0; i < dim; ++i) + tmp[i] = coord_[i]; + return tmp; } - +#endif template <typename G, typename C> inline - typename point<G,C>::vec + const typename point<G,C>::vec& point<G,C>::to_vec() const { - 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_; } template <typename G, typename C> @@ -423,15 +437,9 @@ namespace mln typename point<G,C>::h_vec point<G,C>::to_h_vec() const { - algebra::h_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]; - + algebra::h_vec<G::dim, C> tmp; + for (unsigned i = 0; i < dim; ++i) + tmp[i] = coord_[i]; tmp[G::dim] = 1; return tmp; } @@ -468,27 +476,20 @@ namespace mln template <typename G, typename C, typename E> inline - typename point<G,C>::vec + const 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 - algebra::vec<point<G,C>::dim - 1, C> + const algebra::vec<point<G,C>::dim - 1, C>& cut_(const point<G,C>& p) { - return *(algebra::vec<point<G,C>::dim - 1, C>*)(& p.to_vec()); + return *(const algebra::vec<point<G,C>::dim - 1, C>*)(& p.to_vec()); } template <typename C> @@ -501,8 +502,7 @@ 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 1daefa8..e264462 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_or(mlc_bool(I::psite::dim == 2), mlc_bool(I::psite::dim == 3))::check(); + //mlc_bool(I::psite::dim == 2)::check(); } template <typename I> @@ -141,14 +141,14 @@ namespace mln // | | | // q11----r1----q21 - double x = v[0]; - double y = v[1]; + double x = v[1]; + double y = v[2]; 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[3]); + def::coord z = math::round<float>()(v[0]); //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 2a1d594..3015502 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[0]; // row - double y = v[1]; // col - double z = v[2]; // sli + double x = v[1]; // row + double y = v[2]; // col + double z = v[0]; // 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 cbe1dd2..9addb50 100644 --- a/milena/mln/fun/x2x/rotation.hh +++ b/milena/mln/fun/x2x/rotation.hh @@ -197,10 +197,11 @@ namespace mln inline rotation<n,C>::rotation(const algebra::quat& q) { - // FIXME: Should also work for 2d. - mlc_bool(n == 3)::check(); mln_precondition(q.is_unit()); + // FIXME: Should also work for 2d. + mln_precondition(n == 3); + float w = q.to_vec()[0], x = q.to_vec()[1], x2 = 2*x*x, xw = 2*x*w, @@ -220,7 +221,6 @@ namespace mln axis_[0] = x; axis_[1] = y; axis_[2] = z; - axis_.normalize(); } diff --git a/milena/mln/registration/icp.hh b/milena/mln/registration/icp.hh index 3fc54c0..de763ea 100644 --- a/milena/mln/registration/icp.hh +++ b/milena/mln/registration/icp.hh @@ -229,18 +229,17 @@ namespace mln mln_site(I) operator()(const vec3d_f& v) const { - vec3d_f best_x = X_[0]; + vec3d_f best_x = convert::to<vec3d_f>(X_[0].to_vec()); float best_d = norm::l2_distance(v, best_x); mln_piter(X_t) X_i(X_); for_all(X_i) { - vec3d_f X_i_vec = X_i; - float d = norm::l2_distance(v, X_i_vec); + float d = norm::l2_distance(v, convert::to<vec3d_f>(X_i)); if (d < best_d) { best_d = d; - best_x = X_i_vec; + best_x = X_i.to_vec(); } } return best_x; @@ -267,11 +266,11 @@ namespace mln mln_piter(p_array<P>) p(kept); for_all(p) - ext_result(qR.rotate(p) + qT) = literal::green; + ext_result(qR.rotate(p.to_vec()) + qT) = literal::green; mln_piter(p_array<P>) p2(removed); for_all(p2) - ext_result(qR.rotate(p2) + qT) = literal::red; + ext_result(qR.rotate(p2.to_vec()) + qT) = literal::red; io::ppm::save(slice(ext_result,0), "registered-2.ppm"); } @@ -290,7 +289,7 @@ namespace mln mln_piter(p_array<P>) p(P_); for_all(p) { - vec3d_f Pk_i = pair.first.rotate(p) + pair.second; + vec3d_f Pk_i = pair.first.rotate(p.to_vec()) + pair.second; vec3d_f Yk_i = closest_point(Pk_i).to_vec(); // yk_i - pk_i e_k_accu.take(Yk_i - Pk_i); @@ -318,8 +317,8 @@ namespace mln for_all(p) { - vec3d_f Pk_i = pair.first.rotate(p) + pair.second; - vec3d_f Yk_i = closest_point(Pk_i); + vec3d_f Pk_i = pair.first.rotate(p.to_vec()) + pair.second; + vec3d_f Yk_i = closest_point(Pk_i).to_vec(); int d_i = closest_point.dmap_X_(Pk_i); if (d_i >= d_min && d_i <= d_max) @@ -400,7 +399,7 @@ namespace mln for_all(p) { vec3d_f Pk_i = pair.first.rotate(p.to_vec()) + pair.second; - vec3d_f Yk_i = closest_point(Pk_i); + vec3d_f Yk_i = closest_point(Pk_i).to_vec(); int d_i = closest_point.dmap_X_(Pk_i); if (d_i >= d_min && d_i <= d_max) @@ -441,27 +440,31 @@ namespace mln const std::pair<algebra::quat,mln_vec(P)>& pair, const std::string& period, const value::rgb8& c) { +# ifndef NDEBUG data::fill(out, literal::black); data::fill((out | X).rw(), literal::white); +# endif // !NDEBUG mln_piter(p_array<P>) p1(P_); for_all(p1) { - vec3d_f Pk_i = pair.first.rotate(p1) + pair.second; + vec3d_f Pk_i = pair.first.rotate(p1.to_vec()) + pair.second; out(Pk_i) = literal::red; } mln_piter(p_array<P>) p2(P_sub); for_all(p2) { - vec3d_f Pk_i = pair.first.rotate(p2) + pair.second; + vec3d_f Pk_i = pair.first.rotate(p2.to_vec()) + pair.second; out(Pk_i) = c; } +# ifndef NDEBUG std::ostringstream ss; ss << prefix << "_" << r << "_" << period << ".ppm"; io::ppm::save(slice(out,0), ss.str()); +# endif // ! NDEBUG } @@ -480,9 +483,8 @@ namespace mln for_all(p) { // yk_i - pk+1_i - vec3d_f P_i = p; - vec3d_f Pk_i = qR_old.rotate(P_i) + qT_old; - vec3d_f Pk_1_i = qR.rotate(P_i) + qT; + vec3d_f Pk_i = qR_old.rotate(p.to_vec()) + qT_old; + vec3d_f Pk_1_i = qR.rotate(p.to_vec()) + qT; accu.take(closest_point(Pk_i).to_vec() - Pk_1_i); } return accu.to_result(); @@ -506,9 +508,9 @@ namespace mln // FIXME: could we use an accu? for_all(p) { - vec3d_f P_i = p; - vec3d_f Pk_i = qR.rotate(P_i) + qT; - vec3d_f Yk_i = closest_point(Pk_i); + vec3d_f P_i = p.to_vec(); + vec3d_f Pk_i = qR.rotate(p.to_vec()) + qT; + vec3d_f Yk_i = closest_point(Pk_i).to_vec(); Spx += make::mat(P_i - mu_P) * trans(make::mat(Yk_i - mu_Yk)); } Spx /= P_.nsites(); @@ -562,7 +564,7 @@ namespace mln { // yk_i - pk_i vec3d_f Pk_i = qR.rotate(p.to_vec()) + qT; - vec3d_f Yk_i = closest_point(Pk_i); + vec3d_f Yk_i = closest_point(Pk_i).to_vec(); mu_yk.take(Yk_i); e_k_accu.take(Yk_i - Pk_i); } @@ -639,7 +641,7 @@ namespace mln image3d<value::rgb8> tmp_ = duplicate(debug); mln_piter(p_array<P>) p_dbg(P_); for_all(p_dbg) - tmp_(qR_old.rotate(p_dbg) + qT_old) = literal::green; + tmp_(qR_old.rotate(p_dbg.to_vec()) + qT_old) = literal::green; std::ostringstream ss; ss << "tmp_0"; if (k < 10) -- 1.5.6.5