$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
find_full.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/core/image/image1d.hh>
27 #include <mln/core/image/image2d.hh>
28 #include <mln/core/image/image3d.hh>
29 #include <mln/core/image/dmorph/sub_image.hh>
30 
31 #include <mln/core/image/dmorph/image_if.hh>
32 #include <mln/fun/p2b/chess.hh>
33 #include <mln/border/find.hh>
34 #include <mln/literal/origin.hh>
35 #include <mln/value/int_u8.hh>
36 #include <mln/value/rgb8.hh>
37 
38 
39 #include <mln/debug/iota.hh>
40 #include <mln/border/find.hh>
41 #include <mln/core/routine/duplicate.hh>
42 
43 
44 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
45 {
46  f_box1d_t(const mln::box1d& b)
47  : b_(b)
48  {
49  }
50  mln::box1d b_;
51  bool operator()(const mln::point1d& p) const
52  {
53  return b_.has(p);
54  }
55 };
56 
57 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
58 {
59  f_box2d_t(const mln::box2d& b)
60  : b_(b)
61  {
62  }
63  mln::box2d b_;
64  bool operator()(const mln::point2d& p) const
65  {
66  return b_.has(p);
67  }
68 };
69 
70 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
71 {
72  f_box3d_t(const mln::box3d& b)
73  : b_(b)
74  {
75  }
76  mln::box3d b_;
77  bool operator()(const mln::point3d& p) const
78  {
79  return b_.has(p);
80  }
81 };
82 
83 
84 int main()
85 {
86  using namespace mln;
87 
89  box2d b2(literal::origin, point2d(1,1));
90  box3d b3(literal::origin, point3d(1,1,1));
91  f_box1d_t f_b1(b1);
92  f_box2d_t f_b2(b2);
93  f_box3d_t f_b3(b3);
95 
96  {
97  typedef image1d<int> I;
98  (std::cerr << "Tests border::find on int in 1d ... ").flush ();
99  I ima(3, 51);
100  debug::iota(ima);
101  mln_assertion(border::find(ima) == 51);
102  sub_image<I, box1d> sub(ima, b1);
103  mln_assertion(border::find(sub) == 51);
104 
105  image_if<I, f_box1d_t> imaif(ima, f_b1);
106  mln_assertion(border::find(imaif) == 51);
107 
108  mln_assertion(border::find( (ima | b1) ) == 51);
109  mln_assertion(border::find( (ima | b1) | f_b1 ) == 51);
110  std::cerr << "OK" << std::endl;
111  }
112 
113  {
114  typedef image2d<value::int_u8> I;
115  (std::cerr << "Tests border::find on int_u8 in 2d ... ").flush ();
116  I ima(10, 10, 42);
117  debug::iota(ima);
118  mln_assertion(border::find(ima) == 42);
119  sub_image<I, box2d> sub(ima, b2);
120  mln_assertion(border::find(sub) == 42);
121 
122  image_if<I, f_box2d_t > imaif(ima, f_b2);
123  mln_assertion(border::find(imaif) == 42);
124 
125  image_if<I, fun::p2b::chess > imaif_chess(ima, c_b);
126  mln_assertion(border::find(imaif_chess) == 42);
127 
128 
129  mln_assertion(border::find( (ima | b2) ) == 42);
130  mln_assertion(border::find( (ima | b2) | f_b2 ) == 42);
131  mln_assertion(border::find( (ima | b2) | c_b ) == 42);
132  mln_assertion(border::find( (ima | b2) | c_b | f_b2 ) == 42);
133  mln_assertion(border::find( (ima | b2) | f_b2 | c_b ) == 42);
134 
135  std::cerr << "OK" << std::endl;
136  }
137 
138  {
139  typedef image3d<value::rgb8> I;
140  (std::cerr << "Tests border::find on rgb8 in 3d ... ").flush ();
141  I ima(10, 10, 10, 36);
142  mln_assertion(border::find(ima) == 36);
143  mln_assertion( ima.has(point3d(2,2,2)) == true );
144  sub_image<I, box3d> sub(ima, b3);
145  mln_assertion(border::find(sub) == 36);
146 
147  image_if<I, f_box3d_t> imaif(ima, f_b3);
148  mln_assertion(border::find(imaif) == 36);
149  mln_assertion(border::find( (ima | b3) ) == 36);
150  mln_assertion(border::find( (ima | b3) | f_b3 ) == 36);
151  std::cerr << "OK" << std::endl;
152  }
153 }