Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
October 2008
- 14 participants
- 373 discussions
cleanup-2008 2752: Clean-up from_to, add some new overloads, and fix (c).
by Thierry Geraud 31 Oct '08
by Thierry Geraud 31 Oct '08
31 Oct '08
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Clean-up from_to, add some new overloads, and fix (c).
* milena/tests/core/other/w_window.cc: New.
* milena/tests/core/other/Makefile.am: Update.
* milena/tests/core/alias/window2d.cc: Remove echos.
* milena/mln/make/image2d.hh: New.
* milena/tests/make/image2d.cc: New.
* milena/tests/make/Makefile.am: Update.
* milena/tests/convert/to_image.cc: Fix copyright.
(include): Remove; useless.
* milena/mln/core/alias/window2d.hh: Fix include.
* milena/mln/core/w_window.hh (from_to): New overload.
* milena/mln/core/dpoint.hh: Fix (c).
* milena/mln/core/concept/weighted_window.hh: Fix (c).
* milena/mln/core/concept/object.hh: Include all metal math.
Include metal converts_to.
* milena/mln/core/concept/window.hh (from_to): New overload.
(todo): New.
* milena/mln/core/concept/image.hh (from_to): New overload.
* milena/mln/core/concept/gpoint.hh: Fix doc.
* milena/mln/core/concept/gdpoint.hh (from_to): New overload.
* milena/mln/core/def/all.hh: New.
* milena/mln/core/window.hh: Fix copyright.
* milena/mln/linear/convolve.hh: Fix warning + copyright.
* milena/mln/make/image.hh (image): New overload for 3D.
* milena/mln/make/w_window2d.hh: Fix copyright.
Remove useless include.
* milena/mln/convert/to_image.hh
(mln_image_from, helper_dim_, helper_image_from_): Remove.
Redundant with image_from_grid.
(to_image): Update and use convert::from_to.
* milena/mln/convert/from_to.hxx: Layout and update.
mln/convert/from_to.hxx | 84 +++++++++++++++-----
mln/convert/to_image.hh | 148 +++++++++++-------------------------
mln/core/alias/window2d.hh | 8 +
mln/core/concept/gdpoint.hh | 35 ++++++++
mln/core/concept/gpoint.hh | 4
mln/core/concept/image.hh | 51 +++++++++++-
mln/core/concept/object.hh | 3
mln/core/concept/weighted_window.hh | 1
mln/core/concept/window.hh | 74 ++++++++++++++++--
mln/core/def/all.hh | 49 +++++++++++
mln/core/dpoint.hh | 3
mln/core/w_window.hh | 63 +++++++++++++--
mln/core/window.hh | 1
mln/linear/convolve.hh | 5 -
mln/make/image.hh | 48 +++++++++--
mln/make/image2d.hh | 77 ++++++++++++++++++
mln/make/w_window2d.hh | 2
tests/convert/to_image.cc | 15 ---
tests/core/alias/window2d.cc | 23 ++---
tests/core/other/Makefile.am | 4
tests/core/other/w_window.cc | 48 +++++++++++
tests/make/Makefile.am | 2
tests/make/image2d.cc | 47 +++++++++++
23 files changed, 617 insertions(+), 178 deletions(-)
Index: milena/tests/core/other/w_window.cc
--- milena/tests/core/other/w_window.cc (revision 0)
+++ milena/tests/core/other/w_window.cc (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file tests/core/other/w_window.cc
+/// \brief Tests on regular weighted windows.
+
+#include <mln/core/w_window.hh>
+#include <mln/core/image/image2d.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ int vals[] = { 1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9 };
+ w_window<dpoint2d,int> w_win;
+ convert::from_to(vals, w_win);
+
+ image2d<int> ima;
+ convert::from_to(w_win, ima);
+ mln_assertion(ima.domain() == make::box2d(-1,-1, 1,1));
+}
Index: milena/tests/core/other/Makefile.am
--- milena/tests/core/other/Makefile.am (revision 2751)
+++ milena/tests/core/other/Makefile.am (working copy)
@@ -20,7 +20,8 @@
pixter2d_more \
pixter3d \
pixter3d_more \
- point_set_compatibility
+ point_set_compatibility \
+ w_window
box_runstart_piter_SOURCES = box_runstart_piter.cc
category_SOURCES = category.cc
@@ -40,5 +41,6 @@
pixter3d_SOURCES = pixter3d.cc
pixter3d_more_SOURCES = pixter3d_more.cc
point_set_compatibility_SOURCES = point_set_compatibility.cc
+w_window_SOURCES = w_window.cc
TESTS = $(check_PROGRAMS)
Index: milena/tests/core/alias/window2d.cc
--- milena/tests/core/alias/window2d.cc (revision 2751)
+++ milena/tests/core/alias/window2d.cc (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,17 +26,13 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/core/alias/window2d.cc
- *
- * \brief Tests on mln::window2d.
- */
+/// \file tests/core/alias/window2d.cc
+///
+/// Tests on mln::window2d.
#include <mln/core/alias/window2d.hh>
#include <mln/core/image/image2d.hh>
#include <mln/convert/to_image.hh>
-#include <mln/debug/println.hh>
-#include <mln/logical/not.hh>
-
int main()
@@ -50,9 +47,11 @@
w .insert(-1,-1)
.insert( 1, 1);
- image2d<bool> ima = convert::to_image(w);
- debug::println(ima);
- debug::println(logical::not_(ima));
-
mln_assertion(w.delta() == 1);
+
+ // The code below is equivalent to:
+ // image2d<bool> ima;
+ // convert::from_to(w, ima);
+ image2d<bool> ima = convert::to_image(w);
+ (void) ima;
}
Index: milena/tests/make/Makefile.am
--- milena/tests/make/Makefile.am (revision 2751)
+++ milena/tests/make/Makefile.am (working copy)
@@ -4,10 +4,12 @@
check_PROGRAMS = \
dual_neighb \
+ image2d \
mat \
w_window
dual_neighb_SOURCES = dual_neighb.cc
+image2d_SOURCES = image2d.cc
mat_SOURCES = mat.cc
w_window_SOURCES = w_window.cc
Index: milena/tests/make/image2d.cc
--- milena/tests/make/image2d.cc (revision 0)
+++ milena/tests/make/image2d.cc (revision 0)
@@ -0,0 +1,47 @@
+// Copyright (C) 2008 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/make/image2d.cc
+ *
+ * \brief Tests on mln::make::image2d.
+ */
+
+#include <mln/make/image2d.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ bool vals[] = { 1, 1, 0, 0, 1,
+ 1, 1, 1, 1, 0,
+ 0, 1, 1, 1, 0,
+ 0, 1, 1, 1, 0,
+ 0, 1, 0, 0, 0 };
+ image2d<bool> ima = make::image2d(vals);
+ mln_assertion(ima.domain() == box2d(5,5));
+}
Index: milena/tests/convert/to_image.cc
--- milena/tests/convert/to_image.cc (revision 2751)
+++ milena/tests/convert/to_image.cc (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,10 +26,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/convert/to_image.cc
- *
- * \brief Tests on mln::convert::to_image.
- */
+/// \file tests/convert/to_image.cc
+/// Tests on mln::convert::to_image.
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/window2d.hh>
@@ -40,10 +39,6 @@
#include <mln/convert/to.hh>
-#include <mln/debug/println.hh>
-
-
-
int main()
{
using namespace mln;
@@ -61,6 +56,4 @@
image2d<bool> ima_X = convert::to_image(box_3x3 | fun::p2b::chess, 0);
window2d win_X = convert::to<window2d>(X);
mln_assertion(convert::to_image(win_X) == ima_X);
-
- // FIXME: nbh!
}
Index: milena/mln/core/alias/window2d.hh
--- milena/mln/core/alias/window2d.hh (revision 2751)
+++ milena/mln/core/alias/window2d.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -29,7 +30,8 @@
# define MLN_CORE_ALIAS_WINDOW2D_HH
/// \file mln/core/alias/window2d.hh
-/// \brief Definition of the mln::window2d alias and of a construction
+///
+/// Definition of the mln::window2d alias and of a construction
/// routine.
///
/// \todo c8p etc.
@@ -37,7 +39,7 @@
# include <mln/core/window.hh>
# include <mln/core/alias/dpoint2d.hh>
# include <mln/metal/math/sqrt.hh>
-# include <mln/convert/from_to.hh>
+# include <mln/convert/from_to.hxx>
namespace mln
Index: milena/mln/core/w_window.hh
--- milena/mln/core/w_window.hh (revision 2751)
+++ milena/mln/core/w_window.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,10 +29,11 @@
#ifndef MLN_CORE_W_WINDOW_HH
# define MLN_CORE_W_WINDOW_HH
-/*! \file mln/core/w_window.hh
- *
- * \brief Definition of the generic weighted window class mln::w_window.
- */
+/// \file mln/core/w_window.hh
+///
+/// Definition of the generic weighted window class mln::w_window.
+///
+/// \todo Generalize W_Window -> Image.
# include <map>
@@ -43,8 +45,8 @@
# include <mln/value/ops.hh>
# include <mln/util/ord.hh>
-# include <mln/metal/converts_to.hh>
-# include <mln/metal/math/root.hh>
+# include <mln/level/fill.hh>
+# include <mln/geom/bbox.hh> // FIXME: We may have some dep trouble with this include.
# include <mln/literal/zero.hh>
# include <mln/convert/to.hh>
@@ -150,6 +152,10 @@
void
from_to(const Image<I>& from, w_window<D,W>& to);
+ template <typename D, typename W, typename I>
+ void
+ from_to(const w_window<D,W>& from, Image<I>& to);
+
template <typename V, unsigned S, typename D, typename W>
void
from_to(const V (&weight)[S], w_window<D,W>& to);
@@ -331,7 +337,6 @@
{
template <typename I, typename D, typename W>
- inline
void
from_to(const Image<I>& from_, w_window<D,W>& to)
{
@@ -345,10 +350,54 @@
to.insert(ima(p), convert::to<D>(p));
}
+ template <typename D, typename W, typename I>
+ void
+ from_to(const w_window<D,W>& w_win, Image<I>& ima_)
+ {
+ typedef mln_site(I) P;
+ mlc_converts_to(D, mln_delta(P))::check();
+ mlc_converts_to(W, mln_value(I))::check();
+
+ I& ima = exact(ima_);
+ mln_precondition(! ima.has_data());
+ // mln_precondition(w_win.is_valid());
+
+ ima.init_(geom::bbox(w_win));
+ level::fill(ima, literal::zero);
+
+ unsigned n = w_win.size();
+ for (unsigned i = 0; i < n; ++i)
+ ima(convert::to<P>(w_win.dp(i))) = w_win.w(i);
+ }
+
+ // FIXME: Sample code (below) to generalize the code above:
+
+// template <typename W>
+// inline
+// mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win_)
+// {
+// const W& w_win = exact(w_win_);
+// mln_precondition(! w_win.is_empty());
+
+// typedef mln_psite(W) P;
+// box<P> b = geom::bbox(w_win);
+// mln_image_from(W, mln_weight(W)) ima(b);
+// // Fill the image with zeros, as (weighted) windows are not
+// // necessarily box-shaped (there might be holes corresponding to
+// // null weights).
+// level::fill(ima, literal::zero);
+// P O = P::origin;
+// mln_qiter(W) q(w_win, O);
+// for_all(q)
+// ima(q) = q.w();
+// return ima;
+// }
+
template <typename V, unsigned S, typename D, typename W>
void
from_to(const V (&weight)[S], w_window<D,W>& to)
{
+ mlc_bool(S != 0)::check();
mlc_converts_to(V, W)::check();
enum { d = D::dim,
s = mlc_root(d,S)::value / 2 };
Index: milena/mln/core/dpoint.hh
--- milena/mln/core/dpoint.hh (revision 2751)
+++ milena/mln/core/dpoint.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
Index: milena/mln/core/concept/weighted_window.hh
--- milena/mln/core/concept/weighted_window.hh (revision 2751)
+++ milena/mln/core/concept/weighted_window.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
Index: milena/mln/core/concept/object.hh
--- milena/mln/core/concept/object.hh (revision 2751)
+++ milena/mln/core/concept/object.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -46,8 +47,10 @@
# include <mln/metal/is_a.hh>
# include <mln/metal/is.hh>
# include <mln/metal/is_not.hh>
+# include <mln/metal/converts_to.hh>
# include <mln/metal/ret.hh>
# include <mln/metal/unqualif.hh>
+# include <mln/metal/math/all.hh>
/*! \mainpage Documentation of milena
Index: milena/mln/core/concept/window.hh
--- milena/mln/core/concept/window.hh (revision 2751)
+++ milena/mln/core/concept/window.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -37,13 +38,21 @@
*
* \todo The is_centered() method could also exist when the window is
* not regular...
+ *
+ * \todo Remove hack.
*/
# include <mln/core/concept/object.hh>
# include <mln/core/concept/iterator.hh>
# include <mln/trait/windows.hh>
+
# include <mln/core/site_set/p_array.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/literal/origin.hh>
+# include <mln/level/fill.hh>
+# include <mln/convert/from_to.hxx>
+
# define mln_is_simple_window(W) \
@@ -60,9 +69,10 @@
namespace mln
{
- // Fwd decl.
+ // Forward declaration.
template <typename E> struct Window;
+
// Window category flag type.
template <>
struct Window<void>
@@ -105,14 +115,18 @@
- template <typename W>
- void check_simple(const Window<W>& win);
+ namespace convert
+ {
+ template <typename W, typename I>
+ void
+ from_to(const Window<W>& from, Image<I>& to);
+ } // end of namespace mln::convert
-# ifndef MLN_INCLUDE_ONLY
+# ifndef MLN_INCLUDE_ONLY
namespace internal
{
@@ -273,7 +287,7 @@
ostr << " ]";
}
- } // end of namespace mln
+ } // end of namespace mln::internal
template <typename W>
inline
@@ -289,6 +303,56 @@
return ostr;
}
+
+ namespace convert
+ {
+
+ namespace internal
+ {
+
+
+ // FIXME: Hack to avoid including geom::bbox (circular
+ // dependency).
+
+ template <typename W>
+ box<mln_psite(W)> bbox_(const Window<W>& win)
+ {
+ typedef mln_psite(W) P;
+ accu::bbox<P> b;
+ P O = literal::origin;
+ mln_qiter(W) q(exact(win), O);
+ for_all(q)
+ b.take(q);
+ return b;
+ }
+
+ }
+
+ template <typename W, typename I>
+ void
+ from_to(const Window<W>& win_, Image<I>& ima_)
+ {
+ mln_is_simple_window(W)::check();
+ typedef mln_psite(I) P;
+ mlc_converts_to(mln_dpsite(W), mln_delta(P))::check();
+ mlc_equal(mln_value(I), bool)::check();
+
+ const W& win = exact(win_);
+ I& ima = exact(ima_);
+
+ // mln_precondition(win.is_valid());
+ mln_precondition(! ima.has_data());
+
+ ima.init_(internal::bbox_(win)); // geom::bbox(win));
+ level::fill(ima, false);
+
+ unsigned n = win.size();
+ for (unsigned i = 0; i < n; ++i)
+ ima(convert::to<P>(win.dp(i))) = true;
+ }
+
+ } // end of namespace mln::convert
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: milena/mln/core/concept/image.hh
--- milena/mln/core/concept/image.hh (revision 2751)
+++ milena/mln/core/concept/image.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,15 +29,17 @@
#ifndef MLN_CORE_CONCEPT_IMAGE_HH
# define MLN_CORE_CONCEPT_IMAGE_HH
-/*! \file mln/core/concept/image.hh
- * \brief Definition of the concept of mln::Image.
- */
+/// \file mln/core/concept/image.hh
+///
+/// Definition of the concept of mln::Image.
# include <mln/core/concept/site_set.hh>
# include <mln/core/concept/mesh.hh>
# include <mln/core/trait/all.hh> // FIXME: Move out of core!
# include <mln/core/macros.hh>
+# include <mln/core/site_set/box.hh>
+
# include <mln/trait/concrete.hh> // FIXME: Should be in all.hh!
# include <mln/trait/images.hh>
@@ -109,6 +112,18 @@
};
+
+ namespace convert
+ {
+
+ template <typename V, unsigned S, typename I>
+ void
+ from_to(const V (&values)[S], Image<I>& to);
+
+ } // end of namespace mln::convert
+
+
+
# ifndef MLN_INCLUDE_ONLY
@@ -224,10 +239,40 @@
E>::run();
}
+
+ namespace convert
+ {
+
+ template <typename V, unsigned S, typename I>
+ void
+ from_to(const V (&values)[S], Image<I>& to_)
+ {
+ mlc_bool(S != 0)::check();
+ mlc_converts_to(V, mln_value(I))::check();
+ typedef mln_site(I) P;
+ enum { d = P::dim,
+ s = mlc_root(d,S)::value / 2 };
+ metal::bool_<(mlc_pow_int(2 * s + 1, d) == S)>::check();
+
+ I& to = exact(to_);
+ mln_precondition(! to.has_data());
+
+ box<P> b(all_to(0), all_to(2 * s));
+ to.init_(b);
+ mln_fwd_piter(box<P>) p(b);
+ unsigned i = 0;
+ for_all(p)
+ to(p) = values[i++];
+ }
+
+ } // end of namespace mln::convert
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
+
# include <mln/core/routine/initialize.hh>
+
#endif // ! MLN_CORE_CONCEPT_IMAGE_HH
Index: milena/mln/core/concept/gpoint.hh
--- milena/mln/core/concept/gpoint.hh (revision 2751)
+++ milena/mln/core/concept/gpoint.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -43,7 +44,7 @@
namespace mln
{
- // Fwd decl.
+ // Forward declaration.
template <typename E> struct Gpoint;
@@ -308,6 +309,7 @@
// Gpoint -> algebra::vec.
template <typename P, unsigned n, typename T>
+ inline
void
from_to(const Gpoint<P>& from_, algebra::vec<n,T>& to)
{
Index: milena/mln/core/concept/gdpoint.hh
--- milena/mln/core/concept/gdpoint.hh (revision 2751)
+++ milena/mln/core/concept/gdpoint.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -124,6 +125,23 @@
+ namespace convert
+ {
+
+ template <typename D>
+ void
+ from_to(const Gdpoint<D>& from, mln_site(D)& to);
+
+// template <typename D, unsigned n, typename T>
+// void
+// from_to(const Gdpoint<D>& from, algebra::vec<n,T>& to);
+
+// template <unsigned n, typename T, typename D>
+// void
+// from_to(const algebra::vec<n,T>& from, Gdpoint<D>& to);
+
+ } // end of namespace::convert
+
# ifndef MLN_INCLUDE_ONLY
@@ -174,6 +192,23 @@
return tmp;
}
+
+ namespace convert
+ {
+
+ template <typename D>
+ inline
+ void
+ from_to(const Gdpoint<D>& dp_, mln_site(D)& p)
+ {
+ enum { n = D::dim };
+ const D& dp = exact(dp_);
+ for (unsigned i = 0; i < n; ++i)
+ p[i] = dp[i];
+ }
+
+ } // end of namespace::convert
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: milena/mln/core/def/all.hh
--- milena/mln/core/def/all.hh (revision 0)
+++ milena/mln/core/def/all.hh (revision 0)
@@ -0,0 +1,49 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_DEF_ALL_HH
+# define MLN_CORE_DEF_ALL_HH
+
+/// mln/core/def/all.hh
+/// File that includes all core definitions.
+
+
+namespace mln
+{
+
+ /// Namespace for core definitions.
+ namespace def
+ {}
+
+}
+
+
+# include <mln/core/def/coord.hh>
+# include <mln/core/def/coordf.hh>
+
+
+#endif // ! MLN_CORE_DEF_ALL_HH
Index: milena/mln/core/window.hh
--- milena/mln/core/window.hh (revision 2751)
+++ milena/mln/core/window.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
Index: milena/mln/linear/convolve.hh
--- milena/mln/linear/convolve.hh (revision 2751)
+++ milena/mln/linear/convolve.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -78,6 +79,8 @@
{
mln_precondition(exact(input).has_data());
// mln_precondition(exact(w_win).is_valid());
+ (void) input;
+ (void) w_win;
}
} // end of namespace mln::linear::internal
Index: milena/mln/make/image.hh
--- milena/mln/make/image.hh (revision 2751)
+++ milena/mln/make/image.hh (working copy)
@@ -29,13 +29,14 @@
#ifndef MLN_MAKE_IMAGE_HH
# define MLN_MAKE_IMAGE_HH
-/*! \file mln/make/image.hh
- *
- * \brief Routine to create an image from various input.
- */
+/// \file mln/make/image.hh
+///
+/// Routine to create an image from values given as a C-array.
# include <mln/core/image/image1d.hh>
# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
+
namespace mln
@@ -44,19 +45,19 @@
namespace make
{
- /*! \brief Create an image1d from an 1d array of values.
+ /*! \brief Create an image1d from an 1D array of values.
*
- * \param[in] values 1d array.
+ * \param[in] values 1D array.
*
* \return A 1D image.
*/
template <typename V, unsigned L>
- mln::image1d<V> image1d(V (&values)[L]);
+ mln::image1d<V> image(V (&values)[L]);
- /*! \brief Create an image2d from an 2d array of values.
+ /*! \brief Create an image2d from an 2D array of values.
*
- * \param[in] values 2d array.
+ * \param[in] values 2D array.
*
* \return A 2D image.
*/
@@ -64,11 +65,22 @@
mln::image2d<V> image(V (&values)[R][C]);
+ /*! \brief Create an image3d from an 3D array of values.
+ *
+ * \param[in] values 3D array.
+ *
+ * \return A 3D image.
+ */
+ template <typename V, unsigned S, unsigned R, unsigned C>
+ mln::image3d<V> image(V (&values)[S][R][C]);
+
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename V, unsigned L>
mln::image1d<V>
- image1d(V (&values)[L])
+ image(V (&values)[L])
{
mlc_bool(L != 0)::check();
mln::image1d<V> tmp(L);
@@ -81,10 +93,24 @@
mln::image2d<V>
image(V (&values)[R][C])
{
+ mlc_bool(R != 0 && C != 0)::check();
mln::image2d<V> tmp(R, C);
for (unsigned row = 0; row < R; ++row)
for (unsigned col = 0; col < C; ++col)
- tmp(point2d(row, col)) = values[row][col];
+ tmp.at(row, col) = values[row][col];
+ return tmp;
+ }
+
+ template <typename V, unsigned S, unsigned R, unsigned C>
+ mln::image3d<V>
+ image(V (&values)[S][R][C])
+ {
+ mlc_bool(S != 0 && R != 0 && C != 0)::check();
+ mln::image3d<V> tmp(S, R, C);
+ for (unsigned sli = 0; sli < S; ++sli)
+ for (unsigned row = 0; row < R; ++row)
+ for (unsigned col = 0; col < C; ++col)
+ tmp.at(sli, row, col) = values[sli][row][col];
return tmp;
}
Index: milena/mln/make/w_window2d.hh
--- milena/mln/make/w_window2d.hh (revision 2751)
+++ milena/mln/make/w_window2d.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -35,7 +36,6 @@
# include <mln/core/w_window.hh>
# include <mln/core/alias/dpoint2d.hh>
-# include <mln/metal/math/sqrt.hh>
namespace mln
Index: milena/mln/make/image2d.hh
--- milena/mln/make/image2d.hh (revision 0)
+++ milena/mln/make/image2d.hh (revision 0)
@@ -0,0 +1,77 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_IMAGE2D_HH
+# define MLN_MAKE_IMAGE2D_HH
+
+/// \file mln/make/image2d.hh
+///
+/// Routine to create a 2D image from a 1D array.
+
+# include <mln/core/image/image2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an image2d from an 2D array of values.
+ *
+ * \param[in] values 2D array.
+ *
+ * \return A 2D image.
+ */
+ template <typename V, unsigned S>
+ mln::image2d<V>
+ image2d(V (&values)[S]);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, unsigned S>
+ mln::image2d<V>
+ image2d(V (&values)[S])
+ {
+ mlc_bool(S != 0)::check();
+ enum { s = mlc_sqrt_int(S) / 2 };
+ metal::bool_<((2 * s + 1) * (2 * s + 1) == S)>::check();
+ mln::image2d<V> tmp;
+ convert::from_to(values, tmp);
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_IMAGE2D_HH
Index: milena/mln/convert/to_image.hh
--- milena/mln/convert/to_image.hh (revision 2751)
+++ milena/mln/convert/to_image.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,16 +29,11 @@
#ifndef MLN_CONVERT_TO_IMAGE_HH
# define MLN_CONVERT_TO_IMAGE_HH
-/*! \file mln/convert/to_image.hh
- *
- * \brief Conversions to mln::Image.
- *
- * \todo Remove. Use from_to instead...
- */
-
-# include <mln/core/image/image1d.hh>
-# include <mln/core/image/image2d.hh>
-# include <mln/core/image/image3d.hh>
+/// mln/convert/to_image.hh
+///
+/// Conversions to mln::Image.
+
+# include <mln/trait/image_from_grid.hh>
# include <mln/core/concept/site_set.hh>
# include <mln/core/concept/window.hh>
@@ -45,64 +41,16 @@
# include <mln/core/concept/neighborhood.hh>
# include <mln/literal/zero.hh>
-
-# include <mln/convert/to_window.hh>
# include <mln/geom/bbox.hh>
# include <mln/level/fill.hh>
# include <mln/histo/data.hh>
-# define mln_image_from(Src, Value) typename mln::image_from_< Src, Value >::ret
-
namespace mln
{
- // FIXME: Move elsewhere.
- namespace internal
- {
-
- template <typename T>
- struct helper_dim_
- {
- typedef mln_psite(T) P;
- enum { value = P::dim };
- };
-
- template <unsigned dim, typename V> struct helper_image_from_;
-
- template <typename V>
- struct helper_image_from_< 3, V >
- {
- typedef image3d<V> ret;
- };
-
- template <typename V>
- struct helper_image_from_< 2, V >
- {
- typedef image2d<V> ret;
- };
-
- template <typename V>
- struct helper_image_from_< 1, V >
- {
- typedef image1d<V> ret;
- };
-
- } // end of namespace mln::internal
-
-
- // FIXME: Doc + move elsewhere!
- template <typename T, typename V>
- struct image_from_
- {
- enum { dim = internal::helper_dim_<T>::value };
- typedef typename internal::helper_image_from_< dim, V >::ret ret;
- };
-
-
-
namespace convert
{
@@ -110,23 +58,28 @@
/// Convert a point set \p pset into a binary image. Width of the
/// converted image will be pset.bbox + 2 * \p border.
template <typename S>
- mln_image_from(S, bool) to_image(const Site_Set<S>& pset, unsigned border = 1);
+ mln_image_from_grid(mln_site(S)::grid, bool)
+ to_image(const Site_Set<S>& pset, unsigned border = 1);
/// Convert a window \p win into a binary image.
template <typename W>
- mln_image_from(W, bool) to_image(const Window<W>& win);
-
- /// Convert a neighborhood \p nbh into a binary image.
- template <typename N>
- mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh);
+ mln_image_from_grid(mln_site(W)::grid, bool)
+ to_image(const Window<W>& win);
/// Convert a weighted window \p w_win into an image.
template <typename W>
- mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win);
+ mln_image_from_grid(mln_site(W)::grid, bool)
+ to_image(const Weighted_Window<W>& w_win);
+
+ /// Convert a neighborhood \p nbh into a binary image.
+ template <typename N>
+ mln_image_from_grid(mln_site(N)::grid, bool)
+ to_image(const Neighborhood<N>& nbh);
/// Convert an histo \p h into an image1d<std::size_t>.
template <typename T>
- image1d<std::size_t> to_image(const histo::data<T>& h);
+ image1d<std::size_t>
+ to_image(const histo::data<T>& h);
@@ -134,10 +87,12 @@
template <typename S>
inline
- mln_image_from(S, bool) to_image(const Site_Set<S>& pset_, unsigned border)
+ mln_image_from_grid(mln_site(S)::grid, bool)
+ to_image(const Site_Set<S>& pset_, unsigned border)
{
const S& pset = exact(pset_);
- mln_image_from(S, bool) ima(geom::bbox(pset).to_larger(border));
+ mln_image_from_grid(mln_site(S)::grid, bool) ima;
+ ima.init_(geom::bbox(pset).to_larger(border));
level::fill(ima, false);
mln_piter(S) p(pset);
for_all(p)
@@ -147,52 +102,41 @@
template <typename W>
inline
- mln_image_from(W, bool) to_image(const Window<W>& win_)
+ mln_image_from_grid(mln_site(W)::grid, bool)
+ to_image(const Window<W>& win)
{
- const W& win = exact(win_);
- mln_precondition(! win.is_empty());
-
- typedef mln_psite(W) P;
- box<P> b = geom::bbox(win);
- mln_image_from(W, bool) ima(b);
- level::fill(ima, false);
- P O = P::origin;
- mln_qiter(W) q(win, O);
- for_all(q)
- ima(q) = true;
- return ima;
+ mln_is_simple_window(W)::check();
+ // mln_precondition(exact(win).is_valid());
+ mln_image_from_grid(mln_site(W)::grid, bool) tmp;
+ convert::from_to(win, tmp);
+ return tmp;
}
- template <typename N>
+ template <typename W>
inline
- mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh)
+ mln_image_from_grid(mln_site(W)::grid, bool)
+ to_image(const Weighted_Window<W>& w_win)
{
- return to_image(convert::to_window(nbh));
+ mln_is_simple_window(W)::check();
+ // mln_precondition(exact(w_win).is_valid());
+ mln_image_from_grid(mln_site(W)::grid, bool) tmp;
+ convert::from_to(exact(w_win), tmp);
+ return tmp;
}
- template <typename W>
+ template <typename N>
inline
- mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win_)
+ mln_image_from_grid(mln_site(N)::grid, bool)
+ to_image(const Neighborhood<N>& nbh)
{
- const W& w_win = exact(w_win_);
- mln_precondition(! w_win.is_empty());
-
- typedef mln_psite(W) P;
- box<P> b = geom::bbox(w_win);
- mln_image_from(W, mln_weight(W)) ima(b);
- // Fill the image with zeros, as (weighted) windows are not
- // necessarily box-shaped (there might be holes corresponding to
- // null weights).
- level::fill(ima, literal::zero);
- mln_qiter(W) q(w_win, P::origin);
- for_all(q)
- ima(q) = q.w();
- return ima;
+ // mln_precondition(exact(nbh).is_valid());
+ return to_image(exact(nbh).win());
}
template <typename T>
inline
- image1d<std::size_t> to_image(const histo::data<T>& h)
+ image1d<std::size_t>
+ to_image(const histo::data<T>& h)
{
T v_min = h.vset()[0],
v_max = h.vset()[h.vset().nvalues() - 1];
Index: milena/mln/convert/from_to.hxx
--- milena/mln/convert/from_to.hxx (revision 2751)
+++ milena/mln/convert/from_to.hxx (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -33,6 +33,9 @@
// All overloaded "convert::from_to" routines have to be declared in
// the present file. It allows for *deferred* use of these routines.
+# include <mln/core/def/all.hh>
+# include <mln/core/grids.hh>
+
namespace mln
{
@@ -40,17 +43,22 @@
// Forward declarations.
+ template <typename E> struct Gdpoint;
+ template <typename E> struct Gpoint;
+ template <typename E> struct Image;
template <typename E> struct Object;
template <typename E> struct Proxy;
- template <typename E> struct Image;
template <typename E> struct Site_Set;
- template <typename E> struct Weighted_Window;
- template <typename E> struct Gpoint;
template <typename E> struct Value;
+ template <typename E> struct Weighted_Window;
+ template <typename E> struct Window;
+
+ template <typename G, typename C> struct dpoint;
+ template <typename G, typename C> struct point;
- template <typename D, typename W> class w_window;
template <typename D> class neighb;
template <typename D> class window;
+ template <typename D, typename W> class w_window;
namespace algebra {
template <unsigned n, typename T> class vec;
@@ -87,16 +95,8 @@
template <typename F, typename T>
void
from_to(const Object<F>&, Object<T>&);
+ // end of Guard.
- // Image -> Site_Set.
- template <typename I, typename S>
- void
- from_to(const Image<I>& from, Site_Set<S>& to);
-
- // Gpoint -> algebra::vec.
- template <typename P, unsigned n, typename T>
- void
- from_to(const Gpoint<P>& from, algebra::vec<n,T>& to);
// algebra::vec -> Gpoint.
template <unsigned n, typename T, typename P>
@@ -108,11 +108,39 @@
void
from_to(const algebra::vec<3,T>& from, value::rgb<m>& to);
+
// bool -> rgb.
template <unsigned m>
void
from_to(bool from, value::rgb<m>& to);
+
+ // C-array -> Image.
+ template <typename V, unsigned S, typename I>
+ void
+ from_to(const V (&values)[S], Image<I>& to);
+
+ // C-array -> w_window
+ template <typename V, unsigned S, typename D, typename W>
+ void
+ from_to(const V (&weight)[S], w_window<D,W>& to);
+
+
+ // C-array -> window2d
+ template <unsigned S>
+ void
+ from_to(const bool (&values)[S], window< dpoint<grid::square, def::coord> >& win);
+ template <unsigned R, unsigned C>
+ void
+ from_to(const bool (&values)[R][C], window< dpoint<grid::square, def::coord> >& win);
+
+
+ // Gdpoint -> point
+ template <typename D>
+ void
+ from_to(const Gdpoint<D>& from, mln_site(D)& to);
+
+
// Value -> Value
template <typename F, typename T>
void
@@ -133,22 +161,28 @@
void
from_to(const Proxy<P>& from, T& to);
+
+ // Gpoint -> algebra::vec.
+ template <typename P, unsigned n, typename T>
+ void
+ from_to(const Gpoint<P>& from, algebra::vec<n,T>& to);
+
// Gpoint -> delta-point
template <typename P>
void
from_to(const Gpoint<P>& from, mln_delta(P)& to);
+ // Image -> Site_Set.
+ template <typename I, typename S>
+ void
+ from_to(const Image<I>& from, Site_Set<S>& to);
+
// Image -> w_window
template <typename I, typename D, typename W>
void
from_to(const Image<I>& from, w_window<D,W>& to);
- // C-array -> w_window
- template <typename V, unsigned S, typename D, typename W>
- void
- from_to(const V (&weight)[S], w_window<D,W>& to);
-
// neighb<W> -> W
template <typename W>
@@ -160,6 +194,18 @@
void
from_to(const W& from, mln::neighb<W>& to);
+
+ // Window -> Image
+ template <typename W, typename I>
+ void
+ from_to(const Window<W>& from, Image<I>& to);
+
+
+ // w_window -> Image
+ template <typename D, typename W, typename I>
+ void
+ from_to(const w_window<D,W>& from, Image<I>& to);
+
} // end of namespace mln::convert
} // end of namespace mln
1
0
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
ChangeLog:
2008-10-31 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Improve Skeleton computation.
* garrigues/ocr/check_simple_point.cc: New. check the analysis of the
local configuration of a pixel.
* garrigues/ocr/enlarge.hh: Add routine for int_u8 images.
* garrigues/ocr/ocr_with_preprocess.cc: Add the use of skeleton in the
ocr preprocessing.
* garrigues/ocr/simple_point.cc: .
* garrigues/ocr/simple_point.hh: .
* garrigues/ocr/skel.cc: Remove.
* garrigues/ocr/skeleton.cc: Remove.
* garrigues/ocr/skeleton.old.cc: New.
* garrigues/ocr/skeleton.old.hh: New.
* garrigues/ocr/Makefile: .
* garrigues/ocr/check.sh: .
---
Makefile | 5
check.sh | 1
check_simple_point.cc | 61 ++++
enlarge.hh | 124 +++++++--
ocr_with_preprocess.cc | 94 +++++--
simple_point.cc | 2
simple_point.hh | 35 ++
skeleton.hh | 631 +++++++------------------------------------------
skeleton.old.cc | 30 ++
skeleton.old.hh | 611 +++++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 1006 insertions(+), 588 deletions(-)
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/skel.cc (deleted)
===================================================================
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.cc (deleted)
===================================================================
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.old.hh
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.old.hh (revision 0)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.old.hh (revision 2750)
@@ -0,0 +1,611 @@
+// Copyright (C) 2007, 2008 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 SKELETON_HH
+# define SKELETON_HH
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <sandbox/aroumougame/skeleton/sedt.hh>
+
+#include <mln/core/site_set/p_set.hh>
+#include <mln/math/sqrt.hh>
+
+namespace mln
+{
+
+
+template <typename P>
+ std::vector< std::pair< double, P > > remove(std::vector< std::pair< double, P > > Q, P p)
+{
+ typename std::vector<std::pair< double, P > >::iterator it;
+
+ for(it = Q.begin(); it!=Q.end(); it++)
+ {
+ if((*it).second==p)
+ {
+ it = Q.erase(it);
+ break;
+ }
+ }
+ return Q;
+}
+template <typename N>
+ double distance(N a, N b, N c, N d)
+{
+ double dist = sqrt((a-c)*(a-c)+(b-d)*(b-d));
+ return dist;
+}
+template <typename P>
+ std::vector< std::pair< double, P > > insertDicho(std::vector< std::pair< double, P > > Q, std::pair< double, P> p)
+{
+ int indMin, indMax, indMid;
+
+ indMin = 0;
+ indMax = Q.size();
+
+ if(indMax==0 || Q[indMax-1].first <= p.first)
+ Q.push_back(p);
+ else
+ {
+ while(indMax > indMin)
+ {
+ indMid = int(indMin + (indMax-indMin)/2);
+ if(Q[indMid].first < p.first)
+ {
+ indMin = indMid+1;
+ if(Q[indMin].first > p.first)
+ {
+ indMax = indMid;
+ }
+ }
+ else
+ {
+ indMax = indMid-1;
+ if(Q[indMax].first < p.first)
+ {
+ indMin = indMid;
+ }
+ }
+ }
+
+ typename std::vector< std::pair< double, P > >::iterator it=Q.begin();
+ it = Q.insert ( it+indMin, p);
+ }
+
+ return Q;
+}
+
+
+const neighb2d& complement_neighborhood(const Neighborhood<neighb2d>& nbh)
+{
+ if(&nbh == &c4())
+ return c8();
+ return c4();
+}
+
+template <typename N>
+ int nb_composant_connexe(p_set< mln_psite(N) > X_full,const Neighborhood<N>& nbh_,const mln_psite(N)& p_ref, bool local)
+{
+ N nbh = exact(nbh_);
+ p_set< mln_psite(N) > X;
+ if(local)
+ {
+ mln_niter(N) n(max_neighborhood(nbh), p_ref);
+
+ for_all(n)
+ {
+ if (X_full.has(n))
+ X.insert(n);
+ }
+ }
+ else
+ {
+ X = X_full;
+ }
+
+ int T;
+ p_set< mln_psite(N) > done;
+ p_set< mln_psite(N) > neighbors;
+ p_set< mln_psite(N) > composant;
+
+ done.insert(p_ref);
+ mln_niter(N) q(nbh, p_ref);
+ for_all(q)
+ {
+ if (X.has(q)&&!done.has(q))
+ {
+ neighbors.insert(q);
+ }
+ }
+// std::cout << "nb_composant_connexe: neighbors " << neighbors.nsites() <<std::endl;
+ if(neighbors.nsites()<=1)
+ {
+ return neighbors.nsites();
+ }
+ else
+ T=0;
+
+ while(neighbors.nsites()!=0)
+ {
+ T++;
+ done.insert(neighbors[0]);
+ mln_niter(N) t(nbh, neighbors[0]);
+ neighbors.remove(neighbors[0]);
+ for_all(t)
+ {
+ if (X.has(t)&&!done.has(t))
+ {
+ composant.insert(t);
+ }
+ }
+
+ while(composant.nsites()!=0)
+ {
+ done.insert(composant[0]);
+ if(neighbors.has(composant[0]))
+ {
+ neighbors.remove(composant[0]);
+ if(neighbors.nsites()==0)
+ return T;
+ }
+
+ mln_niter(N) r(nbh, composant[0]);
+ composant.remove(composant[0]);
+ for_all(r)
+ {
+ if (X.has(r) && !done.has(r))
+ {
+ composant.insert(r);
+ }
+ }
+ }
+ }
+ return T;
+}
+
+template <typename N>
+ bool simple_point(p_set< mln_psite(N) > X,const Neighborhood<N>& nbh, p_set< mln_psite(N) > X_complement, const mln_psite(N)& p_ref, bool local)
+{
+ int nX = nb_composant_connexe(X,exact(nbh),p_ref,local);
+ int nX_complement = nb_composant_connexe(X_complement,complement_neighborhood(exact(nbh)),p_ref,local);
+
+ if((nX_complement == 1)&&(nX == 1))
+ return true;
+ return false;
+}
+
+
+ template <typename N>
+ p_set<mln_psite(N)> euclideanSkeleton(p_set<mln_psite(N)> X, p_set<mln_psite(N)> X_complement, image2d<value::int_u8> dt, p_set<mln_psite(N)>& Y, const Neighborhood<N>& nbh_, bool local)
+ {
+ std::vector< std::pair< double, mln::point2d> > Q;
+ std::vector< std::pair< double, mln::point2d> > R;
+ N nbh = exact(nbh_);
+
+ // fill Q
+ for (uint i = 0; i < X.nsites(); i++)
+ {
+ if (!Y.has(X[i]))
+ {
+ std::pair<double, mln_psite(N)> p(math::sqrt(double(dt(X[i]))),X[i]);
+ Q = insertDicho(Q,p);
+ }
+ }
+
+ // fill R
+ for (uint i = 0; i < X.nsites(); i++)
+ {
+ if (!Y.has(X[i]))
+ {
+ double min = 1023.99;
+ mln_niter(N) r(nbh, X[i]);
+ for_all(r)
+ {
+ if (Y.has(r))
+ {
+ double tmp = distance(r[0], r[1], X[i][0], X[i][1]);
+ double d = math::sqrt(double(dt(r)))+(math::sqrt(double(dt(X[i])))-math::sqrt(double(dt(r))))/tmp;
+ min = math::min(min,d);
+ }
+ }
+ if (min!=1023.99)
+ {
+ std::pair<double, mln_psite(N)> p(min,X[i]);
+ R = insertDicho(R, p);
+ }
+ }
+ }
+
+ while (!Q.empty() || !R.empty())
+ {
+ mln_psite(N) tmp;
+ if (Q[0].first < R[0].first)
+ {
+ tmp = Q[0].second;
+ }
+ else
+ {
+ tmp = R[0].second;
+ }
+
+ Q = remove(Q, tmp);
+ R = remove(R, tmp);
+
+ if (!Y.has(tmp) && X.has(tmp))
+ {
+ if (simple_point(X, nbh, X_complement, tmp, local))
+ {
+ X.remove(tmp);
+ X_complement.insert(tmp);
+ }
+ else
+ {
+ Y.insert(tmp);
+ mln_niter(N) r(nbh, tmp);
+ for_all(r)
+ {
+ if (!Y.has(r) && X.has(r))
+ {
+ double dist = distance(r[0], r[1], tmp[0], tmp[1]);
+ double d = math::sqrt(double(dt(tmp)))+(math::sqrt(double(dt(r)))-math::sqrt(double(dt(tmp))))/dist;
+ std::pair<double, mln_psite(N)> p(d,r);
+ R = insertDicho(R, p);
+ }
+ }
+
+ }
+ }
+
+ }
+ return X;
+ }
+
+
+ p_set<point2d> EP(image2d<value::int_u8> dt, point2d x, std::vector< std::vector<std::pair< int, int> > > lut, const neighb2d& nbh)
+ {
+ p_set<point2d> EP;
+ p_set<point2d> tmp;
+ int w = geom::ncols(dt);
+ int h = geom::nrows(dt);
+
+
+ mln_niter_(neighb2d) r(nbh, x);
+ for_all(r)
+ {
+ if (dt(r) <= dt(x))
+ {
+ for (uint i=0; i<lut[dt(r)].size(); i++)
+ {
+ if ((r[0]+lut[dt(r)][i].first < h) && (r[1]+lut[dt(r)][i].second < w))
+ {
+ if (!dt(r+dpoint2d(lut[dt(r)][i].first, lut[dt(r)][i].second)))
+ EP.insert(r+dpoint2d(lut[dt(r)][i].first, lut[dt(r)][i].second));
+ }
+ if ((r[0]-lut[dt(r)][i].first >= 0) && (r[1]-lut[dt(r)][i].second >= 0))
+ {
+ if (!dt(r+dpoint2d(-lut[dt(r)][i].first, -lut[dt(r)][i].second)))
+ EP.insert(r+dpoint2d(-lut[dt(r)][i].first, -lut[dt(r)][i].second));
+ }
+ if ((r[0]+lut[dt(r)][i].first < h) && (r[1]-lut[dt(r)][i].second >= 0))
+ {
+ if (!dt(r+dpoint2d(lut[dt(r)][i].first, -lut[dt(r)][i].second)))
+ EP.insert(r+dpoint2d(lut[dt(r)][i].first, -lut[dt(r)][i].second));
+ }
+ if ((r[0]-lut[dt(r)][i].first >= 0) && (r[1]+lut[dt(r)][i].second < w))
+ {
+ if (!dt(r+dpoint2d(-lut[dt(r)][i].first, lut[dt(r)][i].second)))
+ EP.insert(r+dpoint2d(-lut[dt(r)][i].first, lut[dt(r)][i].second));
+ }
+ if ((r[0]+lut[dt(r)][i].second < h) && (r[1]+lut[dt(r)][i].first < w))
+ {
+ if (!dt(r+dpoint2d(lut[dt(r)][i].second, lut[dt(r)][i].first)))
+ EP.insert(r+dpoint2d(lut[dt(r)][i].second, lut[dt(r)][i].first));
+ }
+ if ((r[0]-lut[dt(r)][i].second >= 0) && (r[1]-lut[dt(r)][i].first >= 0))
+ {
+ if (!dt(r+dpoint2d(-lut[dt(r)][i].second, -lut[dt(r)][i].first)))
+ EP.insert(r+dpoint2d(-lut[dt(r)][i].second, -lut[dt(r)][i].first));
+ }
+ if ((r[0]+lut[dt(r)][i].second < h) && (r[1]-lut[dt(r)][i].first >= 0))
+ {
+ if (!dt(r+dpoint2d(lut[dt(r)][i].second, -lut[dt(r)][i].first)))
+ EP.insert(r+dpoint2d(lut[dt(r)][i].second, -lut[dt(r)][i].first));
+ }
+ if ((r[0]-lut[dt(r)][i].second >= 0) && (r[1]+lut[dt(r)][i].first < w))
+ {
+ if (!dt(r+dpoint2d(-lut[dt(r)][i].second, lut[dt(r)][i].first)))
+ EP.insert(r+dpoint2d(-lut[dt(r)][i].second, lut[dt(r)][i].first));
+ }
+ }
+ }
+ }
+
+ return EP;
+ }
+
+ std::vector< std::vector<std::pair< int, int> > > Lut2d(int N)
+ {
+ int n = int(sqrt(N))+1;
+ int i=0;
+ std::vector< std::vector<std::pair< int, int> > > lut;
+
+ for(i = 0; i <= N; i++)
+ {
+ std::vector<std::pair< int, int> > vect;
+ lut.push_back(vect);
+ }
+
+ for(int x = 0; x <= n; x++)
+ {
+ for(int y = 0; y <= x; y++)
+ {
+ i=x*x+y*y;
+ if(i<=N)
+ {
+ std::pair<int,int> p(x,y);
+ lut[i].push_back(p);
+ }
+ }
+ }
+
+ return lut;
+}
+
+ image2d<value::int_u8> DiscreteBisector(image2d<value::int_u8> dt, p_set<point2d> Y, const neighb2d& nbh, int N)
+ {
+ int w = geom::ncols(dt);
+ int h = geom::nrows(dt);
+
+ int ux,uy,vx,vy, produit, angle, max;
+ double cos, normu, normv;
+
+ std::vector< std::vector<std::pair< int, int> > > lut;
+ lut = Lut2d(N);
+
+ p_set<point2d> proj;
+
+ image2d<value::int_u8> bisector(h, w);
+ level::fill(bisector, 0);
+
+ for (uint i=0; i<Y.nsites(); i++)
+ {
+ proj = EP(dt, Y[i], lut, nbh);
+
+ int n=proj.nsites();
+
+ if (n>1)
+ {
+ max = 0;
+ for (int y=0; y<n; y++)
+ {
+ for (int z=0; z<y; z++)
+ {
+ ux = proj[y][0]-Y[i][0];
+ uy = proj[y][1]-Y[i][1];
+ vx = proj[z][0]-Y[i][0];
+ vy = proj[z][1]-Y[i][1];
+
+ produit = ux * vx + uy * vy;
+
+ normu = sqrt(ux*ux + uy*uy);
+ normv = sqrt(vx*vx + vy*vy);
+
+ cos = produit/(normu*normv);
+ angle = int(acos(cos)*180.0/3.1415);
+
+ max = math::max(max, angle);
+ }
+ }
+ bisector(Y[i]) = max;
+ }
+
+ }
+
+ return bisector;
+
+ }
+
+
+
+const neighb2d& max_neighborhood(const Neighborhood<neighb2d>& nbh)
+{
+ return c8();
+}
+template <typename N>
+ p_set<mln_psite(N)> ultimateSkeleton(p_set<mln_psite(N)> X, p_set<mln_psite(N)> X_complement, image2d<value::int_u8> dt, p_set<mln_psite(N)> Y, const Neighborhood<N>& nbh_, bool local)
+{
+ std::vector< std::pair< double, mln::point2d> > Q;
+
+ N nbh = exact(nbh_);
+ // fill Q
+ for(uint i = 0; i < X.nsites(); i++)
+ {
+ if (!Y.has(X[i]))
+ {
+ std::pair<double, mln_psite(N)> p(dt(X[i]),X[i]);
+ Q = insertDicho(Q,p);
+ }
+ }
+
+
+ while(!Q.empty())
+ {
+ mln_psite(N) tmp = Q[0].second;
+
+ Q = remove(Q, tmp);
+
+ if(simple_point(X, nbh, X_complement, tmp, local))
+ {
+ X.remove(tmp);
+ X_complement.insert(tmp);
+ mln_niter(N) r(nbh, tmp);
+ for_all(r)
+ {
+ if(!Y.has(r) && X.has(r))
+ {
+ std::pair<double, mln_psite(N)> p(dt(r),r);
+ Q = insertDicho(Q, p);
+ }
+ }
+ }
+
+ }
+ return X;
+}
+
+ image2d<value::int_u8> intImage(image2d<bool> pic)
+{
+ int w = geom::ncols(pic);
+ int h = geom::nrows(pic);
+
+ image2d<value::int_u8> out(h,w);
+ for(int i=0; i<w; i++)
+ for(int j=0; j<h; j++)
+ {
+ if(pic.at(j,i))
+ out.at(j,i) = 1;
+ else
+ out.at(j,i) = 0;
+ }
+ return out;
+}
+ image2d<bool> filteredSkeleton(image2d<bool> pic, const neighb2d& nbh, uint r, uint alpha, bool local)
+ {
+ using value::int_u8;
+
+ typedef image2d<bool> I;
+ typedef p_set<point2d> S;
+
+ image2d<value::int_u8> pic1 = intImage(pic);
+ image2d<value::int_u8> dt = sedt(pic1);
+
+ mln::io::pgm::save(dt, "dt.pgm");
+
+ int w = geom::ncols(pic);
+ int h = geom::nrows(pic);
+ int l= math::min(w, h);
+ uint rmax = getRMax(dt);
+ uint rknown = 0;
+ p_set<point2d> X,Y,Z;
+ p_set<point2d> X_complement, Z_complement;
+
+ image2d<value::int_u8> DTg(l,l,0);
+ std::vector< std::vector<int> > Mgl;
+ std::vector< std::vector<int> > Lut;
+
+ Mgl = CompLutMask (DTg,Mgl,Lut,l,0,rmax);
+
+ rknown =rmax;
+
+ mln_fwd_piter_(image2d<bool>) p(pic.domain());
+
+ for_all(p)
+ {
+ if (pic(p)==1)
+ {
+ X.insert(p);
+ }
+ else
+ {
+ X_complement.insert(p);
+ }
+ }
+ std::cout << " medial axis " << std::endl;
+ pic = MA(pic, Mgl, dt, Lut);
+
+ mln::io::pbm::save(pic, "ma.pbm");
+
+ for_all(p)
+ {
+ if (pic(p)==1)
+ {
+ Y.insert(p);
+ }
+ }
+
+ std::cout << " euclidean skeleton " << std::endl;
+ Z = euclideanSkeleton(X, X_complement, dt, Y, nbh, local);
+
+ sub_image<I, S> es = pic | Z;
+ I es1(pic.domain());
+ level::fill(es1, false);
+
+ level::paste(es, es1);
+
+ mln::io::pbm::save(es1, "euclidean.pbm");
+
+ for_all(p)
+ {
+ if (!Z.has(p))
+ {
+ Z_complement.insert(p);
+ }
+ }
+ std::cout << " discrete bisector " << std::endl;
+ pic1 = DiscreteBisector(dt, Y, nbh, rmax);
+
+
+ mln::io::pgm::save(pic1, "bisector.pgm");
+
+ uint cpt=0;
+ while (cpt!=Y.nsites())
+ {
+ if (dt(Y[cpt])>=r && pic1(Y[cpt])>=alpha)
+ {
+ cpt++;
+ }
+ else
+ {
+ Y.remove(Y[cpt]);
+ }
+ }
+
+
+ sub_image<I, S> skel = pic | Y;
+ I test(pic.domain());
+ level::fill(test, false);
+
+ level::paste(skel, test);
+
+ mln::io::pbm::save(test, "Y.pbm");
+
+ std::cout << " ultimate skeleton " << std::endl;
+ Z = ultimateSkeleton(Z, Z_complement, dt, Y, nbh, local);
+
+
+
+ sub_image<I, S> skeleton = pic | Z;
+ I output(pic.domain());
+ level::fill(output, false);
+
+ level::paste(skeleton, output);
+
+ return output;
+ }
+
+} // End of namespace mln
+#endif // ! SKELETON_HH
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/simple_point.hh
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/simple_point.hh (revision 2749)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/simple_point.hh (revision 2750)
@@ -139,7 +139,7 @@
for_all(n)
{
res = (res << 1);
- if (ima(n) == object)
+ if (ima.domain().has(n) && ima(n) == object)
res = res | 1;
}
@@ -152,18 +152,43 @@
}
}
- bool is_curve_extremum(const image2d<bool>& ima, unsigned nbh, const point2d& p)
+ bool is_curve_extremum(const image2d<bool>& ima, unsigned nbh_i, const point2d& p_, unsigned deep)
{
+// return false;
unsigned cpt = 0;
- mln_bkd_niter_(neighb2d) n(c8() , p);
+ mln_site_(image2d<bool>) next = p_;
+ mln_site_(image2d<bool>) p = next;
+ mln_niter_(neighb2d) n(int_to_neighb(nbh_i) , p);
+ p = next;
for_all(n)
{
- if (ima(n) == true)
+ if (ima.domain().has(n) && ima(n) == true)
+ {
+ next = n;
cpt++;
}
+ }
+ if (cpt != 1)
+ return false;
+
+ for (unsigned i = 0; i < deep - 1; i++)
+ {
+ cpt = 0;
+ p = next;
+ for_all(n)
+ {
+ if (ima.domain().has(n) && ima(n) == true)
+ {
+ next = n;
+ cpt++;
+ }
+ }
+ if (cpt != 2)
+ return false;
+ }
- return cpt == 1;
+ return true;
}
bool is_simple_point2d(const image2d<bool>& ima, unsigned nbh, const point2d& p)
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.hh
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.hh (revision 2749)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.hh (revision 2750)
@@ -24,588 +24,159 @@
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SKELETON_HH
-# define SKELETON_HH
-#include <mln/core/image/image2d.hh>
-#include <mln/core/alias/neighb2d.hh>
-#include <sandbox/aroumougame/skeleton/sedt.hh>
-
-#include <mln/core/site_set/p_set.hh>
-#include <mln/math/sqrt.hh>
-
-namespace mln
-{
-
-
-template <typename P>
- std::vector< std::pair< double, P > > remove(std::vector< std::pair< double, P > > Q, P p)
-{
- typename std::vector<std::pair< double, P > >::iterator it;
-
- for(it = Q.begin(); it!=Q.end(); it++)
- {
- if((*it).second==p)
- {
- it = Q.erase(it);
- break;
- }
- }
- return Q;
-}
-template <typename N>
- double distance(N a, N b, N c, N d)
-{
- double dist = sqrt((a-c)*(a-c)+(b-d)*(b-d));
- return dist;
-}
-template <typename P>
- std::vector< std::pair< double, P > > insertDicho(std::vector< std::pair< double, P > > Q, std::pair< double, P> p)
-{
- int indMin, indMax, indMid;
-
- indMin = 0;
- indMax = Q.size();
-
- if(indMax==0 || Q[indMax-1].first <= p.first)
- Q.push_back(p);
- else
- {
- while(indMax > indMin)
- {
- indMid = int(indMin + (indMax-indMin)/2);
- if(Q[indMid].first < p.first)
- {
- indMin = indMid+1;
- if(Q[indMin].first > p.first)
- {
- indMax = indMid;
- }
- }
- else
- {
- indMax = indMid-1;
- if(Q[indMax].first < p.first)
- {
- indMin = indMid;
- }
- }
- }
-
- typename std::vector< std::pair< double, P > >::iterator it=Q.begin();
- it = Q.insert ( it+indMin, p);
- }
-
- return Q;
-}
-
-
-const neighb2d& complement_neighborhood(const Neighborhood<neighb2d>& nbh)
-{
- if(&nbh == &c4())
- return c8();
- return c4();
-}
-
-template <typename N>
- int nb_composant_connexe(p_set< mln_psite(N) > X_full,const Neighborhood<N>& nbh_,const mln_psite(N)& p_ref, bool local)
-{
- N nbh = exact(nbh_);
- p_set< mln_psite(N) > X;
- if(local)
- {
- mln_niter(N) n(max_neighborhood(nbh), p_ref);
-
- for_all(n)
- {
- if (X_full.has(n))
- X.insert(n);
- }
- }
- else
- {
- X = X_full;
- }
-
- int T;
- p_set< mln_psite(N) > done;
- p_set< mln_psite(N) > neighbors;
- p_set< mln_psite(N) > composant;
-
- done.insert(p_ref);
- mln_niter(N) q(nbh, p_ref);
- for_all(q)
- {
- if (X.has(q)&&!done.has(q))
- {
- neighbors.insert(q);
- }
- }
-// std::cout << "nb_composant_connexe: neighbors " << neighbors.nsites() <<std::endl;
- if(neighbors.nsites()<=1)
- {
- return neighbors.nsites();
- }
- else
- T=0;
-
- while(neighbors.nsites()!=0)
- {
- T++;
- done.insert(neighbors[0]);
- mln_niter(N) t(nbh, neighbors[0]);
- neighbors.remove(neighbors[0]);
- for_all(t)
- {
- if (X.has(t)&&!done.has(t))
- {
- composant.insert(t);
- }
- }
+#ifndef MLN_SKELETON_HH
+# define MLN_SKELETON_HH
- while(composant.nsites()!=0)
- {
- done.insert(composant[0]);
- if(neighbors.has(composant[0]))
- {
- neighbors.remove(composant[0]);
- if(neighbors.nsites()==0)
- return T;
- }
+# include <iomanip>
+# include <iostream>
+# include <sstream>
- mln_niter(N) r(nbh, composant[0]);
- composant.remove(composant[0]);
- for_all(r)
- {
- if (X.has(r) && !done.has(r))
- {
- composant.insert(r);
- }
- }
- }
- }
- return T;
-}
-
-template <typename N>
- bool simple_point(p_set< mln_psite(N) > X,const Neighborhood<N>& nbh, p_set< mln_psite(N) > X_complement, const mln_psite(N)& p_ref, bool local)
-{
- int nX = nb_composant_connexe(X,exact(nbh),p_ref,local);
- int nX_complement = nb_composant_connexe(X_complement,complement_neighborhood(exact(nbh)),p_ref,local);
-
- if((nX_complement == 1)&&(nX == 1))
- return true;
- return false;
-}
-
-
- template <typename N>
- p_set<mln_psite(N)> euclideanSkeleton(p_set<mln_psite(N)> X, p_set<mln_psite(N)> X_complement, image2d<value::int_u8> dt, p_set<mln_psite(N)>& Y, const Neighborhood<N>& nbh_, bool local)
- {
- std::vector< std::pair< double, mln::point2d> > Q;
- std::vector< std::pair< double, mln::point2d> > R;
- N nbh = exact(nbh_);
-
- // fill Q
- for (uint i = 0; i < X.nsites(); i++)
- {
- if (!Y.has(X[i]))
- {
- std::pair<double, mln_psite(N)> p(math::sqrt(double(dt(X[i]))),X[i]);
- Q = insertDicho(Q,p);
- }
- }
-
- // fill R
- for (uint i = 0; i < X.nsites(); i++)
- {
- if (!Y.has(X[i]))
- {
- double min = 1023.99;
- mln_niter(N) r(nbh, X[i]);
- for_all(r)
- {
- if (Y.has(r))
- {
- double tmp = distance(r[0], r[1], X[i][0], X[i][1]);
- double d = math::sqrt(double(dt(r)))+(math::sqrt(double(dt(X[i])))-math::sqrt(double(dt(r))))/tmp;
- min = math::min(min,d);
- }
- }
- if (min!=1023.99)
- {
- std::pair<double, mln_psite(N)> p(min,X[i]);
- R = insertDicho(R, p);
- }
- }
- }
-
- while (!Q.empty() || !R.empty())
- {
- mln_psite(N) tmp;
- if (Q[0].first < R[0].first)
- {
- tmp = Q[0].second;
- }
- else
- {
- tmp = R[0].second;
- }
-
- Q = remove(Q, tmp);
- R = remove(R, tmp);
-
- if (!Y.has(tmp) && X.has(tmp))
- {
- if (simple_point(X, nbh, X_complement, tmp, local))
- {
- X.remove(tmp);
- X_complement.insert(tmp);
- }
- else
- {
- Y.insert(tmp);
- mln_niter(N) r(nbh, tmp);
- for_all(r)
- {
- if (!Y.has(r) && X.has(r))
- {
- double dist = distance(r[0], r[1], tmp[0], tmp[1]);
- double d = math::sqrt(double(dt(tmp)))+(math::sqrt(double(dt(r)))-math::sqrt(double(dt(tmp))))/dist;
- std::pair<double, mln_psite(N)> p(d,r);
- R = insertDicho(R, p);
- }
- }
-
- }
- }
+# include <mln/core/var.hh>
- }
- return X;
- }
-
-
- p_set<point2d> EP(image2d<value::int_u8> dt, point2d x, std::vector< std::vector<std::pair< int, int> > > lut, const neighb2d& nbh)
- {
- p_set<point2d> EP;
- p_set<point2d> tmp;
- int w = geom::ncols(dt);
- int h = geom::nrows(dt);
-
-
- mln_niter_(neighb2d) r(nbh, x);
- for_all(r)
- {
- if (dt(r) <= dt(x))
- {
- for (uint i=0; i<lut[dt(r)].size(); i++)
- {
- if ((r[0]+lut[dt(r)][i].first < h) && (r[1]+lut[dt(r)][i].second < w))
- {
- if (!dt(r+dpoint2d(lut[dt(r)][i].first, lut[dt(r)][i].second)))
- EP.insert(r+dpoint2d(lut[dt(r)][i].first, lut[dt(r)][i].second));
- }
- if ((r[0]-lut[dt(r)][i].first >= 0) && (r[1]-lut[dt(r)][i].second >= 0))
- {
- if (!dt(r+dpoint2d(-lut[dt(r)][i].first, -lut[dt(r)][i].second)))
- EP.insert(r+dpoint2d(-lut[dt(r)][i].first, -lut[dt(r)][i].second));
- }
- if ((r[0]+lut[dt(r)][i].first < h) && (r[1]-lut[dt(r)][i].second >= 0))
- {
- if (!dt(r+dpoint2d(lut[dt(r)][i].first, -lut[dt(r)][i].second)))
- EP.insert(r+dpoint2d(lut[dt(r)][i].first, -lut[dt(r)][i].second));
- }
- if ((r[0]-lut[dt(r)][i].first >= 0) && (r[1]+lut[dt(r)][i].second < w))
- {
- if (!dt(r+dpoint2d(-lut[dt(r)][i].first, lut[dt(r)][i].second)))
- EP.insert(r+dpoint2d(-lut[dt(r)][i].first, lut[dt(r)][i].second));
- }
- if ((r[0]+lut[dt(r)][i].second < h) && (r[1]+lut[dt(r)][i].first < w))
- {
- if (!dt(r+dpoint2d(lut[dt(r)][i].second, lut[dt(r)][i].first)))
- EP.insert(r+dpoint2d(lut[dt(r)][i].second, lut[dt(r)][i].first));
- }
- if ((r[0]-lut[dt(r)][i].second >= 0) && (r[1]-lut[dt(r)][i].first >= 0))
- {
- if (!dt(r+dpoint2d(-lut[dt(r)][i].second, -lut[dt(r)][i].first)))
- EP.insert(r+dpoint2d(-lut[dt(r)][i].second, -lut[dt(r)][i].first));
- }
- if ((r[0]+lut[dt(r)][i].second < h) && (r[1]-lut[dt(r)][i].first >= 0))
- {
- if (!dt(r+dpoint2d(lut[dt(r)][i].second, -lut[dt(r)][i].first)))
- EP.insert(r+dpoint2d(lut[dt(r)][i].second, -lut[dt(r)][i].first));
- }
- if ((r[0]-lut[dt(r)][i].second >= 0) && (r[1]+lut[dt(r)][i].first < w))
- {
- if (!dt(r+dpoint2d(-lut[dt(r)][i].second, lut[dt(r)][i].first)))
- EP.insert(r+dpoint2d(-lut[dt(r)][i].second, lut[dt(r)][i].first));
- }
- }
- }
- }
-
- return EP;
- }
-
- std::vector< std::vector<std::pair< int, int> > > Lut2d(int N)
- {
- int n = int(sqrt(N))+1;
- int i=0;
- std::vector< std::vector<std::pair< int, int> > > lut;
+# include <mln/core/image/image2d.hh>
+# include <mln/core/image/cast_image.hh>
+# include <mln/core/alias/neighb2d.hh>
+# include <mln/core/site_set/p_queue_fast.hh>
+# include <mln/core/site_set/p_priority.hh>
- for(i = 0; i <= N; i++)
- {
- std::vector<std::pair< int, int> > vect;
- lut.push_back(vect);
- }
+# include <mln/value/int_u8.hh>
+# include <mln/arith/revert.hh>
+# include <mln/transform/distance.hh>
- for(int x = 0; x <= n; x++)
- {
- for(int y = 0; y <= x; y++)
- {
- i=x*x+y*y;
- if(i<=N)
- {
- std::pair<int,int> p(x,y);
- lut[i].push_back(p);
- }
- }
- }
+# include <mln/make/w_window2d_int.hh>
- return lut;
-}
+# include <mln/level/fill.hh>
- image2d<value::int_u8> DiscreteBisector(image2d<value::int_u8> dt, p_set<point2d> Y, const neighb2d& nbh, int N)
- {
- int w = geom::ncols(dt);
- int h = geom::nrows(dt);
+# include <mln/debug/println.hh>
- int ux,uy,vx,vy, produit, angle, max;
- double cos, normu, normv;
+# include <mln/logical/not.hh>
- std::vector< std::vector<std::pair< int, int> > > lut;
- lut = Lut2d(N);
+# include "simple_point.hh"
- p_set<point2d> proj;
+#include <mln/make/w_window2d_int.hh>
- image2d<value::int_u8> bisector(h, w);
- level::fill(bisector, 0);
+# include <mln/io/pgm/save.hh>
+# include <mln/io/pbm/save.hh>
- for (uint i=0; i<Y.nsites(); i++)
+namespace mln
{
- proj = EP(dt, Y[i], lut, nbh);
-
- int n=proj.nsites();
- if (n>1)
+ template <typename V>
+ void save_state(const image2d<V>& ima)
{
- max = 0;
- for (int y=0; y<n; y++)
- {
- for (int z=0; z<y; z++)
- {
- ux = proj[y][0]-Y[i][0];
- uy = proj[y][1]-Y[i][1];
- vx = proj[z][0]-Y[i][0];
- vy = proj[z][1]-Y[i][1];
-
- produit = ux * vx + uy * vy;
+ static int id = 0;
+ std::stringstream filename;
- normu = sqrt(ux*ux + uy*uy);
- normv = sqrt(vx*vx + vy*vy);
+ std::cout << id << std::endl;
+ filename << "skel_trace_" << std::setw(5) << std::setfill('0')
+ << std::right << id++ << ".ppm";
- cos = produit/(normu*normv);
- angle = int(acos(cos)*180.0/3.1415);
-
- max = math::max(max, angle);
- }
- }
- bisector(Y[i]) = max;
+ io::pbm::save(ima, filename.str());
}
- }
-
- return bisector;
-
- }
-
-
-
-const neighb2d& max_neighborhood(const Neighborhood<neighb2d>& nbh)
-{
- return c8();
-}
-template <typename N>
- p_set<mln_psite(N)> ultimateSkeleton(p_set<mln_psite(N)> X, p_set<mln_psite(N)> X_complement, image2d<value::int_u8> dt, p_set<mln_psite(N)> Y, const Neighborhood<N>& nbh_, bool local)
-{
- std::vector< std::pair< double, mln::point2d> > Q;
-
- N nbh = exact(nbh_);
- // fill Q
- for(uint i = 0; i < X.nsites(); i++)
+ image2d<bool> crest(const image2d<bool>& input,
+ const image2d<value::int_u8>& dist_map,
+ const neighb2d& nbh)
{
- if (!Y.has(X[i]))
- {
- std::pair<double, mln_psite(N)> p(dt(X[i]),X[i]);
- Q = insertDicho(Q,p);
- }
- }
-
+ image2d<bool> is_crest;
+ initialize(is_crest, input);
+ level::fill(is_crest, false);
- while(!Q.empty())
+ mln_piter_(image2d<value::int_u8>) p(dist_map.domain());
+ mln_niter_(neighb2d) n(nbh, p);
+ for_all(p)
{
- mln_psite(N) tmp = Q[0].second;
-
- Q = remove(Q, tmp);
+ if (!input(p) || dist_map(p) < 20)
+ continue;
- if(simple_point(X, nbh, X_complement, tmp, local))
- {
- X.remove(tmp);
- X_complement.insert(tmp);
- mln_niter(N) r(nbh, tmp);
- for_all(r)
- {
- if(!Y.has(r) && X.has(r))
+ unsigned nb_eq = 0;
+ unsigned nb_gt = 0;
+ for_all(n)
+ if (input.domain().has(n))
{
- std::pair<double, mln_psite(N)> p(dt(r),r);
- Q = insertDicho(Q, p);
- }
- }
+ if (dist_map(n) == dist_map(p))
+ nb_eq++;
+ else if (dist_map(n) > dist_map(p))
+ nb_gt++;
}
+ if ((nb_gt == 1 && nb_eq == 0) ||
+ (nb_gt == 0))
+ is_crest(p) = true;
}
- return X;
+ return is_crest;
}
- image2d<value::int_u8> intImage(image2d<bool> pic)
-{
- int w = geom::ncols(pic);
- int h = geom::nrows(pic);
-
- image2d<value::int_u8> out(h,w);
- for(int i=0; i<w; i++)
- for(int j=0; j<h; j++)
- {
- if(pic.at(j,i))
- out.at(j,i) = 1;
- else
- out.at(j,i) = 0;
- }
- return out;
-}
- image2d<bool> filteredSkeleton(image2d<bool> pic, const neighb2d& nbh, uint r, uint alpha, bool local)
+ image2d<bool>
+ skeleton(const image2d<bool>& input, unsigned nbh_i)
{
- using value::int_u8;
+ mln_assertion(nbh_i == 4 || nbh_i == 8);
- typedef image2d<bool> I;
- typedef p_set<point2d> S;
+ neighb2d nbh = int_to_neighb(nbh_i);
+ image2d<bool> output;
+ initialize(output, input);
- image2d<value::int_u8> pic1 = intImage(pic);
- image2d<value::int_u8> dt = sedt(pic1);
- mln::io::pgm::save(dt, "dt.pgm");
+ int vals[] = { 0, 9, 0, 9, 0,
+ 9, 6, 4, 6, 9,
+ 0, 4, 0, 4, 0, // Values of distaces.
+ 9, 6, 4, 6, 9,
+ 0, 9, 0, 9, 0 };
- int w = geom::ncols(pic);
- int h = geom::nrows(pic);
- int l= math::min(w, h);
- uint rmax = getRMax(dt);
- uint rknown = 0;
- p_set<point2d> X,Y,Z;
- p_set<point2d> X_complement, Z_complement;
+ image2d<value::int_u8> dist_map_n = transform::distance(value::int_u8(), logical::not_(input), nbh, make::w_window2d_int(vals));
+ image2d<value::int_u8> dist_map = arith::revert(dist_map_n);
- image2d<value::int_u8> DTg(l,l,0);
- std::vector< std::vector<int> > Mgl;
- std::vector< std::vector<int> > Lut;
+ io::pgm::save(dist_map, "distance.pgm");
+ io::pgm::save(dist_map_n, "distance_n.pgm");
- Mgl = CompLutMask (DTg,Mgl,Lut,l,0,rmax);
+ // Make K
+ image2d<bool> K = crest(input, dist_map_n, nbh);
- rknown =rmax;
+ io::pbm::save(K, "K.pbm");
- mln_fwd_piter_(image2d<bool>) p(pic.domain());
+ typedef mln_site_(image2d<bool>) P;
+ p_priority<value::int_u8, p_queue_fast<P> > q;
- for_all(p)
- {
- if (pic(p)==1)
+ // Initialization.
{
- X.insert(p);
- }
- else
- {
- X_complement.insert(p);
- }
- }
- std::cout << " medial axis " << std::endl;
- pic = MA(pic, Mgl, dt, Lut);
-
- mln::io::pbm::save(pic, "ma.pbm");
+ p_priority<value::int_u8, p_queue_fast<P> > q_tmp;
+ level::fill(output, input);
+ mln_piter_(image2d<bool>) p(input.domain());
for_all(p)
- {
- if (pic(p)==1)
- {
- Y.insert(p);
+ if (!input(p) &&
+ is_simple_point2d(input, nbh_i, p)) // p is a simple point of background
+ q.push(dist_map(p), p);
}
- }
-
- std::cout << " euclidean skeleton " << std::endl;
- Z = euclideanSkeleton(X, X_complement, dt, Y, nbh, local);
-
- sub_image<I, S> es = pic | Z;
- I es1(pic.domain());
- level::fill(es1, false);
- level::paste(es, es1);
-
- mln::io::pbm::save(es1, "euclidean.pbm");
-
- for_all(p)
+ // Propagation.
{
- if (!Z.has(p))
+ P p;
+ mln_niter_(neighb2d) n(nbh, p);
+ while (! q.is_empty())
{
- Z_complement.insert(p);
- }
- }
- std::cout << " discrete bisector " << std::endl;
- pic1 = DiscreteBisector(dt, Y, nbh, rmax);
-
-
- mln::io::pgm::save(pic1, "bisector.pgm");
+ p = q.pop_front();
- uint cpt=0;
- while (cpt!=Y.nsites())
- {
- if (dt(Y[cpt])>=r && pic1(Y[cpt])>=alpha)
- {
- cpt++;
+ for_all(n)
+ if (output.domain().has(n) &&
+ output(n) &&
+ K(n) == false &&
+ is_simple_point2d(output, nbh_i, n)
+ // && // n is simple
+ // !is_curve_extremum(output, nbh_i, n, 1)
+ )
+ {
+ output(n) = false; // Remove n from object
+ // save_state(output);
+ q.push(dist_map(n), n);
}
- else
- {
- Y.remove(Y[cpt]);
}
}
-
- sub_image<I, S> skel = pic | Y;
- I test(pic.domain());
- level::fill(test, false);
-
- level::paste(skel, test);
-
- mln::io::pbm::save(test, "Y.pbm");
-
- std::cout << " ultimate skeleton " << std::endl;
- Z = ultimateSkeleton(Z, Z_complement, dt, Y, nbh, local);
-
-
-
- sub_image<I, S> skeleton = pic | Z;
- I output(pic.domain());
- level::fill(output, false);
-
- level::paste(skeleton, output);
-
return output;
}
-} // End of namespace mln
-#endif // ! SKELETON_HH
+} // end of namespace mln
+
+#endif
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/check_simple_point.cc
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/check_simple_point.cc (revision 0)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/check_simple_point.cc (revision 2750)
@@ -0,0 +1,61 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/labeling/blobs.hh>
+#include <mln/level/fill.hh>
+#include <mln/debug/println.hh>
+#include "simple_point.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using namespace mln::value;
+
+ typedef image2d<bool> I;
+ image2d<bool> ima(3,3);
+ point2d p(1,1);
+
+ std::cout << "----- Object in C8 ------" << std::endl;
+
+ for (unsigned i = 0; i < 256; i++)
+ {
+ level::fill(ima, false);
+ int_u8 tmp = i;
+
+ mln_niter_(neighb2d) n(c8() , p);
+ for_all(n)
+ {
+ if (tmp % 2)
+ ima(n) = true;
+ tmp = tmp >> 1;
+ }
+
+ unsigned x;
+ labeling::blobs(ima, c8(), x);
+
+ mln_assertion(nb_connexity2d(ima, 8, p, true) == x);
+ }
+
+ std::cout << "----- Object in C4 ------" << std::endl;
+
+ for (unsigned i = 0; i < 256; i++)
+ {
+ level::fill(ima, false);
+ int_u8 tmp = i;
+
+ mln_niter_(neighb2d) n(c8() , p);
+ for_all(n)
+ {
+ if (tmp % 2)
+ ima(n) = true;
+ tmp = tmp >> 1;
+ }
+
+
+ unsigned x;
+ labeling::blobs(ima, c4(), x);
+
+ mln_assertion(nb_connexity2d(ima, 4, p, true) == x);
+ }
+}
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.old.cc
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.old.cc (revision 0)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/skeleton.old.cc (revision 2750)
@@ -0,0 +1,30 @@
+
+#include <mln/core/alias/point2d.hh>
+#include "skeleton.hh"
+#include <mln/level/paste.hh>
+#include <mln/level/fill.hh>
+#include <mln/core/image/sub_image.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/io/pbm/save.hh>
+#include <mln/io/pbm/load.hh>
+
+
+int main(int argc, char* argv[])
+{
+ if(argc!=5)
+ {
+ std::cout << "arguments: filename voisinage R alpha" << std::endl;
+ exit(1);
+ }
+ image2d<bool> output;
+ std::string filename = argv[1];
+ int r = atoi(argv[3]);
+ int alpha = atoi(argv[4]);
+
+ image2d<bool> pic = io::pbm::load(filename);
+ if(atoi(argv[2])==4)
+ output = filteredSkeleton( pic, c4(), r, alpha, true);
+ else
+ output = filteredSkeleton( pic, c8(), r, alpha, true);
+ mln::io::pbm::save(output, "FS-"+std::string(argv[2])+"_"+std::string(argv[3])+"_"+std::string(argv[4])+"_"+filename);
+}
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/check.sh
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/check.sh (revision 2749)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/check.sh (revision 2750)
@@ -22,7 +22,6 @@
d_without=`diff ./tmp/without tmp/ref | diffstat | grep insert | sed -r 's/.*, ([0-9]+) insertion.*/\1/g'`
echo "$(($d_without * 100 / $total))% missmatch without preprocessing"
- ./ocr_with_preprocess $i tmp/`basename $i` | sed -e 's/\(.\)/\1\n/g' > tmp/with
d_with=`diff ./tmp/with tmp/ref | diffstat | grep insert | sed -r 's/.*, ([0-9]+) insertion.*/\1/g'`
echo "$(($d_with * 100 / $total))% missmatch with preprocessing"
echo ""
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/simple_point.cc
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/simple_point.cc (revision 2749)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/simple_point.cc (revision 2750)
@@ -32,7 +32,7 @@
mln_piter_(I) p(input.domain());
for_all(p)
- if (input(p) && simple_point2d(input, 8, p))
+ if (input(p) && simple_point2d(input, 4, p))
output(p) = true;
io::pbm::save(output, argv[2]);
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/ocr_with_preprocess.cc
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/ocr_with_preprocess.cc (revision 2749)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/ocr_with_preprocess.cc (revision 2750)
@@ -38,23 +38,28 @@
#include "resize.hh"
#include "enlarge.hh"
#include "skeleton.hh"
+
#include <mln/linear/gaussian.hh>
#include <mln/trace/all.hh>
-#include <mln/io/pgm/load.hh>
-#include <mln/io/pgm/save.hh>
-#include <mln/io/pbm/load.hh>
-#include <mln/io/pbm/save.hh>
-#include <mln/core/alias/w_window2d_float.hh>
+
+#include <mln/fun/p2v/ternary.hh>
+#include <mln/pw/image.hh>
#include <mln/debug/println.hh>
-#include <mln/geom/chamfer.hh>
-#include <mln/make/win_chamfer.hh>
#include <mln/labeling/regional_maxima.hh>
#include <mln/morpho/dilation.hh>
+#include <mln/win/octagon2d.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pbm/save.hh>
+#include <mln/logical/not.hh>
#include <tesseract/baseapi.h>
+
// _COMPILATION_
// g++ -DNDEBUG -O3 -I../../.. ocr.cc -L/usr/lib -ltesseract_full -lpthread
@@ -93,38 +98,69 @@
io::pbm::load(input, argv[1]);
// Resize
- image2d<int_u8> output = enlarge(input, 1);
+ std::cerr << "Enlarge the image" << std::endl;
+ image2d<int_u8> enlarged = enlarge(logical::not_(input), 2);
+ //image2d<bool> enlarged = geom::resize(logical::not_(input), 4);
+ io::pgm::save(enlarged, "1_enlage.pgm");
- // TODO CLEANUP
-#if 1
// Blur.
- output = linear::gaussian(output, 1);
-#endif
+ std::cerr << "Blur the enlarged image" << std::endl;
+// image2d<int_u8> blur = linear::gaussian(fun::p2v::ternary(pw::value(enlarged), pw::cst(int_u8(255)), pw::cst(int_u8(0))) | enlarged.domain(),
+// 4);
+ image2d<int_u8> blur = linear::gaussian(enlarged, 1);
+
+ io::pgm::save(blur, "2_gaussian.pgm");
+
+ // Crest.
+// image2d<bool> c = crest(enlarged, blur, c4());
+// io::pbm::save(c, "3_crest.pbm");
+
+
-#if 1
// Threshold
- mln_piter_(image2d<unsigned>) p(output.domain());
- for_all(p)
+ image2d<bool> binary;
{
- output(p) = output(p) > 150 ? 255 : 0;
- }
-#endif
+ std::cerr << "Threshold the blur image" << std::endl;
+
+// // Compute the histogram.
+// histo::data<int_u8> h = histo::compute(blur);
+// image1d<std::size_t> h_ima = convert::to_image(h);
-#if 0
- // Compute chamfer distance map.
- const w_window2d_int& w_win = make::mk_chamfer_3x3_int<8, 0> ();
- image2d<unsigned> out = geom::chamfer(output, w_win, 255);
+// // Blur the histogram.
+// h_ima = linear::gaussian(h_ima, 4);
+// // Get the maxima.
+// unsigned n;
+// image1d<std::size_t> maxs = regional_maxima(h_ima, c2(), n);
+// mln_piter()
+
+
+ initialize(binary, blur);
+ mln_piter_(image2d<int_u8>) p(blur.domain());
for_all(p)
- {
- out(p) = out(p) > 10 ? 255 : 0;
- }
-#endif
+ binary(p) = blur(p) > 100;
- io::pgm::save(cast_image<int_u8>(output), argv[2]);
+ io::pbm::save(binary, "3_threshold.pbm");
+ }
- std::cout << "> with preprocessing." << std::endl;
- char* s = tesseract("fra", output);
+ // Skeleton
+ std::cerr << "Compute the skeleton" << std::endl;
+ image2d<bool> skel = skeleton(binary, 4);
+ io::pbm::save(skel, "4_skeleton.pbm");
+
+ // Dilation
+ std::cerr << "Dilate the skeleton" << std::endl;
+ win::octagon2d oct(7);
+ for (unsigned i = 0; i < 1; i++)
+ skel = morpho::dilation(skel, oct);
+
+ io::pbm::save(skel, "5_dilation.pbm");
+
+ io::pbm::save(skel, argv[2]);
+
+ std::cerr << "Text recognition" << std::endl;
+ char* s = tesseract("fra", clone(logical::not_(skel)));
+ std::cerr << "Tesseract result:"<< std::endl;
std::cout << s;
free(s);
}
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/enlarge.hh
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/enlarge.hh (revision 2749)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/enlarge.hh (revision 2750)
@@ -1,10 +1,16 @@
-#ifndef ENLARGE_HH
-# define ENLARGE_HH
-
# include <iostream>
# include <mln/core/image/image2d.hh>
+# include <mln/core/routine/initialize.hh>
+
# include <mln/value/int_u8.hh>
+# include <mln/fun/p2v/ternary.hh>
+
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
+# include <mln/pw/value.hh>
+
+# include <mln/core/routine/clone.hh>
float val(bool b) { return b ? 1 : 0; }
@@ -14,11 +20,12 @@
return 255.f * value;
}
+namespace mln
+{
-mln::image2d<mln::value::int_u8>
-enlargex2(mln::image2d<bool> input)
+ image2d<value::int_u8>
+ enlargex2(const image2d<bool>& input)
{
- using namespace mln;
using value::int_u8;
unsigned nrows, ncols;
@@ -91,31 +98,104 @@
}
-// enlarge 2^n times
-mln::image2d<mln::value::int_u8>
-enlarge(mln::image2d<bool> input, unsigned int n)
+
+ image2d<value::int_u8>
+ enlargex2(const image2d<value::int_u8>& input)
{
- using namespace mln;
using value::int_u8;
- image2d<int_u8> output;
+ unsigned nrows, ncols;
+
+ nrows = input.nrows();
+ ncols = input.ncols();
+
+ image2d<int_u8> output(2 * nrows, 2 * ncols);
+ unsigned value;
+
+ // row 0
+
+ output.at(0, 0) = (input.at(0, 0));
+
+ for (int col = 2; col < output.ncols(); col += 2)
+ {
+ value = (input.at(0, col / 2));
+ value += (input.at(0, col / 2 - 1));
+ output.at(0, col) = (value / 2);
+ }
+
+ for (int col = 1; col < output.ncols(); col += 2)
+ output.at(0, col) = (input.at(0, col / 2));
+
+ // col 0
+
+ for (int row = 2; row < output.nrows(); row += 2)
+ {
+ value = (input.at(row / 2, 0));
+ value += (input.at(row / 2 - 1, 0));
+ output.at(row, 0) = (value / 2);
+ }
+
+ for (int row = 1; row < output.nrows(); row += 2)
+ output.at(row, 0) = (input.at(row / 2, 0));
+
+ // others
- do
+ for (int row = 2; row < output.nrows(); row += 2)
+ {
+ for (int col = 2; col < output.ncols(); col += 2)
+ {
+ value = (input.at(row / 2, col / 2));
+ value += (input.at(row / 2 - 1, col / 2));
+ value += (input.at(row / 2, col / 2 - 1));
+ value += (input.at(row / 2 - 1, col / 2 - 1));
+ output.at(row, col) = ((unsigned(value)+2) / 4);
+ }
+ for (int col = 1; col < output.ncols(); col += 2)
{
- output = enlargex2(input);
+ value = (input.at(row / 2, col / 2));
+ value += (input.at(row / 2 - 1, col / 2));
+ output.at(row, col) = (value / 2);
+ }
+ }
- if (--n > 0)
+ for (int row = 1; row < output.nrows(); row += 2)
{
- initialize(input, output);
- mln_piter_(image2d<bool>) p(input.domain());
- for_all(p)
- input(p) = output(p) > 0;
+ for (int col = 2; col < output.ncols(); col += 2)
+ {
+ value = (input.at(row / 2, col / 2));
+ value += (input.at(row / 2, col / 2 - 1));
+ output.at(row, col) = (value / 2);
+ }
+ for (int col = 1; col < output.ncols(); col += 2)
+ output.at(row, col) = (input.at(row / 2, col / 2));
}
- else
- break;
+
+ return output;
}
- while (1);
+
+
+
+
+
+
+ // enlarge 2^n times
+ image2d<value::int_u8>
+ enlarge(const image2d<bool>& input, unsigned int n)
+ {
+ using value::int_u8;
+
+ if (n == 0)
+ return clone(fun::p2v::ternary(pw::value(input),
+ pw::cst(int_u8(255)),
+ pw::cst(int_u8(0)))
+ | input.domain());
+
+ image2d<int_u8> output = enlargex2(input);
+
+ while (--n)
+ output = enlargex2(output);
+
return output;
}
-#endif // ! ENLARGE_HH
+} // mln
Index: branches/cleanup-2008/milena/sandbox/garrigues/ocr/Makefile
===================================================================
--- branches/cleanup-2008/milena/sandbox/garrigues/ocr/Makefile (revision 2749)
+++ branches/cleanup-2008/milena/sandbox/garrigues/ocr/Makefile (revision 2750)
@@ -19,3 +19,8 @@
check: logs tmp ocr_without_preprocess ocr_with_preprocess
./check.sh
+
+skeleton: skeleton.cc
+ g++ -DNDEBUG -W -Wall -Wextra ${CXXFLAGS} $< -o $@
+
+.PHONY: skeleton
1
0
From: Maxime van Noppen <yabo(a)lrde.epita.fr>
To: transformers-patches(a)lrde.epita.fr, olena-patches(a)lrde.epita.fr
Subject: scool r125: Start work on static functions
URL: https://svn.lrde.epita.fr/svn/scool/branches/scool-ng
ChangeLog:
2008-10-31 Maxime van Noppen <yabo(a)lrde.epita.fr>
Start work on static functions.
* scl-syn/Lexical.sdf: Fix typo.
* scoolt/Class.str: Fix typos and handle the StaticClassFunction
constructor (work still in progress).
* scl-syn/Declaration.sdf:
* scoolt/Declaration.str: Change the place of the class qualifiers
to be more coherent with Scool's philosphy.
---
scl-syn/Declaration.sdf | 6 +++---
scl-syn/Lexical.sdf | 2 +-
scoolt/Class.str | 15 +++++++++++++--
scoolt/Declaration.str | 15 ++++++++++++---
4 files changed, 29 insertions(+), 9 deletions(-)
Index: branches/scool-ng/src/scoolt/Class.str
===================================================================
--- branches/scool-ng/src/scoolt/Class.str (revision 124)
+++ branches/scool-ng/src/scoolt/Class.str (revision 125)
@@ -79,13 +79,13 @@
<? None()> cqualif
CheckDaughter(| scl_idf):
- daughter -> 42 // The result isn't used
+ daughter -> 42 // The result isn't used, should this be a strategy ?
where
<?Identifier(idf)> scl_idf
; <eq> (daughter, idf)
CheckDaughter(| scl_idf):
- daughter -> <say(<concat-strings> [ "Error: class name \"", daughter, "\" doest not match with \"", idf, "\"" ]); fail>
+ daughter -> <say(<concat-strings> [ "Error: class name \"", daughter, "\" does not match with \"", idf, "\"" ]); fail>
where
<?Identifier(idf)> scl_idf
@@ -114,6 +114,17 @@
; <IdentifierToCxx> idf => cxx_idf
; <InheritanceToCxx(| cqualif, cxx_idf)> mother => cxx_mother
+
+ // Handle static class functions
+
+ StaticClassFunctionToCxx(|cqualif, idf, params, body):
+ _ -> CxxClassDecl(cxx_params, cxx_idf, [], cxx_body)
+ where
+ <IdentifierToCxx> idf => cxx_idf
+ ; <AddExactType(| cqualif)> <ParametersToCxx> params => cxx_params // FIXME: cqualif is rather a qualifier of the function than the returned class
+ ; ![] => cxx_body
+
+
strategies
ClassInit = rules(IsInClass: _ -> 0)
Index: branches/scool-ng/src/scoolt/Declaration.str
===================================================================
--- branches/scool-ng/src/scoolt/Declaration.str (revision 124)
+++ branches/scool-ng/src/scoolt/Declaration.str (revision 125)
@@ -68,7 +68,7 @@
////////////////////////////////////////////////////////////////////////////////
DeclarationToCxx:
- ClassDeclaration(cqualif, idf, _) -> CxxClassDecl(cxx_params, cxx_idf, [])
+ ClassDeclaration(idf, cqualif, _) -> CxxClassDecl(cxx_params, cxx_idf, [])
where
<AddExactType(|cqualif)> [] => cxx_params
; <IdentifierToCxx> idf => cxx_idf
@@ -79,14 +79,23 @@
DeclarationToCxx:
- ClassDefinition(cqualif, idf, None(), ClassBlock(body)) -> CxxClassDecl(cxx_params, cxx_idf, [], cxx_body)
+ ClassDefinition(idf, cqualif, None(), ClassBlock(body)) -> CxxClassDecl(cxx_params, cxx_idf, [], cxx_body)
where
<AddExactType(|cqualif)> [] => cxx_params
; <IdentifierToCxx> idf => cxx_idf
; <ClassBodyToCxx> body => cxx_body
+// FIXME: handle multiple where clauses
DeclarationToCxx:
- ClassDefinition(cqualif, idf, Some(ClassWhereClause([wclause])), ClassBlock(body)) -> cxx_code
+ ClassDefinition(idf, cqualif, Some(ClassWhereClause([wclause])), ClassBlock(body)) -> cxx_code
where
<ClassWhereClauseToCxx(|cqualif, idf, body)> wclause => cxx_code
+ ////////////////////////////////////////////////////////////////////////////////
+ // Static functions //
+ ////////////////////////////////////////////////////////////////////////////////
+
+ DeclarationToCxx:
+ StaticClassFunction(idf, params, cqualif, StaticClassBlock(body)) -> cxx_code
+ where
+ <StaticClassFunctionToCxx(|cqualif, idf, params, body)> [] => cxx_code
Index: branches/scool-ng/src/scl-syn/Declaration.sdf
===================================================================
--- branches/scool-ng/src/scl-syn/Declaration.sdf (revision 124)
+++ branches/scool-ng/src/scl-syn/Declaration.sdf (revision 125)
@@ -27,7 +27,7 @@
FunctionQualifier? Identifier ":" FunctionType "=" FunctionBlock -> Declaration {cons("FunctionDefinition")}
Identifier ":" ParametersDeclaration "->" "type" "=" StaticBlock -> StaticFunction {cons("StaticTypeFunction")}
- ClassQualifier? Identifier ":" ParametersDeclaration "->" "class" "=" StaticClassBlock -> StaticFunction {cons("StaticClassFunction")}
+ Identifier ":" ParametersDeclaration "->" ClassQualifier? "class" "=" StaticClassBlock -> StaticFunction {cons("StaticClassFunction")}
- ClassQualifier? Identifier ":" "class" ClassWhereClause? ";" -> Declaration {cons("ClassDeclaration")}
- ClassQualifier? Identifier ":" "class" ClassWhereClause? "=" ClassBlock -> Declaration {cons("ClassDefinition")}
+ Identifier ":" ClassQualifier? "class" ClassWhereClause? ";" -> Declaration {cons("ClassDeclaration")}
+ Identifier ":" ClassQualifier? "class" ClassWhereClause? "=" ClassBlock -> Declaration {cons("ClassDefinition")}
Index: branches/scool-ng/src/scl-syn/Lexical.sdf
===================================================================
--- branches/scool-ng/src/scl-syn/Lexical.sdf (revision 124)
+++ branches/scool-ng/src/scl-syn/Lexical.sdf (revision 125)
@@ -29,7 +29,7 @@
"var" -> SimpleQualifier
"final" -> ClassQualifier
- "abtract" -> ClassQualifier
+ "abstract" -> ClassQualifier
"models" -> TypeQualifier
"abtract" -> FunctionQualifier
"mutable" -> FunctionQualifier
1
0
31 Oct '08
From: Maxime van Noppen <yabo(a)lrde.epita.fr>
To: transformers-patches(a)lrde.epita.fr, olena-patches(a)lrde.epita.fr
Subject: scool r124: Add reference files for tests on static functions
URL: https://svn.lrde.epita.fr/svn/scool/branches/scool-ng
ChangeLog:
2008-10-31 Maxime van Noppen <yabo(a)lrde.epita.fr>
Add reference files for tests on static functions.
* config: Little hack to avoid binary output files from g++.
* class/scool_ast/inheritance_003.aterm: New.
* class/c++_ast/inheritance_003.aterm: New.
* class/c++_ast/inheritance_004.aterm: New.
* class/c++_ast/static_function_001.aterm: New.
* class/c++_ast/static_function_002.aterm: New.
* class/c++_build/inheritance_003.g++: New.
* class/c++_build/inheritance_004.g++: New.
* class/c++_build/static_function_001.g++: New.
* class/c++_build/static_function_002.g++: New.
* class/c++_src/inheritance_003.cc: New.
* class/c++_src/inheritance_004.cc: New.
* class/c++_src/static_function_001.cc: New.
* class/c++_src/static_function_002.cc: New.
* class/scool_ast/declaration_001.aterm,
* class/scool_ast/declaration_002.aterm,
* class/scool_ast/empty.aterm,
* class/scool_ast/empty_accessblocks.aterm,
* class/scool_ast/empty_private.aterm,
* class/scool_ast/empty_protected.aterm,
* class/scool_ast/empty_public.aterm,
* class/scool_ast/final_001.aterm,
* class/scool_ast/inheritance_001.aterm,
* class/scool_ast/inheritance_002.aterm,
* class/scool_ast/inheritance_004.aterm,
* class/scool_ast/member_001.aterm,
* class/scool_ast/member_002.aterm,
* class/scool_ast/method_001.aterm,
* class/scool_ast/method_002.aterm,
* class/scool_ast/method_003.aterm,
* class/scool_ast/method_004.aterm,
* class/scool_ast/method_005.aterm,
* class/scool_ast/mutable_1.aterm,
* class/scool_ast/static_function_001.aterm,
* class/scool_ast/static_function_002.aterm,
* class/scool_ast/static_function_003.aterm,
* class/scool_src/final_001.scl,
* class/scool_src/inheritance_002.scl,
* class/scool_src/inheritance_003.scl,
* function/scool_ast/declaration_003.aterm,
* function/scool_ast/declaration_004.aterm,
* function/scool_src/declaration_003.scl,
* function/scool_src/declaration_004.scl: Update.
---
class/c++_ast/inheritance_003.aterm | 1 +
class/c++_ast/inheritance_004.aterm | 1 +
class/c++_ast/static_function_001.aterm | 1 +
class/c++_ast/static_function_002.aterm | 1 +
class/c++_src/inheritance_003.cc | 8 ++++++++
class/c++_src/inheritance_004.cc | 8 ++++++++
class/c++_src/static_function_001.cc | 4 ++++
class/c++_src/static_function_002.cc | 4 ++++
class/scool_ast/declaration_001.aterm | 2 +-
class/scool_ast/declaration_002.aterm | 2 +-
class/scool_ast/empty.aterm | 2 +-
class/scool_ast/empty_accessblocks.aterm | 2 +-
class/scool_ast/empty_private.aterm | 2 +-
class/scool_ast/empty_protected.aterm | 2 +-
class/scool_ast/empty_public.aterm | 2 +-
class/scool_ast/final_001.aterm | 2 +-
class/scool_ast/inheritance_001.aterm | 2 +-
class/scool_ast/inheritance_002.aterm | 2 +-
class/scool_ast/inheritance_003.aterm | 1 +
class/scool_ast/inheritance_004.aterm | 2 +-
class/scool_ast/member_001.aterm | 2 +-
class/scool_ast/member_002.aterm | 2 +-
class/scool_ast/method_001.aterm | 2 +-
class/scool_ast/method_002.aterm | 2 +-
class/scool_ast/method_003.aterm | 2 +-
class/scool_ast/method_004.aterm | 2 +-
class/scool_ast/method_005.aterm | 2 +-
class/scool_ast/mutable_1.aterm | 2 +-
class/scool_ast/static_function_001.aterm | 2 +-
class/scool_ast/static_function_002.aterm | 2 +-
class/scool_ast/static_function_003.aterm | 2 +-
class/scool_src/final_001.scl | 2 +-
class/scool_src/inheritance_002.scl | 2 +-
class/scool_src/inheritance_003.scl | 2 +-
config | 2 +-
function/scool_ast/declaration_003.aterm | 2 +-
function/scool_ast/declaration_004.aterm | 2 +-
function/scool_src/declaration_003.scl | 2 +-
function/scool_src/declaration_004.scl | 2 +-
39 files changed, 59 insertions(+), 30 deletions(-)
Index: branches/scool-ng/tests/class/c++_ast/inheritance_003.aterm
===================================================================
--- branches/scool-ng/tests/class/c++_ast/inheritance_003.aterm (revision 0)
+++ branches/scool-ng/tests/class/c++_ast/inheritance_003.aterm (revision 124)
@@ -0,0 +1 @@
+CxxProgram([CxxClassDecl([(CxxType("typename"),"Exact")],CxxId("Animal"),[],[]),CxxClassDecl([(CxxType("typename"),"Exact")],CxxId("Mammal"),[("public",CxxType(CxxId("Animal"),[CxxId("Exact")]))],[])])
Index: branches/scool-ng/tests/class/c++_ast/inheritance_004.aterm
===================================================================
--- branches/scool-ng/tests/class/c++_ast/inheritance_004.aterm (revision 0)
+++ branches/scool-ng/tests/class/c++_ast/inheritance_004.aterm (revision 124)
@@ -0,0 +1 @@
+CxxProgram([CxxClassDecl([(CxxType("typename"),"Exact"),(CxxType("int"),CxxId("I"))],CxxId("Foo"),[],[]),CxxClassDecl([(CxxType("typename"),"Exact")],CxxId("Cat"),[("public",CxxType(CxxId("Foo"),[CxxId("Exact"),CxxInt("42")]))],[])])
Index: branches/scool-ng/tests/class/c++_ast/static_function_001.aterm
===================================================================
--- branches/scool-ng/tests/class/c++_ast/static_function_001.aterm (revision 0)
+++ branches/scool-ng/tests/class/c++_ast/static_function_001.aterm (revision 124)
@@ -0,0 +1 @@
+CxxProgram([CxxClassDecl([(CxxType("typename"),"Exact"),(CxxType("typename"),CxxId("T"))],CxxId("A"),[],[])])
Index: branches/scool-ng/tests/class/c++_ast/static_function_002.aterm
===================================================================
--- branches/scool-ng/tests/class/c++_ast/static_function_002.aterm (revision 0)
+++ branches/scool-ng/tests/class/c++_ast/static_function_002.aterm (revision 124)
@@ -0,0 +1 @@
+CxxProgram([CxxClassDecl([(CxxType("typename"),"Exact"),(CxxType("typename"),CxxId("T")),(CxxType("bool"),CxxId("B"))],CxxId("A"),[],[])])
Index: branches/scool-ng/tests/class/c++_src/inheritance_003.cc
===================================================================
--- branches/scool-ng/tests/class/c++_src/inheritance_003.cc (revision 0)
+++ branches/scool-ng/tests/class/c++_src/inheritance_003.cc (revision 124)
@@ -0,0 +1,8 @@
+template < typename Exact >
+class Animal
+{
+};
+template < typename Exact >
+class Mammal : public Animal< Exact >
+{
+};
Index: branches/scool-ng/tests/class/c++_src/inheritance_004.cc
===================================================================
--- branches/scool-ng/tests/class/c++_src/inheritance_004.cc (revision 0)
+++ branches/scool-ng/tests/class/c++_src/inheritance_004.cc (revision 124)
@@ -0,0 +1,8 @@
+template < typename Exact, int I >
+class Foo
+{
+};
+template < typename Exact >
+class Cat : public Foo< Exact, 42 >
+{
+};
Index: branches/scool-ng/tests/class/c++_src/static_function_001.cc
===================================================================
--- branches/scool-ng/tests/class/c++_src/static_function_001.cc (revision 0)
+++ branches/scool-ng/tests/class/c++_src/static_function_001.cc (revision 124)
@@ -0,0 +1,4 @@
+template < typename Exact, typename T >
+class A
+{
+};
Index: branches/scool-ng/tests/class/c++_src/static_function_002.cc
===================================================================
--- branches/scool-ng/tests/class/c++_src/static_function_002.cc (revision 0)
+++ branches/scool-ng/tests/class/c++_src/static_function_002.cc (revision 124)
@@ -0,0 +1,4 @@
+template < typename Exact, typename T, bool B >
+class A
+{
+};
Index: branches/scool-ng/tests/class/scool_ast/inheritance_001.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/inheritance_001.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/inheritance_001.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Bar"),None,ClassBlock([])),ClassDefinition(None,Identifier("Foo"),Some(ClassWhereClause([Inherits("Foo",SimpleType("Bar"))])),ClassBlock([]))])
+Program([ClassDefinition(Identifier("Bar"),None,None,ClassBlock([])),ClassDefinition(Identifier("Foo"),None,Some(ClassWhereClause([Inherits("Foo",SimpleType("Bar"))])),ClassBlock([]))])
Index: branches/scool-ng/tests/class/scool_ast/final_001.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/final_001.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/final_001.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(Some("final"),Identifier("Student"),None,ClassBlock([]))])
+Program([ClassDefinition(Identifier("Student"),Some("final"),None,ClassBlock([]))])
Index: branches/scool-ng/tests/class/scool_ast/mutable_1.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/mutable_1.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/mutable_1.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("foo"),None,ClassBlock([AccessBlock(Public,[FunctionDefinition(Some("mutable"),Identifier("f"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("void")),FunctionBlock([ExpressionStatement(Assign(Identifier("x"),Integer("42")))])),SimpleDeclaration(Some("var"),Identifier("x"),SimpleType("int"),None)])]))])
+Program([ClassDefinition(Identifier("foo"),None,None,ClassBlock([AccessBlock(Public,[FunctionDefinition(Some("mutable"),Identifier("f"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("void")),FunctionBlock([ExpressionStatement(Assign(Identifier("x"),Integer("42")))])),SimpleDeclaration(Some("var"),Identifier("x"),SimpleType("int"),None)])]))])
Index: branches/scool-ng/tests/class/scool_ast/inheritance_002.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/inheritance_002.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/inheritance_002.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Animal"),None,ClassBlock([])),ClassDefinition(None,Identifier("Mammal"),Some(ClassWhereClause([Inherits("Mammal",SimpleType("Animal"))])),ClassBlock([])),ClassDefinition(Some("final"),Identifier("Monkey"),Some(ClassWhereClause([Inherits("Monkey",SimpleType("Mammal"))])),ClassBlock([]))])
+Program([ClassDefinition(Identifier("Animal"),None,None,ClassBlock([])),ClassDefinition(Identifier("Mammal"),None,Some(ClassWhereClause([Inherits("Mammal",SimpleType("Animal"))])),ClassBlock([])),ClassDefinition(Identifier("Monkey"),Some("final"),Some(ClassWhereClause([Inherits("Monkey",SimpleType("Mammal"))])),ClassBlock([]))])
Index: branches/scool-ng/tests/class/scool_ast/inheritance_003.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/inheritance_003.aterm (revision 0)
+++ branches/scool-ng/tests/class/scool_ast/inheritance_003.aterm (revision 124)
@@ -0,0 +1 @@
+Program([ClassDefinition(Identifier("Animal"),Some("abstract"),None,ClassBlock([])),ClassDefinition(Identifier("Mammal"),None,Some(ClassWhereClause([Inherits("Mammal",SimpleType("Animal"))])),ClassBlock([]))])
Index: branches/scool-ng/tests/class/scool_ast/inheritance_004.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/inheritance_004.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/inheritance_004.aterm (revision 124)
@@ -1 +1 @@
-Program([StaticClassFunction(None,Identifier("Foo"),ParametersDeclaration([TypedId(Identifier("I"),SimpleType("int"))]),StaticClassBlock([])),ClassDefinition(None,Identifier("Cat"),Some(ClassWhereClause([Inherits("Cat",StaticFunctionCall(Identifier("Foo"),Parameters([Integer("42")])))])),ClassBlock([]))])
+Program([StaticClassFunction(Identifier("Foo"),ParametersDeclaration([TypedId(Identifier("I"),SimpleType("int"))]),None,StaticClassBlock([])),ClassDefinition(Identifier("Cat"),None,Some(ClassWhereClause([Inherits("Cat",StaticFunctionCall(Identifier("Foo"),Parameters([Integer("42")])))])),ClassBlock([]))])
Index: branches/scool-ng/tests/class/scool_ast/static_function_001.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/static_function_001.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/static_function_001.aterm (revision 124)
@@ -1 +1 @@
-Program([StaticClassFunction(None,Identifier("A"),ParametersDeclaration([TypedId(Identifier("T"),"type")]),StaticClassBlock([]))])
+Program([StaticClassFunction(Identifier("A"),ParametersDeclaration([TypedId(Identifier("T"),"type")]),None,StaticClassBlock([]))])
Index: branches/scool-ng/tests/class/scool_ast/empty_accessblocks.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/empty_accessblocks.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/empty_accessblocks.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([AccessBlock(Public,[]),AccessBlock(Protected,[]),AccessBlock(Private,[])]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([AccessBlock(Public,[]),AccessBlock(Protected,[]),AccessBlock(Private,[])]))])
Index: branches/scool-ng/tests/class/scool_ast/static_function_002.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/static_function_002.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/static_function_002.aterm (revision 124)
@@ -1 +1 @@
-Program([StaticClassFunction(None,Identifier("A"),ParametersDeclaration([TypedId(Identifier("T"),"type"),TypedId(Identifier("B"),SimpleType("bool"))]),StaticClassBlock([]))])
+Program([StaticClassFunction(Identifier("A"),ParametersDeclaration([TypedId(Identifier("T"),"type"),TypedId(Identifier("B"),SimpleType("bool"))]),None,StaticClassBlock([]))])
Index: branches/scool-ng/tests/class/scool_ast/static_function_003.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/static_function_003.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/static_function_003.aterm (revision 124)
@@ -1 +1 @@
-Program([StaticClassFunction(None,Identifier("A"),ParametersDeclaration([SimpleType("int")]),StaticClassBlock([]))])
+Program([StaticClassFunction(Identifier("A"),ParametersDeclaration([SimpleType("int")]),None,StaticClassBlock([]))])
Index: branches/scool-ng/tests/class/scool_ast/member_001.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/member_001.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/member_001.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Point1d"),None,ClassBlock([AccessBlock(Public,[SimpleDeclaration(Some("var"),Identifier("x"),SimpleType("int"),None)])]))])
+Program([ClassDefinition(Identifier("Point1d"),None,None,ClassBlock([AccessBlock(Public,[SimpleDeclaration(Some("var"),Identifier("x"),SimpleType("int"),None)])]))])
Index: branches/scool-ng/tests/class/scool_ast/member_002.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/member_002.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/member_002.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Point2d"),None,ClassBlock([AccessBlock(Public,[SimpleDeclaration(Some("var"),Identifier("x"),SimpleType("int"),None),SimpleDeclaration(Some("var"),Identifier("y"),SimpleType("int"),None)])]))])
+Program([ClassDefinition(Identifier("Point2d"),None,None,ClassBlock([AccessBlock(Public,[SimpleDeclaration(Some("var"),Identifier("x"),SimpleType("int"),None),SimpleDeclaration(Some("var"),Identifier("y"),SimpleType("int"),None)])]))])
Index: branches/scool-ng/tests/class/scool_ast/empty_private.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/empty_private.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/empty_private.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([AccessBlock(Private,[])]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([AccessBlock(Private,[])]))])
Index: branches/scool-ng/tests/class/scool_ast/empty_public.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/empty_public.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/empty_public.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([AccessBlock(Public,[])]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([AccessBlock(Public,[])]))])
Index: branches/scool-ng/tests/class/scool_ast/empty.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/empty.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/empty.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([]))])
Index: branches/scool-ng/tests/class/scool_ast/method_001.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/method_001.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/method_001.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("42"))]))])]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("42"))]))])]))])
Index: branches/scool-ng/tests/class/scool_ast/method_002.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/method_002.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/method_002.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock(Integer("42")))])]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock(Integer("42")))])]))])
Index: branches/scool-ng/tests/class/scool_ast/method_003.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/method_003.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/method_003.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock(Integer("42"))),FunctionDefinition(None,Identifier("another_test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock(Integer("51")))])]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock(Integer("42"))),FunctionDefinition(None,Identifier("another_test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock(Integer("51")))])]))])
Index: branches/scool-ng/tests/class/scool_ast/method_004.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/method_004.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/method_004.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("42"))])),FunctionDefinition(None,Identifier("another_test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("51"))]))])]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("42"))])),FunctionDefinition(None,Identifier("another_test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("51"))]))])]))])
Index: branches/scool-ng/tests/class/scool_ast/method_005.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/method_005.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/method_005.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("42"))]))]),AccessBlock(Private,[FunctionDefinition(None,Identifier("another_test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("51"))]))])]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([AccessBlock(Public,[FunctionDefinition(None,Identifier("test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("42"))]))]),AccessBlock(Private,[FunctionDefinition(None,Identifier("another_test"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("int")),FunctionBlock([ReturnStatement(Integer("51"))]))])]))])
Index: branches/scool-ng/tests/class/scool_ast/declaration_001.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/declaration_001.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/declaration_001.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDeclaration(None,Identifier("Foo"),None)])
+Program([ClassDeclaration(Identifier("Foo"),None,None)])
Index: branches/scool-ng/tests/class/scool_ast/declaration_002.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/declaration_002.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/declaration_002.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDeclaration(None,Identifier("Bar"),None),ClassDeclaration(None,Identifier("Foo"),Some(ClassWhereClause([Inherits("Foo",SimpleType("Bar"))])))])
+Program([ClassDeclaration(Identifier("Bar"),None,None),ClassDeclaration(Identifier("Foo"),None,Some(ClassWhereClause([Inherits("Foo",SimpleType("Bar"))])))])
Index: branches/scool-ng/tests/class/scool_ast/empty_protected.aterm
===================================================================
--- branches/scool-ng/tests/class/scool_ast/empty_protected.aterm (revision 123)
+++ branches/scool-ng/tests/class/scool_ast/empty_protected.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDefinition(None,Identifier("Foo"),None,ClassBlock([AccessBlock(Protected,[])]))])
+Program([ClassDefinition(Identifier("Foo"),None,None,ClassBlock([AccessBlock(Protected,[])]))])
Index: branches/scool-ng/tests/class/scool_src/final_001.scl
===================================================================
--- branches/scool-ng/tests/class/scool_src/final_001.scl (revision 123)
+++ branches/scool-ng/tests/class/scool_src/final_001.scl (revision 124)
@@ -1,3 +1,3 @@
-final Student : class =
+Student : final class =
{
}
Index: branches/scool-ng/tests/class/scool_src/inheritance_002.scl
===================================================================
--- branches/scool-ng/tests/class/scool_src/inheritance_002.scl (revision 123)
+++ branches/scool-ng/tests/class/scool_src/inheritance_002.scl (revision 124)
@@ -8,7 +8,7 @@
}
-final Monkey : class where Monkey -> Mammal =
+Monkey : final class where Monkey -> Mammal =
{
}
Index: branches/scool-ng/tests/class/scool_src/inheritance_003.scl
===================================================================
--- branches/scool-ng/tests/class/scool_src/inheritance_003.scl (revision 123)
+++ branches/scool-ng/tests/class/scool_src/inheritance_003.scl (revision 124)
@@ -1,4 +1,4 @@
-abstract Animal: class =
+Animal: abstract class =
{
}
Index: branches/scool-ng/tests/class/c++_build/inheritance_003.g++
===================================================================
Index: branches/scool-ng/tests/class/c++_build/inheritance_004.g++
===================================================================
Index: branches/scool-ng/tests/class/c++_build/static_function_001.g++
===================================================================
Index: branches/scool-ng/tests/class/c++_build/static_function_002.g++
===================================================================
Index: branches/scool-ng/tests/config
===================================================================
--- branches/scool-ng/tests/config (revision 123)
+++ branches/scool-ng/tests/config (revision 124)
@@ -48,7 +48,7 @@
test_4 ()
{
desc="Compilation of generated code"
- cmd='g++ -W -Wall -c $input_file'
+ cmd='g++ -W -Wall -o /dev/null -c $input_file'
cmp='diff -EwbB -u $ref $output'
print_input_cmd='cat $input_file'
print_output_cmd='cat $input_file'
Index: branches/scool-ng/tests/function/scool_ast/declaration_004.aterm
===================================================================
--- branches/scool-ng/tests/function/scool_ast/declaration_004.aterm (revision 123)
+++ branches/scool-ng/tests/function/scool_ast/declaration_004.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDeclaration(Some("final"),Identifier("toto"),None),FunctionDeclaration(None,Identifier("foo"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("void"))),FunctionDeclaration(None,Identifier("foo"),FunctionType(None,ArgumentsDeclaration([TypedId(Identifier("arg1"),SimpleType("int"))]),SimpleType("float"))),FunctionDeclaration(None,Identifier("foo"),FunctionType(None,ArgumentsDeclaration([TypedId(Identifier("arg1"),SimpleType("toto")),TypedId(Identifier("arg2"),ReferenceType(SimpleType("double")))]),SimpleType("char")))])
+Program([ClassDeclaration(Identifier("toto"),Some("final"),None),FunctionDeclaration(None,Identifier("foo"),FunctionType(None,ArgumentsDeclaration([]),SimpleType("void"))),FunctionDeclaration(None,Identifier("foo"),FunctionType(None,ArgumentsDeclaration([TypedId(Identifier("arg1"),SimpleType("int"))]),SimpleType("float"))),FunctionDeclaration(None,Identifier("foo"),FunctionType(None,ArgumentsDeclaration([TypedId(Identifier("arg1"),SimpleType("toto")),TypedId(Identifier("arg2"),ReferenceType(SimpleType("double")))]),SimpleType("char")))])
Index: branches/scool-ng/tests/function/scool_ast/declaration_003.aterm
===================================================================
--- branches/scool-ng/tests/function/scool_ast/declaration_003.aterm (revision 123)
+++ branches/scool-ng/tests/function/scool_ast/declaration_003.aterm (revision 124)
@@ -1 +1 @@
-Program([ClassDeclaration(Some("final"),Identifier("bar"),None),FunctionDeclaration(None,Identifier("foo"),FunctionType(None,ArgumentsDeclaration([TypedId(Identifier("a"),SimpleType("int")),TypedId(Identifier("b"),SimpleType("bar"))]),SimpleType("void")))])
+Program([ClassDeclaration(Identifier("bar"),Some("final"),None),FunctionDeclaration(None,Identifier("foo"),FunctionType(None,ArgumentsDeclaration([TypedId(Identifier("a"),SimpleType("int")),TypedId(Identifier("b"),SimpleType("bar"))]),SimpleType("void")))])
Index: branches/scool-ng/tests/function/scool_src/declaration_003.scl
===================================================================
--- branches/scool-ng/tests/function/scool_src/declaration_003.scl (revision 123)
+++ branches/scool-ng/tests/function/scool_src/declaration_003.scl (revision 124)
@@ -1,3 +1,3 @@
-final bar : class;
+bar : final class;
foo : (a : int, b : bar) -> void;
Index: branches/scool-ng/tests/function/scool_src/declaration_004.scl
===================================================================
--- branches/scool-ng/tests/function/scool_src/declaration_004.scl (revision 123)
+++ branches/scool-ng/tests/function/scool_src/declaration_004.scl (revision 124)
@@ -1,4 +1,4 @@
-final toto : class;
+toto : final class;
foo : () -> void;
foo : (arg1 : int) -> float;
1
0
31 Oct '08
From: Vivien Delmon <vivien.delmon(a)lrde.epita.fr>
To: olena-patches(a)lrde.epita.fr
Subject: milena r2749: Add void cast to remove unused variable warnings
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-10-31 Vivien Delmon <vivien.delmon(a)lrde.epita.fr>
Add void cast to remove unused variable warnings.
* mln/morpho/erosion.hh: Done.
---
erosion.hh | 2 ++
1 file changed, 2 insertions(+)
Index: branches/cleanup-2008/milena/mln/morpho/erosion.hh
===================================================================
--- branches/cleanup-2008/milena/mln/morpho/erosion.hh (revision 2748)
+++ branches/cleanup-2008/milena/mln/morpho/erosion.hh (revision 2749)
@@ -63,6 +63,8 @@
{
const I& input = exact(input_);
const W& win = exact(win_);
+ (void) input;
+ (void) win;
mln_precondition(exact(input).has_data());
mln_precondition(! exact(win).is_empty());
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Introduce make::image.
When there is no ambiguity, the user can call make::image.
* milena/mln/make/image2d.hh: Rename as...
* milena/mln/make/image.hh: ...this.
Import code from...
* milena/mln/make/image1d.hh: ...this removed file.
* milena/mln/make/all.hh: Update.
* milena/tests/debug/iota.cc,
* milena/tests/draw/graph.cc,
* milena/tests/level/abs.cc,
* milena/tests/level/replace.cc,
* milena/tests/level/stretch.cc,
* milena/tests/level/apply.cc,
* milena/tests/level/compare.cc,
* milena/tests/level/saturate.cc,
* milena/tests/arith/minus.cc,
* milena/tests/arith/times.cc,
* milena/tests/arith/plus.cc,
* milena/tests/arith/revert.cc,
* milena/tests/accu/compute.cc,
* milena/tests/geom/resize.cc,
* milena/tests/geom/seed2tiling_roundness.cc,
* milena/tests/geom/seed2tiling.cc,
* milena/tests/display/color_pretty.cc,
* milena/tests/logical/or.cc,
* milena/tests/logical/not.cc,
* milena/tests/logical/and_not.cc,
* milena/tests/logical/and.cc,
* milena/tests/canvas/chamfer.cc,
* milena/tests/util/tree_to_image.cc,
* milena/tests/util/lemmings.cc,
* milena/tests/util/tree_fast_to_image.cc,
* milena/tests/labeling/compute.cc,
* milena/mln/core/image/image1d.hh: Update.
* milena/mln/core/image/image2d.hh: Update.
(todo): New.
* milena/mln/core/w_window.hh (from_to): New overload.
* milena/mln/make/w_window2d.hh: Change tests into checks.
* milena/mln/convert/from_to.hxx: Update.
* milena/mln/canvas/browsing/directional.hh: .
* milena/tests/core/alias/w_window2d_int.cc: Add alt code.
mln/canvas/browsing/directional.hh | 8 -------
mln/convert/from_to.hxx | 7 ++++++
mln/core/image/image1d.hh | 5 ++--
mln/core/image/image2d.hh | 7 +++++-
mln/core/w_window.hh | 36 ++++++++++++++++++++------------
mln/make/all.hh | 2 +
mln/make/image.hh | 40 +++++++++++++++++++++++++++---------
mln/make/w_window2d.hh | 28 +++++++++----------------
tests/accu/compute.cc | 2 -
tests/arith/minus.cc | 2 -
tests/arith/plus.cc | 2 -
tests/arith/revert.cc | 2 -
tests/arith/times.cc | 2 -
tests/canvas/chamfer.cc | 6 ++---
tests/core/alias/w_window2d_int.cc | 4 +++
tests/debug/iota.cc | 2 -
tests/display/color_pretty.cc | 4 +--
tests/draw/graph.cc | 4 +--
tests/geom/resize.cc | 2 -
tests/geom/seed2tiling.cc | 4 +--
tests/geom/seed2tiling_roundness.cc | 4 +--
tests/labeling/compute.cc | 2 -
tests/level/abs.cc | 2 -
tests/level/apply.cc | 2 -
tests/level/compare.cc | 4 +--
tests/level/replace.cc | 4 +--
tests/level/saturate.cc | 2 -
tests/level/stretch.cc | 4 +--
tests/logical/and.cc | 6 ++---
tests/logical/and_not.cc | 6 ++---
tests/logical/not.cc | 4 +--
tests/logical/or.cc | 6 ++---
tests/util/lemmings.cc | 2 -
tests/util/tree_fast_to_image.cc | 2 -
tests/util/tree_to_image.cc | 2 -
35 files changed, 129 insertions(+), 92 deletions(-)
Index: milena/tests/debug/iota.cc
--- milena/tests/debug/iota.cc (revision 2747)
+++ milena/tests/debug/iota.cc (working copy)
@@ -48,7 +48,7 @@
{9, 10,11,12},
{13,14,15,16} };
- image2d<int> ref = make::image2d(vs);
+ image2d<int> ref = make::image(vs);
image2d<int> ima(4, 4);
debug::iota(ima);
Index: milena/tests/core/alias/w_window2d_int.cc
--- milena/tests/core/alias/w_window2d_int.cc (revision 2747)
+++ milena/tests/core/alias/w_window2d_int.cc (working copy)
@@ -56,6 +56,10 @@
-1, 0, 1 };
w_window2d_int w_win = make::w_window2d(ws);
+// w_window2d_int w_win;
+// convert::from_to(ws, w_win);
+// std::cout << w_win << std::endl;
+
image2d<int> ima = convert::to_image(w_win);
w_window2d_int w_win_2 = convert::to<w_window2d_int>(ima);
mln_assertion(w_win_2 == w_win);
Index: milena/tests/draw/graph.cc
--- milena/tests/draw/graph.cc (revision 2747)
+++ milena/tests/draw/graph.cc (working copy)
@@ -90,7 +90,7 @@
{0, 1, 0},
{0, 0, 2}
};
- image2d<int> ref (make::image2d(vs));
+ image2d<int> ref (make::image(vs));
// Points associated to nodes.
points_type points;
@@ -117,7 +117,7 @@
{0, 0, 0, 1, 1},
{0, 0, 0, 2, 2},
};
- image2d<int> ref (make::image2d(vs));
+ image2d<int> ref (make::image(vs));
// Points associated to nodes.
points_type points;
Index: milena/tests/level/abs.cc
--- milena/tests/level/abs.cc (revision 2747)
+++ milena/tests/level/abs.cc (working copy)
@@ -51,7 +51,7 @@
};
- image2d<int> ima(make::image2d(vs));
+ image2d<int> ima(make::image(vs));
image2d<int> out(ima.domain());
level::abs(ima, out);
box_fwd_piter_<point2d> p(ima.domain());
Index: milena/tests/level/replace.cc
--- milena/tests/level/replace.cc (revision 2747)
+++ milena/tests/level/replace.cc (working copy)
@@ -47,7 +47,7 @@
};
- image2d<int> rhs = make::image2d(vs);
+ image2d<int> rhs = make::image(vs);
level::replace(rhs, 10, 11);
@@ -58,6 +58,6 @@
{ 8, 9, 11 },
};
- mln_assertion(make::image2d(vs_ref) == rhs);
+ mln_assertion(make::image(vs_ref) == rhs);
}
Index: milena/tests/level/stretch.cc
--- milena/tests/level/stretch.cc (revision 2747)
+++ milena/tests/level/stretch.cc (working copy)
@@ -47,7 +47,7 @@
{ 1000, 2000, 3000 },
{ 1000, 2000, 3000 }
};
- image2d<int> ima(make::image2d(vs));
+ image2d<int> ima(make::image(vs));
image2d<int_u8> out(3, 3);
@@ -57,7 +57,7 @@
{ 0, 127, 255 }
};
- image2d<int_u8> ref(make::image2d(ws));
+ image2d<int_u8> ref(make::image(ws));
level::stretch(ima, out);
box_fwd_piter_<point2d> p(out.domain());
for_all(p)
Index: milena/tests/level/apply.cc
--- milena/tests/level/apply.cc (revision 2747)
+++ milena/tests/level/apply.cc (working copy)
@@ -47,7 +47,7 @@
{ 6, 6, 6 }
};
- image2d<int> ref(make::image2d(vs));
+ image2d<int> ref(make::image(vs));
debug::iota(ima);
level::apply(ima, fun::v2v::saturate<int>(2, 6));
box_fwd_piter_<point2d> p(ima.domain());
Index: milena/tests/level/compare.cc
--- milena/tests/level/compare.cc (revision 2747)
+++ milena/tests/level/compare.cc (working copy)
@@ -57,7 +57,7 @@
};
- rhs = make::image2d(vs);
+ rhs = make::image(vs);
mln_assertion(! (lhs == rhs));
mln_assertion( (lhs <= rhs));
@@ -80,7 +80,7 @@
};
- rhs = make::image2d(ws);
+ rhs = make::image(ws);
mln_assertion(! (lhs == rhs));
mln_assertion( (lhs <= rhs));
Index: milena/tests/level/saturate.cc
--- milena/tests/level/saturate.cc (revision 2747)
+++ milena/tests/level/saturate.cc (working copy)
@@ -47,7 +47,7 @@
{ 6, 6, 6 }
};
- image2d<int> ref(make::image2d(vs));
+ image2d<int> ref(make::image(vs));
debug::iota(ima);
level::saturate_inplace(ima, 2, 6);
box_fwd_piter_<point2d> p(ima.domain());
Index: milena/tests/arith/minus.cc
--- milena/tests/arith/minus.cc (revision 2747)
+++ milena/tests/arith/minus.cc (working copy)
@@ -51,7 +51,7 @@
{6, 7, 8}
};
- image2d<int> ref(make::image2d(vs));
+ image2d<int> ref(make::image(vs));
mln_assertion (ima - 1 == ref);
}
Index: milena/tests/arith/times.cc
--- milena/tests/arith/times.cc (revision 2747)
+++ milena/tests/arith/times.cc (working copy)
@@ -51,7 +51,7 @@
{14, 16, 18}
};
- image2d<int> ref(make::image2d(vs));
+ image2d<int> ref(make::image(vs));
mln_assertion (ima * 2 == ref);
}
Index: milena/tests/arith/plus.cc
--- milena/tests/arith/plus.cc (revision 2747)
+++ milena/tests/arith/plus.cc (working copy)
@@ -52,7 +52,7 @@
};
ima += 2;
- image2d<int> ref(make::image2d(vs));
+ image2d<int> ref(make::image(vs));
mln_assertion (ima + 1 == ref);
}
Index: milena/tests/arith/revert.cc
--- milena/tests/arith/revert.cc (revision 2747)
+++ milena/tests/arith/revert.cc (working copy)
@@ -52,7 +52,7 @@
{ -8, -9, -10}
};
- image2d<int> ref(make::image2d(vs));
+ image2d<int> ref(make::image(vs));
arith::revert_inplace(ima);
mln_assertion (ima == ref);
Index: milena/tests/accu/compute.cc
--- milena/tests/accu/compute.cc (revision 2747)
+++ milena/tests/accu/compute.cc (working copy)
@@ -48,7 +48,7 @@
// {6,5,4},
// {3,2,1} };
-// image2d<int_u8> ima = make::image2d(vs);
+// image2d<int_u8> ima = make::image(vs);
// int a = accu::compute<accu::min>(ima);
// std::cout << a << std::endl;
Index: milena/tests/geom/resize.cc
--- milena/tests/geom/resize.cc (revision 2747)
+++ milena/tests/geom/resize.cc (working copy)
@@ -60,7 +60,7 @@
{105, 107, 109, 111, 113, 115, 117, 119}
};
- image2d<int> ref(make::image2d(ws));
+ image2d<int> ref(make::image(ws));
mln_assertion (out == ref);
}
Index: milena/tests/geom/seed2tiling_roundness.cc
--- milena/tests/geom/seed2tiling_roundness.cc (revision 2747)
+++ milena/tests/geom/seed2tiling_roundness.cc (working copy)
@@ -82,9 +82,9 @@
{1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
};
- image2d<unsigned> ima (make::image2d(vs));
+ image2d<unsigned> ima (make::image(vs));
image2d<unsigned> out = geom::seeds2tiling_roundness(ima, w_win, max, c4());
- image2d<unsigned> ref (make::image2d(ws));
+ image2d<unsigned> ref (make::image(ws));
mln_assertion (ref == out);
}
Index: milena/tests/geom/seed2tiling.cc
--- milena/tests/geom/seed2tiling.cc (revision 2747)
+++ milena/tests/geom/seed2tiling.cc (working copy)
@@ -78,8 +78,8 @@
{1 ,1 ,1 ,1 ,1 ,1 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3}
};
- image2d<unsigned> ima (make::image2d(vs));
+ image2d<unsigned> ima (make::image(vs));
image2d<unsigned> out = geom::seeds2tiling(ima, c4());
- image2d<unsigned> ref (make::image2d(ws));
+ image2d<unsigned> ref (make::image(ws));
mln_assertion (ref == out);
}
Index: milena/tests/display/color_pretty.cc
--- milena/tests/display/color_pretty.cc (revision 2747)
+++ milena/tests/display/color_pretty.cc (working copy)
@@ -63,7 +63,7 @@
{value::rgb8(255, 0, 0), value::rgb8(51, 51, 51)}
};
- image2d<value::rgb8> ref (make::image2d(vs));
+ image2d<value::rgb8> ref (make::image(vs));
mln_assertion (ref == out);
}
@@ -87,7 +87,7 @@
{value::rgb8(0, 0, 255), value::rgb8(0, 0, 0)}
};
- image2d<value::rgb8> ref (make::image2d(vs));
+ image2d<value::rgb8> ref (make::image(vs));
mln_assertion (ref == out);
}
}
Index: milena/tests/logical/or.cc
--- milena/tests/logical/or.cc (revision 2747)
+++ milena/tests/logical/or.cc (working copy)
@@ -57,9 +57,9 @@
{1, 1, 1}
};
- image2d<bool> ima1 (make::image2d(vs));
- image2d<bool> ima2 (make::image2d(us));
- image2d<bool> ref (make::image2d(ws));
+ image2d<bool> ima1 (make::image(vs));
+ image2d<bool> ima2 (make::image(us));
+ image2d<bool> ref (make::image(ws));
mln_assertion (logical::or_(ima1, ima2) == ref);
}
Index: milena/tests/logical/not.cc
--- milena/tests/logical/not.cc (revision 2747)
+++ milena/tests/logical/not.cc (working copy)
@@ -51,8 +51,8 @@
{0, 1, 0}
};
- image2d<bool> ima (make::image2d(vs));
- image2d<bool> ref (make::image2d(ws));
+ image2d<bool> ima (make::image(vs));
+ image2d<bool> ref (make::image(ws));
mln_assertion (logical::not_(ima) == ref);
}
Index: milena/tests/logical/and_not.cc
--- milena/tests/logical/and_not.cc (revision 2747)
+++ milena/tests/logical/and_not.cc (working copy)
@@ -57,8 +57,8 @@
{1, 0, 1}
};
- image2d<bool> ima1 (make::image2d(vs));
- image2d<bool> ima2 (make::image2d(us));
- image2d<bool> ref (make::image2d(ws));
+ image2d<bool> ima1 (make::image(vs));
+ image2d<bool> ima2 (make::image(us));
+ image2d<bool> ref (make::image(ws));
mln_assertion (logical::and_not(ima1, ima2) == ref);
}
Index: milena/tests/logical/and.cc
--- milena/tests/logical/and.cc (revision 2747)
+++ milena/tests/logical/and.cc (working copy)
@@ -57,9 +57,9 @@
{1, 0, 1}
};
- image2d<bool> ima1 (make::image2d(vs));
- image2d<bool> ima2 (make::image2d(us));
- image2d<bool> ref (make::image2d(ws));
+ image2d<bool> ima1 (make::image(vs));
+ image2d<bool> ima2 (make::image(us));
+ image2d<bool> ref (make::image(ws));
mln_assertion (logical::and_(ima1, ima2) == ref);
}
Index: milena/tests/canvas/chamfer.cc
--- milena/tests/canvas/chamfer.cc (revision 2747)
+++ milena/tests/canvas/chamfer.cc (working copy)
@@ -69,7 +69,7 @@
{16, 14, 12, 10, 8, 10, 12, 14, 16}
};
- image2d<unsigned> ref (make::image2d(r));
+ image2d<unsigned> ref (make::image(r));
mln_assertion (out == ref);
}
@@ -92,7 +92,7 @@
{12, 11, 10, 9, 8, 9, 10, 11, 12}
};
- image2d<unsigned> ref (make::image2d(r));
+ image2d<unsigned> ref (make::image(r));
mln_assertion (out == ref);
}
@@ -118,7 +118,7 @@
{12, 10, 9, 8, 8, 8, 9, 10, 12}
};
- image2d<unsigned> ref (make::image2d(r));
+ image2d<unsigned> ref (make::image(r));
mln_assertion (out == ref);
}
Index: milena/tests/util/tree_to_image.cc
--- milena/tests/util/tree_to_image.cc (revision 2747)
+++ milena/tests/util/tree_to_image.cc (working copy)
@@ -133,6 +133,6 @@
};
- image2d<int_u8> ref (make::image2d(vs));
+ image2d<int_u8> ref (make::image(vs));
mln_assertion(ref == output);
}
Index: milena/tests/util/lemmings.cc
--- milena/tests/util/lemmings.cc (revision 2747)
+++ milena/tests/util/lemmings.cc (working copy)
@@ -46,7 +46,7 @@
{3, 3, 4, 4},
{3, 3, 4, 4}};
- I ima = make::image2d<int>(vals);
+ I ima = make::image<int>(vals);
mln_site_(I) pt1(1, 0);
mln_site_(I) pt2(0, 2);
Index: milena/tests/util/tree_fast_to_image.cc
--- milena/tests/util/tree_fast_to_image.cc (revision 2747)
+++ milena/tests/util/tree_fast_to_image.cc (working copy)
@@ -132,6 +132,6 @@
};
debug::printl (output);
- image2d<int_u8> ref (make::image2d(vs));
+ image2d<int_u8> ref (make::image(vs));
mln_assertion(ref == output);
}
Index: milena/tests/labeling/compute.cc
--- milena/tests/labeling/compute.cc (revision 2747)
+++ milena/tests/labeling/compute.cc (working copy)
@@ -52,7 +52,7 @@
{2, 0, 3, 3, 3},
{2, 0, 0, 0, 0}
};
- image2d<int_u8> ima = make::image2d(vals);
+ image2d<int_u8> ima = make::image(vals);
int_u8 nlabels = 3;
accu::sum<int_u8> sum;
Index: milena/mln/core/image/image1d.hh
--- milena/mln/core/image/image1d.hh (revision 2747)
+++ milena/mln/core/image/image1d.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -600,6 +601,6 @@
} // end of namespace mln
-# include <mln/make/image1d.hh>
+# include <mln/make/image.hh>
#endif // ! MLN_CORE_IMAGE_IMAGE1D_HH
Index: milena/mln/core/image/image2d.hh
--- milena/mln/core/image/image2d.hh (revision 2747)
+++ milena/mln/core/image/image2d.hh (working copy)
@@ -31,6 +31,8 @@
/// \file mln/core/image/image2d.hh
/// \brief Definition of the basic mln::image2d class.
+///
+/// \todo Re-activate include at EOF when make::image2d is up again.
# include <mln/core/internal/image_primary.hh>
# include <mln/core/internal/fixme.hh>
@@ -687,6 +689,9 @@
} // end of namespace mln
-# include <mln/make/image2d.hh>
+
+# include <mln/make/image.hh>
+// # include <mln/make/image2d.hh>
+
#endif // ! MLN_CORE_IMAGE_IMAGE2D_HH
Index: milena/mln/core/w_window.hh
--- milena/mln/core/w_window.hh (revision 2747)
+++ milena/mln/core/w_window.hh (working copy)
@@ -37,12 +37,14 @@
# include <mln/core/concept/weighted_window.hh>
# include <mln/core/concept/image.hh>
+# include <mln/core/site_set/box.hh>
# include <mln/core/window.hh>
# include <mln/core/dpsites_piter.hh>
# include <mln/value/ops.hh>
# include <mln/util/ord.hh>
# include <mln/metal/converts_to.hh>
+# include <mln/metal/math/root.hh>
# include <mln/literal/zero.hh>
# include <mln/convert/to.hh>
@@ -150,7 +152,7 @@
template <typename V, unsigned S, typename D, typename W>
void
- from_to(const V (&values)[S], w_window<D,W>& to);
+ from_to(const V (&weight)[S], w_window<D,W>& to);
} // end of namespace mln::convert
@@ -343,18 +345,26 @@
to.insert(ima(p), convert::to<D>(p));
}
-// template <typename V, unsigned S, typename D, typename W>
-// void
-// from_to(const V (&values)[S], w_window<D,W>& to)
-// {
-// enum { d = D::dim,
-// s = mlc_root(d,S)::value / 2 };
-// metal::bool_<(mlc_pow_int(2 * s + 1, d) == S)>::check();
-// to.clear();
-// D dp;
-// dp.set_all(-s);
-// FIXME
-// }
+ template <typename V, unsigned S, typename D, typename W>
+ void
+ from_to(const V (&weight)[S], w_window<D,W>& to)
+ {
+ mlc_converts_to(V, W)::check();
+ enum { d = D::dim,
+ s = mlc_root(d,S)::value / 2 };
+ metal::bool_<(mlc_pow_int(2 * s + 1, d) == S)>::check();
+ to.clear();
+ typedef mln_site(D) P;
+ box<P> b(all_to(-s), all_to(+s));
+ mln_fwd_piter(box<P>) p(b);
+ unsigned i = 0;
+ for_all(p)
+ {
+ if (weight[i] != literal::zero)
+ to.insert(weight[i], convert::to<D>(p));
+ ++i;
+ }
+ }
} // end of namespace mln::convert
Index: milena/mln/make/image.hh
--- milena/mln/make/image.hh (revision 2746)
+++ milena/mln/make/image.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,14 +26,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MAKE_IMAGE2D_HH
-# define MLN_MAKE_IMAGE2D_HH
+#ifndef MLN_MAKE_IMAGE_HH
+# define MLN_MAKE_IMAGE_HH
-/*! \file mln/make/image2d.hh
+/*! \file mln/make/image.hh
*
- * \brief Routine to create an mln::image2d in the 2D case.
+ * \brief Routine to create an image from various input.
*/
+# include <mln/core/image/image1d.hh>
# include <mln/core/image/image2d.hh>
@@ -42,6 +44,16 @@
namespace make
{
+ /*! \brief Create an image1d from an 1d array of values.
+ *
+ * \param[in] values 1d array.
+ *
+ * \return A 1D image.
+ */
+ template <typename V, unsigned L>
+ mln::image1d<V> image1d(V (&values)[L]);
+
+
/*! \brief Create an image2d from an 2d array of values.
*
* \param[in] values 2d array.
@@ -49,15 +61,25 @@
* \return A 2D image.
*/
template <typename V, unsigned R, unsigned C>
- mln::image2d<V> image2d(V (&values)[R][C]);
+ mln::image2d<V> image(V (&values)[R][C]);
# ifndef MLN_INCLUDE_ONLY
+ template <typename V, unsigned L>
+ mln::image1d<V>
+ image1d(V (&values)[L])
+ {
+ mlc_bool(L != 0)::check();
+ mln::image1d<V> tmp(L);
+ for (unsigned ind = 0; ind < L; ++ind)
+ tmp(point1d(ind)) = values[ind];
+ return tmp;
+ }
+
template <typename V, unsigned R, unsigned C>
- inline
mln::image2d<V>
- image2d(V (&values)[R][C])
+ image(V (&values)[R][C])
{
mln::image2d<V> tmp(R, C);
for (unsigned row = 0; row < R; ++row)
@@ -73,4 +95,4 @@
} // end of namespace mln
-#endif // ! MLN_MAKE_IMAGE2D_HH
+#endif // ! MLN_MAKE_IMAGE_HH
Property changes on: milena/mln/make/image.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: milena/mln/make/w_window2d.hh
--- milena/mln/make/w_window2d.hh (revision 2747)
+++ milena/mln/make/w_window2d.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -33,10 +33,9 @@
* \brief Routine to create an mln::w_window in the 2D case.
*/
-# include <cmath>
-
# include <mln/core/w_window.hh>
# include <mln/core/alias/dpoint2d.hh>
+# include <mln/metal/math/sqrt.hh>
namespace mln
@@ -49,32 +48,25 @@
*
* \param[in] weights Array.
*
- * \pre The array size, \c M, has to be a square of an odd integer.
+ * \pre The array size, \c S, has to be a square of an odd integer.
*
* \return A 2D weighted window.
*/
- template <typename W, unsigned M>
- mln::w_window<mln::dpoint2d, W> w_window2d(W (&weights)[M]);
+ template <typename W, unsigned S>
+ mln::w_window<mln::dpoint2d, W> w_window2d(W (&weights)[S]);
# ifndef MLN_INCLUDE_ONLY
- template <typename W, unsigned M>
+ template <typename W, unsigned S>
inline
mln::w_window<mln::dpoint2d, W>
- w_window2d(W (&weights)[M])
+ w_window2d(W (&weights)[S])
{
- int h = unsigned(std::sqrt(float(M))) / 2;
- mln_precondition((2 * h + 1) * (2 * h + 1) == M);
+ enum { s = mlc_sqrt_int(S) / 2 };
+ metal::bool_<(((2 * s + 1) * (2 * s + 1)) == S)>::check();
mln::w_window<mln::dpoint2d, W> tmp;
- unsigned i = 0;
- for (int row = - h; row <= h; ++row)
- for (int col = - h; col <= h; ++col)
- {
- if (weights[i] != 0)
- tmp.insert(weights[i], dpoint2d(row, col));
- i++;
- }
+ convert::from_to(weights, tmp);
return tmp;
}
Index: milena/mln/make/all.hh
--- milena/mln/make/all.hh (revision 2747)
+++ milena/mln/make/all.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -47,6 +48,7 @@
# include <mln/make/box2d_h.hh>
# include <mln/make/box3d.hh>
# include <mln/make/dpoint2d_h.hh>
+# include <mln/make/image.hh>
# include <mln/make/mat.hh>
# include <mln/make/pixel.hh>
# include <mln/make/pix.hh>
Index: milena/mln/convert/from_to.hxx
--- milena/mln/convert/from_to.hxx (revision 2747)
+++ milena/mln/convert/from_to.hxx (working copy)
@@ -138,11 +138,18 @@
void
from_to(const Gpoint<P>& from, mln_delta(P)& to);
+
// Image -> w_window
template <typename I, typename D, typename W>
void
from_to(const Image<I>& from, w_window<D,W>& to);
+ // C-array -> w_window
+ template <typename V, unsigned S, typename D, typename W>
+ void
+ from_to(const V (&weight)[S], w_window<D,W>& to);
+
+
// neighb<W> -> W
template <typename W>
void
Index: milena/mln/canvas/browsing/directional.hh
--- milena/mln/canvas/browsing/directional.hh (revision 2747)
+++ milena/mln/canvas/browsing/directional.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -105,7 +105,6 @@
void
directional_t::operator()(F& f) const
{
- trace::entering("canvas::browsing::directional");
mln_precondition(f.dir < f.dim);
typedef typename F::I I;
@@ -115,9 +114,7 @@
f.p = pmin;
- trace::entering("canvas::browsing::directional::init");
f.init();
- trace::exiting("canvas::browsing::directional::init");
do
{
@@ -147,10 +144,7 @@
} while (f.p != pmin);
- trace::entering("canvas::browsing::directional::final");
f.final();
- trace::exiting("canvas::browsing::directional::final");
- trace::exiting("canvas::browsing::directional");
}
# endif // ! MLN_INCLUDE_ONLY
1
0
From: Vivien Delmon <vivien.delmon(a)lrde.epita.fr>
To: olena-patches(a)lrde.epita.fr
Subject: milena r2746: Fix previous patch
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-10-31 Vivien Delmon <vivien.delmon(a)lrde.epita.fr>
Fix previous patch.
* mln/morpho/erosion.spe.hh: Remove concept.
---
erosion.spe.hh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh
===================================================================
--- branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh (revision 2745)
+++ branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh (revision 2746)
@@ -473,7 +473,7 @@
const I& input;
const W& win;
mln_concrete(I) output;
- Accumulator<A> accu;
+ A accu;
mln_psite(I) p;
1
0
31 Oct '08
Thierry Geraud wrote:
> Index: mln/morpho/erosion.hh
> --- mln/morpho/erosion.hh (revision 2743)
> +++ mln/morpho/erosion.hh (working copy)
> @@ -52,6 +52,25 @@
>
> # ifndef MLN_INCLUDE_ONLY
>
> +
> + namespace internal
> + {
> +
> + template <typename I, typename W>
> + inline
> + void
> + erosion_tests(const Image<I>& input_, const Window<W>& win_)
> + {
> + const I& input = exact(input_);
> + const W& win = exact(win_);
> +
> + mln_precondition(exact(input).has_data());
> + mln_precondition(! exact(win).is_empty());
> + }
> +
> + } // end of mln::morpho::internal
> +
> +
Si on est en -DNDEBUG les2 variables créées ne servent pas.
../milena/mln/morpho/erosion.hh:64: warning: unused variable 'input'
../milena/mln/morpho/erosion.hh:65: warning: unused variable 'win'
--
Vivien Delmon
- ZiXiS -
CSI 2009
1
0
From: Vivien Delmon <vivien.delmon(a)lrde.epita.fr>
To: olena-patches(a)lrde.epita.fr
Subject: milena r2745: Generalize erosion in 2d for any accumulator
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-10-31 Vivien Delmon <vivien.delmon(a)lrde.epita.fr>
Generalize erosion in 2d for any accumulator.
* mln/morpho/erosion.spe.hh: Add accumulator type as parameter and
rename min as accu.
---
erosion.spe.hh | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
Index: branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh
===================================================================
--- branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh (revision 2744)
+++ branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh (revision 2745)
@@ -463,17 +463,17 @@
}
- template <typename I, typename W>
+ template <typename I, typename W, typename A>
struct erosion_arbitrary_2d_functor
{
- typedef erosion_arbitrary_2d_functor<I,W> self;
+ typedef erosion_arbitrary_2d_functor<I,W, A> self;
typedef void (self::*move_fun)();
typedef mln_deduce(I, psite, delta) dpsite;
const I& input;
const W& win;
mln_concrete(I) output;
- accu::min_h<mln_value(I)> min;
+ Accumulator<A> accu;
mln_psite(I) p;
@@ -503,7 +503,7 @@
erosion_arbitrary_2d_functor(const I& input, const W& win)
: input(input),
win(win),
- min(),
+ accu(),
win_left_fwd(win::shift(win, mln::left) - win),
win_right_fwd(win - win::shift(win, mln::left)),
@@ -557,48 +557,48 @@
{
extension::adjust_fill(input, win, mln_max(mln_value(I)));
initialize(output, input);
- min.init();
+ accu.init();
p = input.domain().pmin() - dps[0];
mln_qiter(W) q(win, p);
for_all(q)
- min.take(input(q));
+ accu.take(input(q));
p = input.domain().pmin();
}
void right()
{
for_all(q_l_fwd)
- min.untake(input(q_l_fwd));
+ accu.untake(input(q_l_fwd));
for_all(q_r_fwd)
- min.take(input(q_r_fwd));
- output(p) = min;
+ accu.take(input(q_r_fwd));
+ output(p) = accu;
}
void left()
{
for_all(q_r_bkd)
- min.untake(input(q_r_bkd));
+ accu.untake(input(q_r_bkd));
for_all(q_l_bkd)
- min.take(input(q_l_bkd));
- output(p) = min;
+ accu.take(input(q_l_bkd));
+ output(p) = accu;
}
void down()
{
for_all(q_top_down)
- min.untake(input(q_top_down));
+ accu.untake(input(q_top_down));
for_all(q_bot_down)
- min.take(input(q_bot_down));
- output(p) = min;
+ accu.take(input(q_bot_down));
+ output(p) = accu;
}
void up()
{
for_all(q_bot_up)
- min.untake(input(q_bot_up));
+ accu.untake(input(q_bot_up));
for_all(q_top_up)
- min.take(input(q_top_up));
- output(p) = min;
+ accu.take(input(q_top_up));
+ output(p) = accu;
}
};
@@ -610,7 +610,7 @@
{
trace::entering("morpho::impl:erosion_arbitrary_2d");
- typedef erosion_arbitrary_2d_functor<I, W> F;
+ typedef erosion_arbitrary_2d_functor<I, W, accu::min_h<mln_value(I)> > F;
F f(exact(input), exact(win));
canvas::browsing::snake_generic(f);
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Revamp linear convolution.
* mln/linear/convolve.hh: Re-vamp.
* tests/linear/convolve.cc: Update.
* mln/core/routine/primary.hh: New; not completed yet.
* mln/core/routine/all.hh: Update.
* mln/core/concept/window.hh (todo): New.
* mln/morpho/erosion.hh (tests): New.
mln/core/concept/window.hh | 3
mln/core/routine/all.hh | 7 -
mln/core/routine/primary.hh | 100 ++++++++++++++++++++++
mln/linear/convolve.hh | 198 +++++++++++++++++++++++++-------------------
mln/morpho/erosion.hh | 21 ++++
tests/linear/convolve.cc | 8 -
6 files changed, 245 insertions(+), 92 deletions(-)
Index: tests/linear/convolve.cc
--- tests/linear/convolve.cc (revision 2743)
+++ tests/linear/convolve.cc (working copy)
@@ -54,7 +54,6 @@
image2d<int_u8> lena;
io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
- image2d<int_u8> out(lena.domain());
float ws[] = { .04, .04, .04, .04, .04,
.04, .04, .04, .04, .04,
@@ -63,9 +62,10 @@
.04, .04, .04, .04, .04 };
w_window2d_float w = make::w_window2d(ws);
- image2d<float> tmp(lena.domain());
- linear::convolve(lena, w, tmp);
- level::transform(tmp, math::round<int_u8>(), out);
+// image2d<float> tmp = linear::convolve(lena, w);
+// image2d<int_u8> out = level::transform(tmp, math::round<int_u8>());
+
+ image2d<int_u8> out = linear::convolve(lena, w);
io::pgm::save(out, "out.pgm");
}
Index: mln/core/routine/primary.hh
--- mln/core/routine/primary.hh (revision 0)
+++ mln/core/routine/primary.hh (revision 0)
@@ -0,0 +1,100 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_ROUTINE_PRIMARY_HH
+# define MLN_CORE_ROUTINE_PRIMARY_HH
+
+/*! \file mln/core/routine/primary.hh
+ *
+ * \brief FIXME
+ *
+ * \todo We also need to get the extension image to handle border
+ * routines.
+ */
+
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ /// FIXME: Doc!
+ template <typename I>
+ void primary(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ // Primary_type.
+
+ template <typename I> struct primary_type;
+
+ template <typename I, typename C>
+ struct primary_type_helper
+ {
+ typedef typename primary_type<mln_delegatee(I)>::ret ret;
+ };
+
+ template <typename I>
+ struct primary_type_helper< I, mln::trait::image::category::primary >
+ {
+ typedef I ret;
+ };
+
+ template <typename I>
+ struct primary_type
+ {
+ typedef mln_trait_image_category(I) Cat;
+ typedef typename primary_type_helper<I, Cat>::ret ret;
+ };
+
+
+ // Routine.
+
+ } // end of namespace mln::internal
+
+
+
+ // Facade.
+
+ template <typename I>
+ inline
+ void primary(const Image<I>&)
+ {
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_ROUTINE_PRIMARY_HH
Index: mln/core/routine/all.hh
--- mln/core/routine/all.hh (revision 2743)
+++ mln/core/routine/all.hh (working copy)
@@ -36,10 +36,11 @@
*/
-// # include <mln/core/routine/clone.hh>
-// # include <mln/core/routine/exact.hh>
+# include <mln/core/routine/clone.hh>
+# include <mln/core/routine/exact.hh>
# include <mln/core/routine/extend.hh>
-// # include <mln/core/routine/initialize.hh>
+# include <mln/core/routine/initialize.hh>
+# include <mln/core/routine/primary.hh>
#endif // ! MLN_CORE_ROUTINE_ALL_HH
Index: mln/core/concept/window.hh
--- mln/core/concept/window.hh (revision 2743)
+++ mln/core/concept/window.hh (working copy)
@@ -34,6 +34,9 @@
* \todo Operator== should test if the cmp is possible.
*
* \todo Add an is_valid() method.
+ *
+ * \todo The is_centered() method could also exist when the window is
+ * not regular...
*/
# include <mln/core/concept/object.hh>
Index: mln/linear/convolve.hh
--- mln/linear/convolve.hh (revision 2743)
+++ mln/linear/convolve.hh (working copy)
@@ -31,6 +31,8 @@
/*! \file mln/linear/convolve.hh
*
* \brief Convolution.
+ *
+ * \todo Introduce an accumulator.
*/
# include <mln/core/concept/image.hh>
@@ -56,107 +58,90 @@
*
* \pre output.domain = input.domain
*/
- template <typename I, typename W, typename O>
- void convolve(const Image<I>& input, const Weighted_Window<W>& w_win,
- Image<O>& output);
+ template <typename I, typename W>
+ mln_concrete(I)
+ convolve(const Image<I>& input, const Weighted_Window<W>& w_win);
+
# ifndef MLN_INCLUDE_ONLY
- namespace impl
+ // Tests.
+
+ namespace internal
+ {
+
+ template <typename I, typename W>
+ void
+ convolve_tests(const Image<I>& input,
+ const Weighted_Window<W>& w_win)
{
- /* FIXME: We must clean up the interface of
- mln::linear::impl::convolve_:
+ mln_precondition(exact(input).has_data());
+ // mln_precondition(exact(w_win).is_valid());
+ }
- - either allow certain patterns of speed traits (e.g.,
- any/any, fastest/fastest, fastest/any, etc.). In this
- case, the generic version should abort at compile time;
+ } // end of namespace mln::linear::internal
- - or accept all combinations (which is the current case), and
- default to the slowest one (presumably any/any).
- */
- // Fwd decl.
- template <typename I, typename W, typename O>
- inline
- void convolve_(const I& input,
- const Weighted_Window<W>& w_win_,
- O& output);
-
- /// Default version, delegating to the generic version.
- template <typename Speed_I, typename I, typename W,
- typename Speed_O, typename O>
- inline
- void convolve_(Speed_I, const I& input,
- const Weighted_Window<W>& w_win_,
- Speed_O, O& output)
- {
- /* Don't delegate using such a call:
-
- \code
- impl::convolve_(trait::image::speed::any(), input,
- w_win_,
- trait::image::speed::any(), output);
- \endcode
-
- since it would end up with infinite recursion. The reason
- is that the compiler would select this function (in which
- you read this very comment), instead of the next one (with
- input and output speed traits set to `any'), to resolve the
- call. This is because C++ overloading rules favor the
- generic function over the more specialized one. And we
- cannot use explicit partial specialization, since it just
- doesn't exist for functions.
-
- Hence the chosen solution: create and call another
- overloading for mln::linear::impl::convolve_, with no
- unnatural selection behavior. */
- impl::convolve_(input, w_win_, output);
- }
-
- template <typename I, typename W, typename O>
- inline
- void convolve_(trait::image::speed::any, const I& input,
- const Weighted_Window<W>& w_win_,
- trait::image::speed::any, O& output)
- {
- // Delegate the call to the generic version.
- impl::convolve_(input, w_win_, output);
- }
-
- /// A factored implementation of the most generic version of
- /// mln::linear::impl::convolve_.
- template <typename I, typename W, typename O>
- inline
- void convolve_(const I& input,
- const Weighted_Window<W>& w_win_,
- O& output)
+ // Implementation.
+
+ namespace impl
+ {
+
+ namespace generic
{
+
+ template <typename I, typename W>
+ mln_concrete(I)
+ convolve(const Image<I>& input_,
+ const Weighted_Window<W>& w_win_)
+ {
+ trace::entering("linear::impl::generic::convolve");
+
+ const I& input = exact(input_);
const W& w_win = exact(w_win_);
+ internal::convolve_tests(input, w_win);
+
+ // extension::adjust_duplicate(input, w_win);
+
+ typedef mln_concrete(I) O;
+ O output;
+ initialize(output, input);
mln_piter(I) p(input.domain());
mln_qiter(W) q(w_win, p);
for_all(p)
{
- mln_value(O) v = 0;
+ mln_value(O) v = literal::zero;
for_all(q) if (input.has(q))
v += input(q) * q.w();
output(p) = v;
}
+
+ trace::exiting("linear::impl::generic::convolve");
+ return output;
}
- template <typename I, typename W, typename O>
- inline
- void convolve_(trait::image::speed::fastest, const I& input,
- const Weighted_Window<W>& w_win_,
- trait::image::speed::fastest, O& output)
+ } // end of namespace mln::linear::impl::generic
+
+
+ template <typename I, typename W>
+ mln_concrete(I)
+ convolve_fastest(const Image<I>& input_,
+ const Weighted_Window<W>& w_win_)
{
+ trace::entering("linear::impl::convolve_fastest");
+
+ const I& input = exact(input_);
const W& w_win = exact(w_win_);
+ internal::convolve_tests(input, w_win);
- border::resize(input, w_win.delta());
- border::duplicate(input);
+ // extension::adjust_duplicate(input, w_win);
+ typedef mln_concrete(I) O;
+ O output;
+ initialize(output, input);
mln_pixter(O) p_out(output);
mln_pixter(const I) p(input);
@@ -164,28 +149,71 @@
for_all_2(p, p_out)
{
- mln_value(O) v = 0;
+ mln_value(O) v = literal::zero;
unsigned i = 0;
for_all(q)
v += w_win.w(i++) * q.val();
p_out.val() = v;
}
+
+ trace::exiting("linear::impl::convolve_fastest");
+ return output;
}
} // end of namespace mln::linear::impl
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I, typename W>
+ mln_concrete(I)
+ convolve_dispatch(trait::image::speed::any,
+ const Image<I>& input,
+ const Weighted_Window<W>& w_win)
+ {
+ return impl::generic::convolve(input, w_win);
+ }
+
+ template <typename I, typename W>
+ mln_concrete(I)
+ convolve_dispatch(trait::image::speed::fastest,
+ const Image<I>& input,
+ const Weighted_Window<W>& w_win)
+ {
+ return impl::convolve_fastest(input, w_win);
+ }
+
+ template <typename I, typename W>
+ mln_concrete(I)
+ convolve_dispatch(const Image<I>& input,
+ const Weighted_Window<W>& w_win)
+ {
+ return convolve_dispatch(mln_trait_image_speed(I)(),
+ input, w_win);
+ }
+
+ } // end of namespace mln::linear::internal
+
+
// Facade.
- template <typename I, typename W, typename O>
- inline
- void convolve(const Image<I>& input, const Weighted_Window<W>& w_win,
- Image<O>& output)
- {
- mln_precondition(exact(output).domain() == exact(input).domain());
- impl::convolve_(mln_trait_image_speed(I)(), exact(input),
- exact(w_win),
- mln_trait_image_speed(O)(), exact(output));
+ template <typename I, typename W>
+ mln_concrete(I)
+ convolve(const Image<I>& input, const Weighted_Window<W>& w_win)
+ {
+ trace::entering("linear::convolve");
+
+ internal::convolve_tests(input, w_win);
+
+ mln_concrete(I) output;
+ output = internal::convolve_dispatch(mln_trait_image_speed(I)(),
+ input, w_win);
+
+ trace::exiting("linear::convolve");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/morpho/erosion.hh
--- mln/morpho/erosion.hh (revision 2743)
+++ mln/morpho/erosion.hh (working copy)
@@ -52,6 +52,25 @@
# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename I, typename W>
+ inline
+ void
+ erosion_tests(const Image<I>& input_, const Window<W>& win_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+
+ mln_precondition(exact(input).has_data());
+ mln_precondition(! exact(win).is_empty());
+ }
+
+ } // end of mln::morpho::internal
+
+
namespace impl
{
@@ -69,6 +88,7 @@
const I& input = exact(input_);
const W& win = exact(win_);
+ internal::erosion_tests(input, win);
extension::adjust_fill(input, win, mln_max(mln_value(I)));
@@ -139,6 +159,7 @@
mln_precondition(exact(input).has_data());
mln_precondition(! exact(win).is_empty());
+ internal::erosion_tests(input, win);
mln_concrete(I) output = internal::erosion_dispatch(input, win);
if (exact(win).is_centered())
1
0