Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 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 // Find largest dimensions 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 } // end of namespace mln::debug 00137 00138 } // end of namespace mln 00139 00140 00141 #endif // ! MLN_DEBUG_MOSAIC_HH