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