$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
transform_stop.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_ACCU_TRANSFORM_STOP_HH
27 # define MLN_ACCU_TRANSFORM_STOP_HH
28 
33 
34 # include <mln/core/concept/meta_accumulator.hh>
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/concept/window.hh>
37 # include <mln/extension/adjust.hh>
38 
39 
40 namespace mln
41 {
42 
43  namespace accu
44  {
45 
46  template <typename I, typename A, typename W>
47  mln_ch_value(I, mln_result(A))
48  transform_stop(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win);
49 
50  template <typename I, typename A, typename W>
51  mln_ch_value(I, mln_meta_accu_result(A, mln_value(I)))
52  transform_stop(const Image<I>& input, const Meta_Accumulator<A>& a, const Window<W>& win);
53 
54 
55 
56 # ifndef MLN_INCLUDE_ONLY
57 
58 
59  namespace impl
60  {
61 
62  // Generic version.
63 
64  namespace generic
65  {
66 
67  template <typename I, typename A, typename W>
68  mln_ch_value(I, mln_result(A))
69  transform_stop(const Image<I>& input_,
70  const Accumulator<A>& a_,
71  const Window<W>& win_)
72  {
73  mln_trace("accu::impl::generic::transform_stop");
74 
75  const I& input = exact(input_);
76  const W& win = exact(win_);
77  A a = exact(a_);
78 
79  mln_precondition(input.is_valid());
80  mln_precondition(win.is_valid());
81 
82  extension::adjust(input, win);
83 
84  mln_ch_value(I, mln_result(A)) output;
85  initialize(output, input);
86 
87  mln_piter(I) p(input.domain());
88  mln_qiter(W) q(win, p);
89  for_all(p)
90  {
91  a.init();
92  for_all(q) if (input.has(q))
93  {
94  a.take(input(q));
95  if (a.can_stop())
96  break;
97  }
98  output(p) = a.to_result();
99  }
100 
101  return output;
102  }
103 
104  } // end of namespace mln::accu::impl::generic
105 
106 
107  // Fastest version.
108 
109  template <typename I, typename A, typename W>
110  mln_ch_value(I, mln_result(A))
111  transform_stop_fastest(const Image<I>& input_, const Accumulator<A>& a_, const Window<W>& win_)
112  {
113  mln_trace("accu::impl::transform_stop_fastest");
114 
115  const I& input = exact(input_);
116  const W& win = exact(win_);
117  A a = exact(a_);
118 
119  mln_precondition(input.is_valid());
120  mln_precondition(win.is_valid());
121 
122  extension::adjust(input, win);
123 
124  typedef mln_ch_value(I, mln_result(A)) O;
125  O output;
126  initialize(output, input);
127  mln_pixter(O) o(output);
128 
129  mln_pixter(const I) p(input);
130  mln_qixter(const I, W) q(p, win);
131  for_all_2(p, o)
132  {
133  a.init();
134  for_all(q)
135  {
136  a.take(q.val());
137  if (a.can_stop())
138  break;
139  }
140  o.val() = a.to_result();
141  }
142 
143  return output;
144  }
145 
146 
147  } // end of namespace mln::accu::impl
148 
149 
150  // Dispatch.
151 
152  namespace internal
153  {
154 
155  template <typename I, typename A, typename W>
156  mln_ch_value(I, mln_result(A))
157  transform_stop_dispatch(metal::false_,
158  const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
159  {
160  return impl::generic::transform_stop(input, a, win);
161  }
162 
163  template <typename I, typename A, typename W>
164  mln_ch_value(I, mln_result(A))
165  transform_stop_dispatch(metal::true_,
166  const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
167  {
168  return impl::transform_stop_fastest(input, a, win);
169  }
170 
171  template <typename I, typename A, typename W>
172  mln_ch_value(I, mln_result(A))
173  transform_stop_dispatch(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
174  {
175  return transform_stop_dispatch(mln_is_fastest_IW(I, W)(),
176  input, a, win);
177  }
178 
179  } // end of namespace mln::accu::internal
180 
181 
182  // Facades.
183 
184  template <typename I, typename A, typename W>
185  inline
186  mln_ch_value(I, mln_result(A))
187  transform_stop(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
188  {
189  mln_trace("accu::transform_stop");
190 
191  mln_precondition(exact(input).is_valid());
192  mln_precondition(exact(win).is_valid());
193 
194  mln_ch_value(I, mln_result(A)) output;
195  output = internal::transform_stop_dispatch(input, a, win);
196 
197  return output;
198  }
199 
200  template <typename I, typename A, typename W>
201  mln_ch_value(I, mln_meta_accu_result(A, mln_value(I)))
202  transform_stop(const Image<I>& input, const Meta_Accumulator<A>& a, const Window<W>& win)
203  {
204  mln_trace("accu::transform_stop");
205 
206  mln_precondition(exact(input).is_valid());
207  mln_precondition(exact(win).is_valid());
208 
209  typedef mln_accu_with(A, mln_value(I)) A_;
210  A_ a_ = accu::unmeta(exact(a), mln_value(I)());
211 
212  mln_ch_value(I, mln_result(A_)) output;
213  output = internal::transform_stop_dispatch(input, a_, win);
214 
215  return output;
216  }
217 
218 # endif // ! MLN_INCLUDE_ONLY
219 
220  } // end of namespace mln::accu
221 
222 } // end of namespace mln
223 
224 
225 #endif // ! MLN_ACCU_TRANSFORM_STOP_HH