* mln/core/site_set/p_graph_piter.hh, * mln/core/internal/image_base.hh, * mln/core/image/essential.hh: update doc. * mln/core/image/all.hh: include new headers. * mln/core/image/vertex_image.hh * mln/core/image/edge_image.hh: new image types. * mln/core/image/graph_elt_neighborhood.hh, * mln/core/image/graph_elt_window.hh: update according new image types. * mln/core/image/line_graph_elt_neighborhood.hh, * mln/core/image/line_graph_elt_window.hh: not needed anymore. Removed. * mln/core/internal/neighb_niter_impl.hh: update template parameter names. * mln/core/routine/init.hxx: add new init routines for new image types. * mln/core/site_set/p_edges.hh, * mln/core/site_set/p_vertices.hh: use Graph concept in constructor instead of exact type. * mln/debug/draw_graph.hh: add missing traces. * mln/morpho/attribute/count_adjacent_vertices.hh: make it more generic. * mln/morpho/closing/area_on_vertices.hh, * mln/morpho/line_gradient.hh: use the new types. * mln/pw/image.hh: revamp and move most of the code... * mln/pw/internal/image_base.hh: ... here. * mln/tag/skeleton.hh: add tag::graph. * mln/trait/ch_value.hh: add traits for new image types. * mln/util/graph.hh: Add a method returning the edge vector. * tests/core/image/Makefile.am, * tests/core/image/vertex_image.cc, * tests/core/image/edge_image.cc: new tests. * tests/core/image/graph_image.cc, * tests/core/image/line_graph_image.cc, * tests/core/site_set/p_edges.cc, * tests/morpho/artificial_line_graph_image_wst.cc, * tests/morpho/graph_image_morpho.cc, * tests/morpho/graph_image_wst.cc, * tests/morpho/lena_line_graph_image_wst1.cc, * tests/morpho/lena_line_graph_image_wst2.cc, * tests/morpho/line_graph_image_morpho.cc, * tests/morpho/line_graph_image_wst.cc, * tests/util/graph.cc: update graph related tests. Use the new image types. --- milena/ChangeLog | 65 +++++ milena/mln/core/image/all.hh | 3 +- milena/mln/core/image/edge_image.hh | 254 +++++++++++++++++++ milena/mln/core/image/essential.hh | 10 +- milena/mln/core/image/graph_elt_neighborhood.hh | 10 +- milena/mln/core/image/graph_elt_window.hh | 60 ++++-- .../mln/core/image/line_graph_elt_neighborhood.hh | 67 ----- milena/mln/core/image/line_graph_elt_window.hh | 109 --------- milena/mln/core/image/vertex_image.hh | 250 +++++++++++++++++++ milena/mln/core/internal/image_base.hh | 23 +- milena/mln/core/internal/neighb_niter_impl.hh | 8 +- milena/mln/core/routine/init.hxx | 34 ++- milena/mln/core/site_set/p_edges.hh | 55 ++++- milena/mln/core/site_set/p_graph_piter.hh | 6 +- milena/mln/core/site_set/p_vertices.hh | 53 ++++- milena/mln/debug/draw_graph.hh | 17 ++ .../morpho/attribute/count_adjacent_vertices.hh | 48 ++-- milena/mln/morpho/closing/area_on_vertices.hh | 30 ++-- milena/mln/morpho/line_gradient.hh | 24 +- milena/mln/pw/image.hh | 191 +++------------ milena/mln/pw/internal/image_base.hh | 257 ++++++++++++++++++++ milena/mln/tag/skeleton.hh | 14 +- milena/mln/trait/ch_value.hh | 32 +++- milena/mln/util/graph.hh | 11 + milena/tests/core/image/Makefile.am | 6 +- .../core/image/{graph_image.cc => edge_image.cc} | 80 +++---- milena/tests/core/image/graph_image.cc | 4 +- milena/tests/core/image/line_graph_image.cc | 50 ++-- .../core/image/{graph_image.cc => vertex_image.cc} | 40 +-- milena/tests/core/site_set/p_edges.cc | 4 +- .../morpho/artificial_line_graph_image_wst.cc | 12 +- milena/tests/morpho/graph_image_morpho.cc | 23 +-- milena/tests/morpho/graph_image_wst.cc | 23 +-- milena/tests/morpho/lena_line_graph_image_wst1.cc | 17 +- milena/tests/morpho/lena_line_graph_image_wst2.cc | 12 +- milena/tests/morpho/line_graph_image_morpho.cc | 64 +++--- milena/tests/morpho/line_graph_image_wst.cc | 71 +++--- milena/tests/util/graph.cc | 7 +- 38 files changed, 1346 insertions(+), 698 deletions(-) create mode 100644 milena/mln/core/image/edge_image.hh delete mode 100644 milena/mln/core/image/line_graph_elt_neighborhood.hh delete mode 100644 milena/mln/core/image/line_graph_elt_window.hh create mode 100644 milena/mln/core/image/vertex_image.hh create mode 100644 milena/mln/pw/internal/image_base.hh copy milena/tests/core/image/{graph_image.cc => edge_image.cc} (73%) copy milena/tests/core/image/{graph_image.cc => vertex_image.cc} (84%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 7f95505..4a24f51 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,68 @@ +2009-04-08 Guillaume Lazzara <lazzara@lrde.epita.fr> + + Introduce edge_image and vertex_image types. + + * mln/core/site_set/p_graph_piter.hh, + * mln/core/internal/image_base.hh, + * mln/core/image/essential.hh: update doc. + + * mln/core/image/all.hh: include new headers. + + * mln/core/image/vertex_image.hh, + * mln/core/image/edge_image.hh: new image types. + + * mln/core/image/graph_elt_neighborhood.hh, + * mln/core/image/graph_elt_window.hh: update according new image + types. + + * mln/core/image/line_graph_elt_neighborhood.hh, + * mln/core/image/line_graph_elt_window.hh: not needed anymore. + Removed. + + * mln/core/internal/neighb_niter_impl.hh: update template parameter + names. + + * mln/core/routine/init.hxx: add new init routines for new image + types. + + * mln/core/site_set/p_edges.hh, + * mln/core/site_set/p_vertices.hh: use Graph concept in constructor + instead of exact type. + + * mln/debug/draw_graph.hh: add missing traces. + + * mln/morpho/attribute/count_adjacent_vertices.hh: make it more + generic. + + * mln/morpho/closing/area_on_vertices.hh, + * mln/morpho/line_gradient.hh: use the new types. + + * mln/pw/image.hh: revamp and move most of the code... + * mln/pw/internal/image_base.hh: ... here. + + * mln/tag/skeleton.hh: add tag::graph. + + * mln/trait/ch_value.hh: add traits for new image types. + + * mln/util/graph.hh: Add a method returning the edge vector. + + * tests/core/image/Makefile.am, + * tests/core/image/vertex_image.cc, + * tests/core/image/edge_image.cc: new tests. + + * tests/core/image/graph_image.cc, + * tests/core/image/line_graph_image.cc, + * tests/core/site_set/p_edges.cc, + * tests/morpho/artificial_line_graph_image_wst.cc, + * tests/morpho/graph_image_morpho.cc, + * tests/morpho/graph_image_wst.cc, + * tests/morpho/lena_line_graph_image_wst1.cc, + * tests/morpho/lena_line_graph_image_wst2.cc, + * tests/morpho/line_graph_image_morpho.cc, + * tests/morpho/line_graph_image_wst.cc, + * tests/util/graph.cc: update graph related tests. Use the new image + types. + 2009-04-10 Edwin Carlinet <carlinet@lrde.epita.fr> Merge changes in component tree file. diff --git a/milena/mln/core/image/all.hh b/milena/mln/core/image/all.hh index 0de14fc..c4094af 100644 --- a/milena/mln/core/image/all.hh +++ b/milena/mln/core/image/all.hh @@ -41,6 +41,7 @@ # include <mln/core/image/complex_neighborhoods.hh> # include <mln/core/image/complex_window_piter.hh> # include <mln/core/image/complex_windows.hh> +# include <mln/core/image/edge_image.hh> # include <mln/core/image/image2d.hh> # include <mln/core/image/flat_image.hh> # include <mln/core/image/image_if.hh> @@ -60,7 +61,6 @@ # include <mln/core/image/image_if.hh> # include <mln/core/image/interpolated.hh> # include <mln/core/image/lazy_image.hh> -# include <mln/core/image/line_graph_elt_window.hh> # include <mln/core/image/p2p_image.hh> # include <mln/core/image/plain.hh> # include <mln/core/image/safe.hh> @@ -73,6 +73,7 @@ # include <mln/core/image/tr_image.hh> # include <mln/core/image/tr_mesh.hh> # include <mln/core/image/unproject_image.hh> +# include <mln/core/image/vertex_image.hh> //# include <mln/core/image/bgraph_image.hh> //# include <mln/core/image/bgraph_psite.hh> diff --git a/milena/mln/core/image/edge_image.hh b/milena/mln/core/image/edge_image.hh new file mode 100644 index 0000000..68e7227 --- /dev/null +++ b/milena/mln/core/image/edge_image.hh @@ -0,0 +1,254 @@ +// 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_IMAGE_EDGE_IMAGE_HH +# define MLN_CORE_IMAGE_EDGE_IMAGE_HH + +/// \file mln/core/image/edge_image.hh +/// +/// Image based on graph edges. + +# include <mln/core/concept/graph.hh> +# include <mln/core/site_set/p_edges.hh> +# include <mln/core/image/graph_elt_window.hh> +# include <mln/core/image/graph_elt_neighborhood.hh> +# include <mln/pw/internal/image_base.hh> +# include <mln/fun/i2v/array.hh> + + + +namespace mln +{ + // Forward declaration. + template <typename P, typename V, typename G> class edge_image; + namespace util { class graph; } + + + // Properties + + namespace trait + { + + template <typename P, typename V, typename G> + struct image_< edge_image<P,V,G> > + : pw_image_<fun::i2v::array<V>, + p_edges<util::graph, fun::i2v::array<P> >, + edge_image<P,V,G> > + { + }; + + } // end of namespace mln::traits. + + + + namespace internal + { + + /// Data structure for mln::pw::internal::image + template <typename P, typename V, typename G> + struct data< mln::edge_image<P,V,G> > + { + data(const fun::i2v::array<V>& edge_values, + const p_edges<G,fun::i2v::array<P> >& pv); + + fun::i2v::array<V> f_; + p_edges<G,fun::i2v::array<P> > pset_; + }; + + } // end of namespace mln::internal + + + + + /// Construct a edge image from a fun::i2v::array and a p_edges. + /// image = fun::i2v::array | p_edges. + template <typename V, typename G, typename P> + edge_image<P,V,G> + operator | (const fun::i2v::array<V>& edge_values, + const p_edges<G,fun::i2v::array<P> >& pv); + + + + + template <typename P, typename V, typename G = util::graph> + class edge_image + : public pw::internal::image_base<fun::i2v::array<V>, + p_edges<G, fun::i2v::array<P> >, + edge_image<P,V,G> > + { + typedef pw::internal::image_base<fun::i2v::array<V>, + p_edges<G, fun::i2v::array<P> >, + edge_image<P,V,G> > super_; + + public: + /// Skeleton type. + typedef edge_image< tag::psite_<P>, + tag::value_<V>, + tag::graph_<G> > skeleton; + + /// Function mapping graph elements to sites. + typedef fun::i2v::array<P> site_function_t; + + /// Window type + typedef graph_elt_window<G,p_edges<G,site_function_t> > win_t; + /// Neighborhood type. + typedef graph_elt_neighborhood<G,p_edges<G,site_function_t> > nbh_t; + + /// Constructors. + /// @{ + edge_image(); + + edge_image(const Graph<G>& g, + const Function_i2v< fun::i2v::array<P> >& edge_sites, + const Function_i2v< fun::i2v::array<V> >& edge_values); + + edge_image(const p_edges<G,fun::i2v::array<P> >& pe, + const Function_i2v< fun::i2v::array<V> >& edge_values); + + template <typename FP, typename FV> + edge_image(const Graph<G>& g, + const Function_i2v<FP>& edge_sites, + const Function_i2v<FV>& edge_values); + + template <typename FV> + edge_image(const p_edges<G,fun::i2v::array<P> >& pv, + const Function_i2v<FV>& edge_values); + /// @} + + }; + + template <typename P, typename V, typename G, typename J> + void init_(tag::image_t, edge_image<P,V,G>& target, const Image<J>& model); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename P, typename V, typename G, typename J> + void init_(tag::image_t, edge_image<P,V,G>& target, const Image<J>& model) + { + fun::i2v::array<V> f; + init_(tag::function, f, exact(model)); + p_edges<G,fun::i2v::array<P> > s; + init_(tag::domain, s, exact(model)); + target.init_(f, s); + } + + // Operator. + + template <typename V, typename G, typename P> + inline + edge_image<P,V,G> + operator | (const fun::i2v::array<V>& edge_values, + const p_edges<G,fun::i2v::array<P> >& pv) + { + edge_image<P,V,G> tmp(edge_values, pv); + return tmp; + } + + + + // data< pw::image > + + namespace internal + { + + template <typename P, typename V, typename G> + inline + data< mln::edge_image<P,V,G> >::data(const fun::i2v::array<V>& f, + const p_edges<G,fun::i2v::array<P> >& ps) + : f_(exact(f)), + pset_(ps) + { + } + + } // end of namespace mln::internal + + + + // vertex_image<P,V,G> + template <typename P, typename V, typename G> + inline + edge_image<P,V,G>::edge_image() + { + } + + + template <typename P, typename V, typename G> + inline + edge_image<P,V,G>::edge_image(const Graph<G>& g, + const Function_i2v< fun::i2v::array<P> >& edge_sites, + const Function_i2v< fun::i2v::array<V> >& edge_values) + : super_(exact(edge_values), + p_edges<G,fun::i2v::array<P> >(g, exact(edge_sites))) + { + } + + + template <typename P, typename V, typename G> + inline + edge_image<P,V,G>::edge_image(const p_edges<G,fun::i2v::array<P> >& pv, + const Function_i2v< fun::i2v::array<V> >& edge_values) + : super_(exact(edge_values), pv) + { + } + + + template <typename P, typename V, typename G> + template <typename FP, typename FV> + inline + edge_image<P,V,G>::edge_image(const Graph<G>& g, + const Function_i2v<FP>& edge_sites, + const Function_i2v<FV>& edge_values) + : super_(convert::to<fun::i2v::array<V> >(exact(edge_values)), + p_edges<G,fun::i2v::array<P> >(g, exact(edge_sites))) + { + mlc_converts_to(FV,fun::i2v::array<V>)::check(); + mlc_equal(mln_result(FP),P)::check(); + mlc_equal(mln_result(FV),V)::check(); + } + + + + template <typename P, typename V, typename G> + template <typename FV> + inline + edge_image<P,V,G>::edge_image(const p_edges<G,fun::i2v::array<P> >& pv, + const Function_i2v<FV>& edge_values) + : super_(convert::to<fun::i2v::array<V> >(exact(edge_values)), pv) + { + mlc_converts_to(FV,fun::i2v::array<V>)::check(); + mlc_equal(mln_result(FV),V)::check(); + } + + +# endif // ! MLN_INCLUDE_ONLY + + +} // end of namespace mln + +#endif // ! MLN_CORE_IMAGE_EDGE_IMAGE_HH diff --git a/milena/mln/core/image/essential.hh b/milena/mln/core/image/essential.hh index 5b67315..31ab653 100644 --- a/milena/mln/core/image/essential.hh +++ b/milena/mln/core/image/essential.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008, 2009 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 @@ -28,11 +28,9 @@ #ifndef MLN_CORE_IMAGE_ESSENTIAL_HH # define MLN_CORE_IMAGE_ESSENTIAL_HH -/*! \file mln/core/image/essential.hh - * - * \brief File that includes essential image types. - * - */ +/// \file mln/core/image/essential.hh +/// +/// File that includes essential image types. # include <mln/core/image/cast_image.hh> # include <mln/core/image/image2d.hh> diff --git a/milena/mln/core/image/graph_elt_neighborhood.hh b/milena/mln/core/image/graph_elt_neighborhood.hh index 4de7669..e6bc46c 100644 --- a/milena/mln/core/image/graph_elt_neighborhood.hh +++ b/milena/mln/core/image/graph_elt_neighborhood.hh @@ -41,11 +41,11 @@ namespace mln { /// Elementary neighborhood on graph class. - template <typename G, typename F> + template <typename G, typename S> struct graph_elt_neighborhood - : public neighb< graph_elt_window<G,F> > + : public neighb< graph_elt_window<G,S> > { - typedef neighb< graph_elt_window<G,F> > super_; + typedef neighb< graph_elt_window<G,S> > super_; graph_elt_neighborhood(); }; @@ -53,9 +53,9 @@ namespace mln # ifndef MLN_INCLUDE_ONLY -template <typename G, typename F> +template <typename G, typename S> inline -graph_elt_neighborhood<G,F>::graph_elt_neighborhood() +graph_elt_neighborhood<G,S>::graph_elt_neighborhood() { } diff --git a/milena/mln/core/image/graph_elt_window.hh b/milena/mln/core/image/graph_elt_window.hh index 6143c9e..9ca8f60 100644 --- a/milena/mln/core/image/graph_elt_window.hh +++ b/milena/mln/core/image/graph_elt_window.hh @@ -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 @@ -37,33 +37,55 @@ # include <mln/core/internal/neighborhood_base.hh> # include <mln/core/internal/graph_window_base.hh> # include <mln/core/image/graph_window_piter.hh> -# include <mln/core/site_set/p_vertices.hh> namespace mln { /// Forward declaration - template <typename G, typename F> class graph_elt_window; + template <typename G, typename S> class graph_elt_window; + template <typename G, typename F> struct p_edges; + template <typename G, typename F> struct p_vertices; namespace internal { - template <typename G, typename F, typename E> - struct neighborhood_impl<graph_elt_window<G,F>,E> - : public neighborhood_extra_impl<graph_elt_window<G,F>,E> + template <typename G, typename S, typename E> + struct neighborhood_impl<graph_elt_window<G,S>,E> + : public neighborhood_extra_impl<graph_elt_window<G,S>,E> { }; + + /// Default + /// The given site set parameter is not supported yet! + template <typename G, typename S> + struct graph_window_iter_dispatch; + + template <typename G, typename F> + struct graph_window_iter_dispatch<G, p_edges<G,F> > + { + typedef mln_edge_nbh_edge_fwd_iter(G) nbh_fwd_iter_; + typedef mln_edge_nbh_edge_bkd_iter(G) nbh_bkd_iter_; + }; + + template <typename G, typename F> + struct graph_window_iter_dispatch<G, p_vertices<G,F> > + { + typedef mln_vertex_nbh_vertex_fwd_iter(G) nbh_fwd_iter_; + typedef mln_vertex_nbh_vertex_bkd_iter(G) nbh_bkd_iter_; + }; + + } // end of namespace mln::internal namespace trait { - template <typename G, typename F> - struct window_< mln::graph_elt_window<G, F> > + template <typename G, typename S> + struct window_< mln::graph_elt_window<G,S> > { typedef trait::window::size::unknown size; typedef trait::window::support::irregular support; @@ -74,20 +96,24 @@ namespace mln /// Elementary window on graph class. - template <typename G, typename F> - class graph_elt_window : public graph_window_base<mln_result(F), - graph_elt_window<G,F> > - + /// \p G is the graph type. + /// \p S is the image site set. + template <typename G, typename S> + class graph_elt_window + : public graph_window_base<mln_result(S::fun_t), + graph_elt_window<G,S> >, + public internal::graph_window_iter_dispatch<G,S> { - typedef graph_elt_window<G, F> self_; - typedef mln_vertex_nbh_vertex_fwd_iter(G) nbh_fwd_iter_; - typedef mln_vertex_nbh_vertex_bkd_iter(G) nbh_bkd_iter_; + typedef graph_elt_window<G,S> self_; + typedef internal::graph_window_iter_dispatch<G,S> super_; + typedef typename super_::nbh_fwd_iter_ nbh_fwd_iter_; + typedef typename super_::nbh_bkd_iter_ nbh_bkd_iter_; public: /// Associated types. /// \{ - typedef p_vertices<G,F> target; + typedef S target; /// The type of psite corresponding to the window. typedef mln_psite(target) psite; diff --git a/milena/mln/core/image/line_graph_elt_neighborhood.hh b/milena/mln/core/image/line_graph_elt_neighborhood.hh deleted file mode 100644 index da49fdf..0000000 --- a/milena/mln/core/image/line_graph_elt_neighborhood.hh +++ /dev/null @@ -1,67 +0,0 @@ -// 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_IMAGE_GRAPH_ELT_NEIGHBORHOOD_HH -# define MLN_CORE_IMAGE_GRAPH_ELT_NEIGHBORHOOD_HH - -/// \file mln/core/image/line_graph_elt_neighborhood.hh -/// -/// Definition of the elementary ``neighborhood'' on a line graph. - -# include <mln/core/neighb.hh> -# include <mln/core/image/line_graph_elt_window.hh> - - -namespace mln -{ - - /// Elementary neighborhood on line graph class. - template <typename G, typename F> - struct line_graph_elt_neighborhood - : public neighb< line_graph_elt_window<G,F> > - { - typedef neighb< line_graph_elt_window<G,F> > super_; - - line_graph_elt_neighborhood(); - }; - - -# ifndef MLN_INCLUDE_ONLY - -template <typename G, typename F> -inline -line_graph_elt_neighborhood<G,F>::line_graph_elt_neighborhood() -{ -} - -# endif // ! MLN_INCLUDE_ONLY - -} - -#endif // ! MLN_CORE_IMAGE_GRAPH_ELT_NEIGHBORHOOD_HH - diff --git a/milena/mln/core/image/line_graph_elt_window.hh b/milena/mln/core/image/line_graph_elt_window.hh deleted file mode 100644 index 1cb3fee..0000000 --- a/milena/mln/core/image/line_graph_elt_window.hh +++ /dev/null @@ -1,109 +0,0 @@ -// 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 -// 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_IMAGE_LINE_GRAPH_ELT_WINDOW_HH -# define MLN_CORE_IMAGE_LINE_GRAPH_ELT_WINDOW_HH - -/// \file mln/core/image/line_graph_elt_window.hh -/// -/// Definition of the elementary ``window'' on a line graph. - -# include <mln/core/concept/window.hh> -# include <mln/core/internal/neighborhood_base.hh> -# include <mln/core/internal/graph_window_base.hh> -# include <mln/core/image/graph_window_piter.hh> -# include <mln/core/site_set/p_edges.hh> - - -namespace mln -{ - - /// Forward declaration - template <typename G, typename F> class line_graph_elt_window; - - - namespace internal - { - - template <typename G, typename F, typename E> - struct neighborhood_impl<line_graph_elt_window<G,F>,E> - : public neighborhood_extra_impl<line_graph_elt_window<G,F>,E> - { - }; - - } // end of namespace mln::internal - - - namespace trait - { - - template <typename G, typename F> - struct window_< mln::line_graph_elt_window<G, F> > - { - typedef trait::window::size::unknown size; - typedef trait::window::support::irregular support; - typedef trait::window::definition::varying definition; - }; - - } // end of namespace mln::trait - - - /// Elementary window on line graph class. - template <typename G, typename F> - class line_graph_elt_window : public graph_window_base<mln_result(F), - line_graph_elt_window<G, F> > - { - typedef line_graph_elt_window<G, F> self_; - typedef mln_edge_nbh_edge_fwd_iter(G) nbh_fwd_iter_; - typedef mln_edge_nbh_edge_bkd_iter(G) nbh_bkd_iter_; - - public: - /// Associated types. - /// \{ - typedef p_edges<G,F> target; - // The type of psite corresponding to the window. - typedef mln_psite(target) psite; - - /// Site_Iterator type to browse the psites of the window - /// w.r.t. the ordering of edges. - typedef graph_window_piter<target,self_,nbh_fwd_iter_> fwd_qiter; - - /// Site_Iterator type to browse the psites of the window - /// w.r.t. the reverse ordering of edges. - typedef graph_window_piter<target,self_,nbh_bkd_iter_> bkd_qiter; - - /// The default qiter type. - typedef fwd_qiter qiter; - /// \} - - }; - -} // end of namespace mln - - -#endif // ! MLN_CORE_IMAGE_LINE_GRAPH_ELT_WINDOW_HH diff --git a/milena/mln/core/image/vertex_image.hh b/milena/mln/core/image/vertex_image.hh new file mode 100644 index 0000000..09aa15b --- /dev/null +++ b/milena/mln/core/image/vertex_image.hh @@ -0,0 +1,250 @@ +// 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_IMAGE_VERTEX_IMAGE_HH +# define MLN_CORE_IMAGE_VERTEX_IMAGE_HH + +/// \file mln/core/image/vertex_image.hh +/// +/// Image based on graph vertices. + +# include <mln/core/concept/graph.hh> +# include <mln/core/image/graph_elt_window.hh> +# include <mln/core/image/graph_elt_neighborhood.hh> +# include <mln/core/site_set/p_vertices.hh> +# include <mln/pw/internal/image_base.hh> +# include <mln/fun/i2v/array.hh> + +namespace mln +{ + + // Forward declaration. + template <typename P, typename V, typename G> class vertex_image; + namespace util { class graph; } + + + // Properties + + namespace trait + { + + template <typename P, typename V, typename G> + struct image_< vertex_image<P,V,G> > + : pw_image_<fun::i2v::array<V>, + p_vertices<util::graph, fun::i2v::array<P> >, + vertex_image<P,V,G> > + { + }; + + } // end of namespace mln::traits. + + + + namespace internal + { + + /// Data structure for mln::pw::internal::image + template <typename P, typename V, typename G> + struct data< mln::vertex_image<P,V,G> > + { + data(const fun::i2v::array<V>& vertex_values, + const p_vertices<G,fun::i2v::array<P> >& pv); + + fun::i2v::array<V> f_; + p_vertices<G,fun::i2v::array<P> > pset_; + }; + + } // end of namespace mln::internal + + + + /// Construct a vertex image from a fun::i2v::array and a p_vertices. + /// image = fun::i2v::array | p_vertices. + template <typename V, typename G, typename P> + vertex_image<P,V,G> + operator | (const fun::i2v::array<V>& vertex_values, + const p_vertices<G,fun::i2v::array<P> >& pv); + + + template <typename P, typename V, typename G = util::graph> + class vertex_image + : public pw::internal::image_base<fun::i2v::array<V>, + p_vertices<G, fun::i2v::array<P> >, + vertex_image<P,V,G> > + { + typedef pw::internal::image_base<fun::i2v::array<V>, + p_vertices<G, fun::i2v::array<P> >, + vertex_image<P,V,G> > super_; + + public: + /// Skeleton type. + typedef vertex_image< tag::psite_<P>, + tag::value_<V>, + tag::graph_<G> > skeleton; + + /// Function mapping graph elements to sites. + typedef fun::i2v::array<P> site_function_t; + + /// Window type + typedef graph_elt_window<G,p_vertices<G,site_function_t> > win_t; + /// Neighborhood type. + typedef graph_elt_neighborhood<G,p_vertices<G,site_function_t> > nbh_t; + + /// Constructors. + /// @{ + vertex_image(); + vertex_image(const Graph<G>& g, + const Function_i2v< fun::i2v::array<P> >& vertex_sites, + const Function_i2v< fun::i2v::array<V> >& vertex_values); + + vertex_image(const p_vertices<G,fun::i2v::array<P> >& pv, + const Function_i2v< fun::i2v::array<V> >& vertex_values); + + template <typename FP, typename FV> + vertex_image(const Graph<G>& g, + const Function_i2v<FP>& vertex_sites, + const Function_i2v<FV>& vertex_values); + + template <typename FV> + vertex_image(const p_vertices<G,fun::i2v::array<P> >& pv, + const Function_i2v<FV>& vertex_values); + /// @} + + }; + + template <typename P, typename V, typename G, typename J> + void init_(tag::image_t, vertex_image<P,V,G>& target, const Image<J>& model); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename P, typename V, typename G, typename J> + void init_(tag::image_t, vertex_image<P,V,G>& target, const Image<J>& model) + { + fun::i2v::array<V> f; + init_(tag::function, f, exact(model)); + p_vertices<G,fun::i2v::array<P> > s; + init_(tag::domain, s, exact(model)); + target.init_(f, s); + } + + // Operator. + + template <typename V, typename G, typename P> + inline + vertex_image<P,V,G> + operator | (const fun::i2v::array<V>& vertex_values, + const p_vertices<G,fun::i2v::array<P> >& pv) + { + vertex_image<P,V,G> tmp(vertex_values, pv); + return tmp; + } + + + + // data< pw::image > + + namespace internal + { + + template <typename P, typename V, typename G> + inline + data< mln::vertex_image<P,V,G> >::data(const fun::i2v::array<V>& f, + const p_vertices<G,fun::i2v::array<P> >& ps) + : f_(f), + pset_(ps) + { + } + + } // end of namespace mln::internal + + + + // vertex_image<P,V,G> + + template <typename P, typename V, typename G> + inline + vertex_image<P,V,G>::vertex_image() + { + } + + + template <typename P, typename V, typename G> + inline + vertex_image<P,V,G>::vertex_image(const Graph<G>& g, + const Function_i2v< fun::i2v::array<P> >& vertex_sites, + const Function_i2v< fun::i2v::array<V> >& vertex_values) + : super_(exact(vertex_values), + p_vertices<G,fun::i2v::array<P> >(g, exact(vertex_sites))) + { + } + + + template <typename P, typename V, typename G> + inline + vertex_image<P,V,G>::vertex_image(const p_vertices<G,fun::i2v::array<P> >& pv, + const Function_i2v< fun::i2v::array<V> >& vertex_values) + : super_(exact(vertex_values), pv) + { + } + + + template <typename P, typename V, typename G> + template <typename FP, typename FV> + inline + vertex_image<P,V,G>::vertex_image(const Graph<G>& g, + const Function_i2v<FP>& vertex_sites, + const Function_i2v<FV>& vertex_values) + : super_(convert::to<fun::i2v::array<V> >(exact(vertex_values)), + p_vertices<G,fun::i2v::array<P> >(g, vertex_sites)) + { + mlc_converts_to(FV,fun::i2v::array<V>)::check(); + mlc_equal(mln_result(FP),P)::check(); + mlc_equal(mln_result(FV),V)::check(); + } + + + + template <typename P, typename V, typename G> + template <typename FV> + inline + vertex_image<P,V,G>::vertex_image(const p_vertices<G,fun::i2v::array<P> >& pv, + const Function_i2v<FV>& vertex_values) + : super_(convert::to<fun::i2v::array<V> >(exact(vertex_values)), pv) + { + mlc_converts_to(FV,fun::i2v::array<V>)::check(); + mlc_equal(mln_result(FV),V)::check(); + } + + +# endif // ! MLN_INCLUDE_ONLY + + +} // end of namespace mln + +#endif // ! MLN_CORE_IMAGE_VERTEX_IMAGE_HH diff --git a/milena/mln/core/internal/image_base.hh b/milena/mln/core/internal/image_base.hh index 74be188..a254b54 100644 --- a/milena/mln/core/internal/image_base.hh +++ b/milena/mln/core/internal/image_base.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008, 2009 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 @@ -28,12 +28,11 @@ #ifndef MLN_CORE_INTERNAL_IMAGE_BASE_HH # define MLN_CORE_INTERNAL_IMAGE_BASE_HH -/*! \file mln/core/internal/image_base.hh - * - * \brief Definition of the common base class for all images. - * - * \todo Provide coord iff the site is a grid point. - */ +/// \file mln/core/internal/image_base.hh +/// +/// Definition of the common base class for all images. +/// +/// \todo Provide coord iff the site is a grid point. # include <mln/core/concept/image.hh> # include <mln/core/grids.hh> @@ -51,11 +50,11 @@ // --------------------------- // | | // image_primary image_morpher -// ^ -// | -// ----------------------------------------- -// | | | -// image_domain_morpher image_value_morpher image_identity +// ^ ^ +// | | +// | ----------------------------------------- +// | | | | +// pw_image_base image_domain_morpher image_value_morpher image_identity namespace mln diff --git a/milena/mln/core/internal/neighb_niter_impl.hh b/milena/mln/core/internal/neighb_niter_impl.hh index d80789f..c17ae1d 100644 --- a/milena/mln/core/internal/neighb_niter_impl.hh +++ b/milena/mln/core/internal/neighb_niter_impl.hh @@ -82,10 +82,10 @@ namespace mln /// Add more implementation for neighborhoods made from a /// graph_window_piter. - template <typename G, typename F, typename E> - struct neighb_niter_impl<graph_elt_window<G,F>, E> - : public neighb_niter_impl< graph_window_base< mln_result(F), - graph_elt_window<G, F> >, + template <typename G, typename S, typename E> + struct neighb_niter_impl<graph_elt_window<G,S>, E> + : public neighb_niter_impl< graph_window_base< mln_result(S::fun_t), + graph_elt_window<G,S> >, E > { diff --git a/milena/mln/core/routine/init.hxx b/milena/mln/core/routine/init.hxx index cfeb5ea..46b4045 100644 --- a/milena/mln/core/routine/init.hxx +++ b/milena/mln/core/routine/init.hxx @@ -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 @@ -39,38 +40,43 @@ namespace mln // Forward declarations. namespace fun { namespace i2v { template <typename T> class array; } } namespace fun { namespace l2l { template <typename T> class relabel; } } + namespace pw { namespace internal { template <typename F, typename S, typename E> class image_base; } } namespace pw { template <typename F, typename S> class image; } template <typename I, typename F> class image_if; /// Kind: function_t - /// Type: F, + /// Type: F1, /// From: pw::image<F,S> - template <typename F, typename S> - void init_(tag::function_t, F& f, const pw::image<F,S>& model); + template <typename F, typename S, typename E, typename J> + void init_(tag::image_t, pw::image<F,S>& target, const Image<J>& model); + /// Kind: image_t + /// Type: vertex_image<P,V,G> + /// From: J + template <typename P, typename V, typename G, typename J> + void init_(tag::image_t, vertex_image<P,V,G>& target, const Image<J>& model); /// Kind: image_t - /// Type: pw::image<F,S> + /// Type: F /// From: J - template <typename F, typename S, typename J> - void init_(tag::image_t, mln::pw::image<F,S>& target, const J& model); + template <typename I, typename F, typename J> + void init_(tag::image_t, image_if<I,F>& target, const J& model); /// Kind: function_t + /// Type: F, + /// From: pw::internal::image_base<F,S,E> + template <typename F, typename S, typename E> + void init_(tag::function_t, F& f, const pw::internal::image_base<F,S,E>& model); + + /// Kind: function_t /// Type: F /// From: image_if<I,F> template <typename I, typename F> void init_(tag::function_t, F& f, const image_if<I,F>& model); - /// Kind: image_t - /// Type: F - /// From: J - template <typename I, typename F, typename J> - void init_(tag::image_t, image_if<I,F>& target, const J& model); - - /// Kind: function_t /// Type: fun::i2v::array<T1> /// From: fun::i2v::array<T2> diff --git a/milena/mln/core/site_set/p_edges.hh b/milena/mln/core/site_set/p_edges.hh index 5111c93..ad07474 100644 --- a/milena/mln/core/site_set/p_edges.hh +++ b/milena/mln/core/site_set/p_edges.hh @@ -33,6 +33,8 @@ /// /// Definition of a site set based on graph edges. +# include <mln/core/concept/function.hh> +# include <mln/core/concept/graph.hh> # include <mln/core/internal/site_set_base.hh> # include <mln/core/site_set/p_graph_piter.hh> # include <mln/core/site_set/p_edges_psite.hh> @@ -82,14 +84,25 @@ namespace mln /// Type of graph element this site set focuses on. typedef util::edge<G> graph_element; + /// Constructors + /// @{ + /// Default constructor. + p_edges(); /// Construct a graph edge psite set from a graph and a function. /// /// \param gr The graph upon which the graph edge psite set is built. /// \param f the function mapping edges and sites. - p_edges(const G& gr, const F& f); - /// Default constructor. - p_edges(); + p_edges(const Graph<G>& gr, const Function<F>& f); + + /// Construct a graph edge psite set from a graph and a function. + /// + /// \param gr The graph upon which the graph edge psite set is built. + /// \param f the function mapping edges and sites. + /// It must be convertible towards the function type \c F. + template <typename F2> + p_edges(const Graph<G>& gr, const Function<F2>& f); + ///@} /// Associated types. /// \{ @@ -128,6 +141,10 @@ namespace mln template <typename G2> bool has(const util::edge<G2>& e) const; + /// Does this site set has \a vertex_id? + /// FIXME: causes ambiguities while calling has(mln::neighb_fwd_niter<>); + /// bool has(unsigned vertex_id) const; + // FIXME: Dummy. std::size_t memory_size() const; @@ -171,19 +188,35 @@ namespace mln namespace mln { + template <typename G, typename F> inline - p_edges<G, F>::p_edges(const G& g, const F& f) - : g_ (g), f_(f) + p_edges<G, F>::p_edges() { } template <typename G, typename F> inline - p_edges<G, F>::p_edges() + p_edges<G, F>::p_edges(const Graph<G>& g, const Function<F>& f) + { + mln_precondition(exact(g).is_valid()); + g_ = exact(g); + f_ = exact(f); + } + + template <typename G, typename F> + template <typename F2> + inline + p_edges<G, F>::p_edges(const Graph<G>& g, const Function<F2>& f) { + mln_precondition(exact(g).is_valid()); + mlc_converts_to(F2,F)::check(); + + g_ = exact(g); + convert::from_to(f, f_); } + template <typename G, typename F> inline unsigned @@ -235,6 +268,16 @@ namespace mln return e.graph().is_subgraph_of(g_) && g_.has(e) && e.is_valid(); } +// template <typename G, typename F> +// inline +// bool +// p_edges<G,F>::has(unsigned edge_id) const +// { +// mln_precondition(is_valid()); +// util::edge<G> e(g_, edge_id); +// return has(e); +// } + template <typename G, typename F> inline std::size_t diff --git a/milena/mln/core/site_set/p_graph_piter.hh b/milena/mln/core/site_set/p_graph_piter.hh index e6f4ce8..5642446 100644 --- a/milena/mln/core/site_set/p_graph_piter.hh +++ b/milena/mln/core/site_set/p_graph_piter.hh @@ -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 @@ -85,7 +85,7 @@ namespace mln /// Return the graph associated to the target S. const typename S::graph_t& graph() const; - /// Return the underlying iterator. + /// Return the underlying graph element iterator. const iter& hook_elt_() const; /// Convert towards the graph element id. diff --git a/milena/mln/core/site_set/p_vertices.hh b/milena/mln/core/site_set/p_vertices.hh index a095af3..b20d19b 100644 --- a/milena/mln/core/site_set/p_vertices.hh +++ b/milena/mln/core/site_set/p_vertices.hh @@ -33,6 +33,7 @@ /// /// Definition of a point set based on a graph. +# include <mln/core/concept/function.hh> # include <mln/core/internal/site_set_base.hh> # include <mln/core/site_set/p_graph_piter.hh> # include <mln/core/site_set/p_vertices_psite.hh> @@ -94,7 +95,14 @@ namespace mln /// Construct a graph psite set from a graph of points. /// \param gr The graph upon which the graph psite set is built. /// \param f the function which maps a vertex to a site. - p_vertices(const G& gr, const F& f); + p_vertices(const Graph<G>& gr, const Function<F>& f); + + /// Construct a graph psite set from a graph of points. + /// \param gr The graph upon which the graph psite set is built. + /// \param f the function which maps a vertex to a site. + /// It must be convertible to the function type \c F. + template <typename F2> + p_vertices(const Graph<G>& gr, const Function<F2>& f); /// \} @@ -139,7 +147,11 @@ namespace mln /// Does this site set has \a v? template <typename G2> - bool has(const util::vertex<G2>& p) const; + bool has(const util::vertex<G2>& v) const; + + /// Does this site set has \a vertex_id? + /// FIXME: causes ambiguities while calling has(mln::neighb_fwd_niter<>); + /// bool has(unsigned vertex_id) const; // FIXME: Dummy. std::size_t memory_size() const; @@ -202,9 +214,23 @@ namespace mln template <typename G, typename F> inline - p_vertices<G,F>::p_vertices(const G& g, const F& f) - : g_ (g), f_(f) + p_vertices<G,F>::p_vertices(const Graph<G>& g, const Function<F>& f) + { + mln_precondition(exact(g).is_valid()); + g_ = exact(g); + f_ = exact(f); + } + + template <typename G, typename F> + template <typename F2> + inline + p_vertices<G,F>::p_vertices(const Graph<G>& g, const Function<F2>& f) { + mln_precondition(exact(g).is_valid()); + mlc_converts_to(F2,F)::check(); + + g_ = exact(g); + convert::from_to(f, f_); } template <typename G, typename F> @@ -252,17 +278,28 @@ namespace mln template <typename G2> inline bool - p_vertices<G,F>::has(const util::vertex<G2>& p) const + p_vertices<G,F>::has(const util::vertex<G2>& v) const { mln_precondition(is_valid()); return - // Check whether P is compatible with this psite set. - (p.graph() == g_) && + // Check whether if the graph is 'compatible'. + v.graph().is_subgraph_of(g_) && + g_.has(v) && // Check that the vertex id of P belongs to the range of valid // vertex ids. - (p.is_valid()); + (v.is_valid()); } +// template <typename G, typename F> +// inline +// bool +// p_vertices<G,F>::has(unsigned vertex_id) const +// { +// mln_precondition(is_valid()); +// util::vertex<G> v(g_, vertex_id); +// return has(v); +// } + template <typename G, typename F> inline std::size_t diff --git a/milena/mln/debug/draw_graph.hh b/milena/mln/debug/draw_graph.hh index abc96a4..7584b4e 100644 --- a/milena/mln/debug/draw_graph.hh +++ b/milena/mln/debug/draw_graph.hh @@ -38,8 +38,10 @@ # include <mln/core/site_set/p_vertices.hh> # include <mln/core/site_set/p_edges.hh> # include <mln/util/line_graph.hh> +# include <mln/util/site_pair.hh> # include <mln/draw/line.hh> # include <mln/data/fill.hh> +# include <mln/metal/equal.hh> namespace mln { @@ -92,6 +94,8 @@ namespace mln mln_value(I) vertex_v, mln_value(I) edge_v) { + trace::entering("debug::draw_graph"); + // Draw edges. typedef p_edges<G, F> pe_t; mln_piter(pe_t) p(pe); @@ -105,6 +109,7 @@ namespace mln exact(ima)(p.second()) = vertex_v; } + trace::exiting("debug::draw_graph"); } @@ -116,6 +121,8 @@ namespace mln mln_value(I) vertex_v, mln_value(I) edge_v) { + trace::entering("debug::draw_graph"); + // Draw edges. const G& g = pv.graph(); typedef p_vertices<G, F> pv_t; @@ -128,6 +135,8 @@ namespace mln for_all(p) if (exact(ima).has(p)) exact(ima)(p) = vertex_v; + + trace::exiting("debug::draw_graph"); } // FIXME: Refactor + be more restrictive on the function type. @@ -138,6 +147,8 @@ namespace mln const p_vertices<G, F>& pv, const Function<V>& vcolor_, const Function<E>& ecolor_) { + trace::entering("debug::draw_graph"); + const V& vcolor = exact(vcolor_); const E& ecolor = exact(ecolor_); @@ -153,6 +164,8 @@ namespace mln for_all(p) if (exact(ima).has(p)) exact(ima)(p) = vcolor(p); + + trace::exiting("debug::draw_graph"); } // FIXME: Refactor + be more restrictive on the function type. @@ -163,6 +176,8 @@ namespace mln const p_vertices<util::line_graph<G>, F>& pv, const Function<V>& vcolor_, const Function<E>& ecolor_) { + trace::entering("debug::draw_graph"); + const V& vcolor = exact(vcolor_); const E& ecolor = exact(ecolor_); @@ -184,6 +199,8 @@ namespace mln if (exact(ima).has(l.end())) exact(ima)(l.end()) = vcolor(g.edge(vi).v2()); } + + trace::exiting("debug::draw_graph"); } # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/mln/morpho/attribute/count_adjacent_vertices.hh b/milena/mln/morpho/attribute/count_adjacent_vertices.hh index 8c8df76..49e08b3 100644 --- a/milena/mln/morpho/attribute/count_adjacent_vertices.hh +++ b/milena/mln/morpho/attribute/count_adjacent_vertices.hh @@ -25,6 +25,7 @@ // 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_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH_ # define MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH_ @@ -32,7 +33,10 @@ /// /// Define an accumulator that counts the vertices adjacent to a /// set of p_edges psites. +/// +/// \todo Check that the image is based on a graph. +# include <mln/pw/internal/image_base.hh> # include <mln/accu/internal/base.hh> # include <mln/pw/image.hh> # include <mln/util/pix.hh> @@ -76,12 +80,12 @@ namespace mln /// /// The parameter \p I is the image type on which the accumulator /// of pixels is built. - - template <typename F, typename S> - struct count_adjacent_vertices< pw::image<F, S> > - : public accu::internal::base< unsigned , count_adjacent_vertices< pw::image<F, S> > > + // + template <typename I> + struct count_adjacent_vertices + : public accu::internal::base< unsigned , + count_adjacent_vertices<I> > { - typedef pw::image<F, S> I; typedef mln_psite(I) argument; count_adjacent_vertices(); @@ -117,70 +121,70 @@ namespace mln # ifndef MLN_INCLUDE_ONLY - template <typename F, typename S> + template <typename I> inline - count_adjacent_vertices< pw::image<F, S> >::count_adjacent_vertices() + count_adjacent_vertices<I>::count_adjacent_vertices() { init(); } - template <typename F, typename S> + template <typename I> inline void - count_adjacent_vertices< pw::image<F, S> >::init() + count_adjacent_vertices<I>::init() { vertices_.clear(); update_(); } - template <typename F, typename S> + template <typename I> inline void - count_adjacent_vertices< pw::image<F,S> >::take(const argument& p) + count_adjacent_vertices<I>::take(const argument& p) { vertices_.insert(p.v1()); vertices_.insert(p.v2()); update_(); } - template <typename F, typename S> + template <typename I> inline void - count_adjacent_vertices< pw::image<F,S> >::take(const count_adjacent_vertices< pw::image <F,S> >& other) + count_adjacent_vertices<I>::take(const count_adjacent_vertices<I>& other) { vertices_.insert (other.vertices_.begin(), other.vertices_.end()); update_(); } - template <typename F, typename S> + template <typename I> inline void - count_adjacent_vertices< pw::image<F,S> >::take_as_init(const argument& px) + count_adjacent_vertices<I>::take_as_init(const argument& px) { vertices_.clear(); take(px); } - template <typename F, typename S> + template <typename I> inline unsigned - count_adjacent_vertices< pw::image<F,S> >::to_result() const + count_adjacent_vertices<I>::to_result() const { return count__; } - template <typename F, typename S> + template <typename I> inline void - count_adjacent_vertices< pw::image<F,S> >::update_() + count_adjacent_vertices<I>::update_() { count__ = vertices_.size(); } - template <typename F, typename S> + template <typename I> inline bool - count_adjacent_vertices< pw::image<F,S> >::is_valid() const + count_adjacent_vertices<I>::is_valid() const { return true; } @@ -194,4 +198,4 @@ namespace mln } // end of namespace mln -#endif /* !MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH_ */ +#endif // ! MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH_ diff --git a/milena/mln/morpho/closing/area_on_vertices.hh b/milena/mln/morpho/closing/area_on_vertices.hh index 6087112..099e473 100644 --- a/milena/mln/morpho/closing/area_on_vertices.hh +++ b/milena/mln/morpho/closing/area_on_vertices.hh @@ -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 @@ -35,7 +35,7 @@ /// the area in terms of adjacent vertices. # include <mln/pw/image.hh> -# include <mln/core/site_set/p_edges.hh> +# include <mln/core/image/edge_image.hh> # include <mln/morpho/closing/algebraic.hh> # include <mln/morpho/attribute/count_adjacent_vertices.hh> @@ -49,38 +49,38 @@ namespace mln namespace closing { - /// Morphological area closing on a mln::line_graph_image computing - /// the area in terms of adjacent vertices. - template <typename P2V, typename G, typename V2P, typename N> - pw::image<P2V, p_edges<G, V2P> > - area_on_vertices(const pw::image<P2V, p_edges<G, V2P> >& input, + /// Morphological area closing on a mln::line_graph_image computing + /// the area in terms of adjacent vertices. + template <typename P, typename V, typename G, typename N> + edge_image<P,V,G> + area_on_vertices(const edge_image<P,V,G>& input, const Neighborhood<N>& nbh, unsigned lambda); # ifndef MLN_INCLUDE_ONLY - template <typename P2V, typename G, typename V2P, typename N> + template <typename P, typename V, typename G, typename N> inline - pw::image<P2V, p_edges<G, V2P> > - area_on_vertices(const pw::image<P2V, p_edges<G, V2P> >& input, + edge_image<P,V,G> + area_on_vertices(const edge_image<P,V,G>& input, const Neighborhood<N>& nbh, unsigned lambda) { trace::entering("morpho::closing::area_on_vertices"); mln_precondition(exact(input).is_valid()); - typedef p_edges<G, V2P> pe_t; - typedef attribute::count_adjacent_vertices< pw::image<P2V, pe_t> > attribute_t; + typedef attribute::count_adjacent_vertices< edge_image<P,V,G> > attribute_t; - pw::image<P2V, p_edges<G, V2P> > output; - output = closing::algebraic(input, nbh, attribute_t(), lambda); + edge_image<P,V,G> + output = closing::algebraic(input, nbh, attribute_t(), lambda); trace::exiting("morpho::closing::area_on_vertices"); return output; } # endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::morpho::closing } // end of namespace mln::morpho diff --git a/milena/mln/morpho/line_gradient.hh b/milena/mln/morpho/line_gradient.hh index 4b12d4a..32b5975 100644 --- a/milena/mln/morpho/line_gradient.hh +++ b/milena/mln/morpho/line_gradient.hh @@ -1,4 +1,4 @@ -// 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 @@ -43,10 +43,9 @@ # include <mln/util/ord.hh> # include <mln/core/image/image2d.hh> +# include <mln/core/image/edge_image.hh> # include <mln/core/alias/window2d.hh> -# include <mln/core/site_set/p_edges.hh> - # include <mln/util/graph.hh> # include <mln/util/site_pair.hh> @@ -65,22 +64,25 @@ namespace mln /* FIXME: Currently, the adjacency is set to 4-c and cannot be changed. */ template <typename V> - pw::image<fun::i2v::array<V>, p_edges<util::graph, fun::i2v::array< util::site_pair<point2d> > > > + edge_image<util::site_pair<point2d>, V, util::graph> line_gradient(const mln::image2d<V>& ima); # ifndef MLN_INCLUDE_ONLY template <typename V> - pw::image<fun::i2v::array<V>, p_edges<util::graph, fun::i2v::array< util::site_pair<point2d> > > > + edge_image<util::site_pair<point2d>, V, util::graph> line_gradient(const mln::image2d<V>& ima) { + trace::entering("morpho::line_gradient"); + mln_precondition(ima.is_valid()); + // FIXME: Precondition: Ensure the image is scalar. util::graph g; // Vertices. image2d<unsigned> vpsite(ima.domain()); - fun::i2v::array<mln::point2d> fv2p(ima.domain().nsites()); + fun::i2v::array<point2d> fv2p(ima.domain().nsites()); fun::i2v::array<V> vertex_values(ima.domain().nsites()); mln_fwd_piter(image2d<V>) p(ima.domain()); @@ -111,12 +113,10 @@ namespace mln edge_sites.append(util::site_pair<point2d>(p, q)); } - // Line graph point set. - typedef p_edges<util::graph, edge_sites_t> pe_t; - pe_t plg(g, edge_sites); - // Line graph image. - typedef pw::image<edge_values_t, pe_t> ima_t; - ima_t lg_ima = (edge_values | plg); + edge_image<util::site_pair<point2d>, V, util::graph> + lg_ima(g, edge_sites, edge_values); + + trace::exiting("morpho::line_gradient"); return lg_ima; } diff --git a/milena/mln/pw/image.hh b/milena/mln/pw/image.hh index 49a0afa..e96233e 100644 --- a/milena/mln/pw/image.hh +++ b/milena/mln/pw/image.hh @@ -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 @@ -31,14 +31,11 @@ /// \file mln/pw/image.hh /// -/// FIXME. +/// Point-wised restricted image. - -# include <mln/core/internal/image_primary.hh> +# include <mln/pw/internal/image_base.hh> # include <mln/core/concept/function.hh> # include <mln/value/set.hh> -# include <mln/metal/unqualif.hh> -# include <mln/metal/not_equal.hh> namespace mln @@ -48,19 +45,24 @@ namespace mln namespace pw { template <typename F, typename S> class image; } + // Properties - /// Construct an image from a function and a site set. - /// image = function | site_set. - template <typename F, typename S> - pw::image<F,S> - operator | (const Function_v2v<F>& f, const Site_Set<S>& ps); + namespace trait + { + template <typename F, typename S> + struct image_< pw::image<F,S> > + : pw_image_<F,S, pw::image<F,S> > + { + }; + + } // end of namespace mln::traits. namespace internal { - /// Data structure for mln::pw::image + /// Data structure for mln::pw::internal::image template <typename F, typename S> struct data< mln::pw::image<F,S> > { @@ -72,127 +74,52 @@ namespace mln } // end of namespace mln::internal - - namespace trait - { - - // FIXME: the result type should *not* be qualified - - template <typename F, typename S> - struct image_< pw::image<F,S> > : default_image_< mln_result(F), - pw::image<F,S> > - { - private: - typedef typename F::mutable_result mutable_result; - typedef mlc_not_equal(mutable_result, void) is_mutable; - - public: - // misc - typedef trait::image::category::primary category; - typedef trait::image::speed::fast speed; - typedef trait::image::size::regular size; - - // value - typedef trait::image::vw_io::none vw_io; - typedef trait::image::vw_set::none vw_set; - typedef trait::image::value_access::computed value_access; - typedef trait::image::value_storage::disrupted value_storage; - typedef trait::image::value_browsing::site_wise_only value_browsing; - typedef trait::image::value_alignment::irrelevant value_alignment; - typedef mlc_if(is_mutable, - trait::image::value_io::read_write, - trait::image::value_io::read_only) value_io; - - // site / domain - typedef mlc_if(is_mutable, - trait::image::pw_io::read_write, - trait::image::pw_io::read) pw_io; - typedef /* FIXME: depends on S */ undef localization; - typedef /* FIXME: depends on S */ undef dimension; - - // extended domain - typedef trait::image::ext_domain::none ext_domain; - typedef trait::image::ext_value::irrelevant ext_value; - typedef trait::image::ext_io::irrelevant ext_io; - }; - - } // end of namespace mln::trait + /// Construct an image from a function and a site set. + /// image = function | site_set. + template <typename F, typename S> + pw::image<F,S> + operator | (const Function_v2v<F>& f, const Site_Set<S>& ps); namespace pw { - /// FIXME - /// + /// A generic point-wise image implementation. + /// Parameter \p F is a function restricting the domain. + /// Parameter \p S is the domain type. template <typename F, typename S> class image : - public internal::image_primary<mln_result(F), S, image<F,S> > + public pw::internal::image_base< F, S, image<F,S> > { - typedef typename F::mutable_result mutable_result; - typedef mlc_not_equal(mutable_result, void) is_mutable; + typedef pw::internal::image_base< F, S, image<F,S> > super_; public: - /// Skeleton. typedef image< tag::function_<F>, tag::pset_<S> > skeleton; - /// Function associated type. - typedef F function_t; - - /// Value associated type. - typedef mln_result(F) value; - - /// Return type of read-only access. - typedef mln_result(F) rvalue; - - /// Return type of read-write access. - typedef mlc_if(is_mutable, mutable_result, mln_result(F)) lvalue; - /// Constructor without argument. image(); /// Constructor. image(const Function_v2v<F>& f, const Site_Set<S>& ps); - /// Initialize an empty image. - void init_(const Function_v2v<F>& f, const Site_Set<S>& ps); - - /// Give the definition domain. - const S& domain() const; - - /// Return the function which computes a site value. - F function() const; - - /// Read-only access of pixel value at point site \p p. - rvalue operator()(const mln_psite(S)& p) const; - - /// Read-write access returns either a temporary value (copy) or - /// a reference in the case of a mutable function (container). - lvalue operator()(const mln_psite(S)& p); }; } // end of namespace mln::pw + /// Init_ -# ifndef MLN_INCLUDE_ONLY + template <typename F, typename S, typename E, typename J> + void init_(tag::image_t, pw::image<F,S>& target, const Image<J>& model); - // init_ - template <typename F, typename S> - void init_(tag::function_t, F& f, const pw::image<F,S>& model) - { - f = model.function(); - } +# ifndef MLN_INCLUDE_ONLY - template <typename F1, typename F2, typename S> - void init_(tag::function_t, F1& f, const pw::image<F2,S>& model) - { - init_(tag::function, f, model.function()); - } + /// Init_ - template <typename F, typename S, typename J> - void init_(tag::image_t, pw::image<F,S>& target, const J& model) + template <typename F, typename S, typename E, typename J> + void init_(tag::image_t, pw::image<F,S>& target, const Image<J>& model) { F f; init_(tag::function, f, exact(model)); @@ -201,6 +128,7 @@ namespace mln target.init_(f, s); } + // Operator. template <typename F, typename S> @@ -212,7 +140,8 @@ namespace mln return tmp; } - // internal::data< pw::image<F,S> > + + // data< pw::image > namespace internal { @@ -221,11 +150,13 @@ namespace mln inline data< mln::pw::image<F,S> >::data(const F& f, const S& ps) : f_(f), - pset_(ps) + pset_(ps) { } - } + } // end of namespace mln::internal + + // pw::image<F,S> @@ -242,51 +173,9 @@ namespace mln inline image<F,S>::image(const Function_v2v<F>& f, const Site_Set<S>& ps) { - this->data_ = new internal::data< pw::image<F,S> >(exact(f), exact(ps)); + this->data_ = new mln::internal::data< image<F,S> >(exact(f), exact(ps)); } - template <typename F, typename S> - inline - void - image<F,S>::init_(const Function_v2v<F>& f, const Site_Set<S>& ps) - { - this->data_ = new internal::data< image<F,S> >(exact(f), exact(ps)); - } - - template <typename F, typename S> - inline - const S& - image<F,S>::domain() const - { - return this->data_->pset_; - } - - template <typename F, typename S> - inline - F - image<F,S>:: function() const - { - return this->data_->f_; - } - - - template <typename F, typename S> - inline - typename image<F,S>::rvalue - image<F,S>::operator()(const mln_psite(S)& p) const - { - mln_precondition(this->data_->pset_.has(p)); - return this->data_->f_(p); - } - - template <typename F, typename S> - inline - typename image<F,S>::lvalue - image<F,S>::operator()(const mln_psite(S)& p) - { - mln_precondition(this->data_->pset_.has(p)); - return this->data_->f_(p); - } } // end of namespace mln::pw diff --git a/milena/mln/pw/internal/image_base.hh b/milena/mln/pw/internal/image_base.hh new file mode 100644 index 0000000..2770612 --- /dev/null +++ b/milena/mln/pw/internal/image_base.hh @@ -0,0 +1,257 @@ +// 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_PW_INTERNAL_IMAGE_BASE_HH +# define MLN_PW_INTERNAL_IMAGE_BASE_HH + +/// \file mln/pw/internal/image_base.hh +/// +/// Definition of the common base class for all point-wise images. + +# include <mln/core/internal/image_primary.hh> +# include <mln/metal/unqualif.hh> +# include <mln/metal/not_equal.hh> +# include <mln/value/set.hh> + + +namespace mln +{ + + + // Forward declaration. + namespace pw + { + + namespace internal + { + + template <typename F, typename S, typename E> + struct image_base; + + } // end of namespace mln::pw::internal + + } // end of namespace mln::pw + + namespace trait + { + + // FIXME: the result type should *not* be qualified + + template <typename F, typename S, typename E> + struct pw_image_ + : default_image_<mln_result(F),E> + { + private: + typedef typename F::mutable_result mutable_result; + typedef mlc_not_equal(mutable_result, void) is_mutable; + + public: + // misc + typedef trait::image::category::primary category; + typedef trait::image::speed::fast speed; + typedef trait::image::size::regular size; + + // value + typedef trait::image::vw_io::none vw_io; + typedef trait::image::vw_set::none vw_set; + typedef trait::image::value_access::computed value_access; + typedef trait::image::value_storage::disrupted value_storage; + typedef trait::image::value_browsing::site_wise_only value_browsing; + typedef trait::image::value_alignment::irrelevant value_alignment; + typedef mlc_if(is_mutable, + trait::image::value_io::read_write, + trait::image::value_io::read_only) value_io; + + // site / domain + typedef mlc_if(is_mutable, + trait::image::pw_io::read_write, + trait::image::pw_io::read) pw_io; + typedef /* FIXME: depends on S */ undef localization; + typedef /* FIXME: depends on S */ undef dimension; + + // extended domain + typedef trait::image::ext_domain::none ext_domain; + typedef trait::image::ext_value::irrelevant ext_value; + typedef trait::image::ext_io::irrelevant ext_io; + }; + + } // end of namespace mln::trait + + + namespace pw + { + + namespace internal + { + + /// A base class for point-wise images. + /// Parameter \p F is the image value type. + /// Parameter \p S is the image site set type. + template <typename F, typename S, typename E> + struct image_base + : public mln::internal::image_primary<mln_result(F), S, E > + { + typedef typename F::mutable_result mutable_result; + typedef mlc_not_equal(mutable_result, void) is_mutable; + + public: + /// Function associated type. + typedef F function_t; + + /// Value associated type. + typedef mln_result(F) value; + + /// Return type of read-only access. + typedef mln_result(F) rvalue; + + /// Return type of read-write access. + typedef mlc_if(is_mutable, mutable_result, mln_result(F)) lvalue; + + /// Initialize an empty image. + void init_(const Function_v2v<F>& f, const Site_Set<S>& ps); + + /// Give the definition domain. + const S& domain() const; + + /// Return the function which computes a site value. + F function() const; + + /// Read-only access of pixel value at point site \p p. + rvalue operator()(const mln_psite(S)& p) const; + + /// Read-write access returns either a temporary value (copy) or + /// a reference in the case of a mutable function (container). + lvalue operator()(const mln_psite(S)& p); + + protected: + image_base(); + image_base(const Function_v2v<F>& f, const Site_Set<S>& ps); + }; + + } // end of namespace mln::pw::internal + + } // end of namespace mln::pw + + + // init_ + + template <typename F, typename S, typename E> + void init_(tag::function_t, F& f, const pw::internal::image_base<F,S,E>& model); + + template <typename F1, typename F2, typename S, typename E> + void init_(tag::function_t, F1& f, const pw::internal::image_base<F2,S,E>& model); + + +# ifndef MLN_INCLUDE_ONLY + + // init_ + + template <typename F, typename S, typename E> + void init_(tag::function_t, F& f, const pw::internal::image_base<F,S,E>& model) + { + f = model.function(); + } + + template <typename F1, typename F2, typename S, typename E> + void init_(tag::function_t, F1& f, const pw::internal::image_base<F2,S,E>& model) + { + init_(tag::function, f, model.function()); + } + + + namespace pw + { + + namespace internal + { + + template <typename F, typename S, typename E> + inline + image_base<F,S,E>::image_base() + { + } + + template <typename F, typename S, typename E> + inline + image_base<F,S,E>::image_base(const Function_v2v<F>& f, const Site_Set<S>& ps) + { + this->data_ = new mln::internal::data<E>(exact(f), exact(ps)); + } + + template <typename F, typename S, typename E> + inline + void + image_base<F,S,E>::init_(const Function_v2v<F>& f, const Site_Set<S>& ps) + { + this->data_ = new mln::internal::data<E>(exact(f), exact(ps)); + } + + template <typename F, typename S, typename E> + inline + const S& + image_base<F,S,E>::domain() const + { + return this->data_->pset_; + } + + template <typename F, typename S, typename E> + inline + F + image_base<F,S,E>:: function() const + { + return this->data_->f_; + } + + + template <typename F, typename S, typename E> + inline + typename image_base<F,S,E>::rvalue + image_base<F,S,E>::operator()(const mln_psite(S)& p) const + { + mln_precondition(this->data_->pset_.has(p)); + return this->data_->f_(p); + } + + template <typename F, typename S, typename E> + inline + typename image_base<F,S,E>::lvalue + image_base<F,S,E>::operator()(const mln_psite(S)& p) + { + mln_precondition(this->data_->pset_.has(p)); + return this->data_->f_(p); + } + + } // end of namespace mln::pw::internal + + } // end of namespace mln::pw + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_PW_INTERNAL_IMAGE_BASE_HH diff --git a/milena/mln/tag/skeleton.hh b/milena/mln/tag/skeleton.hh index 36f8581..a90bd05 100644 --- a/milena/mln/tag/skeleton.hh +++ b/milena/mln/tag/skeleton.hh @@ -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 @@ -29,11 +29,10 @@ #ifndef MLN_TAG_SKELETON_HH # define MLN_TAG_SKELETON_HH -/*! \file mln/tag/skeleton.hh - * - * \brief Definition of tags used in the skeleton types associated to - * image types. - */ +/// \file mln/tag/skeleton.hh +/// +/// Definition of tags used in the skeleton types associated to +/// image types. namespace mln @@ -46,6 +45,7 @@ namespace mln template <typename D> struct data_ { typedef D param; }; template <typename E> struct ext_ { typedef E param; }; template <typename F> struct function_ { typedef F param; }; + template <typename G> struct graph_ { typedef G param; }; template <typename I> struct image_ { typedef I param; }; template <typename N> struct neighb_ { typedef N param; }; template <typename P> struct psite_ { typedef P param; }; diff --git a/milena/mln/trait/ch_value.hh b/milena/mln/trait/ch_value.hh index cff3a59..e02bf04 100644 --- a/milena/mln/trait/ch_value.hh +++ b/milena/mln/trait/ch_value.hh @@ -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 @@ -50,6 +50,8 @@ namespace mln 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; + template <typename P, typename V, typename G> class vertex_image; + template <typename P, typename V, typename G> class edge_image; namespace pw { template <typename F, typename S> class image; } @@ -165,7 +167,8 @@ namespace mln typedef typename image_from_grid< grid, V >::ret ret; }; - // line_graph image + + // Graph image based on p_edges template < typename F, typename G, typename FP, typename V > @@ -174,15 +177,36 @@ namespace mln typedef pw::image< mln_ch_function_value(F, V), p_edges<G, FP> > ret; }; - // graph image + // Graph image based on p_vertices 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; }; + // Vertex Image + template < typename P, typename V1, typename G, typename V2> + struct ch_value_< vertex_image< tag::psite_<P>, + tag::value_<V1>, + tag::graph_<G> >, + V2 > + { + typedef vertex_image< P, V2, G > ret; + }; + + // Edge Image + template < typename P, typename V1, typename G, typename V2> + struct ch_value_< edge_image< tag::psite_<P>, + tag::value_<V1>, + tag::graph_<G> >, + V2 > + { + typedef edge_image< P, V2, G > ret; + }; + template < template <class, class> class M, typename T, typename S, typename V > diff --git a/milena/mln/util/graph.hh b/milena/mln/util/graph.hh index 10e900f..c93e0f9 100644 --- a/milena/mln/util/graph.hh +++ b/milena/mln/util/graph.hh @@ -202,6 +202,10 @@ namespace mln /// Return the edge whose id is \a e. edge_t edge(unsigned e) const; + + /// Return the list of all edges. + const std::vector<util::ord_pair<unsigned> >& edges() const; + /// Return the number of edges in the graph. size_t e_nmax() const; @@ -420,6 +424,13 @@ namespace mln } inline + const std::vector<util::ord_pair<unsigned> >& + graph::edges() const + { + return this->data_->edges_; + } + + inline graph::edge_t graph::edge(unsigned e) const { diff --git a/milena/tests/core/image/Makefile.am b/milena/tests/core/image/Makefile.am index b8c3abc..cdd52f6 100644 --- a/milena/tests/core/image/Makefile.am +++ b/milena/tests/core/image/Makefile.am @@ -7,6 +7,7 @@ check_PROGRAMS = \ cast_image \ complex_image \ decorated_image \ + edge_image \ flat_image \ hexa \ graph_image \ @@ -24,7 +25,8 @@ check_PROGRAMS = \ sub_image \ t_image \ tr_image \ - unproject_image + unproject_image \ + vertex_image ## bgraph_image \ ## mono_obased_rle_image \ @@ -66,6 +68,8 @@ t_image_SOURCES = t_image.cc tr_image_SOURCES = tr_image.cc unproject_image_SOURCES = unproject_image.cc ##value_enc_image_SOURCES = value_enc_image.cc +vertex_image_SOURCES = vertex_image.cc +edge_image_SOURCES = edge_image.cc # Tests depending on the FreeImagePlus library. if FREEIMAGEPLUS diff --git a/milena/tests/core/image/graph_image.cc b/milena/tests/core/image/edge_image.cc similarity index 73% copy from milena/tests/core/image/graph_image.cc copy to milena/tests/core/image/edge_image.cc index e8a71f2..7ee2f98 100644 --- a/milena/tests/core/image/graph_image.cc +++ b/milena/tests/core/image/edge_image.cc @@ -1,4 +1,4 @@ -// Copyright(C) 2007, 2008 EPITA Research and Development Laboratory(LRDE) +// 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 @@ -25,27 +25,23 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/// \file tests/core/image/graph_image.cc +/// \file tests/core/image/edge_image.cc /// -/// Tests on mln::graph_image. +/// Tests on mln::edge_image. #include <vector> -#include <mln/core/site_set/p_vertices.hh> -#include <mln/core/image/graph_elt_window.hh> -#include <mln/core/image/graph_elt_neighborhood.hh> -#include <mln/core/concept/function.hh> -#include <mln/core/neighb.hh> -#include <mln/core/var.hh> +#include <mln/core/image/edge_image.hh> +#include <mln/core/image/image2d.hh> #include <mln/accu/bbox.hh> #include <mln/fun/i2v/array.hh> #include <mln/util/graph.hh> +#include <mln/util/site_pair.hh> #include <mln/debug/draw_graph.hh> -#include <mln/debug/println.hh> /* The graph is as follows: @@ -63,17 +59,17 @@ // Expected neighbors for forward and backward iteration. // -1 is an invalid id. -static unsigned expected_fwd_nb[5][3] = { { 1, -1, -1 }, - { 0, 2, 3 }, - { 1, 4, -1 }, - { 1, 4, -1 }, - { 3, 2, -1 } }; +static unsigned expected_fwd_nb[5][3] = { { 1, 2, -1 }, + { 0, 2, 4 }, + { 0, 1, 3 }, + { 2, 4, -1 }, + { 1, 3, -1 } }; -static unsigned expected_bkd_nb[5][3] = { { 1, -1, -1 }, - { 3, 2, 0 }, - { 4, 1, -1 }, - { 4, 1, -1 }, - { 2, 3, -1 } }; +static unsigned expected_bkd_nb[5][3] = { { 2, 1, -1 }, + { 4, 2, 0 }, + { 3, 1, 0 }, + { 4, 2, -1 }, + { 3, 1, -1 } }; int main() @@ -85,15 +81,15 @@ int main() `--------*/ // Points associated to vertices. - typedef fun::i2v::array<point2d> fsite_t; + typedef util::site_pair<point2d> site_t; + typedef fun::i2v::array<site_t> fsite_t; fsite_t sites(5); - sites(0) = point2d(0,0); // Point associated to vertex 0. - sites(1) = point2d(2,2); // Point associated to vertex 1. - sites(2) = point2d(0,4); // Point associated to vertex 2. - sites(3) = point2d(4,3); // Point associated to vertex 3. - sites(4) = point2d(4,4); // Point associated to vertex 4. + sites(0) = site_t(point2d(0,0),point2d(2,2)); // Site associated to edge 0. + sites(1) = site_t(point2d(2,2),point2d(0,4)); // Site associated to edge 1. + sites(2) = site_t(point2d(2,2),point2d(4,3)); // Site associated to edge 2. + sites(3) = site_t(point2d(4,3),point2d(4,4)); // Site associated to edge 3. + sites(4) = site_t(point2d(4,4),point2d(0,4)); // Site associated to edge 4. - // Edges. util::graph g; // Populate the graph with vertices. @@ -108,25 +104,18 @@ int main() //g.print_debug(std::cout); - /*----------------------. - | Graph image support. | - `----------------------*/ - - typedef p_vertices<util::graph, fsite_t> S; - S pv(g, sites); - /*-------------. | Graph image. | `-------------*/ // Graph values. typedef fun::i2v::array<unsigned> viota_t; - viota_t iota(pv.nsites()); + viota_t iota(g.v_nmax()); for (unsigned i = 0; i < iota.size(); ++i) iota(i) = 10 + i; - // Create graph image. - mln_const_VAR(ima, (iota | pv)); + typedef edge_image<site_t,unsigned> ima_t; + ima_t ima(g, sites, iota); { // FIXME: Move this part to a special test case. @@ -135,7 +124,10 @@ int main() accu::bbox<point2d> a; mln_piter_(ima_t) p(ima.domain()); for_all(p) - a.take(p); + { + a.take(p.first()); + a.take(p.second()); + } box2d bbox = a.to_result(); mln_assertion(bbox == make::box2d(5, 5)); @@ -161,7 +153,7 @@ int main() // We use the value 9 in debug::graph to represent edges to distinguish it // from vertices holding a value of 1. - debug::draw_graph(ima_rep, pv, 1, 9); + debug::draw_graph(ima_rep, ima.domain(), 1, 9); } /*------------. @@ -174,7 +166,7 @@ int main() for_all(p) mln_assertion(ima(p) == i++); - typedef graph_elt_window<util::graph, fsite_t> win_t; + typedef ima_t::win_t win_t; win_t win; { @@ -205,11 +197,11 @@ int main() } } - typedef graph_elt_neighborhood<util::graph, fsite_t> neighb_t; - neighb_t neigh; + typedef ima_t::nbh_t nbh_t; + nbh_t neigh; { // Neighborhood - Forward iteration - mln_niter_(neighb_t) n(neigh, p); + mln_niter_(nbh_t) n(neigh, p); for_all(p) { @@ -224,7 +216,7 @@ int main() { // Neighborhood - Backward iteration - mln_bkd_niter_(neighb_t) n(neigh, p); + mln_bkd_niter_(nbh_t) n(neigh, p); for_all(p) { i = 0; diff --git a/milena/tests/core/image/graph_image.cc b/milena/tests/core/image/graph_image.cc index e8a71f2..4902fc0 100644 --- a/milena/tests/core/image/graph_image.cc +++ b/milena/tests/core/image/graph_image.cc @@ -174,7 +174,7 @@ int main() for_all(p) mln_assertion(ima(p) == i++); - typedef graph_elt_window<util::graph, fsite_t> win_t; + typedef graph_elt_window<util::graph,S> win_t; win_t win; { @@ -205,7 +205,7 @@ int main() } } - typedef graph_elt_neighborhood<util::graph, fsite_t> neighb_t; + typedef graph_elt_neighborhood<util::graph,S> neighb_t; neighb_t neigh; { // Neighborhood - Forward iteration diff --git a/milena/tests/core/image/line_graph_image.cc b/milena/tests/core/image/line_graph_image.cc index fe660f5..2c11e73 100644 --- a/milena/tests/core/image/line_graph_image.cc +++ b/milena/tests/core/image/line_graph_image.cc @@ -1,4 +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 @@ -25,16 +26,17 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/// \file tests/core/image/graph_image.cc +/// \file tests/core/image/line_graph_image.cc /// -/// Tests on mln::graph_image. +/// Tests on mln::line_graph_image. #include <mln/core/alias/point2d.hh> /// Required for line graph images. #include <mln/core/site_set/p_edges.hh> -#include <mln/core/image/line_graph_elt_window.hh> -#include <mln/core/image/line_graph_elt_neighborhood.hh> +#include <mln/core/image/graph_elt_window.hh> +#include <mln/core/image/graph_elt_neighborhood.hh> +#include <mln/core/image/vertex_image.hh> #include <mln/core/neighb.hh> #include <mln/core/var.hh> #include <mln/pw/all.hh> @@ -57,17 +59,17 @@ // Expected neighbors for forward and backward iteration. -static unsigned expected_fwd_nbh[5][3] = { { 1, 2, -1 }, - { 0, 2, 4 }, - { 0, 1, 3 }, - { 2, 4, -1 }, - { 1, 3, -1 } }; +static unsigned expected_fwd_nbh[5][3] = { { 1, -1, -1 }, + { 0, 2, 3 }, + { 1, 4, -1 }, + { 1, 4, -1 }, + { 3, 2, -1 } }; -static unsigned expected_bkd_nbh[5][3] = { { 2, 1, -1 }, - { 4, 2, 0 }, - { 3, 1, 0 }, - { 4, 2, -1 }, - { 3, 1, -1 } }; +static unsigned expected_bkd_nbh[5][3] = { { 1, 0, -1 }, + { 3, 2, 0 }, + { 4, 1, -1 }, + { 4, 1, -1 }, + { 2, 3, -1 } }; int main() @@ -99,25 +101,19 @@ int main() g.add_edge(3, 4); g.add_edge(4, 2); - /*---------------------------. - | Line graph image support. | - `---------------------------*/ - - typedef p_edges<util::graph, fsite_t> S; - S pe(g, sites); - /*-------------------. | Line graph image. | `-------------------*/ // Graph values. typedef fun::i2v::array<unsigned> viota_t; - viota_t iota(pe.nsites()); - for(unsigned i = 0; i < iota.size(); ++i) + viota_t iota(g.v_nmax()); + for (unsigned i = 0; i < iota.size(); ++i) iota(i) = 10 + i; // Create line graph image. - mln_const_VAR(ima,(iota | pe)); + typedef vertex_image<point2d,unsigned> ima_t; + ima_t ima(g, sites, iota); /*------------. | Iterators. | @@ -132,7 +128,7 @@ int main() for_all(p) mln_assertion(ima(p) == i++); - typedef line_graph_elt_window<util::graph, fsite_t> win_t; + typedef ima_t::win_t win_t; win_t win; { @@ -164,7 +160,7 @@ int main() } - typedef line_graph_elt_neighborhood<util::graph, fsite_t> neighb_t; + typedef ima_t::nbh_t neighb_t; neighb_t neigh; { diff --git a/milena/tests/core/image/graph_image.cc b/milena/tests/core/image/vertex_image.cc similarity index 84% copy from milena/tests/core/image/graph_image.cc copy to milena/tests/core/image/vertex_image.cc index e8a71f2..3531420 100644 --- a/milena/tests/core/image/graph_image.cc +++ b/milena/tests/core/image/vertex_image.cc @@ -1,4 +1,4 @@ -// Copyright(C) 2007, 2008 EPITA Research and Development Laboratory(LRDE) +// 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 @@ -25,18 +25,14 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/// \file tests/core/image/graph_image.cc +/// \file tests/core/image/vertex_image.cc /// -/// Tests on mln::graph_image. +/// Tests on mln::vertex_image. #include <vector> -#include <mln/core/site_set/p_vertices.hh> -#include <mln/core/image/graph_elt_window.hh> -#include <mln/core/image/graph_elt_neighborhood.hh> -#include <mln/core/concept/function.hh> -#include <mln/core/neighb.hh> -#include <mln/core/var.hh> +#include <mln/core/image/vertex_image.hh> +#include <mln/core/image/image2d.hh> #include <mln/accu/bbox.hh> @@ -45,7 +41,6 @@ #include <mln/util/graph.hh> #include <mln/debug/draw_graph.hh> -#include <mln/debug/println.hh> /* The graph is as follows: @@ -108,25 +103,18 @@ int main() //g.print_debug(std::cout); - /*----------------------. - | Graph image support. | - `----------------------*/ - - typedef p_vertices<util::graph, fsite_t> S; - S pv(g, sites); - /*-------------. | Graph image. | `-------------*/ // Graph values. typedef fun::i2v::array<unsigned> viota_t; - viota_t iota(pv.nsites()); + viota_t iota(g.v_nmax()); for (unsigned i = 0; i < iota.size(); ++i) iota(i) = 10 + i; - // Create graph image. - mln_const_VAR(ima, (iota | pv)); + typedef vertex_image<point2d,unsigned> ima_t; + ima_t ima(g, sites, iota); { // FIXME: Move this part to a special test case. @@ -161,7 +149,7 @@ int main() // We use the value 9 in debug::graph to represent edges to distinguish it // from vertices holding a value of 1. - debug::draw_graph(ima_rep, pv, 1, 9); + debug::draw_graph(ima_rep, ima.domain(), 1, 9); } /*------------. @@ -174,7 +162,7 @@ int main() for_all(p) mln_assertion(ima(p) == i++); - typedef graph_elt_window<util::graph, fsite_t> win_t; + typedef ima_t::win_t win_t; win_t win; { @@ -205,11 +193,11 @@ int main() } } - typedef graph_elt_neighborhood<util::graph, fsite_t> neighb_t; - neighb_t neigh; + typedef ima_t::nbh_t nbh_t; + nbh_t neigh; { // Neighborhood - Forward iteration - mln_niter_(neighb_t) n(neigh, p); + mln_niter_(nbh_t) n(neigh, p); for_all(p) { @@ -224,7 +212,7 @@ int main() { // Neighborhood - Backward iteration - mln_bkd_niter_(neighb_t) n(neigh, p); + mln_bkd_niter_(nbh_t) n(neigh, p); for_all(p) { i = 0; diff --git a/milena/tests/core/site_set/p_edges.cc b/milena/tests/core/site_set/p_edges.cc index 42e0da0..281e70c 100644 --- a/milena/tests/core/site_set/p_edges.cc +++ b/milena/tests/core/site_set/p_edges.cc @@ -1,4 +1,4 @@ -// 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 @@ -38,7 +38,7 @@ // Function mapping an edge to a specific site. template <typename G> -struct my_fun +struct my_fun : mln::Function< my_fun<G> > { typedef mln::point2d result; diff --git a/milena/tests/morpho/artificial_line_graph_image_wst.cc b/milena/tests/morpho/artificial_line_graph_image_wst.cc index 65a31e6..7574c9c 100644 --- a/milena/tests/morpho/artificial_line_graph_image_wst.cc +++ b/milena/tests/morpho/artificial_line_graph_image_wst.cc @@ -54,9 +54,7 @@ #include <mln/core/alias/neighb2d.hh> /// Required for line graph images. -#include <mln/core/site_set/p_edges.hh> -#include <mln/core/image/line_graph_elt_neighborhood.hh> -#include <mln/core/var.hh> +#include <mln/core/image/edge_image.hh> #include <mln/pw/all.hh> #include <mln/fun/i2v/array.hh> #include <mln/util/graph.hh> @@ -117,20 +115,18 @@ int main() `----------------*/ // Line graph image. - typedef pw::image<fun::i2v::array<input_val_t>, p_edges<util::graph, - fun::i2v::array< util::site_pair<point2d> > > > lg_ima_t; + typedef edge_image<util::site_pair<point2d>, input_val_t, util::graph> lg_ima_t; lg_ima_t lg_ima = morpho::line_gradient(input); /*------. | WST. | `------*/ - typedef line_graph_elt_neighborhood<util::graph, lg_ima_t::pset::fun_t> nbh_t; + typedef lg_ima_t::nbh_t nbh_t; nbh_t nbh; // Perform a Watershed Transform. - typedef pw::image<fun::i2v::array<unsigned>, p_edges<util::graph, - fun::i2v::array< util::site_pair<point2d> > > > wshed_t; + typedef edge_image<util::site_pair<point2d>, unsigned, util::graph> wshed_t; unsigned nbasins; wshed_t wshed = morpho::meyer_wst(lg_ima, nbh, nbasins); mln_assertion(nbasins == 1155); diff --git a/milena/tests/morpho/graph_image_morpho.cc b/milena/tests/morpho/graph_image_morpho.cc index 04c18ad..35b3045 100644 --- a/milena/tests/morpho/graph_image_morpho.cc +++ b/milena/tests/morpho/graph_image_morpho.cc @@ -1,4 +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 @@ -37,10 +38,8 @@ #include <mln/morpho/erosion.hh> /// Required for graph images. -#include <mln/core/site_set/p_vertices.hh> -#include <mln/core/image/graph_elt_window.hh> +#include <mln/core/image/vertex_image.hh> #include <mln/core/var.hh> -#include <mln/pw/all.hh> #include <mln/fun/i2v/array.hh> #include <mln/util/graph.hh> @@ -93,25 +92,18 @@ int main() g.add_edge(4, 2); - /*----------------------. - | Graph image support. | - `----------------------*/ - - typedef p_vertices<util::graph, fsite_t> pv_t; - pv_t pv(g, sites); - /*--------------. | Graph image. | `--------------*/ // Graph values. typedef fun::i2v::array<unsigned> viota_t; - viota_t iota(pv.nsites()); + viota_t iota(g.v_nmax()); for (unsigned i = 0; i < iota.size(); ++i) iota(i) = 10 + i; - // Create graph image. - mln_const_VAR(ima, (iota | pv)); + typedef vertex_image<point2d,unsigned,util::graph> ima_t; + ima_t ima(g, sites, iota); /*-------------------------------------. | Image representation/visualization. | @@ -148,7 +140,8 @@ int main() | Processing graph images. | `--------------------------*/ - graph_elt_window<util::graph, fsite_t> win; + + ima_t::win_t win; mln_const_VAR(ima_dil, morpho::dilation(ima, win)); debug::draw_graph(ima_rep, ima_dil.domain(), pw::cst(9), pw::cst(2)); diff --git a/milena/tests/morpho/graph_image_wst.cc b/milena/tests/morpho/graph_image_wst.cc index caecece..7eb1c24 100644 --- a/milena/tests/morpho/graph_image_wst.cc +++ b/milena/tests/morpho/graph_image_wst.cc @@ -1,4 +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 @@ -33,10 +34,8 @@ #include <mln/core/alias/point2d.hh> /// Required for graph images. -#include <mln/core/site_set/p_vertices.hh> -#include <mln/core/image/graph_elt_neighborhood.hh> +#include <mln/core/image/vertex_image.hh> #include <mln/core/var.hh> -#include <mln/pw/all.hh> #include <mln/fun/i2v/array.hh> #include <mln/util/graph.hh> @@ -86,32 +85,24 @@ int main() g.add_edge(3, 4); g.add_edge(4, 2); - - /*----------------------. - | Graph image support. | - `----------------------*/ - - typedef p_vertices<util::graph, fsite_t> pv_t; - pv_t pv(g, sites); - /*-------------. | Graph image. | `-------------*/ // Graph values. typedef fun::i2v::array<unsigned> viota_t; - viota_t iota(pv.nsites()); + viota_t iota(g.v_nmax()); for (unsigned i = 0; i < iota.size(); ++i) iota(i) = 10 + i; - // Create graph image. - mln_const_VAR(ima, (iota | pv)); + typedef vertex_image<point2d,unsigned,util::graph> ima_t; + ima_t ima(g,sites,iota); /*------. | WST. | `------*/ - typedef graph_elt_neighborhood<util::graph, fsite_t> nbh_t; + typedef ima_t::nbh_t nbh_t; nbh_t nbh; unsigned nbasins; diff --git a/milena/tests/morpho/lena_line_graph_image_wst1.cc b/milena/tests/morpho/lena_line_graph_image_wst1.cc index 142bdad..72bd8bb 100644 --- a/milena/tests/morpho/lena_line_graph_image_wst1.cc +++ b/milena/tests/morpho/lena_line_graph_image_wst1.cc @@ -60,10 +60,8 @@ #include <mln/convert/to_window.hh> /// Required for line graph images. -#include <mln/core/site_set/p_edges.hh> -#include <mln/core/image/line_graph_elt_neighborhood.hh> +#include <mln/core/image/edge_image.hh> #include <mln/core/var.hh> -#include <mln/pw/all.hh> #include <mln/fun/i2v/array.hh> #include <mln/util/graph.hh> @@ -146,24 +144,19 @@ int main() } // Line graph point set. - typedef p_edges<util::graph, edge_sites_t> pe_t; - pe_t pe(g, edge_sites); - - // Line graph image - typedef pw::image<edge_values_t, pe_t> lg_ima_t; - lg_ima_t lg_ima = (edge_values | pe); + typedef edge_image<util::site_pair<point2d>,int,util::graph> lg_ima_t; + lg_ima_t lg_ima(g, edge_sites, edge_values); /*------. | WST. | `------*/ - typedef line_graph_elt_neighborhood<util::graph, edge_sites_t> nbh_t; + typedef lg_ima_t::nbh_t nbh_t; nbh_t nbh; // Perform a Watershed Transform. int_u8 nbasins; - typedef pw::image<fun::i2v::array<int_u8>, p_edges<util::graph, - fun::i2v::array< util::site_pair<point2d> > > > wshed_t; + typedef edge_image<util::site_pair<point2d>,int_u8,util::graph> wshed_t; wshed_t wshed = morpho::meyer_wst(lg_ima, nbh, nbasins); mln_assertion(nbasins == 5); diff --git a/milena/tests/morpho/lena_line_graph_image_wst2.cc b/milena/tests/morpho/lena_line_graph_image_wst2.cc index 6922a83..c409346 100644 --- a/milena/tests/morpho/lena_line_graph_image_wst2.cc +++ b/milena/tests/morpho/lena_line_graph_image_wst2.cc @@ -56,10 +56,8 @@ #include <mln/core/alias/neighb2d.hh> /// Required for line graph images. -#include <mln/core/site_set/p_edges.hh> -#include <mln/core/image/line_graph_elt_neighborhood.hh> +#include <mln/core/image/edge_image.hh> #include <mln/core/var.hh> -#include <mln/pw/all.hh> #include <mln/fun/i2v/array.hh> #include <mln/util/graph.hh> @@ -104,15 +102,14 @@ int main() `----------------*/ // Line graph image. - typedef pw::image<fun::i2v::array<input_val_t>, p_edges<util::graph, - fun::i2v::array< util::site_pair<point2d> > > > lg_ima_t; + typedef edge_image<util::site_pair<point2d>,input_val_t,util::graph> lg_ima_t; lg_ima_t lg_ima = morpho::line_gradient(input); /*-----------------. | Simplification. | `-----------------*/ - typedef line_graph_elt_neighborhood<util::graph, lg_ima_t::pset::fun_t> nbh_t; + typedef lg_ima_t::nbh_t nbh_t; nbh_t nbh; lg_ima_t closed_lg_ima = morpho::closing::area_on_vertices(lg_ima, nbh, 20); @@ -123,8 +120,7 @@ int main() // Perform a Watershed Transform. unsigned nbasins; - typedef pw::image<fun::i2v::array<unsigned>, p_edges<util::graph, - fun::i2v::array< util::site_pair<point2d> > > > wshed_t; + typedef edge_image<util::site_pair<point2d>,unsigned,util::graph> wshed_t; wshed_t wshed = morpho::meyer_wst(closed_lg_ima, nbh, nbasins); mln_assertion(nbasins == 46); diff --git a/milena/tests/morpho/line_graph_image_morpho.cc b/milena/tests/morpho/line_graph_image_morpho.cc index 2b32421..3a5becb 100644 --- a/milena/tests/morpho/line_graph_image_morpho.cc +++ b/milena/tests/morpho/line_graph_image_morpho.cc @@ -1,4 +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 @@ -32,16 +33,17 @@ #include <mln/core/alias/point2d.hh> /// Required for line graph images. -#include <mln/core/site_set/p_edges.hh> -#include <mln/core/image/line_graph_elt_window.hh> -#include <mln/core/var.hh> -#include <mln/pw/all.hh> +#include <mln/core/image/vertex_image.hh> #include <mln/fun/i2v/array.hh> +#include <mln/util/line_graph.hh> #include <mln/util/graph.hh> +#include <mln/util/site_pair.hh> #include <mln/morpho/erosion.hh> #include <mln/morpho/dilation.hh> +static const unsigned dil_ref[] = { 12, 14, 13, 14, 13 }; +static const unsigned ero_ref[] = { 11, 10, 10, 12, 11 }; int main() { @@ -67,17 +69,8 @@ int main() // Graph. util::graph g; - // Points associated to vertices. - typedef fun::i2v::array<point2d> fsite_t; - fsite_t sites(5); - sites(0) = point2d(0,0); // Point associated to vertex 0. - sites(1) = point2d(2,2); // Point associated to vertex 1. - sites(2) = point2d(0,4); // Point associated to vertex 2. - sites(3) = point2d(4,3); // Point associated to vertex 3. - sites(4) = point2d(4,4); // Point associated to vertex 4. - // Populate the graph with vertices. - g.add_vertices(sites.size()); + g.add_vertices(5); // Populate the graph with edges. g.add_edge(0, 1); @@ -86,13 +79,19 @@ int main() g.add_edge(3, 4); g.add_edge(4, 2); + /// Create the corresponding line graph. + /// Edges are now considered as vertices. + util::line_graph<util::graph> lg(g); - /*---------------------------. - | Line graph image support. | - `---------------------------*/ - - typedef p_edges<util::graph, fsite_t> pe_t; - pe_t pe(g, sites); + // Points associated to the line graph vertices (edges in the graph). + typedef util::site_pair<point2d> P; + typedef fun::i2v::array<P> fsite_t; + fsite_t sites(5); + sites(0) = P(point2d(0,0), point2d(2,2)); // Site associated to vertex 0. + sites(1) = P(point2d(2,2), point2d(0,4)); // Site associated to vertex 1. + sites(2) = P(point2d(2,2), point2d(4,3)); // Site associated to vertex 2. + sites(3) = P(point2d(4,3), point2d(4,4)); // Site associated to vertex 3. + sites(4) = P(point2d(0,4), point2d(4,4)); // Site associated to vertex 4. /*-------------------. | Line graph image. | @@ -100,30 +99,31 @@ int main() // Line graph values. typedef fun::i2v::array<unsigned> viota_t; - viota_t iota(pe.nsites()); + viota_t iota(lg.v_nmax()); for (unsigned i = 0; i < iota.size(); ++i) iota(i) = 10 + i; - // Create line graph image. - mln_const_VAR(ima, (iota | pe)); + typedef vertex_image<P,unsigned,util::line_graph<util::graph> > ima_t; + ima_t ima(lg, sites, iota); /*-------------------------------. | Processing line graph images. | `-------------------------------*/ - line_graph_elt_window<util::graph, fsite_t> win; + ima_t::win_t win; + unsigned i = 0; - mln_const_VAR(ima_dil, morpho::dilation(ima, win)); + ima_t ima_dil = morpho::dilation(ima, win); // Manual iteration over the domain of IMA_DIL. - mln_piter_(ima_dil_t) p_dil(ima_dil.domain()); + mln_piter_(ima_t) p_dil(ima_dil.domain()); for_all (p_dil) - std::cout << "ima_dil (" << p_dil << ") = " << ima_dil(p_dil) << std::endl; - std::cout << std::endl; + mln_assertion(dil_ref[i++] == ima_dil(p_dil)); - mln_const_VAR(ima_ero, morpho::erosion(ima, win)); + ima_t ima_ero = morpho::erosion(ima, win); // Manual iteration over the domain of IMA_ERO. - mln_piter_(ima_ero_t) p_ero(ima_ero.domain()); + mln_piter_(ima_t) p_ero(ima_ero.domain()); + i = 0; for_all (p_ero) - std::cout << "ima_ero (" << p_ero << ") = " << ima_ero(p_ero) << std::endl; + mln_assertion(ero_ref[i++] == ima_ero(p_ero)); } diff --git a/milena/tests/morpho/line_graph_image_wst.cc b/milena/tests/morpho/line_graph_image_wst.cc index 73afbda..6df2052 100644 --- a/milena/tests/morpho/line_graph_image_wst.cc +++ b/milena/tests/morpho/line_graph_image_wst.cc @@ -1,4 +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 @@ -32,16 +33,17 @@ #include <mln/core/alias/point2d.hh> /// Required for line graph images. -#include <mln/core/site_set/p_edges.hh> -#include <mln/core/image/line_graph_elt_neighborhood.hh> -#include <mln/core/var.hh> +#include <mln/core/image/vertex_image.hh> #include <mln/pw/all.hh> #include <mln/fun/i2v/array.hh> #include <mln/util/graph.hh> +#include <mln/util/line_graph.hh> #include <mln/util/site_pair.hh> -#include <mln/morpho/meyer_wst.hh> +#include <mln/morpho/watershed/flooding.hh> +static const unsigned ima_ref[] = { 0, 10, 5, 2, 4, 6, 0, 3, 5, 2 }; +static const unsigned ima_wst[] = { 2, 0, 1, 2, 2, 1, 1, 2, 0, 1 }; int main() { @@ -68,20 +70,8 @@ int main() foward order. */ util::graph g; - // Sites associated to vertices. - typedef fun::i2v::array<point2d> fsite_t; - fsite_t sites(8); - sites(0) = point2d(0,0); // Point associated to vertex 0. - sites(1) = point2d(0,1); // Point associated to vertex 1. - sites(2) = point2d(0,2); // Point associated to vertex 2. - sites(3) = point2d(0,3); // Point associated to vertex 3. - sites(4) = point2d(1,0); // Point associated to vertex 4. - sites(5) = point2d(1,1); // Point associated to vertex 5. - sites(6) = point2d(1,2); // Point associated to vertex 6. - sites(7) = point2d(1,3); // Point associated to vertex 7. - // Populate the graph with vertices. - g.add_vertices(sites.size()); + g.add_vertices(8); // Populate the graph with edges. g.add_edge(0, 1); @@ -97,47 +87,56 @@ int main() g.add_edge(5, 6); g.add_edge(6, 7); - // Associate edges to sites. - typedef fun::i2v::array< util::site_pair<point2d> > edge_sites_t; - edge_sites_t edge_sites(g.e_nmax()); - mln_edge_iter_(util::graph) e(g); - for_all(e) - edge_sites(e) = util::site_pair<point2d>(sites(e.v1()), sites(e.v2())); + util::line_graph<util::graph> lg(g); - typedef p_edges<util::graph, edge_sites_t> pe_t; - pe_t pe(g, edge_sites); + // Sites associated to vertices. + typedef util::site_pair<point2d> P; + typedef fun::i2v::array<P> fsite_t; + fsite_t sites(10); + sites(0) = P(point2d(0,0), point2d(0,1)); // Site associated to vertex 0. + sites(1) = P(point2d(0,1), point2d(0,2)); // Site associated to vertex 1. + sites(2) = P(point2d(0,2), point2d(0,3)); // Site associated to vertex 2. + sites(3) = P(point2d(0,0), point2d(1,0)); // Site associated to vertex 7. + sites(4) = P(point2d(0,1), point2d(1,1)); // Site associated to vertex 8. + sites(5) = P(point2d(0,2), point2d(1,2)); // Site associated to vertex 9. + sites(6) = P(point2d(0,3), point2d(1,3)); // Site associated to vertex 3. + sites(7) = P(point2d(1,0), point2d(1,1)); // Site associated to vertex 4. + sites(8) = P(point2d(1,1), point2d(1,2)); // Site associated to vertex 5. + sites(9) = P(point2d(1,2), point2d(1,3)); // Site associated to vertex 6. // Edge values. typedef fun::i2v::array<int> edge_values_t; - edge_values_t edge_values(pe.nsites()); + edge_values_t edge_values(10); static const int values[] = { 0, 10, 5, 2, 4, 6, 0, 3, 5, 2 }; for (unsigned i = 0; i < edge_values.size(); ++i) edge_values(i) = values[i]; - // Create line graph image. - mln_const_VAR(ima,(edge_values | pe)); + typedef vertex_image< P, int, util::line_graph<util::graph> > ima_t; + ima_t ima(lg, sites, edge_values); /*------------. | Iterators. | `------------*/ + unsigned i = 0; + // Manual iteration over the domain of IMA. mln_piter_(ima_t) p(ima.domain()); for_all (p) - std::cout << "ima (" << p << ") = " << ima(p) << std::endl; - std::cout << std::endl; + mln_assertion(ima_ref[i++] == ima(p)); - typedef line_graph_elt_neighborhood<util::graph, edge_sites_t> nbh_t; + typedef ima_t::nbh_t nbh_t; nbh_t nbh; - unsigned nbasins; - mln_const_VAR(wshed, morpho::meyer_wst(ima, nbh, nbasins)); - std::cout << "nbasins = " << nbasins << std::endl; + typedef mln_ch_value_(ima_t,unsigned) wshed_t; + wshed_t wshed = morpho::watershed::flooding(ima, nbh, nbasins); + mln_assertion(nbasins == 2); + i = 0; // Manual iteration over the domain of WSHED. mln_piter_(wshed_t) pw(wshed.domain()); for_all (pw) - std::cout << "wshed (" << pw << ") = " << wshed(pw) << std::endl; + mln_assertion(ima_wst[i++] == wshed(pw)); } diff --git a/milena/tests/util/graph.cc b/milena/tests/util/graph.cc index 60a609a..d832023 100644 --- a/milena/tests/util/graph.cc +++ b/milena/tests/util/graph.cc @@ -37,12 +37,7 @@ int main () util::graph g; - g.add_vertex (); // 0 - g.add_vertex (); // 1 - g.add_vertex (); // 2 - g.add_vertex (); // 3 - g.add_vertex (); // 4 - g.add_vertex (); // 5 + g.add_vertices(6); g.add_edge (0, 1); g.add_edge (0, 2); g.add_edge (3, 4); -- 1.5.6.5