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