$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
core/image/vertex_image.hh
1 // Copyright (C) 2009, 2012, 2013 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_CORE_IMAGE_VERTEX_IMAGE_HH
28 # define MLN_CORE_IMAGE_VERTEX_IMAGE_HH
29 
33 
34 # include <mln/core/concept/graph.hh>
35 # include <mln/core/image/graph_elt_window.hh>
36 # include <mln/core/image/graph_elt_neighborhood.hh>
37 # include <mln/core/image/graph_elt_mixed_neighborhood.hh>
38 # include <mln/core/site_set/p_vertices.hh>
39 # include <mln/pw/internal/image_base.hh>
40 # include <mln/fun/i2v/array.hh>
41 
42 # include <mln/util/internal/id2element.hh>
43 
44 
45 namespace mln
46 {
47 
48  // Forward declaration.
49  template <typename P, typename V, typename G> class vertex_image;
50  namespace util { class graph; }
51 
52 
53  // Properties
54 
55  namespace trait
56  {
57 
58  template <typename P, typename V, typename G>
59  struct image_< vertex_image<P,V,G> >
60  : pw_image_<fun::i2v::array<V>,
61  p_vertices<util::graph, fun::i2v::array<P> >,
62  vertex_image<P,V,G> >
63  {
64  };
65 
66  } // end of namespace mln::traits.
67 
68 
69 
70  namespace internal
71  {
72 
77  template <typename P, typename V, typename G>
78  struct data< mln::vertex_image<P,V,G> >
79  {
80  typedef typename vertex_image<P,V,G>::site_function_t site_function_t;
81 
82  template <typename F>
83  data(const fun::i2v::array<V>& vertex_values,
84  const p_vertices<G,F>& pv);
85 
86  fun::i2v::array<V> f_;
87  p_vertices<G,site_function_t> domain_;
88  };
89 
90  } // end of namespace mln::internal
91 
92 
93 
96  template <typename V, typename G, typename P>
97  vertex_image<P,V,G>
98  operator | (const fun::i2v::array<V>& vertex_values,
99  const p_vertices<G,fun::i2v::array<P> >& pv);
100 
101 
102  // Vertex_image_fsite_selector
103 
104  namespace internal
105  {
106 
107  template <typename P, typename G>
109  {
111  };
112 
113 
114 
115  template <typename G>
116  struct vfsite_selector<void,G>
117  {
119  };
120 
121 
122  } // end of namespace mln::internal
123 
124 
128  //
129  template <typename P, typename V, typename G = util::graph>
131  : public pw::internal::image_base<fun::i2v::array<V>,
132  p_vertices<G, typename internal::vfsite_selector<P,G>::site_function_t >,
133  vertex_image<P,V,G> >
134  {
138 
139  public:
140  typedef typename super_::psite psite;
141  typedef typename super_::rvalue rvalue;
142  typedef typename super_::lvalue lvalue;
143 
145  typedef G graph_t;
146 
150  typedef mln_result(site_function_t) function_result_t;
151 
152 
154  typedef vertex_image< tag::psite_<P>,
155  tag::value_<V>,
156  tag::graph_<G> > skeleton;
157 
159 
162 
165 
167  typedef vertex_win_t win_t;
169  typedef vertex_nbh_t nbh_t;
170 
171 
172 
175  vertex_image();
176  vertex_image(const p_vertices<G, site_function_t>& pv);
178  const Function_v2v< fun::i2v::array<V> >& vertex_values);
179  template <typename FV>
181  const Function_v2v<FV>& vertex_values);
183 
186  rvalue operator()(unsigned v_id) const;
187  lvalue operator()(unsigned v_id);
189 
190 
191  // Just to help g++-2.95...
192  rvalue operator()(const psite& p) const;
193  lvalue operator()(const psite& p);
194  // ...because "using super_::operator()" does not properly work.
195 
196  };
197 
198 
200  template <typename P, typename V, typename G, typename J>
201  void init_(tag::image_t, vertex_image<P,V,G>& target, const Image<J>& model);
203 
204 
205 # ifndef MLN_INCLUDE_ONLY
206 
207  template <typename P, typename V, typename G, typename J>
208  void init_(tag::image_t, vertex_image<P,V,G>& target, const Image<J>& model)
209  {
211  init_(tag::function, f, exact(model));
213  init_(tag::domain, s, exact(model));
214  target.init_(f, s);
215  }
216 
217  // Operator.
218 
219  template <typename V, typename G, typename P>
220  inline
222  operator | (const fun::i2v::array<V>& vertex_values,
223  const p_vertices<G, fun::i2v::array<P> >& pv)
224  {
225  vertex_image<P,V,G> tmp(pv, vertex_values);
226  return tmp;
227  }
228 
229 
230 
231  // data< pw::image >
232 
233  namespace internal
234  {
235 
236  template <typename P, typename V, typename G>
237  template <typename F>
238  inline
239  data< mln::vertex_image<P,V,G> >::data(const fun::i2v::array<V>& f,
240  const p_vertices<G,F>& ps)
241  : f_(f),
242  domain_(ps)
243  {
244  }
245 
246  } // end of namespace mln::internal
247 
248 
249 
250  // vertex_image<P,V,G>
251 
252  template <typename P, typename V, typename G>
253  inline
254  vertex_image<P,V,G>::vertex_image()
255  {
256  }
257 
258  template <typename P, typename V, typename G>
259  inline
260  vertex_image<P,V,G>::vertex_image(const p_vertices<G,site_function_t>& pv)
261  : super_(fun::i2v::array<V>(pv.nsites()), pv)
262  {
263  }
264 
265  template <typename P, typename V, typename G>
266  inline
267  vertex_image<P,V,G>::vertex_image(const p_vertices<G,site_function_t>& pv,
268  const Function_v2v< fun::i2v::array<V> >& vertex_values)
269  : super_(exact(vertex_values), pv)
270  {
271  }
272 
273  template <typename P, typename V, typename G>
274  template <typename FV>
275  inline
276  vertex_image<P,V,G>::vertex_image(const p_vertices<G,site_function_t>& pv,
277  const Function_v2v<FV>& vertex_values)
278  : super_(convert::to<fun::i2v::array<V> >(exact(vertex_values)), pv)
279  {
280  mlc_equal(mln_result(FV),V)::check();
281  }
282 
283 // template <typename P, typename V, typename G>
284 // typename vertex_image<P,V,G>::rvalue
285 // vertex_image<P,V,G>::operator()(const util::vertex<G>& v) const
286 // {
287 // return this->data_->f_(v.id());
288 // }
289 
290 // template <typename P, typename V, typename G>
291 // typename vertex_image<P,V,G>::lvalue
292 // vertex_image<P,V,G>::operator()(const util::vertex<G>& v)
293 // {
294 // return this->data_->f_(v.id());
295 // }
296 
297  template <typename P, typename V, typename G>
298  typename vertex_image<P,V,G>::rvalue
299  vertex_image<P,V,G>::operator()(unsigned v_id) const
300  {
301  return this->data_->f_(v_id);
302  }
303 
304  template <typename P, typename V, typename G>
305  typename vertex_image<P,V,G>::lvalue
306  vertex_image<P,V,G>::operator()(unsigned v_id)
307  {
308  return this->data_->f_(v_id);
309  }
310 
311  template <typename P, typename V, typename G>
312  typename vertex_image<P,V,G>::rvalue
313  vertex_image<P,V,G>::operator()(const typename vertex_image<P,V,G>::psite& p) const
314  {
315  return this->super_::operator()(p);
316  }
317 
318  template <typename P, typename V, typename G>
319  typename vertex_image<P,V,G>::lvalue
320  vertex_image<P,V,G>::operator()(const typename vertex_image<P,V,G>::psite& p)
321  {
322  return this->super_::operator()(p);
323  }
324 
325 # endif // ! MLN_INCLUDE_ONLY
326 
327 } // end of namespace mln
328 
329 
330 #endif // ! MLN_CORE_IMAGE_VERTEX_IMAGE_HH