https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add subset notion in milena.
Add materials.
* mln/convert/to_image.hh: New.
* mln/convert/to_window.hh: New.
* mln/estim: New.
* mln/estim/count.hh: New.
* mln/debug/format.hh: New.
* mln/geom: New.
* mln/geom/pmin_pmax.hh: New.
* mln/geom/bbox.hh: New.
* mln/core/psubset.hh: New.
* mln/core/psubset_piter.hh: New.
* mln/core/concept/function.hh: New.
* mln/core/internal/piter_adaptor.hh: New.
* mln/fun/chess.hh: New.
Add some tests.
* tests/safe_image.cc: New.
* tests/to_image.cc: New.
* tests/psubset.cc: New.
* tests/println.cc: New.
Several improvements.
* mln/debug/println.hh: Use debug::format.
* mln/core/box.hh (len): Move...
* mln/core/concept/box.hh: ...here.
* mln/core/point.hh (zero): Turn into var.
(point_): Bound ctor arg f.
* mln/core/dpoint.hh: Likewise.
* mln/core/neighb.hh (dpoint): New typedef.
* mln/core/concept/image.hh: Remove obsolete commentary.
* mln/core/concept/iterator.hh
(for_all_remaining): New macro.
* mln/core/concept/point_set.hh (operator<<): New.
* mln/core/concept/neighborhood.hh
(dpoint): Make it appear in commentary.
* mln/core/concept/doc/neighborhood.hh (dpoint): New.
* mln/core/concept/doc/box.hh: Cosmetics.
* mln/core/window.hh (b_): New attribute.
Update.
* mln/core/image2d_b.hh (bbox): Remove; redundant.
(at): New couple of methods.
Update.
* mln/core/internal/image_adaptor.hh: Fix.
* mln/core/internal/image_base.hh: Add preconditions.
* mln/core/internal/set_of.hh: Add a todo entry.
* mln/core/safe_image.hh: Help g++-2.95.
* mln/fun/all.hh: Add inheritance.
Change mk_<object> into make::<object>.
* mln/make: New directory.
* mln/core/dpoint2d.hh (mk_dpoint2d): Move to...
* mln/make/dpoint2d.hh: this new file.
(mk_dpoint2d): Rename as...
(dpoint2d): ...this.
* mln/core/window2d.hh (mk_window2d): Move to...
* mln/make/window2d.hh: this new file.
(mk_window2d): Rename as...
(window2d): ...this.
* mln/core/box2d.hh (mk_box2d): Move to...
* mln/make/box2d.hh: this new file.
(mk_box2d): Rename as...
(box2d): ...this.
* mln/core/point2d.hh (mk_point2d): Move to...
* mln/make/point2d.hh: this new file.
(mk_point2d): Rename as...
(point2d): ...this.
* tests/window2d.cc,
* tests/pixter_dpoint2d.cc,
* tests/box2d.cc,
* tests/point2d.cc,
* tests/dpoint2d.cc,
* tests/main.cc,
* mln/core/neighb2d.hh,
* mln/debug/println.hh,
* mln/core/rectangle2d.hh,
* mln/core/pixter2d_b.hh,
* mln/io/save_pgm.hh,
* mln/io/load_pgm.hh: Update.
mln/convert/to_image.hh | 109 +++++++++++++++++++
mln/convert/to_window.hh | 73 +++++++++++++
mln/core/box.hh | 13 --
mln/core/box2d.hh | 43 -------
mln/core/concept/box.hh | 19 ++-
mln/core/concept/doc/box.hh | 4
mln/core/concept/doc/neighborhood.hh | 3
mln/core/concept/function.hh | 135 ++++++++++++++++++++++++
mln/core/concept/image.hh | 2
mln/core/concept/iterator.hh | 8 +
mln/core/concept/neighborhood.hh | 3
mln/core/concept/point_set.hh | 27 ++++
mln/core/dpoint.hh | 15 +-
mln/core/dpoint2d.hh | 33 +----
mln/core/image2d_b.hh | 44 +++++--
mln/core/internal/image_adaptor.hh | 2
mln/core/internal/image_base.hh | 3
mln/core/internal/piter_adaptor.hh | 171 ++++++++++++++++++++++++++++++
mln/core/internal/set_of.hh | 2
mln/core/neighb.hh | 3
mln/core/neighb2d.hh | 16 +-
mln/core/pixter2d_b.hh | 4
mln/core/point.hh | 15 +-
mln/core/point2d.hh | 16 --
mln/core/psubset.hh | 194 +++++++++++++++++++++++++++++++++++
mln/core/psubset_piter.hh | 118 +++++++++++++++++++++
mln/core/rectangle2d.hh | 2
mln/core/safe_image.hh | 10 +
mln/core/window.hh | 10 +
mln/core/window2d.hh | 32 -----
mln/debug/format.hh | 92 ++++++++++++++++
mln/debug/println.hh | 20 ++-
mln/estim/count.hh | 86 +++++++++++++++
mln/fun/all.hh | 6 -
mln/fun/chess.hh | 71 ++++++++++++
mln/geom/bbox.hh | 113 ++++++++++++++++++++
mln/geom/pmin_pmax.hh | 90 ++++++++++++++++
mln/io/load_pgm.hh | 2
mln/io/save_pgm.hh | 2
mln/make/box2d.hh | 101 ++++++++++++++++++
mln/make/dpoint2d.hh | 72 ++++++++++++
mln/make/point2d.hh | 72 ++++++++++++
mln/make/window2d.hh | 82 ++++++++++++++
tests/box2d.cc | 2
tests/dpoint2d.cc | 6 -
tests/main.cc | 4
tests/pixter_dpoint2d.cc | 8 -
tests/point2d.cc | 2
tests/println.cc | 46 ++++++++
tests/psubset.cc | 45 ++++++++
tests/safe_image.cc | 47 ++++++++
tests/to_image.cc | 65 +++++++++++
tests/window2d.cc | 9 +
53 files changed, 1974 insertions(+), 198 deletions(-)
Index: tests/window2d.cc
--- tests/window2d.cc (revision 1009)
+++ tests/window2d.cc (working copy)
@@ -31,6 +31,9 @@
*/
#include <mln/core/window2d.hh>
+#include <mln/core/image2d_b.hh>
+#include <mln/convert/to_image.hh>
+#include <mln/debug/println.hh>
@@ -41,5 +44,9 @@
window2d w;
mln_assertion(w.is_centered() = false);
mln_assertion(w.is_symmetric() = true);
-}
+ w.insert(make::dpoint2d(-1,-1));
+ w.insert(make::dpoint2d( 1, 1));
+ image2d_b<bool> ima = convert::to_image(w);
+ debug::println(ima);
+}
Index: tests/pixter_dpoint2d.cc
--- tests/pixter_dpoint2d.cc (revision 1009)
+++ tests/pixter_dpoint2d.cc (working copy)
@@ -17,10 +17,10 @@
I::piter f(ima.domain());
window_<I::dpoint> set;
- set.insert(mk_dpoint2d(0, -1));
- set.insert(mk_dpoint2d(0, -1));
- set.insert(mk_dpoint2d(1, 0));
- set.insert(mk_dpoint2d(1, 0));
+ set.insert(make::dpoint2d(0, -1));
+ set.insert(make::dpoint2d(0, -1));
+ set.insert(make::dpoint2d(1, 0));
+ set.insert(make::dpoint2d(1, 0));
for_all(f)
{
Index: tests/box2d.cc
--- tests/box2d.cc (revision 1009)
+++ tests/box2d.cc (working copy)
@@ -38,5 +38,5 @@
{
using namespace mln;
- box2d b = mk_box2d(2, 3);
+ box2d b = make::box2d(2, 3);
}
Index: tests/point2d.cc
--- tests/point2d.cc (revision 1009)
+++ tests/point2d.cc (working copy)
@@ -50,7 +50,7 @@
mln_assertion(p.col() = 1 && p[1] = 1);
// construction
- q = mk_point2d(5, 1);
+ q = make::point2d(5, 1);
mln_assertion(p = q);
q.set_all(0);
Index: tests/safe_image.cc
--- tests/safe_image.cc (revision 0)
+++ tests/safe_image.cc (revision 0)
@@ -0,0 +1,47 @@
+// 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/safe_image.cc
+ *
+ * \brief Tests on mln::safe_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/safe_image.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ I ima(1, 1);
+ safe_image<I> ima_ = safe(ima);
+
+ point2d p = make::point2d(-5, -1);
+ ima_(p) = 0;
+}
Index: tests/dpoint2d.cc
--- tests/dpoint2d.cc (revision 1009)
+++ tests/dpoint2d.cc (working copy)
@@ -41,9 +41,9 @@
point2d p, q;
dpoint2d dp;
- p = mk_point2d(1, 2);
- q = mk_point2d(4, 7);
- dp = mk_dpoint2d(3, 5);
+ p = make::point2d(1, 2);
+ q = make::point2d(4, 7);
+ dp = make::dpoint2d(3, 5);
mln_assertion(dp = q - p);
mln_assertion(q = p + dp);
Index: tests/to_image.cc
--- tests/to_image.cc (revision 0)
+++ tests/to_image.cc (revision 0)
@@ -0,0 +1,65 @@
+// 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/to_image.cc
+ *
+ * \brief Tests on mln::convert::to_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/window2d.hh>
+#include <mln/core/psubset.hh>
+#include <mln/fun/chess.hh>
+#include <mln/level/compare.hh>
+
+#include <mln/convert/to_image.hh>
+
+
+#include <mln/debug/println.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d box_3x3 = make::box2d(-1,+1, -1,+1);
+ // ^^^^^ ^^^^^
+ // rows cols
+
+ // center point
+ // V
+ bool X[] = { 1, 0, 1,
+ 0, 1, 0, // < center point
+ 1, 0, 1 };
+
+ image2d_b<bool> ima_X = convert::to_image(box_3x3 | fun::chess);
+ window2d win_X = make::window2d(X);
+ mln_assertion(convert::to_image(win_X) = ima_X);
+
+ // FIXME: nbh!
+}
Index: tests/main.cc
--- tests/main.cc (revision 1009)
+++ tests/main.cc (working copy)
@@ -60,7 +60,7 @@
-// box2d b = mk_box2d(/* row = */ 1, 3,
+// box2d b = make::box2d(/* row = */ 1, 3,
// /* col = */ 4, 6);
// std::cout << b << std::endl;
@@ -68,7 +68,7 @@
// { 0, 1, 0,
// 0, 1, 0,
// 1, 0, 0 };
-// window2d win = mk_window2d(w);
+// window2d win = make::window2d(w);
// std::cout << win << std::endl;
// std::cout << c8() << std::endl;
Index: tests/psubset.cc
--- tests/psubset.cc (revision 0)
+++ tests/psubset.cc (revision 0)
@@ -0,0 +1,45 @@
+// 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/psubset.cc
+ *
+ * \brief Tests on mln::psubset.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/psubset.hh>
+#include <mln/fun/chess.hh>
+#include <mln/convert/to_image.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d box_8x8 = make::box2d(8, 8);
+ mln_assertion((box_8x8 | fun::chess).npoints() = 32);
+}
Index: tests/println.cc
--- tests/println.cc (revision 0)
+++ tests/println.cc (revision 0)
@@ -0,0 +1,46 @@
+// 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/println.cc
+ *
+ * \brief Test on mln::debug::println.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/level/fill.hh>
+#include <mln/debug/println.hh>
+
+
+using namespace mln;
+
+
+int main()
+{
+ image2d_b<bool> msk(3, 3);
+ msk.at(1, 1) = true;
+ debug::println(msk);
+}
Index: mln/convert/to_image.hh
--- mln/convert/to_image.hh (revision 0)
+++ mln/convert/to_image.hh (revision 0)
@@ -0,0 +1,109 @@
+// 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_CONVERT_TO_IMAGE_HH
+# define MLN_CONVERT_TO_IMAGE_HH
+
+/*! \file mln/convert/to_image.hh
+ *
+ * \brief Convertions to mln::Image.
+ */
+
+# include <mln/core/image2d_b.hh>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/window.hh>
+# include <mln/core/concept/neighborhood.hh>
+
+# include <mln/convert/to_window.hh>
+# include <mln/geom/bbox.hh>
+# include <mln/level/fill.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert a point set \p pset into a binary image.
+ template <typename S>
+ image2d_b<bool> to_image(const Point_Set<S>& pset);
+
+ /// Convert a window \p win into a binary image.
+ template <typename W>
+ image2d_b<bool> to_image(const Window<W>& win);
+
+ /// Convert a neighborhood \p nbh into a binary image.
+ template <typename N>
+ image2d_b<bool> to_image(const Neighborhood<N>& nbh);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S>
+ image2d_b<bool> to_image(const Point_Set<S>& pset_)
+ {
+ const S& pset = exact(pset_);
+ image2d_b<bool> ima(pset.bbox());
+ level::fill(ima, false);
+ mln_piter(S) p(pset);
+ for_all(p)
+ ima(p) = true;
+ return ima;
+ }
+
+ template <typename W>
+ image2d_b<bool> to_image(const Window<W>& win_)
+ {
+ const W& win = exact(win_);
+ mln_precondition(! win.is_empty());
+
+ typedef mln_point(W) P;
+ box2d b = geom::bbox(win);
+ image2d_b<bool> ima(b);
+ level::fill(ima, false);
+ mln_qiter(W) q(win, P::zero);
+ for_all(q)
+ ima(q) = true;
+ return ima;
+ }
+
+ template <typename N>
+ image2d_b<bool> to_image(const Neighborhood<N>& nbh)
+ {
+ return to_image(convert::to_window(nbh));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_IMAGE_HH
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 0)
+++ mln/convert/to_window.hh (revision 0)
@@ -0,0 +1,73 @@
+// 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_CONVERT_TO_WINDOW_HH
+# define MLN_CONVERT_TO_WINDOW_HH
+
+/*! \file mln/convert/to_window.hh
+ *
+ * \brief Convertions to mln::Image.
+ */
+
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/window.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert a neighborhood \p nbh into a window.
+ template <typename N>
+ window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename N>
+ window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
+ {
+ const N& nbh = exact(nbh_);
+ typedef mln_dpoint(N) D;
+ typedef mln_point(D) P;
+ window_<D> win;
+ mln_niter(N) n(nbh, P::zero);
+ for_all(n)
+ win.insert(n - P::zero);
+ return win;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_WINDOW_HH
Index: mln/estim/count.hh
--- mln/estim/count.hh (revision 0)
+++ mln/estim/count.hh (revision 0)
@@ -0,0 +1,86 @@
+// 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_ESTIM_COUNT_HH
+# define MLN_ESTIM_COUNT_HH
+
+/*! \file mln/estim/count.hh
+ *
+ * \brief Several routines to count the number of points.
+ */
+
+
+namespace mln
+{
+
+ namespace estim
+ {
+
+
+ /// Compute the number FIXME minimum and maximum points when browsing with
+ /// iterator \p p.
+ template <typename S>
+ std::size_t count(const Point_Set<S>& pset);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ std::pair<mln_point(I), mln_point(I)>
+ count(const Piter<I>& p_)
+ {
+ const I& p = exact(p_);
+
+ typedef mln_point(I) P;
+ std::pair<P, P> tmp;
+ P& pmin = tmp.first;
+ P& pmax = tmp.second;
+
+ // init with first point
+ p.start();
+ pmin = pmax = p;
+
+ // update with remaining points
+ for_all_remaining(p)
+ for (unsigned i = 0; i < P::dim; ++i)
+ if (p[i] < pmin[i])
+ pmin()[i] = p[i];
+ else if (p[i] > pmax[i])
+ pmax[i] = p[i];
+
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::estim
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ESTIM_COUNT_HH
Index: mln/debug/println.hh
--- mln/debug/println.hh (revision 1009)
+++ mln/debug/println.hh (working copy)
@@ -35,6 +35,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/window.hh>
+# include <mln/debug/format.hh>
+
# include <mln/core/box2d.hh>
@@ -54,24 +56,30 @@
namespace impl
{
+ // generic version
template <typename S, typename I>
void println(const S&, const Image<I>& input_)
{
const I& input = exact(input_);
mln_piter(I) p(input.domain());
for_all(p)
- std::cout << input(p) << ' ';
+ std::cout << format( input(p) ) << ' ';
std::cout << std::endl;
}
+ // "domain = box2d" version
template <typename I>
- void println(const box2d& b,
- const I& input)
+ void println(const box2d& b, const I& input)
{
- for (int row = b.pmin().row(); row <= b.pmax().row(); ++row)
+ 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 (int col = b.pmin().col(); col <= b.pmax().col(); ++col)
- std::cout << input(mk_point2d(row, col)) << ' ';
+ for (col = b.min_col(); col <= max_col; ++col)
+ std::cout << format( input(p) ) << ' ';
std::cout << std::endl;
}
std::cout << std::endl;
Index: mln/debug/format.hh
--- mln/debug/format.hh (revision 0)
+++ mln/debug/format.hh (revision 0)
@@ -0,0 +1,92 @@
+// 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_FORMAT_HH
+# define MLN_DEBUG_FORMAT_HH
+
+/*! \file mln/debug/format.hh
+ *
+ * \brief Routines that format a value to print it properly.
+ */
+
+
+namespace mln
+{
+
+ namespace debug
+ {
+
+ /// Default version for formatting a value is a no-op.
+ template <typename T>
+ const T& format(const T& v);
+
+ /// Format a Boolean to print it nicely: "|" for true and "-"
for
+ /// false.
+ char format(bool v);
+
+ /// Format a signed char to print it properly, i.e., like an
+ /// integer value.
+ signed short format(signed char v);
+
+ /// Format an unsigned char to print it properly, i.e., like an
+ /// integer value.
+ unsigned short format(unsigned char v);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ const T& format(const T& v)
+ {
+ return v;
+ }
+
+ char format(bool v)
+ {
+ return v ? '|' : '-';
+ }
+
+ signed short format(signed char v)
+ {
+ return v;
+ }
+
+ unsigned short format(unsigned char v)
+ {
+ return v;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::debug
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DEBUG_FORMAT_HH
Index: mln/geom/pmin_pmax.hh
--- mln/geom/pmin_pmax.hh (revision 0)
+++ mln/geom/pmin_pmax.hh (revision 0)
@@ -0,0 +1,90 @@
+// 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_PMIN_PMAX_HH
+# define MLN_GEOM_PMIN_PMAX_HH
+
+/*! \file mln/geom/pmin_pmax.hh
+ *
+ * \brief Several routines to compute the minimum point and/or maximum
+ * point.
+ */
+
+# include <utility>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+
+ /// Compute the minimum and maximum points when browsing with
+ /// iterator \p p.
+ template <typename I>
+ std::pair<mln_point(I), mln_point(I)>
+ pmin_pmax(const Piter<I>& p);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ std::pair<mln_point(I), mln_point(I)>
+ pmin_pmax(Piter<I>& p_)
+ {
+ I& p = exact(p_);
+
+ typedef mln_point(I) P;
+ std::pair<P, P> tmp;
+ P& pmin = tmp.first;
+ P& pmax = tmp.second;
+
+ // init with first point
+ p.start();
+ pmin = pmax = p;
+
+ // update with remaining points
+ for_all_remaining(p)
+ for (unsigned i = 0; i < P::dim; ++i)
+ if (p[i] < pmin[i])
+ pmin[i] = p[i];
+ else if (p[i] > pmax[i])
+ pmax[i] = p[i];
+
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_PMIN_PMAX_HH
Index: mln/geom/bbox.hh
--- mln/geom/bbox.hh (revision 0)
+++ mln/geom/bbox.hh (revision 0)
@@ -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_GEOM_BBOX_HH
+# define MLN_GEOM_BBOX_HH
+
+/*! \file mln/geom/bbox.hh
+ *
+ * \brief Several routines to compute the precise bounding box of some
+ * objects.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/window.hh>
+# include <mln/geom/pmin_pmax.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+
+ /// Compute the precise bounding box of a window \p win centered
+ /// at the origin.
+ template <typename W>
+ box_<mln_point(W)> bbox(const Window<W>& win);
+
+
+ /// Compute the precise bounding box of a point set \p pset.
+ template <typename S>
+ box_<mln_point(S)> bbox(const Point_Set<S>& pset);
+
+
+ /// Compute the precise bounding box of an image \p ima.
+ template <typename I>
+ box_<mln_point(I)> bbox(const Image<I>& ima);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename W>
+ box_<mln_point(W)> bbox(const Window<W>& win_)
+ {
+ const W& win = exact(win_);
+ mln_precondition(! win.is_empty());
+
+ typedef mln_point(W) P;
+ mln_qiter(W) q(win, P::zero);
+ std::pair<P, P> pp = geom::pmin_pmax(q);
+
+ box_<P> tmp(pp.first, pp.second);
+ return tmp;
+ }
+
+ template <typename S>
+ box_<mln_point(S)> bbox(const Point_Set<S>& pset_)
+ {
+ const S& pset = exact(pset_);
+ mln_precondition(pset.npoints() != 0);
+
+ typedef mln_point(S) P;
+ mln_piter(S) p(pset);
+ std::pair<P, P> pp = geom::pmin_pmax(p);
+
+ box_<P> tmp(pp.first, pp.second);
+ // FIXME: mln_postcondition(tmp <= pset.bbox());
+ return tmp;
+ }
+
+ template <typename I>
+ box_<mln_point(I)> bbox(const Image<I>& ima_)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+ return bbox(ima.domain());
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_BBOX_HH
Index: mln/core/neighb2d.hh
--- mln/core/neighb2d.hh (revision 1009)
+++ mln/core/neighb2d.hh (working copy)
@@ -101,8 +101,8 @@
static neighb2d it;
if (flower)
{
- it.insert(mk_dpoint2d(0, 1));
- it.insert(mk_dpoint2d(1, 0));
+ it.insert(make::dpoint2d(0, 1));
+ it.insert(make::dpoint2d(1, 0));
flower = false;
}
return it;
@@ -114,10 +114,10 @@
static neighb2d it;
if (flower)
{
- it.insert(mk_dpoint2d(0, 1));
- it.insert(mk_dpoint2d(1,-1));
- it.insert(mk_dpoint2d(1, 0));
- it.insert(mk_dpoint2d(1, 1));
+ it.insert(make::dpoint2d(0, 1));
+ it.insert(make::dpoint2d(1,-1));
+ it.insert(make::dpoint2d(1, 0));
+ it.insert(make::dpoint2d(1, 1));
flower = false;
}
return it;
@@ -129,7 +129,7 @@
static neighb2d it;
if (flower)
{
- it.insert(mk_dpoint2d(0, 1));
+ it.insert(make::dpoint2d(0, 1));
flower = false;
}
return it;
@@ -141,7 +141,7 @@
static neighb2d it;
if (flower)
{
- it.insert(mk_dpoint2d(1, 0));
+ it.insert(make::dpoint2d(1, 0));
flower = false;
}
return it;
Index: mln/core/dpoint2d.hh
--- mln/core/dpoint2d.hh (revision 1009)
+++ mln/core/dpoint2d.hh (working copy)
@@ -46,38 +46,23 @@
typedef dpoint_<2,int> dpoint2d;
- /*! \brief Create an mln::dpoint2d.
- *
- * \param[in] row Index of row.
- * \param[in] col Index of column.
- *
- * \return A 2D delta-point.
- */
- dpoint2d mk_dpoint2d(int row, int col);
-
+} // end of namespace mln
- const dpoint2d up = mk_dpoint2d( -1, 0 );
- const dpoint2d down = mk_dpoint2d( +1, 0 );
- const dpoint2d left = mk_dpoint2d( 0, -1 );
- const dpoint2d right = mk_dpoint2d( 0, +1 );
+# include <mln/make/dpoint2d.hh>
+# include <mln/core/point2d.hh>
-# ifndef MLN_INCLUDE_ONLY
- dpoint2d mk_dpoint2d(int row, int col)
+namespace mln
{
- dpoint2d tmp;
- tmp[0] = row;
- tmp[1] = col;
- return tmp;
- }
-# endif // ! MLN_INCLUDE_ONLY
+ // FIXME: Doc!
+ const dpoint2d up = make::dpoint2d( -1, 0 );
+ const dpoint2d down = make::dpoint2d( +1, 0 );
+ const dpoint2d left = make::dpoint2d( 0, -1 );
+ const dpoint2d right = make::dpoint2d( 0, +1 );
} // end of namespace mln
-# include <mln/core/point2d.hh>
-
-
#endif // ! MLN_CORE_DPOINT2D_HH
Index: mln/core/psubset.hh
--- mln/core/psubset.hh (revision 0)
+++ mln/core/psubset.hh (revision 0)
@@ -0,0 +1,194 @@
+// 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_CORE_PSUBSET_HH
+# define MLN_CORE_PSUBSET_HH
+
+/*! \file mln/core/psubset.hh
+ *
+ * \brief This file defines a generic class for subset of point set.
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename S, typename F> struct psubset;
+ template <typename S, typename F> struct psubset_fwd_piter_;
+ template <typename S, typename F> struct psubset_bkd_piter_;
+
+
+
+ /*! \brief Restrict a point set \p pset to points that verify \p f.
+ *
+ * \param[in] pset A point set.
+ * \param[in] f A function from point to Boolean.
+ * \return A subset of points.
+ */
+ template <typename S, typename F>
+ psubset<S, F>
+ operator | (const Point_Set<S>& pset, const Function_p2b<F>& f);
+
+
+
+ /*! \brief Generic subset class.
+ *
+ * Parameter \c S is a point set type; parameter F is a function
+ * from point to Boolean.
+ */
+ template <typename S, typename F>
+ struct psubset : public Point_Set< psubset<S,F> >
+ {
+ /// Psite associated type.
+ typedef mln_psite(S) psite;
+
+ /// Point associated type.
+ typedef mln_point(S) point;
+
+
+ /// Forward Piter associated type.
+ typedef psubset_fwd_piter_<S,F> fwd_piter;
+
+ /// Backward Piter associated type.
+ typedef psubset_fwd_piter_<S,F> bkd_piter; // FIXME: bkd!!!
+
+ /// Piter associated type.
+ typedef fwd_piter piter;
+
+
+ /// Constructor without argument.
+ psubset(const S& pset, const F& f);
+
+
+ /// Test if \p p belongs to the subset.
+ bool has(const psite& p) const;
+
+ /// Give a bounding box of the subset.
+ const box_<point>& bbox() const;
+
+ /// Give the number of points of the subset.
+ std::size_t npoints() const;
+
+ /// Give the primary overset.
+ const S& overset() const;
+
+ /// Test predicate on point site \p p.
+ bool pred(const psite& p) const;
+
+ protected:
+
+ const S& pset_;
+ F f_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename S, typename F>
+ psubset<S, F>
+ operator | (const Point_Set<S>& pset, const Function_p2b<F>& f)
+ {
+ psubset<S, F> tmp(exact(pset), exact(f));
+ return tmp;
+ }
+
+
+ // psubset<S,F>
+
+ template <typename S, typename F>
+ bool
+ psubset<S,F>::has(const psite& p) const
+ {
+ return pset_.has(p) && f_(p);
+ }
+
+ template <typename S, typename F>
+ const box_<mln_point(S)>&
+ psubset<S,F>::bbox() const
+ {
+ return pset_.bbox();
+ }
+
+ template <typename S, typename F>
+ const S&
+ psubset<S,F>::overset() const
+ {
+ return pset_;
+ }
+
+ template <typename S, typename F>
+ bool
+ psubset<S,F>::pred(const psite& p) const
+ {
+ return f_(p);
+ }
+
+ template <typename S, typename F>
+ psubset<S,F>::psubset(const S& pset, const F& f)
+ : pset_(pset),
+ f_(f)
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+# include <mln/core/psubset_piter.hh>
+
+
+
+namespace mln
+{
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ std::size_t
+ psubset<S,F>::npoints() const
+ {
+ std::size_t n = 0;
+ piter p(*this);
+ for_all(p)
+ ++n;
+ return n;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSUBSET_HH
Index: mln/core/psubset_piter.hh
--- mln/core/psubset_piter.hh (revision 0)
+++ mln/core/psubset_piter.hh (revision 0)
@@ -0,0 +1,118 @@
+// 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_CORE_PSUBSET_PITER_HH
+# define MLN_CORE_PSUBSET_PITER_HH
+
+/*! \file mln/core/psubset_piter.hh
+ *
+ * \brief Definition of iterators on points of psubsetes.
+ */
+
+# include <mln/core/concept/piter.hh>
+# include <mln/core/internal/piter_adaptor.hh>
+# include <mln/core/psubset.hh>
+
+
+namespace mln
+{
+
+ /*! \brief A generic forward iterator on points of subsets.
+ *
+ * Parameter \c S is a point set type; parameter F is a function
+ * from point to Boolean.
+ *
+ * \see mln::psubset
+ */
+ template <typename S, typename F>
+ class psubset_fwd_piter_ : public internal::piter_adaptor_< mln_fwd_piter(S),
+ psubset_fwd_piter_<S,F> >
+ {
+ typedef mln_fwd_piter(S) adaptee_;
+ typedef psubset_fwd_piter_<S,F> self_;
+ typedef internal::piter_adaptor_<adaptee_, self_> super_;
+
+ public:
+
+ /// Constructor from a subset of points.
+ psubset_fwd_piter_(const psubset<S,F>& subset);
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ private:
+
+ const psubset<S,F>& subset_;
+ };
+
+ // FIXME: psubset_bkd_piter_<S,F>
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // psubset_fwd_piter_<S,F>
+
+ template <typename S, typename F>
+ psubset_fwd_piter_<S,F>::psubset_fwd_piter_(const psubset<S,F>&
subset)
+ : super_(adaptee_(subset.overset())),
+ subset_(subset)
+ {
+ }
+
+ template <typename S, typename F>
+ void
+ psubset_fwd_piter_<S,F>::start()
+ {
+ this->piter_.start();
+ while (this->piter_.is_valid() && ! subset_.pred(this->piter_))
+ this->piter_.next();
+ }
+
+ template <typename S, typename F>
+ void
+ psubset_fwd_piter_<S,F>::next_()
+ {
+ do
+ this->piter_.next();
+ while (this->piter_.is_valid() && ! subset_.pred(this->piter_));
+ }
+
+
+ // FIXME: psubset_bkd_piter_<S,F>
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSUBSET_PITER_HH
Index: mln/core/box.hh
--- mln/core/box.hh (revision 1009)
+++ mln/core/box.hh (working copy)
@@ -90,11 +90,6 @@
*/
P& pmax();
- /*! \brief Give the length of the \p i-th side.
- * \pre i < dim
- */
- unsigned len(unsigned i) const;
-
/*! \brief Constructor without argument.
*/
box_();
@@ -158,14 +153,6 @@
}
template <typename P>
- unsigned
- box_<P>::len(unsigned i) const
- {
- mln_precondition(i < P::dim);
- return 1 + pmax_[i] - pmin_[i];
- }
-
- template <typename P>
box_<P>::box_()
{
}
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1009)
+++ mln/core/point.hh (working copy)
@@ -87,14 +87,14 @@
/*! \brief Constructor; coordinates are set by function \p f.
*/
template <typename F>
- point_(F f);
+ point_(const Function<F>& f);
/*! \brief Set all coordinates to the value \p c.
*/
void set_all(C c);
- /// Give the origin (all coordinates are 0).
- static const point_<n,C>& zero();
+ /// Origin point (all coordinates are 0).
+ static const point_<n,C> zero;
protected:
C coord_[n];
@@ -124,8 +124,9 @@
template <unsigned n, typename C>
template <typename F>
- point_<n,C>::point_(F f)
+ point_<n,C>::point_(const Function<F>& f_)
{
+ const F& f = exact(f_);
for (unsigned i = 0; i < n; ++i)
coord_[i] = f(i);
}
@@ -138,11 +139,7 @@
}
template <unsigned n, typename C>
- const point_<n,C>& point_<n,C>::zero()
- {
- static const point_<n,C> zero_(all(0));
- return zero_;
- }
+ const point_<n,C> point_<n,C>::zero = all(0);
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/rectangle2d.hh
--- mln/core/rectangle2d.hh (revision 1009)
+++ mln/core/rectangle2d.hh (working copy)
@@ -139,7 +139,7 @@
const int drow = half_height, dcol = half_width;
for (int row = - drow; row <= drow; ++row)
for (int col = - dcol; col <= dcol; ++col)
- insert(mk_dpoint2d(row, col));
+ insert(make::dpoint2d(row, col));
}
bool rectangle2d::is_centered() const
Index: mln/core/neighb.hh
--- mln/core/neighb.hh (revision 1009)
+++ mln/core/neighb.hh (working copy)
@@ -55,6 +55,9 @@
struct neighb_ : public Neighborhood< neighb_<D> >,
public internal::set_of_<D>
{
+ /// Dpoint associated type.
+ typedef D dpoint;
+
/*! \brief Piter type to browse the points of a generic
* neighborhood w.r.t. the ordering of delta-points.
*/
Index: mln/core/concept/image.hh
--- mln/core/concept/image.hh (revision 1009)
+++ mln/core/concept/image.hh (working copy)
@@ -55,7 +55,7 @@
bool has_data() const;
- bool owns_(const psite& p) const; // default is like "has(p)"
+ bool owns_(const psite& p) const;
const pset& domain() const;
rvalue operator()(const psite& p) const;
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 0)
+++ mln/core/concept/function.hh (revision 0)
@@ -0,0 +1,135 @@
+// 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_CORE_CONCEPT_FUNCTION_HH
+# define MLN_CORE_CONCEPT_FUNCTION_HH
+
+/*! \file mln/core/concept/function.hh
+ *
+ * \brief Definition of several concepts of functions.
+ */
+
+# include <mln/core/concept/object.hh>
+
+
+namespace mln
+{
+
+
+ /*! \brief Base class for implementation of function-objects.
+ *
+ * The parameter \a E is the exact type.
+ */
+ template <typename E>
+ struct Function : public Object<E>
+ {
+ /*
+ An operator() has to be provided. Its signature depends
+ on the particular function-object one considers.
+ */
+ protected:
+ Function();
+ };
+
+
+ // Value -> Value.
+
+ /// Base class for implementation of function-objects from value to
+ /// value.
+ template <typename E>
+ struct Function_v2v : public Function<E>
+ {
+ protected:
+ Function_v2v();
+ };
+
+
+ // Point -> Value.
+
+ /// Base class for implementation of function-objects from point to
+ /// value.
+ template <typename E>
+ struct Function_p2v : public Function_v2v<E>
+ {
+ protected:
+ Function_p2v();
+ };
+
+
+ // Point -> bool.
+
+ /// Base class for implementation of function-objects from point to
+ /// bool.
+ template <typename E>
+ struct Function_p2b : public Function_p2v<E>
+ {
+ protected:
+ Function_p2b();
+ };
+
+
+ // Point -> Point.
+
+ /// Base class for implementation of function-objects from point to
+ /// point.
+ template <typename E>
+ struct Function_p2p : public Function_p2v<E>
+ {
+ protected:
+ Function_p2p();
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Function<E>::Function()
+ {
+ }
+
+ template <typename E>
+ Function_v2v<E>::Function_v2v()
+ {
+ }
+
+ template <typename E>
+ Function_p2v<E>::Function_p2v()
+ {
+ }
+
+ template <typename E>
+ Function_p2b<E>::Function_p2b()
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_FUNCTION_HH
Index: mln/core/concept/box.hh
--- mln/core/concept/box.hh (revision 1009)
+++ mln/core/concept/box.hh (working copy)
@@ -52,10 +52,17 @@
/*
const point& pmin() const;
const point& pmax() const;
- unsigned len(unsigned i) const; // FIXME: Doc!
*/
- /*! \brief Return the bounding box of this point set.
+ /*! \brief Give the length of the \p i-th side of the box.
+ *
+ * \pre i < point::dim
+ *
+ * \warning This method is final for all box classes.
+ */
+ unsigned len(unsigned i) const;
+
+ /*! \brief Give the bounding box of this point set.
*
* Return the bounding box of this point set, so that is itself.
* This method is declared by the mln::Point_Set concept.
@@ -64,7 +71,7 @@
*/
const E& bbox() const;
- /*! \brief Return the number of points of this box.
+ /*! \brief Give the number of points of this box.
*
* Return the number of points of this box. This method is
* declared by the mln::Point_Set concept.
@@ -87,6 +94,12 @@
}
template <typename E>
+ unsigned Box<E>::len(unsigned i) const
+ {
+ return 1 + exact(this)->pmax()[i] - exact(this)->pmin()[i];
+ }
+
+ template <typename E>
Box<E>::Box()
{
typedef mln_point(E) point;
Index: mln/core/concept/iterator.hh
--- mln/core/concept/iterator.hh (revision 1009)
+++ mln/core/concept/iterator.hh (working copy)
@@ -40,6 +40,14 @@
# define for_all(x) for(x.start(); x.is_valid(); x.next())
+/*! \brief Loop to browse all the remaining elements targetted by the
+ * iterator \p x.
+ */
+# define for_all_remaining(x) \
+ if (! x.is_valid()) {} else while (x.next(), x.is_valid())
+
+
+
namespace mln
{
/*! \brief Base class for implementation classes that are iterators.
Index: mln/core/concept/point_set.hh
--- mln/core/concept/point_set.hh (revision 1009)
+++ mln/core/concept/point_set.hh (working copy)
@@ -64,6 +64,20 @@
};
+ /*! \brief Print a point set \p pset into the output stream \p
+ * ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] pset A point set.
+ *
+ * \return The modified output stream \p ostr.
+ *
+ * \relates mln::Point_Set
+ */
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const
Point_Set<S>& pset);
+
+
# ifndef MLN_INCLUDE_ONLY
// fwd decl
@@ -74,6 +88,7 @@
{
typedef mln_point(E) point;
typedef mln_psite(E) psite;
+
typedef mln_piter(E) piter;
typedef mln_fwd_piter(E) fwd_piter;
typedef mln_bkd_piter(E) bkd_piter;
@@ -86,6 +101,18 @@
m3 = 0;
}
+
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const
Point_Set<S>& pset_)
+ {
+ const S& pset = exact(pset_);
+ ostr << '{';
+ mln_piter(S) p(pset);
+ for_all(p)
+ ostr << p;
+ return ostr << '}';
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/concept/neighborhood.hh
--- mln/core/concept/neighborhood.hh (revision 1009)
+++ mln/core/concept/neighborhood.hh (working copy)
@@ -50,6 +50,8 @@
typedef niter;
typedef fwd_niter;
typedef bkd_niter;
+
+ typedef dpoint;
*/
protected:
@@ -65,6 +67,7 @@
typedef mln_niter(E) niter;
typedef mln_fwd_niter(E) fwd_niter;
typedef mln_bkd_niter(E) bkd_niter;
+ typedef mln_dpoint(E) dpoint;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/doc/neighborhood.hh
--- mln/core/concept/doc/neighborhood.hh (revision 1009)
+++ mln/core/concept/doc/neighborhood.hh (working copy)
@@ -56,6 +56,9 @@
* neighbors in a backward way.
*/
typedef void bkd_niter;
+
+ /// Dpoint associated type.
+ typedef void dpoint;
};
} // end of namespace mln::doc
Index: mln/core/concept/doc/box.hh
--- mln/core/concept/doc/box.hh (revision 1009)
+++ mln/core/concept/doc/box.hh (working copy)
@@ -41,7 +41,7 @@
template <typename E>
struct Box : public Point_Set<E>
{
- /*! \brief Return the box "minimum" point.
+ /*! \brief Give the box "minimum" point.
*
* Return the "minimum" point w.r.t. the ordering between points.
* For instance, with mln::box2d, this minimum is the top left
@@ -49,7 +49,7 @@
*/
const point& pmin() const;
- /*! \brief Return the box "maximum" point.
+ /*! \brief Give the box "maximum" point.
*
* Return the "maximum" point w.r.t. the ordering between points.
* For instance, with mln::box2d, this maximum is the bottom
Index: mln/core/window2d.hh
--- mln/core/window2d.hh (revision 1009)
+++ mln/core/window2d.hh (working copy)
@@ -34,7 +34,6 @@
* routine.
*/
-# include <cmath>
# include <mln/core/window.hh>
# include <mln/core/dpoint2d.hh>
@@ -48,37 +47,10 @@
typedef window_<dpoint2d> window2d;
- /*! \brief Create an mln::window2d.
- *
- * \param[in] values Array of Booleans.
- *
- * \pre The array size, \c M, has to be a square of an odd integer.
- *
- * \return A 2D window.
- */
- template <unsigned M>
- window2d mk_window2d(const bool (&values)[M]);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <unsigned M>
- window2d mk_window2d(const bool (&values)[M])
- {
- int h = unsigned(std::sqrt(float(M))) / 2;
- assert((2 * h + 1) * (2 * h + 1) = M);
- window2d tmp;
- unsigned i = 0;
- for (int row = - h; row <= h; ++row)
- for (int col = - h; col <= h; ++col)
- if (values[i++])
- tmp.insert(mk_dpoint2d(row, col));
- return tmp;
- }
+} // end of namespace mln
-# endif // ! MLN_INCLUDE_ONLY
-} // end of namespace mln
+# include <mln/make/window2d.hh>
#endif // ! MLN_CORE_WINDOW2D_HH
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 1009)
+++ mln/core/dpoint.hh (working copy)
@@ -87,14 +87,14 @@
/*! \brief Constructor; coordinates are set by function \p f.
*/
template <typename F>
- dpoint_(F f); // FIXME: Bound parameter!
+ dpoint_(const Function<F>& f);
/*! \brief Set all coordinates to the value \p c.
*/
void set_all(C c);
- /// Give the null delta-point (all coordinates are 0).
- static const dpoint_<n,C>& zero();
+ /// Null delta-point (all coordinates are 0).
+ static const dpoint_<n,C> zero;
protected:
C coord_[n];
@@ -124,8 +124,9 @@
template <unsigned n, typename C>
template <typename F>
- dpoint_<n,C>::dpoint_(F f)
+ dpoint_<n,C>::dpoint_(const Function<F>& f_)
{
+ const F& f = exact(f_);
for (unsigned i = 0; i < n; ++i)
coord_[i] = f(i);
}
@@ -138,11 +139,7 @@
}
template <unsigned n, typename C>
- const dpoint_<n,C>& dpoint_<n,C>::zero()
- {
- static const dpoint_<n,C> zero_(all(0));
- return zero_;
- }
+ const dpoint_<n,C> dpoint_<n,C>::zero = all(0);
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/pixter2d_b.hh
--- mln/core/pixter2d_b.hh (revision 1009)
+++ mln/core/pixter2d_b.hh (working copy)
@@ -79,7 +79,7 @@
+ 2 * border_size_ + 1)
{
this->start_ = &ima(ima.domain().pmin());
- this->eor_ = &ima(mk_point2d(ima.domain().pmin()[0], ima.domain().pmax()[1]))
+ 1;
+ this->eor_ = &ima(make::point2d(ima.domain().pmin()[0],
ima.domain().pmax()[1])) + 1;
this->eoi_ = &ima(ima.domain().pmax()) + 1;
}
@@ -88,7 +88,7 @@
{
++(this->current_);
- if (this->current_ = this->eor_ and this->current_ != this->eoi_)
+ if (this->current_ = this->eor_ && this->current_ != this->eoi_)
{
this->current_ += 2 * this->border_size_;
this->eor_ += this->row_offset_;
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1009)
+++ mln/core/window.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/core/concept/genpoint.hh>
# include <mln/core/internal/set_of.hh>
# include <mln/core/dpoint.hh>
+# include <mln/core/box.hh>
# include <mln/convert/to_dpoint.hh>
# include <mln/fun/all.hh>
@@ -79,6 +80,7 @@
*/
typedef fwd_qiter qiter;
+
/*! \brief Constructor without argument.
*
* The constructed window is empty.
@@ -99,6 +101,10 @@
/// Give the symmetrical window.
window_<D> sym_() const;
+
+ protected:
+
+ box_<point> b_;
};
@@ -159,7 +165,7 @@
{
typedef mln_point(W) P;
window_<mln_dpoint(W)> tmp;
- mln_qiter(W) q(win, P::zero());
+ mln_qiter(W) q(win, P::zero);
for_all(q)
tmp.insert(convert::to_dpoint(q) + dp);
return tmp;
@@ -178,7 +184,7 @@
{
typedef mln_point(W) P;
window_<mln_dpoint(W)> tmp;
- mln_qiter(W) q(lhs, P::zero());
+ mln_qiter(W) q(lhs, P::zero);
for_all(q)
{
mln_dpoint(W) dp = convert::to_dpoint(q);
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1009)
+++ mln/core/image2d_b.hh (working copy)
@@ -112,6 +112,9 @@
/// Assignment operator.
image2d_b& operator=(const image2d_b<T>& rhs);
+ /// Destructor.
+ ~image2d_b();
+
/// Initialize an empty image.
void init_with(int nrows, int ncols, unsigned bdr = border::thickness);
@@ -129,9 +132,6 @@
/// Give the definition domain.
const box2d& domain() const;
- /// Give a bounding box.
- const box2d& bbox() const;
-
/// Give the border thickness.
unsigned border() const;
@@ -144,11 +144,16 @@
/// Read-write access to the image value located at \p p.
T& operator()(const point2d& p);
- /// Return an offset from a dpoints
+ /// Read-only access to the image value located at (\p row, \p col).
+ const T& at(int row, int col) const;
+
+ /// Read-write access to the image value located at (\p row, \p col).
+ T& at(int row, int col);
+
+
+ /// Return the offset corresponding to the dpoint \p dp.
int offset(const dpoint2d& dp);
- /// Destructor.
- ~image2d_b();
private:
@@ -167,6 +172,7 @@
};
+
# ifndef MLN_INCLUDE_ONLY
// ctors
@@ -192,7 +198,7 @@
image2d_b<T>::init_with(int nrows, int ncols, unsigned bdr)
{
mln_precondition(! this->has_data());
- b_ = mk_box2d(nrows, ncols);
+ b_ = make::box2d(nrows, ncols);
bdr_ = bdr;
allocate_();
}
@@ -265,14 +271,6 @@
}
template <typename T>
- const box2d&
- image2d_b<T>::bbox() const
- {
- mln_precondition(this->has_data());
- return b_;
- }
-
- template <typename T>
unsigned
image2d_b<T>::border() const
{
@@ -313,6 +311,22 @@
}
template <typename T>
+ const T&
+ image2d_b<T>::at(int row, int col) const
+ {
+ mln_precondition(this->owns_(make::point2d(row, col)));
+ return array_[row][col];
+ }
+
+ template <typename T>
+ T&
+ image2d_b<T>::at(int row, int col)
+ {
+ mln_precondition(this->owns_(make::point2d(row, col)));
+ return array_[row][col];
+ }
+
+ template <typename T>
image2d_b<T>::~image2d_b()
{
deallocate_();
Index: mln/core/internal/image_adaptor.hh
--- mln/core/internal/image_adaptor.hh (revision 1009)
+++ mln/core/internal/image_adaptor.hh (working copy)
@@ -105,7 +105,7 @@
}
template <typename I, typename E>
- const image_adaptor_<I,E>::pset&
+ const typename image_adaptor_<I,E>::pset&
image_adaptor_<I,E>::domain() const
{
return adaptee_.domain();
Index: mln/core/internal/image_base.hh
--- mln/core/internal/image_base.hh (revision 1009)
+++ mln/core/internal/image_base.hh (working copy)
@@ -87,6 +87,7 @@
bool
image_base_<S,E>::has(const psite& p) const
{
+ mln_precondition(exact(this)->has_data());
return exact(this)->domain().has(p);
}
@@ -94,6 +95,7 @@
const box_<mln_point(S)>&
image_base_<S,E>::bbox() const
{
+ mln_precondition(exact(this)->has_data());
return exact(this)->domain().bbox();
}
@@ -101,6 +103,7 @@
std::size_t
image_base_<S,E>::npoints() const
{
+ mln_precondition(exact(this)->has_data());
return exact(this)->domain().npoints();
}
Index: mln/core/internal/piter_adaptor.hh
--- mln/core/internal/piter_adaptor.hh (revision 0)
+++ mln/core/internal/piter_adaptor.hh (revision 0)
@@ -0,0 +1,171 @@
+// 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_CORE_INTERNAL_PITER_ADAPTOR_HH
+# define MLN_CORE_INTERNAL_PITER_ADAPTOR_HH
+
+/*! \file mln/core/internal/piter_adaptor_.hh
+ *
+ * \brief Definition of iterators on points of boxes.
+ */
+
+# include <mln/core/concept/piter.hh>
+# include <mln/core/concept/box.hh>
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+ /*! \brief A base class for point iterator adaptors.
+ *
+ * Parameter \c Pi is the type of the point iterator adaptee;
+ * parameter E is the exact type.
+ */
+ template <typename Pi, typename E>
+ class piter_adaptor_ : public Piter<E>
+ {
+ public:
+
+ /// Space dimension.
+ enum { dim = Pi::dim };
+
+ /// Psite associated type.
+ typedef mln_psite(Pi) psite;
+
+ /// Point associated type.
+ typedef mln_point(Pi) point;
+
+ /// Dpoint associated type.
+ typedef mln_dpoint(Pi) dpoint;
+
+ /// Coordinate associated type.
+ typedef mln_coord(Pi) coord;
+
+
+ /// Constructor from a point iterator \p \piter.
+ piter_adaptor_(const Pi& piter);
+
+
+ /// Convertion to point.
+ operator point() const;
+
+ /// Address of the point.
+ const point* pointer() const;
+
+ /// Give the i-th coordinate.
+ coord operator[](unsigned i) const;
+
+ /// Test the iterator validity.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ protected:
+
+ Pi piter_; // own copy
+ };
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename Pi, typename E>
+ piter_adaptor_<Pi,E>::piter_adaptor_(const Pi& piter)
+ : piter_(piter)
+ {
+ invalidate();
+ }
+
+ template <typename Pi, typename E>
+ piter_adaptor_<Pi,E>::operator mln_point(Pi) () const
+ {
+ return piter_;
+ }
+
+ template <typename Pi, typename E>
+ const mln_point(Pi)*
+ piter_adaptor_<Pi,E>::pointer() const
+ {
+ return piter_.pointer();
+ }
+
+ template <typename Pi, typename E>
+ mln_coord(Pi)
+ piter_adaptor_<Pi,E>::operator[](unsigned i) const
+ {
+ assert(i < dim);
+ return piter_[i];
+ }
+
+ template <typename Pi, typename E>
+ bool
+ piter_adaptor_<Pi,E>::is_valid() const
+ {
+ return piter_.is_valid();
+ }
+
+ template <typename Pi, typename E>
+ void
+ piter_adaptor_<Pi,E>::invalidate()
+ {
+ piter_.invalidate();
+ }
+
+ template <typename Pi, typename E>
+ void
+ piter_adaptor_<Pi,E>::start()
+ {
+ piter_.start();
+ }
+
+ template <typename Pi, typename E>
+ void
+ piter_adaptor_<Pi,E>::next_()
+ {
+ piter_.next();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_PITER_ADAPTOR_HH
Index: mln/core/internal/set_of.hh
--- mln/core/internal/set_of.hh (revision 1009)
+++ mln/core/internal/set_of.hh (working copy)
@@ -69,6 +69,8 @@
* \param[in] elt The element to be inserted.
*
* If \p elt is already in the set, this method is a no-op.
+ *
+ * \todo Returns exact(*this).
*/
void insert(const E& elt);
Index: mln/core/box2d.hh
--- mln/core/box2d.hh (revision 1009)
+++ mln/core/box2d.hh (working copy)
@@ -49,47 +49,10 @@
typedef box_<point2d> box2d;
- /*! \brief Create an mln::box2d.
- *
- * \param[in] nrows Number of rows.
- * \param[in] ncols Number of columns.
- *
- * \pre \p nrows != 0 and \p ncols != 0.
- *
- * \return A 2D box.
- */
- box2d mk_box2d(unsigned nrows, unsigned ncols)
- {
- mln_precondition(nrows != 0 && ncols != 0);
- box2d tmp(mk_point2d(0, 0),
- mk_point2d(nrows - 1, ncols - 1));
- return tmp;
- }
-
-
- /*! \brief Create an mln::box2d.
- *
- * \overload
- *
- * \param[in] min_row Index of the top most row.
- * \param[in] max_row Index of the botton most row.
- * \param[in] min_col Index of the left most column.
- * \param[in] max_col Index of the right most column.
- *
- * \pre \p max_row >= \p min_row and \p max_col >= \p min_col.
- *
- * \return A 2D box.
- */
- box2d mk_box2d(int min_row, int max_row,
- int min_col, int max_col)
- {
- mln_precondition(max_row >= min_row && max_col >= min_col);
- box2d tmp(mk_point2d(min_row, min_col),
- mk_point2d(max_row, max_col));
- return tmp;
- }
-
} // end of namespace mln
+# include <mln/make/box2d.hh>
+
+
#endif // ! MLN_CORE_BOX2D_HH
Index: mln/core/point2d.hh
--- mln/core/point2d.hh (revision 1009)
+++ mln/core/point2d.hh (working copy)
@@ -46,24 +46,10 @@
typedef point_<2,int> point2d;
- /*! \brief Create an mln::point2d.
- *
- * \param[in] row Index of row.
- * \param[in] col Index of column.
- *
- * \return A 2D point.
- */
- point2d mk_point2d(int row, int col)
- {
- point2d tmp;
- tmp[0] = row;
- tmp[1] = col;
- return tmp;
- }
-
} // end of namespace mln
+# include <mln/make/point2d.hh>
# include <mln/core/dpoint2d.hh>
Index: mln/core/safe_image.hh
--- mln/core/safe_image.hh (revision 1009)
+++ mln/core/safe_image.hh (working copy)
@@ -44,6 +44,12 @@
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
mln_lvalue(I) operator()(const mln_psite(I)& p);
+
+ template <typename U>
+ struct change_value
+ {
+ typedef safe_image<mln_ch_value(I, U)> ret;
+ };
};
@@ -67,7 +73,7 @@
safe_image<I>::operator()(const mln_psite(I)& p) const
{
static mln_value(I) tmp;
- if (not this->owns_(p))
+ if (! this->owns_(p))
return tmp;
return this->adaptee_(p);
}
@@ -77,7 +83,7 @@
safe_image<I>::operator()(const mln_psite(I)& p)
{
static mln_value(I) tmp;
- if (not this->owns_(p))
+ if (! this->owns_(p))
return tmp;
return this->adaptee_(p);
}
Index: mln/fun/chess.hh
--- mln/fun/chess.hh (revision 0)
+++ mln/fun/chess.hh (revision 0)
@@ -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_FUN_CHESS_HH
+# define MLN_FUN_CHESS_HH
+
+/*! \file mln/fun/chess.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/core/point2d.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ // FIXME: Doc!
+
+ struct chess_t : public Function_p2b< chess_t >
+ {
+ bool operator()(const point2d& p) const;
+ }
+
+ chess;
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ bool
+ chess_t::operator()(const point2d& p) const
+ {
+ return (p.row() + p.col()) % 2 = 0;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_CHESS_HH
Index: mln/fun/all.hh
--- mln/fun/all.hh (revision 1009)
+++ mln/fun/all.hh (working copy)
@@ -33,6 +33,10 @@
* \brief FIXME.
*/
+# include <mln/core/concept/function.hh>
+
+
+// FIXME: Usually all.hh is the file to include all files in the current directory...
namespace mln
{
@@ -41,7 +45,7 @@
{
template <typename T>
- struct all
+ struct all : public Function< all<T> >
{
all(T t);
template <typename U>
Index: mln/io/save_pgm.hh
--- mln/io/save_pgm.hh (revision 1009)
+++ mln/io/save_pgm.hh (working copy)
@@ -55,7 +55,7 @@
file << "# olena" << std::endl;
file << ima.ncols() << ' ' << ima.nrows() <<
std::endl;
file << "255" << std::endl;
- point2d p = mk_point2d(ima.domain().pmin().row(),
+ point2d p = make::point2d(ima.domain().pmin().row(),
ima.domain().pmin().col());
size_t len = ima.ncols() * sizeof(unsigned char);
for (;
Index: mln/io/load_pgm.hh
--- mln/io/load_pgm.hh (revision 1009)
+++ mln/io/load_pgm.hh (working copy)
@@ -134,7 +134,7 @@
template <typename I>
void load_pgm_raw_2d(std::ifstream& file, I& ima)
{
- point2d p = mk_point2d(0, ima.domain().pmin().col());
+ point2d p = make::point2d(0, ima.domain().pmin().col());
size_t len = ima.ncols() * sizeof(mln_value(I));
for (p.row() = ima.domain().pmin().row();
p.row() <= ima.domain().pmax().row();
Index: mln/make/dpoint2d.hh
--- mln/make/dpoint2d.hh (revision 0)
+++ mln/make/dpoint2d.hh (revision 0)
@@ -0,0 +1,72 @@
+// 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_MAKE_DPOINT2D_HH
+# define MLN_MAKE_DPOINT2D_HH
+
+/*! \file mln/make/dpoint2d.hh
+ *
+ * \brief Routine to construct an mln::dpoint2d.
+ */
+
+# include <mln/core/dpoint2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an mln::dpoint2d.
+ *
+ * \param[in] row Row coordinate.
+ * \param[in] Col Column coordinate.
+ *
+ * \return A 2D dpoint.
+ */
+ mln::dpoint2d dpoint2d(int row, int col);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ mln::dpoint2d dpoint2d(int row, int col)
+ {
+ mln::dpoint2d tmp;
+ tmp[0] = row;
+ tmp[1] = col;
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_DPOINT2D_HH
Index: mln/make/window2d.hh
--- mln/make/window2d.hh (revision 0)
+++ mln/make/window2d.hh (revision 0)
@@ -0,0 +1,82 @@
+// 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_MAKE_WINDOW2D_HH
+# define MLN_MAKE_WINDOW2D_HH
+
+/*! \file mln/make/window2d.hh
+ *
+ * \brief Routine to create an mln::window2d.
+ */
+
+# include <cmath>
+# include <mln/core/window2d.hh>
+# include <mln/make/dpoint2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an mln::window2d.
+ *
+ * \param[in] values Array of Booleans.
+ *
+ * \pre The array size, \c M, has to be a square of an odd integer.
+ *
+ * \return A 2D window.
+ */
+ template <unsigned M>
+ mln::window2d window2d(const bool (&values)[M]);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned M>
+ mln::window2d window2d(const bool (&values)[M])
+ {
+ int h = unsigned(std::sqrt(float(M))) / 2;
+ assert((2 * h + 1) * (2 * h + 1) = M);
+ mln::window2d tmp;
+ unsigned i = 0;
+ for (int row = - h; row <= h; ++row)
+ for (int col = - h; col <= h; ++col)
+ if (values[i++])
+ tmp.insert(make::dpoint2d(row, col));
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_WINDOW2D_HH
Index: mln/make/box2d.hh
--- mln/make/box2d.hh (revision 0)
+++ mln/make/box2d.hh (revision 0)
@@ -0,0 +1,101 @@
+// 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_MAKE_BOX2D_HH
+# define MLN_MAKE_BOX2D_HH
+
+/*! \file mln/make/box2d.hh
+ *
+ * \brief Routines to construct an mln::box2d.
+ */
+
+# include <mln/core/box2d.hh>
+# include <mln/make/point2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an mln::box2d.
+ *
+ * \param[in] nrows Number of rows.
+ * \param[in] ncols Number of columns.
+ *
+ * \pre \p nrows != 0 and \p ncols != 0.
+ *
+ * \return A 2D box.
+ */
+ mln::box2d box2d(unsigned nrows, unsigned ncols);
+
+
+ /*! \brief Create an mln::box2d.
+ *
+ * \overload
+ *
+ * \param[in] min_row Index of the top most row.
+ * \param[in] max_row Index of the botton most row.
+ * \param[in] min_col Index of the left most column.
+ * \param[in] max_col Index of the right most column.
+ *
+ * \pre \p max_row >= \p min_row and \p max_col >= \p min_col.
+ *
+ * \return A 2D box.
+ */
+ mln::box2d box2d(int min_row, int max_row,
+ int min_col, int max_col);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ mln::box2d box2d(unsigned nrows, unsigned ncols)
+ {
+ mln_precondition(nrows != 0 && ncols != 0);
+ mln::box2d tmp(make::point2d(0, 0),
+ make::point2d(nrows - 1, ncols - 1));
+ return tmp;
+ }
+
+ mln::box2d box2d(int min_row, int max_row,
+ int min_col, int max_col)
+ {
+ mln_precondition(max_row >= min_row && max_col >= min_col);
+ mln::box2d tmp(make::point2d(min_row, min_col),
+ make::point2d(max_row, max_col));
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_BOX2D_HH
Index: mln/make/point2d.hh
--- mln/make/point2d.hh (revision 0)
+++ mln/make/point2d.hh (revision 0)
@@ -0,0 +1,72 @@
+// 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_MAKE_POINT2D_HH
+# define MLN_MAKE_POINT2D_HH
+
+/*! \file mln/make/point2d.hh
+ *
+ * \brief Routine to construct an mln::point2d.
+ */
+
+# include <mln/core/point2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an mln::point2d.
+ *
+ * \param[in] row Row coordinate.
+ * \param[in] Col Column coordinate.
+ *
+ * \return A 2D point.
+ */
+ mln::point2d point2d(int row, int col);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ mln::point2d point2d(int row, int col)
+ {
+ mln::point2d tmp;
+ tmp[0] = row;
+ tmp[1] = col;
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_POINT2D_HH