$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
breadth_first_thinning.hh
1 // Copyright (C) 2009, 2010, 2011, 2013 EPITA Research and Development
2 // Laboratory (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 MLN_TOPO_SKELETON_BREADTH_FIRST_THINNING_HH
28 # define MLN_TOPO_SKELETON_BREADTH_FIRST_THINNING_HH
29 
41 
42 # include <mln/core/routine/duplicate.hh>
43 
44 # include <mln/core/concept/image.hh>
45 # include <mln/core/concept/neighborhood.hh>
46 
47 # include <mln/core/site_set/p_queue_fast.hh>
48 
49 # include <mln/topo/no_constraint.hh>
50 
51 # include <mln/data/fill.hh>
52 
53 
54 namespace mln
55 {
56 
57  namespace topo
58  {
59 
60  namespace skeleton
61  {
62 
81  template <typename I, typename N, typename F, typename G, typename H>
82  mln_concrete(I)
83  breadth_first_thinning(const Image<I>& input,
84  const Neighborhood<N>& nbh,
85  Function_v2b<F>& is_simple,
86  G& detach,
87  const Function_v2b<H>& constraint);
88 
89 
105  template <typename I, typename N, typename F, typename G>
106  mln_concrete(I)
107  breadth_first_thinning(const Image<I>& input,
108  const Neighborhood<N>& nbh,
109  Function_v2b<F>& is_simple,
110  G& detach);
111 
112 
113 # ifndef MLN_INCLUDE_ONLY
114 
115  template <typename I, typename N, typename F, typename G, typename H>
116  inline
117  mln_concrete(I)
118  breadth_first_thinning(const Image<I>& input_,
119  const Neighborhood<N>& nbh_,
120  Function_v2b<F>& is_simple_,
121  G& detach,
122  const Function_v2b<H>& constraint_)
123  {
124  mln_trace("topo::skeleton::breadth_first_thinning");
125 
126  const I& input = exact(input_);
127  const N& nbh = exact(nbh_);
128  F& is_simple = exact(is_simple_);
129  const H& constraint = exact(constraint_);
130 
131  mln_concrete(I) output = duplicate(input);
132  // Attach the work image to IS_SIMPLE and DETACH.
133  is_simple.set_image(output);
134  detach.set_image(output);
135 
136  // FIFO queue.
137  typedef mln_psite(I) psite;
138  typedef p_queue_fast<psite> queue_t;
139  queue_t queue;
140  // Image showing whether a site has been inserted into the queue.
141  mln_ch_value(I, bool) in_queue;
142  initialize(in_queue, input);
143  data::fill(in_queue, false);
144 
145  // Populate QUEUE with candidate simple points.
146  mln_piter(I) p(output.domain());
147  for_all(p)
148  {
149  if (output(p) && constraint(p) && is_simple(p))
150  {
151  queue.push(p);
152  in_queue(p) = true;
153  }
154  }
155 
156  while (!queue.is_empty())
157  {
158  psite p = queue.pop_front();
159  in_queue(p) = false;
160  if (output(p) && constraint(p) && is_simple(p))
161  {
162  detach(p);
163  mln_niter(N) n(nbh, p);
164  for_all(n)
165  {
166  if (output.domain().has(n)
167  && output(n) && constraint(n) && is_simple(n)
168  && !in_queue(n))
169  {
170  queue.push(n);
171  in_queue(n) = true;
172  }
173  }
174  }
175  }
176 
177  return output;
178  }
179 
180 
181  template <typename I, typename N, typename F, typename G>
182  inline
183  mln_concrete(I)
184  breadth_first_thinning(const Image<I>& input,
185  const Neighborhood<N>& nbh,
186  Function_v2b<F>& is_simple,
187  G& detach)
188  {
189  // mln::topo::no_constraint is a dummy functor always
190  // returning `true'.
191  no_constraint constraint;
192  return breadth_first_thinning(input, nbh, is_simple, detach,
193  constraint);
194  }
195 
196 # endif // MLN_INCLUDE_ONLY
197 
198  } // end of namespace mln::topo::skeleton
199 
200  } // end of namespace mln::topo
201 
202 } // end of namespace mln
203 
204 #endif // ! MLN_TOPO_SKELETON_BREADTH_FIRST_THINNING_HH