oln 10.194: Add func_morpher, rotation, translation, fpoint2d, and fdpoint2d

Je sais que y'a plein de trucs crades dans ce checkin, alors si vous avez des suggestions, n'hesitez pas a m'en faire part, j'en tiendrai compte lorsque je retoucherai tout ca (apres mon seminaire). Index: olena/ChangeLog from Damien Thivolle <damien@lrde.epita.fr> * oln/makefile.src: Add new files to the distribution. * oln/transforms/shapelets.hh: Small Changes. * oln/morpher/func_morpher.hh: Add file, image can now be seen through a functor. * oln/core/fpoint2d.hh: Add file. Contain floating point implementation. * oln/core/fdpoint2d.hh: Add file. Contain floating dpoint implementation. * oln/geom/translate.hh: Add file. Implementation of image translation using floating dpoint. * oln/geom/rotate.hh: Add file. Implementation of image rotation using floating point. -2004-07-06 Damien Thivolle <damien@lrde.epita.fr> +2004-06-07 Damien Thivolle <damien@lrde.epita.fr> * oln/transforms/shapelets.hh: Change functions to functors, bug fixes. Index: olena/oln/makefile.src --- olena/oln/makefile.src Mon, 14 Jun 2004 09:07:03 +0200 odou_s (oln/r/4_makefile.s 1.3 600) +++ olena/oln/makefile.src Tue, 15 Jun 2004 19:41:15 +0200 thivol_d (oln/r/4_makefile.s 1.3 600) @@ -76,7 +76,9 @@ core/dpoint2d.hxx \ core/dpoint3d.hh \ core/dpoint3d.hxx \ + core/fdpoint2d.hh \ core/fold.hh \ + core/fpoint2d.hh \ core/fwd_iter1d.hh \ core/fwd_iter2d.hh \ core/fwd_iter3d.hh \ @@ -113,6 +115,8 @@ core/window3d.hh \ core/winiter.hh \ core/winneighb.hh \ + geom/rotate.hh \ + geom/translate.hh \ io/base.hh \ io/basics.hh \ io/file.hh \ @@ -147,6 +151,7 @@ level/threshold.hh \ math/macros.hh \ morpher/color_morpher.hh \ + morpher/func_morpher.hh \ morpher/generic_morpher.hh \ morpher/iter_morpher.hh \ morpher/piece_morpher.hh \ Index: olena/oln/transforms/shapelets.hh --- olena/oln/transforms/shapelets.hh Mon, 07 Jun 2004 19:41:27 +0200 thivol_d (oln/r/10_shapelets. 1.2 600) +++ olena/oln/transforms/shapelets.hh Tue, 15 Jun 2004 19:39:53 +0200 thivol_d (oln/r/10_shapelets. 1.2 600) @@ -18,17 +18,21 @@ { T operator()(unsigned n, T x) { + if (n == 0) return 1; if (n == 1) return 2. * x; - return 2. * x * (*this)(n - 1, x) - 2. * double(n - 1) * (*this)(n - 2, x); + return 2. * x * (*this)(n - 1, x) - 2. * T(n - 1) * (*this)(n - 2, x); } }; template <class T> struct fact : public std::unary_function<T, T> { + + + T operator() (T n) { precondition(n >= 0); @@ -49,7 +53,7 @@ T operator()(int n, T x) { assert(n >= 0); - const double c = sqrt(pow(2.0, n) * sqrt(M_PI) * T(fact<int>()(n))); + const double c = sqrt(pow(2.0, n) * sqrt(M_PI) * fact<T>()(n)); return hermite<T>()(n, x) * exp(x * x / -2.0) / c; } @@ -111,6 +115,8 @@ func(k, l, double(it.row() - row), double(it.col() - col), b); } res[k * n + l] = s; + // std::cout << k << " - " << l << " = " << s << std::endl; + } return res; } @@ -136,9 +142,15 @@ for (int k = 0; k < m; k++) for (int l = 0; l < n; l++) // Add the value at the point + { + if (vec[k * n + l] * vec[k * n + l] > 40000) + { for_all(it) resf[it] += vec[k * n + l] * shapelets_basis<2, double>()(k, l, double(it.row() - nrows / 2), double(it.col() - ncols / 2), b); + //std::cout << k << " - " << l << std::endl; + } + } image2d<D> res(oln::image2d_size(nrows, ncols, 0)); Index: olena/oln/morpher/func_morpher.hh --- olena/oln/morpher/func_morpher.hh Tue, 15 Jun 2004 19:49:30 +0200 thivol_d () +++ olena/oln/morpher/func_morpher.hh Tue, 15 Jun 2004 16:01:36 +0200 thivol_d (oln/r/14_func_morph 644) @@ -0,0 +1,142 @@ +// Copyright (C) 2004 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHER_FUNC_MORPHER_HH +# define OLENA_MORPHER_FUNC_MORPHER_HH + +# include <oln/morpher/generic_morpher.hh> + + +namespace oln { + + namespace morpher { + + template <class SrcType, class Ftor, class Exact = mlc::final> + struct func_morpher; + + + } // end of namespace morpher + + template <class SrcType, class Ftor, class Exact> + struct image_id<oln::morpher::func_morpher<SrcType, Ftor, Exact> > + { + enum {dim = SrcType::dim}; + /*! <The image dimension. */ + typedef oln_impl_type(SrcType) impl_type; + /*! <The underlying implementation.*/ + typedef oln_value_type(SrcType) value_type; + /*! <The modified value type.*/ + typedef typename mlc::exact_vt<oln::morpher::func_morpher<SrcType, Ftor, Exact>, + Exact>::ret exact_type; + + typedef oln_point_type(SrcType) point_type; + }; + + /*! Specialized version for subq_morpher. + ** + ** \param SrcType Input type decorated. + ** + ** \param N The new number of bits by components. + ** + ** \param Exact The exact type of the morpher. + */ + template <class SrcType, class Ftor, class Exact> + struct image_traits <oln::morpher::func_morpher<SrcType, Ftor, Exact> > : + public image_traits<oln::morpher::abstract::generic_morpher<SrcType, + typename image_id<oln::morpher::func_morpher<SrcType, Ftor, Exact> >::exact_type> > + { + }; + + namespace morpher { + + + + template <class SrcType, class Ftor, class Exact> + struct func_morpher: + public abstract::generic_morpher<SrcType, + typename oln::image_id<func_morpher<SrcType, Ftor, Exact> >::exact_type> + { + + Ftor f; + + /// The exact type of \a this. This class can be derived. + typedef typename oln::image_id<func_morpher<SrcType, Ftor, Exact> >::exact_type exact_type; + + /// The upper class. + typedef abstract::generic_morpher<SrcType, + exact_type> super_type; + + /// The value point of the resulting image. + typedef typename image_id<exact_type>::value_type value_type; + typedef typename image_id<exact_type>::point_type point_type; + typedef typename image_id<exact_type>::impl_type impl_type; + + /// Construct the morpher with an image. + func_morpher(const SrcType &ima, const Ftor f_) + : super_type(ima) + { f = f_;} + + /// Construct the morpher with another morpher. + func_morpher(const func_morpher<SrcType, Ftor>& r) + : super_type(r.get_ima()) + { f = r.f; } + + /*! Empty constructor. + ** + ** Needed by mlc_hierarchy::any_with_diamond. + */ + func_morpher() {} + + /// Return the value stored at \a p in the resulting image. + const value_type + at(const point_type& p) const + { + return f(ima_, p); + } + + /// Return the implementation. + const impl_type* + impl() const + { + return ima_.impl(); + } + + static std::string + name() + { + return "subq_morpher<" + SrcType::name() + ">"; + } + + }; + } +} + + + +#endif // !OLENA_MORPHER_FUNC_MORPHER_HH Index: olena/oln/core/fpoint2d.hh --- olena/oln/core/fpoint2d.hh Tue, 15 Jun 2004 19:49:30 +0200 thivol_d () +++ olena/oln/core/fpoint2d.hh Tue, 15 Jun 2004 14:23:37 +0200 thivol_d (oln/r/15_fpoint2d.h 644) @@ -0,0 +1,321 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FPOINT2D_HH +# define OLENA_CORE_FPOINT2D_HH + +# include <iostream> + +# include <oln/core/abstract/image.hh> +# include <oln/core/point2d.hh> + +namespace oln { + + + // fwd decl + template <class F> + class fpoint2d; + + template <class F> + class fdpoint2d; + + /*! \class point_traits<fpoint2d> + ** + ** The specialized version for fpoint2d. + */ + + template<class F> + struct point_traits<fpoint2d<F> > + { + enum { dim = 2 }; + typedef fdpoint2d<F> dpoint_type; + }; + + /*! \class fpoint2d + ** + ** Olena Floating class point2d. + */ + + template <class F> + class fpoint2d + { + private: + + F coord_[2]; + + public: + + typedef fpoint2d<F> exact_type; + typedef fpoint2d<F> self_type; + typedef fdpoint2d<F> dpoint_type; + + fpoint2d(F x, F y) + { + coord_[0] = x; + coord_[1] = y; + } + + fpoint2d() + {} + + /// Give the value of the nth coordinate of the point. + + F + row() const + { + return coord_[0]; + } + + F& + row() + { + return coord_[0]; + } + + F + col() const + { + return coord_[1]; + } + + F& + col() + { + return coord_[1]; + } + + F + nth(const unsigned dim) const + { + assert(dim < 2); + return coord_[dim]; + } + + /// Return a reference to the nth coordinate of the point. + + F& + nth(const unsigned dim) + { + assert(dim < 2); + return coord_[dim]; + } + + exact_type + operator-() const + { + return exact_type(-coord_[0], -coord_[1]); + } + + exact_type& + operator+=(const dpoint_type& dp) + { + row() += dp.row(); + col() += dp.col(); + return *this; + } + + exact_type& + operator-=(const dpoint_type& dp) + { + row() += dp.row(); + col() += dp.col(); + return *this; + } + + dpoint_type + operator-(const self_type& p) const + { + dpoint_type dp(row() - p.row(), col() - p.col()); + return dp; + } + + + exact_type + operator-(const dpoint_type& dp) const + { + exact_type p = *this; + p += dp; + return p; + } + + dpoint_type + operator+(const self_type& p) const + { + dpoint_type dp(row() + p.row(), col() + p.col()); + return dp; + } + + exact_type + operator+(const dpoint_type& dp) const + { + exact_type p = *this; + p -= dp; + return p; + } + + + /*! \brief Test if \a p and the current point have the same coordinates + ** + ** \return True if \a p and the current point have the same coordinates, + ** false otherwise. + */ + + bool + operator==(const self_type& p) const + { + return p.nth(0) == coord_[0] && p.nth(1) == coord_[1]; + } + + + /*! \brief Test if \a p and the current point do + ** not have the same coordinates. + ** + ** \return False if \a p and the current point have + ** the same coordinates, true otherwise. + */ + + bool + operator!=(const self_type& p) const + { + return !(p.nth(0) == coord_[0] && p.nth(1) == coord_[1]); + } + + + + }; + + template <class T> + struct func_traits + { + }; + + template <class T, class F> + struct nearest; + + template <class T, class F> + struct bilinear; + + template <class T, class F> + struct func_traits<nearest<T, F> > + { + typedef F f_type; + }; + + template <class T, class F> + struct func_traits<bilinear<T, F> > + { + typedef F f_type; + }; + + template <class T, class Exact> + struct fpoint2d_access + { + + typedef typename func_traits<Exact>::f_type f_type; + + const T operator()(const image2d<T> &ima, const fpoint2d<f_type> p) const + { + return (static_cast<const Exact *>(this))->access_impl(ima, p); + } + + }; + + + template <class T, class F> + struct nearest : public fpoint2d_access<T, nearest<T, F> > + { + + const T access_impl(const image2d<T> &ima, const fpoint2d<F> p) const + { + + point2d p2d(int(p.nth(0)), int(p.nth(1))); + + if (ima.hold(p2d)) + return ima[p2d]; + else // FIXME : should be ntg_max_val(T) + return ntg::rgb_8(255, 255, 255); + } + + }; + + template <class T, class F> + struct bilinear : public fpoint2d_access<T, bilinear<T, F> > + { + + const T access_impl(const image2d<T> &ima, const fpoint2d<F> p) const + { + double x = floorf(p.nth(0)); + double y = floorf(p.nth(1)); + + int a = int(x); + int b = int(y); + + + if (ima.hold(point2d(a, b)) && ima.hold(point2d(a + 1, b + 1))) + { + int res[3]; + + res[0] = int((double(ima(a, b)[0]) * (x + 1 - p.nth(0)) + + double(ima(a + 1, b)[0]) * (p.nth(0) - x)) * (y + 1 - p.nth(1)) + + (double(ima(a, b + 1)[0]) * (p.nth(0) - x) + + double(ima(a + 1, b + 1)[0]) * (x + 1 - p.nth(0))) * (p.nth(1) - y)); + res[1] = int((double(ima(a, b)[1]) * (x + 1 - p.nth(0)) + + double(ima(a + 1, b)[1]) * (p.nth(0) - x)) * (y + 1 - p.nth(1)) + + (double(ima(a, b + 1)[1]) * (p.nth(0) - x) + + double(ima(a + 1, b + 1)[1]) * (x + 1 - p.nth(0))) * (p.nth(1) - y)); + res[2] = int((double(ima(a, b)[2]) * (x + 1 - p.nth(0)) + + double(ima(a + 1, b)[2]) * (p.nth(0) - x)) * (y + 1 - p.nth(1)) + + (double(ima(a, b + 1)[2]) * (p.nth(0) - x) + + double(ima(a + 1, b + 1)[2]) * (x + 1 - p.nth(0))) * (p.nth(1) - y)); + return ntg::rgb_8(res[0], res[1], res[2]); + } + else if (ima.hold(point2d(a, b))) + return ima(a, b); + else // FIXME : should be ntg_max_val(T) + return ntg::rgb_8(255, 255, 255); + } + + }; + + +} // end of oln + + +/// Write on an output stream \a o the coordinate of the fpoint2d \a p. + +template <class F> +inline std::ostream& +operator<<(std::ostream& o, const oln::fpoint2d<F>& p) +{ + return o << '(' << p.nth(0) << ',' << p.nth(1) << ')'; +} + + + + + +#endif // ! OLENA_CORE_FPOINT2D_HH Index: olena/oln/core/fdpoint2d.hh --- olena/oln/core/fdpoint2d.hh Tue, 15 Jun 2004 19:49:30 +0200 thivol_d () +++ olena/oln/core/fdpoint2d.hh Tue, 15 Jun 2004 11:02:18 +0200 thivol_d (oln/r/16_fdpoint2d. 644) @@ -0,0 +1,201 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FDPOINT2D_HH +# define OLENA_CORE_FDPOINT2D_HH + +# include <iostream> + +# include <oln/core/abstract/image.hh> +# include <oln/core/fpoint2d.hh> + +namespace oln { + + // fwd decl + template <class F> + class dfpoint2d; + + + + /*! \class dpoint_traits<fdpoint2d> + ** + ** The specialized version for fdpoint2d. + */ + + template<class F> + struct dpoint_traits<fdpoint2d<F> > + { + enum { dim = 2 }; + typedef fpoint2d<F> point_type; + }; + + /*! \class fdpoint2d + ** + */ + + template <class F> + class fdpoint2d + { + private: + + F coord_[2]; + + + public: + + + typedef fdpoint2d<F> exact_type; + + fdpoint2d() + {} + + /// The coordinates of the dpoint2d are set to \a row and \a col. + + fdpoint2d(F row, F col) + { + coord_[0] = row; + coord_[1] = col; + } + + /// The coordinates of the dpoint2d are set to the \a p coordinates. + fdpoint2d(const exact_type& p) + { + coord_[0] = p.row(); + coord_[1] = p.col(); + } + + /// Return the value of the dpoint2d row coordinate. + + F + row() const + { + return coord_[0]; + } + + /// Return a reference to the dpoint2d row coordinate. + + F& + row() + { + return coord_[0]; + } + + /// Return the value of the dpoint2d column coordinate. + + F + col() const + { + return coord_[1]; + } + + /// Return a reference to the dpoint2d column coordinate. + + F& + col() + { + return coord_[1]; + } + + static std::string + name() + { + return "fdpoint2d"; + } + + exact_type + operator+(const exact_type& dp) const + { + exact_type tmp(*this); + tmp += dp; + return tmp; + } + + /*! \brief Return a dpoint2d whose coordinates are equal to + ** the opposite of the current dpoint2d coordinates. + */ + + exact_type + operator-() const + { + exact_type dp(-row(), -col()); + return dp; + } + + + /*! \brief Return a dpoint2d whose coordinates are equal to + ** the current dpoint2d coordinates minus \a dp coordinates. + */ + + exact_type + operator-(const exact_type& dp) const + { + exact_type tmp = *this; + tmp -= dp; + return tmp; + } + + + /*! \brief Return a reference to the current dpoint2d + ** plus \a dp. + */ + + exact_type& + operator+=(const exact_type& dp) + { + row() += dp.row(); + col() += dp.col(); + return *this; + } + + /*! \brief Return a reference to the current dpoint2d + ** minus \a dp. + */ + + exact_type& + operator-=(const exact_type& dp) + { + row() -= dp.row(); + col() -= dp.col(); + return *this; + } + }; + + +} // end of oln + +/// Write on an output stream \a o the coordinates of the dpoint2d \a dp. + +template <class F> +inline std::ostream& +operator<<(std::ostream& o, const oln::fdpoint2d<F> dp) +{ + o << "(" << dp.row() << "," << dp.col() << ")" << std::endl; + return o; +} + + +#endif // !OLENA_CORE_FDPOINT2D_HH Index: olena/oln/geom/translate.hh --- olena/oln/geom/translate.hh Tue, 15 Jun 2004 19:49:30 +0200 thivol_d () +++ olena/oln/geom/translate.hh Tue, 15 Jun 2004 11:53:36 +0200 thivol_d (oln/s/6_translate. 644) @@ -0,0 +1,72 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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, 59 Temple Place - Suite 330, 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 OLENA_GEOM_TRANSLATE_HH +# define OLENA_GEOM_TRANSLATE_HH + +# include <cmath> +# include <iostream> + +# include <oln/core/image2d.hh> +# include <oln/core/fpoint2d.hh> +# include <oln/core/fdpoint2d.hh> + +namespace oln { + + namespace geom { + + template <class T, class F, class Exact> + struct translate + { + typedef oln::image2d<T> im_type; + + + image2d<T> + operator()(const oln::image2d<T>& ima, + const fdpoint2d<F> dp, + fpoint2d_access<T, Exact> interp) + { + im_type res(ima.size()); + oln_iter_type(im_type) it(ima); + + for_all(it) + { + res[it] = interp(ima, fpoint2d<F>(it.row(), it.col()) - dp); + } + return res; + } + }; + } +} + + + + + +#endif // !OLENA_GEOM_TRANSLATE_HH + Index: olena/oln/geom/rotate.hh --- olena/oln/geom/rotate.hh Tue, 15 Jun 2004 19:49:30 +0200 thivol_d () +++ olena/oln/geom/rotate.hh Tue, 15 Jun 2004 16:07:48 +0200 thivol_d (oln/u/14_rotate.hh 644) @@ -0,0 +1,219 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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, 59 Temple Place - Suite 330, 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 OLENA_GEOM_ROTATE_HH +# define OLENA_GEOM_ROTATE_HH + +# include <cmath> +# include <iostream> + +# include <oln/core/image2d.hh> +# include <oln/core/fpoint2d.hh> + +namespace oln { + + namespace geom { + + template <class T, class Access> + struct ftor_rotate + { + private: + fpoint2d_access<T, Access> interp; + point2d center; + double cos_angle, sin_angle, a, b; + + public: + ftor_rotate(const point2d& center_, + const fpoint2d_access<T, Access>& interp_, + const double rad_angle_) : + interp(interp_), + center(center_) + { + cos_angle = cos(-rad_angle_); + sin_angle = sin(-rad_angle_); + + std::cout << sin_angle << " " << cos_angle << std::endl; + + a = double(center.row()); + b = double(center.col()); + + } + + ftor_rotate() {} + + ftor_rotate(const ftor_rotate<T, Access>& rhs) + { + interp = rhs.interp; + center = rhs.center; + cos_angle = rhs.cos_angle; + sin_angle = rhs.sin_angle; + a = rhs.a; + b = rhs.b; + } + + const T + operator()(const image2d<T>& ima, + const point2d p) const + { + double x, y; + double c, d; + + c = a + ima.size().nrows() / 2; + d = b + ima.size().ncols() / 2; + + x = cos_angle * double(p.row()) - sin_angle * double(p.col()) - + c * cos_angle + d * sin_angle + c; + y = sin_angle * double(p.row()) + cos_angle * double(p.col()) - + c * sin_angle - d * cos_angle + d; + + return interp(ima, fpoint2d<double>(x, y)); + } + }; + + template <class T, class Access> + struct rotate + { + typedef image2d<T> im_type; + + im_type + operator()(const im_type& ima, + const point2d center, + double rad_angle, + fpoint2d_access<T, Access> interp) + { + im_type res(ima.size()); + ftor_rotate<T, Access> f(center, interp, rad_angle); + oln_iter_type(im_type) it(res); + + for_all(it) + { + res[it] = f(ima, point2d(it.row(), it.col())); + } + return res; + } + }; + + + template <class T, class Access> + struct ftor_rotate_enlarge + { + private: + fpoint2d_access<T, Access> interp; + point2d center; + double cos_angle; + double sin_angle; + double a; + double b; + + public: + ftor_rotate_enlarge(const point2d& center_, + const fpoint2d_access<T, Access>& interp_, + const double rad_angle_) : + interp(interp_), + center(center_) + { + cos_angle = cos(-rad_angle_); + sin_angle = sin(-rad_angle_); + a = double(center.row()); + b = double(center.col()); + } + + ftor_rotate_enlarge() + {} + + ftor_rotate_enlarge(const ftor_rotate_enlarge& rhs) : + interp(rhs.interp), + center(rhs.center) + { + cos_angle = rhs.cos_angle; + sin_angle = rhs.sin_angle; + a = rhs.a; + b = rhs.b; + } + + T + operator()(const image2d<T>& ima, + const point2d p) + { + double x, y; + double c, d; + double rrows = ima.size().nrows() * cos_angle + + ima.size().ncols() * -sin_angle; + double rcols = ima.size().nrows() * -sin_angle + + ima.size().ncols() * cos_angle; + double vt = (rrows - ima.size().nrows()) / 2; + double ht = (rcols - ima.size().ncols()) / 2; + + c = a + ima.size().nrows() / 2; + d = b + ima.size().ncols() / 2; + + x = cos_angle * double(p.row() - vt) - sin_angle * double(p.col() - ht) - + c * cos_angle + d * sin_angle + c; + y = sin_angle * double(p.row() - vt) + cos_angle * double(p.col() - ht) - + c * sin_angle - d * cos_angle + d; + + return interp(ima, fpoint2d<double>(x, y)); + } + }; + + + + + template <class T, class Access> + struct rotate_enlarge + { + + typedef image2d<T> im_type; + + im_type + operator()(const im_type& ima, + const point2d center, + double rad_angle, + fpoint2d_access<T, Access> interp) + { + im_type res(image2d_size(int(ima.size().nrows() * cos(rad_angle) + + ima.size().ncols() * sin(rad_angle)), + int(ima.size().nrows() * sin(rad_angle) + + ima.size().ncols() * cos(rad_angle)), + 0)); + + oln_iter_type(im_type) it(res); + ftor_rotate_enlarge<T, Access> f(center, interp, rad_angle); + + for_all(it) + { + res[it] = f(ima, point2d(it.row(), it.col())); + } + return res; + } + }; + + } +} + + +#endif // !OLENA_CORE_FPOINT2D_HH -- Damien Thivolle damien.thivolle@lrde.epita.fr

"Damien" == Damien Thivolle <damien@lrde.epita.fr> writes:
Index: olena/ChangeLog from Damien Thivolle <damien@lrde.epita.fr>
* oln/makefile.src: Add new files to the distribution. * oln/transforms/shapelets.hh: Small Changes. * oln/morpher/func_morpher.hh: Add file, image can now be seen through a functor. * oln/core/fpoint2d.hh: Add file. Contain floating point implementation. * oln/core/fdpoint2d.hh: Add file. Contain floating dpoint implementation. * oln/geom/translate.hh: Add file. Implementation of image translation using floating dpoint. * oln/geom/rotate.hh: Add file. Implementation of image rotation using floating point.
Shouldn't such a massive change be reflected in NEWS? Are you working on the documentation and test suite too?

Akim Demaille <akim@epita.fr> writes:
"Damien" == Damien Thivolle <damien@lrde.epita.fr> writes:
Index: olena/ChangeLog from Damien Thivolle <damien@lrde.epita.fr>
* oln/makefile.src: Add new files to the distribution. * oln/transforms/shapelets.hh: Small Changes. * oln/morpher/func_morpher.hh: Add file, image can now be seen through a functor. * oln/core/fpoint2d.hh: Add file. Contain floating point implementation. * oln/core/fdpoint2d.hh: Add file. Contain floating dpoint implementation. * oln/geom/translate.hh: Add file. Implementation of image translation using floating dpoint. * oln/geom/rotate.hh: Add file. Implementation of image rotation using floating point.
Shouldn't such a massive change be reflected in NEWS? Are you working on the documentation and test suite too?
Not yet, i know i should, but i don't really have the time right now, so it will be done after my seminar. -- Damien Thivolle damien.thivolle@lrde.epita.fr

Damien Thivolle wrote:
Je sais que y'a plein de trucs crades dans ce checkin, alors si vous avez des suggestions, n'hesitez pas a m'en faire part, j'en tiendrai compte lorsque je retoucherai tout ca (apres mon seminaire).
Merci de répondre OK à cette news après l'avoir fait. Je trouve ça cool ce genre de message, ça fait penser à: "Attention ce patch risque de blesser votre sensibilité." [Il y a pas mal de choses qui ne vont pas, mais c'est normale car tu as fait beaucoup de choses !]
template <class T> struct fact : public std::unary_function<T, T>
Souvent on ajoute un typedef pour le type de retour (T).
T operator()(int n, T x) { assert(n >= 0); - const double c = sqrt(pow(2.0, n) * sqrt(M_PI) * T(fact<int>()(n))); + const double c = sqrt(pow(2.0, n) * sqrt(M_PI) * fact<T>()(n));
J'ai du mal a comprendre pourquoi il y a 'double'.
func(k, l, double(it.row() - row), double(it.col() - col), b);
De même.
+ // std::cout << k << " - " << l << " = " << s << std::endl;
A supprimer.
+ if (vec[k * n + l] * vec[k * n + l] > 40000)
Non. Ca ne va pas. Si c'est un seuil il doit être passé en arg et expliqué.
+ //std::cout << k << " - " << l << std::endl;
A supprimer.
+ template <class SrcType, class Ftor, class Exact>
Il manque la doc et un exemple.
+ struct func_morpher: + public abstract::generic_morpher<SrcType, + typename oln::image_id<func_morpher<SrcType, Ftor, Exact> >::exact_type> + { + + Ftor f; + + /// The exact type of \a this. This class can be derived. + typedef typename oln::image_id<func_morpher<SrcType, Ftor, Exact> >::exact_type exact_type; + + /// The upper class. + typedef abstract::generic_morpher<SrcType, + exact_type> super_type; + + /// The value point of the resulting image. + typedef typename image_id<exact_type>::value_type value_type; + typedef typename image_id<exact_type>::point_type point_type; + typedef typename image_id<exact_type>::impl_type impl_type; + + /// Construct the morpher with an image. + func_morpher(const SrcType &ima, const Ftor f_)
const Ftor & f_ Je ne comprends pas pourquoi tu as une image. Une fonction n'a pas besoin d'image. Si la fonction s'appuie sur une image, alors l'image doit être dans le Ftor et non dans le morpher. En gros c'est un cas particulier.
+ return f(ima_, p);
Cf ci-dessus. Le Ftor doit prendre un point, et c'est tout.
+ return "subq_morpher<" + SrcType::name() + ">";
Changer subq_morpher.
Index: olena/oln/core/fpoint2d.hh --- olena/oln/core/fpoint2d.hh Tue, 15 Jun 2004 19:49:30 +0200 thivol_d () +++ olena/oln/core/fpoint2d.hh Tue, 15 Jun 2004 14:23:37 +0200 thivol_d (oln/r/15_fpoint2d.h 644) @@ -0,0 +1,321 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory
Non. Pas de dev sur ces fichier en 2001-2003.
+#ifndef OLENA_CORE_FPOINT2D_HH
A changer entièrement après avoir réfléchis à la nouvelle hiérarchie. Il manque de la doc.
+ struct fpoint2d_access + return (static_cast<const Exact *>(this))->access_impl(ima, p);
Ouille. Il y a des trucs pour faire ça.
+ template <class T, class F> + struct nearest : public fpoint2d_access<T, nearest<T, F> > + return ntg::rgb_8(255, 255, 255);
Ouille.
+ double x = floorf(p.nth(0));
Ouille (double, floorf).
+ return ntg::rgb_8(res[0], res[1], res[2]);
Ouille.
+ return ntg::rgb_8(255, 255, 255);
Ouille.
+// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory
Idem.
+# define OLENA_CORE_FDPOINT2D_HH
Idem que pour OLENA_CORE_FPOINT2D_HH
+ namespace geom {
Le mettre dans utils. namespace utils.
Index: olena/oln/geom/rotate.hh
Idem. Le mettre dans utils.
+ namespace geom { + operator()(const image2d<T>& ima, + const point2d p) const
Pourquoi rotate dépend d'une image ? Une rotation à un centre et est appliquée à des points, suivant des angles. Une rotation n'est pas une rotation 2D. Il manque de la doc.
+#endif // !OLENA_CORE_FPOINT2D_HH ??
PS: verifier tous les headers des nouveaux fichiers, j'en ai sauté. -- Niels

Niels van Vliet <van-vl_n@lrde.epita.fr> writes:
Damien Thivolle wrote:
Je sais que y'a plein de trucs crades dans ce checkin, alors si vous avez des suggestions, n'hesitez pas a m'en faire part, j'en tiendrai compte lorsque je retoucherai tout ca (apres mon seminaire).
Merci de répondre OK à cette news après l'avoir fait.
Je trouve ça cool ce genre de message, ça fait penser à: "Attention ce patch risque de blesser votre sensibilité."
[Il y a pas mal de choses qui ne vont pas, mais c'est normale car tu as fait beaucoup de choses !]
template <class T> struct fact : public std::unary_function<T, T>
Souvent on ajoute un typedef pour le type de retour (T).
Il est deja present dans unary_function
T operator()(int n, T x) { assert(n >= 0); - const double c = sqrt(pow(2.0, n) * sqrt(M_PI) * T(fact<int>()(n))); + const double c = sqrt(pow(2.0, n) * sqrt(M_PI) * fact<T>()(n));
J'ai du mal a comprendre pourquoi il y a 'double'.
moi aussi :)
func(k, l, double(it.row() - row), double(it.col() - col), b);
De même.
+ // std::cout << k << " - " << l << " = " << s << std::endl;
A supprimer.
+ if (vec[k * n + l] * vec[k * n + l] > 40000)
Non. Ca ne va pas. Si c'est un seuil il doit être passé en arg et expliqué.
J'ai eu la fleme de faire un truc plus evolue.
+ //std::cout << k << " - " << l << std::endl;
A supprimer.
+ template <class SrcType, class Ftor, class Exact>
Il manque la doc et un exemple.
+ struct func_morpher: + public abstract::generic_morpher<SrcType, + typename oln::image_id<func_morpher<SrcType, Ftor, Exact> >::exact_type> + { + + Ftor f; + + /// The exact type of \a this. This class can be derived. + typedef typename oln::image_id<func_morpher<SrcType, Ftor, Exact> >::exact_type exact_type; + + /// The upper class. + typedef abstract::generic_morpher<SrcType, + exact_type> super_type; + + /// The value point of the resulting image. + typedef typename image_id<exact_type>::value_type value_type; + typedef typename image_id<exact_type>::point_type point_type; + typedef typename image_id<exact_type>::impl_type impl_type; + + /// Construct the morpher with an image. + func_morpher(const SrcType &ima, const Ftor f_)
const Ftor & f_
Je ne comprends pas pourquoi tu as une image. Une fonction n'a pas besoin d'image. Si la fonction s'appuie sur une image, alors l'image doit être dans le Ftor et non dans le morpher. En gros c'est un cas particulier.
+ return f(ima_, p);
Cf ci-dessus. Le Ftor doit prendre un point, et c'est tout.
+ return "subq_morpher<" + SrcType::name() + ">";
Changer subq_morpher.
Index: olena/oln/core/fpoint2d.hh --- olena/oln/core/fpoint2d.hh Tue, 15 Jun 2004 19:49:30 +0200 thivol_d () +++ olena/oln/core/fpoint2d.hh Tue, 15 Jun 2004 14:23:37 +0200 thivol_d (oln/r/15_fpoint2d.h 644) @@ -0,0 +1,321 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory
Non. Pas de dev sur ces fichier en 2001-2003.
+#ifndef OLENA_CORE_FPOINT2D_HH
A changer entièrement après avoir réfléchis à la nouvelle hiérarchie.
Il manque de la doc.
+ struct fpoint2d_access + return (static_cast<const Exact *>(this))->access_impl(ima, p);
Ouille. Il y a des trucs pour faire ça.
+ template <class T, class F> + struct nearest : public fpoint2d_access<T, nearest<T, F> > + return ntg::rgb_8(255, 255, 255);
Ouille.
+ double x = floorf(p.nth(0));
Ouille (double, floorf).
+ return ntg::rgb_8(res[0], res[1], res[2]);
Ouille.
+ return ntg::rgb_8(255, 255, 255);
Ouille.
+// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory
Idem.
+# define OLENA_CORE_FDPOINT2D_HH
Idem que pour OLENA_CORE_FPOINT2D_HH
+ namespace geom {
Le mettre dans utils. namespace utils.
C'etait une idee de Theo :p
Index: olena/oln/geom/rotate.hh
Idem. Le mettre dans utils.
+ namespace geom { + operator()(const image2d<T>& ima, + const point2d p) const
Pourquoi rotate dépend d'une image ? Une rotation à un centre et est appliquée à des points, suivant des angles. Une rotation n'est pas une rotation 2D.
Il manque de la doc.
+#endif // !OLENA_CORE_FPOINT2D_HH ??
PS: verifier tous les headers des nouveaux fichiers, j'en ai sauté.
Sinon pour tout le reste, ca sera corrige plus tard, mais j'ai vraiment fait au plus rapide. -- Damien Thivolle damien.thivolle@lrde.epita.fr

"Niels" == Niels van Vliet <van-vl_n@lrde.epita.fr> writes:
Merci de répondre OK à cette news après l'avoir fait.
Je trouve ça cool ce genre de message, ça fait penser à: "Attention ce patch risque de blesser votre sensibilité."
[...] Du beau travail de relecture !
participants (3)
-
Akim Demaille
-
Damien Thivolle
-
Niels van Vliet