
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@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); + +}