$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rag_and_labeled_wsl.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/alias/neighb2d.hh>
27 
28 #include <mln/util/graph.hh>
29 
30 #include <mln/value/label_8.hh>
31 
32 #include <mln/make/image2d.hh>
33 #include <mln/make/rag_and_labeled_wsl.hh>
34 
35 # include <mln/debug/println.hh>
36 
37 int main()
38 {
39  using namespace mln;
40 
41  value::label_8 vals[16] = { 1, 0, 3, 3,
42  1, 0, 0, 0,
43  0, 0, 4, 4,
44  2, 2, 0, 4 };
45 
46  typedef image2d<value::label_8> wst_t;
47  wst_t ima = make::image2d(vals);
48 
50  res = make::rag_and_labeled_wsl(ima, c4(), 4u);
51 
52  wst_t& lwsl = res.second();
53  util::graph& g = res.first();
54 
55  // check that adjacency labels map edge labels.
56  mln_piter_(wst_t) p(lwsl.domain());
57  mln_niter_(neighb2d) n(c4(),p);
58  for_all(p)
59  if (lwsl(p) != mln_max(value::label_8).prev())
60  {
61  value::label_8 l1 = 0, l2 = 0;
62  for_all(n)
63  if (ima.has(n) && ima(n) != 0u)
64  {
65  if (l1 == 0u) // First label to be stored.
66  l1 = ima(n);
67  else
68  if (ima(n) != l1) // Useless: && l2 == 0)
69  { // Second label to be stored.
70  mln_invariant(l2 == 0u);
71  l2 = ima(n);
72  break;
73  }
74  }
75  if (l2 < l1)
76  std::swap(l1, l2);
77  mln_assertion(g.v1(lwsl(p)) == l1);
78  mln_assertion(g.v2(lwsl(p)) == l2);
79  }
80 
81  mln_assertion(g.e_nmax() == 4u);
82  mln_assertion(g.v_nmax() == 5u);
83  mln_assertion(g.v_nmax_nbh_edges(0) == 0);
84  for (unsigned i = 1; i < 4; ++i)
85  mln_assertion(g.v_nmax_nbh_edges(i) == 2);
86 }