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