Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
compute_in_window.hh
1 // Copyright (C) 2012 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_LABELING_COMPUTE_IN_WINDOW_HH
27 # define MLN_LABELING_COMPUTE_IN_WINDOW_HH
28 
33 
34 # include <mln/accu/image/init.hh>
35 # include <mln/accu/image/to_result.hh>
36 # include <mln/core/concept/meta_accumulator.hh>
37 # include <mln/border/mirror.hh>
38 # include <mln/extension/adjust.hh>
39 # include <mln/value/succ.hh>
40 
41 # include <mln/debug/println_with_border.hh>
42 
43 namespace mln
44 {
45 
46  namespace labeling
47  {
48 
49 
52  template <typename A, typename I, typename L, typename W>
54  compute_in_window(const Accumulator<A>& a, const Image<I>& input,
55  const Image<L>& label, const mln_value(L)& nlabels,
56  const Window<W>& win);
57 
64  template <typename A, typename I, typename L, typename W>
66  compute_in_window(const Meta_Accumulator<A>& a, const Image<I>& input,
67  const Image<L>& label, const mln_value(L)& nlabels,
68  const Window<W>& win);
69 
70 
71 # ifndef MLN_INCLUDE_ONLY
72 
73  namespace internal
74  {
75 
76  template <typename A, typename I, typename L, typename W>
77  void
78  compute_in_window_tests(const Accumulator<A>& a, const Image<I>& input_,
79  const Image<L>& label_, const mln_value(L)& nlabels,
80  const Window<W>& win_)
81  {
82  (void) a;
83  (void) nlabels;
84  const W& win = exact(win_);
85  const I& input = exact(input_);
86  const L& label = exact(label_);
87 
88  mln_assertion(win.is_valid());
89  mln_assertion(input.is_valid());
90  mln_assertion(label.is_valid());
91  }
92 
93  } // end of namespace mln::labeling::internal
94 
95 
96  namespace impl
97  {
98 
99  namespace generic
100  {
101 
102  template <typename A, typename I, typename L, typename W>
104  compute_in_window(const Accumulator<A>& a_, const Image<I>& input_,
105  const Image<L>& label_, const mln_value(L)& nlabels,
106  const Window<W>& win_)
107  {
108  trace::entering("mln::impl::generic::compute_in_window");
109 
110  const I& input = exact(input_);
111  const L& label = exact(label_);
112  const W& win = exact(win_);
113 
114  internal::compute_in_window_tests(a_, input, label, nlabels, win);
115 
116  mln::util::array<A> accu(value::succ(nlabels), exact(a_));
117 
118  mln_piter(I) p(input.domain());
119  mln_qiter(W) q(win, p);
120 
121  for_all(p)
122  for_all(q)
123  if (input.domain().has(q))
124  accu[label(p)].take(input(q));
125 
126  mln::util::array<mln_result(A)> output;
127  convert::from_to(accu, output);
128 
129  trace::exiting("mln::impl::generic::compute_in_window");
130  return output;
131  }
132 
133  } // end of namespace mln::impl::generic
134 
135  } // end of namespace mln::labeling::impl
136 
137 
138  // Dispatch
139 
140  namespace internal
141  {
142 
143  template <typename A, typename I, typename L, typename W>
145  compute_in_window_dispatch(const Accumulator<A>& a, const Image<I>& input,
146  const Image<L>& label, const mln_value(L)& nlabels,
147  const Window<W>& win,
148  trait::image::speed::any)
149  {
150  return impl::generic::compute_in_window(a, input, label, nlabels, win);
151  }
152 
153  template <typename A, typename I, typename L, typename W>
155  compute_in_window_dispatch(const Accumulator<A>& a, const Image<I>& input,
156  const Image<L>& label, const mln_value(L)& nlabels,
157  const Window<W>& win)
158  {
159  return compute_in_window_dispatch(a, input, label, nlabels, win,
160  mln_trait_image_speed(I)());
161  }
162 
163  } // end of namespace mln::labeling::internal
164 
165 
166 
167  // Facades.
168 
169  template <typename A, typename I, typename L, typename W>
171  compute_in_window(const Accumulator<A>& a, const Image<I>& input,
172  const Image<L>& label, const mln_value(L)& nlabels,
173  const Window<W>& win)
174  {
175  trace::entering("labeling::compute_in_window");
176 
177  internal::compute_in_window_tests(a, input, win);
178 
179  mln_ch_value(I, mln_result(A))
180  output = labeling::internal::compute_in_window_dispatch(a, input, win);
181 
182  trace::exiting("labeling::compute_in_window");
183  return output;
184  }
185 
186 
187  template <typename A, typename I, typename L, typename W>
189  compute_in_window(const Meta_Accumulator<A>& a, const Image<I>& input,
190  const Image<L>& label, const mln_value(L)& nlabels,
191  const Window<W>& win)
192  {
193  typedef mln_accu_with(A, mln_value(I)) A_;
194  A_ a_ = accu::unmeta(exact(a), mln_value(I)());
195 
196  return labeling::compute_in_window(a_, input, label, nlabels, win);
197  }
198 
199 # endif // ! MLN_INCLUDE_ONLY
200 
201  } // end of namespace mln::labeling
202 
203 } // end of namespace mln
204 
205 
206 #endif // ! MLN_LABELING_COMPUTE_IN_WINDOW_HH