$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
closest_point_functor.hh
1 // Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
2 // (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_TRANSFORM_INTERNAL_CLOSEST_POINT_FUNCTOR_HH
28 # define MLN_TRANSFORM_INTERNAL_CLOSEST_POINT_FUNCTOR_HH
29 
33 
34 # include <mln/core/site_set/p_array.hh>
35 # include <mln/core/macros.hh>
36 # include <mln/data/fill.hh>
37 # include <mln/trait/ch_value.hh>
38 
39 namespace mln
40 {
41 
42  namespace transform
43  {
44 
45  namespace internal
46  {
47 
48 
53  template <typename I>
55  {
56  typedef mln_value(I) V;
57  typedef mln_psite(I) P;
58 
60 
61  mln_ch_value(I,unsigned) cp_ima;
62  const p_array<P>& pset_;
63 
65  void init(const I&);
66  bool inqueue_p_wrt_input_p(const V& input_p);
67  void init_p(const P&);
68  bool inqueue_p_wrt_input_n(const V& input_n);
69  void process(const P&, const P&);
70 
72  void init_(const I& input);
73  bool inqueue_p_wrt_input_p_(const V& input_p);
74  void init_p_(unsigned);
75  bool inqueue_p_wrt_input_n_(const V& input_n);
76  void process_(unsigned p, unsigned n);
77  };
78 
83  template <typename I>
85  {
86  typedef mln_value(I) V;
87  typedef mln_psite(I) P;
88 
89  closest_point_functor_with_sites();
90 
91  mln_ch_value(I,P) cp_ima;
92 
94  void init(const I&);
95  bool inqueue_p_wrt_input_p(const V& input_p);
96  void init_p(const P&);
97  bool inqueue_p_wrt_input_n(const V& input_n);
98  void process(const P&, const P&);
99 
101  void init_(const I& input);
102  bool inqueue_p_wrt_input_p_(const V& input_p);
103  void init_p_(unsigned p);
104  bool inqueue_p_wrt_input_n_(const V& input_n);
105  void process_(unsigned p, unsigned n);
106  };
107 
108 
109 # ifndef MLN_INCLUDE_ONLY
110 
111  template <typename I>
112  inline
114  const p_array<mln_psite(I)>& pset)
115  : pset_(pset)
116  {
117  }
118 
119  template <typename I>
120  inline
121  void
123  {
124  initialize(cp_ima, input);
125  data::fill(cp_ima, pset_.nsites());
126 
127  mln_piter(p_array<mln_psite(I)>) p(pset_);
128  for_all(p)
129  cp_ima(p) = p.index();
130  }
131 
132  template <typename I>
133  inline
134  bool
135  closest_point_functor_with_indexes<I>::inqueue_p_wrt_input_p(const V& input_p)
136  {
137  return input_p == true;
138  }
139 
140  template <typename I>
141  inline
142  void
144  {
145  }
146 
147  template <typename I>
148  inline
149  bool
151  {
152  return input_n == false;
153  }
154 
155  template <typename I>
156  inline
157  void closest_point_functor_with_indexes<I>::process(const P& p, const P& n)
158  {
159  cp_ima(n) = cp_ima(p);
160  }
161 
162 
163 
164  template <typename I>
165  inline
166  void
168  {
169  init(input);
170  }
171 
172  template <typename I>
173  inline
174  bool
176  {
177  return input_p == true;
178  }
179 
180  template <typename I>
181  inline
183  {
184  }
185 
186  template <typename I>
187  inline
188  bool
190  {
191  return input_n == false;
192  }
193 
194  template <typename I>
195  inline
196  void
198  {
199  cp_ima.element(n) = cp_ima.element(p);
200  }
201 
202 
206 
207 
208  template <typename I>
209  inline
211  {
212  }
213 
214  template <typename I>
215  inline
216  void
218  {
219  initialize(cp_ima, input);
220  data::fill(cp_ima, literal::origin);
221  }
222 
223  template <typename I>
224  inline
225  bool
227  {
228  return input_p == true;
229  }
230 
231  template <typename I>
232  inline
233  void
235  {
236  cp_ima(p) = p;
237  }
238 
239  template <typename I>
240  inline
241  bool
243  {
244  return input_n == false;
245  }
246 
247  template <typename I>
248  inline
249  void
250  closest_point_functor_with_sites<I>::process(const P& p, const P& n)
251  {
252  cp_ima(n) = cp_ima(p);
253  }
254 
255 
256 
257  template <typename I>
258  inline
259  void
261  {
262  init(input);
263  }
264 
265  template <typename I>
266  inline
267  bool
269  {
270  return input_p == true;
271  }
272 
273  template <typename I>
274  inline
276  {
277  cp_ima.element(p) = cp_ima.point_at_offset(p);
278  }
279 
280  template <typename I>
281  inline
282  bool
284  {
285  return input_n == false;
286  }
287 
288  template <typename I>
289  inline
290  void
291  closest_point_functor_with_sites<I>::process_(unsigned p, unsigned n)
292  {
293  cp_ima.element(n) = cp_ima.element(p);
294  }
295 
296 # endif // ! MLN_INCLUDE_ONLY
297 
298  } // end of namespace mln::transform::internal
299 
300  } // end of namespace mln::transform
301 
302 } // end of namespace mln
303 
304 
305 #endif // ! MLN_TRANSFORM_INTERNAL_CLOSEST_POINT_FUNCTOR_HH