https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add front computation of distance and influence zone.
* mln/transform/internal: New directory.
* mln/transform/internal/all.hh: New.
* mln/transform/distance_geodesic.hh: Copy to...
* mln/transform/distance_front.hh: ...this new file.
Update.
* mln/transform/distance_geodesic.hh
(distance_functor): Move into...
* mln/transform/internal/distance_functor.hh: ...this new file.
Split decl and def.
* mln/transform/influence_zone_geodesic.hh
(iz_functor): Move into...
* mln/transform/internal/influence_zone_functor.hh: ...this new
file.
(iz_functor): Rename as...
(influence_zone_functor): ...this.
Split decl and def.
* mln/transform/distance.hh: Remove.
* mln/transform/influence_zone_front.hh: New.
* mln/transform/all.hh: Update.
* mln/canvas/distance_front.hh: New.
* mln/canvas/all.hh: Update.
* tests/transform/distance.cc: Copy to...
* tests/transform/influence_zone_front.cc: ...this new file.
(vals): Rename as...
(ws): ...this less ambiguous name.
Update.
* tests/transform/distance.cc: Rename as...
* tests/transform/distance_front.cc: ...this.
Update.
* tests/transform/Makefile.am: Update.
mln/canvas/all.hh | 17 +-
mln/canvas/distance_front.hh | 136 +++++++++--------------
mln/transform/all.hh | 3
mln/transform/distance_front.hh | 61 +++-------
mln/transform/distance_geodesic.hh | 30 -----
mln/transform/influence_zone_front.hh | 93 +++++++++++++++
mln/transform/influence_zone_geodesic.hh | 53 +++-----
mln/transform/internal/all.hh | 53 ++++++++
mln/transform/internal/distance_functor.hh | 101 +++++++++++++++++
mln/transform/internal/influence_zone_functor.hh | 105 +++++++++++++++++
tests/transform/Makefile.am | 6 -
tests/transform/distance_front.cc | 16 +-
tests/transform/influence_zone_front.cc | 29 ++--
13 files changed, 486 insertions(+), 217 deletions(-)
Index: tests/transform/influence_zone_front.cc
--- tests/transform/influence_zone_front.cc (revision 2983)
+++ tests/transform/influence_zone_front.cc (working copy)
@@ -25,19 +25,17 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/transform/distance.cc
- *
- * \brief Test on mln::transform::distance.
- */
+/// \file tests/transform/influence_zone_front.cc
+///
+/// Test on mln::transform::influence_zone_front.
#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/level/fill.hh>
#include <mln/debug/println.hh>
-#include <mln/transform/distance.hh>
+#include <mln/transform/influence_zone_front.hh>
int main()
@@ -45,17 +43,24 @@
using namespace mln;
using value::int_u8;
- image2d<bool> input(9, 9);
- level::fill(input, false);
- input.at(4, 4) = true;
+ int_u8 vals[] =
+ { 1, 1, 0, 0, 0, 0, 3,
+ 1, 1, 1, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 2, 0,
+ 0, 0, 0, 0, 2, 2, 0,
+ 0, 0, 0, 0, 0, 0, 0 };
+ image2d<int_u8> input = make::image2d(vals);
- int vals[] = { 0, 9, 0, 9, 0,
+ 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 };
- image2d<int_u8> output = transform::distance(int_u8(), input,
- c4(), make::w_window2d_int(vals));
+ image2d<int_u8> output;
+ output = transform::influence_zone_front(input,
+ c4(), make::w_window2d_int(ws));
debug::println(output);
}
Property changes on: tests/transform/influence_zone_front.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: tests/transform/distance_front.cc
--- tests/transform/distance_front.cc (revision 2981)
+++ tests/transform/distance_front.cc (working copy)
@@ -25,10 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/transform/distance.cc
- *
- * \brief Test on mln::transform::distance.
- */
+/// \file tests/transform/distance_front.cc
+///
+/// Test on mln::transform::distance_front.
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/neighb2d.hh>
@@ -37,7 +36,7 @@
#include <mln/level/fill.hh>
#include <mln/debug/println.hh>
-#include <mln/transform/distance.hh>
+#include <mln/transform/distance_front.hh>
int main()
@@ -49,13 +48,14 @@
level::fill(input, false);
input.at(4, 4) = true;
- int vals[] = { 0, 9, 0, 9, 0,
+ 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 };
- image2d<int_u8> output = transform::distance(int_u8(), input,
- c4(), make::w_window2d_int(vals));
+ image2d<int_u8> output = transform::distance_front(input,
+ c4(), make::w_window2d_int(ws),
+ int_u8(18));
debug::println(output);
}
Property changes on: tests/transform/distance_front.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: tests/transform/Makefile.am
--- tests/transform/Makefile.am (revision 2984)
+++ tests/transform/Makefile.am (working copy)
@@ -3,12 +3,14 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
- distance \
+ distance_front \
distance_geodesic \
+ influence_zone_front \
influence_zone_geodesic
-distance_SOURCES = distance.cc
+distance_front_SOURCES = distance_front.cc
distance_geodesic_SOURCES = distance_geodesic.cc
+influence_zone_front_SOURCES = influence_zone_front.cc
influence_zone_geodesic_SOURCES = influence_zone_geodesic.cc
TESTS = $(check_PROGRAMS)
Index: mln/transform/distance_front.hh
--- mln/transform/distance_front.hh (revision 2981)
+++ mln/transform/distance_front.hh (working copy)
@@ -25,14 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_TRANSFORM_DISTANCE_GEODESIC_HH
-# define MLN_TRANSFORM_DISTANCE_GEODESIC_HH
+#ifndef MLN_TRANSFORM_DISTANCE_FRONT_HH
+# define MLN_TRANSFORM_DISTANCE_FRONT_HH
-/// \file mln/transform/distance_geodesic.hh
+/// \file mln/transform/distance_front.hh
///
-/// Discrete geodesic distance transform.
+/// Discrete front distance transform.
-# include <mln/canvas/distance_geodesic.hh>
+# include <mln/canvas/distance_front.hh>
+# include <mln/transform/internal/distance_functor.hh>
@@ -42,58 +43,32 @@
namespace transform
{
- /// Discrete geodesic distance transform.
- template <typename I, typename N, typename D>
+ /// Discrete front distance transform.
+ template <typename I, typename N, typename W, typename D>
mln_ch_value(I, D)
- distance_geodesic(const Image<I>& input, const Neighborhood<N>&
nbh, D max);
+ distance_front(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win, D
max);
# ifndef MLN_INCLUDE_ONLY
-
- namespace internal
- {
-
- template <typename I>
- struct distance_functor
- {
- typedef mln_value(I) V;
- typedef mln_site(I) P;
-
- void init(const I&)
- {
- }
- bool inqueue_p_wrt_input_p(const V& input_p)
- {
- return input_p == true;
- }
- bool inqueue_p_wrt_input_n(const V& input_n)
- {
- return input_n == false;
- }
- void process(const P&, const P&)
- {
- }
- };
-
- } // end of namespace mln::transform::internal
-
-
- template <typename I, typename N, typename D>
+ template <typename I, typename N, typename W, typename D>
inline
mln_ch_value(I, D)
- distance_geodesic(const Image<I>& input, const Neighborhood<N>&
nbh, D max)
+ distance_front(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win, D
max)
{
- trace::entering("transform::distance_geodesic");
+ trace::entering("transform::distance_front");
mln_precondition(exact(input).has_data());
// mln_precondition(exact(nbh).is_valid());
+ // mln_precondition(exact(w_win).is_valid());
mln_ch_value(I, D) output;
internal::distance_functor<I> f;
- output = mln::canvas::distance_geodesic(input, nbh, max, f);
+ output = mln::canvas::distance_front(input, nbh, w_win, max, f);
- trace::exiting("transform::distance_geodesic");
+ trace::exiting("transform::distance_front");
return output;
}
@@ -104,4 +79,4 @@
} // end of namespace mln
-#endif // ! MLN_TRANSFORM_DISTANCE_GEODESIC_HH
+#endif // ! MLN_TRANSFORM_DISTANCE_FRONT_HH
Property changes on: mln/transform/distance_front.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: mln/transform/influence_zone_geodesic.hh
--- mln/transform/influence_zone_geodesic.hh (revision 2984)
+++ mln/transform/influence_zone_geodesic.hh (working copy)
@@ -30,10 +30,10 @@
/// \file mln/transform/influence_zone_geodesic.hh
///
-/// Discrete geodesic distance transform.
+/// Geodesic influence zone transform.
# include <mln/canvas/distance_geodesic.hh>
-# include <mln/literal/zero.hh>
+# include <mln/transform/internal/influence_zone_functor.hh>
namespace mln
@@ -42,45 +42,21 @@
namespace transform
{
- /// Discrete geodesic distance transform.
+ /// Geodesic influence zone transform.
template <typename I, typename N, typename D>
mln_concrete(I)
- influence_zone_geodesic(const Image<I>& input, const
Neighborhood<N>& nbh, D max);
+ influence_zone_geodesic(const Image<I>& input,
+ const Neighborhood<N>& nbh, D max);
-# ifndef MLN_INCLUDE_ONLY
-
- namespace internal
- {
-
- template <typename I>
- struct iz_functor
- {
- typedef mln_value(I) V;
- typedef mln_site(I) P;
-
- mln_concrete(I) output;
+ /// Geodesic influence zone transform.
+ template <typename I, typename N>
+ mln_concrete(I)
+ influence_zone_geodesic(const Image<I>& input, const
Neighborhood<N>& nbh);
- void init(const I& input)
- {
- output = clone(input);
- }
- bool inqueue_p_wrt_input_p(const V& input_p)
- {
- return input_p != 0u;
- }
- bool inqueue_p_wrt_input_n(const V& input_n)
- {
- return input_n == 0u;
- }
- void process(const P& p, const P& n)
- {
- output(n) = output(p);
- }
- };
- } // end of namespace mln::transform::internal
+# ifndef MLN_INCLUDE_ONLY
template <typename I, typename N, typename D>
mln_concrete(I)
@@ -92,13 +68,20 @@
mln_precondition(exact(input).has_data());
// mln_precondition(exact(nbh).is_valid());
- internal::iz_functor<I> f;
+ internal::influence_zone_functor<I> f;
(void) mln::canvas::distance_geodesic(input, nbh, max, f);
trace::exiting("transform::influence_zone_geodesic");
return f.output;
}
+ template <typename I, typename N>
+ mln_concrete(I)
+ influence_zone_geodesic(const Image<I>& input, const
Neighborhood<N>& nbh)
+ {
+ return influence_zone_geodesic(input, nbh, mln_max(unsigned));
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::transform
Index: mln/transform/all.hh
--- mln/transform/all.hh (revision 2984)
+++ mln/transform/all.hh (working copy)
@@ -42,8 +42,9 @@
} // end of namespace mln
-# include <mln/transform/distance.hh>
+# include <mln/transform/distance_front.hh>
# include <mln/transform/distance_geodesic.hh>
+# include <mln/transform/influence_zone_front.hh>
# include <mln/transform/influence_zone_geodesic.hh>
Index: mln/transform/influence_zone_front.hh
--- mln/transform/influence_zone_front.hh (revision 0)
+++ mln/transform/influence_zone_front.hh (revision 0)
@@ -0,0 +1,93 @@
+// 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_TRANSFORM_INFLUENCE_ZONE_FRONT_HH
+# define MLN_TRANSFORM_INFLUENCE_ZONE_FRONT_HH
+
+/// \file mln/transform/influence_zone_front.hh
+///
+/// Influence zone transform.
+
+# include <mln/canvas/distance_front.hh>
+# include <mln/transform/internal/influence_zone_functor.hh>
+
+
+namespace mln
+{
+
+ namespace transform
+ {
+
+ /// Influence zone transform.
+ template <typename I, typename N, typename W, typename D>
+ mln_concrete(I)
+ influence_zone_front(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win, D
max);
+
+ /// Influence zone transform.
+ template <typename I, typename N, typename W>
+ mln_concrete(I)
+ influence_zone_front(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename N, typename W, typename D>
+ mln_concrete(I)
+ influence_zone_front(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win, D
max)
+ {
+ trace::entering("transform::influence_zone_front");
+
+ mln_precondition(exact(input).has_data());
+ // mln_precondition(exact(nbh).is_valid());
+ // mln_precondition(exact(w_win).is_valid());
+
+ internal::influence_zone_functor<I> f;
+ (void) mln::canvas::distance_front(input, nbh, w_win, max, f);
+
+ trace::exiting("transform::influence_zone_front");
+ return f.output;
+ }
+
+ template <typename I, typename N, typename W>
+ mln_concrete(I)
+ influence_zone_front(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win)
+ {
+ return influence_zone_front(input, nbh, w_win, mln_max(unsigned));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::transform
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRANSFORM_INFLUENCE_ZONE_FRONT_HH
Index: mln/transform/distance_geodesic.hh
--- mln/transform/distance_geodesic.hh (revision 2984)
+++ mln/transform/distance_geodesic.hh (working copy)
@@ -33,6 +33,7 @@
/// Discrete geodesic distance transform.
# include <mln/canvas/distance_geodesic.hh>
+# include <mln/transform/internal/distance_functor.hh>
@@ -50,35 +51,6 @@
# ifndef MLN_INCLUDE_ONLY
-
- namespace internal
- {
-
- template <typename I>
- struct distance_functor
- {
- typedef mln_value(I) V;
- typedef mln_site(I) P;
-
- void init(const I&)
- {
- }
- bool inqueue_p_wrt_input_p(const V& input_p)
- {
- return input_p == true;
- }
- bool inqueue_p_wrt_input_n(const V& input_n)
- {
- return input_n == false;
- }
- void process(const P&, const P&)
- {
- }
- };
-
- } // end of namespace mln::transform::internal
-
-
template <typename I, typename N, typename D>
inline
mln_ch_value(I, D)
Index: mln/transform/internal/influence_zone_functor.hh
--- mln/transform/internal/influence_zone_functor.hh (revision 0)
+++ mln/transform/internal/influence_zone_functor.hh (revision 0)
@@ -0,0 +1,105 @@
+// 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_TRANSFORM_INTERNAL_INFLUENCE_ZONE_FUNCTOR_HH
+# define MLN_TRANSFORM_INTERNAL_INFLUENCE_ZONE_FUNCTOR_HH
+
+/// \file mln/transform/internal/influence_zone_functor.hh
+///
+/// Influence zone functor.
+
+# include <mln/core/routine/clone.hh>
+
+
+
+namespace mln
+{
+
+ namespace transform
+ {
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct influence_zone_functor
+ {
+ typedef mln_value(I) V;
+ typedef mln_site(I) P;
+
+ mln_concrete(I) output;
+
+ void init(const I& input);
+ bool inqueue_p_wrt_input_p(const V& input_p);
+ bool inqueue_p_wrt_input_n(const V& input_n);
+ void process(const P& p, const P& n);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ void
+ influence_zone_functor<I>::init(const I& input)
+ {
+ output = clone(input);
+ }
+
+ template <typename I>
+ inline
+ bool
+ influence_zone_functor<I>::inqueue_p_wrt_input_p(const V& input_p)
+ {
+ return input_p != 0u;
+ }
+
+ template <typename I>
+ inline
+ bool
+ influence_zone_functor<I>::inqueue_p_wrt_input_n(const V& input_n)
+ {
+ return input_n == 0u;
+ }
+
+ template <typename I>
+ inline
+ void influence_zone_functor<I>::process(const P& p, const P& n)
+ {
+ output(n) = output(p);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::transform::internal
+
+ } // end of namespace mln::transform
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRANSFORM_INTERNAL_INFLUENCE_ZONE_FUNCTOR_HH
Index: mln/transform/internal/all.hh
--- mln/transform/internal/all.hh (revision 0)
+++ mln/transform/internal/all.hh (revision 0)
@@ -0,0 +1,53 @@
+// 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_TRANSFORM_INTERNAL_ALL_HH
+# define MLN_TRANSFORM_INTERNAL_ALL_HH
+
+/// \file mln/transform/internal/all.hh
+///
+/// File that includes all internals of mln/transform.
+
+
+namespace mln
+{
+
+ namespace transform
+ {
+
+ namespace internal {}
+
+ } // end of namespace mln::transform
+
+} // end of namespace mln
+
+
+# include <mln/transform/internal/distance_functor.hh>
+# include <mln/transform/internal/influence_zone_functor.hh>
+
+
+#endif // ! MLN_TRANSFORM_INTERNAL_ALL_HH
Index: mln/transform/internal/distance_functor.hh
--- mln/transform/internal/distance_functor.hh (revision 0)
+++ mln/transform/internal/distance_functor.hh (revision 0)
@@ -0,0 +1,101 @@
+// 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_TRANSFORM_INTERNAL_DISTANCE_FUNCTOR_HH
+# define MLN_TRANSFORM_INTERNAL_DISTANCE_FUNCTOR_HH
+
+/// \file mln/transform/internal/distance_functor.hh
+///
+/// Distance functor.
+
+# include <mln/core/macros.hh>
+
+
+
+namespace mln
+{
+
+ namespace transform
+ {
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct distance_functor
+ {
+ typedef mln_value(I) V;
+ typedef mln_site(I) P;
+
+ void init(const I&);
+ bool inqueue_p_wrt_input_p(const V& input_p);
+ bool inqueue_p_wrt_input_n(const V& input_n);
+ void process(const P&, const P&);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ void
+ distance_functor<I>::init(const I&)
+ {
+ }
+
+ template <typename I>
+ inline
+ bool
+ distance_functor<I>::inqueue_p_wrt_input_p(const V& input_p)
+ {
+ return input_p == true;
+ }
+
+ template <typename I>
+ inline
+ bool
+ distance_functor<I>::inqueue_p_wrt_input_n(const V& input_n)
+ {
+ return input_n == false;
+ }
+
+ template <typename I>
+ inline
+ void distance_functor<I>::process(const P&, const P&)
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::transform::internal
+
+ } // end of namespace mln::transform
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRANSFORM_INTERNAL_DISTANCE_FUNCTOR_HH
Index: mln/canvas/distance_front.hh
--- mln/canvas/distance_front.hh (revision 2981)
+++ mln/canvas/distance_front.hh (working copy)
@@ -25,14 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_TRANSFORM_DISTANCE_HH
-# define MLN_TRANSFORM_DISTANCE_HH
+#ifndef MLN_CANVAS_DISTANCE_FRONT_HH
+# define MLN_CANVAS_DISTANCE_FRONT_HH
-/// \file mln/transform/distance.hh
+/// \file mln/canvas/distance_front.hh
///
-/// Discrete distance transform.
-///
-/// \todo Make a canvas out of it.
+/// Discrete distance canvas by front propagation.
# include <vector>
# include <mln/core/concept/image.hh>
@@ -42,78 +40,76 @@
# include <mln/accu/max.hh>
-
namespace mln
{
- namespace transform
+ namespace canvas
{
- /*! Discrete distance transform.
- *
- * FIXME: doc.
- */
- template <typename D, typename I, typename N, typename W>
+ /// Discrete distance canvas by front propagation.
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
mln_ch_value(I, D)
- distance(D, const Image<I>& input,
- const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win);
+ distance_front(const Image<I>& input,
+ const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win, D
max,
+ F& functor);
# ifndef MLN_INCLUDE_ONLY
- namespace impl
- {
-
- namespace generic
- {
- template <typename D, typename I, typename N, typename W>
+ template <typename I,
+ typename N, typename W, typename D,
+ typename F>
+ inline
mln_ch_value(I, D)
- distance(D, const Image<I>& input_,
- const Neighborhood<N>& nbh_, const Weighted_Window<W>& w_win_)
+ distance_front(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, const Weighted_Window<W>& w_win_,
D max,
+ F& functor)
{
- trace::entering("transform::impl::generic::distance");
+ trace::entering("canvas::distance_front");
const I& input = exact(input_);
const N& nbh = exact(nbh_);
const W& w_win = exact(w_win_);
mln_precondition(input.has_data());
-
- const D Max = mln_max(D);
+ // mln_precondition(w_win.is_valid());
typedef mln_site(I) P;
typedef std::vector<P> bucket_t;
- mln_ch_value(I, D) output;
- initialize(output, input);
- level::fill(output, Max);
+ // Distance map.
+ mln_ch_value(I, D) dmap;
+ initialize(dmap, input);
+ level::fill(dmap, max);
- // Modulus determination.
+ // Mod determination.
unsigned mod;
{
- mln::accu::max<unsigned> accu;
- P p;
- mln_qiter(W) q(w_win, p);
- for_all(q)
- accu.take(q.w());
- mod = accu.to_result() + 1;
+ accu::max<unsigned> m;
+ for (unsigned i = 0; i < w_win.size(); ++i)
+ m.take(w_win.w(i));
+ mod = unsigned(m) + 1;
}
- std::vector<bucket_t> bucket;
- bucket.resize(mod);
+ // 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 (input(p) == true)
+ if (functor.inqueue_p_wrt_input_p(input(p))) // <-- inqueue_p_wrt_input_p
{
- output(p) = literal::zero;
+ dmap(p) = 0;
for_all(n)
- if (input.domain().has(n) && input(n) == false)
+ 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;
@@ -126,30 +122,32 @@
{
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 (output(p) < d)
+
+ 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 (output.domain().has(q) && output(q) > d)
+ if (dmap.domain().has(q) && dmap(q) > d)
{
- if (unsigned(Max - q.w()) < d) // Saturation => Stop!
- {
- // trace::warning...
- trace::exiting("transform::impl::generic::distance");
- return output;
- }
unsigned d_ = d + q.w();
-
- if (d_ < output(q))
+ if (d_ < dmap(q))
{
- output(q) = d_;
+ dmap(q) = d_;
+ functor.process(p, q); // <- process
bucket[d_ % mod].push_back(q);
++bucket_size;
}
@@ -158,41 +156,17 @@
bucket_size -= bucket_d.size();
bucket_d.clear();
}
- }
-
- trace::exiting("transform::impl::generic::distance");
- return output;
+ trace::exiting("canvas::distance_front");
+ return dmap;
}
-
- } // end of namespace mln::transform::impl::generic
-
- } // end of namespace mln::transform::impl
-
-
- // Facade.
-
- template <typename D, typename I, typename N, typename W>
- inline
- mln_ch_value(I, D)
- distance(D, const Image<I>& input,
- const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win)
- {
- trace::entering("transform::distance");
-
- // FIXME: tests.
- mln_ch_value(I, D) output = impl::generic::distance(D(), input,
- nbh, w_win);
-
- trace::exiting("transform::distance");
- return output;
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::transform
+ } // end of namespace mln::canvas
} // end of namespace mln
-#endif // ! MLN_TRANSFORM_DISTANCE_HH
+#endif // ! MLN_CANVAS_DISTANCE_FRONT_HH
Property changes on: mln/canvas/distance_front.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: mln/canvas/all.hh
--- mln/canvas/all.hh (revision 2984)
+++ mln/canvas/all.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,10 +29,9 @@
#ifndef MLN_CANVAS_ALL_HH
# define MLN_CANVAS_ALL_HH
-/*! \file mln/canvas/all.hh
- *
- * \brief File that includes all canvas-related routines.
- */
+/// \file mln/canvas/all.hh
+///
+/// File that includes all canvas-related routines.
namespace mln
@@ -40,15 +40,20 @@
/// Namespace of canvas.
namespace canvas
{
+
/// Implementation namespace of canvas namespace.
namespace impl {}
- }
}
+}
+
# include <mln/canvas/browsing/all.hh>
# include <mln/canvas/morpho/all.hh>
# include <mln/canvas/chamfer.hh>
+# include <mln/canvas/distance_front.hh>
+# include <mln/canvas/distance_geodesic.hh>
# include <mln/canvas/labeling.hh>
+
#endif // ! MLN_CANVAS_ALL_HH