$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
data.cc
1 // Copyright (C) 2008, 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/image2d.hh>
27 #include <mln/core/alias/neighb2d.hh>
28 #include <mln/core/site_set/p_array.hh>
29 
30 #include <mln/data/sort_psites.hh>
31 #include <mln/debug/println.hh>
32 
33 #include <mln/morpho/tree/data.hh>
34 
35 
36 int main()
37 {
38  using namespace mln;
39 
40  typedef image2d<unsigned char> I;
41 // unsigned char vals[] = { 3, 2, 1,
42 // 3, 2, 3,
43 // 3, 4, 1 };
44 
45  unsigned char vals[] = { 3, 3, 3,
46  3, 4, 4,
47  3, 4, 4 };
48 
49  I ima = make::image2d(vals);
50 
51  debug::println("ima = ", ima);
52 
53  typedef p_array<point2d> S;
55 
56  typedef morpho::tree::data<I,S> tree_t;
57  tree_t t(ima, s, c4());
58 
59  debug::println( "parent = ", t.parent_image() | t.domain() );
60  debug::println( "on node = ", t.parent_image() | t.nodes() );
61  debug::println( "on leaves = ", t.parent_image() | t.leaves() );
62 
63  {
64  /* Check site and node up order */
65  tree_t::up_node_piter n(t);
66  tree_t::up_site_piter s(t);
67  tree_t::up_leaf_piter l(t);
68  n.start();
69  l.start();
70  for_all(s)
71  if (t.is_a_node(s))
72  {
73  mln_assertion(s == n);
74  if (t.is_a_leaf(n))
75  {
76  mln_assertion(l == n);
77  l.next();
78  }
79  n.next();
80  }
81  mln_assertion(!n.is_valid() && !s.is_valid() && !l.is_valid());
82  }
83 
84  {
85  /* Check site and node up order */
86  tree_t::dn_node_piter n(t);
87  tree_t::dn_site_piter s(t);
88  tree_t::dn_leaf_piter l(t);
89  n.start();
90  l.start();
91  for_all(s)
92  if (t.is_a_node(s))
93  {
94  mln_assertion(s == n);
95  if (t.is_a_leaf(n))
96  {
97  mln_assertion(l == n);
98  l.next();
99  }
100  n.next();
101  }
102  mln_assertion(!n.is_valid() && !s.is_valid() && !l.is_valid());
103  }
104 
105 
106  {
107  std::cout << "nodes = ";
108  tree_t::up_node_piter n(t);
109  for_all(n)
110  std::cout << n << ' ';
111  std::cout << std::endl
112  << std::endl;
113  }
114 
115 
116  {
117  image2d<unsigned> area(ima.domain());
118  data::fill(area, 1);
119  tree_t::up_site_piter p(t);
120  for_all(p)
121  if (! t.is_root(p))
122  area(t.parent(p)) += area(p);
123  debug::println("area = ", area | t.nodes());
124  }
125 
126 }