$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
linear/local/convolve.hh
1 // Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_LINEAR_LOCAL_CONVOLVE_HH
28 # define MLN_LINEAR_LOCAL_CONVOLVE_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/site.hh>
36 # include <mln/core/concept/generalized_pixel.hh>
37 # include <mln/core/concept/weighted_window.hh>
38 # include <mln/metal/const.hh>
39 
40 
41 
42 namespace mln
43 {
44 
45  namespace linear
46  {
47 
48  namespace local
49  {
50 
62  template <typename I, typename P, typename W, typename R>
63  void convolve(const Image<I>& input,
64  const Site<P>& p,
65  const Weighted_Window<W>& w_win,
66  R& result);
67 
68 
80  template <typename P, typename W, typename R>
81  void convolve(const Generalized_Pixel<P>& p,
82  const Weighted_Window<W>& w_win,
83  R& result);
84 
85 
86 # ifndef MLN_INCLUDE_ONLY
87 
88  namespace impl
89  {
90 
91  template <typename I, typename P, typename W, typename R>
92  inline
93  void convolve(trait::image::speed::any,
94  const I& input,
95  const Site<P>& p_,
96  const W& w_win,
97  R& result)
98  {
99  const P& p = exact(p_);
100 
101  R tmp = literal::zero; // FIXME: zero?
102  mln_qiter(W) q(w_win, p);
103  for_all(q) if (input.has(q))
104  tmp += input(q) * q.w();
105  result = tmp;
106  }
107 
108  template <typename I, typename P, typename W, typename R>
109  inline
110  void convolve(trait::image::speed::fastest,
111  const I& input,
112  const Site<P>& p_,
113  const W& w_win,
114  R& result)
115  {
116  const P& p = exact(p_);
117 
118  mln_precondition(input.border() >= w_win.delta());
119 
120  R tmp = 0;
121  unsigned i = 0;
122  mln_qixter(const I, W) q(input, w_win, p);
123  for_all(q)
124  tmp += w_win.w(i++) * q.val();
125  result = tmp;
126  }
127 
128  template <typename P, typename W, typename R>
129  inline
130  void convolve(const Generalized_Pixel<P>& p_,
131  const W& w_win,
132  R& result)
133  {
134  const P& p = mln::internal::force_exact<P>(p_);
135  mln_precondition(p.ima().border() >= w_win.delta());
136 
137  R tmp = 0;
138  unsigned i = 0;
139  // FIXME: mln_qixter(const P, W) should work
140  // FIXME: so make the trait make this job...
141  mln_qixter(mlc_const(mln_image(P)), W) q(p, w_win);
142  for_all(q)
143  tmp += w_win.w(i++) * q.val();
144  result = tmp;
145  }
146 
147  } // end of namespace mln::linear::impl
148 
149 
150  // Facades.
151 
152  template <typename I, typename P, typename W, typename R>
153  inline
154  void convolve(const Image<I>& input,
155  const Site<P>& p,
156  const Weighted_Window<W>& w_win,
157  R& result)
158  {
159  mln_precondition(exact(input).is_valid());
160  impl::convolve(mln_trait_image_speed(I)(), exact(input),
161  p, exact(w_win), result);
162  }
163 
164  template <typename P, typename W, typename R>
165  inline
166  void convolve(const Generalized_Pixel<P>& p,
167  const Weighted_Window<W>& w_win,
168  R& result)
169  {
170  impl::convolve(p, exact(w_win), result);
171  }
172 
173 # endif // ! MLN_INCLUDE_ONLY
174 
175  } // end of namespace mln::linear::local
176 
177  } // end of namespace mln::linear
178 
179 } // end of namespace mln
180 
181 
182 #endif // ! MLN_LINEAR_LOCAL_CONVOLVE_HH