$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
influence_zone_adjacency_graph.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_MAKE_INFLUENCE_ZONE_ADJACENCY_GRAPH_HH
27 # define MLN_MAKE_INFLUENCE_ZONE_ADJACENCY_GRAPH_HH
28 
37 
38 # include <mln/core/concept/image.hh>
39 # include <mln/core/concept/neighborhood.hh>
40 # include <mln/core/image/image2d.hh>
41 # include <mln/core/alias/box2d.hh>
42 # include <mln/extension/adjust_fill.hh>
43 # include <mln/util/graph.hh>
44 # include <mln/util/adjacency_matrix.hh>
45 
46 
47 namespace mln
48 {
49 
50  namespace make
51  {
52 
60  //
61  template <typename I, typename N>
62  util::graph
63  influence_zone_adjacency_graph(const Image<I>& iz,
64  const Neighborhood<N>& nbh,
65  const mln_value(I)& nlabels);
66 
67 
68 
69 # ifndef MLN_INCLUDE_ONLY
70 
71 
72  namespace internal
73  {
74 
75  template <typename I, typename N>
76  void
77  influence_zone_adjacency_graph_tests(const Image<I>& iz,
78  const Neighborhood<N>& nbh,
79  const mln_value(I)&)
80  {
81  mln_precondition(exact(iz).is_valid());
82  mln_precondition(exact(nbh).is_valid());
83  (void) iz;
84  (void) nbh;
85  }
86 
87  } // end of namespace mln::make::internal
88 
89 
90  namespace impl
91  {
92 
93  namespace generic
94  {
95 
103  //
104  template <typename I, typename N>
105  util::graph
106  influence_zone_adjacency_graph(const Image<I>& iz_,
107  const Neighborhood<N>& nbh_,
108  const mln_value(I)& nlabels)
109  {
110  mln_trace("make::impl::generic::influence_zone_adjacency_graph");
111 
112  internal::influence_zone_adjacency_graph_tests(iz_, nbh_, nlabels);
113  const I& iz = exact(iz_);
114  const N& nbh = exact(nbh_);
115 
116  util::adjacency_matrix<> adj(nlabels.next());
117  extension::adjust_fill(iz, nbh, 0u);
118 
119  typedef mln_value(I) L;
120  mln_piter(I) p(iz.domain());
121  mln_niter(N) n(nbh, p);
122  for_all(p)
123  {
124  L l1 = iz(p);
125  for_all(n)
126  {
127  if (iz.domain().has(n))
128  {
129  L l2 = iz(n);
130  if (iz(n) != iz((p)))
131  adj.add(l1, l2);
132  }
133  }
134  }
135 
136  // Construct graph.
137  util::graph g;
138  g.add_vertices(nlabels.next());
139  for (unsigned i = 0; i < nlabels.next(); ++i)
140  for (unsigned j = 0; j < i; ++j)
141  if (adj.are_adjacent(i, j))
142  g.add_edge(i, j);
143 
144  return g;
145  }
146 
147  } // end of namespace mln::make::impl::generic
148 
149  } // end of namespace mln::make::impl
150 
151 
152 
153  namespace internal
154  {
155 
156  template <typename I, typename N>
157  util::graph
158  influence_zone_adjacency_graph_dispatch(const Image<I>& iz,
159  const Neighborhood<N>& nbh,
160  const mln_value(I)& nlabels)
161  {
163  }
164 
165  } // end of namespace mln::make::internal
166 
167 
168 
169  // Facade
170 
171  template <typename I, typename N>
172  inline
173  util::graph
174  influence_zone_adjacency_graph(const Image<I>& iz,
175  const Neighborhood<N>& nbh,
176  const mln_value(I)& nlabels)
177  {
178  mln_trace("make::influence_zone_adjacency_graph");
179 
180  internal::influence_zone_adjacency_graph_tests(iz, nbh, nlabels);
181 
182  util::graph g = internal::influence_zone_adjacency_graph_dispatch(iz, nbh, nlabels);
183 
184  return g;
185  }
186 
187 
188 # endif // ! MLN_INCLUDE_ONLY
189 
190 
191  } // end of namespace mln::make
192 
193 } // end of namespace mln
194 
195 
196 #endif // ! MLN_MAKE_INFLUENCE_ZONE_ADJACENCY_GRAPH_HH