milena r1332: Fix transformation. (it works !)

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-12 Simon Nivault <simon.nivault@lrde.epita.fr> Fix transformation. (it works !). * tests/fun_x2x_composed.cc, * tests/h_vec.cc, * mln/fun/x2x/composed.hh, * mln/fun/x2x/rotation.hh, * mln/fun/x2x/translation.hh, * mln/core/point.hh: Fix to respect homogeneous vector handling. * mln/fun/internal/x2x_impl.hh: Rename as ... * mln/fun/internal/x2x_linear_impl.hh: ...this (operator()) : Take vec and return vec. --- mln/core/point.hh | 2 mln/fun/internal/x2x_linear_impl.hh | 100 ++++++++++++++++++++++++++++++++++++ mln/fun/x2x/composed.hh | 86 +++++++++++++----------------- mln/fun/x2x/rotation.hh | 6 +- mln/fun/x2x/translation.hh | 6 +- tests/fun_x2x_composed.cc | 12 +++- tests/h_vec.cc | 10 +-- 7 files changed, 158 insertions(+), 64 deletions(-) Index: trunk/milena/tests/fun_x2x_composed.cc =================================================================== --- trunk/milena/tests/fun_x2x_composed.cc (revision 1331) +++ trunk/milena/tests/fun_x2x_composed.cc (revision 1332) @@ -51,7 +51,13 @@ metal::vec<3,float> vec1 = make::vec(a, b, c); fun::x2x::translation<3,float> tr(all(1.6)); fun::x2x::rotation<3,float> rot(0.3, 1); - std::cout << vec1 << std::endl; - std::cout << compose(tr, rot)(vec1) << std::endl; - std::cout << compose(rot, tr)(vec1) << std::endl; + + std::cout << "vec : " << vec1 << std::endl; + std::cout << "tr(vec) : " << tr(vec1) << std::endl; + std::cout << "rot(vec) : " << rot(vec1) << std::endl; + std::cout << "tr(rot(vec)) : " << compose(tr, rot)(vec1) << std::endl; + std::cout << "rot(rot_1(vec)) : " << compose(rot, rot.inv())(vec1) << std::endl; + std::cout << "tr(rot(tr(vec))) : " << compose(tr, compose(rot, tr))(vec1) << std::endl; + std::cout << "(rototr_1)(rot(tr(vec)))) : " + << compose(compose(rot, tr).inv(), compose(rot, tr))(vec1) << std::endl; } Index: trunk/milena/tests/h_vec.cc =================================================================== --- trunk/milena/tests/h_vec.cc (revision 1331) +++ trunk/milena/tests/h_vec.cc (revision 1332) @@ -54,11 +54,11 @@ { metal::vec<3, int> x; - h_vec<3, int> w = x; + h_vec<3, int> w = x.to_h_vec(); typedef h_vec<3, int> p3d; p3d p; - run_in_3d(p); + run_in_3d(p.to_vec()); point3d k; run_in_3d(k); @@ -66,8 +66,8 @@ { metal::vec<3,float> v; - h_vec<3,float> w(v); - w = v; - foo(v); + h_vec<3,float> w(v.to_h_vec()); + w = v.to_h_vec(); + foo(v.to_h_vec()); } } Index: trunk/milena/mln/core/point.hh =================================================================== --- trunk/milena/mln/core/point.hh (revision 1331) +++ trunk/milena/mln/core/point.hh (revision 1332) @@ -305,7 +305,7 @@ template <typename M, typename C> point_<M,C>::operator typename internal::point_to_<M, C>::h_vec () const { - return coord_; + return coord_.to_h_vec(); } # endif // ! MLN_INCLUDE_ONLY Index: trunk/milena/mln/fun/x2x/composed.hh =================================================================== --- trunk/milena/mln/fun/x2x/composed.hh (revision 1331) +++ trunk/milena/mln/fun/x2x/composed.hh (revision 1332) @@ -34,7 +34,7 @@ */ # include <mln/core/concept/function.hh> -# include <mln/fun/internal/x2x_impl.hh> +# include <mln/fun/internal/x2x_linear_impl.hh> # include <mln/metal/vec.hh> # include <mln/metal/is.hh> # include <mln/metal/bexpr.hh> @@ -56,16 +56,16 @@ namespace internal { - template <unsigned n, typename F, typename G, typename E, bool is_bij> + template <typename F, typename G, typename E, bool is_bij> struct helper_composed_; - template <unsigned n, typename F, typename G, typename E> - struct helper_composed_<n, F, G, E, true> - : public fun::internal::x2x_impl_<mln_result(F), E >, + template <typename F, typename G, typename E> + struct helper_composed_< F, G, E, true> + : public fun::internal::x2x_linear_impl_<mln_result(F), E >, public Bijection_x2x<E> { - typedef fun::internal::x2x_impl_<typename F::result, E > super_; + typedef fun::internal::x2x_linear_impl_<typename F::result, E > super_; using super_::dim; @@ -73,28 +73,26 @@ helper_composed_(const F& f, const G& g); using super_::operator(); - metal::vec<n,mln_result(F)> - operator()(const metal::vec<n,mln_result(F)>& v) const; void set_first(const F& f); void set_second(const G& g); + typedef composed<mln_invert(G),mln_invert(F)> invert; + + invert inv() const; + protected: F f_; G g_; - - typedef composed<mln_invert(G),mln_invert(F)> invert; - - invert inv() const; }; - template <unsigned n, typename F, typename G, typename E> - struct helper_composed_<n, F, G, E, false> - : public fun::internal::x2x_impl_<mln_result(F), E >, + template <typename F, typename G, typename E> + struct helper_composed_< F, G, E, false> + : public fun::internal::x2x_linear_impl_<mln_result(F), E >, public Function_x2x<E> { - typedef fun::internal::x2x_impl_<typename F::result, E > super_; + typedef fun::internal::x2x_linear_impl_<typename F::result, E > super_; using super_::dim; @@ -102,8 +100,6 @@ helper_composed_(const F& f, const G& g); using super_::operator(); - metal::vec<n,mln_result(F)> - operator()(const metal::vec<n,mln_result(F)>& v) const; void set_first(const F& f); void set_second(const G& g); @@ -120,7 +116,7 @@ template <typename F, typename G> struct composed - : public internal::helper_composed_<F::dim, F, G, composed<F,G>, + : public internal::helper_composed_<F, G, composed<F,G>, mlc_is(F, Bijection_x2x<F>)::value && mlc_is(G, Bijection_x2x<G>)::value>, @@ -132,7 +128,7 @@ composed() {} composed(const F& f, const G& g) - : internal::helper_composed_<F::dim, F, G, composed<F,G>, + : internal::helper_composed_<F, G, composed<F,G>, mlc_is(F, Bijection_x2x<F>)::value && mlc_is(G, Bijection_x2x<G>)::value>(f, g) { @@ -159,38 +155,38 @@ // Implementation of the bijective version. - template <unsigned n, typename F, typename G, typename E> - helper_composed_<n,F,G,E,true>::helper_composed_() + template <typename F, typename G, typename E> + helper_composed_<F,G,E,true>::helper_composed_() { - this->m_ = h_mat<dim,mln_result(F)>::Id; } - template <unsigned n, typename F, typename G, typename E> - helper_composed_<n,F,G,E,true>::helper_composed_(const F& f, const G& g) + template <typename F, typename G, typename E> + helper_composed_<F,G,E,true>::helper_composed_(const F& f, const G& g) :f_(f), g_(g) { this->m_ = f_.mat() * g_.mat(); } - template <unsigned n, typename F, typename G, typename E> - metal::vec<n, mln_result(F)> - helper_composed_<n,F,G,E,true>::operator()(const metal::vec<n, mln_result(F)>& v) const + template <typename F, typename G, typename E> + typename helper_composed_<F,G,E,true>::invert + helper_composed_<F,G,E,true>::inv() const { - return this->m_(v); + return compose(g_.inv(), f_.inv()); } - template <unsigned n, typename F, typename G, typename E> + + template <typename F, typename G, typename E> void - helper_composed_<n,F,G,E,true>::set_first(const F& f) + helper_composed_<F,G,E,true>::set_first(const F& f) { this->f_ = f; this->m_ = this->f_.mat() * this->g_.mat(); } - template <unsigned n, typename F, typename G, typename E> + template <typename F, typename G, typename E> void - helper_composed_<n,F,G,E,true>::set_second(const G& g) + helper_composed_<F,G,E,true>::set_second(const G& g) { this->g_ = g; this->m_ = this->f_.mat() * this->g_.mat(); @@ -198,38 +194,30 @@ // Implementation of the non bijective version. - template <unsigned n, typename F, typename G, typename E> - helper_composed_<n,F,G,E,false>::helper_composed_() + template <typename F, typename G, typename E> + helper_composed_<F,G,E,false>::helper_composed_() { - this->m_ = h_mat<dim,mln_result(F)>::Id; } - template <unsigned n, typename F, typename G, typename E> - helper_composed_<n,F,G,E,false>::helper_composed_(const F& f, const G& g) + template <typename F, typename G, typename E> + helper_composed_<F,G,E,false>::helper_composed_(const F& f, const G& g) :f_(f), g_(g) { this->m_ = f_.mat() * g_.mat(); } - template <unsigned n, typename F, typename G, typename E> - metal::vec<n, mln_result(F)> - helper_composed_<n,F,G,E,false>::operator()(const metal::vec<n, mln_result(F)>& v) const - { - return this->m_(v); - } - - template <unsigned n, typename F, typename G, typename E> + template <typename F, typename G, typename E> void - helper_composed_<n,F,G,E,false>::set_first(const F& f) + helper_composed_<F,G,E,false>::set_first(const F& f) { this->f_ = f; this->m_ = this->f_.mat() * this->g_.mat(); } - template <unsigned n, typename F, typename G, typename E> + template <typename F, typename G, typename E> void - helper_composed_<n,F,G,E,false>::set_second(const G& g) + helper_composed_<F,G,E,false>::set_second(const G& g) { this->g_ = g; this->m_ = this->f_.mat() * this->g_.mat(); Index: trunk/milena/mln/fun/x2x/translation.hh =================================================================== --- trunk/milena/mln/fun/x2x/translation.hh (revision 1331) +++ trunk/milena/mln/fun/x2x/translation.hh (revision 1332) @@ -34,7 +34,7 @@ */ # include <mln/core/concept/function.hh> -# include <mln/fun/internal/x2x_impl.hh> +# include <mln/fun/internal/x2x_linear_impl.hh> # include <mln/metal/vec.hh> # include <mln/core/h_mat.hh> # include <mln/fun/i2v/all.hh> @@ -53,11 +53,11 @@ template <unsigned n, typename C> struct translation - : internal::x2x_impl_< metal::vec<n,C>, translation<n,C> > + : internal::x2x_linear_impl_< metal::vec<n,C>, translation<n,C> > , public Bijection_x2x< translation<n,C> > { - typedef fun::internal::x2x_impl_< metal::vec<n,C>, translation<n,C> > super_; + typedef fun::internal::x2x_linear_impl_< metal::vec<n,C>, translation<n,C> > super_; typedef translation<n,C> invert; invert inv() const; Index: trunk/milena/mln/fun/x2x/rotation.hh =================================================================== --- trunk/milena/mln/fun/x2x/rotation.hh (revision 1331) +++ trunk/milena/mln/fun/x2x/rotation.hh (revision 1332) @@ -34,7 +34,7 @@ */ # include <mln/core/concept/function.hh> -# include <mln/fun/internal/x2x_impl.hh> +# include <mln/fun/internal/x2x_linear_impl.hh> # include <mln/metal/vec.hh> # include <mln/metal/mat.hh> # include <cmath> @@ -52,10 +52,10 @@ template <unsigned n, typename C> struct rotation - : internal::x2x_impl_< metal::vec<n,C>, rotation<n,C> > + : internal::x2x_linear_impl_< metal::vec<n,C>, rotation<n,C> > , public Bijection_x2x< rotation<n,C> > { - typedef fun::internal::x2x_impl_< metal::vec<n,C>, rotation<n,C> > super_; + typedef fun::internal::x2x_linear_impl_< metal::vec<n,C>, rotation<n,C> > super_; typedef rotation<n,C> invert; invert inv() const; Index: trunk/milena/mln/fun/internal/x2x_impl.hh (deleted) =================================================================== Index: trunk/milena/mln/fun/internal/x2x_linear_impl.hh =================================================================== --- trunk/milena/mln/fun/internal/x2x_linear_impl.hh (revision 0) +++ trunk/milena/mln/fun/internal/x2x_linear_impl.hh (revision 1332) @@ -0,0 +1,100 @@ +// Copyright (C) 2007 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_INTERNAL_X2X_LINEAR_IMPL_HH +# define MLN_FUN_INTERNAL_X2X_LINEAR_IMPL_HH + +/*! \file mln/fun/internal/x2x_linear_impl.hh + * + * \brief Implementation class for every linear Function_x2x. + */ + +# include <mln/core/concept/function.hh> +# include <mln/core/h_mat.hh> +# include <mln/core/h_vec.hh> + +namespace mln +{ + + namespace fun + { + + namespace internal + { + + template <typename V, typename E> + struct x2x_linear_impl_ + { + enum { dim = V::dim }; + + typedef V argument; + typedef V result; + typedef typename V::coord coord; + typedef h_mat<dim, coord> matrix; + + V operator()(const V& x) const + { + h_vec<dim, coord> tmp = m_ * x.to_h_vec(); + return tmp.to_vec(); + } + + const matrix& mat() const; + + protected: + x2x_linear_impl_(); + + matrix m_; + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename V, typename E> + x2x_linear_impl_<V,E>::x2x_linear_impl_() + { + } + + + template <typename V, typename E> + const typename x2x_linear_impl_<V,E>::matrix& + x2x_linear_impl_<V,E>::mat() const + { + return m_; + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::internal + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_INTERNAL_X2X_LINEAR_IMPL_HH
participants (1)
-
Simon Nivault