Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
core/image/vertex_image.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_CORE_IMAGE_VERTEX_IMAGE_HH
27 # define MLN_CORE_IMAGE_VERTEX_IMAGE_HH
28 
32 
33 # include <mln/core/concept/graph.hh>
34 # include <mln/core/image/graph_elt_window.hh>
35 # include <mln/core/image/graph_elt_neighborhood.hh>
36 # include <mln/core/image/graph_elt_mixed_neighborhood.hh>
37 # include <mln/core/site_set/p_vertices.hh>
38 # include <mln/pw/internal/image_base.hh>
39 # include <mln/fun/i2v/array.hh>
40 
41 # include <mln/util/internal/id2element.hh>
42 
43 
44 namespace mln
45 {
46 
47  // Forward declaration.
48  template <typename P, typename V, typename G> class vertex_image;
49  namespace util { class graph; }
50 
51 
52  // Properties
53 
54  namespace trait
55  {
56 
57  template <typename P, typename V, typename G>
58  struct image_< vertex_image<P,V,G> >
59  : pw_image_<fun::i2v::array<V>,
60  p_vertices<util::graph, fun::i2v::array<P> >,
61  vertex_image<P,V,G> >
62  {
63  };
64 
65  } // end of namespace mln::traits.
66 
67 
68 
69  namespace internal
70  {
71 
73  template <typename P, typename V, typename G>
74  struct data< mln::vertex_image<P,V,G> >
75  {
76  typedef typename vertex_image<P,V,G>::site_function_t site_function_t;
77 
78  template <typename F>
79  data(const fun::i2v::array<V>& vertex_values,
80  const p_vertices<G,F>& pv);
81 
82  fun::i2v::array<V> f_;
83  p_vertices<G,site_function_t> domain_;
84  };
85 
86  } // end of namespace mln::internal
87 
88 
89 
92  template <typename V, typename G, typename P>
93  vertex_image<P,V,G>
94  operator | (const fun::i2v::array<V>& vertex_values,
95  const p_vertices<G,fun::i2v::array<P> >& pv);
96 
97 
98  // Vertex_image_fsite_selector
99 
100  namespace internal
101  {
102 
103  template <typename P, typename G>
104  struct vfsite_selector
105  {
106  typedef fun::i2v::array<P> site_function_t;
107  };
108 
109 
110 
111  template <typename G>
112  struct vfsite_selector<void,G>
113  {
114  typedef util::internal::id2element< G,util::vertex<G> > site_function_t;
115  };
116 
117 
118  } // end of namespace mln::internal
119 
120 
124  //
125  template <typename P, typename V, typename G = util::graph>
127  : public pw::internal::image_base<fun::i2v::array<V>,
128  p_vertices<G, typename internal::vfsite_selector<P,G>::site_function_t >,
129  vertex_image<P,V,G> >
130  {
131  typedef pw::internal::image_base<fun::i2v::array<V>,
133  vertex_image<P,V,G> > super_;
134 
135  public:
136  typedef typename super_::psite psite;
137  typedef typename super_::rvalue rvalue;
138  typedef typename super_::lvalue lvalue;
139 
141  typedef G graph_t;
142 
144  typedef typename internal::vfsite_selector<P,G>::site_function_t
146  typedef mln_result(site_function_t) function_result_t;
147 
148 
150  typedef vertex_image< tag::psite_<P>,
151  tag::value_<V>,
152  tag::graph_<G> > skeleton;
153 
154  typedef p_vertices<G,site_function_t> S;
155 
157  typedef graph_elt_window<G,S> vertex_win_t;
158 
161 
163  typedef vertex_win_t win_t;
165  typedef vertex_nbh_t nbh_t;
166 
167 
168 
171  vertex_image();
172  vertex_image(const p_vertices<G, site_function_t>& pv);
174  const Function_v2v< fun::i2v::array<V> >& vertex_values);
175  template <typename FV>
177  const Function_v2v<FV>& vertex_values);
179 
182  rvalue operator()(unsigned v_id) const;
183  lvalue operator()(unsigned v_id);
185 
186 
187  // Just to help g++-2.95...
188  rvalue operator()(const psite& p) const;
189  lvalue operator()(const psite& p);
190  // ...because "using super_::operator()" does not properly work.
191 
192  };
193 
194  template <typename P, typename V, typename G, typename J>
195  void init_(tag::image_t, vertex_image<P,V,G>& target, const Image<J>& model);
196 
197 
198 # ifndef MLN_INCLUDE_ONLY
199 
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)
202  {
203  fun::i2v::array<V> f;
204  init_(tag::function, f, exact(model));
206  init_(tag::domain, s, exact(model));
207  target.init_(f, s);
208  }
209 
210  // Operator.
211 
212  template <typename V, typename G, typename P>
213  inline
215  operator | (const fun::i2v::array<V>& vertex_values,
216  const p_vertices<G, fun::i2v::array<P> >& pv)
217  {
218  vertex_image<P,V,G> tmp(pv, vertex_values);
219  return tmp;
220  }
221 
222 
223 
224  // data< pw::image >
225 
226  namespace internal
227  {
228 
229  template <typename P, typename V, typename G>
230  template <typename F>
231  inline
232  data< mln::vertex_image<P,V,G> >::data(const fun::i2v::array<V>& f,
233  const p_vertices<G,F>& ps)
234  : f_(f),
235  domain_(ps)
236  {
237  }
238 
239  } // end of namespace mln::internal
240 
241 
242 
243  // vertex_image<P,V,G>
244 
245  template <typename P, typename V, typename G>
246  inline
248  {
249  }
250 
251  template <typename P, typename V, typename G>
252  inline
254  : super_(fun::i2v::array<V>(pv.nsites()), pv)
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  const Function_v2v< fun::i2v::array<V> >& vertex_values)
262  : super_(exact(vertex_values), pv)
263  {
264  }
265 
266  template <typename P, typename V, typename G>
267  template <typename FV>
268  inline
269  vertex_image<P,V,G>::vertex_image(const p_vertices<G,site_function_t>& pv,
270  const Function_v2v<FV>& vertex_values)
271  : super_(convert::to<fun::i2v::array<V> >(exact(vertex_values)), pv)
272  {
273  mlc_equal(mln_result(FV),V)::check();
274  }
275 
276 // template <typename P, typename V, typename G>
277 // typename vertex_image<P,V,G>::rvalue
278 // vertex_image<P,V,G>::operator()(const util::vertex<G>& v) const
279 // {
280 // return this->data_->f_(v.id());
281 // }
282 
283 // template <typename P, typename V, typename G>
284 // typename vertex_image<P,V,G>::lvalue
285 // vertex_image<P,V,G>::operator()(const util::vertex<G>& v)
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>::rvalue
292  vertex_image<P,V,G>::operator()(unsigned v_id) const
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>::lvalue
299  vertex_image<P,V,G>::operator()(unsigned v_id)
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>::rvalue
306  vertex_image<P,V,G>::operator()(const typename vertex_image<P,V,G>::psite& p) const
307  {
308  return this->super_::operator()(p);
309  }
310 
311  template <typename P, typename V, typename G>
312  typename vertex_image<P,V,G>::lvalue
313  vertex_image<P,V,G>::operator()(const typename vertex_image<P,V,G>::psite& p)
314  {
315  return this->super_::operator()(p);
316  }
317 
318 # endif // ! MLN_INCLUDE_ONLY
319 
320 } // end of namespace mln
321 
322 
323 #endif // ! MLN_CORE_IMAGE_VERTEX_IMAGE_HH