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 00039 00040 #include <mln/debug/iota.hh> 00041 00042 #include <mln/arith/minus.hh> 00043 00044 00045 00046 00047 00048 00049 00050 struct f_box1d_t : mln::Function_v2b< f_box1d_t > 00051 { 00052 f_box1d_t(const mln::box1d& b) 00053 : b_(b) 00054 { 00055 } 00056 mln::box1d b_; 00057 bool operator()(const mln::point1d& p) const 00058 { 00059 return b_.has(p); 00060 } 00061 }; 00062 00063 struct f_box2d_t : mln::Function_v2b< f_box2d_t > 00064 { 00065 f_box2d_t(const mln::box2d& b) 00066 : b_(b) 00067 { 00068 } 00069 mln::box2d b_; 00070 bool operator()(const mln::point2d& p) const 00071 { 00072 return b_.has(p); 00073 } 00074 }; 00075 00076 struct f_box3d_t : mln::Function_v2b< f_box3d_t > 00077 { 00078 f_box3d_t(const mln::box3d& b) 00079 : b_(b) 00080 { 00081 } 00082 mln::box3d b_; 00083 bool operator()(const mln::point3d& p) const 00084 { 00085 return b_.has(p); 00086 } 00087 }; 00088 00089 00090 00091 namespace mln 00092 { 00093 template <typename I, typename J> 00094 void 00095 chck(const Image<I>& ref_, const Image<J>& ima_, const mln_value(I) v) 00096 { 00097 const I& ref = exact(ref_); 00098 const J& ima = exact(ima_); 00099 00100 mln_piter(I) p (ima.domain ()); 00101 for_all(p) 00102 mln_assertion ((mln_value(I))ima(p) == (ref(p) - v)); 00103 } 00104 00105 template <typename V> 00106 void 00107 chk(const V max) 00108 { 00109 box1d b1(literal::origin, point1d(1)); 00110 box2d b2(literal::origin, point2d(1,1)); 00111 box3d b3(literal::origin, point3d(1,1,1)); 00112 f_box1d_t f_b1(b1); 00113 f_box2d_t f_b2(b2); 00114 f_box3d_t f_b3(b3); 00115 unsigned sli = 2; 00116 unsigned row = 3; 00117 unsigned col = 16; 00118 00119 00120 (std::cerr << "in 1d ... ").flush (); 00121 { 00122 typedef image1d<V> I; 00123 00124 for (V v = 0; v < max; ++v) 00125 for (unsigned i = 1; i < col; ++i) 00126 { 00127 I ima(i); 00128 debug::iota(ima); 00129 chck (ima, ima - v, v); 00130 } 00131 } 00132 std::cerr << "OK" << std::endl; 00133 00134 (std::cerr << "in 2d ... ").flush (); 00135 { 00136 typedef image2d<V> I; 00137 00138 for (V v = 0; v < max; ++v) 00139 for (unsigned i = 1; i < col; ++i) 00140 for (unsigned j = 1; j < row; ++j) 00141 { 00142 I ima(j, i); 00143 debug::iota(ima); 00144 chck (ima, ima - v, v); 00145 } 00146 } 00147 std::cerr << "OK" << std::endl; 00148 00149 (std::cerr << "in 3d ... ").flush (); 00150 { 00151 typedef image3d<V> I; 00152 00153 for (V v = 0; v < max; ++v) 00154 for (unsigned i = 1; i < col; ++i) 00155 for (unsigned j = 1; j < row; ++j) 00156 for (unsigned k = 1; k < sli; ++k) 00157 { 00158 I ima(k, j, i); 00159 debug::iota(ima); 00160 chck (ima, ima - v, v); 00161 } 00162 } 00163 std::cerr << "OK" << std::endl; 00164 00165 00166 (std::cerr << "in subimage 1d ... ").flush (); 00167 { 00168 typedef image1d<V> I; 00169 typedef sub_image<I, box1d> J; 00170 00171 00172 for (V v = 0; v < max; ++v) 00173 for (unsigned i = 1; i < col; ++i) 00174 { 00175 I image(i); 00176 J ima(image, b1); 00177 debug::iota(ima); 00178 chck (ima, ima - v, v); 00179 } 00180 } 00181 std::cerr << "OK" << std::endl; 00182 00183 (std::cerr << "in subimage 2d ... ").flush (); 00184 { 00185 typedef image2d<V> I; 00186 typedef sub_image<I, box2d> J; 00187 00188 00189 for (V v = 0; v < max; ++v) 00190 for (unsigned i = 1; i < col; ++i) 00191 for (unsigned j = 1; j < row; ++j) 00192 { 00193 I image(j, i); 00194 J ima(image, b2); 00195 debug::iota(ima); 00196 chck (ima, ima - v, v); 00197 } 00198 } 00199 std::cerr << "OK" << std::endl; 00200 00201 (std::cerr << "in subimage 3d ... ").flush (); 00202 { 00203 typedef image3d<V> I; 00204 typedef sub_image<I, box3d> J; 00205 00206 00207 for (V v = 0; v < max; ++v) 00208 for (unsigned i = 1; i < col; ++i) 00209 for (unsigned j = 1; j < row; ++j) 00210 for (unsigned k = 1; k < sli; ++k) 00211 { 00212 I image(k, j, i); 00213 J ima(image, b3); 00214 debug::iota(ima); 00215 chck (ima, ima - v, v); 00216 } 00217 } 00218 std::cerr << "OK" << std::endl; 00219 } 00220 00221 } 00222 00223 00224 00225 00226 00227 int main() 00228 { 00229 using namespace mln; 00230 00231 std::cerr << "Tests arith::minus:" << std::endl; 00232 std::cerr << "on int:" << std::endl; 00233 chk<int>(1000); 00234 std::cerr << "on unsigned:" << std::endl; 00235 chk<unsigned>(1000); 00236 std::cerr << "on int_s8:" << std::endl; 00237 chk<value::int_s8>(8); 00238 std::cerr << "on int_s16:" << std::endl; 00239 chk<value::int_s16>(1000); 00240 00241 00242 }