$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
from_graph.hh
1 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef SCRIBO_PRIMITIVE_GROUP_FROM_GRAPH_HH
28 # define SCRIBO_PRIMITIVE_GROUP_FROM_GRAPH_HH
29 
33 
34 
35 # include <mln/core/concept/graph.hh>
36 # include <mln/core/concept/image.hh>
37 # include <mln/core/site_set/box.hh>
38 
39 # include <mln/canvas/browsing/depth_first_search.hh>
40 
41 # include <mln/accu/shape/bbox.hh>
42 
43 # include <mln/pw/all.hh>
44 
45 # include <mln/fun/i2v/array.hh>
46 
47 # include <mln/util/array.hh>
48 # include <mln/util/graph_ids.hh>
49 
50 # include <scribo/core/object_links.hh>
51 # include <scribo/core/object_groups.hh>
52 # include <scribo/core/macros.hh>
53 
54 
55 namespace scribo
56 {
57 
58  namespace primitive
59  {
60 
61  namespace group
62  {
63 
64  using namespace mln;
65 
72  //
73  template <typename L, typename G>
74  object_groups<L>
75  from_graph(const component_set<L>& comps,
76  const Graph<G>& g_);
77 
78 
79 # ifndef MLN_INCLUDE_ONLY
80 
81 
82  namespace internal
83  {
84 
87  template <typename L>
88  struct map_vertex_to_representative_id_functor
89  {
90 
91  map_vertex_to_representative_id_functor(const component_set<L>& comps)
92  : vertextorep(comps)
93  {
94  }
95 
97  template <typename G>
98  void init(const Graph<G>& g)
99  {
100  vertextorep.resize(exact(g).v_nmax(), mln_max(mln_value(L)));
101  }
102 
104  void final()
105  {}
106 
108  void next_component()
109  {}
110 
113  void new_component_from_vertex(const mln::util::vertex_id_t& id)
114  {
115  current_ = id;
116  vertextorep(id) = id;
117  }
118 
121  void added_to_queue(const mln::util::vertex_id_t&)
122  {}
123 
125  void process_vertex(const mln::util::vertex_id_t& id)
126  {
127  vertextorep(id) = current_;
128  }
129 
131  bool to_be_treated(const mln::util::vertex_id_t& id)
132  { return vertextorep(id) == mln_max(mln_value(L)); }
133 
135  bool to_be_queued(const mln::util::vertex_id_t& id)
136  { return to_be_treated(id); }
137 
139  mln::util::vertex_id_t current_;
140 
142  object_links<L> vertextorep;
143  };
144 
145  } // end of namespace scribo::primitive::group::internal
146 
147 
148 
149  template <typename L, typename G>
150  inline
151  object_groups<L>
152  from_graph(const component_set<L>& comps,
153  const Graph<G>& g_)
154  {
155  mln_trace("scribo::primitive::group::from_graph");
156 
157  const G& g = exact(g_);
158 
159  mln_assertion(g.is_valid());
160 
161  internal::map_vertex_to_representative_id_functor<L> f(comps);
162  canvas::browsing::depth_first_search(g, f);
163 
164  object_groups<L> groups(comps);
165  groups.init_(f.vertextorep);
166 
167  return groups;
168  }
169 
170 
171 # endif // ! MLN_INCLUDE_ONLY
172 
173  } // end of namespace scribo::primitive::group
174 
175  } // end of namespace scribo::primitive
176 
177 } // end of namespace scribo
178 
179 #endif // ! SCRIBO_PRIMITIVE_GROUP_FROM_GRAPH_HH