
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-09-24 Simon Nivault <simon.nivault@lrde.epita.fr> Add translation. * mln/core/concept/function.hh: Add Function_x2x. * mln/fun/internal/selector.hh: Add comment. * mln/fun/x2x/translation.hh: New. * mln/fun/x2x: New. * mln/metal/mat.hh: Add identity. * tests/fun_x2x_translation.cc: New. --- mln/core/concept/function.hh | 23 +++++++ mln/fun/internal/selector.hh | 2 mln/fun/x2x/translation.hh | 132 +++++++++++++++++++++++++++++++++++++++++++ mln/metal/mat.hh | 17 +++++ tests/fun_x2x_translation.cc | 53 +++++++++++++++++ 5 files changed, 227 insertions(+) Index: trunk/milena/tests/fun_x2x_translation.cc =================================================================== --- trunk/milena/tests/fun_x2x_translation.cc (revision 0) +++ trunk/milena/tests/fun_x2x_translation.cc (revision 1161) @@ -0,0 +1,53 @@ +// 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. + +/*! \file tests/image2d_b.cc + * + * \brief Tests on mln::image2d_b. + */ + + +#include <iostream> +#include <mln/fun/x2x/translation.hh> + + + +int main() +{ + using namespace mln; + + float + a = 2.3, + b = 0, + c = 2.9; + + metal::vec<3,float> vec1 = make::vec(a, b, c); + fun::x2x::translation<3,float> tr1(make::vec<3,float>(1.6)); + + std::cout << vec1 << std::endl; + std::cout << tr1(vec1) << std::endl; +} Index: trunk/milena/mln/fun/x2x/translation.hh =================================================================== --- trunk/milena/mln/fun/x2x/translation.hh (revision 0) +++ trunk/milena/mln/fun/x2x/translation.hh (revision 1161) @@ -0,0 +1,132 @@ +// 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_X2X_TRANSLATION_HH +# define MLN_FUN_X2X_TRANSLATION_HH + +/*! \file mln/fun/x2x/translation.hh + * + * \brief FIXME. + */ + +# include <mln/core/concept/function.hh> +# include <mln/metal/vec.hh> +# include <mln/metal/mat.hh> + + +namespace mln +{ + + namespace fun + { + + namespace x2x + { + + // FIXME: Doc! + + template <unsigned n, typename C> + struct translation : public Function_x2x< translation<n,C> > + { + + enum {dim = n}; + + typedef metal::vec<n,C> result; + typedef metal::vec<n,C> invert; + + translation(); + translation(const metal::vec<n,C>& t); + + 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() + { + 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) + { + m_ = metal::mat<n+1,n+1,C>::Id; + for (unsigned i = 0; i < n; ++i) + 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 + { + typename translation::result res; + for (unsigned i = 0; i < n; ++i) + res[i] = v[i] + t_[i]; + return res; + } + + template <unsigned n, typename C> + metal::vec<n,C> + translation<n,C>::inv() const + { + typename translation::invert res(-t_); + + return res; + } + + template <unsigned n, typename C> + void + translation<n,C>::set_t(const metal::vec<n,C>& t) + { + t_ = t; + for (unsigned i = 0; i < n; ++i) + m_(i,n) = t_[i]; + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::x2x + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_X2X_TRANSLATION_HH Index: trunk/milena/mln/fun/internal/selector.hh =================================================================== --- trunk/milena/mln/fun/internal/selector.hh (revision 1160) +++ trunk/milena/mln/fun/internal/selector.hh (revision 1161) @@ -56,6 +56,8 @@ // | | // + -- Function_i2v | // | | + // + -- Function_x2x | + // | | // + -- Function_p2v | // | | // + -- Function_p2b -- + Index: trunk/milena/mln/core/concept/function.hh =================================================================== --- trunk/milena/mln/core/concept/function.hh (revision 1160) +++ trunk/milena/mln/core/concept/function.hh (revision 1161) @@ -138,6 +138,18 @@ }; + // Vector -> Vector. + + /// Base class for implementation of function-objects from vector to + /// vector. + template <typename E> + struct Function_x2x : public Function_v2v<E> + { + protected: + Function_x2x(); + Function_x2x(const Function_x2x&); + }; + # ifndef MLN_INCLUDE_ONLY @@ -221,6 +233,17 @@ { } + template <typename E> + Function_x2x<E>::Function_x2x() + { + } + + template <typename E> + Function_x2x<E>::Function_x2x(const Function_x2x<E>& rhs) + : Function_v2v<E>(rhs) + { + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: trunk/milena/mln/metal/mat.hh =================================================================== --- trunk/milena/mln/metal/mat.hh (revision 1160) +++ trunk/milena/mln/metal/mat.hh (revision 1161) @@ -48,6 +48,7 @@ typedef T value_type; enum {N = n, M = m}; + static const mat<n,m,T> Id; mat() { @@ -67,6 +68,8 @@ unsigned size() const; + static mat identity(); + private: T data_[n][m]; }; @@ -74,6 +77,20 @@ # ifndef MLN_INCLUDE_ONLY template <unsigned n, unsigned m, typename T> + const mat<n,m,T> mat<n,m,T>::Id = mat<n,m,T>::identity(); + + template <unsigned n, unsigned m, typename T> + mat<n,m,T> mat<n,m,T>::identity() + { + mat<n,m,T> id; + + for (unsigned i = 0; i < n; ++i) + for (unsigned j = 0; j < m; ++j) + id.data_[i][j] = (i == j); + return id; + } + + template <unsigned n, unsigned m, typename T> template <typename U> mat<n,m,T>::mat(const mat<n,m,U>& rhs) {
participants (1)
-
Simon Nivault