Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 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 #include <mln/core/image/image1d.hh> 00027 #include <mln/core/image/image2d.hh> 00028 #include <mln/core/image/image3d.hh> 00029 00030 #include <mln/value/int_u8.hh> 00031 #include <mln/value/int_u16.hh> 00032 #include <mln/value/int_s8.hh> 00033 #include <mln/value/int_s16.hh> 00034 00035 #include <mln/core/image/dmorph/sub_image.hh> 00036 #include <mln/core/image/dmorph/image_if.hh> 00037 #include <mln/fun/p2b/chess.hh> 00038 00039 #include <mln/accu/stat/min.hh> 00040 #include <mln/accu/stat/max.hh> 00041 #include <mln/debug/iota.hh> 00042 #include <mln/debug/println.hh> 00043 #include <mln/data/compute.hh> 00044 00045 00046 00047 struct f_box1d_t : mln::Function_v2b< f_box1d_t > 00048 { 00049 f_box1d_t(const mln::box1d& b) 00050 : b_(b) 00051 { 00052 } 00053 mln::box1d b_; 00054 bool operator()(const mln::point1d& p) const 00055 { 00056 return b_.has(p); 00057 } 00058 }; 00059 00060 struct f_box2d_t : mln::Function_v2b< f_box2d_t > 00061 { 00062 f_box2d_t(const mln::box2d& b) 00063 : b_(b) 00064 { 00065 } 00066 mln::box2d b_; 00067 bool operator()(const mln::point2d& p) const 00068 { 00069 return b_.has(p); 00070 } 00071 }; 00072 00073 struct f_box3d_t : mln::Function_v2b< f_box3d_t > 00074 { 00075 f_box3d_t(const mln::box3d& b) 00076 : b_(b) 00077 { 00078 } 00079 mln::box3d b_; 00080 bool operator()(const mln::point3d& p) const 00081 { 00082 return b_.has(p); 00083 } 00084 }; 00085 00086 00087 namespace mln 00088 { 00089 template <typename I> 00090 void 00091 chk1d(unsigned cols) 00092 { 00093 box1d b1(literal::origin, point1d(1)); 00094 00095 image1d<I> ima (cols); 00096 debug::iota (ima); 00097 I real_min = 1; 00098 I real_min2 = 1; 00099 I real_max = (I)(cols % (unsigned) mln_max(I)); 00100 I real_max2 = 2; 00101 if (cols >= (unsigned)mln_max(I)) 00102 { 00103 real_min = 0; 00104 real_max = mln_max(I) - 1; 00105 } 00106 00107 00108 { 00109 accu::stat::min<I> acu_min; 00110 accu::stat::max<I> acu_max; 00111 00112 I min = data::compute(acu_min, ima); 00113 I max = data::compute(acu_max, ima); 00114 mln_assertion(min == real_min); 00115 mln_assertion(max == real_max); 00116 } 00117 00118 { 00119 sub_image<image1d<I>, box1d> sub_ima (ima, b1); 00120 00121 accu::stat::min<I> acu_min; 00122 accu::stat::max<I> acu_max; 00123 00124 I min = data::compute(acu_min, sub_ima); 00125 I max = data::compute(acu_max, sub_ima); 00126 mln_assertion(min == real_min2); 00127 mln_assertion(max == real_max2); 00128 } 00129 00130 { 00131 f_box1d_t f_b(b1); 00132 image_if<image1d<I>, f_box1d_t> if_ima(ima, f_b); 00133 00134 accu::stat::min<I> acu_min; 00135 accu::stat::max<I> acu_max; 00136 00137 I min = data::compute(acu_min, if_ima); 00138 I max = data::compute(acu_max, if_ima); 00139 mln_assertion(min == real_min2); 00140 mln_assertion(max == real_max2); 00141 } 00142 } 00143 00144 template <typename I> 00145 void 00146 chk2d(unsigned rows, unsigned cols) 00147 { 00148 box2d b2(literal::origin, point2d(1, 1)); 00149 00150 image2d<I> ima (rows, cols); 00151 debug::iota (ima); 00152 I real_min = 1; 00153 I real_min2 = 1; 00154 I real_max; 00155 if (rows * cols >= (unsigned)mln_max(I)) 00156 { 00157 real_min = 0; 00158 real_max = mln_max(I) - 1; 00159 } 00160 else 00161 { 00162 real_max = (I)(rows * cols); 00163 if ((cols == (unsigned)mln_max(I) - 2) || 00164 (cols == (unsigned)mln_max(I) - 1)) 00165 real_min2 = 0; 00166 } 00167 00168 { 00169 accu::stat::min<I> acu_min; 00170 accu::stat::max<I> acu_max; 00171 00172 I min = data::compute(acu_min, ima); 00173 I max = data::compute(acu_max, ima); 00174 00175 mln_assertion(min == real_min); 00176 mln_assertion(max == real_max); 00177 } 00178 00179 } 00180 00181 template <typename I> 00182 void 00183 chk3d(unsigned slis, unsigned rows, unsigned cols) 00184 { 00185 box3d b3(literal::origin, point3d(1, 1, 1)); 00186 00187 image3d<I> ima (slis, rows, cols); 00188 debug::iota (ima); 00189 I real_min = 1; 00190 I real_max; 00191 if (slis * rows * cols >= (unsigned)mln_max(I)) 00192 { 00193 real_min = 0; 00194 real_max = mln_max(I) - 1; 00195 } 00196 else 00197 real_max = (I)(slis * rows * cols); 00198 { 00199 accu::stat::min<I> acu_min; 00200 accu::stat::max<I> acu_max; 00201 00202 I min = data::compute(acu_min, ima); 00203 I max = data::compute(acu_max, ima); 00204 00205 mln_assertion(min == real_min); 00206 mln_assertion(max == real_max); 00207 } 00208 00209 } 00210 } 00211 00212 00213 int main() 00214 { 00215 using namespace mln; 00216 00217 unsigned slis_start = 2; 00218 unsigned slis_end = 3; 00219 00220 unsigned rows_start = 2; 00221 unsigned rows_end = 16; 00222 00223 unsigned cols_start = 2; 00224 unsigned cols_end = 256; 00225 00226 00227 std::cerr << "Tests data::compute:" << std::endl; 00228 00229 (std::cerr << "in 1d ... ").flush (); 00230 { 00231 for (unsigned i = cols_start; i < cols_end; ++i) 00232 { 00233 chk1d<int>(i); 00234 chk1d<unsigned>(i); 00235 chk1d<value::int_u8>(i); 00236 chk1d<value::int_u16>(i); 00237 chk1d<value::int_s8>(i); 00238 chk1d<value::int_s16>(i); 00239 } 00240 } 00241 std::cerr << "OK" << std::endl; 00242 00243 (std::cerr << "in 2d ... ").flush (); 00244 { 00245 for (unsigned j = rows_start; j < rows_end; ++j) 00246 for (unsigned i = cols_start; i < cols_end; ++i) 00247 { 00248 chk2d<int>(j, i); 00249 chk2d<unsigned>(j, i); 00250 chk2d<value::int_u8>(j, i); 00251 chk2d<value::int_u16>(j, i); 00252 chk2d<value::int_s8>(j, i); 00253 chk2d<value::int_s16>(j, i); 00254 } 00255 } 00256 std::cerr << "OK" << std::endl; 00257 00258 (std::cerr << "in 3d ... ").flush (); 00259 { 00260 for (unsigned k = slis_start; k < slis_end; ++k) 00261 for (unsigned j = rows_start; j < rows_end; ++j) 00262 for (unsigned i = cols_start; i < cols_end; ++i) 00263 { 00264 chk3d<int>(k, j, i); 00265 chk3d<unsigned>(k, j, i); 00266 chk3d<value::int_u8>(k, j, i); 00267 chk3d<value::int_u16>(k, j, i); 00268 chk3d<value::int_s8>(k, j, i); 00269 } 00270 } 00271 std::cerr << "OK" << std::endl; 00272 }