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
- 9625 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add routines to deal with images of accumulators.
* mln/accu/image: New directory.
* mln/accu/image/init.hh: New.
* mln/accu/image/take.hh: New.
* mln/accu/image/set_value.hh: New.
* mln/accu/image/all.hh: New.
* mln/accu/image/take_as_init.hh: New.
* mln/accu/image/to_result.hh: New.
* mln/accu/all.hh: Update.
* tests/accu/image: New.
* tests/accu/image/to_result.cc: New.
* tests/accu/image/init.cc: New.
* tests/accu/image/take.cc: New.
* tests/accu/image/Makefile.am: New.
* tests/accu/image/set_value.cc: New.
* tests/accu/image/take_as_init.cc: New.
* tests/accu/Makefile.am: Update.
mln/accu/all.hh | 8 +
mln/accu/image/all.hh | 56 +++++++++++
mln/accu/image/init.hh | 162 +++++++++++++++++++++++++++++++++
mln/accu/image/set_value.hh | 166 ++++++++++++++++++++++++++++++++++
mln/accu/image/take.hh | 186 +++++++++++++++++++++++++++++++++++++++
mln/accu/image/take_as_init.hh | 166 ++++++++++++++++++++++++++++++++++
mln/accu/image/to_result.hh | 178 +++++++++++++++++++++++++++++++++++++
tests/accu/Makefile.am | 3
tests/accu/image/Makefile.am | 18 +++
tests/accu/image/init.cc | 45 +++++++++
tests/accu/image/set_value.cc | 48 ++++++++++
tests/accu/image/take.cc | 58 ++++++++++++
tests/accu/image/take_as_init.cc | 48 ++++++++++
tests/accu/image/to_result.cc | 49 ++++++++++
14 files changed, 1189 insertions(+), 2 deletions(-)
Index: mln/accu/image/init.hh
--- mln/accu/image/init.hh (revision 0)
+++ mln/accu/image/init.hh (revision 0)
@@ -0,0 +1,162 @@
+// Copyright (C) 2009 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_ACCU_IMAGE_INIT_HH
+# define MLN_ACCU_IMAGE_INIT_HH
+
+/// \file mln/accu/image/init.hh
+///
+/// Initialize an image of accumulators.
+
+# include <mln/core/concept/accumulator.hh>
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+ namespace image
+ {
+
+ template <typename I>
+ void
+ init(Image<I>& input);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ namespace generic
+ {
+
+ template <typename I>
+ void
+ init(Image<I>& input_)
+ {
+ trace::entering("accu::impl::image::generic::init");
+
+ I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ input(p).init();
+
+ trace::exiting("accu::impl::image::generic::init");
+ }
+
+ } // end of namespace mln::accu::image::impl::generic
+
+
+ // Fastest version.
+
+ template <typename I>
+ void
+ init_fastest(Image<I>& input_)
+ {
+ trace::entering("accu::impl::image::init_fastest");
+
+ I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_pixter(I) px(input);
+ for_all(px)
+ px.val().init();
+
+ trace::exiting("accu::impl::image::init_fastest");
+ }
+
+ } // end of namespace mln::accu::image::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I>
+ void
+ init_dispatch(trait::image::speed::any,
+ Image<I>& input)
+ {
+ impl::generic::init(input);
+ }
+
+ template <typename I>
+ void
+ init_dispatch(trait::image::speed::fastest,
+ Image<I>& input)
+ {
+ impl::init_fastest(input);
+ }
+
+ template <typename I>
+ void
+ init_dispatch(Image<I>& input)
+ {
+ init_dispatch(mln_trait_image_speed(I)(),
+ input);
+ }
+
+ } // end of namespace mln::accu::image::internal
+
+
+ // Facade.
+
+ template <typename I>
+ void
+ init(Image<I>& input)
+ {
+ trace::entering("accu::image::init");
+
+ mlc_is_a(mln_value(I), Accumulator)::check();
+
+ mln_precondition(exact(input).is_valid());
+ internal::init_dispatch(input);
+
+ trace::exiting("accu::image::init");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu::image
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_IMAGE_INIT_HH
Index: mln/accu/image/take.hh
--- mln/accu/image/take.hh (revision 0)
+++ mln/accu/image/take.hh (revision 0)
@@ -0,0 +1,186 @@
+// Copyright (C) 2009 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_ACCU_IMAGE_TAKE_HH
+# define MLN_ACCU_IMAGE_TAKE_HH
+
+/// \file mln/accu/image/take.hh
+///
+/// Update an image of accumulators by taking the contents of another
+/// image.
+
+# include <mln/core/concept/accumulator.hh>
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+ namespace image
+ {
+
+ template <typename I, typename J>
+ void
+ take(Image<I>& input, const Image<J>& arg);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ namespace generic
+ {
+
+ template <typename I, typename J>
+ void
+ take(Image<I>& input_, const Image<J>& arg_)
+ {
+ trace::entering("accu::impl::image::generic::take");
+
+ I& input = exact(input_);
+ const J& arg = exact(arg_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(arg.is_valid());
+ mln_precondition(arg.domain() <= input.domain());
+
+ mln_piter(J) p(arg.domain());
+ for_all(p)
+ input(p).take(arg(p));
+
+ trace::exiting("accu::impl::image::generic::take");
+ }
+
+ } // end of namespace mln::accu::image::impl::generic
+
+
+ // Fastest version.
+
+ template <typename I, typename J>
+ void
+ take_fastest(Image<I>& input_, const Image<J>& arg_)
+ {
+ trace::entering("accu::impl::image::take_fastest");
+
+ I& input = exact(input_);
+ const J& arg = exact(arg_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(arg.is_valid());
+ mln_precondition(arg.domain() == input.domain());
+
+ mln_pixter(I) p_in(input);
+ mln_pixter(const J) p_arg(arg);
+ for_all_2(p_in, p_arg)
+ p_in.val().take( p_arg.val() );
+
+ trace::exiting("accu::impl::image::take_fastest");
+ }
+
+ } // end of namespace mln::accu::image::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I, typename J>
+ void
+ take_dispatch(trait::image::speed::any,
+ trait::image::speed::any,
+ Image<I>& input, const Image<J>& arg)
+ {
+ impl::generic::take(input, arg);
+ }
+
+ template <typename I, typename J>
+ void
+ take_dispatch(trait::image::speed::fastest,
+ trait::image::speed::fastest,
+ Image<I>& input, const Image<J>& arg)
+ {
+ if (exact(arg).domain() == exact(input).domain())
+ impl::take_fastest(input, arg);
+ else
+ impl::generic::take(input, arg);
+ }
+
+ template <typename I, typename J>
+ void
+ take_dispatch(Image<I>& input, const Image<J>& arg)
+ {
+ take_dispatch(mln_trait_image_speed(I)(),
+ mln_trait_image_speed(J)(),
+ input, arg);
+ }
+
+ } // end of namespace mln::accu::image::internal
+
+
+ // Facade.
+
+ template <typename I, typename J>
+ void
+ take(Image<I>& input_, const Image<J>& arg_)
+ {
+ trace::entering("accu::image::take");
+
+ mlc_is_a(mln_value(I), Accumulator)::check();
+ mlc_converts_to(mln_value(J),
+ mln_deduce(I, value, argument))::check();
+
+ I& input = exact(input_);
+ const J& arg = exact(arg_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(arg.is_valid());
+ mln_precondition(arg.domain() <= input.domain());
+
+ internal::take_dispatch(input, arg);
+
+ trace::exiting("accu::image::take");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu::image
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_IMAGE_TAKE_HH
Index: mln/accu/image/set_value.hh
--- mln/accu/image/set_value.hh (revision 0)
+++ mln/accu/image/set_value.hh (revision 0)
@@ -0,0 +1,166 @@
+// Copyright (C) 2009 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_ACCU_IMAGE_SET_VALUE_HH
+# define MLN_ACCU_IMAGE_SET_VALUE_HH
+
+/// \file mln/accu/image/set_value.hh
+///
+/// Set the values of an image of accumulators.
+
+# include <mln/core/concept/accumulator.hh>
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+ namespace image
+ {
+
+ template <typename I>
+ void
+ set_value(Image<I>& input,
+ const mln_deduce(I, value, result)& res);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ namespace generic
+ {
+
+ template <typename I>
+ void
+ set_value(Image<I>& input_,
+ const mln_deduce(I, value, result)& res)
+ {
+ trace::entering("accu::impl::image::generic::set_value");
+
+ I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ input(p).set_value(res);
+
+ trace::exiting("accu::impl::image::generic::set_value");
+ }
+
+ } // end of namespace mln::accu::image::impl::generic
+
+
+ // Fastest version.
+
+ template <typename I>
+ void
+ set_value_fastest(Image<I>& input_,
+ const mln_deduce(I, value, result)& res)
+ {
+ trace::entering("accu::impl::image::set_value_fastest");
+
+ I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_pixter(I) px(input);
+ for_all(px)
+ px.val().set_value(res);
+
+ trace::exiting("accu::impl::image::set_value_fastest");
+ }
+
+ } // end of namespace mln::accu::image::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I, typename V>
+ void
+ set_value_dispatch(trait::image::speed::any,
+ Image<I>& input, const V& res)
+ {
+ impl::generic::set_value(input, res);
+ }
+
+ template <typename I, typename V>
+ void
+ set_value_dispatch(trait::image::speed::fastest,
+ Image<I>& input, const V& res)
+ {
+ impl::set_value_fastest(input, res);
+ }
+
+ template <typename I, typename V>
+ void
+ set_value_dispatch(Image<I>& input, const V& res)
+ {
+ set_value_dispatch(mln_trait_image_speed(I)(),
+ input, res);
+ }
+
+ } // end of namespace mln::accu::image::internal
+
+
+ // Facade.
+
+ template <typename I>
+ void
+ set_value(Image<I>& input,
+ const mln_deduce(I, value, result)& res)
+ {
+ trace::entering("accu::image::set_value");
+
+ mlc_is_a(mln_value(I), Accumulator)::check();
+
+ mln_precondition(exact(input).is_valid());
+ internal::set_value_dispatch(input, res);
+
+ trace::exiting("accu::image::set_value");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu::image
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_IMAGE_SET_VALUE_HH
Index: mln/accu/image/all.hh
--- mln/accu/image/all.hh (revision 0)
+++ mln/accu/image/all.hh (revision 0)
@@ -0,0 +1,56 @@
+// Copyright (C) 2009 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_ACCU_IMAGE_ALL_HH
+# define MLN_ACCU_IMAGE_ALL_HH
+
+/// \file mln/accu/image/all.hh
+///
+/// File that includes all accumulator image routines.
+
+
+namespace mln
+{
+
+ /// Namespace of accumulators.
+ namespace accu
+ {
+ /// Namespace of accumulator image routines.
+ namespace image {}
+
+ }
+}
+
+
+# include <mln/accu/image/init.hh>
+# include <mln/accu/image/set_value.hh>
+# include <mln/accu/image/take_as_init.hh>
+# include <mln/accu/image/take.hh>
+# include <mln/accu/image/to_result.hh>
+
+
+#endif // ! MLN_ACCU_IMAGE_ALL_HH
Index: mln/accu/image/take_as_init.hh
--- mln/accu/image/take_as_init.hh (revision 0)
+++ mln/accu/image/take_as_init.hh (revision 0)
@@ -0,0 +1,166 @@
+// Copyright (C) 2009 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_ACCU_IMAGE_TAKE_AS_INIT_HH
+# define MLN_ACCU_IMAGE_TAKE_AS_INIT_HH
+
+/// \file mln/accu/image/take_as_init.hh
+///
+/// Initialize an image of accumulators by taking a first value.
+
+# include <mln/core/concept/accumulator.hh>
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+ namespace image
+ {
+
+ template <typename I>
+ void
+ take_as_init(Image<I>& input,
+ const mln_deduce(I, value, argument)& v);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ namespace generic
+ {
+
+ template <typename I>
+ void
+ take_as_init(Image<I>& input_,
+ const mln_deduce(I, value, argument)& v)
+ {
+ trace::entering("accu::impl::image::generic::take_as_init");
+
+ I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ input(p).take_as_init(v);
+
+ trace::exiting("accu::impl::image::generic::take_as_init");
+ }
+
+ } // end of namespace mln::accu::image::impl::generic
+
+
+ // Fastest version.
+
+ template <typename I>
+ void
+ take_as_init_fastest(Image<I>& input_,
+ const mln_deduce(I, value, argument)& v)
+ {
+ trace::entering("accu::impl::image::take_as_init_fastest");
+
+ I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_pixter(I) px(input);
+ for_all(px)
+ px.val().take_as_init(v);
+
+ trace::exiting("accu::impl::image::take_as_init_fastest");
+ }
+
+ } // end of namespace mln::accu::image::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I, typename V>
+ void
+ take_as_init_dispatch(trait::image::speed::any,
+ Image<I>& input, const V& v)
+ {
+ impl::generic::take_as_init(input, v);
+ }
+
+ template <typename I, typename V>
+ void
+ take_as_init_dispatch(trait::image::speed::fastest,
+ Image<I>& input, const V& v)
+ {
+ impl::take_as_init_fastest(input, v);
+ }
+
+ template <typename I, typename V>
+ void
+ take_as_init_dispatch(Image<I>& input, const V& v)
+ {
+ take_as_init_dispatch(mln_trait_image_speed(I)(),
+ input, v);
+ }
+
+ } // end of namespace mln::accu::image::internal
+
+
+ // Facade.
+
+ template <typename I>
+ void
+ take_as_init(Image<I>& input,
+ const mln_deduce(I, value, argument)& v)
+ {
+ trace::entering("accu::image::take_as_init");
+
+ mlc_is_a(mln_value(I), Accumulator)::check();
+
+ mln_precondition(exact(input).is_valid());
+ internal::take_as_init_dispatch(input, v);
+
+ trace::exiting("accu::image::take_as_init");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu::image
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_IMAGE_TAKE_AS_INIT_HH
Property changes on: mln/accu/image/take_as_init.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: mln/accu/image/to_result.hh
--- mln/accu/image/to_result.hh (revision 0)
+++ mln/accu/image/to_result.hh (revision 0)
@@ -0,0 +1,178 @@
+// Copyright (C) 2009 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_ACCU_IMAGE_TO_RESULT_HH
+# define MLN_ACCU_IMAGE_TO_RESULT_HH
+
+/// \file mln/accu/image/to_result.hh
+///
+/// Convert an image of accumulators into a result image.
+
+# include <mln/core/concept/accumulator.hh>
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+ namespace image
+ {
+
+ template <typename I>
+ mln_ch_value(I, mln_deduce(I, value, result))
+ to_result(const Image<I>& input);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ namespace generic
+ {
+
+ template <typename I>
+ mln_ch_value(I, mln_deduce(I, value, result))
+ to_result(const Image<I>& input_)
+ {
+ trace::entering("accu::impl::image::generic::to_result");
+
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ typedef mln_deduce(I, value, result) R;
+ mln_ch_value(I, R) output;
+ initialize(output, input);
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ output(p) = input(p).to_result();
+
+ trace::exiting("accu::impl::image::generic::to_result");
+ return output;
+ }
+
+ } // end of namespace mln::accu::image::impl::generic
+
+
+ // Fastest version.
+
+ template <typename I>
+ mln_ch_value(I, mln_deduce(I, value, result))
+ to_result_fastest(const Image<I>& input_)
+ {
+ trace::entering("accu::impl::image::to_result_fastest");
+
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ typedef mln_deduce(I, value, result) R;
+ typedef mln_ch_value(I, R) O;
+ O output;
+ initialize(output, input);
+
+ mln_pixter(const I) p_in(input);
+ mln_pixter(O) p_out(output);
+ for_all_2(p_in, p_out)
+ p_out.val() = p_in.val().to_result();
+
+ trace::exiting("accu::impl::image::to_result_fastest");
+ return output;
+ }
+
+ } // end of namespace mln::accu::image::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I>
+ mln_ch_value(I, mln_deduce(I, value, result))
+ to_result_dispatch(trait::image::speed::any,
+ const Image<I>& input)
+ {
+ return impl::generic::to_result(input);
+ }
+
+ template <typename I>
+ mln_ch_value(I, mln_deduce(I, value, result))
+ to_result_dispatch(trait::image::speed::fastest,
+ const Image<I>& input)
+ {
+ return impl::to_result_fastest(input);
+ }
+
+ template <typename I>
+ mln_ch_value(I, mln_deduce(I, value, result))
+ to_result_dispatch(const Image<I>& input)
+ {
+ return to_result_dispatch(mln_trait_image_speed(I)(),
+ input);
+ }
+
+ } // end of namespace mln::accu::image::internal
+
+
+ // Facade.
+
+ template <typename I>
+ mln_ch_value(I, mln_deduce(I, value, result))
+ to_result(const Image<I>& input)
+ {
+ trace::entering("accu::image::to_result");
+
+ mlc_is_a(mln_value(I), Accumulator)::check();
+
+ mln_precondition(exact(input).is_valid());
+
+ typedef mln_deduce(I, value, result) R;
+ mln_ch_value(I, R) output;
+ output = internal::to_result_dispatch(input);
+
+ trace::exiting("accu::image::to_result");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu::image
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_IMAGE_TO_RESULT_HH
Property changes on: mln/accu/image/to_result.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: mln/accu/all.hh
--- mln/accu/all.hh (revision 3531)
+++ mln/accu/all.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 2009 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
@@ -93,5 +93,9 @@
# include <mln/accu/transform_line.hh>
# include <mln/accu/transform_snake.hh>
+// Sub-directories
+
+# include <mln/accu/image/all.hh>
+
#endif // ! MLN_ACCU_ALL_HH
Index: tests/accu/image/to_result.cc
--- tests/accu/image/to_result.cc (revision 0)
+++ tests/accu/image/to_result.cc (revision 0)
@@ -0,0 +1,49 @@
+// Copyright (C) 2009 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/accu/image/to_result.cc
+///
+/// Tests on mln::accu::image::to_result.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/accu/count.hh>
+#include <mln/accu/image/init.hh>
+#include <mln/accu/image/to_result.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef accu::count<int> A;
+ image2d<A> ima(2, 2);
+
+ accu::image::init(ima);
+ image2d<unsigned> res = accu::image::to_result(ima);
+ debug::println(res);
+}
Property changes on: tests/accu/image/to_result.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: tests/accu/image/init.cc
--- tests/accu/image/init.cc (revision 0)
+++ tests/accu/image/init.cc (revision 0)
@@ -0,0 +1,45 @@
+// Copyright (C) 2009 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/accu/image/init.cc
+///
+/// Tests on mln::accu::image::init.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/accu/count.hh>
+#include <mln/accu/image/init.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef accu::count<int> A;
+ image2d<A> ima(2, 2);
+
+ accu::image::init(ima);
+}
Index: tests/accu/image/take.cc
--- tests/accu/image/take.cc (revision 0)
+++ tests/accu/image/take.cc (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2009 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/accu/image/take.cc
+///
+/// Tests on mln::accu::image::take.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/data/fill.hh>
+#include <mln/accu/sum.hh>
+#include <mln/accu/image/init.hh>
+#include <mln/accu/image/take.hh>
+
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef accu::sum<int> A;
+ image2d<A> ima(2, 2);
+ accu::image::init(ima);
+ debug::println(ima);
+
+ image2d<int> dta(2, 2);
+ data::fill(dta, 7);
+
+ accu::image::take(ima, dta);
+ debug::println(ima);
+
+ accu::image::take(ima, ima);
+ debug::println(ima);
+}
Index: tests/accu/image/Makefile.am
--- tests/accu/image/Makefile.am (revision 0)
+++ tests/accu/image/Makefile.am (revision 0)
@@ -0,0 +1,18 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ init \
+ set_value \
+ take \
+ take_as_init \
+ to_result
+
+init_SOURCES = init.cc
+set_value_SOURCES = set_value.cc
+take_SOURCES = take.cc
+take_as_init_SOURCES = take_as_init.cc
+to_result_SOURCES = to_result.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/accu/image/set_value.cc
--- tests/accu/image/set_value.cc (revision 0)
+++ tests/accu/image/set_value.cc (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2009 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/accu/image/set_value.cc
+///
+/// Tests on mln::accu::image::set_value.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/accu/count.hh>
+#include <mln/accu/image/set_value.hh>
+
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef accu::count<int> A;
+ image2d<A> ima(2, 2);
+
+ accu::image::set_value(ima, 3);
+ debug::println(ima);
+}
Index: tests/accu/image/take_as_init.cc
--- tests/accu/image/take_as_init.cc (revision 0)
+++ tests/accu/image/take_as_init.cc (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2009 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/accu/image/take_as_init.cc
+///
+/// Tests on mln::accu::image::take_as_init.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/accu/sum.hh>
+#include <mln/accu/image/take_as_init.hh>
+
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef accu::sum<int> A;
+ image2d<A> ima(2, 2);
+
+ accu::image::take_as_init(ima, 3);
+ debug::println(ima);
+}
Property changes on: tests/accu/image/take_as_init.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: tests/accu/Makefile.am
--- tests/accu/Makefile.am (revision 3531)
+++ tests/accu/Makefile.am (working copy)
@@ -2,6 +2,9 @@
include $(top_srcdir)/milena/tests/tests.mk
+SUBDIRS = \
+ image
+
check_PROGRAMS = \
all_accus \
bbox \
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-03-14 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Disambiguate component tree iterators.
* mln/morpho/tree/data.hh:
Add children image to get instant access to child relationship.
Remove mln_fwd_piter, mln_bkd_piter and mln_piter definition
from tree structure.
Add mln_up_site_piter, mln_dn_site_piter, mln_up_node_piter,
mln_dn_node_piter iterator adaptator.
Add mln_preorder_piter, the preorder tree traversal
iterator.
Move inline code out of class definition.
* sandbox/edwin/tree/propagate_node.hh: Fix with new iterator,
but not yet optimized with new tree structure.
* sandbox/edwin/tree/propagate_value.hh: Fix with new
iterator, but not yet optimized with new tree structure.
* sandbox/edwin/tree/propagation.cc: Update test file.
---
mln/morpho/tree/data.hh | 462 +++++++++++++++++++++++++++-------
sandbox/edwin/tree/propagate_node.hh | 10
sandbox/edwin/tree/propagate_value.hh | 12
sandbox/edwin/tree/propagation.cc | 31 ++
4 files changed, 410 insertions(+), 105 deletions(-)
Index: trunk/milena/mln/morpho/tree/data.hh
===================================================================
--- trunk/milena/mln/morpho/tree/data.hh (revision 3530)
+++ trunk/milena/mln/morpho/tree/data.hh (revision 3531)
@@ -38,10 +38,27 @@
/// learn why we want the 1st pass to be in forward scan of s).
# include <mln/morpho/tree/compute_parent.hh>
-# include <mln/core/image/sub_image.hh>
+//# include <mln/core/image/sub_image.hh>
# include <mln/core/site_set/p_array.hh>
-# include <mln/core/site_set/p_set.hh>
-# include <mln/data/fill.hh>
+# include <mln/core/internal/site_set_iterator_base.hh>
+# include <mln/core/internal/piter_identity.hh>
+# include <deque>
+
+# define mln_up_site_piter(T) typename T::up_site_piter
+# define mln_dn_site_piter(T) typename T::dn_site_piter
+# define mln_up_node_piter(T) typename T::up_node_piter
+# define mln_dn_node_piter(T) typename T::dn_node_piter
+# define mln_preorder_piter(T) typename T::preorder_piter
+
+# define mln_up_site_piter_(T) T::up_site_piter
+# define mln_dn_site_piter_(T) T::dn_site_piter
+# define mln_up_node_piter_(T) T::up_node_piter
+# define mln_dn_node_piter_(T) T::dn_node_piter
+# define mln_preorder_piter_(T) T::preorder_piter
+
+// FIXME: rename these iterators.
+//# define mln_up_leaf_piter(T) typename T::up_leaf_piter;
+//# define mln_dn_leaf_piter(T) typename T::dn_leaf_piter;
namespace mln
{
@@ -52,144 +69,243 @@
namespace tree
{
+ // Forward declarations.
+
+ /// Iterate on tree's sites from leaves to roots.
+ template <typename T> struct up_site_piter;
+
+ /// Iterate on tree's sites from roots to leaves.
+ template <typename T> struct dn_site_piter;
+
+ /// Iterate on tree's nodes (component representants) from leaves to roots.
+ template <typename T> struct up_node_piter;
+
+ /// Iterate on tree's nodes (component representants) from leaves to roots.
+ template <typename T> struct dn_node_piter;
+
+ /// Preorder tree traversal iterator.
+ template <typename T> struct preorder_piter;
+
+ /// Postorder tree traversal iterator.
+ //template <typename T> struct postorder_piter;
+
// FIXME: Doc!
+
+
template <typename I, typename S>
class data
{
- public:
-
+ typedef data<I, S> self_;
+ public:
/// Associated type of the function f.
typedef I function;
+ /// Psite associated type.
+ typedef mln_psite(I) psite;
+ typedef mln_site(I) site;
+ /// Site set associated type.
+ typedef S sites_t;
+ /// Node list associated type.
+ typedef p_array<mln_psite(I)> nodes_t;
+ /// Parent image associated type.
+ typedef mln_ch_value(I, mln_psite(I)) parent_t;
- /// Ctor.
+ // Iterate on all sites.
+ typedef mln::morpho::tree::up_site_piter<self_> up_site_piter;
+ typedef mln::morpho::tree::dn_site_piter<self_> dn_site_piter;
+
+ // Iterate on nodes only.
+ typedef mln::morpho::tree::up_node_piter<self_> up_node_piter;
+ typedef mln::morpho::tree::dn_node_piter<self_> dn_node_piter;
+
+ typedef mln::morpho::tree::preorder_piter<self_> preorder_piter;
+
+// typedef mln_bkd_piter(S) piter;
+// typedef mln_bkd_piter(S) fwd_piter;
+// typedef mln_fwd_piter(S) bkd_piter;
+
+ /// Constructor.
template <typename N>
- data(const Image<I>& f, const Site_Set<S>& s, const Neighborhood<N>& nbh);
+ explicit data(const Image<I>& f, const Site_Set<S>& s, const Neighborhood<N>& nbh);
/// \{ Parent-related materials.
- typedef mln_ch_value(I, mln_psite(I)) parent_t;
+ const mln_psite(I)& parent(const mln_psite(I)& p) const;
+ const parent_t& parent_image() const;
+
+ /// \}
- const mln_psite(I)& parent(const mln_psite(I)& p) const
+ const p_array<mln_psite(I)>& children(const mln_psite(I)& p) const
{
- mln_precondition(is_valid());
- mln_precondition(parent_.domain().has(p));
- return parent_(p);
+ return children_(p);
}
- const parent_t& parent_image() const
+ const mln_ch_value(I, nodes_t)& children_image() const
{
- mln_precondition(is_valid());
- return parent_;
+ return children_;
}
- /// \}
+ /// \{ Tests.
+ bool is_valid() const;
+ bool is_root(const mln_psite(I)& p) const;
+ bool is_a_node(const mln_psite(I)& p) const;
+ bool is_a_non_root_node(const mln_psite(I)& p) const;
+ bool is_a_leaf(const mln_psite(I)& p) const;
- /// \{ Tests.
+ /// \}
- bool is_valid() const
- {
- return parent_.is_valid(); // FIXME: and... (?)
- }
- bool is_root(const mln_psite(I)& p) const
- {
- mln_precondition(is_valid());
- mln_precondition(parent_.domain().has(p));
- return parent_(p) == p;
- }
+ /// \{ Nodes-related materials.
- bool is_a_node(const mln_psite(I)& p) const
- {
- mln_precondition(is_valid());
- mln_precondition(parent_.domain().has(p));
- return parent_(p) == p || f_(parent_(p)) != f_(p);
- }
+ const p_array<mln_psite(I)>& nodes() const;
- bool is_a_non_root_node(const mln_psite(I)& p) const
- {
- mln_precondition(is_valid());
- mln_precondition(parent_.domain().has(p));
- return f_(parent_(p)) != f_(p);
- }
+ /// \}
- /// Return true iff p is a leaf (in log time).
- bool is_a_leaf(const mln_psite(I)& p) const
- {
- mln_precondition(is_valid());
- mln_precondition(parent_.domain().has(p));
- return leaves_.has(p);
- }
+ /// \{ Sites-related materials.
+
+ const S& domain() const;
/// \}
+ unsigned nroots() const;
- /// \{ Nodes-related materials.
- typedef p_array<mln_psite(I)> nodes_t;
+ const I& f() const;
- const p_array<mln_psite(I)>& nodes() const
- {
- mln_precondition(is_valid());
- return nodes_;
- }
- /// \}
+ mln_rvalue(I) f(const mln_psite(I)& p) const;
- /// \{ Nodes-related materials.
+ protected:
+ const function& f_;
+ const sites_t& s_;
+ mln_ch_value(I, mln_psite(I)) parent_; // Parent image.
+ mln_ch_value(I, nodes_t) children_; // Children image.
+ nodes_t nodes_;
+ unsigned nroots_;
+ };
+
- typedef p_set<mln_psite(I)> leaves_t;
+ template <typename T>
+ struct up_site_piter
+ : public mln::internal::piter_identity_< typename T::sites_t::bkd_piter, // Adaptee.
+ up_site_piter<T> > // Exact.
+ {
+ private:
+ typedef typename T::sites_t::bkd_piter Pi_;
+ typedef mln::internal::piter_identity_< Pi_, up_site_piter<T> > super_;
- const leaves_t& leaves() const
+ public:
+ up_site_piter(const T& t)
{
- mln_precondition(is_valid());
- return leaves_;
+ this->change_target(t.domain());
}
- /// \}
+ up_site_piter(const Pi_& pi)
+ : super_(pi)
+ {
+ }
+ };
- /// \{ How-to iterate on all sites.
+ template <typename T>
+ struct dn_site_piter
+ : public mln::internal::piter_identity_< typename T::sites_t::fwd_piter, // Adaptee.
+ dn_site_piter<T> > // Exact.
+ {
+ private:
+ typedef typename T::sites_t::fwd_piter Pi_;
+ typedef mln::internal::piter_identity_< Pi_, dn_site_piter<T> > super_;
- typedef mln_bkd_piter(S) piter;
- typedef mln_bkd_piter(S) fwd_piter;
- typedef mln_fwd_piter(S) bkd_piter;
+ public:
+ dn_site_piter(const T& t)
+ {
+ this->change_target(t.domain());
+ }
- const S& domain() const
+ dn_site_piter(const Pi_& pi)
+ : super_(pi)
{
- return s_;
}
+ };
- /// \}
+ template <typename T>
+ struct up_node_piter
+ : public mln::internal::piter_identity_< typename T::nodes_t::fwd_piter, // Adaptee.
+ up_node_piter<T> > // Exact.
+ {
+ private:
+ typedef typename T::sites_t::fwd_piter Pi_;
+ typedef mln::internal::piter_identity_< Pi_, up_node_piter<T> > super_;
- unsigned nroots() const
+ public:
+ up_node_piter(const T& t)
{
- return nroots_;
+ this->change_target(t.nodes());
}
- const I& f() const
+ up_node_piter(const Pi_& pi)
+ : super_(pi)
{
- return f_;
}
+ };
- mln_rvalue(I) f(const mln_psite(I)& p) const
+ template <typename T>
+ struct dn_node_piter
+ : public mln::internal::piter_identity_< typename T::nodes_t::bkd_piter, // Adaptee.
+ dn_node_piter<T> > // Exact.
+ {
+ private:
+ typedef typename T::sites_t::bkd_piter Pi_;
+ typedef mln::internal::piter_identity_< Pi_, dn_node_piter<T> > super_;
+
+ public:
+ dn_node_piter(const T& t)
{
- return f_(p);
+ this->change_target(t.nodes());
}
- protected:
+ dn_node_piter(const Pi_& pi)
+ : super_(pi)
+ {
+ }
+ };
- const I& f_;
- const S& s_;
- mln_ch_value(I, mln_psite(I)) parent_;
- leaves_t leaves_;
- p_array<mln_psite(I)> nodes_;
- unsigned nroots_;
+ template <typename T>
+ class preorder_piter
+ : public mln::internal::site_set_iterator_base< T, preorder_piter<T> >
+ {
+ typedef preorder_piter<T> self_;
+ typedef mln::internal::site_set_iterator_base<T, self_> super_;
+
+ public:
+
+ /// Constructor with no argument.
+ preorder_piter();
+
+ /// Constructor.
+ preorder_piter(const T& t);
+
+ /// Test if the iterator is valid.
+ bool is_valid_() const;
+
+ /// Invalidate the iterator.
+ void invalidate_();
+
+ /// Start an iteration.
+ void start_();
+
+ /// Go to the next point.
+ void next_();
+
+ protected:
+ using super_::p_;
+ using super_::s_;
+ std::deque<mln_psite(T)> stack_; // FIXME: implement p_stack.
};
@@ -208,6 +324,7 @@
// Compute parent image.
parent_ = morpho::tree::compute_parent(f_, nbh_, s_);
+ initialize(children_, f);
// Store tree nodes.
nroots_ = 0;
@@ -217,6 +334,7 @@
if (f_(parent_(p)) != f_(p))
{
nodes_.insert(p);
+ children_(parent_(p)).insert(p);
}
else
if (parent_(p) == p)
@@ -225,21 +343,183 @@
++nroots_;
}
}
+ }
+
+ template <typename I, typename S>
+ inline
+ const mln_psite(I)&
+ data<I,S>::parent(const mln_psite(I)& p) const
+ {
+ mln_precondition(is_valid());
+ mln_precondition(parent_.domain().has(p));
+ return parent_(p);
+ }
+
+ template <typename I, typename S>
+ inline
+ const mln_ch_value(I, mln_psite(I))&
+ data<I,S>::parent_image() const
+ {
+ mln_precondition(is_valid());
+ return parent_;
+ }
+
+ template <typename I, typename S>
+ inline
+ bool
+ data<I,S>::is_valid() const
+ {
+ return parent_.is_valid(); // FIXME: and... (?)
+ }
+
+ template <typename I, typename S>
+ inline
+ bool
+ data<I,S>::is_root(const mln_psite(I)& p) const
+ {
+ mln_precondition(is_valid());
+ mln_precondition(parent_.domain().has(p));
+ return parent_(p) == p;
+ }
+
+
+ template <typename I, typename S>
+ inline
+ bool
+ data<I,S>::is_a_node(const mln_psite(I)& p) const
+ {
+ mln_precondition(is_valid());
+ mln_precondition(parent_.domain().has(p));
+ return parent_(p) == p || f_(parent_(p)) != f_(p);
+ }
+
+ template <typename I, typename S>
+ inline
+ bool
+ data<I,S>::is_a_non_root_node(const mln_psite(I)& p) const
+ {
+ mln_precondition(is_valid());
+ mln_precondition(parent_.domain().has(p));
+ return f_(parent_(p)) != f_(p);
+ }
+
+
+ template <typename I, typename S>
+ inline
+ bool
+ data<I,S>::is_a_leaf(const mln_psite(I)& p) const
+ {
+ mln_precondition(is_valid());
+ mln_precondition(children_.domain().has(p));
+ return children_(p).nsites() == 0;
+ }
+
+ template <typename I, typename S>
+ inline
+ const p_array<mln_psite(I)>&
+ data<I,S>::nodes() const
+ {
+ mln_precondition(is_valid());
+ return nodes_;
+ }
+
+ template <typename I, typename S>
+ inline
+ const S&
+ data<I,S>::domain() const
+ {
+ return s_;
+ }
+
+ template <typename I, typename S>
+ inline
+ unsigned
+ data<I,S>::nroots() const
+ {
+ return nroots_;
+ }
+
+ template <typename I, typename S>
+ inline
+ const I&
+ data<I,S>::f() const
+ {
+ return f_;
+ }
+
+ template <typename I, typename S>
+ inline
+ mln_rvalue(I)
+ data<I,S>::f(const mln_psite(I)& p) const
+ {
+ return f_(p);
+ }
+
+
+
+ // Iterators.
+
+
+ template <typename T>
+ inline
+ preorder_piter<T>::preorder_piter()
+ {
+ }
+
+ template <typename T>
+ inline
+ preorder_piter<T>::preorder_piter(const T& t)
+ {
+ this->change_target(t);
+ }
- // Store leaves.
- mln_ch_value(I, bool) deja_vu;
- initialize(deja_vu, f);
- mln::data::fill(deja_vu, false);
-
- mln_fwd_piter(nodes_t) n(nodes_);
- for_all(n)
- {
- deja_vu(parent_(n)) = true;
- if (!deja_vu(n))
- leaves_.insert(n);
+ template <typename T>
+ inline
+ bool
+ preorder_piter<T>::is_valid_() const
+ {
+ return !stack_.empty();
}
+
+ template <typename T>
+ inline
+ void
+ preorder_piter<T>::invalidate_()
+ {
+ stack_.clear();
}
+ template <typename T>
+ inline
+ void
+ preorder_piter<T>::start_()
+ {
+ this->invalidate();
+ mln_dn_node_piter(T) n(s_->nodes());
+ int roots = 0;
+ for (n.start(); n.is_valid() && roots < s_->nroots(); n.next())
+ if (s_->is_root(n))
+ {
+ stack_.push_back(n);
+ roots++;
+ }
+
+ this->next();
+ }
+
+ template <typename T>
+ inline
+ void
+ preorder_piter<T>::next_()
+ {
+ p_ = stack_.back();
+ stack_.pop_back();
+ mln_fwd_piter(T::nodes_t) child(s_->children(p_));
+ for_all(child)
+ stack_.push_back(child);
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho::tree
Index: trunk/milena/sandbox/edwin/tree/propagate_node.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/propagate_node.hh (revision 3530)
+++ trunk/milena/sandbox/edwin/tree/propagate_node.hh (revision 3531)
@@ -51,7 +51,7 @@
*/
template <typename T, typename A>
void
- propagate_node_to_descendants(mln_bkd_piter(T::nodes_t)& n,
+ propagate_node_to_descendants(mln_dn_node_piter(T)& n,
const T& t,
Image<A>& a_,
mln_value(A) v);
@@ -65,7 +65,7 @@
*/
template <typename T, typename A>
void
- propagate_node_to_descendants(mln_bkd_piter(T::nodes_t)& n,
+ propagate_node_to_descendants(mln_dn_node_piter(T)& n,
const T& t,
Image<A>& a_);
@@ -135,7 +135,7 @@
template <typename T, typename A>
void
- propagate_node_to_descendants(mln_bkd_piter(T::nodes_t)& n,
+ propagate_node_to_descendants(mln_dn_node_piter(T)& n,
const T& t,
Image<A>& a_,
mln_value(A) v)
@@ -151,7 +151,7 @@
data::fill(ancestors, false);
ancestors(n) = true;
- mln_bkd_piter(T::nodes_t) it(n);
+ mln_dn_node_piter(T) it(n);
for (it.next(); it.is_valid(); it.next())
{
if (ancestors(t.parent(it)))
@@ -189,7 +189,7 @@
if (!t.is_a_node(n)) // Get the representant.
n = t.parent(n);
- mln_bkd_piter(T::nodes_t) it = find_bkd(t.nodes(), n);
+ mln_dn_node_piter(T) it(find_bkd(t.nodes(), n));
propagate_node_to_descendants(it, t, a, v);
}
Index: trunk/milena/sandbox/edwin/tree/propagation.cc
===================================================================
--- trunk/milena/sandbox/edwin/tree/propagation.cc (revision 3530)
+++ trunk/milena/sandbox/edwin/tree/propagation.cc (revision 3531)
@@ -32,6 +32,20 @@
<< "*********************" << std::endl;
}
+template <typename I>
+void print(I& img, mln_psite(I) p)
+{
+ using namespace mln;
+
+ std::cout << p << " -> ";
+ mln_fwd_piter(p_array<mln_psite(I)>) it(img(p));
+// for_all(it)
+// std::cout << it << " ";
+// std::cout << std::endl;
+ for_all(it)
+ print(img, it);
+}
+
int main(int argc, char* argv[])
{
using namespace mln;
@@ -109,9 +123,20 @@
dsp("Propagate value to descendants : (it_max, tree, dup, 69)");
display_tree_attributes(tree, dup);
-
-
-
+ mln_dn_node_piter_(tree_t) n(tree);
+ n.start();
+ print(tree.children_image(), n);
+
+ std::cout << "\n";
+ mln_preorder_piter_(tree_t) pit(tree);
+ mln_psite_(I) parent;
+ for_all(pit)
+ {
+ if (parent != tree.parent(pit))
+ std::cout << std::endl;
+ std::cout << pit << " -> ";
+ parent = pit;
+ }
}
Index: trunk/milena/sandbox/edwin/tree/propagate_value.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/propagate_value.hh (revision 3530)
+++ trunk/milena/sandbox/edwin/tree/propagate_value.hh (revision 3531)
@@ -83,7 +83,7 @@
template <typename T, typename A>
bool check_propagate_ancestors(const T& t, const A& a, mln_value(A) v)
{
- mln_fwd_piter(T::nodes_t) n(t.nodes());
+ mln_up_node_piter(T) n(t.nodes());
for_all(n)
if (a(n) == v && a(t.parent(n)) != v)
return false;
@@ -93,7 +93,7 @@
template <typename T, typename A>
bool check_propagate_descendants(const T& t, const A& a, mln_value(A) v)
{
- mln_fwd_piter(T::nodes_t) n(t.nodes());
+ mln_up_node_piter(T) n(t.nodes());
for_all(n)
if (a(n) != v && a(t.parent(n)) == v)
return false;
@@ -123,7 +123,7 @@
initialize(deja_vu, a);
data::fill(deja_vu, false);
- mln_fwd_piter(T::nodes_t) n(t.nodes());
+ mln_up_node_piter(T) n(t.nodes());
for_all(n)
{
if (a(n) == v || deja_vu(n))
@@ -148,7 +148,7 @@
mln_precondition(a.is_valid());
mln_precondition(a.domain() == t.f().domain());
- mln_fwd_piter(T::nodes_t) n(t.nodes());
+ mln_up_node_piter(T) n(t.nodes());
for_all(n)
{
if (a(n) == v)
@@ -183,7 +183,7 @@
initialize(deja_vu, a);
data::fill(deja_vu, false);
- mln_bkd_piter(T::nodes_t) n(t.nodes());
+ mln_dn_node_piter(T) n(t.nodes());
for_all(n)
{
if (a(n) == v)
@@ -211,7 +211,7 @@
mln_precondition(a.is_valid());
mln_precondition(a.domain() == t.f().domain());
- mln_bkd_piter(T::nodes_t) n(t.nodes());
+ mln_dn_node_piter(T) n(t.nodes());
for_all(n)
{
if (a(t.parent(n)) == v)
1
0
13 Mar '09
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-13 Etienne FOLIO <folio(a)lrde.epita.fr>
Classification of 2D images with their respective RGB histograms.
* sandbox/folio/mln/histo/classify_with_histo_rgb.hh: New
algorithm that classifies an image 2d with its rgb histogram.
* sandbox/folio/mln/histo/compute_histo_rgb.hh: Use component of
value's trait.
* sandbox/folio/test/histo/classify_with_histo_rgb.cc: New test
for the classification of 2d images with their respective RGB
histograms.
* sandbox/folio/test/histo/compute_histo_rgb.cc: Correct an include.
* sandbox/folio/test/histo/compute_histo_rgb_from_ppm.cc: New test
for building an histogram with a ppm image.
---
mln/histo/classify_with_histo_rgb.hh | 40 +++++++++++++
mln/histo/compute_histo_rgb.hh | 11 ++-
test/histo/classify_with_histo_rgb.cc | 89 +++++++++++++++++++++++++++++++
test/histo/compute_histo_rgb.cc | 2
test/histo/compute_histo_rgb_from_ppm.cc | 30 ++++++++++
5 files changed, 166 insertions(+), 6 deletions(-)
Index: trunk/milena/sandbox/folio/test/histo/compute_histo_rgb_from_ppm.cc
===================================================================
--- trunk/milena/sandbox/folio/test/histo/compute_histo_rgb_from_ppm.cc (revision 0)
+++ trunk/milena/sandbox/folio/test/histo/compute_histo_rgb_from_ppm.cc (revision 3530)
@@ -0,0 +1,30 @@
+/*!
+ * \file compute_histo_rgb_from_ppm.cc
+ * \author etiennefolio <ornthalas(a)gmail.com>
+ */
+
+#include <iostream>
+#include <mln/debug/println.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/level/stretch.hh>
+
+#include "../../mln/histo/compute_histo_rgb.hh"
+
+int main()
+{
+ using namespace mln;
+
+ // build test image
+ image2d<value::rgb8> ima;
+ io::ppm::load(ima, "../../../../img/lena.ppm");
+
+ // let's run !
+ image3d<value::int_u8> out = histo::compute_histo_rgb<value::int_u8>(ima);
+
+ // output ?
+ // FIXME: need projection to visualize.
+
+ return 0;
+}
Index: trunk/milena/sandbox/folio/test/histo/compute_histo_rgb.cc
===================================================================
--- trunk/milena/sandbox/folio/test/histo/compute_histo_rgb.cc (revision 3529)
+++ trunk/milena/sandbox/folio/test/histo/compute_histo_rgb.cc (revision 3530)
@@ -7,7 +7,7 @@
#include <mln/debug/println.hh>
#include <mln/literal/all.hh>
-#include "../../histo/compute_histo_rgb.hh"
+#include "../../mln/histo/compute_histo_rgb.hh"
int main()
{
Index: trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc
===================================================================
--- trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc (revision 0)
+++ trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc (revision 3530)
@@ -0,0 +1,89 @@
+/*!
+ * \file classify_with_histo_rgb.cc
+ * \author etiennefolio <ornthalas(a)gmail.com>
+ */
+
+#include <iostream>
+#include <mln/debug/println.hh>
+#include <mln/debug/slices_2d.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/data/fill.hh>
+#include <mln/literal/all.hh>
+
+#include <mln/arith/revert.hh>
+#include <mln/core/alias/neighb3d.hh>
+#include <mln/morpho/closing/volume.hh>
+#include <mln/value/label_8.hh>
+#include <mln/morpho/watershed/flooding.hh>
+
+#include "../../mln/histo/compute_histo_rgb.hh"
+#include "../../mln/histo/classify_with_histo_rgb.hh"
+
+#include <mln/level/transform.hh>
+
+namespace mln
+{
+ struct rgb8to6 : Function_v2v< rgb8to6 >
+ {
+ typedef value::rgb<6> result;
+ value::rgb<6> operator()(const value::rgb<8>& c) const
+ {
+ value::rgb<6> res(c.red() / 4, c.green() / 4, c.blue() / 4);
+ return res;
+ }
+ };
+}
+
+int main(int argc, char** argv)
+{
+ using namespace mln;
+
+ // check arguments
+ if (argc < 3)
+ {
+ std::cerr << "Usage:" << std::endl
+ << " ./a.out ../../../../lena.ppm 51" << std::endl
+ << std::endl
+ << "BTW, the number is the closure's lambda." << std::endl;
+ exit(1);
+ }
+
+ typedef value::rgb<6> rgb6;
+ typedef value::int_u<6> int_u6;
+
+ // build test image
+ std::cout << " => loading " << argv[1] << "..." << std::endl;
+ image2d<value::rgb8> lena;
+ io::ppm::load(lena, argv[1]);
+ image2d<rgb6> ima = level::transform(lena, rgb8to6());
+
+ // let's run !
+ std::cout << " => computing histogram..." << std::endl;
+ image3d<unsigned> histo = histo::compute_histo_rgb<unsigned>(ima);
+
+ std::cout << " => computing reverted histogram..." << std::endl;
+ image3d<unsigned> reverted = arith::revert(histo);
+
+// std::cout << " => dump it to reverted.pgm..." << std::endl;
+// image2d<int_u6> d1 = debug::slices_2d(reverted, 1.f, 0);
+// io::pgm::save(d1, "reverted.pgm");
+
+ std::cout << " => computing closure..." << std::endl;
+ image3d<unsigned> closed = morpho::closing::volume(reverted, c6(), atoi(argv[2]));
+
+ std::cout << " => computing watershed..." << std::endl;
+ value::label_8 nbasin;
+ image3d<value::label_8> labels = morpho::watershed::flooding(closed, c6(), nbasin);
+ std::cout << "found " << nbasin << " labels" << std::endl;
+
+ std::cout << " => computing output labelized image..." << std::endl;
+ image2d<value::label_8> out = histo::classify_with_histo_rgb(ima, labels);
+
+ std::cout << " => saving out.ppm..." << std::endl;
+ io::pgm::save(out, "out.ppm");
+
+ return 0;
+}
Index: trunk/milena/sandbox/folio/mln/histo/classify_with_histo_rgb.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/histo/classify_with_histo_rgb.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/histo/classify_with_histo_rgb.hh (revision 3530)
@@ -0,0 +1,40 @@
+/*!
+ * \file classify_with_histo.hh
+ * \author etiennefolio <ornthalas(a)gmail.com>
+ */
+
+
+#ifndef CLASSIFY_WITH_HISTO_HH_
+# define CLASSIFY_WITH_HISTO_HH_
+
+namespace mln
+{
+
+ namespace histo
+ {
+
+ template <typename T, typename C>
+ image2d<C>
+ classify_with_histo_rgb(image2d<T>& ref,
+ image3d<C>& regions)
+ {
+ image2d<C> out;
+ initialize(out, ref);
+
+ mln_fwd_piter(image2d<T>) p(ref.domain());
+ for_all(p)
+ {
+ // get 3d point in regions image.
+ point3d p3 = point3d(ref(p).red(), ref(p).green(), ref(p).blue());
+
+ out(p) = regions(p3); // copy the label in out's pixel.
+ }
+
+ return out;
+ }
+
+ } // end of namespace mln::histo
+
+} // end of namespace mln
+
+#endif /* !CLASSIFY_WITH_HISTO_HH_ */
Index: trunk/milena/sandbox/folio/mln/histo/compute_histo_rgb.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/histo/compute_histo_rgb.hh (revision 3529)
+++ trunk/milena/sandbox/folio/mln/histo/compute_histo_rgb.hh (revision 3530)
@@ -8,6 +8,7 @@
#include <mln/value/int_u8.hh>
#include <mln/value/rgb8.hh>
#include <iostream>
+
namespace mln
{
namespace histo
@@ -17,11 +18,11 @@
image3d<C> compute_histo_rgb(image2d<T> ima)
{
// out
- typedef value::int_u8::enc enc;
- image3d<C> out(mln_max(enc) + abs(mln_min(enc)) + 1,
- mln_max(enc) + abs(mln_min(enc)) + 1,
- mln_max(enc) + abs(mln_min(enc)) + 1);
- data::fill(out, mln_min(C));
+ typedef typename trait::value_<T>::comp enc;
+ image3d<C> out(mln_max(enc) + abs(mln_min(enc) + 1),
+ mln_max(enc) + abs(mln_min(enc) + 1),
+ mln_max(enc) + abs(mln_min(enc) + 1));
+ data::fill(out, 0);
// count
mln_fwd_piter(image2d<T>) p(ima.domain());
1
0
13 Mar '09
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-03-13 Etienne FOLIO <folio(a)lrde.epita.fr>
Add dimendions and components types in values' traits.
Everything in the title, same for each file.
* mln/trait/value_.hh: .
* mln/value/float01.hh: .
* mln/value/float01_.hh: .
* mln/value/float01_f.hh: .
* mln/value/graylevel.hh: .
* mln/value/graylevel_f.hh: .
* mln/value/hsl.hh: .
* mln/value/int_s.hh: .
* mln/value/int_u.hh: .
* mln/value/int_u_sat.hh: .
* mln/value/label.hh: .
* mln/value/rgb.hh: .
* mln/value/sign.hh: .
---
trait/value_.hh | 8 ++++++++
value/float01.hh | 1 -
value/float01_.hh | 3 +++
value/float01_f.hh | 3 +++
value/graylevel.hh | 3 +++
value/graylevel_f.hh | 3 +++
value/hsl.hh | 5 +++++
value/int_s.hh | 3 +++
value/int_u.hh | 3 +++
value/int_u_sat.hh | 10 ++++++++--
value/label.hh | 2 ++
value/rgb.hh | 12 ++++++++----
value/sign.hh | 9 ++++-----
13 files changed, 53 insertions(+), 12 deletions(-)
Index: trunk/milena/mln/trait/value_.hh
===================================================================
--- trunk/milena/mln/trait/value_.hh (revision 3528)
+++ trunk/milena/mln/trait/value_.hh (revision 3529)
@@ -107,6 +107,7 @@
/*
* enum {
+ * dim = ?
* nbits = ?,
* card = ?
* };
@@ -124,6 +125,7 @@
struct default_value_ : undefined_value_
{
enum {
+ dim = 0,
nbits = 0,
card = 0
};
@@ -131,6 +133,12 @@
typedef trait::value::nature::unknown nature;
typedef trait::value::kind::data kind;
typedef trait::value::quant::high quant;
+
+ /*
+ * typedef ? comp_0;
+ * typedef ? comp_1;
+ * ...
+ */
};
Index: trunk/milena/mln/value/hsl.hh
===================================================================
--- trunk/milena/mln/value/hsl.hh (revision 3528)
+++ trunk/milena/mln/value/hsl.hh (revision 3529)
@@ -130,6 +130,7 @@
struct value_< mln::value::hsl_<H,S,L> >
{
enum {
+ dim = 3,
nbits = (sizeof (H) + sizeof (S) + sizeof (L)) * 8,
card = mln_value_card_from_(nbits)
};
@@ -138,6 +139,10 @@
typedef trait::value::kind::color kind;
typedef mln_value_quant_from_(card) quant;
+ typedef H comp_0;
+ typedef S comp_1;
+ typedef L comp_2;
+
// typedef algebra::vec<3, float> sum;
typedef mln::value::hsl_<H,S,L> sum;
};
Index: trunk/milena/mln/value/graylevel.hh
===================================================================
--- trunk/milena/mln/value/graylevel.hh (revision 3528)
+++ trunk/milena/mln/value/graylevel.hh (revision 3529)
@@ -162,6 +162,7 @@
public:
enum {
+ dim = 1,
nbits = n,
card = mln_value_card_from_(n)
};
@@ -174,6 +175,8 @@
static const self_ max() { return card - 1; }
static const self_ epsilon() { return 0; }
+ typedef mln::value::int_u<n> comp;
+
typedef float sum;
};
Index: trunk/milena/mln/value/graylevel_f.hh
===================================================================
--- trunk/milena/mln/value/graylevel_f.hh (revision 3528)
+++ trunk/milena/mln/value/graylevel_f.hh (revision 3529)
@@ -168,6 +168,7 @@
public:
enum {
+ dim = 1,
nbits = mln_nbits(equiv_),
card = 0
};
@@ -180,6 +181,8 @@
static const equiv_ max() { return 1; }
static const equiv_ epsilon() { return mln_epsilon(equiv_); }
+ typedef float comp;
+
typedef float sum;
};
Index: trunk/milena/mln/value/sign.hh
===================================================================
--- trunk/milena/mln/value/sign.hh (revision 3528)
+++ trunk/milena/mln/value/sign.hh (revision 3529)
@@ -40,10 +40,9 @@
namespace mln
{
+
namespace value
{
-
-
/*!
** \brief The sign class represents the value type
** composed by the set (-1, 0, 1)
@@ -201,7 +200,6 @@
} // end of namespace value
-
namespace trait
{
@@ -210,6 +208,7 @@
{
enum {
+ dim = 1,
nbits = 2,
card = 3
};
@@ -222,13 +221,13 @@
static mln::value::sign max() { return 1; }
static mln::value::sign epsilon() { return 0; }
+ typedef int comp;
+
typedef int sum;
};
-
} // end of namespace trait
-
} // end of namespace mln
Index: trunk/milena/mln/value/float01_.hh
===================================================================
--- trunk/milena/mln/value/float01_.hh (revision 3528)
+++ trunk/milena/mln/value/float01_.hh (revision 3529)
@@ -64,6 +64,7 @@
struct value_< mln::value::float01_<n> >
{
enum constants_ {
+ dim = 1,
nbits = n,
card = mln_value_card_from_(nbits)
};
@@ -76,6 +77,8 @@
static float max() { return 1.f; }
static float epsilon() { return 0.f; }
+ typedef float comp;
+
typedef float sum;
};
Index: trunk/milena/mln/value/int_s.hh
===================================================================
--- trunk/milena/mln/value/int_s.hh (revision 3528)
+++ trunk/milena/mln/value/int_s.hh (revision 3529)
@@ -76,6 +76,7 @@
public:
enum constants_ {
+ dim = 1,
nbits = n,
card = mln_value_card_from_(n) - 1
};
@@ -88,6 +89,8 @@
static const self_ min() { return - max(); }
static const self_ epsilon() { return 0; }
+ typedef mln::value::int_s<n> comp;
+
typedef float sum;
static const char* name()
Index: trunk/milena/mln/value/int_u.hh
===================================================================
--- trunk/milena/mln/value/int_u.hh (revision 3528)
+++ trunk/milena/mln/value/int_u.hh (revision 3529)
@@ -82,6 +82,7 @@
public:
enum constants_ {
+ dim = 1,
nbits = n,
card = mln_value_card_from_(n)
};
@@ -94,6 +95,8 @@
static const self_ max() { return mlc_pow_int(2, n) - 1; }
static const self_ epsilon() { return 0; }
+ typedef unsigned comp;
+
typedef float sum;
static const char* name()
Index: trunk/milena/mln/value/int_u_sat.hh
===================================================================
--- trunk/milena/mln/value/int_u_sat.hh (revision 3528)
+++ trunk/milena/mln/value/int_u_sat.hh (revision 3529)
@@ -58,17 +58,23 @@
template <unsigned n>
struct value_< mln::value::int_u_sat<n> >
{
+ enum {
+ dim = 1,
+ card = metal::math::pow_int<2, n>::value,
+ nbits = n;
+ };
+
// FIXME: Overhaul these traits (see other value traits).
- static const std::size_t card = metal::math::pow_int<2, n>::value;
static const mln::value::int_u_sat<n> min() { return 0; }
static const mln::value::int_u_sat<n> max() { return card - 1; }
- static const unsigned nbits = n;
typedef trait::value::nature::integer nature;
typedef trait::value::kind::data kind;
// FIXME: Is that right?
typedef mln_value_quant_from_(card) quant;
+ typedef unsigned comp;
+
typedef float sum;
};
Index: trunk/milena/mln/value/float01.hh
===================================================================
--- trunk/milena/mln/value/float01.hh (revision 3528)
+++ trunk/milena/mln/value/float01.hh (revision 3529)
@@ -40,7 +40,6 @@
# include <mln/value/concept/floating.hh>
# include <mln/trait/value_.hh>
# include <mln/trait/all.hh> // FIXME!
-# include <mln/trait/value_.hh>
Index: trunk/milena/mln/value/rgb.hh
===================================================================
--- trunk/milena/mln/value/rgb.hh (revision 3528)
+++ trunk/milena/mln/value/rgb.hh (revision 3529)
@@ -105,9 +105,7 @@
// Forward declaration.
namespace value
{
- template <unsigned n> struct rgb;
template <typename H, typename S, typename L> class hsl_;
- template <unsigned n> struct int_u;
}
@@ -208,7 +206,8 @@
struct value_< mln::value::rgb<n> >
{
enum {
- nbits = 3 * n,
+ dim = 3,
+ nbits = dim * n,
card = mln_value_card_from_(nbits)
};
@@ -216,7 +215,9 @@
typedef trait::value::kind::color kind;
typedef mln_value_quant_from_(card) quant;
- typedef algebra::vec<3, float> sum;
+ typedef mln::value::int_u<n> comp;
+
+ typedef algebra::vec<dim, float> sum;
static const char* name()
{
@@ -260,6 +261,9 @@
int_u<n> blue() const { return this->v_[2]; }
int_u<n>& blue() { return this->v_[2]; }
+
+ int_u<n> comp(unsigned k) const { return this->v_[k]; }
+ int_u<n>& comp(unsigned k) { return this->v_[k]; }
/// \}
/// Constructor without argument.
Index: trunk/milena/mln/value/float01_f.hh
===================================================================
--- trunk/milena/mln/value/float01_f.hh (revision 3528)
+++ trunk/milena/mln/value/float01_f.hh (revision 3529)
@@ -62,6 +62,7 @@
typedef trait::value::quant::high quant;
enum {
+ dim = 1,
nbits = 8 * sizeof(float),
card = 0
};
@@ -70,6 +71,8 @@
static float max() { return 1; }
static float epsilon() { return mln_epsilon(float); }
+ typedef float comp;
+
typedef float sum;
};
Index: trunk/milena/mln/value/label.hh
===================================================================
--- trunk/milena/mln/value/label.hh (revision 3528)
+++ trunk/milena/mln/value/label.hh (revision 3529)
@@ -68,6 +68,7 @@
public:
enum {
+ dim = 1,
nbits = n,
card = mln_value_card_from_(n)
};
@@ -85,6 +86,7 @@
return s.c_str();
}
+ typedef unsigned comp;
};
} // end of namespace trait
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-03-13 Etienne FOLIO <folio(a)lrde.epita.fr>
Orthograph correction in error message.
* mln/canvas/labeling.hh: Orthograph.
* mln/labeling/blobs.hh: Orthograph.
---
canvas/labeling.hh | 6 +++---
labeling/blobs.hh | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
Index: trunk/milena/mln/canvas/labeling.hh
===================================================================
--- trunk/milena/mln/canvas/labeling.hh (revision 3527)
+++ trunk/milena/mln/canvas/labeling.hh (revision 3528)
@@ -197,7 +197,7 @@
if (nlabels == mln_max(L))
{
status = false;
- trace::warning("labeling aborted! Too much labels \
+ trace::warning("labeling aborted! Too many labels \
for this label type: nlabels > \
max(label_type).");
@@ -324,7 +324,7 @@
if (nlabels == mln_max(L))
{
status = false;
- trace::warning("labeling aborted! Too much labels for \
+ trace::warning("labeling aborted! Too many labels for \
this label type: nlabels > \
max(label_type).");
return output;
@@ -442,7 +442,7 @@
if (nlabels == mln_max(L))
{
status = false;
- trace::warning("labeling aborted! Too much labels \
+ trace::warning("labeling aborted! Too many labels \
for this label type: nlabels > \
max(label_type).");
return output;
Index: trunk/milena/mln/labeling/blobs.hh
===================================================================
--- trunk/milena/mln/labeling/blobs.hh (revision 3527)
+++ trunk/milena/mln/labeling/blobs.hh (revision 3528)
@@ -101,7 +101,7 @@
// Label this point component.
if (nlabels == mln_max(L))
{
- trace::warning("labeling aborted! Too much labels \
+ trace::warning("labeling aborted! Too many labels \
for this label type: nlabels > \
max(label_type).");
1
0
* milena/doc/tutorial/tutorial.tex: Fix syntax errors.
---
milena/ChangeLog | 6 ++++
milena/doc/tutorial/tutorial.tex | 55 ++++++++++++++++++--------------------
2 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 991185f..3e5daca 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,9 @@
+2009-03-13 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Fix tutorial compilation.
+
+ * milena/doc/tutorial/tutorial.tex: Fix syntax errors.
+
2009-03-13 Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fix missing trace in mln::test routines.
diff --git a/milena/doc/tutorial/tutorial.tex b/milena/doc/tutorial/tutorial.tex
index 903ac14..a36a365 100644
--- a/milena/doc/tutorial/tutorial.tex
+++ b/milena/doc/tutorial/tutorial.tex
@@ -305,10 +305,6 @@ $$
\end{latexonly}
}
-\newcommand{\path}[1]{
-\textit{#1}
-}
-
\newcommand{\dir}[1]{
\textbf{\textit{#1}}
}
@@ -387,16 +383,16 @@ It is a more detailed explanations of the library's features.
\textit{end users} and \textit{designers} may be also interested by all the
examples provided with the documentation and the tutorial. The source code is
-available in \path{milena/doc/examples} (FIXME: ref) and is usually pointed
+available in \hpath{milena/doc/examples} (FIXME: ref) and is usually pointed
out and commented by the documentation.
Taking a look at the test suite is also a good idea. The tests usually focus on
a single functionality and handle several use cases which may overlap your needs.
-The test suite is located at \path{milena/tests} (FIXME: ref?).
+The test suite is located at \hpath{milena/tests} (FIXME: ref?).
Still not enough information? More information about all the functions is
available in the User HTML documentation (FIXME:ref).
-It mainly targets \textit{designers} and \texit{providers}.
+It mainly targets \textit{designers} and \textit{providers}.
The latter may also be interested by the Developer HTML documentation
(FIXME:ref).
@@ -437,7 +433,7 @@ We strongly advise you to not use it for production use.
%download page.
%--------------------------
-\subdoxysection{tuto1downloadingsvn}{Downloading from SVN}
+\doxysubsection{tuto1downloadingsvn}{Downloading from SVN}
First, be sure that SVN is already installed on your system.
Open a terminal and type:
@@ -486,17 +482,17 @@ and/or use the other documentations ressources (\ref{tuto1ressources}).
%--------------------------
-\subdoxysection{tuto1downloadingpackages}{Downloading packaged releases}
+\doxysubsection{tuto1downloadingpackages}{Downloading packaged releases}
%details.
Milena's packages can be downloaded from:
-\begin{centerize}
+\begin{center}
\begin{verbatim}
http://www.lrde.epita.fr/Olena/Download
\end{verbatim}
-\end{centerize}
+\end{center}
On this page you will find the latest and past releases.
Currently, we provide only '.tar.gz' and 'tar.bz2' archives.
@@ -568,33 +564,33 @@ you finding what you need, you will find a description of all these
subdirectories.
-List of \path{milena}'s subdirectories:
+List of \hpath{milena}'s subdirectories:
\begin{itemize}
-\dir{apps} --- A full example of a 3D mesh visualization tool. It
+\item \dir{apps} --- A full example of a 3D mesh visualization tool. It
uses milena.
-\dir{doc} --- THE directory you must know. Contains all the
+\item \dir{doc} --- THE directory you must know. Contains all the
documentation material.
-\dir{img} --- A set of common test images. They are used in the
+\item \dir{img} --- A set of common test images. They are used in the
test suite. Feel free to use it in your programs.
-\dir{mesh} --- A set of 3D meshes. They can be used with the full
- example located in \path{milena/apps}.
+\item \dir{mesh} --- A set of 3D meshes. They can be used with the full
+ example located in \hpath{milena/apps}.
-\dir{mln} --- The core of the libray. Contains all the library headers.
+\item \dir{mln} --- The core of the libray. Contains all the library headers.
-\dir{tests} --- The test suite. Is it subdivided in sub directories.
- The directory hierarchy respects \path{milena/mln}'s.
+\item \dir{tests} --- The test suite. Is it subdivided in sub directories.
+ The directory hierarchy respects \hpath{milena/mln}'s.
-\dir{tools} --- Small tools written with milena. They can be used as examples.
+\item \dir{tools} --- Small tools written with milena. They can be used as examples.
\end{itemize}
-List of \path{mln}'s subdirectories:
+List of \hpath{mln}'s subdirectories:
\begin{itemize}
\item \dir{accu} --- Set of Accumulators.
\item \dir{algebra} --- Algebraic structures like vectors or matrices.
@@ -645,12 +641,12 @@ List of \path{mln}'s subdirectories:
\item \dir{util} --- Various utilitarian classes.
\item \dir{value} --- Set of value types which can be used in an image.
\item \dir{win} --- Set of various window kinds.
-\end{itemize}}
+\end{itemize}
-The source code and the material of the documentation is available in \path{
+The source code and the material of the documentation is available in \hpath{
milena/doc}.
-List of \path{doc}'s subdirectories:
+List of \hpath{doc}'s subdirectories:
\begin{itemize}
\item \dir{examples} --- All the source code of the documentation examples.
\item \dir{benchmark} --- Some benchmarks.
@@ -746,6 +742,7 @@ The buildfarm can show you whether it is safe to update your svn copy of Milena
--- Through this page, you can see exactly which tests do not compile or pass.
This page is updated every night.
+\end{itemize}
%**************************
@@ -910,7 +907,7 @@ $ cd /my/path/to/olena-1.0/build
\end{verbatim}
If you did not change the default install path prefix, set to
-\path{/usr/local}, you will need to have administrator privileges to
+\hpath{/usr/local}, you will need to have administrator privileges to
perform the installation. Then, you may type:
\begin{verbatim}
$ sudo make install
@@ -943,7 +940,7 @@ compiled if you want to use them.
\doxysubsection{tuto2examples}{Examples}
Examples are part of the documentation. The sources are located in
-\path{milena/doc/examples}.
+\hpath{milena/doc/examples}.
To compile the examples simply run:
\begin{verbatim}
@@ -959,7 +956,7 @@ $ make examples
\end{verbatim}
Text and image outputs will be respectively stored in
-\path{build/milena/doc/outputs} and \path{build/milena/doc/figures}.
+\hpath{build/milena/doc/outputs} and \hpath{build/milena/doc/figures}.
@@ -973,7 +970,7 @@ Currently two tools are available:
area\_flooding.cc & FIXME:description \\
\hline
seed2tiling.cc & FIXME:description \\
-\end{itemize}
+\end{tabular}
To build these tools, run:
\begin{verbatim}
--
1.5.6.5
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-13 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Find threshold value thanks to watershed.
* fabien/bin/dumpi12_to_pgm.cc: New tool.
* fabien/igr/Makefile: Update.
* fabien/igr/check.sh: Update.
* fabien/igr/graph.cc: Update.
* fabien/igr/med.cc: Find median region value.
* fabien/igr/thres.cc: Threshold image.
---
TODO | 8 +++-
bin/dumpi12_to_pgm.cc | 55 +++++++++++++++++++++++++++++++
igr/Makefile | 6 +++
igr/check.sh | 37 +++++++++++++--------
igr/graph.cc | 13 ++++++-
igr/med.cc | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++
igr/thres.cc | 67 ++++++++++++++++++++++++++++++++++++++
7 files changed, 256 insertions(+), 17 deletions(-)
Index: trunk/milena/sandbox/fabien/igr/graph.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/graph.cc (revision 3525)
+++ trunk/milena/sandbox/fabien/igr/graph.cc (revision 3526)
@@ -11,11 +11,13 @@
#include <mln/io/dump/all.hh>
#include <mln/io/dicom/load.hh>
#include <mln/io/pgm/save.hh>
+#include <mln/io/ppm/save.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_u12.hh>
#include <mln/value/label_16.hh>
#include <mln/value/label_32.hh>
+#include <mln/value/rgb8.hh>
#include <mln/morpho/watershed/flooding.hh>
@@ -53,6 +55,8 @@
#include <mln/extract/all.hh>
#include <mln/make/region_adjacency_graph.hh>
+#include <mln/debug/colorize.hh>
+
@@ -241,6 +245,7 @@
using value::int_u12;
using value::label_16;
using value::label_32;
+ using value::rgb8;
typedef label_32 L;
if (argc != 6)
@@ -315,8 +320,12 @@
mln_VAR(wsd2_, morpho::elementary::dilation(extend(wsd2 | (pw::value(wsd2) == 0u), wsd2), c8()));
data::fill((wsd2 | (pw::value(wsd2) == 0u)).rw(), wsd2_);
- io::pgm::save(level::stretch(int_u8(), labeling::mean_values(dcm, wshed, nbasins)), "wsd_original.pgm");
- io::pgm::save(level::stretch(int_u8(), labeling::mean_values(dcm, wsd2, nbasins2)), "wsd_mean_colors.pgm");
+ mln_VAR(original, level::stretch(int_u8(), labeling::mean_values(dcm, wshed, nbasins)));
+ mln_VAR(mean, level::stretch(int_u8(), labeling::mean_values(dcm, wsd2, nbasins2)));
+ io::pgm::save(original, "wsd_original.pgm");
+ io::pgm::save(mean, "wsd_mean_colors.pgm");
+ io::ppm::save(debug::colorize(rgb8(), wshed, nbasins), "wsd_colorize_01.ppm");
+ io::ppm::save(debug::colorize(rgb8(), wsd2, nbasins2), "wsd_colorize_02.ppm");
}
else
{
Index: trunk/milena/sandbox/fabien/igr/check.sh
===================================================================
--- trunk/milena/sandbox/fabien/igr/check.sh (revision 3525)
+++ trunk/milena/sandbox/fabien/igr/check.sh (revision 3526)
@@ -4,22 +4,33 @@
{
echo "Processing $3..."
dist_max=10
+ input=$1
+ dim=$2
- ./grad $1 $2
- for lambda_closing in 10 50 100 500 1000 5000 10000 50000; do
+ ./grad $input $dim
+ for lambda_closing in 50 100 500 1000 5000 10000 50000; do
echo " for lambda_closing = ${lambda_closing}";
- ./clo_vol grad.dump $2 ${lambda_closing}
- nbasins=`./wst clo_vol.dump $2`
- ../bin/dumpl32_to_colorize wst.dump $2 $nbasins results/colorize_${3}_${lambda_closing}.ppm
+ ./clo_vol grad.dump $dim ${lambda_closing}
+ nbasins=`./wst clo_vol.dump $dim`
+ ../bin/dumpl32_to_colorize wst.dump $dim $nbasins results/colorize_${3}_${lambda_closing}.ppm
+ median=`./med wst.dump $dim $input $nbasins`
+ ../bin/dumpi12_to_pgm med.dump $dim results/median_${3}_${lambda_closing}.pgm
+ ./thres med.dump $dim $median
+ mv bin_result.pbm results/result_${3}_${lambda_closing}.pbm
- if [ ${lambda_closing} -eq 100 ]; then
- for lambda_dist in 10 50 100; do
- nbasins_after=`./graph wst.dump $2 $1 $lambda_dist $nbasins`
- mv wsd_original.pgm results/graph_${3}_${lambda_closing}_${lambda_dist}_01.pgm
- mv wsd_mean_colors.pgm results/graph_${3}_${lambda_closing}_${lambda_dist}_02.pgm
- echo "nbasins was" $nbasins "and now is" $nbasins_after "( diff =" $(($nbasins - $nbasins_after)) ")"
- done
- fi
+#if [ $2 -eq 2 ]; then
+# if [ ${lambda_closing} -eq 100 ]; then
+# for lambda_dist in 50 100 120 130 140 150; do
+# nbasins_after=`./graph wst.dump $2 $1 $lambda_dist $nbasins`
+# mv wsd_original.pgm results/graph_${3}_${lambda_closing}_${lambda_dist}_01.pgm
+# mv wsd_mean_colors.pgm results/graph_${3}_${lambda_closing}_${lambda_dist}_02.pgm
+# mv wsd_colorize_01.ppm results/graph_${3}_${lambda_closing}_${lambda_dist}_03.ppm
+# mv wsd_colorize_02.ppm results/graph_${3}_${lambda_closing}_${lambda_dist}_04.ppm
+# diff=$(($nbasins - $nbasins_after))
+# echo " dist = $lambda_dist | $nbasins -> $nbasins_after (diff = $diff ) $(($diff * 100 / $nbasins))%"
+# done
+# fi
+# fi
done
# rm *.dump
}
Index: trunk/milena/sandbox/fabien/igr/med.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/med.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/med.cc (revision 3526)
@@ -0,0 +1,87 @@
+#include <iostream>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/alias/window2d.hh>
+#include <mln/core/alias/neighb3d.hh>
+#include <mln/core/alias/window3d.hh>
+
+#include <mln/io/dump/all.hh>
+#include <mln/io/dicom/load.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u12.hh>
+#include <mln/value/label_16.hh>
+#include <mln/value/label_32.hh>
+
+#include <mln/core/var.hh>
+#include <mln/core/routine/extend.hh>
+#include <mln/accu/mean.hh>
+#include <mln/accu/median_h.hh>
+#include <mln/morpho/elementary/dilation.hh>
+#include <mln/labeling/mean_values.hh>
+#include <mln/level/compute.hh>
+#include <mln/pw/all.hh>
+#include <mln/util/array.hh>
+
+
+
+///////////////////
+// //
+// Main Function //
+// //
+///////////////////
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u12;
+ using value::label_16;
+ using value::label_32;
+ typedef label_32 L;
+
+ if (argc != 5)
+ {
+ std::cout << "Usage: " << argv[0] << " <ima.dump> <dimensions> <ima.dcm> <nbasins>"
+ << std::endl;
+ return 1;
+ }
+
+ unsigned dim = atoi(argv[2]);
+ L nbasins = atoi(argv[4]);
+ if (dim != 2 && dim != 3)
+ {
+ std::cout << "<dimensions> invalid" << std::endl;
+ return 1;
+ }
+
+ if (dim == 2)
+ {
+ image2d<L> labels;
+ io::dump::load(labels, argv[1]);
+ image2d<int_u12> dcm;
+ io::dicom::load(dcm, argv[3]);
+
+ mln_VAR(wst_dilate, morpho::elementary::dilation(extend(labels | (pw::value(labels) == 0u), labels), c8()));
+ data::fill((labels | (pw::value(labels) == 0u)).rw(), wst_dilate);
+ mln_VAR(wst_mean, labeling::mean_values(dcm, labels, nbasins));
+
+ accu::mean<float> accu_mean;
+ util::array<float> means = level::compute(accu_mean, wst_mean);
+
+ // FIXME: Take median value of means
+
+ io::dump::save(wst_mean, "med.dump");
+ std::cout << median << std::endl;
+ }
+ else
+ {
+ // FIXME
+ }
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/thres.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/thres.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/thres.cc (revision 3526)
@@ -0,0 +1,67 @@
+#include <iostream>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/alias/window2d.hh>
+#include <mln/core/alias/neighb3d.hh>
+#include <mln/core/alias/window3d.hh>
+
+#include <mln/io/dump/all.hh>
+#include <mln/io/pbm/save.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u12.hh>
+#include <mln/value/label_16.hh>
+#include <mln/value/label_32.hh>
+
+#include <mln/binarization/threshold.hh>
+
+
+
+///////////////////
+// //
+// Main Function //
+// //
+///////////////////
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u12;
+ using value::label_16;
+ using value::label_32;
+ typedef label_32 L;
+
+ if (argc != 4)
+ {
+ std::cout << "Usage: " << argv[0] << " <ima.dump> <dimensions> <threshold>"
+ << std::endl;
+ return 1;
+ }
+
+ unsigned dim = atoi(argv[2]);
+ unsigned threshold = atoi(argv[3]);
+ if (dim != 2 && dim != 3)
+ {
+ std::cout << "<dimensions> invalid" << std::endl;
+ return 1;
+ }
+
+ if (dim == 2)
+ {
+ image2d<int_u12> input;
+ io::dump::load(input, argv[1]);
+ image2d<bool> bin_result = binarization::threshold(input, threshold);
+ io::pbm::save(bin_result, "result.pbm");
+ }
+ else
+ {
+ // FIXME
+ }
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/igr/Makefile (revision 3525)
+++ trunk/milena/sandbox/fabien/igr/Makefile (revision 3526)
@@ -42,5 +42,11 @@
graph: graph.cc
g++ -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o graph
+med: med.cc
+ g++ -I../../../ ${DICOM_INC} ${DICOM_LIBS} ${CXXFLAGS} $^ -o med
+
+thres: thres.cc
+ g++ -I../../../ ${CXXFLAGS} $^ -o thres
+
clean:
rm -rf *.dump *.p?m *.plot *.log *.csv
Index: trunk/milena/sandbox/fabien/TODO
===================================================================
--- trunk/milena/sandbox/fabien/TODO (revision 3525)
+++ trunk/milena/sandbox/fabien/TODO (revision 3526)
@@ -28,5 +28,9 @@
[X] Batch process watershed with 2D, 3D and any combination of parameters
[X] Cut into small tools
[X] Test 3D workflow on 2D images
-[ ] Create colorized colors for graph
-[ ] Diff with %
+[X] Create colorized colors for graph
+[X] Diff with %
+[ ] Find biggest dark regions (threshold value or median accu - median / 2 - )
+ [ ] Learn regions value
+ [ ] Threshold
+[ ] Profile for performance
Index: trunk/milena/sandbox/fabien/bin/dumpi12_to_pgm.cc
===================================================================
--- trunk/milena/sandbox/fabien/bin/dumpi12_to_pgm.cc (revision 0)
+++ trunk/milena/sandbox/fabien/bin/dumpi12_to_pgm.cc (revision 3526)
@@ -0,0 +1,55 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/make/image3d.hh>
+#include <mln/debug/slices_2d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u12.hh>
+#include <mln/value/label_32.hh>
+
+#include <mln/io/dump/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/level/stretch.hh>
+
+
+int usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.dump dim output.pgm" << std::endl;
+ return 1;
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u12;
+ using value::label_32;
+ using value::rgb8;
+
+ if (argc != 4)
+ return usage(argv);
+
+ unsigned dim = atoi(argv[2]);
+ unsigned nbasins = atoi(argv[3]);
+ if (dim != 2 && dim != 3)
+ {
+ std::cout << "<dimensions> invalid" << std::endl;
+ return 1;
+ }
+
+ if (dim == 2)
+ {
+ image2d<int_u12> ima2d;
+ io::dump::load(ima2d, argv[1]);
+ image2d<int_u8> ima_pgm = level::stretch(int_u8(), ima2d);
+ io::pgm::save(ima_pgm, argv[3]);
+ }
+ else
+ {
+ // FIXME
+ }
+
+ return 0;
+}
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fix missing trace in mln::test routines.
* mln/level/compare.hh,
* mln/test/positive.hh,
* mln/test/predicate.hh: Add trace.
Upgrade doc style.
* tests/level/compare.cc: Upgrade doc style.
mln/level/compare.hh | 88 +++++++++++++++++++++++++++++--------------------
mln/test/positive.hh | 17 ++++++---
mln/test/predicate.hh | 37 +++++++++++++++++---
tests/level/compare.cc | 10 ++---
4 files changed, 101 insertions(+), 51 deletions(-)
Index: mln/level/compare.hh
--- mln/level/compare.hh (revision 3524)
+++ mln/level/compare.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2009 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,9 @@
#ifndef MLN_LEVEL_COMPARE_HH
# define MLN_LEVEL_COMPARE_HH
-/*! \file mln/level/compare.hh
- *
- * \brief Comparison operators between the pixel values of images.
- */
+/// \file mln/level/compare.hh
+///
+/// Comparison operators between the pixel values of images.
# include <mln/core/concept/image.hh>
# include <mln/fun/vv2b/eq.hh>
@@ -43,38 +43,38 @@
namespace mln
{
- /*! Point-wise test if the pixel values of \p lhs are equal to the
- * pixel values of \p rhs.
- *
- * \param[in] lhs A first image.
- * \param[in] rhs A second image.
- *
- * \pre lhs.domain == rhs.domain
- */
+ /// Point-wise test if the pixel values of \p lhs are equal to the
+ /// pixel values of \p rhs.
+ ///
+ /// \param[in] lhs A first image.
+ /// \param[in] rhs A second image.
+ ///
+ /// \pre lhs.domain == rhs.domain
+ //
template <typename L, typename R>
bool operator == (const Image<L>& lhs, const Image<R>& rhs);
- /*! Point-wise test if the pixel values of \p lhs are point-wise
- * less than the pixel values of \p rhs.
- *
- * \param[in] lhs A first image.
- * \param[in] rhs A second image.
- *
- * \pre lhs.domain == rhs.domain
- */
+ /// Point-wise test if the pixel values of \p lhs are point-wise
+ /// less than the pixel values of \p rhs.
+ ///
+ /// \param[in] lhs A first image.
+ /// \param[in] rhs A second image.
+ ///
+ /// \pre lhs.domain == rhs.domain
+ //
template <typename L, typename R>
bool operator < (const Image<L>& lhs, const Image<R>& rhs);
- /*! Point-wise test if the pixel values of \p lhs are point-wise
- * less than or equal to the pixel values of \p rhs.
- *
- * \param[in] lhs A first image.
- * \param[in] rhs A second image.
- *
- * \pre lhs.domain == rhs.domain
- */
+ /// Point-wise test if the pixel values of \p lhs are point-wise
+ /// less than or equal to the pixel values of \p rhs.
+ ///
+ /// \param[in] lhs A first image.
+ /// \param[in] rhs A second image.
+ ///
+ /// \pre lhs.domain == rhs.domain
+ //
template <typename L, typename R> // required!
bool operator <= (const Image<L>& lhs, const Image<R>& rhs);
@@ -82,45 +82,63 @@
# ifndef MLN_INCLUDE_ONLY
+
template <typename L, typename R>
inline
bool operator == (const Image<L>& lhs_, const Image<R>& rhs_)
{
- typedef fun::vv2b::eq<mln_value(L), mln_value(R)> F;
+ trace::entering("level::compare (==)");
const L& lhs = exact(lhs_);
const R& rhs = exact(rhs_);
+
mln_precondition(lhs.is_valid());
mln_precondition(rhs.is_valid());
mln_precondition(lhs.domain() == rhs.domain());
- return test::predicate(lhs_, rhs_, F());
+ typedef fun::vv2b::eq<mln_value(L), mln_value(R)> F;
+ bool res = test::predicate(lhs_, rhs_, F());
+
+ trace::exiting("level::compare (==)");
+ return res;
}
+
template <typename L, typename R>
inline
bool operator < (const Image<L>& lhs_, const Image<R>& rhs_)
{
- typedef fun::vv2b::lt<mln_value(L), mln_value(R)> F;
+ trace::entering("level::compare (<)");
const L& lhs = exact(lhs_);
const R& rhs = exact(rhs_);
+
mln_precondition(lhs.domain() == rhs.domain());
- return test::predicate(lhs_, rhs_, F());
+ typedef fun::vv2b::lt<mln_value(L), mln_value(R)> F;
+ bool res = test::predicate(lhs_, rhs_, F());
+
+ trace::exiting("level::compare (<)");
+ return res;
}
+
template <typename L, typename R> // required!
inline
bool operator <= (const Image<L>& lhs_, const Image<R>& rhs_)
{
- typedef fun::vv2b::le<mln_value(L), mln_value(R)> F;
+ trace::entering("level::compare (<=)");
const L& lhs = exact(lhs_);
const R& rhs = exact(rhs_);
+
mln_precondition(lhs.domain() == rhs.domain());
- return test::predicate(lhs_, rhs_, F());
+ typedef fun::vv2b::le<mln_value(L), mln_value(R)> F;
+ bool res = test::predicate(lhs_, rhs_, F());
+
+ trace::exiting("level::compare (<=)");
+ return res;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/test/positive.hh
--- mln/test/positive.hh (revision 3524)
+++ mln/test/positive.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2009 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,9 @@
#ifndef MLN_TEST_POSITIVE_HH
# define MLN_TEST_POSITIVE_HH
-/*! \file mln/test/positive.hh
- *
- * \brief Test if an image only contains positive values.
- */
+/// \file mln/test/positive.hh
+///
+/// Test if an image only contains positive values.
# include <mln/test/predicate.hh>
# include <mln/pw/all.hh>
@@ -56,17 +56,22 @@
inline
bool positive(const Image<I>& input_)
{
+ trace::entering("test::positive");
+
const I& input = exact(input_);
mln_precondition(input.is_valid());
// FIXME: Below the '>=' op should properly work with signed/unsigned without
// FIXME: warnings; so we really need to overload ops for functions when literals
// FIXME: are involved.
mln_value(I) zero_ = literal::zero;
- return test::predicate(input.domain(),
+ bool res = test::predicate(input.domain(),
pw::value(input) >= pw::cst(zero_));
// FIXME: test the version below.
// return test::predicate(input,
// fun::v2v::id<mln_value(I)>() >= pw::cst(0));
+
+ trace::exiting("test::positive");
+ return res;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/test/predicate.hh
--- mln/test/predicate.hh (revision 3524)
+++ mln/test/predicate.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 2009 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
@@ -49,6 +49,7 @@
///
/// \param[in] ima The image.
/// \param[in] f The predicate.
+ //
template <typename I, typename F>
bool predicate(const Image<I>& ima, const Function_v2b<F>& f);
@@ -59,6 +60,7 @@
/// \param[in] lhs The image.
/// \param[in] rhs The image.
/// \param[in] f The predicate.
+ //
template <typename I, typename J, typename F>
bool predicate(const Image<I>& lhs, const Image<J>& rhs, const Function_vv2b<F>& f);
@@ -67,12 +69,16 @@
///
/// \param[in] pset The point set.
/// \param[in] f The predicate.
+ //
template <typename S, typename F>
bool predicate(const Site_Set<S>& pset, const Function_p2b<F>& f);
# ifndef MLN_INCLUDE_ONLY
+
+ // Tests.
+
namespace internal
{
@@ -115,6 +121,9 @@
} // end of namespace mln::test::internal
+
+ // Implementations.
+
namespace impl
{
@@ -191,15 +200,22 @@
} // end of namespace mln::test::impl
+
// Facades.
+
template <typename I, typename F>
inline
bool predicate(const Image<I>& ima, const Function_v2b<F>& f)
{
+ trace::entering("test::predicate");
+
internal::predicate_tests(ima, f);
- return impl::predicate_(mln_trait_image_speed(I)(), exact(ima),
+ bool res = impl::predicate_(mln_trait_image_speed(I)(), exact(ima),
exact(f));
+
+ trace::exiting("test::predicate");
+ return res;
}
@@ -207,23 +223,34 @@
inline
bool predicate(const Image<I>& lhs_, const Image<J>& rhs_, const Function_vv2b<F>& f)
{
+ trace::entering("test::predicate");
+
const I& lhs = exact(lhs_);
const J& rhs = exact(rhs_);
internal::predicate_tests(lhs_, rhs_, f);
- return impl::predicate_(mln_trait_image_speed(I)(),
+ bool res = impl::predicate_(mln_trait_image_speed(I)(),
mln_trait_image_speed(J)(),
lhs, rhs,
exact(f));
+
+ trace::exiting("test::predicate");
+ return res;
}
template <typename S, typename F>
inline
bool predicate(const Site_Set<S>& pset, const Function_p2b<F>& f)
{
+ trace::entering("test::predicate");
+
internal::predicate_tests(pset, f);
- return impl::predicate_(exact(pset), exact(f));
+
+ bool res = impl::predicate_(exact(pset), exact(f));
+
+ trace::exiting("test::predicate");
+ return res;
}
# endif // ! MLN_INCLUDE_ONLY
Index: tests/level/compare.cc
--- tests/level/compare.cc (revision 3524)
+++ tests/level/compare.cc (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2009 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,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/level/compare.cc
- *
- * \brief Tests on mln::level::compare.
- */
+/// \file tests/level/compare.cc
+///
+/// Tests on mln::level::compare.
#include <mln/core/image/image2d.hh>
#include <mln/level/compare.hh>
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-13 Etienne FOLIO <folio(a)lrde.epita.fr>
Sandbox reorganization.
Moved again many old things...
* folio/dt/canvas_dt.hh: Remove.
* folio/dt/chamfer.hh: Remove.
* folio/dt/cp.hh: Remove.
* folio/dt/dmap.hh: Remove.
* folio/dt/path.hh: Remove.
* folio/dt/raw_cp_fast.hh: Remove.
* folio/dt/raw_cp_slow.hh: Remove.
* folio/dt/raw_dmap_fast.hh: Remove.
* folio/dt/raw_dmap_slow.hh: Remove.
* folio/dt/raw_path_fast.hh: Remove.
* folio/dt/raw_path_slow.hh: Remove.
* folio/dt: Remove.
* folio/dt_old/canevas_dt.hh: Remove.
* folio/dt_old/chamfer.cc: Remove.
* folio/dt_old/distance_front.cc: Remove.
* folio/dt_old/distance_front_new.hh: Remove.
* folio/dt_old/dt.cc: Remove.
* folio/dt_old/dt.hh: Remove.
* folio/dt_old/dt.spe.hh: Remove.
* folio/dt_old/naive.cc: Remove.
* folio/dt_old/psn.cc: Remove.
* folio/dt_old/psn_log.cc: Remove.
* folio/dt_old: Remove.
* folio/mln/dt/dt_old: New.
* folio/mln/dt: New.
---
canvas_dt.hh | 178 ++++++++++++++++++
chamfer.hh | 156 +++++++++++++++
cp.hh | 121 ++++++++++++
dmap.hh | 119 ++++++++++++
dt_old/canevas_dt.hh | 231 +++++++++++++++++++++++
dt_old/chamfer.cc | 206 +++++++++++++++++++++
dt_old/distance_front.cc | 88 +++++++++
dt_old/distance_front_new.hh | 420 +++++++++++++++++++++++++++++++++++++++++++
dt_old/dt.cc | 59 ++++++
dt_old/dt.hh | 101 ++++++++++
dt_old/dt.spe.hh | 123 ++++++++++++
dt_old/naive.cc | 142 ++++++++++++++
dt_old/psn.cc | 203 ++++++++++++++++++++
dt_old/psn_log.cc | 290 +++++++++++++++++++++++++++++
path.hh | 121 ++++++++++++
raw_cp_fast.hh | 173 +++++++++++++++++
raw_cp_slow.hh | 155 +++++++++++++++
raw_dmap_fast.hh | 164 ++++++++++++++++
raw_dmap_slow.hh | 149 +++++++++++++++
raw_path_fast.hh | 173 +++++++++++++++++
raw_path_slow.hh | 155 +++++++++++++++
21 files changed, 3527 insertions(+)
Index: trunk/milena/sandbox/folio/mln/dt/dmap.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dmap.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dmap.hh (revision 3524)
@@ -0,0 +1,119 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_DMAP_HH
+# define MLN_DT_DMAP_HH
+
+# include "canvas_dt.hh"
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the output image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, unsigned)
+ dmap(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic functor.
+
+ template <typename I_, typename N_>
+ struct dmap_functor
+ {
+ typedef I_ I;
+ typedef N_ N;
+
+ const I& input;
+ const N& nbh;
+ unsigned max;
+
+ dmap_functor(const I& input, const N& nbh, unsigned max)
+ : input(input),
+ nbh(nbh),
+ max(max)
+ {}
+
+ void init()
+ {
+ }
+
+ void init_in_for(const mln_point(I)& p)
+ {
+ (void) p;
+ }
+
+ void run_in_for(const mln_point(I)& p, const mln_point(I)& n)
+ {
+ (void) p;
+ (void) n;
+ }
+ };
+
+ } // end of namespace mln::dt::impl
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, unsigned)
+ dmap(const Image<I>& input, const N& nbh, unsigned max)
+ {
+ trace::entering("dt::dmap");
+ mln_precondition(exact(input).is_valid());
+
+ typedef impl::dmap_functor<I, N> F;
+ F f(exact(input), nbh, max);
+ mln::canvas::dt<F> call(f);
+
+ trace::exiting("dt::dmap");
+ return call.distance;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_DMAP_HH
Index: trunk/milena/sandbox/folio/mln/dt/canvas_dt.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/canvas_dt.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/canvas_dt.hh (revision 3524)
@@ -0,0 +1,178 @@
+// 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 MLN_DT_CANVAS_HH
+# define MLN_DT_CANVAS_HH
+
+# include <vector>
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ // General version.
+
+ template <typename F>
+ class dt
+ {
+ public:
+
+ // Ctor.
+ dt(F& f);
+
+ typedef typename F::I I;
+ typedef typename F::N N;
+ typedef mln_point(I) point;
+
+ mln_ch_value(I, unsigned) distance;
+
+ private:
+
+ // Functor.
+ F& f;
+
+ void init();
+ void run();
+
+ std::vector< std::vector<point> > bucket;
+ unsigned bucket_size;
+ unsigned mod;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /*-------------.
+ | canvas::dt. |
+ `-------------*/
+
+ template <typename F>
+ dt<F>::dt(F& f)
+ : f(f),
+ bucket_size(0)
+ {
+ trace::entering("canvas::dt");
+
+ this->init();
+ this->run();
+
+ trace::exiting("canvas::dt");
+ }
+
+ template <typename F>
+ void
+ dt<F>::init()
+ {
+ // Preconditions.
+ mln_precondition(f.input.is_valid());
+
+ f.init(); //< f call.
+
+ initialize(distance, f.input);
+
+ // Mod determination.
+ mln::accu::max<unsigned> accu;
+ mln_fwd_piter(I) p(f.input.domain());
+ mln_qiter(N) n(f.nbh, p);
+ for_all(n)
+ accu.take(n.w());
+ mod = accu.to_result() + 1;
+
+ bucket.resize(mod);
+
+ // Initialization
+ for_all(p)
+ {
+ f.init_in_for(p); //< f call.
+ if (f.input(p))
+ {
+ distance(p) = literal::zero;
+ for_all(n)
+ if (f.input.has(n) && ! f.input(n))
+ {
+ bucket[0].push_back(p);
+ ++bucket_size;
+ break;
+ }
+ }
+ else
+ distance(p) = f.max;
+ }
+ }
+
+ template <typename F>
+ void
+ dt<F>::run()
+ {
+ point p;
+ mln_qiter(N) n(f.nbh, p);
+
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ std::vector<point>& bucket_d = bucket[d % mod];
+ for (unsigned i = 0; i < bucket_d.size(); ++i)
+ {
+ p = bucket_d[i];
+
+ /* |00| |00| insert "a" in bucket 1 |00|
+ |ab| -> |12| -> insert "b" in bucket 1 -> |11| -> then in bucket 2.
+ when d = 2, "b" has already been processed when d = 1. */
+ if (distance(p) < d)
+ continue;
+
+ for_all(n)
+ if (distance.has(n) && distance(n) > d)
+ {
+ unsigned newDist = d + n.w();
+
+ if (newDist < distance(n))
+ {
+ f.run_in_for(p, n); //< f call.
+ distance(n) = newDist;
+ bucket[newDist % mod].push_back(n);
+ ++bucket_size;
+ }
+ }
+ }
+ bucket_size -= bucket_d.size();
+ bucket_d.clear();
+ }
+
+ } // end of method dt::run()
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DT_CANVAS_HH
Index: trunk/milena/sandbox/folio/mln/dt/cp.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/cp.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/cp.hh (revision 3524)
@@ -0,0 +1,121 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_CP_HH
+# define MLN_DT_CP_HH
+
+# include "canvas_dt.hh"
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the output image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, mln_point(I))
+ cp(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic functor.
+
+ template <typename I_, typename N_>
+ struct cp_functor
+ {
+ typedef I_ I;
+ typedef N_ N;
+
+ const I& input;
+ const N& nbh;
+ unsigned max;
+
+ cp_functor(const I& input, const N& nbh, unsigned max)
+ : input(input),
+ nbh(nbh),
+ max(max)
+ {}
+
+ mln_ch_value(I, mln_point(I)) output;
+
+ void init()
+ {
+ initialize(output, input);
+ }
+
+ void init_in_for(const mln_point(I)& p)
+ {
+ output(p) = p;
+ }
+
+ void run_in_for(const mln_point(I)& p, const mln_point(I)& n)
+ {
+ output(n) = p;
+ }
+ };
+
+ } // end of namespace mln::dt::impl
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, mln_point(I))
+ cp(const Image<I>& input, const N& nbh, unsigned max)
+ {
+ trace::entering("dt::cp");
+ mln_precondition(exact(input).is_valid());
+
+ typedef impl::cp_functor<I, N> F;
+ F f(exact(input), nbh, max);
+ mln::canvas::dt<F> call(f);
+
+ trace::exiting("dt::cp");
+ return f.output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_CP_HH
Index: trunk/milena/sandbox/folio/mln/dt/raw_path_fast.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/raw_path_fast.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/raw_path_fast.hh (revision 3524)
@@ -0,0 +1,173 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_RAW_PATH_FAST_HH
+# define MLN_DT_RAW_PATH_FAST_HH
+
+# include <queue>
+# include <map>
+# include <cmath>
+
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/literal/zero.hh>
+# include <mln/accu/max.hh>
+
+# include <iostream>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the output image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, mln_point(I))
+ raw_path_fast(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, mln_point(I))
+ raw_path_fast(const Image<I>& input_, const N& nbh, unsigned max)
+ {
+ // Preconditions.
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ // Types.
+ typedef mln_point(I) point;
+
+ // Initialization of distance.
+ mln_ch_value(I, unsigned) distance;
+ initialize(distance, input);
+
+ // Initialization of output.
+ mln_ch_value(I, mln_point(I)) output;
+ initialize(output, input);
+
+ // Mod determination.
+ mln_accu_with_(accu::max, unsigned) accu;
+ mln_fwd_piter(I) p(input.domain());
+ mln_qiter(N) n(nbh, p);
+ for_all(n)
+ accu.take(n.w());
+ unsigned mod = accu.to_result() + 1;
+
+ // Aux data.
+ std::vector< std::vector<point> > bucket(mod);
+ unsigned bucket_size = 0;
+
+ // Initialization.
+ {
+ for_all(p)
+ {
+ output(p) = p;
+ if (input(p))
+ {
+ distance(p) = literal::zero;
+ for_all(n)
+ if (input.has(n) && ! input(n))
+ {
+ bucket[0].push_back(p);
+ ++bucket_size;
+ break;
+ }
+ }
+ else
+ distance(p) = max;
+ }
+ }
+
+ // Propagation.
+ {
+ point p;
+ mln_qiter(N) n(nbh, p);
+
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ std::vector<point>& bucket_d = bucket[d % mod];
+ for (unsigned i = 0; i < bucket_d.size(); ++i)
+ {
+ p = bucket_d[i];
+
+ // FIXME: Draw...
+ if (distance(p) < d)
+ // p has already been processed, having a distance less than d.
+ continue;
+
+ for_all(n)
+ if (distance.has(n) && distance(n) > d)
+ {
+ unsigned newDist = d + n.w();
+
+ if (newDist < distance(n))
+ {
+ output(n) = output(p);
+ distance(n) = newDist;
+ bucket[newDist % mod].push_back(n);
+ ++bucket_size;
+ }
+ }
+ }
+ bucket_size -= bucket_d.size();
+ bucket_d.clear();
+ }
+
+ } // end of propagation.
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_RAW_PATH_FAST_HH
Index: trunk/milena/sandbox/folio/mln/dt/chamfer.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/chamfer.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/chamfer.hh (revision 3524)
@@ -0,0 +1,156 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_CHAMFER_HH
+# define MLN_DT_CHAMFER_HH
+
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Distance tranform by chamfer application.
+ *
+ * \param[in] input_ The input image.
+ * \param[in] chamfer The chamfer window to use for distance calcul.
+ * \return A pair (distance map, nearest point map).
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename T>
+ std::pair<mln_ch_value(I, T), mln_ch_value(I, mln_point(I))>
+ chamfer(const Image<I>& input_,
+ w_window<mln_dpoint(I), T> chamfer);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ /*! Computes a pass of the chamfer DT algorithm.
+ *
+ * \param[in] p Iterator on the input image to use.
+ * \param[in] chamfer The chamfer window to use for distance calcul.
+ * \param[in] input The input image.
+ * \param[out] outputDistance The distance map updated.
+ * \param[out] outputnearest The nearest points map updated.
+ */
+ template<typename Q, typename I, typename T>
+ inline
+ void
+ chamfer_pass(const w_window<mln_dpoint(I), T> chamfer,
+ const I& input,
+ mln_ch_value(I, T)& outputDistance,
+ mln_ch_value(I, mln_point(I))& outputNearest)
+ {
+ typedef w_window<mln_dpoint(I), T> W;
+
+ Q p(input.domain());
+ mln_qiter(W) q(chamfer, p);
+ for_all(p)
+ {
+ std::pair<T, mln_point(I)> min(mln_max(T), p);
+
+ for_all(q)
+ if (input.has(q) && outputDistance(q) != mln_max(T))
+ {
+ T v = outputDistance(q) + q.w();
+
+ if (v < min.first)
+ {
+ min.first = v;
+ min.second = outputNearest(q);
+ }
+ }
+
+ if (min.first < outputDistance(p))
+ {
+ outputDistance(p) = min.first;
+ outputNearest(p) = min.second;
+ }
+ }
+ }
+
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename T>
+ inline
+ std::pair<mln_ch_value(I, T), mln_ch_value(I, mln_point(I))>
+ chamfer(const Image<I>& input_,
+ w_window<mln_dpoint(I), T> chamfer)
+ {
+ typedef w_window<mln_dpoint(I), T> W;
+
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_ch_value(I, T) outputDistance;
+ initialize(outputDistance, input);
+
+ mln_ch_value(I, mln_point(I)) outputNearest;
+ initialize(outputNearest, input);
+
+ // Initialization.
+ {
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ {
+ outputDistance(p) = input(p) ? literal::zero : mln_max(T);
+ outputNearest(p) = p;
+ }
+ }
+
+ // First pass.
+ impl::chamfer_pass<mln_fwd_piter(I)>
+ (chamfer, input, outputDistance, outputNearest);
+
+ chamfer.sym();
+
+ // Second pass.
+ impl::chamfer_pass<mln_bkd_piter(I)>
+ (chamfer, input, outputDistance, outputNearest);
+
+ return std::pair<mln_ch_value(I, T), mln_ch_value(I, mln_point(I))>
+ (outputDistance, outputNearest);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_CHAMFER_HH
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/psn.cc
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/psn.cc (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/psn.cc (revision 3524)
@@ -0,0 +1,203 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_CHAMFER_HH
+# define MLN_DT_CHAMFER_HH
+
+# include <queue>
+# include <map>
+# include <cmath>
+
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/literal/zero.hh>
+
+# include <iostream>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the output image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, unsigned)
+ psn(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, unsigned)
+ psn(const Image<I>& input_, const N& nbh, unsigned max)
+ {
+ // Preconditions.
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ // Types.
+ typedef mln_point(I) point;
+
+ // Initialization of output.
+ mln_ch_value(I, unsigned) output;
+ initialize(output, input);
+
+ // Initialization.
+ // {
+
+ std::map<unsigned, std::queue<point> > bucket;
+ unsigned bucket_size = 0;
+
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ if (input(p))
+ {
+ output(p) = literal::zero;
+ bucket[0].push(p);
+ ++bucket_size;
+ }
+ else
+ output(p) = max;
+
+ unsigned d = 0;
+
+ // }
+
+ while (bucket_size != 0)
+ {
+ std::queue<point> bucket_d = bucket[d];
+ while (! bucket_d.empty())
+ {
+ point p = bucket_d.front();
+ bucket_d.pop();
+ --bucket_size;
+
+ if (output(p) == d)
+ {
+ mln_qiter(N) n(nbh, p);
+
+ for_all(n)
+ if (output.has(n))
+ {
+ unsigned newOut = output(p) + n.w();
+
+ if (newOut < output(n))
+ {
+ output(n) = newOut;
+ bucket[newOut].push(n);
+ ++bucket_size;
+ }
+ }
+ }
+ }
+ bucket.erase(d);
+ ++d;
+ }
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_CHAMFER_HH
+
+#include <iostream>
+#include <mln/core/image/image2d.hh>
+#include <mln/debug/println.hh>
+#include <mln/make/win_chamfer.hh>
+#include <mln/data/fill.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/level/stretch.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/core/image/sub_image.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/pw/value.hh>
+
+int main()
+{
+ using namespace mln;
+
+ image2d<bool> ima(5,5);
+ bool vals[] = { 1, 0, 0, 1, 1,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0};
+ data::fill(ima, vals);
+
+ image2d<bool> msk(5,5);
+ bool rest[] = { 1, 0, 1, 1, 1,
+ 1, 0, 1, 1, 1,
+ 1, 1, 0, 0, 0,
+ 1, 1, 0, 1, 1,
+ 1, 1, 1, 1, 1};
+ data::fill(msk, rest);
+
+ int ws[] = { 2, 1, 2,
+ 1, 0, 1,
+ 2, 1, 2 };
+ image2d<unsigned> out;
+ out = dt::psn(ima | pw::value(msk), make::w_window2d(ws), 50);
+
+ debug::println(ima | pw::value(msk));
+ debug::println(out);
+
+// image2d<bool> ima = io::pbm::load("../../img/c01.pbm");
+
+// image2d<value::int_u8> out2(out.domain());
+// level::stretch(out, out2);
+
+// io::pgm::save(out2, "out.pgm");
+}
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/canevas_dt.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/canevas_dt.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/canevas_dt.hh (revision 3524)
@@ -0,0 +1,231 @@
+/*!
+ * \file canevas_dt.hh
+ * \author ornthalas <ornthalas(a)gmail.com>
+ */
+
+#ifndef CANEVAS_DT_HH
+# define CANEVAS_DT_HH
+
+# include <queue>
+# include <map>
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+# include <mln/literal/zero.hh>
+
+# include <mln/core/concept/neighborhood.hh>
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ // General version.
+
+ template <typename F>
+ struct dt
+ {
+ // Functor.
+ F& f;
+
+ typedef typename F::I I;
+ typedef typename F::N N;
+ typedef typename F::L L;
+ typedef mln_psite(I) point;
+
+ mln_ch_value(I, L) output;
+
+ // Ctor.
+ dt(F& f);
+
+ void init();
+ void run();
+
+ std::map<unsigned, std::queue<point> > bucket;
+ unsigned bucket_size;
+
+ unsigned current_distance;
+ };
+
+ template <typename F>
+ struct dt_fastest
+ {
+ // Functor.
+ F& f;
+
+ typedef typename F::I I;
+ typedef typename F::N N;
+ typedef typename F::L L;
+ typedef mln_psite(I) point;
+
+ mln_ch_value(I, L) output;
+
+ // Ctor.
+ dt_fastest(F& f);
+
+ void init();
+ void run();
+
+ std::map<unsigned, std::queue<point> > bucket;
+ unsigned bucket_size;
+
+ unsigned current_distance;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /*-------------.
+ | canvas::dt. |
+ `-------------*/
+
+ template <typename F>
+ dt<F>::dt(F& f)
+ : f(f),
+ bucket_size(0),
+ current_distance(0)
+ {
+ trace::entering("canvas::dt");
+
+ this->init();
+ this->run();
+
+ trace::exiting("canvas::dt");
+ }
+
+ template <typename F>
+ void
+ dt<F>::init()
+ {
+ this->f.init();
+ initialize(this->output, this->f.input);
+
+ mln_fwd_piter(I) p(this->f.input.domain());
+ for_all(p)
+ if (this->f.input(p))
+ {
+ this->output(p) = literal::zero;
+ this->bucket[0].push(p);
+ ++this->bucket_size;
+ }
+ else
+ this->output(p) = this->max;
+ }
+
+ template <typename F>
+ void
+ dt<F>::run()
+ {
+ while (this->bucket_size != 0)
+ {
+ std::queue<point> bucket_d = this->bucket[this->current_distance];
+ while (! bucket_d.empty())
+ {
+ point p = bucket_d.front();
+ bucket_d.pop();
+ --bucket_size;
+
+ if (this->output(p) == this->current_distance)
+ {
+ mln_qiter(N) n(this->nbh, p);
+
+ for_all(n)
+ if (this->output.has(n))
+ {
+ unsigned new_out = this->output(p) + n.w();
+
+ if (new_out < this->output(n))
+ {
+ this->output(n) = new_out;
+ this->bucket[new_out].push(n);
+ ++this->bucket_size;
+ }
+ }
+ }
+ }
+ this->bucket.erase(this->current_distance);
+ ++this->current_distance;
+ }
+ }
+
+ /*---------------------.
+ | canvas::dt_fastest. |
+ `---------------------*/
+ template <typename F>
+ dt_fastest<F>::dt_fastest(F& f)
+ : f(f),
+ bucket_size(0),
+ current_distance(0)
+ {
+ trace::entering("canvas::dt");
+
+ this->init();
+ this->run();
+
+ trace::exiting("canvas::dt");
+ }
+
+ template <typename F>
+ void
+ dt_fastest<F>::init()
+ {
+ this->f.init();
+ initialize(this->output, this->f.input);
+
+ mln_fwd_piter(I) p(this->f.input.domain());
+ for_all(p)
+ if (this->f.input(p))
+ {
+ this->output(p) = literal::zero;
+ this->bucket[0].push(p);
+ ++this->bucket_size;
+ }
+ else
+ this->output(p) = this->max;
+ }
+
+ template <typename F>
+ void
+ dt_fastest<F>::run()
+ {
+ while (this->bucket_size != 0)
+ {
+ std::queue<point> bucket_d = this->bucket[this->current_distance];
+ while (! bucket_d.empty())
+ {
+ point p = bucket_d.front();
+ bucket_d.pop();
+ --bucket_size;
+
+ if (this->output(p) == this->current_distance)
+ {
+ mln_qiter(N) n(this->nbh, p);
+
+ for_all(n)
+ if (this->output.has(n))
+ {
+ unsigned new_out = this->output(p) + n.w();
+
+ if (new_out < this->output(n))
+ {
+ this->output(n) = new_out;
+ this->bucket[new_out].push(n);
+ ++this->bucket_size;
+ }
+ }
+ }
+ }
+ this->bucket.erase(this->current_distance);
+ ++this->current_distance;
+ }
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_DT_HH
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/dt.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/dt.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/dt.hh (revision 3524)
@@ -0,0 +1,101 @@
+/*!
+ * \file psn.cc
+ * \author ornthalas <ornthalas(a)gmail.com>
+ */
+
+#ifndef DT_HH
+# define DT_HH
+
+// The 'fastest' specialization is in:
+# include "dt.spe.hh"
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ template<typename I, typename N, typename L>
+ inline
+ mln_ch_value(I, L)
+ dt(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic functor.
+
+ template <typename I_, typename N_, typename L_>
+ struct dt_functor
+ {
+ typedef I_ I;
+ typedef N_ N;
+ typedef L_ L;
+
+ const I& input;
+ const N& nbh;
+ unsigned max;
+
+ dt_functor(const I_& input, const N_& nbh, const unsigned max)
+ : input(input),
+ nbh(nbh),
+ max(max)
+ {}
+
+ void init() {}
+ };
+
+
+ // Generic implementation.
+
+ namespace generic
+ {
+
+ template<typename I, typename N, typename L>
+ inline
+ mln_ch_value(I, L)
+ dt_(const Image<I>& input, const N& nbh, unsigned max)
+ {
+ trace::entering("dt::impl::generic::dt_");
+
+ typedef dt_functor<I, N, L> F;
+ F f(input, nbh, max);
+ canvas::dt<F> run(f);
+
+ trace::exiting("dt::impl::generic::dt_");
+ return run.output;
+ }
+
+ } // end of namespace mln::dt::impl::generic
+
+ } // end of namespace mln::dt::impl
+
+
+ // Facade.
+
+ template<typename I, typename N, typename L>
+ inline
+ mln_ch_value(I, L)
+ dt(const Image<I>& input, const N& nbh, unsigned max)
+ {
+ trace::entering("dt::dt");
+ mln_precondition(exact(input).is_valid());
+
+ mln_ch_value(I, L) output =
+ impl::dt_(mln_trait_image_speed(I)(),
+ exact(input), nbh, max);
+
+ trace::exiting("dt::dt");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // !DT_HH
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/psn_log.cc
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/psn_log.cc (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/psn_log.cc (revision 3524)
@@ -0,0 +1,290 @@
+
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_CHAMFER_HH
+# define MLN_DT_CHAMFER_HH
+
+# include <vector>
+# include <queue>
+# include <map>
+# include <cmath>
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/literal/zero.hh>
+
+#include <mln/core/image/image2d.hh>
+# include <mln/debug/println.hh>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] chamfer The chamfer window to use for distance calcul.
+ * \return A pair <distance map, closest point map>.
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, unsigned)
+ psn(const Image<I>& input_, const N& nbh);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+
+ template <typename BP>
+ class compare
+ {
+ public:
+ bool
+ operator()(const BP& lhs, const BP& rhs) const
+ {
+ return lhs.second > rhs.second;
+ }
+ };
+
+ template <typename D>
+ unsigned
+ sq(const D& dp)
+ {
+ unsigned res = 0;
+
+ for (unsigned i = 0; i < D::dim; ++i)
+ res += std::abs(dp[i]); // FIXME: dp[i] * dp[i];
+
+ return res;
+ }
+
+ template <typename BP>
+ unsigned
+ size(const std::map<unsigned, std::queue<BP> >& bucket,
+ int d)
+ {
+ unsigned s = 0;
+ typename std::map<unsigned, std::queue<BP> >::const_iterator i;
+ for (i = bucket.begin(); i != bucket.end(); ++i)
+ if (i->first >= d)
+ s += i->second.size();
+ return s;
+ }
+
+ template <typename BP>
+ unsigned
+ size(const std::map<unsigned, std::queue<BP> >& bucket)
+ {
+ unsigned s = 0;
+ typename std::map<unsigned, std::queue<BP> >::const_iterator i;
+ for (i = bucket.begin(); i != bucket.end(); ++i)
+ s += i->second.size();
+ return s;
+ }
+
+ template <typename BP>
+ void
+ print(const std::map<unsigned, std::queue<BP> >& bucket)
+ {
+ typename std::map<unsigned, std::queue<BP> >::const_iterator i;
+ int d = -1;
+ for (i = bucket.begin(); i != bucket.end(); ++i)
+ {
+ if (i->first != d)
+ {
+ d = i->first;
+ std::cout << std::endl << d << ": ";
+ }
+ std::queue<BP> qu = i->second; // copy
+ std::vector<BP> v;
+ v.push_back(qu.front()); qu.pop();
+ typename std::vector<BP>::const_iterator j;
+ for (j = v.begin(); j != v.end(); ++j)
+ std::cout << j->first << " "; // point
+ }
+ std::cout << std::endl;
+ }
+
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, unsigned)
+ psn(const Image<I>& input_, const N& nbh)
+ {
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_ch_value(I, unsigned) D;
+ initialize(D, input);
+
+ static const unsigned M = 666; // FIXME
+
+ // Initialization.
+ typedef mln_point(I) point;
+ typedef mln_dpoint(I) dpoint;
+ typedef std::pair<point, dpoint> BP;
+
+ std::map<unsigned, std::queue<BP> > bucket;
+ unsigned bucket_size = 0;
+
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ if (input(p))
+ {
+ D(p) = literal::zero;
+ bucket[0].push(BP(p, literal::zero));
+ ++bucket_size;
+ }
+ else
+ D(p) = M;
+
+ debug::println(input);
+ debug::println(D);
+ impl::print(bucket);
+
+ unsigned d = 0;
+
+ while (impl::size(bucket, d) != 0)
+ {
+
+ mln_invariant(impl::size(bucket) == bucket_size);
+
+ std::cout << "PROCESSING d = " << d << std::endl;
+
+ std::queue<BP>& bucket_d = bucket[d];
+
+ while (! bucket_d.empty())
+ {
+ point p = bucket_d.front().first;
+ dpoint dp = bucket_d.front().second;
+
+ bucket_d.pop();
+ --bucket_size;
+
+ std::cout << "pop " << p << " at D=" << D(p) << std::endl;
+
+ if (D(p) == d)
+ {
+ mln_niter(N) n_(nbh, p);
+
+ for_all(n_)
+ if (D.has(n_))
+ {
+ dpoint n = n_ - p;
+ unsigned newD = impl::sq(dp + n);
+
+ std::cout << " n=" << n_ << " at D=" << D(n_)
+ << " and newD=" << newD
+ << (newD < D(p + n) ? " push" : "")
+ << std::endl;
+
+ if (newD < D(p + n)) // p + n = p + n_ - p = n_
+ {
+ D(n_) = newD;
+ bucket[newD].push(BP(p + n, dp + n));
+ ++bucket_size;
+ }
+ }
+ }
+ }
+ ++d;
+ }
+
+ return D;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_CHAMFER_HH
+
+#include <iostream>
+#include <mln/debug/println.hh>
+#include <mln/make/win_chamfer.hh>
+#include <mln/data/fill.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/level/stretch.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/core/image/sub_image.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/pw/value.hh>
+
+int main()
+{
+ using namespace mln;
+
+// image2d<bool> ima(5,5);
+// bool vals[] = { 1, 1, 1, 0, 0,
+// 0, 0, 1, 0, 0,
+// 0, 0, 1, 0, 0,
+// 0, 0, 0, 0, 0,
+// 0, 0, 0, 0, 0 };
+
+ image2d<bool> ima(3,3);
+ bool vals[] = { 1, 0, 0,
+ 0, 0, 0,
+ 0, 0, 0};
+ data::fill(ima, vals);
+
+ image2d<bool> msk(3,3);
+ bool rest[] = { 1, 0, 1,
+ 1, 0, 1,
+ 1, 1, 1};
+ data::fill(msk, rest);
+
+ image2d<unsigned> out;
+ out = dt::psn(ima | pw::value(msk), c4());
+
+ debug::println(ima | pw::value(msk));
+ debug::println(out);
+
+// image2d<bool> ima = io::pbm::load("../../img/c01.pbm");
+
+// image2d<value::int_u8> out2(out.domain());
+// level::stretch(out, out2);
+
+// io::pgm::save(out2, "out.pgm");
+}
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/distance_front.cc
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/distance_front.cc (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/distance_front.cc (revision 3524)
@@ -0,0 +1,88 @@
+// Copyright (C) 2008, 2009 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/transform/distance_front.cc
+///
+/// Test on mln::transform::distance_front.
+
+#include <mln/core/var.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/make/w_window2d_int.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/data/fill.hh>
+#include <mln/debug/println.hh>
+#include <mln/opt/at.hh>
+#include <mln/level/compare.hh>
+
+#include <mln/transform/internal/distance_functor.hh>
+#include "distance_front_new.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ typedef image2d<bool> I;
+
+ I input(9, 9);
+ data::fill(input, false);
+ opt::at(input, 4, 4) = true;
+
+
+ int_u8 dmax = 18;
+ mln_VAR(nbh, c4());
+
+ int ws[] = { 0, 9, 0, 9, 0,
+ 9, 6, 4, 6, 9,
+ 0, 4, 0, 4, 0,
+ 9, 6, 4, 6, 9,
+ 0, 9, 0, 9, 0 };
+ mln_VAR(w_win, make::w_window2d_int(ws));
+
+
+ transform::internal::distance_functor<I> f;
+ image2d<int_u8> ref, output;
+
+ ref = canvas::impl::generic::distance_front(input,
+ nbh,
+ w_win,
+ dmax,
+ f);
+ // debug::println("ref", ref);
+
+ output = canvas::impl::distance_front_fastest(input,
+ nbh,
+ w_win,
+ dmax,
+ f);
+ // debug::println("output", output);
+
+ mln_invariant(output == ref);
+}
Property changes on: trunk/milena/sandbox/folio/mln/dt/dt_old/distance_front.cc
___________________________________________________________________
Name: svn:mergeinfo
+
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/naive.cc
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/naive.cc (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/naive.cc (revision 3524)
@@ -0,0 +1,142 @@
+// 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
+// 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 TODO
+ *
+ * \brief Defines a function that creates a distance map corresponding to a
+ * given image.
+ */
+
+#ifndef MLN_DT_NAIVE_HH
+# define MLN_DT_NAIVE_HH
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/literal/zero.hh>
+# include <mln/accu/min.hh>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Calculates the distance map corresponding to a given image
+ *
+ * \param[in] input_ The binary reference image.
+ * \param[in] fun_ The function used for distance aclculus.
+ * \return New distance map image.
+ *
+ * \pre \p input_ has to be initialized.
+ *
+ * \fixme Use instead of R the result type of F::operator().
+ */
+ template <typename I, typename F>
+ inline
+ mln_ch_value(I, mln_result(F))
+ naive(const Image<I>& input_, const Function_v2v<F>& fun_);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // Facade.
+
+ template <typename I, typename F>
+ inline
+ mln_ch_value(I, mln_result(F))
+ naive(const Image<I>& input_, const Function_v2v<F>& fun_)
+ {
+ const I& input = exact(input_);
+ const F& fun = exact(fun_);
+ mln_precondition(input.is_valid());
+
+ mln_ch_value(I, mln_result(F)) output;
+ initialize(output, input);
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ {
+ if (input(p))
+ output(p) = literal::zero;
+ else
+ {
+ // p is in the background so the distance has to be computed.
+ accu::min_<mln_result(F)> min;
+ min.init();
+
+ mln_piter(I) q(input.domain());
+ for_all(q)
+ if (input(q))
+ {
+ // q is in the object.
+// metal::vec<2, int> vp = p.to_point(), vq = q.to_point();
+// min.take(fun_(vp, vq));
+ min.take(fun(p - q));
+ }
+ output(p) = min;
+ }
+ }
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_NAIVE_HH
+
+#include <iostream>
+#include <mln/debug/println.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/data/fill.hh>
+#include <mln/fun/v2v/norm.hh>
+
+int main()
+{
+ using namespace mln;
+
+ {
+ image2d<bool> ima(5,5);
+ bool vals[] = { 1, 1, 1, 0, 0,
+ 0, 0, 1, 0, 0,
+ 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0 };
+
+ data::fill(ima, vals);
+ debug::println(ima);
+
+ typedef fun::v2v::l2_norm< algebra::vec<2,float>, float > L2;
+ image2d<float> out = dt::naive(ima, L2());
+
+ std::cerr << "Distance:" << std::endl;
+ debug::println(out);
+ }
+}
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/chamfer.cc
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/chamfer.cc (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/chamfer.cc (revision 3524)
@@ -0,0 +1,206 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_CHAMFER_HH
+# define MLN_DT_CHAMFER_HH
+
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Distance tranform by chamfer application.
+ *
+ * \param[in] input_ The input image.
+ * \param[in] chamfer The chamfer window to use for distance calcul.
+ * \return A pair (distance map, nearest point map).
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename T>
+ std::pair<mln_ch_value(I, T), mln_ch_value(I, mln_point(I))>
+ chamfer(const Image<I>& input_,
+ w_window<mln_dpoint(I), T> chamfer);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ /*! Computes a pass of the chamfer DT algorithm.
+ *
+ * \param[in] p Iterator on the input image to use.
+ * \param[in] chamfer The chamfer window to use for distance calcul.
+ * \param[in] input The input image.
+ * \param[out] outputDistance The distance map updated.
+ * \param[out] outputnearest The nearest points map updated.
+ */
+ template<typename Q, typename I, typename T>
+ inline
+ void
+ chamfer_pass(const w_window<mln_dpoint(I), T> chamfer,
+ const I& input,
+ mln_ch_value(I, T)& outputDistance,
+ mln_ch_value(I, mln_point(I))& outputNearest)
+ {
+ typedef w_window<mln_dpoint(I), T> W;
+
+ Q p(input.domain());
+ mln_qiter(W) q(chamfer, p);
+ for_all(p)
+ {
+ std::pair<T, mln_point(I)> min(mln_max(T), p);
+
+ for_all(q)
+ if (input.has(q) && outputDistance(q) != mln_max(T))
+ {
+ T v = outputDistance(q) + q.w();
+
+ if (v < min.first)
+ {
+ min.first = v;
+ min.second = outputNearest(q);
+ }
+ }
+
+ if (min.first < outputDistance(p))
+ {
+ outputDistance(p) = min.first;
+ outputNearest(p) = min.second;
+ }
+ }
+ }
+
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename T>
+ inline
+ std::pair<mln_ch_value(I, T), mln_ch_value(I, mln_point(I))>
+ chamfer(const Image<I>& input_,
+ w_window<mln_dpoint(I), T> chamfer)
+ {
+ typedef w_window<mln_dpoint(I), T> W;
+
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_ch_value(I, T) outputDistance;
+ initialize(outputDistance, input);
+
+ mln_ch_value(I, mln_point(I)) outputNearest;
+ initialize(outputNearest, input);
+
+ // Initialization.
+ {
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ {
+ outputDistance(p) = input(p) ? literal::zero : mln_max(T);
+ outputNearest(p) = p;
+ }
+ }
+
+ // First pass.
+ impl::chamfer_pass<mln_fwd_piter(I)>
+ (chamfer, input, outputDistance, outputNearest);
+
+ chamfer.sym();
+
+ // Second pass.
+ impl::chamfer_pass<mln_bkd_piter(I)>
+ (chamfer, input, outputDistance, outputNearest);
+
+ return std::pair<mln_ch_value(I, T), mln_ch_value(I, mln_point(I))>
+ (outputDistance, outputNearest);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_CHAMFER_HH
+
+#include <iostream>
+#include <mln/core/image/image2d.hh>
+#include <mln/debug/println.hh>
+#include <mln/make/win_chamfer.hh>
+#include <mln/data/fill.hh>
+
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/level/stretch.hh>
+#include <mln/value/int_u8.hh>
+
+int main()
+{
+ using namespace mln;
+
+ w_window2d_int chamfer = make::mk_chamfer_3x3_int<1, 2>();
+
+ {
+// image2d<bool> ima(5,5);
+// bool vals[] = { 1, 1, 1, 0, 0,
+// 0, 0, 1, 0, 0,
+// 0, 0, 1, 0, 0,
+// 0, 0, 0, 0, 0,
+// 0, 0, 0, 0, 0 };
+
+// data::fill(ima, vals);
+// debug::println(ima);
+
+// std::pair<image2d<int>, image2d<mln_point_(image2d<bool>)> > out;
+// for (int i = 0; i < 999; ++i)
+// out = dt::chamfer(ima, chamfer);
+
+// std::cerr << "Distance:" << std::endl;
+// debug::println(out.first);
+// std::cerr << "PPP:" << std::endl;
+// debug::println(out.second);
+
+ image2d<bool> ima = io::pbm::load("../../img/c01.pbm");
+
+ std::pair<image2d<int>, image2d<mln_point_(image2d<bool>)> > out;
+ out = dt::chamfer(ima, chamfer);
+
+ image2d<value::int_u8> out2(out.first.domain());
+ level::stretch(out.first, out2);
+
+ io::pgm::save(out2, "out.pgm");
+
+ }
+}
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/distance_front_new.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/distance_front_new.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/distance_front_new.hh (revision 3524)
@@ -0,0 +1,420 @@
+// 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_CANVAS_DISTANCE_FRONT_HH
+# define MLN_CANVAS_DISTANCE_FRONT_HH
+
+/// \file mln/canvas/distance_front.hh
+///
+/// Discrete distance canvas by front propagation.
+
+# include <vector>
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/weighted_window.hh>
+# include <mln/data/fill.hh>
+# include <mln/accu/max.hh>
+# include <mln/extension/adjust_fill.hh>
+
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ /// Discrete front distance canvas.
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
+ mln_ch_value(I, D)
+ distance_front(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win, D max,
+ F& functor);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Tests.
+
+ namespace internal
+ {
+
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
+ void
+ distance_front_tests(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const Weighted_Window<W>& w_win_,
+ D max,
+ F& functor)
+ {
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const W& w_win = exact(w_win_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(nbh.is_valid());
+
+ (void) input;
+ (void) nbh;
+ (void) max;
+ (void) functor;
+ }
+
+
+ } // of namespace mln::canvas::internal
+
+
+
+ // Implementations.
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
+ mln_ch_value(I, D)
+ distance_front(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const Weighted_Window<W>& w_win_,
+ D max,
+ F& functor)
+ {
+ trace::entering("canvas::impl::generic::distance_front");
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const W& w_win = exact(w_win_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(w_win.is_valid());
+
+ typedef mln_site(I) P;
+ typedef std::vector<P> bucket_t;
+
+ // Distance map.
+ mln_ch_value(I, D) dmap;
+ initialize(dmap, input);
+ data::fill(dmap, max);
+
+ // Mod determination.
+ unsigned mod;
+ {
+ accu::max<unsigned> m;
+ for (unsigned i = 0; i < w_win.size(); ++i)
+ m.take(w_win.w(i));
+ mod = unsigned(m) + 1;
+ }
+
+ // Aux data.
+ std::vector<bucket_t> bucket(mod);
+ unsigned bucket_size = 0;
+
+ // Initialization.
+ {
+ functor.init(input); // <-- init
+ mln_piter(I) p(input.domain());
+ mln_niter(N) n(nbh, p);
+ for_all(p)
+ if (functor.inqueue_p_wrt_input_p(input(p))) // <-- inqueue_p_wrt_input_p
+ {
+ dmap(p) = 0;
+ for_all(n)
+ if (input.domain().has(n) &&
+ functor.inqueue_p_wrt_input_n(input(n))) // <-- inqueue_p_wrt_input_n
+ {
+ bucket[0].push_back(p);
+ ++bucket_size;
+ break;
+ }
+ }
+ } // end of Initialization.
+
+ // Propagation.
+ {
+ P p;
+ mln_qiter(W) q(w_win, p);
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ bucket_t& bucket_d = bucket[d % mod];
+ for (unsigned i = 0; i < bucket_d.size(); ++i)
+ {
+ p = bucket_d[i];
+
+ if (dmap(p) == max)
+ {
+ // Saturation so stop.
+ bucket_size = bucket_d.size(); // So at end bucket_size == 0.
+ break;
+ }
+
+ if (dmap(p) < d)
+ // p has already been processed, having a distance less than d.
+ continue;
+
+ for_all(q)
+ if (dmap.domain().has(q) && dmap(q) > d)
+ {
+ unsigned d_ = d + q.w();
+ if (d_ < dmap(q))
+ {
+ dmap(q) = d_;
+ functor.process(p, q); // <- process
+ bucket[d_ % mod].push_back(q);
+ ++bucket_size;
+ }
+ }
+ }
+ bucket_size -= bucket_d.size();
+ bucket_d.clear();
+ }
+ } // end of Propagation.
+
+ trace::exiting("canvas::impl::generic::distance_front");
+ return dmap;
+ }
+
+ } // of namespace mln::canvas::impl::generic
+
+
+
+ // Fastest version.
+
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
+ mln_ch_value(I, D)
+ distance_front_fastest(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const Weighted_Window<W>& w_win_,
+ D max, F& functor)
+ {
+ trace::entering("canvas::impl::distance_front_fastest");
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const W& w_win = exact(w_win_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(w_win.is_valid());
+
+ // Handling w_win.
+ extension::adjust(input, w_win);
+ const unsigned n_ws = w_win.size();
+ util::array<int> dp = offsets_wrt(input, w_win.win());
+ mln_invariant(dp.nelements() == n_ws);
+
+ // Distance map.
+ mln_ch_value(I, D) dmap;
+ initialize(dmap, input);
+ data::fill(dmap, max);
+
+ // Mod determination.
+ unsigned mod;
+ {
+ accu::max<unsigned> m;
+ for (unsigned i = 0; i < w_win.size(); ++i)
+ m.take(w_win.w(i));
+ mod = unsigned(m) + 1;
+ }
+
+ // Aux data.
+ typedef std::vector<unsigned> bucket_t;
+ std::vector<bucket_t> bucket(mod);
+ unsigned bucket_size = 0;
+
+ // Initialization.
+ {
+ functor.init_(input); // <-- init
+
+ // For the extension to be ignored:
+ extension::fill(input, true);
+ extension::fill(dmap, D(0));
+
+ mln_pixter(const I) p(input);
+ mln_nixter(const I, N) n(p, nbh);
+ for_all(p)
+ if (functor.inqueue_p_wrt_input_p_(p.val())) // <-- inqueue_p_wrt_input_p
+ {
+ dmap.element(p.offset()) = 0;
+ for_all(n)
+ if (functor.inqueue_p_wrt_input_n_(n.val())) // <-- inqueue_p_wrt_input_n
+ {
+ bucket[0].push_back(p.offset());
+ ++bucket_size;
+ break;
+ }
+ }
+ } // end of Initialization.
+
+ // Propagation.
+ {
+ unsigned p;
+
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ bucket_t& bucket_d = bucket[d % mod];
+ for (unsigned i = 0; i < bucket_d.size(); ++i)
+ {
+ p = bucket_d[i];
+
+ if (dmap.element(p) == max)
+ {
+ // Saturation so stop.
+ bucket_size = bucket_d.size(); // So at end bucket_size == 0.
+ break;
+ }
+
+ if (dmap.element(p) < d)
+ // p has already been processed, having a distance less than d.
+ continue;
+
+ for (unsigned i = 0; i < n_ws; ++i)
+ {
+ unsigned q = p + dp[i];
+ if (dmap.element(q) > d)
+ {
+ unsigned d_ = d + w_win.w(i);
+ if (d_ < dmap.element(q))
+ {
+ dmap.element(q) = d_;
+ functor.process_(p, q); // <- process
+ bucket[d_ % mod].push_back(q);
+ ++bucket_size;
+ }
+ }
+ }
+ }
+ bucket_size -= bucket_d.size();
+ bucket_d.clear();
+ }
+ } // end of Propagation.
+
+ trace::exiting("canvas::impl::distance_front_fastest");
+ return dmap;
+ }
+
+
+ } // of namespace mln::canvas::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
+ inline
+ mln_ch_value(I, D)
+ distance_front_dispatch(metal::false_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win,
+ D max, F& functor)
+ {
+ return impl::generic::distance_front(input, nbh, max, w_win, functor);
+ }
+
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
+ inline
+ mln_ch_value(I, D)
+ distance_front_dispatch(metal::true_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win,
+ D max, F& functor)
+ {
+ return impl::distance_front_fastest(input, nbh, w_win, max, functor);
+ // return impl::generic::distance_front(input, nbh, w_win, max, functor);
+ }
+
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
+ inline
+ mln_ch_value(I, D)
+ distance_front_dispatch(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win,
+ D max, F& functor)
+ {
+ enum {
+ test = mlc_equal(mln_trait_image_speed(I),
+ trait::image::speed::fastest)::value
+ &&
+ mln_is_simple_neighborhood(N)::value
+ };
+ return distance_front_dispatch(metal::bool_<test>(),
+ input, nbh, w_win, max, functor);
+ }
+
+
+ } // of namespace mln::canvas::internal
+
+
+
+ // Facade.
+
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
+ inline
+ mln_ch_value(I, D)
+ distance_front(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win,
+ D max, F& functor)
+ {
+ trace::entering("canvas::distance_front");
+
+ internal::distance_front_tests(input, nbh, w_win, max, functor);
+
+ mln_ch_value(I,D) output;
+ output = internal::distance_front_dispatch(input, nbh, w_win, max, functor);
+
+ trace::exiting("canvas::distance_front");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_DISTANCE_FRONT_HH
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/dt.cc
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/dt.cc (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/dt.cc (revision 3524)
@@ -0,0 +1,59 @@
+/*!
+ * \file dt.cc
+ * \author ornthalas <ornthalas(a)gmail.com>
+ */
+
+#include <iostream>
+#include <mln/core/image/image2d.hh>
+#include <mln/debug/println.hh>
+#include <mln/make/win_chamfer.hh>
+#include <mln/data/fill.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/level/stretch.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/core/image/sub_image.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/pw/value.hh>
+
+#include "dt.hh"
+
+int main()
+{
+ using namespace mln;
+
+ image2d<bool> ima(5,5);
+ bool vals[] = { 1, 0, 0, 1, 1,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0};
+ data::fill(ima, vals);
+
+ image2d<bool> msk(5,5);
+ bool rest[] = { 1, 0, 1, 1, 1,
+ 1, 0, 1, 1, 1,
+ 1, 1, 0, 0, 0,
+ 1, 1, 0, 1, 1,
+ 1, 1, 1, 1, 1};
+ data::fill(msk, rest);
+
+ int ws[] = { 2, 1, 2,
+ 1, 0, 1,
+ 2, 1, 2 };
+ image2d<unsigned> out;
+ out = dt::dt(ima | pw::value(msk), make::w_window2d(ws), 50);
+
+ debug::println(ima | pw::value(msk));
+ debug::println(out);
+
+// image2d<bool> ima = io::pbm::load("../../img/c01.pbm");
+
+// image2d<value::int_u8> out2(out.domain());
+// level::stretch(out, out2);
+
+// io::pgm::save(out2, "out.pgm");
+}
Index: trunk/milena/sandbox/folio/mln/dt/dt_old/dt.spe.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/dt_old/dt.spe.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/dt_old/dt.spe.hh (revision 3524)
@@ -0,0 +1,123 @@
+/*!
+ * \file test_psn.spe.hh
+ * \author ornthalas <ornthalas(a)gmail.com>
+ */
+
+#ifndef DT_SPE_HH
+# define DT_SPE_HH
+
+# ifndef DT_HH
+# error "Forbidden inclusion of *.spe.hh"
+# endif // ! DT_HH
+
+# include "canevas_dt.hh"
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ template<typename I, typename N, typename L>
+ inline
+ mln_ch_value(I, L)
+ dt(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+
+ // Fwd decl of the Generic version.
+
+ namespace generic
+ {
+
+ template<typename I, typename N, typename L>
+ inline
+ mln_ch_value(I, L)
+ dt_(const Image<I>& input_, const N& nbh, unsigned max);
+
+ } // end of namespace mln::dt::impl::generic
+
+
+ // Fastest functor.
+
+ template <typename I_, typename N_, typename L_>
+ struct dt_fasfunctor
+ {
+ typedef I_ I;
+ typedef N_ N;
+ typedef L_ L;
+
+ const I& input;
+ const N& nbh;
+ unsigned max;
+
+ dt_fasfunctor(const I_& input, const N_& nbh, const unsigned max)
+ : input(input),
+ nbh(nbh),
+ max(max)
+ {}
+
+ void init() {}
+ };
+
+
+ // Fastest implementation.
+
+ namespace fastest
+ {
+
+ template<typename I, typename N, typename L>
+ inline
+ mln_ch_value(I, L)
+ dt_(const I& input, const N& nbh, unsigned max)
+ {
+ trace::entering("dt::impl::dt_fas");
+
+ typedef dt_fasfunctor<I,N,L> F;
+ F f(input, nbh, max);
+ canvas::dt_fastest<F> run(f);
+
+ trace::exiting("dt::impl::dt_fas");
+ return run.output;
+ }
+
+ } // end of namespace mln::dt::impl::fastest
+
+
+ // Disjunction between "fastest" and "not fastest".
+
+ template<typename I, typename N, typename L>
+ inline
+ mln_ch_value(I, L)
+ dt_(trait::image::speed::any,
+ const I& input, const N& nbh, unsigned max)
+ {
+ return generic::dt_(input, nbh, max);
+ }
+
+ template<typename I, typename N, typename L>
+ inline
+ mln_ch_value(I, L)
+ dt_(trait::image::speed::fastest,
+ const I& input, const N& nbh, unsigned max)
+ {
+ return fastest::dt_(input, nbh, max);
+ }
+
+
+ } // end of namespace mln::dt::impl
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+
+#endif // !DT_SPE_HH
Index: trunk/milena/sandbox/folio/mln/dt/raw_dmap_fast.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/raw_dmap_fast.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/raw_dmap_fast.hh (revision 3524)
@@ -0,0 +1,164 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_RAW_DMAP_FAST_HH
+# define MLN_DT_RAW_DMAP_FAST_HH
+
+# include <queue>
+# include <map>
+# include <cmath>
+
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/literal/zero.hh>
+
+# include <iostream>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the distance image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, unsigned)
+ raw_dmap_fast(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, unsigned)
+ raw_dmap_fast(const Image<I>& input_, const N& nbh, unsigned max)
+ {
+ // Preconditions.
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ // Types.
+ typedef mln_point(I) point;
+
+ // Initialization of distance.
+ mln_ch_value(I, unsigned) distance;
+ initialize(distance, input);
+
+ // Mod determination.
+ mln_accu_with_(accu::max, unsigned) accu;
+ mln_fwd_piter(I) p(input.domain());
+ mln_qiter(N) n(nbh, p);
+ for_all(n)
+ accu.take(n.w());
+ unsigned mod = accu.to_result() + 1;
+
+ // Aux data.
+ std::vector< std::vector<point> > bucket(mod);
+ unsigned bucket_size = 0;
+
+ // Initialization.
+ {
+ for_all(p)
+ if (input(p))
+ {
+ distance(p) = literal::zero;
+ for_all(n)
+ if (input.has(n) && ! input(n))
+ {
+ bucket[0].push_back(p);
+ ++bucket_size;
+ break;
+ }
+ }
+ else
+ distance(p) = max;
+ }
+
+ // Propagation.
+ {
+ point p;
+ mln_qiter(N) n(nbh, p);
+
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ std::vector<point>& bucket_d = bucket[d % mod];
+ for (unsigned i = 0; i < bucket_d.size(); ++i)
+ {
+ p = bucket_d[i];
+
+ // FIXME: Draw...
+ if (distance(p) < d)
+ // p has already been processed, having a distance less than d.
+ continue;
+
+ for_all(n)
+ if (distance.has(n) && distance(n) > d)
+ {
+ unsigned newDist = d + n.w();
+
+ if (newDist < distance(n))
+ {
+ distance(n) = newDist;
+ bucket[newDist % mod].push_back(n);
+ ++bucket_size;
+ }
+ }
+ }
+ bucket_size -= bucket_d.size();
+ bucket_d.clear();
+ }
+
+ } // end of propagation.
+
+ return distance;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_RAW_DMAP_FAST_HH
Index: trunk/milena/sandbox/folio/mln/dt/raw_cp_fast.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/raw_cp_fast.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/raw_cp_fast.hh (revision 3524)
@@ -0,0 +1,173 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_RAW_CP_FAST_HH
+# define MLN_DT_RAW_CP_FAST_HH
+
+# include <queue>
+# include <map>
+# include <cmath>
+
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/literal/zero.hh>
+# include <mln/accu/max.hh>
+
+# include <iostream>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the output image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialcped.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, mln_point(I))
+ raw_cp_fast(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, mln_point(I))
+ raw_cp_fast(const Image<I>& input_, const N& nbh, unsigned max)
+ {
+ // Preconditions.
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ // Types.
+ typedef mln_point(I) point;
+
+ // Initialcpation of distance.
+ mln_ch_value(I, unsigned) distance;
+ initialize(distance, input);
+
+ // Initialcpation of output.
+ mln_ch_value(I, mln_point(I)) output;
+ initialize(output, input);
+
+ // Mod determination.
+ mln_accu_with_(accu::max, unsigned) accu;
+ mln_fwd_piter(I) p(input.domain());
+ mln_qiter(N) n(nbh, p);
+ for_all(n)
+ accu.take(n.w());
+ unsigned mod = accu.to_result() + 1;
+
+ // Aux data.
+ std::vector< std::vector<point> > bucket(mod);
+ unsigned bucket_size = 0;
+
+ // Initialcpation.
+ {
+ for_all(p)
+ {
+ output(p) = p;
+ if (input(p))
+ {
+ distance(p) = literal::zero;
+ for_all(n)
+ if (input.has(n) && ! input(n))
+ {
+ bucket[0].push_back(p);
+ ++bucket_size;
+ break;
+ }
+ }
+ else
+ distance(p) = max;
+ }
+ }
+
+ // Propagation.
+ {
+ point p;
+ mln_qiter(N) n(nbh, p);
+
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ std::vector<point>& bucket_d = bucket[d % mod];
+ for (unsigned i = 0; i < bucket_d.size(); ++i)
+ {
+ p = bucket_d[i];
+
+ // FIXME: Draw...
+ if (distance(p) < d)
+ // p has already been processed, having a distance less than d.
+ continue;
+
+ for_all(n)
+ if (distance.has(n) && distance(n) > d)
+ {
+ unsigned newDist = d + n.w();
+
+ if (newDist < distance(n))
+ {
+ output(n) = p;
+ distance(n) = newDist;
+ bucket[newDist % mod].push_back(n);
+ ++bucket_size;
+ }
+ }
+ }
+ bucket_size -= bucket_d.size();
+ bucket_d.clear();
+ }
+
+ } // end of propagation.
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_RAW_CP_FAST_HH
Index: trunk/milena/sandbox/folio/mln/dt/raw_path_slow.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/raw_path_slow.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/raw_path_slow.hh (revision 3524)
@@ -0,0 +1,155 @@
+// Copyright (C) 2007 EPITA Research and Development unsignedaboratory
+//
+// This file is part of the Olena unsignedibrary. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public unsignedicense 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 unsignedicense for more details.
+//
+// You should have received a copy of the GNU General Public unsignedicense
+// 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
+// unsignedicense. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public unsignedicense.
+
+#ifndef MLN_DT_RAW_PATH_SLOW_HH
+# define MLN_DT_RAW_PATH_SLOW_HH
+
+# include <queue>
+# include <map>
+# include <cmath>
+
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/literal/zero.hh>
+
+# include <iostream>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the output image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, mln_point(I))
+ raw_path_slow(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, mln_point(I))
+ raw_path_slow(const Image<I>& input_, const N& nbh, unsigned max)
+ {
+ // Preconditions.
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ // Types.
+ typedef mln_point(I) point;
+
+ // Initialization of distance.
+ mln_ch_value(I, unsigned) distance;
+ initialize(distance, input);
+
+ // Initialization of output.
+ mln_ch_value(I, mln_point(I)) output;
+ initialize(output, input);
+
+ // Initialization.
+ // {
+
+ std::map< unsigned, std::queue<point> > bucket;
+ unsigned bucket_size = 0;
+
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ {
+ output(p) = p;
+ if (input(p))
+ {
+ distance(p) = literal::zero;
+ bucket[0].push(p);
+ ++bucket_size;
+ }
+ else
+ distance(p) = max;
+ }
+
+ // }
+
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ std::queue<point> bucket_d = bucket[d];
+ while (! bucket_d.empty())
+ {
+ point p = bucket_d.front();
+ bucket_d.pop();
+ --bucket_size;
+
+ if (distance(p) == d)
+ {
+ mln_qiter(N) n(nbh, p);
+
+ for_all(n)
+ if (distance.has(n))
+ {
+ unsigned newDist = d + n.w();
+
+ if (newDist < distance(n))
+ {
+ distance(n) = newDist;
+ output(n) = output(p);
+ bucket[newDist].push(n);
+ ++bucket_size;
+ }
+ }
+ }
+ }
+ bucket.erase(d);
+ }
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_RAW_PATH_SLOW_HH
Index: trunk/milena/sandbox/folio/mln/dt/path.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/path.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/path.hh (revision 3524)
@@ -0,0 +1,121 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DT_PATH_HH
+# define MLN_DT_PATH_HH
+
+# include "canvas_dt.hh"
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the output image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, mln_point(I))
+ path(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic functor.
+
+ template <typename I_, typename N_>
+ struct path_functor
+ {
+ typedef I_ I;
+ typedef N_ N;
+
+ const I& input;
+ const N& nbh;
+ unsigned max;
+
+ path_functor(const I& input, const N& nbh, unsigned max)
+ : input(input),
+ nbh(nbh),
+ max(max)
+ {}
+
+ mln_ch_value(I, mln_point(I)) output;
+
+ void init()
+ {
+ initialize(output, input);
+ }
+
+ void init_in_for(const mln_point(I)& p)
+ {
+ output(p) = p;
+ }
+
+ void run_in_for(const mln_point(I)& p, const mln_point(I)& n)
+ {
+ output(n) = output(p);
+ }
+ };
+
+ } // end of namespace mln::dt::impl
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, mln_point(I))
+ path(const Image<I>& input, const N& nbh, unsigned max)
+ {
+ trace::entering("dt::path");
+ mln_precondition(exact(input).is_valid());
+
+ typedef impl::path_functor<I, N> F;
+ F f(exact(input), nbh, max);
+ mln::canvas::dt<F> call(f);
+
+ trace::exiting("dt::path");
+ return f.output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_PATH_HH
Index: trunk/milena/sandbox/folio/mln/dt/raw_dmap_slow.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/raw_dmap_slow.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/raw_dmap_slow.hh (revision 3524)
@@ -0,0 +1,149 @@
+// Copyright (C) 2007 EPITA Research and Development unsignedaboratory
+//
+// This file is part of the Olena unsignedibrary. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public unsignedicense 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 unsignedicense for more details.
+//
+// You should have received a copy of the GNU General Public unsignedicense
+// 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
+// unsignedicense. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public unsignedicense.
+
+#ifndef MLN_DT_RAW_DMAP_SLOW_HH
+# define MLN_DT_RAW_DMAP_SLOW_HH
+
+# include <queue>
+# include <map>
+# include <cmath>
+
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/literal/zero.hh>
+
+# include <iostream>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the output image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialized.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, unsigned)
+ raw_dmap_slow(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, unsigned)
+ raw_dmap_slow(const Image<I>& input_, const N& nbh, unsigned max)
+ {
+ // Preconditions.
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ // Types.
+ typedef mln_point(I) point;
+
+ // Initialization of distance.
+ mln_ch_value(I, unsigned) distance;
+ initialize(distance, input);
+
+ // Initialization.
+ // {
+
+ std::map< unsigned, std::queue<point> > bucket;
+ unsigned bucket_size = 0;
+
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ {
+ if (input(p))
+ {
+ distance(p) = literal::zero;
+ bucket[0].push(p);
+ ++bucket_size;
+ }
+ else
+ distance(p) = max;
+ }
+
+ // }
+
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ std::queue<point> bucket_d = bucket[d];
+ while (! bucket_d.empty())
+ {
+ point p = bucket_d.front();
+ bucket_d.pop();
+ --bucket_size;
+
+ if (distance(p) == d)
+ {
+ mln_qiter(N) n(nbh, p);
+
+ for_all(n)
+ if (distance.has(n))
+ {
+ unsigned newDist = d + n.w();
+
+ if (newDist < distance(n))
+ {
+ distance(n) = newDist;
+ bucket[newDist].push(n);
+ ++bucket_size;
+ }
+ }
+ }
+ }
+ bucket.erase(d);
+ }
+
+ return distance;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_RAW_DMAP_SLOW_HH
Index: trunk/milena/sandbox/folio/mln/dt/raw_cp_slow.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/dt/raw_cp_slow.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/dt/raw_cp_slow.hh (revision 3524)
@@ -0,0 +1,155 @@
+// Copyright (C) 2007 EPITA Research and Development unsignedaboratory
+//
+// This file is part of the Olena unsignedibrary. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public unsignedicense 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 unsignedicense for more details.
+//
+// You should have received a copy of the GNU General Public unsignedicense
+// 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
+// unsignedicense. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public unsignedicense.
+
+#ifndef MLN_DT_RAW_CP_SLOW_HH
+# define MLN_DT_RAW_CP_SLOW_HH
+
+# include <queue>
+# include <map>
+# include <cmath>
+
+# include <mln/core/concept/image.hh>
+# include <mln/make/w_window.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/literal/zero.hh>
+
+# include <iostream>
+
+namespace mln
+{
+
+ namespace dt
+ {
+
+ /*! Propagation using a single neighborhood (PSN).
+ *
+ * \param[in] input_ The input image.
+ * \param[in] nbh The chamfer window to use for distance calcul.
+ * \param[in] max Max value of the output image.
+ * \return A distance map.
+ *
+ * \pre \p img has to be initialcped.
+ */
+ template<typename I, typename N>
+ mln_ch_value(I, mln_point(I))
+ raw_cp_slow(const Image<I>& input_, const N& nbh, unsigned max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+ } // end of namespace mln::dt::impl
+
+
+
+ // Facade.
+
+ template<typename I, typename N>
+ inline
+ mln_ch_value(I, mln_point(I))
+ raw_cp_slow(const Image<I>& input_, const N& nbh, unsigned max)
+ {
+ // Preconditions.
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ // Types.
+ typedef mln_point(I) point;
+
+ // Initialcpation of distance.
+ mln_ch_value(I, unsigned) distance;
+ initialize(distance, input);
+
+ // Initialcpation of output.
+ mln_ch_value(I, mln_point(I)) output;
+ initialize(output, input);
+
+ // Initialcpation.
+ // {
+
+ std::map< unsigned, std::queue<point> > bucket;
+ unsigned bucket_size = 0;
+
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ {
+ output(p) = p;
+ if (input(p))
+ {
+ distance(p) = literal::zero;
+ bucket[0].push(p);
+ ++bucket_size;
+ }
+ else
+ distance(p) = max;
+ }
+
+ // }
+
+ for (unsigned d = 0; bucket_size != 0; ++d)
+ {
+ std::queue<point> bucket_d = bucket[d];
+ while (! bucket_d.empty())
+ {
+ point p = bucket_d.front();
+ bucket_d.pop();
+ --bucket_size;
+
+ if (distance(p) == d)
+ {
+ mln_qiter(N) n(nbh, p);
+
+ for_all(n)
+ if (distance.has(n))
+ {
+ unsigned newDist = d + n.w();
+
+ if (newDist < distance(n))
+ {
+ distance(n) = newDist;
+ output(n) = p;
+ bucket[newDist].push(n);
+ ++bucket_size;
+ }
+ }
+ }
+ }
+ bucket.erase(d);
+ }
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::dt
+
+} // end of namespace mln
+
+#endif // ! MLN_DT_RAW_CP_SLOW_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add an identity site iterator adaptor.
* mln/core/internal/piter_identity.hh: New.
* mln/core/internal/site_iterator_base.hh (todo): Remove; done.
* mln/core/internal/site_set_iterator_base.hh (pset): New.
Upgrade file doc style.
piter_identity.hh | 88 ++++++++++++++++++++++++++++++++++++++++++++++
site_iterator_base.hh | 8 +---
site_set_iterator_base.hh | 29 ++++++++-------
3 files changed, 106 insertions(+), 19 deletions(-)
Index: mln/core/internal/piter_identity.hh
--- mln/core/internal/piter_identity.hh (revision 0)
+++ mln/core/internal/piter_identity.hh (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (C) 2009 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_INTERNAL_PITER_IDENTITY_HH
+# define MLN_CORE_INTERNAL_PITER_IDENTITY_HH
+
+/// \file mln/core/internal/piter_identity.hh
+///
+/// \brief Definition of site iterator identity adaptors.
+
+# include <mln/core/internal/piter_adaptor.hh>
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+ /// A base class for site iterator identity adaptors.
+ ///
+ /// Parameter \c Pi is the type of the site iterator adaptee;
+ /// parameter E is the exact type.
+ ///
+ template <typename Pi, typename E>
+ class piter_identity_ : public piter_adaptor_< Pi, // Adaptee.
+ mln_pset(Pi), // Site set.
+ E > // Exact type.
+ {
+ typedef piter_adaptor_< Pi, mln_pset(Pi), E > super_;
+
+ protected:
+
+ /// Constructor without argument.
+ piter_identity_();
+
+ /// Constructor from a point iterator \p piter.
+ piter_identity_(const Pi& piter);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename Pi, typename E>
+ inline
+ piter_identity_<Pi,E>::piter_identity_()
+ {
+ }
+
+ template <typename Pi, typename E>
+ inline
+ piter_identity_<Pi,E>::piter_identity_(const Pi& pi)
+ : super_(pi)
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_PITER_IDENTITY_HH
Index: mln/core/internal/site_iterator_base.hh
--- mln/core/internal/site_iterator_base.hh (revision 3521)
+++ mln/core/internal/site_iterator_base.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 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
@@ -31,17 +32,12 @@
/// \file mln/core/internal/site_iterator_base.hh
///
/// Base class to factor code for site iterator classes.
-///
-/// \todo Import tech doc from home.
# include <mln/core/concept/site_iterator.hh>
# include <mln/core/concept/pseudo_site.hh> // Use of if_possible::change_target.
-// FIXME: See todo.
-
-
namespace mln
{
Index: mln/core/internal/site_set_iterator_base.hh
--- mln/core/internal/site_set_iterator_base.hh (revision 3521)
+++ mln/core/internal/site_set_iterator_base.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2008, 2009 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,11 +29,10 @@
#ifndef MLN_CORE_INTERNAL_SITE_SET_ITERATOR_BASE_HH
# define MLN_CORE_INTERNAL_SITE_SET_ITERATOR_BASE_HH
-/*! \file mln/core/internal/site_set_iterator_base.hh
- *
- * \brief Base class to factor code for iterator classes directly
- * working on site sets.
- */
+/// \file mln/core/internal/site_set_iterator_base.hh
+///
+/// \brief Base class to factor code for iterator classes directly
+/// working on site sets.
# include <mln/core/internal/site_iterator_base.hh>
@@ -43,18 +43,21 @@
namespace internal
{
- /*! A base class for site iterators.
- *
- * Parameter \c S is the targeted site set type.
- *
- * IMPORTANT: Sub-classes have to define start_, next_,
- * is_valid_ and invalidate_.
- */
+ /// A base class for iterators on site sets.
+ ///
+ /// Parameter \c S is the targeted site set type.
+ ///
+ /// IMPORTANT: Sub-classes have to define start_, next_,
+ /// is_valid_ and invalidate_.
+ //
template <typename S, typename E>
class site_set_iterator_base : public site_iterator_base<S, E>
{
public:
+ /// The associated site set type.
+ typedef S pset;
+
/// Give the site set that this iterator browses.
const S& site_set() const;
1
0