$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_runs.cc
1 # include <mln/io/pbm/load.hh>
2 # include <mln/core/image/image2d.hh>
3 # include <mln/core/alias/p_run2d.hh>
4 # include <mln/core/p_set_of.hh>
5 # include <mln/convert/from_to.hh>
6 # include <mln/util/timer.hh>
7 
8 # include <sandbox/geraud/p_runs__with_dedicated_piter.hh>
9 
10 
11 const unsigned n_times = 32;
12 
13 
14 template <typename I>
15 float browse_ima(const I& ima, unsigned& c)
16 {
18  t.start();
19  for (unsigned i = 0; i < n_times; ++i)
20  {
21  c = 0;
22  mln_piter(I) p(ima.domain());
23  for_all(p)
24  if (ima(p))
25  ++c;
26  }
27  return t.read();
28 }
29 
30 template <typename R>
31 float browse_runs(const R& runs, unsigned& c)
32 {
34  t.start();
35  for (unsigned i = 0; i < n_times; ++i)
36  {
37  c = 0;
38  mln_fwd_piter(R) p(runs);
39  for_all(p)
40  ++c;
41  }
42  return t.read();
43 }
44 
45 
46 int main()
47 {
48  using namespace mln;
49  image2d<bool> ima;
50  io::pbm::load(ima, "../../img/lena.pbm");
51 
52  unsigned c;
53  std::cout << "ref: " << browse_ima(ima, c) << std::endl;
54 
55  {
56  util::timer t;
57  t.start();
58 
59  // Conversion.
61  convert::from_to(ima, rs);
62  std::cout << "enc: " << t.read() << std::endl;
63  // FIXME: mln_assertion(rs.zratio() < 1);
64 
65  // Browsing.
66  unsigned cr;
67  std::cout << "brs: " << browse_runs(rs, cr) << std::endl;
68  mln_assertion(cr == c);
69  }
70 
71  {
72  util::timer t;
73  t.start();
74 
75  // Conversion.
76  p_runs<point2d> rs;
77  convert::from_to(ima, rs);
78  std::cout << "enc: " << t.read() << std::endl;
79  // FIXME: mln_assertion(rs.zratio() < 1);
80 
81  // Browsing.
82  unsigned cr;
83  std::cout << "brs: " << browse_runs(rs, cr) << std::endl;
84  mln_assertion(cr == c);
85  }
86 
87 }