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 #include <mln/core/image/dmorph/sub_image.hh> 00030 00031 #include <mln/core/image/dmorph/image_if.hh> 00032 #include <mln/fun/p2b/chess.hh> 00033 00034 #include <mln/literal/origin.hh> 00035 00036 #include <mln/value/int_s8.hh> 00037 #include <mln/value/int_s16.hh> 00038 #include <mln/value/int_u8.hh> 00039 #include <mln/value/int_u16.hh> 00040 00041 #include <mln/value/rgb8.hh> 00042 #include <mln/value/rgb16.hh> 00043 00044 00045 #include <mln/debug/iota.hh> 00046 00047 #include <mln/data/fill.hh> 00048 00049 #include <mln/fun/p2v/iota.hh> 00050 00051 00052 00053 00054 00055 00056 struct f_box1d_t : mln::Function_v2b< f_box1d_t > 00057 { 00058 f_box1d_t(const mln::box1d& b) 00059 : b_(b) 00060 { 00061 } 00062 mln::box1d b_; 00063 bool operator()(const mln::point1d& p) const 00064 { 00065 return b_.has(p); 00066 } 00067 }; 00068 00069 struct f_box2d_t : mln::Function_v2b< f_box2d_t > 00070 { 00071 f_box2d_t(const mln::box2d& b) 00072 : b_(b) 00073 { 00074 } 00075 mln::box2d b_; 00076 bool operator()(const mln::point2d& p) const 00077 { 00078 return b_.has(p); 00079 } 00080 }; 00081 00082 struct f_box3d_t : mln::Function_v2b< f_box3d_t > 00083 { 00084 f_box3d_t(const mln::box3d& b) 00085 : b_(b) 00086 { 00087 } 00088 mln::box3d b_; 00089 bool operator()(const mln::point3d& p) const 00090 { 00091 return b_.has(p); 00092 } 00093 }; 00094 00095 00096 00097 namespace mln 00098 { 00099 template <typename I> 00100 void 00101 chck(Image<I>& ima_, const mln_value(I) v) 00102 { 00103 I& ima = exact(ima_); 00104 00105 data::fill(ima, v); 00106 00107 { 00108 mln_piter(I) p (ima.domain ()); 00109 for_all(p) 00110 mln_assertion (ima(p) == v); 00111 } 00112 } 00113 00114 template <typename V> 00115 void 00116 chk(const V max) 00117 { 00118 box1d b1(literal::origin, point1d(1)); 00119 box2d b2(literal::origin, point2d(1,1)); 00120 box3d b3(literal::origin, point3d(1,1,1)); 00121 f_box1d_t f_b1(b1); 00122 f_box2d_t f_b2(b2); 00123 f_box3d_t f_b3(b3); 00124 unsigned sli = 2; 00125 unsigned row = 3; 00126 unsigned col = 16; 00127 00128 00129 (std::cerr << "in 1d ... ").flush (); 00130 { 00131 typedef image1d<V> I; 00132 00133 for (V v = 0; v < max; ++v) 00134 for (unsigned i = 1; i < col; ++i) 00135 { 00136 I ima(i); 00137 chck (ima, v); 00138 } 00139 } 00140 std::cerr << "OK" << std::endl; 00141 00142 (std::cerr << "in 2d ... ").flush (); 00143 { 00144 typedef image2d<V> I; 00145 00146 for (V v = 0; v < max; ++v) 00147 for (unsigned i = 1; i < col; ++i) 00148 for (unsigned j = 1; j < row; ++j) 00149 { 00150 I ima(j, i); 00151 chck (ima, v); 00152 } 00153 } 00154 std::cerr << "OK" << std::endl; 00155 00156 (std::cerr << "in 3d ... ").flush (); 00157 { 00158 typedef image3d<V> I; 00159 00160 for (V v = 0; v < max; ++v) 00161 for (unsigned i = 1; i < col; ++i) 00162 for (unsigned j = 1; j < row; ++j) 00163 for (unsigned k = 1; k < sli; ++k) 00164 { 00165 I ima(k, j, i); 00166 chck (ima, v); 00167 } 00168 } 00169 std::cerr << "OK" << std::endl; 00170 00171 00172 (std::cerr << "in subimage 1d ... ").flush (); 00173 { 00174 typedef image1d<V> I; 00175 typedef sub_image<I, box1d> J; 00176 00177 00178 for (V v = 0; v < max; ++v) 00179 for (unsigned i = 1; i < col; ++i) 00180 { 00181 I image(i); 00182 J ima(image, b1); 00183 chck (ima, v); 00184 } 00185 } 00186 std::cerr << "OK" << std::endl; 00187 00188 (std::cerr << "in subimage 2d ... ").flush (); 00189 { 00190 typedef image2d<V> I; 00191 typedef sub_image<I, box2d> J; 00192 00193 00194 for (V v = 0; v < max; ++v) 00195 for (unsigned i = 1; i < col; ++i) 00196 for (unsigned j = 1; j < row; ++j) 00197 { 00198 I image(j, i); 00199 J ima(image, b2); 00200 chck (ima, v); 00201 } 00202 } 00203 std::cerr << "OK" << std::endl; 00204 00205 (std::cerr << "in subimage 3d ... ").flush (); 00206 { 00207 typedef image3d<V> I; 00208 typedef sub_image<I, box3d> J; 00209 00210 00211 for (V v = 0; v < max; ++v) 00212 for (unsigned i = 1; i < col; ++i) 00213 for (unsigned j = 1; j < row; ++j) 00214 for (unsigned k = 1; k < sli; ++k) 00215 { 00216 I image(k, j, i); 00217 J ima(image, b3); 00218 chck (ima, v); 00219 } 00220 } 00221 std::cerr << "OK" << std::endl; 00222 } 00223 00224 template <typename V> 00225 void 00226 chk_rgb(const unsigned min, const unsigned max) 00227 { 00228 box1d b1(literal::origin, point1d(1)); 00229 box2d b2(literal::origin, point2d(1,1)); 00230 box3d b3(literal::origin, point3d(1,1,1)); 00231 f_box1d_t f_b1(b1); 00232 f_box2d_t f_b2(b2); 00233 f_box3d_t f_b3(b3); 00234 unsigned sli = 2; 00235 unsigned row = 3; 00236 unsigned col = 16; 00237 00238 00239 (std::cerr << "in 1d ... ").flush (); 00240 { 00241 typedef image1d<V> I; 00242 00243 for (unsigned r = min; r < max; ++r) 00244 for (unsigned g = min; g < max; ++g) 00245 for (unsigned b = min; b < max; ++b) 00246 for (unsigned i = 1; i < col; ++i) 00247 { 00248 I ima(i); 00249 chck (ima, V(r,g,b)); 00250 } 00251 } 00252 std::cerr << "OK" << std::endl; 00253 00254 (std::cerr << "in 2d ... ").flush (); 00255 { 00256 typedef image2d<V> I; 00257 00258 for (unsigned r = min; r < max; ++r) 00259 for (unsigned g = min; g < max; ++g) 00260 for (unsigned b = min; b < max; ++b) 00261 for (unsigned i = 1; i < col; ++i) 00262 for (unsigned j = 1; j < row; ++j) 00263 { 00264 I ima(j, i); 00265 chck (ima, V(r,g,b)); 00266 } 00267 } 00268 std::cerr << "OK" << std::endl; 00269 00270 (std::cerr << "in 3d ... ").flush (); 00271 { 00272 typedef image3d<V> I; 00273 00274 for (unsigned r = min; r < max; ++r) 00275 for (unsigned g = min; g < max; ++g) 00276 for (unsigned b = min; b < max; ++b) 00277 for (unsigned i = 1; i < col; ++i) 00278 for (unsigned j = 1; j < row; ++j) 00279 for (unsigned k = 1; k < sli; ++k) 00280 { 00281 I ima(k, j, i); 00282 chck (ima, V(r,g,b)); 00283 } 00284 } 00285 std::cerr << "OK" << std::endl; 00286 00287 00288 (std::cerr << "in subimage 1d ... ").flush (); 00289 { 00290 typedef image1d<V> I; 00291 typedef sub_image<I, box1d> J; 00292 00293 00294 for (unsigned r = min; r < max; ++r) 00295 for (unsigned g = min; g < max; ++g) 00296 for (unsigned b = min; b < max; ++b) 00297 for (unsigned i = 1; i < col; ++i) 00298 { 00299 I image(i); 00300 J ima(image, b1); 00301 chck (ima, V(r,g,b)); 00302 } 00303 } 00304 std::cerr << "OK" << std::endl; 00305 00306 (std::cerr << "in subimage 2d ... ").flush (); 00307 { 00308 typedef image2d<V> I; 00309 typedef sub_image<I, box2d> J; 00310 00311 00312 for (unsigned r = min; r < max; ++r) 00313 for (unsigned g = min; g < max; ++g) 00314 for (unsigned b = min; b < max; ++b) 00315 for (unsigned i = 1; i < col; ++i) 00316 for (unsigned j = 1; j < row; ++j) 00317 { 00318 I image(j, i); 00319 J ima(image, b2); 00320 chck (ima, V(r,g,b)); 00321 } 00322 } 00323 std::cerr << "OK" << std::endl; 00324 00325 (std::cerr << "in subimage 3d ... ").flush (); 00326 { 00327 typedef image3d<V> I; 00328 typedef sub_image<I, box3d> J; 00329 00330 00331 for (unsigned r = min; r < max; ++r) 00332 for (unsigned g = min; g < max; ++g) 00333 for (unsigned b = min; b < max; ++b) 00334 for (unsigned i = 1; i < col; ++i) 00335 for (unsigned j = 1; j < row; ++j) 00336 for (unsigned k = 1; k < sli; ++k) 00337 { 00338 I image(k, j, i); 00339 J ima(image, b3); 00340 chck (ima, V(r,g,b)); 00341 } 00342 } 00343 std::cerr << "OK" << std::endl; 00344 } 00345 00346 } 00347 00348 00349 int main() 00350 { 00351 using namespace mln; 00352 00353 std::cerr << "Tests data::fill:" << std::endl; 00354 std::cerr << "on int:" << std::endl; 00355 chk<int>(1000); 00356 std::cerr << "on unsigned:" << std::endl; 00357 chk<unsigned>(1000); 00358 std::cerr << "on int_u8:" << std::endl; 00359 chk<value::int_u8>(16); 00360 std::cerr << "on int_u16:" << std::endl; 00361 chk<value::int_u16>(1000); 00362 std::cerr << "on int_s8:" << std::endl; 00363 chk<value::int_s8>(16); 00364 std::cerr << "on int_s16:" << std::endl; 00365 chk<value::int_s16>(1000); 00366 std::cerr << "on rgb8:" << std::endl; 00367 chk_rgb<value::rgb8>(140, 150); 00368 std::cerr << "on rgb16:" << std::endl; 00369 chk_rgb<value::rgb16>(60000, 60015); 00370 }