https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a maker of image3d from an array of 2D images.
* mln/trait/concrete.hh: Upgrade file doc style.
(mon_concrete_): New macro.
* mln/core/image/slice_image.hh (ch_value): New specialization.
* mln/make/image2d.hh (todo): New.
* mln/make/image3d.hh: New.
* mln/make/all.hh: Update.
* tests/make/image3d.cc: New.
* tests/make/Makefile.am: Update.
mln/core/image/slice_image.hh | 14 ++++++
mln/make/all.hh | 1
mln/make/image2d.hh | 3 +
mln/make/image3d.hh | 90 ++++++++++++++++++++++++++++++++++++++++++
mln/trait/concrete.hh | 12 +++--
tests/make/Makefile.am | 2
tests/make/image3d.cc | 54 +++++++++++++++++++++++++
7 files changed, 171 insertions(+), 5 deletions(-)
Index: mln/trait/concrete.hh
--- mln/trait/concrete.hh (revision 3215)
+++ mln/trait/concrete.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 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
@@ -28,15 +29,16 @@
#ifndef MLN_TRAIT_CONCRETE_HH
# define MLN_TRAIT_CONCRETE_HH
-/*! \file mln/trait/concrete.hh
- *
- * \brief Definition of the concrete image trait.
- */
+/// \file mln/trait/concrete.hh
+///
+/// Definition of the concrete image trait.
# include <mln/trait/ch_value.hh>
# define mln_concrete(I) typename mln::trait::concrete< I >::ret
+# define mln_concrete_(I) mln::trait::concrete< I >::ret
+
# define mln_concrete_ch_value(I, V) mln_ch_value(mln_concrete(I), V)
Index: mln/core/image/slice_image.hh
--- mln/core/image/slice_image.hh (revision 3215)
+++ mln/core/image/slice_image.hh (working copy)
@@ -132,6 +132,20 @@
+
+ namespace trait
+ {
+
+ template <typename I, typename V>
+ struct ch_value< slice_image<I>, V >
+ {
+ typedef image2d<V> ret;
+ };
+
+ } // end of namespace mln::trait
+
+
+
# ifndef MLN_INCLUDE_ONLY
Index: mln/make/all.hh
--- mln/make/all.hh (revision 3215)
+++ mln/make/all.hh (working copy)
@@ -51,6 +51,7 @@
# include <mln/make/graph.hh>
# include <mln/make/image.hh>
# include <mln/make/image2d.hh>
+# include <mln/make/image3d.hh>
# include <mln/make/mat.hh>
# include <mln/make/pix.hh>
# include <mln/make/pixel.hh>
Index: mln/make/image2d.hh
--- mln/make/image2d.hh (revision 3215)
+++ mln/make/image2d.hh (working copy)
@@ -31,6 +31,9 @@
/// \file mln/make/image2d.hh
///
/// Routine to create a 2D image from a 1D array.
+///
+/// \todo Think about removing make::image2d since it is redundant
+/// with convert::to and convert::from_to.
# include <mln/core/image/image2d.hh>
Index: mln/make/image3d.hh
--- mln/make/image3d.hh (revision 0)
+++ mln/make/image3d.hh (revision 0)
@@ -0,0 +1,90 @@
+// 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_MAKE_IMAGE3D_HH
+# define MLN_MAKE_IMAGE3D_HH
+
+/// \file mln/make/image3d.hh
+///
+/// Routine to create a 3D image from an array of 2D images.
+///
+/// \todo Think about removing make::image3d since it is redundant
+/// with convert::to and convert::from_to.
+
+# include <mln/core/image/image3d.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/core/image/slice_image.hh>
+# include <mln/data/paste.hh>
+# include <mln/util/array.hh>
+
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /// Create an image3d from an array of 2D images.
+ ///
+ template <typename I>
+ mln::image3d<mln_value(I)>
+ image3d(const util::array<I>& ima);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ mln::image3d<mln_value(I)>
+ image3d(const util::array<I>& ima)
+ {
+ mlc_is_a(mln_pset(I), Box)::check();
+ mln_precondition(! ima.is_empty());
+
+ def::coord n_slices = ima.nelements();
+ mln::box2d b = ima[0].domain();
+ mln::box3d b_ = make::box3d(0, b.pmin().row(), b.pmin().col(),
+ n_slices - 1, b.pmax().row(), b.pmax().col());
+ mln::image3d<mln_value(I)> output(b_);
+ for (def::coord sli = 0; sli < n_slices; ++sli)
+ {
+ mln_assertion(ima[sli].domain() == b);
+ data::paste(ima[sli], slice(output, sli).rw());
+ }
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_IMAGE3D_HH
Index: tests/make/Makefile.am
--- tests/make/Makefile.am (revision 3215)
+++ tests/make/Makefile.am (working copy)
@@ -5,12 +5,14 @@
check_PROGRAMS = \
dual_neighb \
image2d \
+ image3d \
mat \
w_window \
w_window_directional
dual_neighb_SOURCES = dual_neighb.cc
image2d_SOURCES = image2d.cc
+image3d_SOURCES = image3d.cc
mat_SOURCES = mat.cc
w_window_SOURCES = w_window.cc
w_window_directional_SOURCES = w_window_directional.cc
Index: tests/make/image3d.cc
--- tests/make/image3d.cc (revision 0)
+++ tests/make/image3d.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/make/image3d.cc
+///
+/// Tests on mln::make::image3d.
+
+#include <mln/make/image3d.hh>
+#include <mln/debug/iota.hh>
+#include <mln/core/routine/duplicate.hh>
+#include <mln/level/compare.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ unsigned n_slices = 3;
+
+ image3d<int> vol(n_slices, 2, 4);
+ debug::iota(vol);
+
+ typedef image2d<int> I;
+ util::array<I> ima;
+ for (unsigned i = 0; i < n_slices; ++i)
+ ima.append( duplicate(slice(vol, i)) );
+
+ image3d<int> vol_ = make::image3d(ima);
+ mln_assertion(vol_ == vol);
+}