* tools/Makefile.am: enable the target.
* tools/area_flooding.cc: update according the new graph structure.
---
milena/ChangeLog | 8 ++++++
milena/tools/Makefile.am | 6 ++--
milena/tools/area_flooding.cc | 57 +++++++++++++++++++++--------------------
3 files changed, 40 insertions(+), 31 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 0973adf..c42010f 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,13 @@
2008-12-31 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Re-enable tools/area_flooding.
+
+ * tools/Makefile.am: enable the target.
+
+ * tools/area_flooding.cc: update according the new graph structure.
+
+2008-12-31 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Fix line_gradient.
* morpho/line_gradient.hh: update according the new graph structure.
diff --git a/milena/tools/Makefile.am b/milena/tools/Makefile.am
index 1d6347c..335f622 100644
--- a/milena/tools/Makefile.am
+++ b/milena/tools/Makefile.am
@@ -3,10 +3,10 @@
include $(top_srcdir)/milena/tools/tools.mk
bin_PROGRAMS = \
- seed2tiling
-#area_flooding
+ seed2tiling \
+ area_flooding
-#area_flooding_SOURCES = area_flooding.cc
+area_flooding_SOURCES = area_flooding.cc
seed2tiling_SOURCES = seed2tiling.cc
# FIXME: Add some tests for these tools.
diff --git a/milena/tools/area_flooding.cc b/milena/tools/area_flooding.cc
index 5d34af0..0157f9c 100644
--- a/milena/tools/area_flooding.cc
+++ b/milena/tools/area_flooding.cc
@@ -25,10 +25,11 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/** \file tests/morpho/lena_line_graph_image_wst2.cc
- \brief More tests on the Watershed Transform (WST) on a
- mln::line_graph_image.
-
+/// \file tests/morpho/lena_line_graph_image_wst2.cc
+///
+/// More tests on the Watershed Transform (WST) on a
+/// an image base on a p_edges (line_graph_image).
+/*!
The scenario is as follows:
\li load a 2-D, gray-level image from a PGM file;
\li convert this 2-D image into a line graph-based one, where values
@@ -42,6 +43,8 @@
\li create a 2D image of this watershed image, where each basin has
an average grey level of the corresponding region in the input
image.
+
+ FIXME: do not use mln_VAR.
*/
#include <cstdlib>
@@ -55,10 +58,8 @@
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/neighb2d.hh>
-
-#include <mln/core/image/line_graph_image.hh>
-#include <mln/core/image/line_graph_elt_neighborhood.hh>
-#include <mln/core/image/line_graph_neighborhood_piter.hh>
+#include <mln/core/image/line_graph_elt_window.hh>
+#include <mln/core/var.hh>
#include <mln/morpho/line_gradient.hh>
#include <mln/morpho/closing_area_on_vertices.hh>
@@ -92,18 +93,19 @@ int main(int argc, char* argv[])
orig_ima_t input;
io::pgm::load(input, argv[2]);
if (!input.has_data())
- {
- std::cerr << "Error reading input " << argv[2] << std::endl;
- std::exit(2);
- }
+ {
+ std::cerr << "Error reading input " << argv[2] << std::endl;
+ std::exit(2);
+ }
/*----------------.
| Line gradient. |
`----------------*/
// Line graph image.
- typedef line_graph_image<point2d, val_t> ima_t;
- ima_t lg_ima = morpho::line_gradient(input);
+ typedef fun::i2v::array<val_t> fval_t;
+ fval_t values;
+ mln_VAR(lg_ima, morpho::line_gradient(input));
/*-----------.
| Flooding. |
@@ -112,7 +114,7 @@ int main(int argc, char* argv[])
/* FIXME: I'm not sure this is the way it should be done. Anyway,
we should implement this as a canvas. */
- typedef line_graph_elt_neighborhood<point2d> nbh_t;
+ typedef neighb< line_graph_elt_window<util::graph, lg_ima_t::pset::fun_t> > nbh_t;
nbh_t nbh;
unsigned area = 0;
@@ -120,15 +122,15 @@ int main(int argc, char* argv[])
unsigned nregions = mln_max(unsigned);
unsigned max_nregions = atoi(argv[1]);
- ima_t result = duplicate(lg_ima);
+ lg_ima_t result = duplicate(lg_ima);
while (area < max_area && nregions > max_nregions)
{
++area;
std::cerr << "area = " << area << " \t"
<< "nregions = " << nregions << std::endl;
- ima_t work = duplicate(result);
+ lg_ima_t work = duplicate(result);
// Compute the closing.
- morpho::closing_area_on_vertices(work, nbh, area, result);
+ result = morpho::closing_area_on_vertices(work, nbh, area);
// Compute the number of local minima (but get rid of the image,
// as we don't need it).
labeling::regional_minima(result, nbh, nregions);
@@ -141,8 +143,7 @@ int main(int argc, char* argv[])
// Perform a Watershed Transform.
typedef int_u16 wst_val_t;
wst_val_t nbasins;
- typedef line_graph_image<point2d, wst_val_t> wst_ima_t;
- wst_ima_t wshed = morpho::meyer_wst(result, nbh, nbasins);
+ mln_VAR(wshed, morpho::meyer_wst(result, nbh, nbasins));
std::cout << "nbasins = " << nbasins << std::endl;
/*---------.
@@ -153,21 +154,21 @@ int main(int argc, char* argv[])
// Create a 2D-equivalent of WSHED.
image2d<wst_val_t> wshed2d(input.domain());
-
+
/* FIXME: It'd better if we could iterate over the *vertices* of a
line graph image. We could avoid all this lengthy code. */
// Iterate over each edge of the watershed image, and propagate the
// label of an edge to its adjacent vertices when this edge is not
// part of the watershed.
- mln_piter_(wst_ima_t) p(wshed.domain());
+ mln_piter_(wshed_t) p(wshed.domain());
for_all(p)
if (wshed(p) != wshed_label)
- {
- // FIXME: Equip the iterator with first() and second()
- // accessors?
- wshed2d(p.unproxy_().first()) = wshed(p);
- wshed2d(p.unproxy_().second()) = wshed(p);
- }
+ {
+ // FIXME: Equip the iterator with first() and second()
+ // accessors?
+ wshed2d(p.first()) = wshed(p);
+ wshed2d(p.second()) = wshed(p);
+ }
// For each basin, compute the average gray level.
std::vector<mln_sum_(val_t)> sum(nbasins + 1, 0);
--
1.5.6.5
* mln/fun/v2v/ch_function_value.hh: new. Wrap a function and
convert that function results to another type thanks to from_to.
* mln/fun/internal/ch_function_value_impl.hh: new. Allow extensions to
ch_function_value according to the function it wraps.
* mln/trait/ch_function_value.hh: Dispatch to the proper way to change
the function return type.
* mln/trait/ch_value.hh: handle ch_value on graph images here.
* headers.mk: add new headers to distribution.
---
milena/ChangeLog | 17 ++++
milena/headers.mk | 3 +
milena/mln/fun/internal/ch_function_value_impl.hh | 57 +++++++++++
milena/mln/fun/v2v/ch_function_value.hh | 106 +++++++++++++++++++++
milena/mln/trait/ch_function_value.hh | 84 ++++++++++++++++
milena/mln/trait/ch_value.hh | 35 ++++++--
6 files changed, 295 insertions(+), 7 deletions(-)
create mode 100644 milena/mln/fun/internal/ch_function_value_impl.hh
create mode 100644 milena/mln/fun/v2v/ch_function_value.hh
create mode 100644 milena/mln/trait/ch_function_value.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 0541e7e..6c23d7b 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,22 @@
2008-12-31 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Handle ch_value on graph images and introduce ch_function_value.
+
+ * mln/fun/v2v/ch_function_value.hh: new. Wrap a function and
+ convert that function results to another type thanks to from_to.
+
+ * mln/fun/internal/ch_function_value_impl.hh: new. Allow extensions to
+ ch_function_value according to the function it wraps.
+
+ * mln/trait/ch_function_value.hh: Dispatch to the proper way to change
+ the function return type.
+
+ * mln/trait/ch_value.hh: handle ch_value on graph images here.
+
+ * headers.mk: add new headers to distribution.
+
+2008-12-31 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Fix/improve graph related classes.
* mln/core/image/graph_window_piter.hh: update comments.
diff --git a/milena/headers.mk b/milena/headers.mk
index 8cd49e1..b348a9e 100644
--- a/milena/headers.mk
+++ b/milena/headers.mk
@@ -189,6 +189,7 @@ mln/fun/vv2v/min.hh \
mln/fun/vv2v/essential.hh \
mln/fun/internal/array_base.hh \
mln/fun/internal/x2x_linear_impl.hh \
+mln/fun/internal/ch_function_value_impl.hh \
mln/fun/internal/selector.hh \
mln/fun/v2w_w2v/norm.hh \
mln/fun/p2v/ternary.hh \
@@ -211,6 +212,7 @@ mln/fun/v2v/dec.hh \
mln/fun/v2v/abs.hh \
mln/fun/v2v/rgb_to_hsl.hh \
mln/fun/v2v/cast.hh \
+mln/fun/v2v/ch_function_value.hh \
mln/fun/v2v/rgb_to_hsi.hh \
mln/fun/v2v/enc.hh \
mln/fun/v2v/convert.hh \
@@ -440,6 +442,7 @@ mln/trait/value/essential.hh \
mln/trait/images.hh \
mln/trait/window/props.hh \
mln/trait/window/print.hh \
+mln/trait/ch_function_value.hh \
mln/trait/ch_value.hh \
mln/trait/solve.hh \
mln/trait/solve_unary.hh \
diff --git a/milena/mln/fun/internal/ch_function_value_impl.hh b/milena/mln/fun/internal/ch_function_value_impl.hh
new file mode 100644
index 0000000..fa57290
--- /dev/null
+++ b/milena/mln/fun/internal/ch_function_value_impl.hh
@@ -0,0 +1,57 @@
+// 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_FUN_INTERNAL_CH_FUNCTION_VALUE_IMPL_HH
+# define MLN_FUN_INTERNAL_CH_FUNCTION_VALUE_IMPL_HH
+
+/// \file mln/fun/internal/ch_function_value_impl.hh
+///
+/// Enable the possibility of adding methods to fun::v2v::ch_function_value.
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace internal
+ {
+
+ /// Default implementation.
+ template <typename F, typename V>
+ struct ch_function_value_impl
+ {
+ };
+
+ } // end of namespace mln::fun::internal
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+#endif // ! MLN_FUN_INTERNAL_CH_FUNCTION_VALUE_IMPL_HH
diff --git a/milena/mln/fun/v2v/ch_function_value.hh b/milena/mln/fun/v2v/ch_function_value.hh
new file mode 100644
index 0000000..a4c7ca4
--- /dev/null
+++ b/milena/mln/fun/v2v/ch_function_value.hh
@@ -0,0 +1,106 @@
+// 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_FUN_V2V_CH_FUNCTION_VALUE_HH
+# define MLN_FUN_V2V_CH_FUNCTION_VALUE_HH
+
+/// \file mln/fun/v2v/ch_function_value.hh
+///
+/// Wrap a function v2v and convert its result to another type.
+
+# include <mln/core/concept/function.hh>
+# include <mln/convert/to.hh>
+# include <mln/fun/internal/ch_function_value_impl.hh>
+
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ /// Wrap a function v2v and convert its result to another type.
+ template <typename F, typename V>
+ class ch_function_value : public Function_v2v< ch_function_value<F,V> >,
+ public internal::ch_function_value_impl<F, V>
+ {
+ public:
+ typedef F function;
+ typedef V result;
+ typedef V rvalue;
+ typedef V lvalue;
+
+ ch_function_value();
+ ch_function_value(const F& f);
+
+ template <typename W>
+ V operator()(const W& w) const;
+
+ private:
+ F f_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename F, typename V>
+ inline
+ ch_function_value<F,V>::ch_function_value()
+ {
+ }
+
+ template <typename F, typename V>
+ inline
+ ch_function_value<F,V>::ch_function_value(const F& f)
+ {
+ f_ = f;
+ }
+
+ template <typename F, typename V>
+ template <typename W>
+ inline
+ V
+ ch_function_value<F,V>::operator()(const W& w) const
+ {
+ return mln::convert::to<V>(f_(w));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::v2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_V2V_CH_FUNCTION_VALUE_HH
diff --git a/milena/mln/trait/ch_function_value.hh b/milena/mln/trait/ch_function_value.hh
new file mode 100644
index 0000000..6ed1e47
--- /dev/null
+++ b/milena/mln/trait/ch_function_value.hh
@@ -0,0 +1,84 @@
+// 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_TRAIT_CH_FUNCTION_VALUE_HH
+# define MLN_TRAIT_CH_FUNCTION_VALUE_HH
+
+/// \file mln/trait/ch_function_value.hh
+///
+/// Definition of the "change value" function trait.
+
+# define mln_ch_function_value(I, V) \
+typename mln::trait::ch_function_value< I, V >::ret
+
+# define mln_ch_function_value_(I, V) \
+mln::trait::ch_functionvalue< I, V >::ret
+
+# include <mln/fun/v2v/ch_function_value.hh>
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ // Forward declaration.
+ template <typename F, typename V> struct ch_function_value;
+
+
+ namespace impl
+ {
+
+ /// Default.
+ template <typename F, typename VF, typename V>
+ struct ch_function_value
+ {
+ typedef fun::v2v::ch_function_value<F, V> ret;
+ };
+
+ template <typename VF, typename V>
+ struct ch_function_value<fun::i2v::array<VF>, VF, V>
+ {
+ typedef fun::i2v::array<V> ret;
+ };
+
+ } // end of namespace mln::trait::impl
+
+
+ template <typename F, typename V>
+ struct ch_function_value
+ {
+ typedef typename impl::ch_function_value<F, mln_result(F), V>::ret ret;
+ };
+
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+#endif // ! MLN_TRAIT_CH_FUNCTION_VALUE_HH
diff --git a/milena/mln/trait/ch_value.hh b/milena/mln/trait/ch_value.hh
index 0333a16..cff3a59 100644
--- a/milena/mln/trait/ch_value.hh
+++ b/milena/mln/trait/ch_value.hh
@@ -29,13 +29,13 @@
#ifndef MLN_TRAIT_CH_VALUE_HH
# define MLN_TRAIT_CH_VALUE_HH
-/*! \file mln/trait/ch_value.hh
- *
- * \brief Definition of the "change value" image trait.
- */
+/// \file mln/trait/ch_value.hh
+///
+/// Definition of the "change value" image trait.
# include <mln/tag/skeleton.hh>
# include <mln/trait/image_from_grid.hh>
+# include <mln/trait/ch_function_value.hh>
# define mln_ch_value(I, V) typename mln::trait::ch_value< I, V >::ret
@@ -46,16 +46,18 @@
namespace mln
{
- // Fwd decl.
+ // Forward declarations.
namespace algebra { template <unsigned n, typename T> class vec; }
-
+ template <typename G, typename F> class p_edges;
+ template <typename G, typename F> class p_vertices;
+ namespace pw { template <typename F, typename S> class image; }
namespace trait
{
- // Fwd decl.
+ // Forward declaration.
template <typename I, typename V> struct ch_value;
@@ -163,6 +165,25 @@ namespace mln
typedef typename image_from_grid< grid, V >::ret ret;
};
+ // line_graph image
+ template < typename F,
+ typename G, typename FP,
+ typename V >
+ struct ch_value_< pw::image< tag::function_<F>, tag::pset_<p_edges<G, FP> > >, V >
+ {
+ typedef pw::image< mln_ch_function_value(F, V), p_edges<G, FP> > ret;
+ };
+
+ // graph image
+ template < typename F,
+ typename G, typename FP,
+ typename V >
+ struct ch_value_< pw::image< tag::function_<F>, tag::pset_<p_vertices<G, FP> > >, V >
+ {
+ typedef pw::image< mln_ch_function_value(F, V), p_vertices<G, FP> > ret;
+ };
+
+
template < template <class, class> class M, typename T, typename S,
typename V >
struct ch_value_< M< tag::value_<T>, tag::pset_<S> >, V >
--
1.5.6.5