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_LINEAR_LOCAL_CONVOLVE_HH 00027 # define MLN_LINEAR_LOCAL_CONVOLVE_HH 00028 00032 00033 # include <mln/core/concept/image.hh> 00034 # include <mln/core/concept/site.hh> 00035 # include <mln/core/concept/generalized_pixel.hh> 00036 # include <mln/core/concept/weighted_window.hh> 00037 # include <mln/metal/const.hh> 00038 00039 00040 00041 namespace mln 00042 { 00043 00044 namespace linear 00045 { 00046 00047 namespace local 00048 { 00049 00059 template <typename I, typename P, typename W, typename R> 00060 void convolve(const Image<I>& input, 00061 const Site<P>& p, 00062 const Weighted_Window<W>& w_win, 00063 R& result); 00064 00065 00075 template <typename P, typename W, typename R> 00076 void convolve(const Generalized_Pixel<P>& p, 00077 const Weighted_Window<W>& w_win, 00078 R& result); 00079 00080 00081 # ifndef MLN_INCLUDE_ONLY 00082 00083 namespace impl 00084 { 00085 00086 template <typename I, typename P, typename W, typename R> 00087 inline 00088 void convolve(trait::image::speed::any, 00089 const I& input, 00090 const Site<P>& p_, 00091 const W& w_win, 00092 R& result) 00093 { 00094 const P& p = exact(p_); 00095 00096 R tmp = literal::zero; // FIXME: zero? 00097 mln_qiter(W) q(w_win, p); 00098 for_all(q) if (input.has(q)) 00099 tmp += input(q) * q.w(); 00100 result = tmp; 00101 } 00102 00103 template <typename I, typename P, typename W, typename R> 00104 inline 00105 void convolve(trait::image::speed::fastest, 00106 const I& input, 00107 const Site<P>& p_, 00108 const W& w_win, 00109 R& result) 00110 { 00111 const P& p = exact(p_); 00112 00113 mln_precondition(input.border() >= w_win.delta()); 00114 00115 R tmp = 0; 00116 unsigned i = 0; 00117 mln_qixter(const I, W) q(input, w_win, p); 00118 for_all(q) 00119 tmp += w_win.w(i++) * q.val(); 00120 result = tmp; 00121 } 00122 00123 template <typename P, typename W, typename R> 00124 inline 00125 void convolve(const Generalized_Pixel<P>& p_, 00126 const W& w_win, 00127 R& result) 00128 { 00129 const P& p = mln::internal::force_exact<P>(p_); 00130 mln_precondition(p.ima().border() >= w_win.delta()); 00131 00132 R tmp = 0; 00133 unsigned i = 0; 00134 // FIXME: mln_qixter(const P, W) should work 00135 // FIXME: so make the trait make this job... 00136 mln_qixter(mlc_const(mln_image(P)), W) q(p, w_win); 00137 for_all(q) 00138 tmp += w_win.w(i++) * q.val(); 00139 result = tmp; 00140 } 00141 00142 } // end of namespace mln::linear::impl 00143 00144 00145 // Facades. 00146 00147 template <typename I, typename P, typename W, typename R> 00148 inline 00149 void convolve(const Image<I>& input, 00150 const Site<P>& p, 00151 const Weighted_Window<W>& w_win, 00152 R& result) 00153 { 00154 mln_precondition(exact(input).is_valid()); 00155 impl::convolve(mln_trait_image_speed(I)(), exact(input), 00156 p, exact(w_win), result); 00157 } 00158 00159 template <typename P, typename W, typename R> 00160 inline 00161 void convolve(const Generalized_Pixel<P>& p, 00162 const Weighted_Window<W>& w_win, 00163 R& result) 00164 { 00165 impl::convolve(p, exact(w_win), result); 00166 } 00167 00168 # endif // ! MLN_INCLUDE_ONLY 00169 00170 } // end of namespace mln::linear::local 00171 00172 } // end of namespace mln::linear 00173 00174 } // end of namespace mln 00175 00176 00177 #endif // ! MLN_LINEAR_LOCAL_CONVOLVE_HH