$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dilation-lena-table.cc
1 // Copyright (C) 2010, 2011 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 <iostream>
27 #include <iomanip>
28 
29 #include "apps/bench/dilation-lena.hh"
30 #include "apps/data.hh"
31 
32 
33 // Shortcut macros for run.
34 
35 #define DILATION_WITH_BUILTIN_WINDOW(Namespace, Suffix, Headline) \
36  do \
37  { \
38  d = lena; \
39  t.start(); \
40  for (unsigned i = 0; i < niters; ++i) \
41  d = Namespace::dilation(d); \
42  t.stop(); \
43  std::cerr << Headline << t.read() << " s" << std::endl; \
44  io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
45  times.push_back(t.read()); \
46  } \
47  while (0)
48 
49 #define DILATION(Namespace, Win, Suffix, Headline) \
50  do \
51  { \
52  d = lena; \
53  t.start(); \
54  for (unsigned i = 0; i < niters; ++i) \
55  d = Namespace::dilation(d, Win); \
56  t.stop(); \
57  std::cerr << Headline << t.read() << " s" << std::endl; \
58  io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
59  times.push_back(t.read()); \
60  } \
61  while (0)
62 
63 
64 std::vector<float>
65 run(const std::string& filename, const std::string& length, unsigned niters)
66 {
67  using namespace mln;
68  using value::int_u8;
69 
71  image2d<int_u8> lena;
72  io::pgm::load(lena, filename);
73 
75  util::timer t;
76 
77  std::string prefix = "dilation-lena-table-out";
78  std::cerr << "== " << filename << std::endl;
79 
80  std::vector<float> times;
81  times.reserve(5);
82 
83  DILATION_WITH_BUILTIN_WINDOW(nongen, "nongen", "nongen\t\t");
84  DILATION_WITH_BUILTIN_WINDOW(nongen_2ptr, "nongen_2ptr", "nongen_2ptr\t");
85 # if 0
86  // Disabled, not used in the paper's table.
87  DILATION_WITH_BUILTIN_WINDOW(nongen_1ptr, "nongen_1ptr", "nongen_1ptr\t");
88 #endif
89 
90  DILATION(gen, win_c4p(), "gen", "gen\t\t");
91  // FIXME: Introduce a new test case, gen_static, using a static window
92  // and static_qiters.
93  DILATION(fast, win_c4p(), "fast", "fast\t\t");
94 # if 0
95  // Disabled, not used in the paper's table.
96  DILATION(fast_noaccu, win_c4p(), "fast_noaccu", "fast_noaccu\t");
97  DILATION(faster, win_c4p(), "faster", "faster\t\t");
98  DILATION(faster_noaccu, win_c4p(), "faster_noaccu", "faster_noaccu\t");
99 #endif
100 
101  // Static windows and qixters.
102  const unsigned n = 5;
103  mln::dpoint2d dps[n] = { mln::dpoint2d( 0, -1),
104  mln::dpoint2d(-1, 0),
105  mln::dpoint2d( 0, 0),
106  mln::dpoint2d(+1, 0),
107  mln::dpoint2d( 0, +1) };
109  mln::static_window<mln::dpoint2d, n> static_win_c4p (sa);
110 
111  DILATION(fast_static, static_win_c4p, "fast_static", "fast_static\t");
112 # if 0
113  // Disabled, not used in the paper's table.
114  DILATION(faster_static, static_win_c4p, "faster_static", "faster_static\t");
115 #endif
116 
117  std::cerr << std::endl;
118 
119  return times;
120 }
121 
122 int
123 main (int /* argc */, char* argv[])
124 {
125  unsigned niters = 10;
126  typedef std::vector<float> times_t;
127 
128  // Compute times.
129  times_t times_512 = run(MLN_IMG_DIR "/lena.pgm", "512", niters);
130  times_t times_1024 = run(MLN_APPS_DIR "/bench/lena1024.pgm", "1024", niters);
131  times_t times_2048 = run(MLN_APPS_DIR "/bench/lena2048.pgm", "2048", niters);
132 
133  // Display times.
134  times_t::const_iterator i_512 = times_512.begin();
135  times_t::const_iterator i_1024 = times_1024.begin();
136  times_t::const_iterator i_2048 = times_2048.begin();
137  std::cout <<
138  "% Generated by `" << argv[0] << "', do not modify.\n"
139  "\n"
140  "\\begin{table}[tbp]\n"
141  " \\centering\n"
142  " \\begin{tabular}{lrrr}\n"
143  " \\hline\n"
144  " Implementation & \\multicolumn{3}{c}{Execution times (s)} \\\\\n"
145  " & $512^2$ & $1024^2$ & $2048^2$ \\\\\n"
146  " \\hline\n"
147  " \\hline\n";
148 
149  // Fix the output format for floats.
150  std::cout << std::fixed << std::setprecision(4);
151 
152  /* Increment each iterator only once in each output statement to
153  avoid non-determinism due to the successive uses of operator++ on
154  a given iterator. */
155 
156  // nongen.
157  std::cout <<
158  " Non generic (\\algref{lst:non-gen-dilation}) & " <<
159  *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
160  " \\hline\n";
161 
162  // nongen_2ptr.
163  std::cout <<
164  " Non generic, pointer-based\\footnotemark[1] & " <<
165  *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
166  " \\hline\n";
167 
168  // gen.
169  std::cout <<
170  " Generic (\\algref{lst:gen-dilation}) & " <<
171  *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
172  " \\hline\n";
173 
174  // fast.
175  std::cout <<
176  " Fast, partly generic (\\algref{lst:fast-dilation}) & " <<
177  *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
178  " \\hline\n";
179 
180  // fast_static.
181  std::cout <<
182  " Fast, partly generic with & " <<
183  *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
184  " static window (\\algref{lst:fast-static-dilation}) & & & \\\\\n"
185  " \\hline\n";
186 
187  std::cout <<
188  " \\end{tabular}\n"
189  " \\caption{Execution times of various dilation implementations.}\n"
190  " \\label{tab:results}\n"
191  "\\end{table}\n"
192  "\\footnotetext[1]{Implementation not shown in this paper for space\n"
193  " reasons.}\n" << std::flush;
194 }