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);
+}
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add debug conversion from 3D image to 2D mozaic image.
* mln/debug/slices_2d.hh: New.
* mln/debug/all.hh: Update.
* mln/core/image/slice_image.hh (operator): New conversion.
* mln/core/image/image3d.hh
(nslices, nrows, ncols): New methods.
* tests/debug/slices_2d.cc: New.
* tests/debug/Makefile.am: Update.
mln/core/image/image3d.hh | 37 +++++++++++++
mln/core/image/slice_image.hh | 18 +++++-
mln/debug/all.hh | 3 +
mln/debug/slices_2d.hh | 114 ++++++++++++++++++++++++++++++++++++++++++
tests/debug/Makefile.am | 4 +
tests/debug/slices_2d.cc | 72 ++++++++++++++++++++++++++
6 files changed, 245 insertions(+), 3 deletions(-)
Index: mln/debug/slices_2d.hh
--- mln/debug/slices_2d.hh (revision 0)
+++ mln/debug/slices_2d.hh (revision 0)
@@ -0,0 +1,114 @@
+// 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_DEBUG_SLICES_2D_HH
+# define MLN_DEBUG_SLICES_2D_HH
+
+/// \file mln/debug/slices_2d.hh
+///
+/// Create a 2D image of the slices of the 3D image \p input.
+
+# include <mln/core/image/image2d.hh>
+
+# include <mln/core/image/image3d.hh>
+# include <mln/core/image/slice_image.hh>
+
+# include <mln/core/image/p2p_image.hh>
+# include <mln/fun/p2p/translation.hh>
+
+# include <mln/data/paste.hh>
+# include <mln/data/fill.hh>
+
+
+
+namespace mln
+{
+
+ namespace debug
+ {
+
+ /// Create a 2D image of the slices of the 3D image \p input.
+ ///
+ template <typename I>
+ image2d<mln_value(I)>
+ slices_2d(const Image<I>& input,
+ unsigned n_horizontal, unsigned n_vertical,
+ const mln_value(I)& bg);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ image2d<mln_value(I)>
+ slices_2d(const Image<I>& input_,
+ unsigned n_horizontal, unsigned n_vertical,
+ const mln_value(I)& bg)
+ {
+ trace::entering("debug::slices_2d");
+ mlc_equal(mln_pset(I), box3d)::check();
+
+ const I& input = exact(input_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(n_horizontal > 0 && n_vertical > 0);
+ mln_precondition(input.nslices() <= n_horizontal * n_vertical);
+
+ image2d<mln_value(I)> output(input.nrows() * n_vertical,
+ input.ncols() * n_horizontal);
+ if (input.nslices() != n_horizontal * n_vertical)
+ data::fill(output, bg);
+
+ for (unsigned i = 0; i < n_vertical; ++i)
+ for (unsigned j = 0; j < n_horizontal; ++j)
+ {
+ unsigned sli = i * n_horizontal + j;
+ if (sli == input.nslices())
+ {
+ i = n_vertical;
+ j = n_horizontal;
+ break;
+ }
+ dpoint2d dp(i * input.nrows(), j * input.ncols());
+ data::paste(apply_p2p(slice(input, sli),
+ fun::p2p::translation(dp)),
+ output);
+ }
+
+ trace::exiting("debug::slices_2d");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::debug
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DEBUG_SLICES_2D_HH
Index: mln/debug/all.hh
--- mln/debug/all.hh (revision 3217)
+++ mln/debug/all.hh (working copy)
@@ -46,6 +46,7 @@
}
+
# include <mln/debug/colorize.hh>
# include <mln/debug/format.hh>
# include <mln/debug/draw_graph.hh>
@@ -54,5 +55,7 @@
# include <mln/debug/println_with_border.hh>
# include <mln/debug/put_word.hh>
# include <mln/debug/quiet.hh>
+# include <mln/debug/slices_2d.hh>
+
#endif // ! MLN_DEBUG_ALL_HH
Index: mln/core/image/slice_image.hh
--- mln/core/image/slice_image.hh (revision 3217)
+++ mln/core/image/slice_image.hh (working copy)
@@ -118,6 +118,10 @@
/// Read-write access to the image value located at point \p p.
mln_morpher_lvalue(I) operator()(const point2d& p);
+
+
+ /// Const promotion via conversion.
+ operator slice_image<const I>() const;
};
@@ -245,6 +249,16 @@
return this->data_->ima_(p_);
}
+ template <typename I>
+ inline
+ slice_image<I>::operator slice_image<const I>() const
+ {
+ mln_precondition(this->is_valid());
+ slice_image<const I> tmp(this->data_->ima_,
+ this->data_->sli_);
+ return tmp;
+ }
+
// Routines.
@@ -271,12 +285,12 @@
{
mlc_equal(mln_pset(I), box3d)::check();
- I& ima = exact(ima_);
+ const I& ima = exact(ima_);
mln_precondition(ima.is_valid());
mln_precondition(sli >= ima.domain().pmin().sli() &&
sli <= ima.domain().pmax().sli());
- slice_image<I> tmp(ima, sli);
+ slice_image<const I> tmp(ima, sli);
return tmp;
}
Index: mln/core/image/image3d.hh
--- mln/core/image/image3d.hh (revision 3217)
+++ mln/core/image/image3d.hh (working copy)
@@ -208,6 +208,16 @@
T& at_(def::coord sli, def::coord row, def::coord col);
+ /// Give the number of slices.
+ unsigned nslices() const;
+
+ /// Give the number of rows.
+ unsigned nrows() const;
+
+ /// Give the number of columns.
+ unsigned ncols() const;
+
+
/// Fast Image method
/// Give the offset corresponding to the delta-point \p dp.
@@ -501,6 +511,33 @@
template <typename T>
inline
+ unsigned
+ image3d<T>::nslices() const
+ {
+ mln_precondition(this->is_valid());
+ return this->data_->b_.len(0);
+ }
+
+ template <typename T>
+ inline
+ unsigned
+ image3d<T>::nrows() const
+ {
+ mln_precondition(this->is_valid());
+ return this->data_->b_.len(1);
+ }
+
+ template <typename T>
+ inline
+ unsigned
+ image3d<T>::ncols() const
+ {
+ mln_precondition(this->is_valid());
+ return this->data_->b_.len(2);
+ }
+
+ template <typename T>
+ inline
const T*
image3d<T>::buffer() const
{
Index: tests/debug/Makefile.am
--- tests/debug/Makefile.am (revision 3217)
+++ tests/debug/Makefile.am (working copy)
@@ -5,10 +5,12 @@
check_PROGRAMS = \
println \
println_with_border \
- iota
+ iota \
+ slices_2d
println_SOURCES = println.cc
println_with_border_SOURCES = println_with_border.cc
iota_SOURCES = iota.cc
+slices_2d_SOURCES = slices_2d.cc
TESTS = $(check_PROGRAMS)
Index: tests/debug/slices_2d.cc
--- tests/debug/slices_2d.cc (revision 0)
+++ tests/debug/slices_2d.cc (revision 0)
@@ -0,0 +1,72 @@
+// 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/debug/slices_2d.cc
+///
+/// Tests on mln::debug::slices_2d.
+
+#include <mln/debug/slices_2d.hh>
+#include <mln/debug/iota.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image3d<int> vol(5, 2, 3);
+ debug::iota(vol);
+
+ // 1 2 3
+ // 4 5 6
+ //
+ // 7 8 9
+ // 10 11 12
+ //
+ // 13 14 15
+ // 16 17 18
+ //
+ // 19 20 21
+ // 22 23 24
+ //
+ // 25 26 27
+ // 28 29 30
+
+ image2d<int> ima = debug::slices_2d(vol, 2, 3,
+ -1);
+
+ // 1 2 3 7 8 9
+ // 4 5 6 10 11 12
+ // 13 14 15 19 20 21
+ // 16 17 18 22 23 24
+ // 25 26 27 -1 -1 -1
+ // 28 29 30 -1 -1 -1
+
+ mln_assertion(ima.at_(0,0) == 1);
+ mln_assertion(ima.at_(5,2) == 30);
+ mln_assertion(ima.at_(5,5) == -1);
+
+}