
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-11-15 Matthieu Garrigues <garrigues@lrde.epita.fr> Review the debug namespace. * mln/debug/format.hh: Fix style. * mln/debug/iota.hh: Move spezialisations to iota.spe.hh. * mln/debug/iota.spe.hh: New, specializations of iota. * mln/debug/println.hh: Move spezialisations to println.spe.hh. * mln/debug/println.spe.hh: New, specializations of println. * mln/debug/println_with_border.hh: Move spezialisations to println_with_border.spe.hh. * mln/debug/println_with_border.spe.hh: New, specializations of println. * tests/debug_iota.cc: New, add a test for iota. --- mln/debug/format.hh | 12 +- mln/debug/iota.hh | 30 +++--- mln/debug/iota.spe.hh | 71 +++++++++++++++ mln/debug/println.hh | 106 +---------------------- mln/debug/println.spe.hh | 160 +++++++++++++++++++++++++++++++++++ mln/debug/println_with_border.hh | 56 +----------- mln/debug/println_with_border.spe.hh | 113 ++++++++++++++++++++++++ tests/debug_iota.cc | 49 ++++++++++ 8 files changed, 434 insertions(+), 163 deletions(-) Index: trunk/milena/tests/debug_iota.cc =================================================================== --- trunk/milena/tests/debug_iota.cc (revision 0) +++ trunk/milena/tests/debug_iota.cc (revision 1487) @@ -0,0 +1,49 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// 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_iota.cc + * + * \brief Tests on mln::debug::iota. + */ + +#include <mln/core/image2d.hh> + +#include <mln/value/int_u8.hh> + +#include <mln/debug/iota.hh> +#include <mln/debug/println.hh> + +int main() +{ + using namespace mln; + using value::int_u8; + + image2d<int_u8> in(32, 32); + + debug::iota(in); + debug::println(in); +} Index: trunk/milena/mln/debug/iota.spe.hh =================================================================== --- trunk/milena/mln/debug/iota.spe.hh (revision 0) +++ trunk/milena/mln/debug/iota.spe.hh (revision 1487) @@ -0,0 +1,71 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// 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_IOTA_SPE_HH +# define MLN_DEBUG_IOTA_SPE_HH + +/*! \file mln/debug/iota.spe.hh + * + * \brief Specializations for mln::debug::iota. + */ + +# include <mln/core/concept/image.hh> + + +namespace mln +{ + + namespace debug + { + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + template <typename I> + void + iota(trait::image::speed::fastest, I& input) + { + unsigned i = 0; + mln_pixter(I) p(input); + for_all(p) + // FIXME : remove the convertion when the bug will be + // resolved. + p.val() = ++i % int(mln_max(mln_value(I))); + } + + } // end of namespace mln::debug::impl + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::debug + +} // end of namespace mln + + +#endif // ! MLN_DEBUG_IOTA_SPE_HH Index: trunk/milena/mln/debug/println_with_border.spe.hh =================================================================== --- trunk/milena/mln/debug/println_with_border.spe.hh (revision 0) +++ trunk/milena/mln/debug/println_with_border.spe.hh (revision 1487) @@ -0,0 +1,113 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// 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_PRINTLN_WITH_BORDER_SPE_HH +# define MLN_DEBUG_PRINTLN_WITH_BORDER_SPE_HH + +/*! \file mln/debug/println_with_border_spe.hh + * + * \brief Specializations for mln::debug::println_with_border. + */ + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/window.hh> +# include <mln/debug/format.hh> + +namespace mln +{ + + namespace debug + { + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + +# ifdef MLN_CORE_BOX2D_HH + + // 2D version. + template <typename I> + void + println_with_border(const box2d& b, const I& input) + { + const std::size_t ncols = b.ncols() + 2 * input.border(); + for (size_t i = 0; i < input.ncells(); i++) + { + std::cout << format(input.buffer()[i]) << ' '; + if (((i + 1) % ncols) == 0) + std::cout << std::endl; + } + std::cout << std::endl; + } +# endif // MLN_CORE_BOX2D_HH + + +# ifdef MLN_CORE_BOX3D_HH + + // 3D version. + template <typename I> + void + println_with_border(const box3d& b, const I& input) + { + typedef mln_point(I) P; + + std::size_t len_s = b.len(P::dim - 3); + std::size_t len_r = b.len(P::dim - 2); + std::size_t len_c = b.len(P::dim - 1); + + std::size_t border = input.border(); + std::size_t real_len_s = len_s + 2 * border; + std::size_t real_len_c = len_c + 2 * border; + std::size_t real_len_r = len_r + 2 * border; + + for (std::size_t k = 0; k < real_len_s; ++k) + { + for (std::size_t j = 0; j < real_len_r; ++j) + { + for (std::size_t i = 0; i < real_len_c; ++i) + std::cout << format(input[k * (real_len_r * real_len_c) + j * real_len_c + i]) + << ' '; + std::cout << std::endl; + } + std::cout << std::endl; + } + std::cout << std::endl; + } + +# endif // MLN_CORE_BOX3D_HH + + } // end of namespace mln::debug::impl + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::debug + +} // end of namespace mln + + +#endif // ! MLN_DEBUG_PRINTLN_WITH_BORDER_SPE_HH Index: trunk/milena/mln/debug/println.hh =================================================================== --- trunk/milena/mln/debug/println.hh (revision 1486) +++ trunk/milena/mln/debug/println.hh (revision 1487) @@ -37,6 +37,8 @@ # include <mln/core/concept/window.hh> # include <mln/debug/format.hh> +// Specializations are in: +# include <mln/debug/println.spe.hh> namespace mln { @@ -54,9 +56,10 @@ namespace impl { - // generic version + // Generic version. template <typename S, typename I> - void println(const S&, const Image<I>& input_) + void + println(const S&, const Image<I>& input_) { const I& input = exact(input_); mln_piter(I) p(input.domain()); @@ -65,108 +68,13 @@ std::cout << std::endl; } -# ifdef MLN_CORE_BOX2D_HH - - // 2D version - template <typename I> - void println(const box2d& b, const I& input) - { - point2d p; - int& row = p.row(); - int& col = p.col(); - const int - max_row = b.max_row(), - max_col = b.max_col(); - - for (row = b.min_row(); row <= max_row; ++row) - { - for (col = b.min_col(); col <= max_col; ++col) - if (input.has(p)) - std::cout << format( input(p) ) << ' '; - else - std::cout << " "; - std::cout << std::endl; - } - std::cout << std::endl; - } - -# endif // MLN_CORE_BOX2D_HH - -# ifdef MLN_CORE_IMAGE2D_H_HH - - // Hexa version - template <typename I> - void println(const box2d_h& b, const hexa<I>& input) - { - typename hexa<I>::fwd_piter p(input.domain()); - - int c = 1; - int r = 1; - int row_len = 1 + (b.max_col() - b.min_col()) / 2; - - for_all(p) - { - if (input.has(p)) - std::cout << format(input(p)) << " "; - else - std::cout << " "; - - if (c >= row_len) - { - std::cout << std::endl; - if (r % 2) - std::cout << " "; - c = 0; - r++; - } - c++; - } - std::cout << std::endl; - } - -# endif // MLN_CORE_IMAGE2D_H_HH - - -# ifdef MLN_CORE_BOX3D_HH - - template <typename I> - void println(const box3d& b, const I& input) - { - point3d p; - int& sli = p.sli(); - int& row = p.row(); - int& col = p.col(); - const int - max_row = b.max_row(), - max_sli = b.max_sli(), - max_col = b.max_col(); - - for (sli = b.min_sli(); sli <= max_sli; ++sli) - { - for (row = b.min_row(); row <= max_row; ++row) - { - for (int i = max_row; i >= row; --i) - std::cout << ' '; - for (col = b.min_col(); col <= max_col; ++col) - if (input.has(p)) - std::cout << format( input(p) ) << ' '; - else - std::cout << " "; - std::cout << std::endl; - } - std::cout << std::endl; - } - } - -# endif // MLN_CORE_BOX3D_HH - } // end of namespace mln::debug::impl // Facade. - template <typename I> - void println(const Image<I>& input) + void + println(const Image<I>& input) { impl::println(exact(input).bbox(), exact(input)); } Index: trunk/milena/mln/debug/format.hh =================================================================== --- trunk/milena/mln/debug/format.hh (revision 1486) +++ trunk/milena/mln/debug/format.hh (revision 1487) @@ -61,22 +61,26 @@ # ifndef MLN_INCLUDE_ONLY template <typename T> - const T& format(const T& v) + const T& + format(const T& v) { return v; } - char format(bool v) + char + format(bool v) { return v ? '|' : '-'; } - signed short format(signed char v) + signed short + format(signed char v) { return v; } - unsigned short format(unsigned char v) + unsigned short + format(unsigned char v) { return v; } Index: trunk/milena/mln/debug/iota.hh =================================================================== --- trunk/milena/mln/debug/iota.hh (revision 1486) +++ trunk/milena/mln/debug/iota.hh (revision 1487) @@ -35,6 +35,9 @@ # include <mln/core/concept/image.hh> +// Specializations are in: +# include <mln/debug/iota.spe.hh> + namespace mln { @@ -42,7 +45,11 @@ namespace debug { - /// FIXME + /*! Fill the image \p input with successive values. + * + * \param[in,out] destination The image in which values are + * assigned. + */ template <typename I> void iota(Image<I>& input); @@ -53,31 +60,28 @@ { template <typename I> - void iota(trait::image::speed::any, I& input) + void + iota(trait::image::speed::any, I& input) { unsigned i = 0; mln_piter(I) p(input.domain()); for_all(p) - input(p) = ++i; - } - - template <typename I> - void iota(trait::image::speed::fastest, I& input) - { - unsigned i = 0; - mln_pixter(I) p(input); - for_all(p) - p.val() = ++i; + // FIXME : remove the convertion when the bug will be + // resolved. + input(p) = ++i % int(mln_max(mln_value(I))); } } // end of namespace mln::debug::impl template <typename I> - void iota(Image<I>& input) + void + iota(Image<I>& input) { + trace::entering("debug::iota"); mln_precondition(exact(input).has_data()); impl::iota(mln_trait_image_speed(I)(), exact(input)); + trace::exiting("debug::iota"); } # endif // ! MLN_INCLUDE_ONLY Index: trunk/milena/mln/debug/println.spe.hh =================================================================== --- trunk/milena/mln/debug/println.spe.hh (revision 0) +++ trunk/milena/mln/debug/println.spe.hh (revision 1487) @@ -0,0 +1,160 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// 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_PRINTLN_SPE_HH +# define MLN_DEBUG_PRINTLN_SPE_HH + +/*! \file mln/debug/println.spe.hh + * + * \brief Specializations for mln::debug::println. + */ + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/window.hh> +# include <mln/debug/format.hh> + + +namespace mln +{ + + namespace debug + { + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + +# ifdef MLN_CORE_BOX2D_HH + + // 2D version. + template <typename I> + void + println(const box2d& b, const I& input) + { + point2d p; + int& row = p.row(); + int& col = p.col(); + const int + max_row = b.max_row(), + max_col = b.max_col(); + + for (row = b.min_row(); row <= max_row; ++row) + { + for (col = b.min_col(); col <= max_col; ++col) + if (input.has(p)) + std::cout << format(input(p)) << ' '; + else + std::cout << " "; + std::cout << std::endl; + } + std::cout << std::endl; + } + +# endif // MLN_CORE_BOX2D_HH + +# ifdef MLN_CORE_IMAGE2D_H_HH + + // Hexa version. + template <typename I> + void + println(const box2d_h& b, const hexa<I>& input) + { + typename hexa<I>::fwd_piter p(input.domain()); + + int c = 1; + int r = 1; + int row_len = 1 + (b.max_col() - b.min_col()) / 2; + + for_all(p) + { + if (input.has(p)) + std::cout << format(input(p)) << " "; + else + std::cout << " "; + + if (c >= row_len) + { + std::cout << std::endl; + if (r % 2) + std::cout << " "; + c = 0; + r++; + } + c++; + } + std::cout << std::endl; + } + +# endif // MLN_CORE_IMAGE2D_H_HH + + +# ifdef MLN_CORE_BOX3D_HH + + // 3D version. + template <typename I> + void + println(const box3d& b, const I& input) + { + point3d p; + int& sli = p.sli(); + int& row = p.row(); + int& col = p.col(); + const int + max_row = b.max_row(), + max_sli = b.max_sli(), + max_col = b.max_col(); + + for (sli = b.min_sli(); sli <= max_sli; ++sli) + { + for (row = b.min_row(); row <= max_row; ++row) + { + for (int i = max_row; i >= row; --i) + std::cout << ' '; + for (col = b.min_col(); col <= max_col; ++col) + if (input.has(p)) + std::cout << format(input(p)) << ' '; + else + std::cout << " "; + std::cout << std::endl; + } + std::cout << std::endl; + } + } + +# endif // MLN_CORE_BOX3D_HH + + } // end of namespace mln::debug::impl + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::debug + +} // end of namespace mln + + +#endif // ! MLN_DEBUG_PRINTLN_SPE_HH Index: trunk/milena/mln/debug/println_with_border.hh =================================================================== --- trunk/milena/mln/debug/println_with_border.hh (revision 1486) +++ trunk/milena/mln/debug/println_with_border.hh (revision 1487) @@ -40,6 +40,9 @@ # include <mln/core/box2d.hh> # include <mln/core/box3d.hh> +// Specializations are in: +# include <mln/debug/println_with_border.spe.hh> + namespace mln { @@ -56,64 +59,23 @@ namespace impl { - // generic version + // Generic version. template <typename S, typename I> - void println_with_border(const S&, const I& input) - { - for (size_t i = 0; i < input.ncells(); i++) - std::cout << format( input.buffer()[i] ) << ' '; - std::cout << std::endl; - } - - // 2D version - template <typename I> - void println_with_border(const box2d& b, const I& input) + void + println_with_border(const S&, const I& input) { - const std::size_t ncols = b.ncols() + 2 * input.border(); for (size_t i = 0; i < input.ncells(); i++) - { std::cout << format( input.buffer()[i] ) << ' '; - if (((i+1) % ncols) == 0) std::cout << std::endl; } - std::cout << std::endl; - } - - // 3D version - template <typename I> - void println_with_border(const box3d& b, const I& input) - { - typedef mln_point(I) P; - - std::size_t len_s = b.len(P::dim - 3); - std::size_t len_r = b.len(P::dim - 2); - std::size_t len_c = b.len(P::dim - 1); - - std::size_t border = input.border (); - std::size_t real_len_s = len_s + 2 * border; - std::size_t real_len_c = len_c + 2 * border; - std::size_t real_len_r = len_r + 2 * border; - for (std::size_t k = 0; k < real_len_s; ++k) - { - for (std::size_t j = 0; j < real_len_r; ++j) - { - for (std::size_t i = 0; i < real_len_c; ++i) - std::cout << format(input[k * (real_len_r * real_len_c) + j * real_len_c + i]) - << ' '; - std::cout << std::endl; - } - std::cout << std::endl; - } - std::cout << std::endl; - } } // end of namespace mln::debug::impl - - // facade + // Facade. template <typename I> - void println_with_border(const Image<I>& input) + void + println_with_border(const Image<I>& input) { mlc_is(mln_trait_image_speed(I), trait::image::speed::fastest)::check();