$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
labeling.cc
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 #include <mln/core/image/edge_image.hh>
27 #include <mln/core/image/vertex_image.hh>
28 
29 #include <mln/core/image/graph_elt_neighborhood_if.hh>
30 
31 #include <mln/data/fill.hh>
32 
33 #include <mln/util/graph.hh>
34 
35 #include <mln/value/label_8.hh>
36 
37 #include <mln/fun/i2v/array.hh>
38 
39 #include <mln/graph/labeling.hh>
40 #include <mln/graph/to_neighb.hh>
41 
42 
43 
44 static const unsigned result[] = { 1, 2, 2, 3, 2, 3 };
45 
46 
47 
48 int main()
49 {
50  using namespace mln;
51 
52  typedef util::graph G;
53 
54  /*--------.
55  | Graph. |
56  `--------*/
57 
58  /* The graph is as follows:
59 
60  _____
61  / \
62  0 1 2 - 3
63  \ / \ /
64  4 - 5
65 
66  */
67 
68  util::graph gr;
69  gr.add_vertices(6);
70  gr.add_edge(1,3);
71  gr.add_edge(1,4);
72  gr.add_edge(2,3);
73  gr.add_edge(2,4);
74  gr.add_edge(2,5);
75  gr.add_edge(3,5);
76  gr.add_edge(4,5);
77 
78 
79  typedef fun::i2v::array<point2d> fsite_t;
80  fsite_t fsite(6);
81  fsite(0) = point2d(0,0);
82  fsite(1) = point2d(2,2);
83  fsite(2) = point2d(4,2);
84  fsite(3) = point2d(6,2);
85  fsite(4) = point2d(2,4);
86  fsite(5) = point2d(2,6);
87 
88  // Create a vertex image.
89  typedef p_vertices<G,fsite_t> pv_t;
90  pv_t pv(gr, fsite);
91  typedef vertex_image<point2d,unsigned> v_ima_t;
92  v_ima_t v_ima(pv);
93  data::fill(v_ima, 4);
94 
95  // Create a mask on edges.
96  typedef p_edges<G> pe_t;
97  pe_t pe(gr);
98  typedef edge_image<void,bool> e_mask_t;
99  e_mask_t e_mask(pe);
100  mln_piter_(e_mask_t) em(e_mask.domain());
101  for_all(em)
102  e_mask(em) = em.id()%2;
103 
104  typedef graph_elt_neighborhood_if<util::graph, pv_t, e_mask_t> nbh_t;
105  nbh_t nbh = graph::to_neighb(v_ima, e_mask);
106 
107  value::label_8 nlabels;
108  typedef mln_ch_value_(v_ima_t,value::label_8) lbl_t;
109  lbl_t lbl = graph::labeling(v_ima, nbh, nlabels);
110 
111  unsigned i = 0;
112  mln_piter_(lbl_t) p(lbl.domain());
113  for_all(p)
114  mln_assertion(result[i++] == lbl(p));
115 }