last-svn-commit-913-g3aef9a5 mln/draw/polygon.hh: New.

--- milena/ChangeLog | 4 ++ milena/mln/draw/{line.hh => polygon.hh} | 76 ++++++++++++++++++------------- 2 files changed, 48 insertions(+), 32 deletions(-) copy milena/mln/draw/{line.hh => polygon.hh} (55%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 47dbff5..459cce6 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,9 @@ 2011-06-07 Guillaume Lazzara <z@lrde.epita.fr> + * mln/draw/polygon.hh: New. + +2011-06-07 Guillaume Lazzara <z@lrde.epita.fr> + Add a missing conversion routine for object ids. * mln/convert/from_to.hxx, diff --git a/milena/mln/draw/line.hh b/milena/mln/draw/polygon.hh similarity index 55% copy from milena/mln/draw/line.hh copy to milena/mln/draw/polygon.hh index 528dce3..5c6c917 100644 --- a/milena/mln/draw/line.hh +++ b/milena/mln/draw/polygon.hh @@ -1,5 +1,4 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development -// Laboratory (LRDE) +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -17,27 +16,24 @@ // // As a special exception, you may use this file as part of a free // software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this +// instantiate templates or use macros or inpolygon 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_DRAW_LINE_HH -# define MLN_DRAW_LINE_HH +#ifndef MLN_DRAW_POLYGON_HH +# define MLN_DRAW_POLYGON_HH /// \file /// -/// Draw a line in an image. -/// \fixme Add specializations for horizontal lines (use pointers/memset). +/// Draw a polygon in an image. +/// \fixme Add specializations for horizontal polygons (use pointers/memset). # include <mln/core/concept/image.hh> -# include <mln/core/site_set/p_line2d.hh> -# include <mln/core/image/imorph/safe.hh> -# include <mln/data/paste.hh> -# include <mln/pw/image.hh> -# include <mln/pw/cst.hh> +# include <mln/core/site_set/p_array.hh> +# include <mln/draw/line.hh> namespace mln @@ -46,41 +42,57 @@ namespace mln namespace draw { - /*! Draw a line at level \p v in image \p ima between the points - * \p beg and \p end. + /*! Draw a polygon at level \p v in image \p ima. * * \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] par The polygon site set. * \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_psite(I)& beg, const mln_psite(I)& end, - const mln_value(I)& v); + void polygon(Image<I>& ima, + const p_array<mln_site(I)>& par, + const mln_value(I)& v, + unsigned output_ratio); + + // \overload + template <typename I> + void polygon(Image<I>& ima, + const p_array<mln_site(I)>& par, + const mln_value(I)& v); # ifndef MLN_INCLUDE_ONLY template <typename I> - inline - void line(Image<I>& ima_, - const mln_psite(I)& beg, const mln_psite(I)& end, - const mln_value(I)& v) + void polygon(Image<I>& ima_, + const p_array<mln_site(I)>& par, + const mln_value(I)& v, + unsigned output_ratio) { I& ima = exact(ima_); mln_precondition(ima.is_valid()); - if (! ima.has(beg)) - trace::warning("Begin site is not part of the given image."); - if (! ima.has(end)) - trace::warning("End site is not part of the given image."); - data::paste(pw::cst(v) | p_line2d(beg, end), - safe(ima).rw()); + mln_precondition(par.nelements() > 1); + + mln_site(I) p_last, tmp; + mln_piter(p_array<mln_site(I)>) p(par); + p_last = par[0] / output_ratio; + for_all(p) + { + tmp = p / output_ratio; + draw::line(ima, p_last, tmp, v); + p_last = tmp; + } + } + + template <typename I> + void polygon(Image<I>& ima, + const p_array<mln_site(I)>& par, + const mln_value(I)& v) + { + polygon(ima, par, v, 1); } # endif // ! MLN_INCLUDE_ONLY @@ -90,4 +102,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_DRAW_LINE_HH +#endif // ! MLN_DRAW_POLYGON_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara