milena r1500: Review draw, create tests subdirectory and fix bug in level

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-11-20 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Review draw, create tests subdirectory and fix bug in level. Draw. * mln/draw/line.hh * mln/draw/mesh.hh: Fix doc and typo. Tests. * tests/Makefile.am: Update for draw. * tests/draw: New subdirectory for draw tests. * tests/draw/Makefile.am: New Makefile.am for draw. * tests/line2d.cc: Remove ... . * tests/draw/line.cc: and replace here and update test. * tests/mesh_image.cc: Remove ... . * tests/draw/mesh.cc: ... and replace here and update test. Fix level bug. * mln/level/fill.hh: Fix specialization bug. --- mln/draw/line.hh | 15 ++++++++-- mln/draw/mesh.hh | 19 ++++++++++++ mln/level/fill.hh | 3 -- tests/Makefile.am | 1 tests/draw/Makefile.am | 12 ++++++++ tests/draw/line.cc | 68 +++++++++++++++++++++++++++++++++++++++++++++ tests/draw/mesh.cc | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 186 insertions(+), 5 deletions(-) Index: trunk/milena/tests/line2d.cc (deleted) =================================================================== Index: trunk/milena/tests/mesh_image.cc (deleted) =================================================================== Index: trunk/milena/tests/Makefile.am =================================================================== --- trunk/milena/tests/Makefile.am (revision 1499) +++ trunk/milena/tests/Makefile.am (revision 1500) @@ -6,6 +6,7 @@ level \ arith \ logical \ + draw \ border check_PROGRAMS = \ Index: trunk/milena/tests/draw/mesh.cc =================================================================== --- trunk/milena/tests/draw/mesh.cc (revision 0) +++ trunk/milena/tests/draw/mesh.cc (revision 1500) @@ -0,0 +1,73 @@ +// 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/draw/mesh.cc + * + * \brief Tests on mln::draw::mesh. + */ + +#include <mln/core/image2d.hh> +#include <mln/core/point2d.hh> +#include <mln/debug/println.hh> +#include <mln/util/graph.hh> +#include <mln/core/mesh_p.hh> +#include <mln/core/mesh_psite.hh> +#include <mln/draw/mesh.hh> +#include <mln/core/mesh_image.hh> +#include <mln/level/compare.hh> + +int +main (void) +{ + using namespace mln; + + int vs[3][3] = { + {2, 0, 0}, + {0, 1, 0}, + {0, 0, 2} + }; + + image2d<int> ref (make::image2d(vs)); + + util::graph<void> g; + + g.add_node (); + g.add_node (); + g.add_edge (0, 1); + g.consistency (); + + std::vector<point2d> v; + v.push_back (make::point2d (0,0)); + v.push_back (make::point2d (2,2)); + + mesh_p<point2d> m(g, v); + + image2d<int> ima (3, 3); + draw::mesh (ima, m, 2, 1); + + mln_assertion (ima == ref); +} Index: trunk/milena/tests/draw/Makefile.am =================================================================== --- trunk/milena/tests/draw/Makefile.am (revision 0) +++ trunk/milena/tests/draw/Makefile.am (revision 1500) @@ -0,0 +1,12 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +include $(top_srcdir)/milena/tests/tests.mk + +check_PROGRAMS = \ + line \ + mesh + +line_SOURCES = line.cc +mesh_SOURCES = mesh.cc + +TESTS = $(check_PROGRAMS) Index: trunk/milena/tests/draw/line.cc =================================================================== --- trunk/milena/tests/draw/line.cc (revision 0) +++ trunk/milena/tests/draw/line.cc (revision 1500) @@ -0,0 +1,68 @@ +// 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/draw/line.cc + * + * \brief Tests on mln::draw::line. + */ + +#include <iterator> + +#include <mln/core/image2d.hh> +#include <mln/core/sub_image.hh> +#include <mln/core/inplace.hh> + +#include <mln/level/fill.hh> +#include <mln/level/compare.hh> +#include <mln/draw/line.hh> +#include <mln/debug/println.hh> + + +int main() +{ + using namespace mln; + + point2d b = make::point2d(0,0), e = make::point2d(6,9); + line2d l(b, e); + mln_assertion(l.npoints() == 10); + + image2d<bool> ima(10,10); + level::fill(ima, false); + draw::line(ima, b, e, true); + + image2d<bool> ima2(10,10); + level::fill(ima2, false); + level::paste(pw::cst(true) | l, ima2); + + mln_assertion(ima2 == ima); + + image2d<bool> ima3(10,10); + level::fill(ima3, false); + level::fill(inplace(ima3 | l), true); + + mln_assertion(ima3 == ima); +} Index: trunk/milena/mln/draw/line.hh =================================================================== --- trunk/milena/mln/draw/line.hh (revision 1499) +++ trunk/milena/mln/draw/line.hh (revision 1500) @@ -46,8 +46,19 @@ namespace draw { - /// Draw a line at level \p v in image \p ima between the points - /// \p beg and \p end. + /*! Draw a line at level \p v in image \p ima between the points + * \p beg and \p end. + * + * \param[in,out] ima The image to be drawn. + * \param[in] beg The start point to drawn line. + * \param[in] end The end point to drawn line. + * \param[in] v The value to assign to all drawn pixels. + * + * \pre \p ima has to be initialized. + * \pre \p ima has \p beg. + * \pre \p ima has \p end. + * + */ template <typename I> void line(Image<I>& ima, const mln_point(I)& beg, const mln_point(I)& end, Index: trunk/milena/mln/draw/mesh.hh =================================================================== --- trunk/milena/mln/draw/mesh.hh (revision 1499) +++ trunk/milena/mln/draw/mesh.hh (revision 1500) @@ -30,7 +30,7 @@ /*! \file mln/draw/mesh.hh * - * \brief Draw an image of type mesh_image into anothor kind of image. + * \brief Draw an image from type mesh_image. * */ @@ -45,12 +45,29 @@ namespace draw { + /*! Draw an image \p ima from a mesh_p \p m, with value \p node_v + * for nodes, value \p link_v for links and 0 for the background. + * + * \param[in,out] ima The image to be drawn. + * \param[in] m The mesh_p which contains nodes and links positions. + * \param[in] node_v The value to assign to pixels which contains nodes. + * \param[in] link_v The value to assign to pixels which contains links. + * + */ template <typename I, typename P> void mesh(Image<I>& ima, const mesh_p<P>& m, mln_value(I) node_v, mln_value(I) link_v); + /*! Draw an image \p ima from a mesh_image \p mesh. + * The background is filled to value 0. + * + * \param[in,out] ima The image to be drawn. + * \param[in] mesh The mesh_image which contains nodes, links + * positions and the values of it. + * + */ template <typename I, typename P, typename V> void mesh(Image<I>& ima, const mesh_image<P, V>& mesh); Index: trunk/milena/mln/level/fill.hh =================================================================== --- trunk/milena/mln/level/fill.hh (revision 1499) +++ trunk/milena/mln/level/fill.hh (revision 1500) @@ -138,8 +138,7 @@ namespace generic { template <typename I> - void fill_with_value(trait::image::speed::any, I& ima, - const mln_value(I)& value) + void fill_with_value(I& ima, const mln_value(I)& value) { trace::entering("level::impl::generic::fill_with_value");
participants (1)
-
Guillaume Duhamel