$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
compute_parent.cc
1 // Copyright (C) 2008, 2009, 2014 EPITA Research and Development
2 // Laboratory (LRDE).
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #include <mln/core/image/image2d.hh>
28 #include <mln/core/alias/neighb2d.hh>
29 #include <mln/core/image/dmorph/image_if.hh>
30 #include <mln/core/site_set/p_array.hh>
31 
32 #include <mln/data/sort_psites.hh>
33 #include <mln/data/compare.hh>
34 #include <mln/pw/value.hh>
35 #include <mln/debug/println.hh>
36 
37 #include <mln/morpho/tree/compute_parent.hh>
38 
39 
40 static mln::image2d<mln::point2d> ref1()
41 {
42  using namespace mln;
43 
44  image2d<point2d> ref1(make::box2d(3,3));
45 
46  ref1(point2d(0,0)) = point2d(0,0);
47  ref1(point2d(0,1)) = point2d(0,0);
48  ref1(point2d(0,2)) = point2d(0,0);
49  ref1(point2d(1,1)) = point2d(0,0);
50  ref1(point2d(2,2)) = point2d(2,2);
51 
52  return ref1;
53 }
54 
55 
56 static mln::image2d<mln::point2d> ref2()
57 {
58  using namespace mln;
59 
60  image2d<point2d> ref2(make::box2d(3,3));
61 
62  ref2(point2d(0,0)) = point2d(0,1);
63  ref2(point2d(0,1)) = point2d(0,2);
64  ref2(point2d(0,2)) = point2d(0,2);
65  ref2(point2d(1,0)) = point2d(0,0);
66  ref2(point2d(1,1)) = point2d(0,1);
67  ref2(point2d(1,2)) = point2d(0,1);
68  ref2(point2d(2,0)) = point2d(0,0);
69  ref2(point2d(2,1)) = point2d(0,0);
70  ref2(point2d(2,2)) = point2d(0,2);
71 
72  return ref2;
73 }
74 
75 
76 int main()
77 {
78  using namespace mln;
79 
80  {
81  bool vals[] = { 1, 1, 1,
82  0, 1, 0,
83  0, 0, 1 };
84  image2d<bool> ima = make::image2d(vals);
86  sub_t sub = ima | pw::value(ima);
87 
89  par_t par = morpho::tree::compute_parent(sub, c4(), sub.domain());
90  mln_assertion(par == (ref1() | sub.domain()));
91  }
92 
93  {
94  unsigned char vals[] = { 3, 2, 1,
95  3, 2, 3,
96  3, 4, 1 };
98 
99  typedef p_array<point2d> S;
100  S s = data::sort_psites_increasing(ima);
102  mln_assertion(par == ref2());
103  }
104 
105 }