00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_DEBUG_MOSAIC_HH
00027 # define MLN_DEBUG_MOSAIC_HH
00028
00032
00033 # include <cmath>
00034
00035 # include <mln/core/image/image2d.hh>
00036
00037 # include <mln/core/image/image3d.hh>
00038 # include <mln/core/image/dmorph/slice_image.hh>
00039
00040 # include <mln/core/image/dmorph/p2p_image.hh>
00041 # include <mln/fun/p2p/translation.hh>
00042
00043 # include <mln/data/paste.hh>
00044 # include <mln/data/fill.hh>
00045
00046
00047
00048 namespace mln
00049 {
00050
00051 namespace debug
00052 {
00053
00064 template <typename I>
00065 mln_concrete(I)
00066 mosaic(const util::array<I>& input,
00067 unsigned n_horizontal,
00068 const mln_value(I)& bg);
00069
00070
00071
00072 # ifndef MLN_INCLUDE_ONLY
00073
00074 template <typename I>
00075 inline
00076 mln_concrete(I)
00077 mosaic(const util::array<I>& input,
00078 unsigned n_horizontal,
00079 const mln_value(I)& bg)
00080 {
00081 trace::entering("debug::mosaic");
00082
00083 mlc_is_a(I, Image)::check();
00084 mlc_equal(mln_domain(I), box2d)::check();
00085 mln_precondition(n_horizontal > 0);
00086
00087
00088 unsigned max_ncols = 0, max_nrows = 0;
00089 for (unsigned i = 0; i < input.nelements(); ++i)
00090 {
00091 const I& ima = exact(input[i]);
00092 mln_precondition(ima.is_valid());
00093
00094 if (ima.ncols() > max_ncols)
00095 max_ncols = ima.ncols();
00096
00097 if (ima.nrows() > max_nrows)
00098 max_nrows = ima.nrows();
00099 }
00100
00101
00102 mln_concrete(I) output(max_nrows
00103 * (input.nelements() / (float)n_horizontal
00104 + 0.51f),
00105 max_ncols * n_horizontal);
00106 data::fill(output, bg);
00107
00108 unsigned brow = 0, bcol = 0;
00109 for (unsigned i = 0; i < input.nelements(); ++i)
00110 {
00111 const I& ima = exact(input[i]);
00112 mln_precondition(ima.is_valid());
00113
00114 dpoint2d dp(brow * max_nrows
00115 + ((max_nrows - ima.domain().height()) / 2),
00116 bcol * max_ncols
00117 + ((max_ncols - ima.domain().width()) / 2));
00118 data::paste(apply_p2p(ima, fun::p2p::translation(dp)),
00119 output);
00120
00121 ++bcol;
00122 if (! (bcol < n_horizontal))
00123 {
00124 ++brow;
00125 bcol = 0;
00126 }
00127 }
00128
00129 trace::exiting("debug::mosaic");
00130 return output;
00131 }
00132
00133
00134 # endif // ! MLN_INCLUDE_ONLY
00135
00136 }
00137
00138 }
00139
00140
00141 #endif // ! MLN_DEBUG_MOSAIC_HH