Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
closest_point_functor.hh
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_TRANSFORM_INTERNAL_CLOSEST_POINT_FUNCTOR_HH
27 # define MLN_TRANSFORM_INTERNAL_CLOSEST_POINT_FUNCTOR_HH
28 
32 
33 # include <mln/core/site_set/p_array.hh>
34 # include <mln/core/macros.hh>
35 # include <mln/data/fill.hh>
36 # include <mln/trait/ch_value.hh>
37 
38 namespace mln
39 {
40 
41  namespace transform
42  {
43 
44  namespace internal
45  {
46 
47 
52  template <typename I>
53  struct closest_point_functor_with_indexes
54  {
55  typedef mln_value(I) V;
56  typedef mln_psite(I) P;
57 
58  closest_point_functor_with_indexes(const p_array<P>& pset);
59 
60  mln_ch_value(I,unsigned) cp_ima;
61  const p_array<P>& pset_;
62 
64  void init(const I&);
65  bool inqueue_p_wrt_input_p(const V& input_p);
66  void init_p(const P&);
67  bool inqueue_p_wrt_input_n(const V& input_n);
68  void process(const P&, const P&);
69 
71  void init_(const I& input);
72  bool inqueue_p_wrt_input_p_(const V& input_p);
73  void init_p_(unsigned);
74  bool inqueue_p_wrt_input_n_(const V& input_n);
75  void process_(unsigned p, unsigned n);
76  };
77 
82  template <typename I>
83  struct closest_point_functor_with_sites
84  {
85  typedef mln_value(I) V;
86  typedef mln_psite(I) P;
87 
88  closest_point_functor_with_sites();
89 
90  mln_ch_value(I,P) cp_ima;
91 
93  void init(const I&);
94  bool inqueue_p_wrt_input_p(const V& input_p);
95  void init_p(const P&);
96  bool inqueue_p_wrt_input_n(const V& input_n);
97  void process(const P&, const P&);
98 
100  void init_(const I& input);
101  bool inqueue_p_wrt_input_p_(const V& input_p);
102  void init_p_(unsigned p);
103  bool inqueue_p_wrt_input_n_(const V& input_n);
104  void process_(unsigned p, unsigned n);
105  };
106 
107 
108 # ifndef MLN_INCLUDE_ONLY
109 
110  template <typename I>
111  inline
112  closest_point_functor_with_indexes<I>::closest_point_functor_with_indexes(
113  const p_array<mln_psite(I)>& pset)
114  : pset_(pset)
115  {
116  }
117 
118  template <typename I>
119  inline
120  void
121  closest_point_functor_with_indexes<I>::init(const I& input)
122  {
123  initialize(cp_ima, input);
124  data::fill(cp_ima, pset_.nsites());
125 
126  mln_piter(p_array<mln_psite(I)>) p(pset_);
127  for_all(p)
128  cp_ima(p) = p.index();
129  }
130 
131  template <typename I>
132  inline
133  bool
134  closest_point_functor_with_indexes<I>::inqueue_p_wrt_input_p(const V& input_p)
135  {
136  return input_p == true;
137  }
138 
139  template <typename I>
140  inline
141  void
142  closest_point_functor_with_indexes<I>::init_p(const P&)
143  {
144  }
145 
146  template <typename I>
147  inline
148  bool
149  closest_point_functor_with_indexes<I>::inqueue_p_wrt_input_n(const V& input_n)
150  {
151  return input_n == false;
152  }
153 
154  template <typename I>
155  inline
156  void closest_point_functor_with_indexes<I>::process(const P& p, const P& n)
157  {
158  cp_ima(n) = cp_ima(p);
159  }
160 
161 
162 
163  template <typename I>
164  inline
165  void
166  closest_point_functor_with_indexes<I>::init_(const I& input)
167  {
168  init(input);
169  }
170 
171  template <typename I>
172  inline
173  bool
174  closest_point_functor_with_indexes<I>::inqueue_p_wrt_input_p_(const V& input_p)
175  {
176  return input_p == true;
177  }
178 
179  template <typename I>
180  inline
181  void closest_point_functor_with_indexes<I>::init_p_(unsigned)
182  {
183  }
184 
185  template <typename I>
186  inline
187  bool
188  closest_point_functor_with_indexes<I>::inqueue_p_wrt_input_n_(const V& input_n)
189  {
190  return input_n == false;
191  }
192 
193  template <typename I>
194  inline
195  void
196  closest_point_functor_with_indexes<I>::process_(unsigned p, unsigned n)
197  {
198  cp_ima.element(n) = cp_ima.element(p);
199  }
200 
201 
205 
206 
207  template <typename I>
208  inline
209  closest_point_functor_with_sites<I>::closest_point_functor_with_sites()
210  {
211  }
212 
213  template <typename I>
214  inline
215  void
216  closest_point_functor_with_sites<I>::init(const I& input)
217  {
218  initialize(cp_ima, input);
219  data::fill(cp_ima, literal::origin);
220  }
221 
222  template <typename I>
223  inline
224  bool
225  closest_point_functor_with_sites<I>::inqueue_p_wrt_input_p(const V& input_p)
226  {
227  return input_p == true;
228  }
229 
230  template <typename I>
231  inline
232  void
233  closest_point_functor_with_sites<I>::init_p(const P& p)
234  {
235  cp_ima(p) = p;
236  }
237 
238  template <typename I>
239  inline
240  bool
241  closest_point_functor_with_sites<I>::inqueue_p_wrt_input_n(const V& input_n)
242  {
243  return input_n == false;
244  }
245 
246  template <typename I>
247  inline
248  void
249  closest_point_functor_with_sites<I>::process(const P& p, const P& n)
250  {
251  cp_ima(n) = cp_ima(p);
252  }
253 
254 
255 
256  template <typename I>
257  inline
258  void
259  closest_point_functor_with_sites<I>::init_(const I& input)
260  {
261  init(input);
262  }
263 
264  template <typename I>
265  inline
266  bool
267  closest_point_functor_with_sites<I>::inqueue_p_wrt_input_p_(const V& input_p)
268  {
269  return input_p == true;
270  }
271 
272  template <typename I>
273  inline
274  void closest_point_functor_with_sites<I>::init_p_(unsigned p)
275  {
276  cp_ima.element(p) = cp_ima.point_at_index(p);
277  }
278 
279  template <typename I>
280  inline
281  bool
282  closest_point_functor_with_sites<I>::inqueue_p_wrt_input_n_(const V& input_n)
283  {
284  return input_n == false;
285  }
286 
287  template <typename I>
288  inline
289  void
290  closest_point_functor_with_sites<I>::process_(unsigned p, unsigned n)
291  {
292  cp_ima.element(n) = cp_ima.element(p);
293  }
294 
295 # endif // ! MLN_INCLUDE_ONLY
296 
297  } // end of namespace mln::transform::internal
298 
299  } // end of namespace mln::transform
300 
301 } // end of namespace mln
302 
303 
304 #endif // ! MLN_TRANSFORM_INTERNAL_CLOSEST_POINT_FUNCTOR_HH