URL: https://svn.lrde.org/svn/oln/trunk/milena ChangeLog: 2007-10-23 Simon Nivault <simon.nivault@lrde.epita.fr> Fix convert_to_set_p and add tests. * mln/convert/to_set_p.hh: Fix. * tests/convert_to_set_p.cc: New. * tests/convert_to_window.cc: New. --- mln/convert/to_set_p.hh | 21 +++++---- tests/convert_to_set_p.cc | 96 +++++++++++++++++++++++++++++++++++++++++++ tests/convert_to_window.cc | 99 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+), 10 deletions(-) Index: trunk/milena/tests/convert_to_set_p.cc =================================================================== --- trunk/milena/tests/convert_to_set_p.cc (revision 0) +++ trunk/milena/tests/convert_to_set_p.cc (revision 1378) @@ -0,0 +1,96 @@ +// 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/convert_to_set_p.cc + * + * \brief Tests on mln::convert::to_set_p. + */ + +#include <mln/core/point2d.hh> +#include <mln/core/image2d.hh> +#include <mln/core/sub_image.hh> +#include <mln/core/window2d.hh> +#include <mln/core/box2d.hh> +#include <mln/core/neighb2d.hh> +#include <mln/core/inplace.hh> + +#include <mln/level/fill.hh> + +#include <mln/convert/to_set_p.hh> + +using namespace mln; + + void test(set_p<point2d> ref, set_p<point2d> cmp) + { + mln_assertion(ref.npoints() == cmp.npoints()); + for (unsigned i = 0; i < ref.npoints(); ++i) + mln_assertion(ref[i] == cmp[i]); + } + +int main() +{ + point2d + a(1, 0), + b(0, 1), + c(-1,0), + d(0,-1); + + set_p<point2d> ref; + ref.insert(a).insert(b).insert(c).insert(d); + // Reference constructed. + + // Nbh : + neighb2d nbh = c4(); + set_p<point2d> test_nbh = convert::to_set_p(nbh); + test(ref, test_nbh); + + // Image : + image2d<bool> ima(make::box2d(-6, -6, 6, 6)); + level::fill(ima, false); + level::fill(inplace(ima | ref), true); + set_p<point2d> test_ima = convert::to_set_p(ima); + test(ref, test_ima); + + // Window : + window2d win; + win + .insert(a - point2d::origin) + .insert(b - point2d::origin) + .insert(c - point2d::origin) + .insert(d - point2d::origin); + set_p<point2d> test_win = convert::to_set_p(win); + test(ref, test_win); + + // std::set : + std::set<point2d> set; + set.insert(a); + set.insert(b); + set.insert(c); + set.insert(d); + set_p<point2d> test_set = convert::to_set_p(set); + test(ref, test_set); +} Index: trunk/milena/tests/convert_to_window.cc =================================================================== --- trunk/milena/tests/convert_to_window.cc (revision 0) +++ trunk/milena/tests/convert_to_window.cc (revision 1378) @@ -0,0 +1,99 @@ +// 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/convert_to_window.cc + * + * \brief Tests on mln::convert::to_window. + */ + +#include <mln/core/dpoint2d.hh> +#include <mln/core/image2d.hh> +#include <mln/core/sub_image.hh> +#include <mln/core/window2d.hh> +#include <mln/core/box2d.hh> +#include <mln/core/neighb2d.hh> +#include <mln/core/inplace.hh> + +#include <mln/level/fill.hh> + +#include <mln/convert/to_window.hh> +#include <mln/convert/to_set_p.hh> + +using namespace mln; + + void test(window2d ref, window2d cmp) + { + mln_assertion(ref.ndpoints() == cmp.ndpoints()); + for (unsigned i = 0; i < ref.ndpoints(); ++i) + mln_assertion(ref.dp(i) == cmp.dp(i)); + } + +int main() +{ + dpoint2d + a(1, 0), + b(0, 1), + c(-1,0), + d(0,-1); + + window2d ref; + ref.insert(a).insert(b).insert(c).insert(d); + // Reference constructed. + + // Nbh : + neighb2d nbh = c4(); + window2d test_nbh = convert::to_window(nbh); + test(ref, test_nbh); + + // Image : + image2d<bool> ima(make::box2d(-6, -6, 6, 6)); + level::fill(ima, false); + level::fill(inplace(ima | convert::to_set_p(ref)), true); + window2d test_ima = convert::to_window(ima); + test(ref, test_ima); + + // Window : + set_p<point2d> setp; + setp + .insert(point2d::origin + a) + .insert(point2d::origin + b) + .insert(point2d::origin + c) + .insert(point2d::origin + d); + window2d test_setp = convert::to_window(setp); + test(ref, test_setp); + + // std::set : + std::set<dpoint2d> set; + set.insert(a); + set.insert(b); + set.insert(c); + set.insert(d); + window2d test_set = convert::to_window(set); + test(ref, test_set); + + // FIXME: To upper window. +} Index: trunk/milena/mln/convert/to_set_p.hh =================================================================== --- trunk/milena/mln/convert/to_set_p.hh (revision 1377) +++ trunk/milena/mln/convert/to_set_p.hh (revision 1378) @@ -51,15 +51,15 @@ /// Convert a neighborhood \p nbh into a point set. template <typename N> - set_p<mln_point(N)> to_window(const Neighborhood<N>& nbh); + set_p<mln_point(N)> to_set_p(const Neighborhood<N>& nbh); /// Convert a binary image \p ima into a point set. template <typename I> set_p<mln_point(I)> to_set_p(const Image<I>& ima); /// Convert a Window \p win into a point set. - template <typename P> - set_p<P> to_set_p(const Window<mln_dpoint(P)> win); + template <typename W> + set_p<mln_point(W)> to_set_p(const Window<W>& win); /// Convert an std::set \p s of points into a point set. template <typename D> @@ -77,7 +77,7 @@ set_p<P> pset; mln_niter(N) n(nbh, P::origin); for_all(n) - pset.insert(n - P::origin); + pset.insert(n); return pset; } @@ -93,18 +93,19 @@ mln_piter(I) p(ima.domain()); for_all(p) if (ima(p)) - pset.insert(p - P::origin); + pset.insert(p); return pset; } - template <typename P> - set_p<P> to_set_p(const Window<mln_dpoint(P)>& win) + template <typename W> + set_p<mln_point(W)> to_set_p(const Window<W>& win) { - typedef mln_dpoint(P) D; + typedef mln_dpoint(W) D; + typedef mln_point(W) P; set_p<P> pset; - mln_qiter(D) q(exact(win), P::origin); + mln_qiter(W) q(exact(win), P::origin); for_all(q) - pset.insert(q - P::origin); + pset.insert(q); return pset; }