Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
core/image/edge_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_EDGE_IMAGE_HH
27 # define MLN_CORE_IMAGE_EDGE_IMAGE_HH
28 
32 
33 # include <mln/core/concept/graph.hh>
34 # include <mln/core/site_set/p_edges.hh>
35 # include <mln/core/image/graph_elt_window.hh>
36 # include <mln/core/image/graph_elt_neighborhood.hh>
37 # include <mln/pw/internal/image_base.hh>
38 # include <mln/fun/i2v/array.hh>
39 
40 
41 
42 namespace mln
43 {
44  // Forward declaration.
45  template <typename P, typename V, typename G> class edge_image;
46  namespace util { class graph; }
47 
48 
49  // Properties
50 
51  namespace trait
52  {
53 
54  template <typename P, typename V, typename G>
55  struct image_< edge_image<P,V,G> >
56  : pw_image_<fun::i2v::array<V>,
57  p_edges<util::graph, fun::i2v::array<P> >,
58  edge_image<P,V,G> >
59  {
60  };
61 
62  } // end of namespace mln::traits.
63 
64 
65 
66  namespace internal
67  {
68 
70  template <typename P, typename V, typename G>
71  struct data< mln::edge_image<P,V,G> >
72  {
73  typedef typename edge_image<P,V,G>::site_function_t site_function_t;
74 
75  data(const fun::i2v::array<V>& edge_values,
76  const p_edges<G,site_function_t>& pe);
77 
78  fun::i2v::array<V> f_;
79  p_edges<G,site_function_t> domain_;
80  };
81 
82  } // end of namespace mln::internal
83 
84 
85 
86 
89  template <typename V, typename G, typename P>
90  edge_image<P,V,G>
91  operator | (const fun::i2v::array<V>& edge_values,
92  const p_edges<G,fun::i2v::array<P> >& pe);
93 
94 
95  // Vertex_image_fsite_selector
96 
97  namespace internal
98  {
99 
100  template <typename P, typename G>
101  struct efsite_selector
102  {
103  typedef fun::i2v::array<P> site_function_t;
104  };
105 
106 
107 
108  template <typename G>
109  struct efsite_selector<void,G>
110  {
111  typedef util::internal::id2element< G,util::edge<G> > site_function_t;
112  };
113 
114 
115  } // end of namespace mln::internal
116 
117 
121  //
122  template <typename P, typename V, typename G = util::graph>
124  : public pw::internal::image_base<fun::i2v::array<V>,
125  p_edges<G, typename internal::efsite_selector<P,G>::site_function_t >,
126  edge_image<P,V,G> >
127  {
128  typedef pw::internal::image_base<fun::i2v::array<V>,
130  edge_image<P,V,G> > super_;
131 
132  public:
133  typedef typename super_::psite psite;
134  typedef typename super_::rvalue rvalue;
135  typedef typename super_::lvalue lvalue;
136 
138  typedef G graph_t;
139 
142  tag::value_<V>,
143  tag::graph_<G> > skeleton;
144 
146  typedef typename internal::efsite_selector<P,G>::site_function_t
148  typedef mln_result(site_function_t) function_result_t;
149 
154 
156  typedef edge_win_t win_t;
157 
159  typedef edge_nbh_t nbh_t;
160 
161 
164  edge_image();
165  edge_image(const p_edges<G, site_function_t>& pe);
166  edge_image(const Graph<G>& g,
167  const Function_v2v< site_function_t >& edge_sites,
168  const Function_v2v< fun::i2v::array<V> >& edge_values);
169 
170  edge_image(const p_edges<G, site_function_t >& pe,
171  const Function_v2v< fun::i2v::array<V> >& edge_values);
172 
173  template <typename FP, typename FV>
174  edge_image(const Graph<G>& g,
175  const Function_v2v<FP>& edge_sites,
176  const Function_v2v<FV>& edge_values);
177 
178  template <typename FV>
179  edge_image(const p_edges<G,site_function_t>& pe,
180  const Function_v2v<FV>& edge_values);
182 
185  rvalue operator()(unsigned e_id) const;
186  lvalue operator()(unsigned e_id);
188 
189  // Just to help g++-2.95...
190  rvalue operator()(const psite& p) const;
191  lvalue operator()(const psite& p);
192  // ...because "using super_::operator()" does not properly work.
193 
194  };
195 
196  template <typename P, typename V, typename G, typename J>
197  void init_(tag::image_t, edge_image<P,V,G>& target, const Image<J>& model);
198 
199 
200 # ifndef MLN_INCLUDE_ONLY
201 
202  template <typename P, typename V, typename G, typename J>
203  void init_(tag::image_t, edge_image<P,V,G>& target, const Image<J>& model)
204  {
205  fun::i2v::array<V> f;
206  init_(tag::function, f, exact(model));
208  init_(tag::domain, s, exact(model));
209  target.init_(f, s);
210  }
211 
212  // Operator.
213 
214  template <typename V, typename G, typename P>
215  inline
217  operator | (const fun::i2v::array<V>& edge_values,
218  const p_edges<G,fun::i2v::array<P> >& pe)
219  {
220  edge_image<P,V,G> tmp(edge_values, pe);
221  return tmp;
222  }
223 
224 
225 
226  // data< pw::image >
227 
228  namespace internal
229  {
230 
231  template <typename P, typename V, typename G>
232  inline
233  data< mln::edge_image<P,V,G> >::data(const fun::i2v::array<V>& f,
234  const p_edges<G,site_function_t>& ps)
235  : f_(exact(f)),
236  domain_(ps)
237  {
238  }
239 
240  } // end of namespace mln::internal
241 
242 
243 
244  // edge_image<P,V,G>
245 
246  template <typename P, typename V, typename G>
247  inline
249  {
250  }
251 
252  template <typename P, typename V, typename G>
253  inline
255  : super_(fun::i2v::array<V>(pe.nsites()), pe)
256  {
257  }
258 
259  template <typename P, typename V, typename G>
260  inline
261  edge_image<P,V,G>::edge_image(const Graph<G>& g,
262  const Function_v2v< site_function_t >& edge_sites,
263  const Function_v2v< fun::i2v::array<V> >& edge_values)
264  : super_(exact(edge_values),
265  p_edges<G,site_function_t>(g, exact(edge_sites)))
266  {
267  }
268 
269  template <typename P, typename V, typename G>
270  inline
271  edge_image<P,V,G>::edge_image(const p_edges<G,site_function_t>& pe,
272  const Function_v2v< fun::i2v::array<V> >& edge_values)
273  : super_(exact(edge_values), pe)
274  {
275  }
276 
277  template <typename P, typename V, typename G>
278  template <typename FP, typename FV>
279  inline
280  edge_image<P,V,G>::edge_image(const Graph<G>& g,
281  const Function_v2v<FP>& edge_sites,
282  const Function_v2v<FV>& edge_values)
283  : super_(convert::to<fun::i2v::array<V> >(exact(edge_values)),
284  p_edges<G,site_function_t>(g, exact(edge_sites)))
285  {
286  mlc_equal(mln_result(FP),P)::check();
287  mlc_equal(mln_result(FV),V)::check();
288  }
289 
290  template <typename P, typename V, typename G>
291  template <typename FV>
292  inline
293  edge_image<P,V,G>::edge_image(const p_edges<G,site_function_t>& pe,
294  const Function_v2v<FV>& edge_values)
295  : super_(convert::to<fun::i2v::array<V> >(exact(edge_values)), pe)
296  {
297  mlc_equal(mln_result(FV),V)::check();
298  }
299 
300  template <typename P, typename V, typename G>
301  typename edge_image<P,V,G>::rvalue
302  edge_image<P,V,G>::operator()(unsigned e_id) const
303  {
304  return this->data_->f_(e_id);
305  }
306 
307  template <typename P, typename V, typename G>
308  typename edge_image<P,V,G>::lvalue
309  edge_image<P,V,G>::operator()(unsigned e_id)
310  {
311  return this->data_->f_(e_id);
312  }
313 
314  template <typename P, typename V, typename G>
315  typename edge_image<P,V,G>::rvalue
316  edge_image<P,V,G>::operator()(const typename edge_image<P,V,G>::psite& p) const
317  {
318  return this->super_::operator()(p);
319  }
320 
321  template <typename P, typename V, typename G>
322  typename edge_image<P,V,G>::lvalue
323  edge_image<P,V,G>::operator()(const typename edge_image<P,V,G>::psite& p)
324  {
325  return this->super_::operator()(p);
326  }
327 
328 # endif // ! MLN_INCLUDE_ONLY
329 
330 } // end of namespace mln
331 
332 
333 #endif // ! MLN_CORE_IMAGE_EDGE_IMAGE_HH