https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add conversion from site set to image.
* mln/convert/impl/from_image_to_site_set.hh: Fix file doc.
* mln/convert/impl/from_site_set_to_image.hh: New.
* mln/convert/impl/all.hh: Update.
* mln/convert/from_to.hh (from_to_dispatch): New overload.
* mln/convert/from_to.hxx (from_to_): New fwd declaration.
* tests/convert/impl: New directory.
* tests/convert/impl/from_site_set_to_image.cc: New.
mln/convert/from_to.hh | 12 +++
mln/convert/from_to.hxx | 6 +
mln/convert/impl/all.hh | 1
mln/convert/impl/from_image_to_site_set.hh | 2
mln/convert/impl/from_site_set_to_image.hh | 92 +++++++++++++++++++++++++++
tests/convert/impl/from_site_set_to_image.cc | 54 +++++++++++++++
6 files changed, 166 insertions(+), 1 deletion(-)
Index: mln/convert/impl/from_image_to_site_set.hh
--- mln/convert/impl/from_image_to_site_set.hh (revision 3222)
+++ mln/convert/impl/from_image_to_site_set.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef MLN_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH
# define MLN_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH
-/// \file mln/convert/from_to.hh
+/// \file mln/convert/impl/from_image_to_site_set.hh
///
/// General conversion procedure from an image to a site_set.
///
Index: mln/convert/impl/from_site_set_to_image.hh
--- mln/convert/impl/from_site_set_to_image.hh (revision 0)
+++ mln/convert/impl/from_site_set_to_image.hh (revision 0)
@@ -0,0 +1,92 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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.
+
+#ifndef MLN_CONVERT_IMPL_FROM_SITE_SET_TO_IMAGE_HH
+# define MLN_CONVERT_IMPL_FROM_SITE_SET_TO_IMAGE_HH
+
+/// \file mln/convert/impl/from_site_set_to_image.hh
+///
+/// General conversion procedure from a site_set to an image.
+
+# include <mln/core/image/sub_image.hh>
+# include <mln/geom/bbox.hh>
+# include <mln/trait/image_from_grid.hh>
+# include <mln/data/fill.hh>
+
+
+namespace mln
+{
+
+ // Forward declarations.
+ template <typename E> struct Site_Set;
+ template <typename E> struct Image;
+
+
+ namespace convert
+ {
+
+ namespace impl
+ {
+
+ /// Conversion of an image \p from towards a site set \p to.
+ template <typename S, typename I>
+ void
+ from_site_set_to_image(const Site_Set<S>& from, Image<I>& to);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S, typename I>
+ inline
+ void
+ from_site_set_to_image(const Site_Set<S>& from_, Image<I>&
to_)
+ {
+ const S& from = exact(from_);
+ I& to = exact(to_);
+
+ box<mln_site(S)> b = geom::bbox(from);
+
+ typedef mln_deduce(I, site, grid) G;
+ typedef mln_value(I) V;
+ mln_image_from_grid(G, V) ima(b);
+ data::fill(ima, false);
+ data::fill((ima | from).rw(), true);
+
+ to = ima;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert::impl
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_IMPL_FROM_SITE_SET_TO_IMAGE_HH
Index: mln/convert/impl/all.hh
--- mln/convert/impl/all.hh (revision 3222)
+++ mln/convert/impl/all.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/convert/impl/from_float_to_value.hh>
# include <mln/convert/impl/from_image_to_site_set.hh>
# include <mln/convert/impl/from_int_to_value.hh>
+# include <mln/convert/impl/from_site_set_to_image.hh>
# include <mln/convert/impl/from_value_to_value.hh>
Index: mln/convert/from_to.hh
--- mln/convert/from_to.hh (revision 3222)
+++ mln/convert/from_to.hh (working copy)
@@ -82,6 +82,18 @@
}
+ // Site_Set -> Image.
+ template <typename S, typename I>
+ inline
+ void
+ from_to_dispatch(const Site_Set<S>& from, Image<I>& to)
+ {
+ mlc_converts_to(mln_site(S), mln_site(I))::check(); // FIXME: Is it too restrictive?
+ mln_precondition(exact(from).is_valid());
+ mln::convert::impl::from_site_set_to_image(from, to);
+ }
+
+
// Value -> Value
template <typename F, typename T>
inline
Index: mln/convert/from_to.hxx
--- mln/convert/from_to.hxx (revision 3222)
+++ mln/convert/from_to.hxx (working copy)
@@ -341,6 +341,12 @@
from_to_(const Accumulator<A>& from, mln_result(A)& to);
+
+ // Site_Set -> Image.
+ template <typename S, typename I>
+ void
+ from_to_(const Site_Set<S>& from, Image<I>& to);
+
// Site_Set -> std::set
template <typename S, typename P, typename _C>
void
Index: tests/convert/impl/from_site_set_to_image.cc
--- tests/convert/impl/from_site_set_to_image.cc (revision 0)
+++ tests/convert/impl/from_site_set_to_image.cc (revision 0)
@@ -0,0 +1,54 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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/impl/from_site_set_to_image.cc
+///
+/// Tests on mln::convert::impl::from_site_set_to_image.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/site_set/p_array.hh>
+#include <mln/convert/from_to.hh>
+
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ p_array<point2d> arr;
+ point2d p(1,1);
+ arr.append(p);
+ dpoint2d dp[] = { right, right, down, down, left, left, up };
+ for (unsigned i = 0; i < 7; ++i)
+ p += dp[i], arr.append(p);
+
+ image2d<bool> ima;
+ convert::impl::from_site_set_to_image(arr, ima);
+
+ // debug::println(ima);
+}