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