3661: Add small routines to help while constructing graph images.

* mln/make/dummy_p_edges.hh, * mln/make/dummy_p_vertices.hh: create graph site sets without localization. * mln/make/all.hh: update includes. * mln/make/graph.hh: rename as... * mln/make/influence_zone_adjacency_graph.hh: ...this. * mln/make/p_edges_with_mass_centers.hh, * mln/make/p_vertices_with_mass_centers.hh: new routines to construct common graph site sets. --- milena/ChangeLog | 17 +++ milena/mln/make/all.hh | 5 +- milena/mln/make/dummy_p_edges.hh | 107 +++++++++++++++++ milena/mln/make/dummy_p_vertices.hh | 107 +++++++++++++++++ ...{graph.hh => influence_zone_adjacency_graph.hh} | 0 milena/mln/make/p_edges_with_mass_centers.hh | 121 ++++++++++++++++++++ milena/mln/make/p_vertices_with_mass_centers.hh | 111 ++++++++++++++++++ 7 files changed, 467 insertions(+), 1 deletions(-) create mode 100644 milena/mln/make/dummy_p_edges.hh create mode 100644 milena/mln/make/dummy_p_vertices.hh rename milena/mln/make/{graph.hh => influence_zone_adjacency_graph.hh} (100%) create mode 100644 milena/mln/make/p_edges_with_mass_centers.hh create mode 100644 milena/mln/make/p_vertices_with_mass_centers.hh diff --git a/milena/ChangeLog b/milena/ChangeLog index 7f69bb3..0b743d3 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,20 @@ +2009-04-14 Guillaume Lazzara <lazzara@lrde.epita.fr> + + Add small routines to help while constructing graph images. + + * mln/make/dummy_p_edges.hh, + * mln/make/dummy_p_vertices.hh: create graph site sets without + localization. + + * mln/make/all.hh: update includes. + + * mln/make/graph.hh: rename as... + * mln/make/influence_zone_adjacency_graph.hh: ...this. + + * mln/make/p_edges_with_mass_centers.hh, + * mln/make/p_vertices_with_mass_centers.hh: new routines to construct + common graph site sets. + 2009-04-09 Guillaume Lazzara <lazzara@lrde.epita.fr> Make util::array a Function_i2v. diff --git a/milena/mln/make/all.hh b/milena/mln/make/all.hh index 9665f14..52571ca 100644 --- a/milena/mln/make/all.hh +++ b/milena/mln/make/all.hh @@ -48,7 +48,6 @@ namespace mln # include <mln/make/box3d.hh> # include <mln/make/dpoint2d_h.hh> # include <mln/make/dual_neighb.hh> -# include <mln/make/graph.hh> # include <mln/make/image.hh> # include <mln/make/image2d.hh> # include <mln/make/image3d.hh> @@ -68,4 +67,8 @@ namespace mln # include <mln/make/w_window_directional.hh> # include <mln/make/win_chamfer.hh> +# include <mln/make/influence_zone_adjacency_graph.hh> +# include <mln/make/region_adjacency_graph.hh> +# include <mln/make/rag_and_labeled_wsl.hh> + #endif // ! MLN_MAKE_ALL_HH diff --git a/milena/mln/make/dummy_p_edges.hh b/milena/mln/make/dummy_p_edges.hh new file mode 100644 index 0000000..927d0d8 --- /dev/null +++ b/milena/mln/make/dummy_p_edges.hh @@ -0,0 +1,107 @@ +// 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. +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_MAKE_DUMMY_P_EDGES_HH +# define MLN_MAKE_DUMMY_P_EDGES_HH + +/// \file mln/make/dummy_p_edges.hh +/// +/// Create a p_edges which associate a graph element to a constant site. +/// +/// \sa edge_image, p_edges + + +# include <mln/core/concept/graph.hh> +# include <mln/core/site_set/p_edges.hh> +# include <mln/pw/cst.hh> + + +namespace mln +{ + + namespace make + { + + + /// Create a p_edges which associate a graph element to a constant site. + /// + /// \param[in] g_ A graph. + /// \param[in] dummy_site The dummy site mapped to graph edges. + /// + /// \return A p_edges. + // + template <typename G, typename P> + p_edges< G, pw::cst_<P> > + dummy_p_edges(const Graph<G>& g_, const P& dummy_site); + + + /// Create a p_edges which associate a graph element to a constant site. + /// \c 0 (int) is used as dummy site. + /// + /// \param[in] g_ A graph. + /// + /// \return A p_edges. + // + template <typename G> + p_edges< G, pw::cst_<int> > + dummy_p_edges(const Graph<G>& g); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename G, typename P> + p_edges<G,pw::cst_<P> > + dummy_p_edges(const Graph<G>& g_, const P& dummy_site) + { + trace::entering("dummy_p_edges"); + + const G& g = exact(g_); + mln_precondition(g.is_valid()); + + p_edges< G, pw::cst_<P> > pe(g, pw::cst(dummy_site)); + + trace::exiting("dummy_p_edges"); + return pe; + } + + + template <typename G> + p_edges< G, pw::cst_<int> > + dummy_p_edges(const Graph<G>& g) + { + return dummy_p_edges(g, 0); + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + +#endif // ! MLN_MAKE_DUMMY_P_EDGES_HH diff --git a/milena/mln/make/dummy_p_vertices.hh b/milena/mln/make/dummy_p_vertices.hh new file mode 100644 index 0000000..910d02e --- /dev/null +++ b/milena/mln/make/dummy_p_vertices.hh @@ -0,0 +1,107 @@ +// 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. +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_MAKE_DUMMY_P_VERTICES_HH +# define MLN_MAKE_DUMMY_P_VERTICES_HH + +/// \file mln/make/dummy_p_vertices.hh +/// +/// Create a p_vertices which associate a graph element to a constant site. +/// +/// \sa edge_image, p_vertices + + +# include <mln/core/concept/graph.hh> +# include <mln/core/site_set/p_vertices.hh> +# include <mln/pw/cst.hh> + + +namespace mln +{ + + namespace make + { + + + /// Create a p_vertices which associate a graph element to a constant site. + /// + /// \param[in] g_ A graph. + /// \param[in] dummy_site The dummy site mapped to graph vertices. + /// + /// \return A p_vertices. + // + template <typename G, typename P> + p_vertices< G, pw::cst_<P> > + dummy_p_vertices(const Graph<G>& g_, const P& dummy_site); + + + /// Create a p_vertices which associate a graph element to a constant site. + /// \c 0 (int) is used as dummy site. + /// + /// \param[in] g_ A graph. + /// + /// \return A p_vertices. + // + template <typename G> + p_vertices< G, pw::cst_<int> > + dummy_p_vertices(const Graph<G>& g); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename G, typename P> + p_vertices<G,pw::cst_<P> > + dummy_p_vertices(const Graph<G>& g_, const P& dummy_site) + { + trace::entering("dummy_p_vertices"); + + const G& g = exact(g_); + mln_precondition(g.is_valid()); + + p_vertices< G, pw::cst_<P> > pe(g, pw::cst(dummy_site)); + + trace::exiting("dummy_p_vertices"); + return pe; + } + + + template <typename G> + p_vertices< G, pw::cst_<int> > + dummy_p_vertices(const Graph<G>& g) + { + return dummy_p_vertices(g, 0); + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + +#endif // ! MLN_MAKE_DUMMY_P_VERTICES_HH diff --git a/milena/mln/make/graph.hh b/milena/mln/make/influence_zone_adjacency_graph.hh similarity index 100% rename from milena/mln/make/graph.hh rename to milena/mln/make/influence_zone_adjacency_graph.hh diff --git a/milena/mln/make/p_edges_with_mass_centers.hh b/milena/mln/make/p_edges_with_mass_centers.hh new file mode 100644 index 0000000..06a2376 --- /dev/null +++ b/milena/mln/make/p_edges_with_mass_centers.hh @@ -0,0 +1,121 @@ +// 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. +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH +# define MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH + +/// \file mln/make/p_edges_with_mass_centers.hh +/// +/// Construct a p_edges from a watershed image and a region adjacency +/// graph (RAG). Map each graph edge to a pair of mass centers of two +/// adjacent regions. +/// +/// \sa edge_image, p_edges + + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/graph.hh> +# include <mln/core/site_set/p_edges.hh> + +# include <mln/labeling/compute.hh> + +# include <mln/accu/center.hh> + +# include <mln/fun/i2v/array.hh> + +# include <mln/util/site_pair.hh> + + +namespace mln +{ + + namespace make + { + + /// Construct a p_edges from a watershed image and a region adjacency + /// graph (RAG). Map each graph edge to a pair of mass centers of two + /// adjacent regions. + /// + /// \param wst_ A watershed image. + /// \param nbasins The number of basins. + /// \param g_ A region adjacency graph. + /// + /// \return A p_edges. + /// + /// \sa edge_image, p_edges, make::region_adjacency_graph + // + template <typename W, typename G> + inline + p_edges<G, fun::i2v::array<util::site_pair<mln_site(W)> > > + p_edges_with_mass_centers(const Image<W>& wst_, + const mln_value(W)& nbasins, + const Graph<G>& g_); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename W, typename G> + inline + p_edges<G, fun::i2v::array<util::site_pair<mln_site(W)> > > + p_edges_with_mass_centers(const Image<W>& wst_, + const mln_value(W)& nbasins, + const Graph<G>& g_) + { + trace::entering("make::p_edges_with_mass_centers"); + + const W& wst = exact(wst_); + const G& g = exact(g_); + mln_precondition(wst.is_valid()); + mln_precondition(g.is_valid()); + + typedef mln_site(W) P; + + util::array<mln_vec(P)> + mass_centers = labeling::compute(accu::center<P>(), wst, nbasins); + + typedef fun::i2v::array< util::site_pair<P> > edge_sites_t; + edge_sites_t edge_sites(g.e_nmax()); + + mln_edge_iter(G) e(g); + for_all(e) + edge_sites(e.id()) = util::site_pair<P>(mass_centers[e.v1()], + mass_centers[e.v2()]); + + p_edges<G, edge_sites_t> pe(g, edge_sites); + + trace::exiting("make::p_edges_with_mass_centers"); + return pe; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + +#endif // ! MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH diff --git a/milena/mln/make/p_vertices_with_mass_centers.hh b/milena/mln/make/p_vertices_with_mass_centers.hh new file mode 100644 index 0000000..064cdbc --- /dev/null +++ b/milena/mln/make/p_vertices_with_mass_centers.hh @@ -0,0 +1,111 @@ +// 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. +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH +# define MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH + +/// \file mln/make/p_vertices_with_mass_centers.hh +/// +/// Create a p_vertices using region mass centers as vertex site. +/// +/// \sa vertex_image, p_vertices + + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/graph.hh> +# include <mln/core/site_set/p_vertices.hh> + +# include <mln/labeling/compute.hh> + +# include <mln/accu/center.hh> + +# include <mln/fun/i2v/array.hh> + + +namespace mln +{ + + namespace make + { + + /// Construct a p_vertices from a watershed image and a region adjacency + /// graph (RAG). Map each graph vertex to the mass center of its + /// corresponding region. + /// + /// \param wst_ A watershed image. + /// \param nbasins The number of basins. + /// \param g_ A region adjacency graph. + /// + /// \return A p_vertices. + /// + /// \sa edge_image, vertex_image, p_vertices, p_edges, make::region_adjacency_graph + // + template <typename W, typename G> + inline + p_vertices<G, fun::i2v::array<mln_site(W)> > + p_vertices_with_mass_centers(const Image<W>& wst_, + const mln_value(W)& nbasins, + const Graph<G>& g_); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename W, typename G> + inline + p_vertices<G, fun::i2v::array<mln_site(W)> > + p_vertices_with_mass_centers(const Image<W>& wst_, + const mln_value(W)& nbasins, + const Graph<G>& g_) + { + trace::entering("make::p_vertices_with_mass_centers"); + + const W& wst = exact(wst_); + const G& g = exact(g_); + mln_precondition(wst.is_valid()); + mln_precondition(g.is_valid()); + + typedef mln_site(W) P; + typedef fun::i2v::array<P> vertex_sites_t; + + vertex_sites_t vertex_sites; + convert::from_to(labeling::compute(accu::center<P>(), wst, nbasins), + vertex_sites); + + p_vertices<G, vertex_sites_t> pv(g, vertex_sites); + + trace::exiting("make::p_vertices_with_mass_centers"); + return pv; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + +#endif // ! MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara