Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
make/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_MAKE_EDGE_IMAGE_HH
27 # define MLN_MAKE_EDGE_IMAGE_HH
28 
32 
33 # include <mln/core/image/edge_image.hh>
34 # include <mln/core/image/vertex_image.hh>
35 # include <mln/core/concept/function.hh>
36 # include <mln/util/internal/id2element.hh>
37 # include <mln/data/fill.hh>
38 
39 
40 namespace mln
41 {
42 
43  namespace make
44  {
45 
46 
53  //
54  template <typename V, typename G>
56  edge_image(const Graph<G>& g, const fun::i2v::array<V>& fv);
57 
64  //
65  template <typename FV, typename G>
67  edge_image(const Graph<G>& g, const Function_v2v<FV>& fv);
68 
69 
77  //
78  template <typename FP, typename FV, typename G>
80  edge_image(const Graph<G>& g_,
81  const Function_v2v<FP>& fp,
82  const Function_v2v<FV>& fv);
83 
84 
85 
94  //
95  template <typename P, typename V, typename G, typename FP, typename FV>
98  const p_edges<G,FP> pe,
99  const Function_vv2v<FV>& fv_);
100 
101 
102 
111  //
112  template <typename P, typename V, typename G, typename FV>
114  edge_image(const mln::vertex_image<P,V,G>& v_ima_,
115  const Function_vv2v<FV>& fv_);
116 
117 
127  //
128  template <typename P, typename V, typename G, typename F>
130  edge_image(const mln::vertex_image<P,V,G>& v_ima_,
131  const Function_v2b<F>& fv_);
132 
133 
134 # ifndef MLN_INCLUDE_ONLY
135 
136 
137 
138  template <typename V, typename G>
139  inline
141  edge_image(const Graph<G>& g, const fun::i2v::array<V>& fv)
142  {
143  trace::entering("make::edge_image");
144  mln_precondition(exact(g).is_valid());
145 
146  p_edges<G> pe(g);
147  mln::edge_image<void,V,G> ima(pe, fv);
148 
149  trace::exiting("make::edge_image");
150  return ima;
151  }
152 
153  template <typename FV, typename G>
155  edge_image(const Graph<G>& g_,
156  const Function_v2v<FV>& fv)
157  {
158  trace::entering("make::edge_image");
159  const G& g = exact(g_);
160  const FV& f = exact(fv);
161  mln_precondition(g.is_valid());
162 
163  p_edges<G> pe(g);
165  ima_t ima(pe);
166 
167  mln_piter(ima_t) e(ima.domain());
168  for_all(e)
169  ima(e) = f(e.id());
170 
171  trace::exiting("make::edge_image");
172  return ima;
173  }
174 
175 
176  template <typename FP, typename FV, typename G>
177  inline
179  edge_image(const Graph<G>& g_,
180  const Function_v2v<FP>& fp,
181  const Function_v2v<FV>& fv)
182  {
183  trace::entering("make::edge_image");
184  const G& g = exact(g_);
185  mln_precondition(g.is_valid());
186 
187  p_edges<G,FP> pe(g,fp);
189 
190  trace::exiting("make::edge_image");
191  return ima;
192  }
193 
194 
195 
196  template <typename P, typename V, typename G, typename FP, typename FV>
197  inline
200  const p_edges<G,FP> pe,
201  const Function_vv2v<FV>& fv_)
202  {
203  trace::entering("make::edge_image");
204 
205  const FV& fv = exact(fv_);
206  const mln::vertex_image<P,V,G>& v_ima = exact(v_ima_);
207  mln_precondition(v_ima.is_valid());
208 
210  edge_ima_t ima_e(pe);
211 
212  mln_piter(edge_ima_t) e(ima_e.domain());
213  for_all(e)
214  ima_e(e) = fv(e.element().v1(), e.element().v2());
215 
216  trace::exiting("make::edge_image");
217  return ima_e;
218  }
219 
220 
221 
222  template <typename P, typename V, typename G, typename FV>
223  inline
226  const Function_vv2v<FV>& fv_)
227  {
228  trace::entering("make::edge_image");
229 
230  const FV& fv = exact(fv_);
231  const mln::vertex_image<P,V,G>& v_ima = exact(v_ima_);
232  mln_precondition(v_ima.is_valid());
233 
234  p_edges<G> pe(v_ima.domain().graph());
235  typedef mln::edge_image<void,mln_result(FV),G> edge_ima_t;
236  edge_ima_t ima_e(pe);
237 
238  mln_piter(edge_ima_t) e(ima_e.domain());
239  for_all(e)
240  ima_e(e) = fv(v_ima(e.element().v1()), v_ima(e.element().v2()));
241 
242  trace::exiting("make::edge_image");
243  return ima_e;
244  }
245 
246 
247  template <typename P, typename V, typename G, typename F>
248  inline
251  const Function_v2b<F>& fv_)
252  {
253  trace::entering("make::edge_image");
254 
255  const F& fv = exact(fv_);
256  typedef mln::vertex_image<P,V,G> v_ima_t;
257  const v_ima_t& v_ima = exact(v_ima_);
258  mln_precondition(v_ima.is_valid());
259 
260  p_edges<G> pe(v_ima.domain().graph());
261  typedef mln::edge_image<void,bool,G> edge_ima_t;
262  edge_ima_t ima_e(pe);
263  data::fill(ima_e, true);
264 
265  mln_piter(v_ima_t) p(v_ima.domain());
266  for_all(p)
267  if (!fv(v_ima(p)))
268  {
269  typename v_ima_t::edge_win_t win;
270  mln_qiter(v_ima_t::edge_win_t) q(win, p);
271  for_all(q)
272  ima_e(q) = false;
273  }
274 
275  trace::exiting("make::edge_image");
276  return ima_e;
277  }
278 
279 
280 
281 # endif // ! MLN_INCLUDE_ONLY
282 
283 
284  } // end of namespace mln::make
285 
286 } // end of namespace mln
287 
288 #endif // ! MLN_MAKE_EDGE_IMAGE_HH