$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends 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  mln_trace("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  return ima;
150  }
151 
152  template <typename FV, typename G>
154  edge_image(const Graph<G>& g_,
155  const Function_v2v<FV>& fv)
156  {
157  mln_trace("make::edge_image");
158  const G& g = exact(g_);
159  const FV& f = exact(fv);
160  mln_precondition(g.is_valid());
161 
162  p_edges<G> pe(g);
164  ima_t ima(pe);
165 
166  mln_piter(ima_t) e(ima.domain());
167  for_all(e)
168  ima(e) = f(e.id());
169 
170  return ima;
171  }
172 
173 
174  template <typename FP, typename FV, typename G>
175  inline
176  mln::edge_image<mln_result(FP),mln_result(FV),G>
177  edge_image(const Graph<G>& g_,
178  const Function_v2v<FP>& fp,
179  const Function_v2v<FV>& fv)
180  {
181  mln_trace("make::edge_image");
182  const G& g = exact(g_);
183  mln_precondition(g.is_valid());
184 
185  p_edges<G,FP> pe(g,fp);
187 
188  return ima;
189  }
190 
191 
192 
193  template <typename P, typename V, typename G, typename FP, typename FV>
194  inline
196  edge_image(const mln::vertex_image<P,V,G>& v_ima_,
197  const p_edges<G,FP> pe,
198  const Function_vv2v<FV>& fv_)
199  {
200  mln_trace("make::edge_image");
201 
202  const FV& fv = exact(fv_);
203  const mln::vertex_image<P,V,G>& v_ima = exact(v_ima_);
204  mln_precondition(v_ima.is_valid());
205 
207  edge_ima_t ima_e(pe);
208 
209  mln_piter(edge_ima_t) e(ima_e.domain());
210  for_all(e)
211  ima_e(e) = fv(e.element().v1(), e.element().v2());
212 
213  return ima_e;
214  }
215 
216 
217 
218  template <typename P, typename V, typename G, typename FV>
219  inline
220  mln::edge_image<void,mln_result(FV),G>
221  edge_image(const mln::vertex_image<P,V,G>& v_ima_,
222  const Function_vv2v<FV>& fv_)
223  {
224  mln_trace("make::edge_image");
225 
226  const FV& fv = exact(fv_);
227  const mln::vertex_image<P,V,G>& v_ima = exact(v_ima_);
228  mln_precondition(v_ima.is_valid());
229 
230  p_edges<G> pe(v_ima.domain().graph());
231  typedef mln::edge_image<void,mln_result(FV),G> edge_ima_t;
232  edge_ima_t ima_e(pe);
233 
234  mln_piter(edge_ima_t) e(ima_e.domain());
235  for_all(e)
236  ima_e(e) = fv(v_ima(e.element().v1()), v_ima(e.element().v2()));
237 
238  return ima_e;
239  }
240 
241 
242  template <typename P, typename V, typename G, typename F>
243  inline
244  mln::edge_image<void,bool,G>
245  edge_image(const mln::vertex_image<P,V,G>& v_ima_,
246  const Function_v2b<F>& fv_)
247  {
248  mln_trace("make::edge_image");
249 
250  const F& fv = exact(fv_);
251  typedef mln::vertex_image<P,V,G> v_ima_t;
252  const v_ima_t& v_ima = exact(v_ima_);
253  mln_precondition(v_ima.is_valid());
254 
255  p_edges<G> pe(v_ima.domain().graph());
256  typedef mln::edge_image<void,bool,G> edge_ima_t;
257  edge_ima_t ima_e(pe);
258  data::fill(ima_e, true);
259 
260  mln_piter(v_ima_t) p(v_ima.domain());
261  for_all(p)
262  if (!fv(v_ima(p)))
263  {
264  typename v_ima_t::edge_win_t win;
265  mln_qiter(v_ima_t::edge_win_t) q(win, p);
266  for_all(q)
267  ima_e(q) = false;
268  }
269 
270  return ima_e;
271  }
272 
273 
274 
275 # endif // ! MLN_INCLUDE_ONLY
276 
277 
278  } // end of namespace mln::make
279 
280 } // end of namespace mln
281 
282 #endif // ! MLN_MAKE_EDGE_IMAGE_HH