$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
data/transform.hh
1 // Copyright (C) 2007, 2008, 2009, 2011 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_DATA_TRANSFORM_HH
28 # define MLN_DATA_TRANSFORM_HH
29 
37 
38 # include <mln/core/concept/image.hh>
39 # include <mln/core/concept/function.hh>
40 # include <mln/value/set.hh>
41 
42 // Specializations are in:
43 # include <mln/data/transform.spe.hh>
44 
45 
46 namespace mln
47 {
48 
49  namespace data
50  {
51 
62  template <typename I, typename F>
63  mln_ch_value(I, mln_result(F))
64  transform(const Image<I>& input, const Function_v2v<F>& f);
65 
66 
78  template <typename I1, typename I2, typename F>
79  mln_ch_value(I1, mln_result(F))
80  transform(const Image<I1>& input1,
81  const Image<I2>& input2,
82  const Function_vv2v<F>& f);
83 
84 
85 
86 # ifndef MLN_INCLUDE_ONLY
87 
88  namespace internal
89  {
90 
91  template <typename I, typename F>
92  void transform_tests(const Image<I>& input,
93  const Function_v2v<F>& f)
94  {
95  // Dynamic test.
96  mln_precondition(exact(input).is_valid());
97 
98  // Avoid a warning about an undefined variable when NDEBUG
99  // is not defined.
100  (void) input;
101  (void) f;
102  }
103 
104  template <typename I1, typename I2, typename F>
105  void transform_tests(const Image<I1>& input1, const Image<I2>& input2,
106  const Function_vv2v<F>& f)
107  {
108  // Dynamic tests.
109  mln_precondition(exact(input1).is_valid());
110  mln_precondition(exact(input2).is_valid());
111  mln_precondition(exact(input2).domain() == exact(input1).domain());
112 
113  // Avoid a warning about an undefined variable when NDEBUG
114  // is not defined.
115  (void) input1;
116  (void) input2;
117  (void) f;
118  }
119 
120  } // end of namespace mln::data::internal
121 
122 
123 
124  namespace impl
125  {
126 
127 
128  // Generic implementations.
129 
130 
131  namespace generic
132  {
133 
138  //
139  template <typename I, typename F>
140  mln_ch_value(I, mln_result(F))
141  transform(const Image<I>& input_, const Function_v2v<F>& f_)
142  {
143  mln_trace("data::impl::generic::transform");
144 
145  const I& input = exact(input_);
146  const F& f = exact(f_);
147 
148  data::internal::transform_tests(input, f);
149 
150  mln_ch_value(I, mln_result(F)) output;
151  initialize(output, input);
152 
153  mln_piter(I) p(input.domain());
154  for_all(p)
155  output(p) = f(input(p));
156 
157  return output;
158  }
159 
160 
166  //
167  template <typename I1, typename I2, typename F>
168  mln_ch_value(I1, mln_result(F))
169  transform(const Image<I1>& input1_,
170  const Image<I2>& input2_,
171  const Function_vv2v<F>& f_)
172  {
173  mln_trace("data::impl::generic::transform");
174 
175  const I1& input1 = exact(input1_);
176  const I2& input2 = exact(input2_);
177  const F& f = exact(f_);
178 
179  data::internal::transform_tests(input1, input2, f);
180 
181  mln_ch_value(I1, mln_result(F)) output;
182  initialize(output, input1);
183 
184  mln_piter(I1) p(input1.domain());
185  for_all(p)
186  output(p) = f(input1(p), input2(p));
187 
188  return output;
189  }
190 
191  } // end of namespace mln::data::impl::generic
192 
193 
194  } // end of namespace mln::data::impl
195 
196 
197 
198  // Facades.
199 
200 
201  template <typename I, typename F>
202  inline
203  mln_ch_value(I, mln_result(F))
204  transform(const Image<I>& input, const Function_v2v<F>& f)
205  {
206  mln_trace("data::transform");
207 
208  internal::transform_tests(input, f);
209 
210  mln_ch_value(I, mln_result(F)) output;
211  output = internal::transform_dispatch(input, f);
212 
213  return output;
214  }
215 
216 
217  template <typename I1, typename I2, typename F>
218  inline
219  mln_ch_value(I1, mln_result(F))
220  transform(const Image<I1>& input1, const Image<I2>& input2,
221  const Function_vv2v<F>& f)
222  {
223  mln_trace("data::transform");
224 
225  internal::transform_tests(input1, input2, f);
226 
227  mln_ch_value(I1, mln_result(F)) output;
228  output = internal::transform_dispatch(input1, input2, f);
229 
230  return output;
231  }
232 
233 
234 # endif // ! MLN_INCLUDE_ONLY
235 
236  } // end of namespace mln::data
237 
238 } // end of namespace mln
239 
240 
241 #endif // ! MLN_DATA_TRANSFORM_HH