00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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; 
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           
00135           
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       } 
00143 
00144 
00145       
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     } 
00171 
00172   } 
00173 
00174 } 
00175 
00176 
00177 #endif // ! MLN_LINEAR_LOCAL_CONVOLVE_HH