Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 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_ARITH_DIV_HH 00027 # define MLN_ARITH_DIV_HH 00028 00034 00035 # include <mln/arith/includes.hh> 00036 00037 // Specializations are in: 00038 # include <mln/arith/div.spe.hh> 00039 00040 00041 namespace mln 00042 { 00043 00044 00045 namespace trait 00046 { 00047 00048 template <typename L, typename R> 00049 struct set_binary_< op::div, Image, L, Image, R > 00050 { 00051 typedef mln_trait_op_div(mln_value(L), mln_value(R)) value; 00052 typedef mln_ch_value(L, value) ret; 00053 }; 00054 00055 template <typename I, typename S> 00056 struct set_binary_< op::div, Image, I, mln::value::Scalar, S > 00057 { 00058 typedef mln_trait_op_div(mln_value(I), S) value; 00059 typedef mln_ch_value(I, value) ret; 00060 }; 00061 00062 } // end of namespace mln::trait 00063 00064 00065 00066 template <typename L, typename R> 00067 mln_trait_op_div(L,R) 00068 operator/(const Image<L>& lhs, const Image<R>& rhs); 00069 00070 template <typename L, typename R> 00071 L& 00072 operator/=(Image<L>& lhs, const Image<R>& rhs); 00073 00074 00075 template <typename I, typename S> 00076 mln_trait_op_div(I,S) 00077 operator/(const Image<I>& ima, const value::Scalar<S>& s); 00078 00079 template <typename I, typename S> 00080 I& 00081 operator/=(Image<I>& ima, const value::Scalar<S>& s); 00082 00083 00084 00085 namespace arith 00086 { 00087 00089 00096 template <typename L, typename R, typename O> 00097 void div(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output); 00098 00099 00101 00108 template <typename I, typename V, typename O> 00109 void div_cst(const Image<I>& input, const V& val, Image<O>& output); 00110 00111 00113 00123 template <typename L, typename R> 00124 void div_inplace(Image<L>& lhs, const Image<R>& rhs); 00125 00126 00127 } // end of namespace mln::arith 00128 00129 00130 00131 00132 # ifndef MLN_INCLUDE_ONLY 00133 00134 00135 template <typename L, typename R> 00136 inline 00137 mln_trait_op_div(L,R) 00138 operator/(const Image<L>& lhs, const Image<R>& rhs) 00139 { 00140 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00141 mln_trait_op_div(L,R) tmp; 00142 initialize(tmp, lhs); 00143 arith::div(lhs, rhs, tmp); 00144 return tmp; 00145 } 00146 00147 template <typename L, typename R> 00148 inline 00149 L& 00150 operator/=(Image<L>& lhs, const Image<R>& rhs) 00151 { 00152 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00153 arith::div_inplace(lhs, rhs); 00154 return exact(lhs); 00155 } 00156 00157 00158 template <typename I, typename S> 00159 inline 00160 mln_trait_op_div(I,S) 00161 operator/(const Image<I>& ima, const value::Scalar<S>& s) 00162 { 00163 mln_precondition(exact(ima).is_valid()); 00164 mln_precondition(s != 0); 00165 mln_trait_op_div(I,S) tmp; 00166 initialize(tmp, ima); 00167 arith::div_cst(ima, exact(s), tmp); 00168 return tmp; 00169 } 00170 00171 template <typename I, typename S> 00172 inline 00173 I& 00174 operator/=(Image<I>& ima, const value::Scalar<S>& s) 00175 { 00176 mln_precondition(exact(ima).is_valid()); 00177 arith::div_cst(ima, exact(s), ima); 00178 return exact(ima); 00179 } 00180 00181 00182 00183 namespace arith 00184 { 00185 00186 namespace impl 00187 { 00188 00189 namespace generic 00190 { 00191 00192 template <typename L, typename R, typename O> 00193 inline 00194 void div_(const L& lhs, const R& rhs, O& output) 00195 { 00196 trace::entering("arith::impl::generic::div_"); 00197 00198 mln_piter(L) p(lhs.domain()); 00199 for_all(p) 00200 output(p) = lhs(p) / rhs(p); 00201 00202 trace::exiting("arith::impl::generic::div_"); 00203 } 00204 00205 template <typename L, typename R> 00206 inline 00207 void div_inplace_(L& lhs, const R& rhs) 00208 { 00209 trace::entering("arith::impl::generic::div_inplace_"); 00210 00211 mln_piter(R) p(rhs.domain()); 00212 for_all(p) 00213 lhs(p) /= rhs(p); 00214 00215 trace::exiting("arith::impl::generic::div_inplace_"); 00216 } 00217 00218 } // end of namespace mln::arith::impl::generic 00219 00220 } // end of namespace mln::arith::impl 00221 00222 00223 // Facades. 00224 00225 template <typename L, typename R, typename O> 00226 inline 00227 void div(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output) 00228 { 00229 trace::entering("arith::div"); 00230 00231 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00232 mln_precondition(exact(output).domain() == exact(lhs).domain()); 00233 impl::div_(mln_trait_image_speed(L)(), exact(lhs), 00234 mln_trait_image_speed(R)(), exact(rhs), 00235 mln_trait_image_speed(O)(), exact(output)); 00236 00237 trace::exiting("arith::div"); 00238 } 00239 00240 template <typename I, typename V, typename O> 00241 inline 00242 void div_cst(const Image<I>& input, const V& val, Image<O>& output) 00243 { 00244 trace::entering("arith::div_cst"); 00245 00246 mln_precondition(exact(output).domain() == exact(input).domain()); 00247 div(input, pw::cst(val) | exact(input).domain(), output); 00248 // Calls the previous version. 00249 00250 trace::exiting("arith::div_cst"); 00251 } 00252 00253 template <typename L, typename R> 00254 inline 00255 void div_inplace(Image<L>& lhs, const Image<R>& rhs) 00256 { 00257 trace::entering("arith::div_inplace"); 00258 00259 mln_precondition(exact(rhs).domain() <= exact(lhs).domain()); 00260 impl::div_inplace_(mln_trait_image_speed(L)(), exact(lhs), 00261 mln_trait_image_speed(R)(), exact(rhs)); 00262 00263 trace::exiting("arith::div_inplace"); 00264 } 00265 00266 template <typename I, typename V> 00267 inline 00268 void div_cst_inplace(Image<I>& input, const V& val) 00269 { 00270 trace::entering("arith::div_cst_inplace"); 00271 00272 mln_precondition(exact(input).is_valid()); 00273 div_inplace(input, pw::cst(val) | exact(input).domain()); 00274 // Calls the previous version. 00275 00276 trace::exiting("arith::div_cst_inplace"); 00277 } 00278 00279 } // end of namespace mln::arith 00280 00281 # endif // ! MLN_INCLUDE_ONLY 00282 00283 } // end of namespace mln 00284 00285 00286 #endif // ! MLN_ARITH_DIV_HH