1058: Replace 2D specific methods in 2D images by routines.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Replace 2D specific methods in 2D images by routines. * mln/geom/max_col.hh: New. * mln/geom/nrows.hh: New. * mln/geom/min_row.hh: New. * mln/geom/max_row.hh: New. * mln/geom/ncols.hh: New. * mln/geom/size2d.hh: New. * mln/geom/min_col.hh: New. * mln/core/image2d_b.hh (image2d_b): Remove inheritance to box_impl. * tests/image2d_b.cc, * mln/core/pixter2d_b.hh, * mln/io/save_pgm.hh, * mln/io/load_pgm.hh, * mln/level/was.median.hh, * mln/level/median.hh, * mln/level/fast_median.hh, * mln/canvas/sbrowsing.hh: Update. mln/canvas/sbrowsing.hh | 7 ++-- mln/core/image2d_b.hh | 4 -- mln/core/pixter2d_b.hh | 5 ++- mln/geom/max_col.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++++ mln/geom/max_row.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++++ mln/geom/min_col.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++++ mln/geom/min_row.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++++ mln/geom/ncols.hh | 67 +++++++++++++++++++++++++++++++++++++++++++++++ mln/geom/nrows.hh | 67 +++++++++++++++++++++++++++++++++++++++++++++++ mln/geom/size2d.hh | 40 ++++++++++++++++++++++++++++ mln/io/load_pgm.hh | 10 +++---- mln/io/save_pgm.hh | 17 +++++------ mln/level/fast_median.hh | 4 +- mln/level/median.hh | 10 ++++--- mln/level/was.median.hh | 13 ++++----- tests/image2d_b.cc | 3 +- 16 files changed, 475 insertions(+), 36 deletions(-) Index: tests/image2d_b.cc --- tests/image2d_b.cc (revision 1057) +++ tests/image2d_b.cc (working copy) @@ -31,6 +31,7 @@ */ #include <mln/core/image2d_b.hh> +#include <mln/geom/size2d.hh> int main() @@ -43,6 +44,6 @@ image2d_b<int> f(nrows, ncols, border); - mln_assertion(f.npoints() = f.nrows() * f.ncols()); + mln_assertion(f.npoints() = geom::nrows(f) * geom::ncols(f)); mln_assertion(f.ncells() = (nrows + 2 * border) * (ncols + 2 * border)); } Index: mln/geom/max_col.hh --- mln/geom/max_col.hh (revision 0) +++ mln/geom/max_col.hh (revision 0) @@ -0,0 +1,66 @@ +// 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_GEOM_MAX_COL_HH +# define MLN_GEOM_MAX_COL_HH + +/*! \file mln/geom/max_col.hh + * + * \brief Give the maximum column of an image. + */ + +# include <mln/core/concept/image.hh> + + +namespace mln +{ + + namespace geom + { + + /// Give the maximum column of an image. + template <typename I> + mln_coord(I) max_col(const Image<I>& ima); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + mln_coord(I) max_col(const Image<I>& ima) + { + mln_precondition(exact(ima).has_data()); + return exact(ima).bbox().pmax().col(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::geom + +} // end of namespace mln + + +#endif // ! MLN_GEOM_MAX_COL_HH Index: mln/geom/nrows.hh --- mln/geom/nrows.hh (revision 0) +++ mln/geom/nrows.hh (revision 0) @@ -0,0 +1,67 @@ +// 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_GEOM_NROWS_HH +# define MLN_GEOM_NROWS_HH + +/*! \file mln/geom/nrows.hh + * + * \brief Give the number of rows of an image. + */ + +# include <mln/geom/min_row.hh> +# include <mln/geom/max_row.hh> + + +namespace mln +{ + + namespace geom + { + + /// Give the number of rows of an image. + template <typename I> + unsigned nrows(const Image<I>& ima); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + unsigned nrows(const Image<I>& ima) + { + mln_precondition(exact(ima).has_data()); + return geom::max_row(ima) - geom::min_row(ima) + 1; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::geom + +} // end of namespace mln + + +#endif // ! MLN_GEOM_NROWS_HH Index: mln/geom/min_row.hh --- mln/geom/min_row.hh (revision 0) +++ mln/geom/min_row.hh (revision 0) @@ -0,0 +1,66 @@ +// 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_GEOM_MIN_ROW_HH +# define MLN_GEOM_MIN_ROW_HH + +/*! \file mln/geom/min_row.hh + * + * \brief Give the minimum row of an image. + */ + +# include <mln/core/concept/image.hh> + + +namespace mln +{ + + namespace geom + { + + /// Give the minimum row of an image. + template <typename I> + mln_coord(I) min_row(const Image<I>& ima); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + mln_coord(I) min_row(const Image<I>& ima) + { + mln_precondition(exact(ima).has_data()); + return exact(ima).bbox().pmin().row(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::geom + +} // end of namespace mln + + +#endif // ! MLN_GEOM_MIN_ROW_HH Index: mln/geom/max_row.hh --- mln/geom/max_row.hh (revision 0) +++ mln/geom/max_row.hh (revision 0) @@ -0,0 +1,66 @@ +// 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_GEOM_MAX_ROW_HH +# define MLN_GEOM_MAX_ROW_HH + +/*! \file mln/geom/max_row.hh + * + * \brief Give the maximum row of an image. + */ + +# include <mln/core/concept/image.hh> + + +namespace mln +{ + + namespace geom + { + + /// Give the maximum row of an image. + template <typename I> + mln_coord(I) max_row(const Image<I>& ima); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + mln_coord(I) max_row(const Image<I>& ima) + { + mln_precondition(exact(ima).has_data()); + return exact(ima).bbox().pmax().row(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::geom + +} // end of namespace mln + + +#endif // ! MLN_GEOM_MAX_ROW_HH Index: mln/geom/ncols.hh --- mln/geom/ncols.hh (revision 0) +++ mln/geom/ncols.hh (revision 0) @@ -0,0 +1,67 @@ +// 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_GEOM_NCOLS_HH +# define MLN_GEOM_NCOLS_HH + +/*! \file mln/geom/ncols.hh + * + * \brief Give the number of columns of an image. + */ + +# include <mln/geom/min_col.hh> +# include <mln/geom/max_col.hh> + + +namespace mln +{ + + namespace geom + { + + /// Give the number of columns of an image. + template <typename I> + unsigned ncols(const Image<I>& ima); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + unsigned ncols(const Image<I>& ima) + { + mln_precondition(exact(ima).has_data()); + return geom::max_col(ima) - geom::min_col(ima) + 1; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::geom + +} // end of namespace mln + + +#endif // ! MLN_GEOM_NCOLS_HH Index: mln/geom/size2d.hh --- mln/geom/size2d.hh (revision 0) +++ mln/geom/size2d.hh (revision 0) @@ -0,0 +1,40 @@ +// 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_GEOM_SIZE2D_HH +# define MLN_GEOM_SIZE2D_HH + +/*! \file mln/geom/size2d.hh + * + * \brief Facade to include 2D size access routines. + */ + +# include <mln/geom/nrows.hh> +# include <mln/geom/ncols.hh> + + +#endif // ! MLN_GEOM_SIZE2D_HH Index: mln/geom/min_col.hh --- mln/geom/min_col.hh (revision 0) +++ mln/geom/min_col.hh (revision 0) @@ -0,0 +1,66 @@ +// 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_GEOM_MIN_COL_HH +# define MLN_GEOM_MIN_COL_HH + +/*! \file mln/geom/min_col.hh + * + * \brief Give the minimum column of an image. + */ + +# include <mln/core/concept/image.hh> + + +namespace mln +{ + + namespace geom + { + + /// Give the minimum column of an image. + template <typename I> + mln_coord(I) min_col(const Image<I>& ima); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + mln_coord(I) min_col(const Image<I>& ima) + { + mln_precondition(exact(ima).has_data()); + return exact(ima).bbox().pmin().col(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::geom + +} // end of namespace mln + + +#endif // ! MLN_GEOM_MIN_COL_HH Index: mln/core/pixter2d_b.hh --- mln/core/pixter2d_b.hh (revision 1057) +++ mln/core/pixter2d_b.hh (working copy) @@ -35,6 +35,7 @@ # include <mln/core/internal/pixel_iterator_base.hh> # include <mln/core/point2d.hh> +# include <mln/geom/size2d.hh> @@ -84,8 +85,8 @@ { mln_precondition(image.has_data()); border_x2_ = 2 * image.border(); - row_offset_ = image.max_col() - image.min_col() + 1 + border_x2_; - eor_ = & image.at(image.min_row(), image.max_col()) + 1; + row_offset_ = geom::max_col(image) - geom::min_col(image) + 1 + border_x2_; + eor_ = & image.at(geom::min_row(image), geom::max_col(image)) + 1; } template <typename I> Index: mln/core/image2d_b.hh --- mln/core/image2d_b.hh (revision 1057) +++ mln/core/image2d_b.hh (working copy) @@ -34,7 +34,6 @@ */ # include <mln/core/internal/image_base.hh> -# include <mln/core/internal/box_impl.hh> # include <mln/core/box2d.hh> # include <mln/border/thickness.hh> @@ -75,8 +74,7 @@ * thickness around data. */ template <typename T> - struct image2d_b : public internal::image_base_< box2d, image2d_b<T> >, - public internal::box_impl_< 2, int, image2d_b<T> > + struct image2d_b : public internal::image_base_< box2d, image2d_b<T> > { // Warning: just to make effective types appear in Doxygen: typedef box2d pset; Index: mln/io/save_pgm.hh --- mln/io/save_pgm.hh (revision 1057) +++ mln/io/save_pgm.hh (working copy) @@ -33,6 +33,7 @@ # include <fstream> # include <mln/core/image2d_b.hh> +# include <mln/geom/size2d.hh> # include <mln/value/int_u8.hh> @@ -53,16 +54,16 @@ } file << "P5" << std::endl; file << "# olena" << std::endl; - file << ima.ncols() << ' ' << ima.nrows() << std::endl; + file << geom::ncols(ima) << ' ' << geom::nrows(ima) << std::endl; file << "255" << std::endl; const int - min_row = ima.domain().pmin().row(), - max_row = ima.domain().pmax().row(); + min_row = geom::min_row(ima), + max_row = geom::max_row(ima); point2d p; if (sizeof(value::int_u8) = 1) { - p.col() = ima.domain().pmin().col(); - size_t len = ima.ncols(); + p.col() = geom::min_col(ima); + size_t len = geom::ncols(ima); for (p.row() = min_row; p.row() <= max_row; ++p.row()) file.write((char*)(& ima(p)), len); } @@ -70,10 +71,8 @@ { // FIXME: code for g++-2.95 when sizeof(int_u8) = 2!!! const int - min_col = ima.domain().pmin().col(), - max_col = ima.domain().pmax().col(); - std::cout << min_row << ' ' << max_row << std::endl; - std::cout << min_col << ' ' << max_col << std::endl; + min_col = geom::min_col(ima), + max_col = geom::max_col(ima); for (p.row() = min_row; p.row() <= max_row; ++p.row()) for (p.col() = min_col; p.col() <= max_col; ++p.col()) { Index: mln/io/load_pgm.hh --- mln/io/load_pgm.hh (revision 1057) +++ mln/io/load_pgm.hh (working copy) @@ -137,11 +137,11 @@ point2d p = make::point2d(0, ima.domain().pmin().col()); typedef mln_value(I) V; const mln_coord(I) - min_row = ima.domain().pmin().row(), - max_row = ima.domain().pmax().row(); + min_row = geom::min_row(ima), + max_row = geom::max_row(ima); if (sizeof(V) = 1) { - size_t len = ima.ncols() * sizeof(mln_enc(V)); + size_t len = geom::ncols(ima) * sizeof(mln_enc(V)); for (p.row() = min_row; p.row() <= max_row; ++p.row()) file.read((char*)(& ima(p)), len); } @@ -149,8 +149,8 @@ { // FIXME: code for g++-2.95 when sizeof(int_u8) = 2!!! const mln_coord(I) - min_col = ima.domain().pmin().col(), - max_col = ima.domain().pmax().col(); + min_col = geom::min_col(ima), + max_col = geom::max_col(ima); for (p.row() = min_row; p.row() <= max_row; ++p.row()) for (p.col() = min_col; p.col() <= max_col; ++p.col()) { Index: mln/level/was.median.hh --- mln/level/was.median.hh (revision 1057) +++ mln/level/was.median.hh (working copy) @@ -55,8 +55,8 @@ mln_precondition(output.has_data()); int - min_row = input.min_row(), max_row = input.max_row(), - min_col = input.min_col(), max_col = input.max_col(); + min_row = geom::min_row(input), max_row = geom::max_row(input), + min_col = geom::min_col(input), max_col = geom::max_col(input); window2d win_fwd_plus = win - (win + left), @@ -76,7 +76,7 @@ // initialization - p = input.domain().pmin() + up; + p = input.bbox().pmin() + up; med.init(); { mln_qiter(W) q(win, p); @@ -137,9 +137,8 @@ { const int - max_row = input.max_row(), - min_col = input.min_col(), - max_col = input.max_col(); + min_row = geom::min_row(input), max_row = geom::max_row(input), + min_col = geom::min_col(input), max_col = geom::max_col(input); const unsigned half = win.length() / 2; point2d p; @@ -148,7 +147,7 @@ accu::median<mln_vset(I)> med(input.values()); - for (row = input.min_row(); row <= max_row; ++row) + for (row = min_row; row <= max_row; ++row) { int ct, cu; Index: mln/level/median.hh --- mln/level/median.hh (revision 1057) +++ mln/level/median.hh (working copy) @@ -34,6 +34,7 @@ */ # include <mln/core/concept/image.hh> +# include <mln/geom/size2d.hh> # include <mln/core/window2d.hh> # include <mln/core/win/hline2d.hh> @@ -162,9 +163,10 @@ { typedef mln_coord(I) coord; const coord - max_row = input.bbox().max_row(), - min_col = input.bbox().min_col(), - max_col = input.bbox().max_col(); + min_row = geom::min_row(input), + max_row = geom::max_row(input), + min_col = geom::min_col(input), + max_col = geom::max_col(input); const coord half = win.length() / 2; point2d p; @@ -179,7 +181,7 @@ accu::median<mln_vset(I)> med(input.values()); - for (row = input.bbox().min_row(); row <= max_row; ++row) + for (row = min_row; row <= max_row; ++row) { pt.row() = pu.row() = row; Index: mln/level/fast_median.hh --- mln/level/fast_median.hh (revision 1057) +++ mln/level/fast_median.hh (working copy) @@ -73,8 +73,8 @@ mln_precondition(output.has_data()); int - min_row = input.min_row(), max_row = input.max_row(), - min_col = input.min_col(), max_col = input.max_col(); + min_row = geom::min_row(input), max_row = geom::max_row(input), + min_col = geom::min_col(input), max_col = geom::max_col(input); window2d win_fwd_plus = win - (win + left), Index: mln/canvas/sbrowsing.hh --- mln/canvas/sbrowsing.hh (revision 1057) +++ mln/canvas/sbrowsing.hh (working copy) @@ -34,6 +34,7 @@ */ # include <mln/core/dpoint2d.hh> // for "up" +# include <mln/geom/size2d.hh> namespace mln @@ -69,11 +70,11 @@ { mln_precondition(f.input.has_data()); int - min_row = f.input.min_row(), max_row = f.input.max_row(), - min_col = f.input.min_col(), max_col = f.input.max_col(); + min_row = geom::min_row(f.input), max_row = geom::max_row(f.input), + min_col = geom::min_col(f.input), max_col = geom::max_col(f.input); // p - f.p = f.input.domain().pmin() + up; + f.p = f.input.bbox().pmin() + up; int& row = f.p.row(); int& col = f.p.col();
participants (1)
-
Thierry Geraud