$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tree_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.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_to_image.hh>
37 #include <mln/debug/println.hh>
38 
39 template <typename P, typename V>
40 struct fllt_node
41 {
42  V value;
43  mln::p_set<P> points;
44  mln::p_set<P> holes;
45 };
46 
47 
48 int main (void)
49 {
50  using namespace mln;
51  using value::int_u8;
52 
53  typedef fllt_node<point2d , int_u8> I;
54 
55  image2d<int_u8> output (16, 16);
56  data::fill(output, 0);
57 
58  I s1;
59  I s2;
60  I s3;
61  I s4;
62  I s5;
63  I s6;
64  I s7;
65 
66  for (int i = 0; i < 4; ++i)
67  for (int j = 0; j < 4; ++j)
68  s1.points.insert(point2d(i, j));
69  s1.value = 60;
70  for (int i = 8; i < 16; ++i)
71  for (int j = 0; j < 4; ++j)
72  s2.points.insert(point2d(i, j));
73  s1.value = 100;
74  for (int i = 0; i < 4; ++i)
75  for (int j = 0; j < 4; ++j)
76  s3.points.insert(point2d(i, j));
77  s3.value = 110;
78  for (int i = 10; i < 12; ++i)
79  for (int j = 0; j < 2; ++j)
80  s4.points.insert(point2d(i, j));
81  s4.value = 170;
82  for (int i = 8; i < 14; ++i)
83  for (int j = 0; j < 2; ++j)
84  s5.points.insert(point2d(i, j));
85  s5.value = 180;
86  for (int i = 13; i < 15; ++i)
87  for (int j = 2; j < 4; ++j)
88  s6.points.insert(point2d(i, j));
89  s6.value = 210;
90  for (int i = 0; i < 16; ++i)
91  for (int j = 0; j < 8; ++j)
92  s7.points.insert(point2d(i, j));
93  s7.value = 10;
94 
95  util::tree_node<I> node(s1);
96  node.add_child(s2);
97  node.add_child(s3);
98  node.add_child(s4);
99  node.add_child(s5);
100  node.add_child(s6);
101  util::tree<I> tree (&node);
102  tree.add_tree_up(s7);
103  util::tree_to_image(tree, output);
104 
105  int_u8 vs[16][16] = {
106 
107 
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  {110, 110, 110, 110, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
111  {110, 110, 110, 110, 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  { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
115  { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
116  {180, 180, 252, 252, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
117  {180, 180, 252, 252, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
118  {180, 180, 252, 252, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
119  {180, 180, 252, 252, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
120  {180, 180, 252, 252, 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  {252, 252, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
123  {252, 252, 252, 252, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0}
124 
125  };
126 
127  image2d<int_u8> ref (make::image(vs));
128  mln_assertion(ref == output);
129 }