milena r1156: Add test of rotation and fix

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-09-24 Simon Nivault <simon.nivault@lrde.epita.fr> Add test of rotation and fix. * mln/core/interpolated.hh: Fix. * mln/core/point.hh: Fix and add constructor for filling. * mln/fun/internal/selector.hh: Add tag x for vectors. * mln/io/internal/pnm/save.hh: Fix. * mln/io/internal/pnm/save_header.hh: Fix. * sandbox/nivault/rotation.cc: Experimentation on rotation. --- mln/core/interpolated.hh | 12 ++++++ mln/core/point.hh | 16 ++++++-- mln/fun/internal/selector.hh | 33 +++++++++++++++- mln/io/internal/pnm/save.hh | 2 + mln/io/internal/pnm/save_header.hh | 2 + sandbox/nivault/rotation.cc | 72 +++++++++++++++++++++++++++++++++++++ 6 files changed, 130 insertions(+), 7 deletions(-) Index: trunk/milena/mln/core/point.hh =================================================================== --- trunk/milena/mln/core/point.hh (revision 1155) +++ trunk/milena/mln/core/point.hh (revision 1156) @@ -85,6 +85,9 @@ /// Constructor without argument. point_(); + /// Constructor with filling. + point_(C c); + /// Constructor; coordinates are set by function \p f. template <typename F> point_(const Function_i2v<F>& f); @@ -99,13 +102,13 @@ point_<M,C>& operator+=(const dpoint& dp); /// Type of the array of coordinates. - typedef metal::vec<dim, C> vec_t; + typedef metal::vec<M::dim, C> vec_t; /// Hook to coordinates. operator metal::vec<M::dim, C>() const; protected: - metal::vec<dim, C> coord_; + metal::vec<M::dim, C> coord_; }; @@ -131,6 +134,12 @@ } template <typename M, typename C> + point_<M,C>::point_(C c) + { + set_all(c); + } + + template <typename M, typename C> template <typename F> point_<M,C>::point_(const Function_i2v<F>& f_) { @@ -142,8 +151,7 @@ template <typename M, typename C> void point_<M,C>::set_all(C c) { - for (unsigned i = 0; i < dim; ++i) - coord_[i] = c; + coord_.set_all(c); } template <typename M, typename C> Index: trunk/milena/mln/core/interpolated.hh =================================================================== --- trunk/milena/mln/core/interpolated.hh (revision 1155) +++ trunk/milena/mln/core/interpolated.hh (revision 1156) @@ -78,6 +78,9 @@ /// Test if a pixel value is accessible at \p p. bool owns_(const psite& p) const; + /// Test if a pixel value is accessible at \p v. + bool owns_(const mln::metal::vec<I::point::dim, float>& v) const; + /// Give the definition domain. const mln_pset(I)& domain() const; @@ -123,6 +126,15 @@ } template <typename I> + bool interpolated<I>::owns_(const mln::metal::vec<I::point::dim, float>& v) const + { + mln_point(I) p; + for (unsigned i = 0; i < I::point::dim; ++i) + p[i] = static_cast<int>(round(v[i])); + return ima_.owns_(p); + } + + template <typename I> const mln_pset(I)& interpolated<I>::domain() const { Index: trunk/milena/mln/fun/internal/selector.hh =================================================================== --- trunk/milena/mln/fun/internal/selector.hh (revision 1155) +++ trunk/milena/mln/fun/internal/selector.hh (revision 1156) @@ -34,10 +34,11 @@ */ # include <mln/core/concept/function.hh> -# include <mln/core/concept/point.hh> +# include <mln/core/concept/point_site.hh> # include <mln/metal/unqualif.hh> # include <mln/metal/if.hh> # include <mln/metal/is_a.hh> +# include <mln/metal/vec.hh> namespace mln @@ -66,7 +67,8 @@ b_, i_, p_, - v_ + v_, + x_ }; template <int arg, int res, typename E> struct helper_selector_; @@ -80,6 +82,8 @@ struct helper_selector_< b_, p_, E > { typedef Function_v2v<E> ret; }; template <typename E> struct helper_selector_< b_, v_, E > { typedef Function_v2v<E> ret; }; + template <typename E> + struct helper_selector_< b_, x_, E > { typedef Function_v2v<E> ret; }; // i2* => i2v type template <typename E> @@ -90,6 +94,8 @@ struct helper_selector_< i_, p_, E > { typedef Function_i2v<E> ret; }; template <typename E> struct helper_selector_< i_, v_, E > { typedef Function_i2v<E> ret; }; + template <typename E> + struct helper_selector_< i_, x_, E > { typedef Function_i2v<E> ret; }; // p2* template <typename E> @@ -100,6 +106,8 @@ struct helper_selector_< p_, p_, E > { typedef Function_p2p<E> ret; }; template <typename E> struct helper_selector_< p_, v_, E > { typedef Function_p2v<E> ret; }; + template <typename E> + struct helper_selector_< p_, x_, E > { typedef Function_p2v<E> ret; }; // v2* => v2v type, except for v2b template <typename E> @@ -110,7 +118,20 @@ struct helper_selector_< v_, p_, E > { typedef Function_v2v<E> ret; }; template <typename E> struct helper_selector_< v_, v_, E > { typedef Function_v2v<E> ret; }; + template <typename E> + struct helper_selector_< v_, x_, E > { typedef Function_v2v<E> ret; }; + // x2* => v2v type + template <typename E> + struct helper_selector_< x_, b_, E > { typedef Function_v2b<E> ret; }; + template <typename E> + struct helper_selector_< x_, i_, E > { typedef Function_v2v<E> ret; }; + template <typename E> + struct helper_selector_< x_, p_, E > { typedef Function_v2v<E> ret; }; + template <typename E> + struct helper_selector_< x_, v_, E > { typedef Function_v2v<E> ret; }; + template <typename E> + struct helper_selector_< x_, x_, E > { typedef Function_v2v<E> ret; }; // tag_ @@ -128,10 +149,16 @@ enum { value = i_ }; }; + template <unsigned n, typename T> + struct tag_< metal::vec<n,T> > + { + enum { value = x_ }; + }; + template <typename T> struct tag_ { - enum { value = mlc_is_a(T, Point)::to_bool + enum { value = mlc_is_a(T, Point_Site)::to_bool ? p_ : v_ }; }; Index: trunk/milena/mln/io/internal/pnm/save_header.hh =================================================================== --- trunk/milena/mln/io/internal/pnm/save_header.hh (revision 1155) +++ trunk/milena/mln/io/internal/pnm/save_header.hh (revision 1156) @@ -33,6 +33,8 @@ # include <fstream> # include <mln/value/rgb.hh> +# include <mln/geom/nrows.hh> +# include <mln/geom/ncols.hh> namespace mln { Index: trunk/milena/mln/io/internal/pnm/save.hh =================================================================== --- trunk/milena/mln/io/internal/pnm/save.hh (revision 1155) +++ trunk/milena/mln/io/internal/pnm/save.hh (revision 1156) @@ -39,6 +39,7 @@ # include <fstream> # include <mln/core/concept/image.hh> +# include <mln/core/point2d.hh> # include <mln/value/rgb.hh> # include <mln/value/rgb8.hh> @@ -51,6 +52,7 @@ # include <mln/geom/size2d.hh> + namespace mln { Index: trunk/milena/sandbox/nivault/rotation.cc =================================================================== --- trunk/milena/sandbox/nivault/rotation.cc (revision 0) +++ trunk/milena/sandbox/nivault/rotation.cc (revision 1156) @@ -0,0 +1,72 @@ +// 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 <cmath> +#include <iostream> + +#include <mln/io/pgm/save.hh> +#include <mln/io/pgm/load.hh> +#include <mln/core/image2d_b.hh> +#include <mln/value/int_u8.hh> +#include <mln/core/interpolated.hh> + + +int main() +{ + using namespace mln; + using value::int_u8; + + image2d_b<int_u8> lena = io::pgm::load("../img/lena.pgm"); + image2d_b<int_u8> out(lena.domain()); + + interpolated<image2d_b<int_u8> > inter(lena); + + image2d_b<int_u8>::fwd_piter p(out.domain()); + float q0, q1; + + float cos10 = cos(0.15); + float sin10 = sin(0.15); + + for_all(p) + { + q0 = cos10 * p[0] - sin10 * p[1]; + q1 = sin10 * p[0] + cos10 * p[1]; + if (inter.owns_(make::vec(q0, q1))) + { + out(p) = inter(make::vec(q0, q1)); +// std::cout << "GOOD" << std::endl; + } + else + out(p) = 0; + } + io::pgm::save(out, "out.pgm"); +}
participants (1)
-
Simon Nivault