$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tree_fast_to_image.cc
1 // Copyright (C) 2007, 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/util/tree_fast.hh>
27 #include <mln/core/contract.hh>
28 #include <mln/core/image/image2d.hh>
29 #include <mln/core/site_set/p_set.hh>
30 #include <mln/value/int_u8.hh>
31 #include <mln/data/stretch.hh>
32 #include <mln/data/fill.hh>
33 #include <mln/data/compare.hh>
34 #include <mln/io/pgm/save.hh>
35 #include <vector>
36 #include <mln/util/tree_fast_to_image.hh>
37 #include <mln/debug/println.hh>
38 
39 
40 template <typename P, typename V>
41 struct fllt_node
42 {
43  V value;
44  mln::p_set<P> points;
45  mln::p_set<P> holes;
46 };
47 
48 
49 int main()
50 {
51  using namespace mln;
52  using value::int_u8;
53 
54  typedef fllt_node<point2d , int_u8> I;
55 
56  I s1;
57  I s2;
58  I s3;
59  I s4;
60  I s5;
61  I s6;
62  I s7;
63 
64  for (int i = 0; i < 4; ++i)
65  for (int j = 0; j < 4; ++j)
66  s1.points.insert(point2d(i, j));
67  s1.value = 60;
68  for (int i = 8; i < 16; ++i)
69  for (int j = 0; j < 4; ++j)
70  s2.points.insert(point2d(i, j));
71  s1.value = 100;
72  for (int i = 0; i < 4; ++i)
73  for (int j = 0; j < 4; ++j)
74  s3.points.insert(point2d(i, j));
75  s3.value = 110;
76  for (int i = 10; i < 12; ++i)
77  for (int j = 0; j < 2; ++j)
78  s4.points.insert(point2d(i, j));
79  s4.value = 170;
80  for (int i = 8; i < 16; ++i)
81  for (int j = 0; j < 2; ++j)
82  s5.points.insert(point2d(i, j));
83  s5.value = 180;
84  for (int i = 8; i < 16; ++i)
85  for (int j = 2; j < 4; ++j)
86  s6.points.insert(point2d(i, j));
87  s6.value = 210;
88  for (int i = 0; i < 16; ++i)
89  for (int j = 0; j < 8; ++j)
90  s7.points.insert(point2d(i, j));
91  s7.value = 10;
92 
93  util::tree_fast<I> tree(s1);
94  tree.add_child(tree.root_, s2);
95  tree.add_child(tree.root_, s3);
96  tree.add_child(tree.root_, s4);
97  tree.add_child(tree.root_, s5);
98  tree.add_child(tree.root_, s6);
99  tree.add_parent(s7);
100  image2d<int_u8> output (16, 16);
101  data::fill(output, 0);
102  util::tree_fast_to_image(tree, output);
103 
104  int_u8 vs[16][16] = {
105 
106  {110, 110, 110, 110, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
107  {110, 110, 110, 110, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
108  {110, 110, 110, 110, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
109  {110, 110, 110, 110, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
110  { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
111  { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
112  { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
113  { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
114  {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
115  {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
116  {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
117  {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
118  {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
119  {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
120  {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
121  {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0}
122 
123  };
124 
125  debug::println(output);
126  image2d<int_u8> ref (make::image(vs));
127  mln_assertion(ref == output);
128 }