$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
accu/transform.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_HH
27 # define MLN_ACCU_TRANSFORM_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(const Image<I>& input,
49  const Accumulator<A>& a,
50  const Window<W>& win);
51 
52  template <typename I, typename A, typename W>
53  mln_ch_value(I, mln_meta_accu_result(A, mln_value(I)))
54  transform(const Image<I>& input,
55  const Meta_Accumulator<A>& a,
56  const Window<W>& win);
57 
58 
59 
60 # ifndef MLN_INCLUDE_ONLY
61 
62 
63  namespace impl
64  {
65 
66  // Generic version.
67 
68  namespace generic
69  {
70 
71  template <typename I, typename A, typename W>
72  mln_ch_value(I, mln_result(A))
73  transform(const Image<I>& input_,
74  const Accumulator<A>& a_,
75  const Window<W>& win_)
76  {
77  mln_trace("accu::impl::generic::transform");
78 
79  const I& input = exact(input_);
80  const W& win = exact(win_);
81  A a = exact(a_);
82 
83  mln_precondition(input.is_valid());
84  mln_precondition(win.is_valid());
85 
86  extension::adjust(input, win);
87 
88  mln_ch_value(I, mln_result(A)) output;
89  initialize(output, input);
90 
91  mln_piter(I) p(input.domain());
92  mln_qiter(W) q(win, p);
93  for_all(p)
94  {
95  a.init();
96  for_all(q) if (input.has(q))
97  a.take(input(q));
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_fastest(const Image<I>& input_, const Accumulator<A>& a_, const Window<W>& win_)
112  {
113  mln_trace("accu::impl::transform_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  a.take(q.val());
136  o.val() = a.to_result();
137  }
138 
139  return output;
140  }
141 
142 
143  } // end of namespace mln::accu::impl
144 
145 
146  // Dispatch.
147 
148  namespace internal
149  {
150 
151  template <typename I, typename A, typename W>
152  mln_ch_value(I, mln_result(A))
153  transform_dispatch(metal::false_,
154  const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
155  {
156  return impl::generic::transform(input, a, win);
157  }
158 
159  template <typename I, typename A, typename W>
160  mln_ch_value(I, mln_result(A))
161  transform_dispatch(metal::true_,
162  const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
163  {
164  return impl::transform_fastest(input, a, win);
165  }
166 
167  template <typename I, typename A, typename W>
168  mln_ch_value(I, mln_result(A))
169  transform_dispatch(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
170  {
171  return transform_dispatch(mln_is_fastest_IW(I, W)(),
172  input, a, win);
173  }
174 
175  } // end of namespace mln::accu::internal
176 
177 
178  // Facades.
179 
180  template <typename I, typename A, typename W>
181  inline
182  mln_ch_value(I, mln_result(A))
183  transform(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
184  {
185  mln_trace("accu::transform");
186 
187  mln_precondition(exact(input).is_valid());
188  mln_precondition(exact(win).is_valid());
189 
190  mln_ch_value(I, mln_result(A)) output;
191  output = internal::transform_dispatch(input, a, win);
192 
193  return output;
194  }
195 
196  template <typename I, typename A, typename W>
197  mln_ch_value(I, mln_meta_accu_result(A, mln_value(I)))
198  transform(const Image<I>& input, const Meta_Accumulator<A>& a, const Window<W>& win)
199  {
200  mln_trace("accu::transform");
201 
202  mln_precondition(exact(input).is_valid());
203  mln_precondition(exact(win).is_valid());
204 
205  typedef mln_accu_with(A, mln_value(I)) A_;
206  A_ a_ = accu::unmeta(exact(a), mln_value(I)());
207 
208  mln_ch_value(I, mln_result(A_)) output;
209  output = internal::transform_dispatch(input, a_, win);
210 
211  return output;
212  }
213 
214 # endif // ! MLN_INCLUDE_ONLY
215 
216  } // end of namespace mln::accu
217 
218 } // end of namespace mln
219 
220 
221 #endif // ! MLN_ACCU_TRANSFORM_HH