$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mosaic.hh
1 // Copyright (C) 2010, 2012 EPITA Research and Development Laboratory
2 // (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 #ifndef MLN_DEBUG_MOSAIC_HH
28 # define MLN_DEBUG_MOSAIC_HH
29 
33 
34 # include <cmath>
35 
36 # include <mln/core/image/image2d.hh>
37 
38 # include <mln/core/image/image3d.hh>
39 # include <mln/core/image/dmorph/slice_image.hh>
40 
41 # include <mln/core/image/dmorph/p2p_image.hh>
42 # include <mln/fun/p2p/translation.hh>
43 
44 # include <mln/data/paste.hh>
45 # include <mln/data/fill.hh>
46 
47 
48 
49 namespace mln
50 {
51 
52  namespace debug
53  {
54 
67  template <typename I>
68  mln_concrete(I)
69  mosaic(const util::array<I>& input,
70  unsigned n_horizontal,
71  const mln_value(I)& bg);
72 
73 
74 
75 # ifndef MLN_INCLUDE_ONLY
76 
77  template <typename I>
78  inline
79  mln_concrete(I)
80  mosaic(const util::array<I>& input,
81  unsigned n_horizontal,
82  const mln_value(I)& bg)
83  {
84  mln_trace("debug::mosaic");
85 
86  mlc_is_a(I, Image)::check();
87  mlc_equal(mln_domain(I), box2d)::check();
88  mln_precondition(n_horizontal > 0);
89 
90  // Find largest dimensions
91  unsigned max_ncols = 0, max_nrows = 0;
92  for (unsigned i = 0; i < input.nelements(); ++i)
93  {
94  const I& ima = exact(input[i]);
95  mln_precondition(ima.is_valid());
96 
97  if (ima.ncols() > max_ncols)
98  max_ncols = ima.ncols();
99 
100  if (ima.nrows() > max_nrows)
101  max_nrows = ima.nrows();
102  }
103 
104 
105  mln_concrete(I) output(max_nrows
106  * (input.nelements() / (float)n_horizontal
107  + 0.51f),
108  max_ncols * n_horizontal);
109  data::fill(output, bg);
110 
111  unsigned brow = 0, bcol = 0;
112  for (unsigned i = 0; i < input.nelements(); ++i)
113  {
114  const I& ima = exact(input[i]);
115  mln_precondition(ima.is_valid());
116 
117  dpoint2d dp(brow * max_nrows
118  + ((max_nrows - ima.domain().height()) / 2),
119  bcol * max_ncols
120  + ((max_ncols - ima.domain().width()) / 2));
122  output);
123 
124  ++bcol;
125  if (! (bcol < n_horizontal))
126  {
127  ++brow;
128  bcol = 0;
129  }
130  }
131 
132  return output;
133  }
134 
135 
136 # endif // ! MLN_INCLUDE_ONLY
137 
138  } // end of namespace mln::debug
139 
140 } // end of namespace mln
141 
142 
143 #endif // ! MLN_DEBUG_MOSAIC_HH