Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_ACCU_TRANSFORM_HH 00027 # define MLN_ACCU_TRANSFORM_HH 00028 00033 00034 # include <mln/core/concept/meta_accumulator.hh> 00035 # include <mln/core/concept/image.hh> 00036 # include <mln/core/concept/window.hh> 00037 # include <mln/extension/adjust.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 namespace accu 00044 { 00045 00046 template <typename I, typename A, typename W> 00047 mln_ch_value(I, mln_result(A)) 00048 transform(const Image<I>& input, 00049 const Accumulator<A>& a, 00050 const Window<W>& win); 00051 00052 template <typename I, typename A, typename W> 00053 mln_ch_value(I, mln_meta_accu_result(A, mln_value(I))) 00054 transform(const Image<I>& input, 00055 const Meta_Accumulator<A>& a, 00056 const Window<W>& win); 00057 00058 00059 00060 # ifndef MLN_INCLUDE_ONLY 00061 00062 00063 namespace impl 00064 { 00065 00066 // Generic version. 00067 00068 namespace generic 00069 { 00070 00071 template <typename I, typename A, typename W> 00072 mln_ch_value(I, mln_result(A)) 00073 transform(const Image<I>& input_, 00074 const Accumulator<A>& a_, 00075 const Window<W>& win_) 00076 { 00077 trace::entering("accu::impl::generic::transform"); 00078 00079 const I& input = exact(input_); 00080 const W& win = exact(win_); 00081 A a = exact(a_); 00082 00083 mln_precondition(input.is_valid()); 00084 mln_precondition(win.is_valid()); 00085 00086 extension::adjust(input, win); 00087 00088 mln_ch_value(I, mln_result(A)) output; 00089 initialize(output, input); 00090 00091 mln_piter(I) p(input.domain()); 00092 mln_qiter(W) q(win, p); 00093 for_all(p) 00094 { 00095 a.init(); 00096 for_all(q) if (input.has(q)) 00097 a.take(input(q)); 00098 output(p) = a.to_result(); 00099 } 00100 00101 trace::exiting("accu::impl::generic::transform"); 00102 return output; 00103 } 00104 00105 } // end of namespace mln::accu::impl::generic 00106 00107 00108 // Fastest version. 00109 00110 template <typename I, typename A, typename W> 00111 mln_ch_value(I, mln_result(A)) 00112 transform_fastest(const Image<I>& input_, const Accumulator<A>& a_, const Window<W>& win_) 00113 { 00114 trace::entering("accu::impl::transform_fastest"); 00115 00116 const I& input = exact(input_); 00117 const W& win = exact(win_); 00118 A a = exact(a_); 00119 00120 mln_precondition(input.is_valid()); 00121 mln_precondition(win.is_valid()); 00122 00123 extension::adjust(input, win); 00124 00125 typedef mln_ch_value(I, mln_result(A)) O; 00126 O output; 00127 initialize(output, input); 00128 mln_pixter(O) o(output); 00129 00130 mln_pixter(const I) p(input); 00131 mln_qixter(const I, W) q(p, win); 00132 for_all_2(p, o) 00133 { 00134 a.init(); 00135 for_all(q) 00136 a.take(q.val()); 00137 o.val() = a.to_result(); 00138 } 00139 00140 trace::exiting("accu::impl::transform_fastest"); 00141 return output; 00142 } 00143 00144 00145 } // end of namespace mln::accu::impl 00146 00147 00148 // Dispatch. 00149 00150 namespace internal 00151 { 00152 00153 template <typename I, typename A, typename W> 00154 mln_ch_value(I, mln_result(A)) 00155 transform_dispatch(metal::false_, 00156 const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) 00157 { 00158 return impl::generic::transform(input, a, win); 00159 } 00160 00161 template <typename I, typename A, typename W> 00162 mln_ch_value(I, mln_result(A)) 00163 transform_dispatch(metal::true_, 00164 const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) 00165 { 00166 return impl::transform_fastest(input, a, win); 00167 } 00168 00169 template <typename I, typename A, typename W> 00170 mln_ch_value(I, mln_result(A)) 00171 transform_dispatch(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) 00172 { 00173 return transform_dispatch(mln_is_fastest_IW(I, W)(), 00174 input, a, win); 00175 } 00176 00177 } // end of namespace mln::accu::internal 00178 00179 00180 // Facades. 00181 00182 template <typename I, typename A, typename W> 00183 inline 00184 mln_ch_value(I, mln_result(A)) 00185 transform(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) 00186 { 00187 trace::entering("accu::transform"); 00188 00189 mln_precondition(exact(input).is_valid()); 00190 mln_precondition(exact(win).is_valid()); 00191 00192 mln_ch_value(I, mln_result(A)) output; 00193 output = internal::transform_dispatch(input, a, win); 00194 00195 trace::exiting("accu::transform"); 00196 return output; 00197 } 00198 00199 template <typename I, typename A, typename W> 00200 mln_ch_value(I, mln_meta_accu_result(A, mln_value(I))) 00201 transform(const Image<I>& input, const Meta_Accumulator<A>& a, const Window<W>& win) 00202 { 00203 trace::entering("accu::transform"); 00204 00205 mln_precondition(exact(input).is_valid()); 00206 mln_precondition(exact(win).is_valid()); 00207 00208 typedef mln_accu_with(A, mln_value(I)) A_; 00209 A_ a_ = accu::unmeta(exact(a), mln_value(I)()); 00210 00211 mln_ch_value(I, mln_result(A_)) output; 00212 output = internal::transform_dispatch(input, a_, win); 00213 00214 trace::exiting("accu::transform"); 00215 return output; 00216 } 00217 00218 # endif // ! MLN_INCLUDE_ONLY 00219 00220 } // end of namespace mln::accu 00221 00222 } // end of namespace mln 00223 00224 00225 #endif // ! MLN_ACCU_TRANSFORM_HH