
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> About nothing. * mln/core/h_vec.hh: Clean-up. (dim): New. * mln/metal/vec.hh (value_type): Rename as... (coord): ...this. * mln/metal/mat.hh: Likewise. (dim): New. * mln/metal/math/pow.hh: Fix file doc. * mln/metal/math/sqrt.hh: New. * mln/metal/math/all.hh: Update. * mln/fun/x2x/translation_alt.hh: New; just for the record. * mln/fun/internal/x2x_impl.hh: New. core/h_vec.hh | 50 +++++++++++-------- fun/internal/x2x_impl.hh | 88 +++++++++++++++++++++++++++++++++++ fun/x2x/translation_alt.hh | 75 +++++++++++++---------------- metal/mat.hh | 7 +- metal/math/all.hh | 1 metal/math/pow.hh | 2 metal/math/sqrt.hh | 113 +++++++++++++++++++++++++++++++++++++++++++++ metal/vec.hh | 2 8 files changed, 274 insertions(+), 64 deletions(-) Index: mln/core/h_vec.hh --- mln/core/h_vec.hh (revision 1292) +++ mln/core/h_vec.hh (working copy) @@ -41,38 +41,49 @@ { - template <unsigned dim, typename T> - struct h_vec : public metal::vec<dim + 1, T> + template <unsigned d, typename C> + struct h_vec : public metal::vec<d + 1, C> { - h_vec() - : metal::vec<dim + 1, T>(make::vec<dim + 1, T>(0)) - { // FIXME: Move in MLN_INCLUDE_ONLY - this->data_[dim] = 1; - } + /// Dimension is the 'natural' one (3 for 3D), not the one of the vector (dim + 1). + enum { dim = d }; + + /// Constructor without argument. + h_vec(); - h_vec(const metal::vec<dim, T>& x); + /// Constructor from a metal::vec. + h_vec(const metal::vec<d,C>& x); - operator metal::vec<dim, T>() const; + /// Conversion to a metal::vec. + operator metal::vec<d,C>() const; }; + # ifndef MLN_INCLUDE_ONLY - template <unsigned dim, typename T> - h_vec<dim,T>::h_vec(const metal::vec<dim, T>& x) + template <unsigned d, typename C> + h_vec<d,C>::h_vec() + { + } + + template <unsigned d, typename C> + h_vec<d,C>::h_vec(const metal::vec<d,C>& x) { - for (unsigned i = 0; i < dim; ++i) + for (unsigned i = 0; i < d; ++i) this->data_[i] = x[i]; - this->data_[dim] = 1; + this->data_[d] = 1; // FIXME: literal::one } - template <unsigned dim, typename T> - h_vec<dim,T>::operator metal::vec<dim,T>() const + template <unsigned d, typename C> + h_vec<d,C>::operator metal::vec<d,C>() const { - metal::vec<dim,T> x; - for (unsigned i = 0; i < dim; ++i) - x[i] = this->data_[i] / this->data_[dim]; - return x; + const C w = this->data_[d]; + mln_assertion(w != 0); + + metal::vec<d,C> tmp; + for (unsigned i = 0; i < n; ++i) + tmp[i] = this->data_[i] / w; + return tmp; } # endif // ! MLN_INCLUDE_ONLY @@ -80,5 +91,4 @@ } // end of namespace mln - #endif // ! MLN_CORE_H_VEC_HH Index: mln/metal/mat.hh --- mln/metal/mat.hh (revision 1292) +++ mln/metal/mat.hh (working copy) @@ -52,8 +52,11 @@ { public: - typedef T value_type; - enum {N = n, M = m}; + typedef T coord; + enum { N = n, + M = m, + dim = n * m }; + static const mat<n,m,T> Id; mat() Index: mln/metal/math/pow.hh --- mln/metal/math/pow.hh (revision 1292) +++ mln/metal/math/pow.hh (working copy) @@ -30,7 +30,7 @@ /*! \file mln/metal/math/pow.hh * - * \brief Definition of some mathematical static functions. + * \brief Definition of the 'power' static function. */ # include <mln/metal/bool.hh> Index: mln/metal/math/all.hh --- mln/metal/math/all.hh (revision 1292) +++ mln/metal/math/all.hh (working copy) @@ -50,6 +50,7 @@ # include <mln/metal/math/pow.hh> +# include <mln/metal/math/sqrt.hh> // ... Index: mln/metal/math/sqrt.hh --- mln/metal/math/sqrt.hh (revision 0) +++ mln/metal/math/sqrt.hh (revision 0) @@ -0,0 +1,113 @@ +// 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_METAL_MATH_SQRT_HH +# define MLN_METAL_MATH_SQRT_HH + +/*! \file mln/metal/math/sqrt.hh + * + * \brief Definition of the 'sqrt' static function. + */ + +# include <mln/metal/bool.hh> +# include <mln/metal/int.hh> + + +namespace mln +{ + + namespace metal + { + + namespace math + { + + // sqrt_int<x, n> + + namespace impl + { + + template <int n, int lo = 1, int hi = n> + struct sqrt_int_ + { + enum { mid = (lo + hi + 1) / 2 }; + + enum { value = n < mid * mid + ? sqrt_int_<n, lo, mid-1>::value + : sqrt_int_<n, mid, hi>::result }; + }; + + template<int n, int m> + struct sqrt_int_<n, m, m> + { + enum { value = m }; + }; + + // Entry. + + template <int n, bool b> + struct sqrt_int_if_ : sqrt_int_<n> + { + enum { value_ = sqrt_int_<n>::value, + reminder_ = n - value_ * value_ }; + // FIXME: Check that reminder_ = 0. + }; + + template <int n> + struct sqrt_int_if_< n, false > + { + }; + + } // end of namespace mln::metal::math::impl + + template <int n> + struct sqrt_int : impl::sqrt_int_if_< n, (n >= 0) > + { + }; + + + // sqrt<N> + + template <typename X, typename N> + struct sqrt; + + template <int n> + struct sqrt< int_<n> > : sqrt_int<n> + { + typedef sqrt_int<n> super_; + typedef int_<super_::value> ret; + }; + + + } // end of namespace mln::metal::math + + } // end of namespace mln::metal + +} // end of namespace mln + + +#endif // ! MLN_METAL_MATH_SQRT_HH Index: mln/metal/vec.hh --- mln/metal/vec.hh (revision 1292) +++ mln/metal/vec.hh (working copy) @@ -134,7 +134,7 @@ typedef T equiv[n]; typedef T enc[n]; - typedef T value_type; + typedef T coord; enum { dim = n }; vec(); Index: mln/fun/x2x/translation_alt.hh --- mln/fun/x2x/translation_alt.hh (revision 1287) +++ mln/fun/x2x/translation_alt.hh (working copy) @@ -25,17 +25,16 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_FUN_X2X_TRANSLATION_HH -# define MLN_FUN_X2X_TRANSLATION_HH +#ifndef MLN_FUN_X2X_TRANSLATION_ALT_HH +# define MLN_FUN_X2X_TRANSLATION_ALT_HH -/*! \file mln/fun/x2x/translation.hh +/*! \file mln/fun/x2x/translation_alt.hh * * \brief FIXME. */ # include <mln/fun/x2x/bijective_tr.hh> -# include <mln/metal/vec.hh> -# include <mln/metal/mat.hh> +# include <mln/fun/internal/x2x_base.hh> namespace mln @@ -50,76 +49,72 @@ // FIXME: Doc! template <unsigned n, typename C> - struct translation : public bijective_tr< translation<n,C> > - { + struct translation_alt + : - enum {dim = n}; + fun::internal::x2x_base_< metal::vec<n,C>, translation_alt<n,C> > + , + Function_x2x< translation_alt<n,C> > - typedef metal::vec<n,C> result; - typedef translation<n,C> invert; + // FIXME: Activate public bijective_tr< translation_alt<n,C> > + { + typedef fun::internal::x2x_base_< metal::vec<n,C>, translation_alt<n,C> > super_; + // typedef translation_alt<n,C> invert; + // invert inv() const; - translation(); - translation(const metal::vec<n,C>& t); + translation_alt(); + translation_alt(const metal::vec<n,C>& t); + using super_::operator(); result operator()(const metal::vec<n,C>& v) const; - invert inv() const; void set_t(const metal::vec<n,C>& t); protected: - metal::vec<n,C> t_; - metal::mat<n + 1,n + 1,C> m_; }; # ifndef MLN_INCLUDE_ONLY template <unsigned n, typename C> - translation<n,C>::translation() + translation_alt<n,C>::translation_alt() { - t_ = make::vec<n,C>(0); - m_ = metal::mat<n+1,n+1,C>::Id; } template <unsigned n, typename C> - translation<n,C>::translation(const metal::vec<n,C>& t) - :t_(t) + translation_alt<n,C>::translation_alt(const metal::vec<n,C>& t) + : + t_(t) { - m_ = metal::mat<n+1,n+1,C>::Id; + this->m_ = matrix::Id; for (unsigned i = 0; i < n; ++i) - m_(i,n) = t_[i]; + this->m_(i,n) = t_[i]; } template <unsigned n, typename C> metal::vec<n,C> - translation<n,C>::operator()(const metal::vec<n,C>& v) const + translation_alt<n,C>::operator()(const metal::vec<n,C>& v) const { - typename translation::result res; - // FIXME: Why not "res = v + t_;"? - for (unsigned i = 0; i < n; ++i) - res[i] = v[i] + t_[i]; - return res; - } - - template <unsigned n, typename C> - translation<n,C> - translation<n,C>::inv() const - { - typename translation::invert res(-t_); - - return res; + return v + t; } template <unsigned n, typename C> void - translation<n,C>::set_t(const metal::vec<n,C>& t) + translation_alt<n,C>::set_t(const metal::vec<n,C>& t) { t_ = t; for (unsigned i = 0; i < n; ++i) - m_(i,n) = t_[i]; + this->m_(i, n) = t_[i]; } +// template <unsigned n, typename C> +// translation_alt<n,C> +// translation_alt<n,C>::inv() const +// { +// typename translation_alt::invert res(-t_); +// return res; +// } # endif // ! MLN_INCLUDE_ONLY @@ -130,4 +125,4 @@ } // end of namespace mln -#endif // ! MLN_FUN_X2X_TRANSLATION_HH +#endif // ! MLN_FUN_X2X_TRANSLATION_ALT_HH Index: mln/fun/internal/x2x_impl.hh --- mln/fun/internal/x2x_impl.hh (revision 0) +++ mln/fun/internal/x2x_impl.hh (revision 0) @@ -0,0 +1,88 @@ +// 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_IMPL_HH +# define MLN_FUN_INTERNAL_X2X_IMPL_HH + +/*! \file mln/fun/internal/x2x_impl.hh + * + * \brief Implementation class for every Function_x2x. + */ + +# include <mln/core/concept/function.hh> +# include <mln/metal/mat.hh> +# include <mln/core/h_vec.hh> + + +namespace mln +{ + + namespace fun + { + + namespace internal + { + + template <typename V, typename E> + struct x2x_impl_ + { + enum { dim = V::dim }; + + typedef V argument; + typedef V result; + typedef typename V::coord coord; + + h_vec<dim, coord> operator()(const h_vec<dim, coord>& x) const + { + return m_ * x; + } + + protected: + x2x_impl_(); + + metal::mat<dim+1, dim+1, coord> m_; // FIXME: Change mat into h_mat<dim, dim, coord>! + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename V, typename E> + x2x_impl_<V,E>::x2x_impl_() + { + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::internal + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_INTERNAL_X2X_IMPL_HH
participants (1)
-
Thierry Geraud