Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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_IMAGE_TO_RESULT_HH 00027 # define MLN_ACCU_IMAGE_TO_RESULT_HH 00028 00032 00033 # include <mln/core/concept/accumulator.hh> 00034 # include <mln/core/concept/image.hh> 00035 00036 00037 namespace mln 00038 { 00039 00040 namespace accu 00041 { 00042 00043 namespace image 00044 { 00045 00046 template <typename I> 00047 mln_ch_value(I, mln_deduce(I, value, result)) 00048 to_result(const Image<I>& input); 00049 00050 00051 00052 # ifndef MLN_INCLUDE_ONLY 00053 00054 namespace impl 00055 { 00056 00057 // Generic version. 00058 00059 namespace generic 00060 { 00061 00062 template <typename I> 00063 mln_ch_value(I, mln_deduce(I, value, result)) 00064 to_result(const Image<I>& input_) 00065 { 00066 trace::entering("accu::impl::image::generic::to_result"); 00067 00068 mlc_is_a(mln_value(I), Accumulator)::check(); 00069 00070 const I& input = exact(input_); 00071 mln_precondition(input.is_valid()); 00072 00073 typedef mln_deduce(I, value, result) R; 00074 mln_ch_value(I, R) output; 00075 initialize(output, input); 00076 00077 mln_piter(I) p(input.domain()); 00078 for_all(p) 00079 output(p) = input(p).to_result(); 00080 00081 trace::exiting("accu::impl::image::generic::to_result"); 00082 return output; 00083 } 00084 00085 } // end of namespace mln::accu::image::impl::generic 00086 00087 00088 // Fastest version. 00089 00090 template <typename I> 00091 mln_ch_value(I, mln_deduce(I, value, result)) 00092 to_result_fastest(const Image<I>& input_) 00093 { 00094 trace::entering("accu::impl::image::to_result_fastest"); 00095 00096 mlc_is_a(mln_value(I), Accumulator)::check(); 00097 00098 const I& input = exact(input_); 00099 mln_precondition(input.is_valid()); 00100 00101 typedef mln_deduce(I, value, result) R; 00102 typedef mln_ch_value(I, R) O; 00103 O output; 00104 initialize(output, input); 00105 00106 mln_pixter(const I) p_in(input); 00107 mln_pixter(O) p_out(output); 00108 for_all_2(p_in, p_out) 00109 p_out.val() = p_in.val().to_result(); 00110 00111 trace::exiting("accu::impl::image::to_result_fastest"); 00112 return output; 00113 } 00114 00115 } // end of namespace mln::accu::image::impl 00116 00117 00118 00119 // Dispatch. 00120 00121 namespace internal 00122 { 00123 00124 template <typename I> 00125 mln_ch_value(I, mln_deduce(I, value, result)) 00126 to_result_dispatch(trait::image::speed::any, 00127 const Image<I>& input) 00128 { 00129 return impl::generic::to_result(input); 00130 } 00131 00132 template <typename I> 00133 mln_ch_value(I, mln_deduce(I, value, result)) 00134 to_result_dispatch(trait::image::speed::fastest, 00135 const Image<I>& input) 00136 { 00137 return impl::to_result_fastest(input); 00138 } 00139 00140 template <typename I> 00141 mln_ch_value(I, mln_deduce(I, value, result)) 00142 to_result_dispatch(const Image<I>& input) 00143 { 00144 return to_result_dispatch(mln_trait_image_speed(I)(), 00145 input); 00146 } 00147 00148 } // end of namespace mln::accu::image::internal 00149 00150 00151 // Facade. 00152 00153 template <typename I> 00154 mln_ch_value(I, mln_deduce(I, value, result)) 00155 to_result(const Image<I>& input) 00156 { 00157 trace::entering("accu::image::to_result"); 00158 00159 mlc_is_a(mln_value(I), Accumulator)::check(); 00160 00161 mln_precondition(exact(input).is_valid()); 00162 00163 typedef mln_deduce(I, value, result) R; 00164 mln_ch_value(I, R) output; 00165 output = internal::to_result_dispatch(input); 00166 00167 trace::exiting("accu::image::to_result"); 00168 return output; 00169 } 00170 00171 # endif // ! MLN_INCLUDE_ONLY 00172 00173 } // end of namespace mln::accu::image 00174 00175 } // end of namespace mln::accu 00176 00177 } // end of namespace mln 00178 00179 00180 #endif // ! MLN_ACCU_IMAGE_TO_RESULT_HH