Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 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 <cmath> 00027 00028 #include <mln/core/image/image1d.hh> 00029 #include <mln/core/image/image2d.hh> 00030 #include <mln/core/image/image3d.hh> 00031 #include <mln/core/image/dmorph/sub_image.hh> 00032 00033 #include <mln/core/image/dmorph/image_if.hh> 00034 #include <mln/fun/p2b/chess.hh> 00035 00036 #include <mln/literal/origin.hh> 00037 00038 #include <mln/value/int_u8.hh> 00039 #include <mln/value/int_u16.hh> 00040 00041 #include <mln/value/int_s8.hh> 00042 #include <mln/value/int_s16.hh> 00043 00044 #include <mln/data/fill.hh> 00045 #include <mln/data/transform.hh> 00046 00047 #include <mln/debug/iota.hh> 00048 00049 #include <mln/arith/plus.hh> 00050 00051 00052 00053 00054 struct mysqrt : mln::Function_v2v<mysqrt> 00055 { 00056 typedef unsigned short result; 00057 result operator()(int c) const 00058 { 00059 return result(c % 42); 00060 } 00061 }; 00062 00063 00064 namespace mln 00065 { 00066 template <typename I> 00067 void 00068 chck(const Image<I>& ref_) 00069 { 00070 const I& ref = exact(ref_); 00071 00072 mln_ch_value(I, mln_result_(mysqrt)) out; 00073 { 00074 out = data::transform(ref, mysqrt()); 00075 mln_piter(I) p (ref.domain ()); 00076 for_all(p) 00077 mln_assertion ((mln_value(I))(ref(p) % 42) == out(p) ); 00078 } 00079 } 00080 00081 template <typename V> 00082 void 00083 chk() 00084 { 00085 unsigned sli = 4; 00086 unsigned row = 16; 00087 unsigned col = 64; 00088 00089 00090 (std::cerr << "in 1d ... ").flush (); 00091 { 00092 typedef image1d<V> I; 00093 typedef sub_image<I, box1d> J; 00094 00095 for (unsigned i = 1; i < col; ++i) 00096 { 00097 I ima(i); 00098 debug::iota(ima); 00099 chck (ima); 00100 } 00101 } 00102 std::cerr << "OK" << std::endl; 00103 00104 (std::cerr << "in 2d ... ").flush (); 00105 { 00106 typedef image2d<V> I; 00107 00108 for (unsigned i = 1; i < col; ++i) 00109 for (unsigned j = 1; j < row; ++j) 00110 { 00111 I ima(j, i); 00112 debug::iota(ima); 00113 chck (ima); 00114 } 00115 } 00116 std::cerr << "OK" << std::endl; 00117 00118 (std::cerr << "in 3d ... ").flush (); 00119 { 00120 typedef image3d<V> I; 00121 00122 for (unsigned i = 1; i < col; ++i) 00123 for (unsigned j = 1; j < row; ++j) 00124 for (unsigned k = 1; k < sli; ++k) 00125 { 00126 I ima(k, j, i); 00127 debug::iota(ima); 00128 chck (ima); 00129 } 00130 } 00131 std::cerr << "OK" << std::endl; 00132 } 00133 00134 } 00135 00136 00137 00138 00139 00140 int main() 00141 { 00142 using namespace mln; 00143 00144 std::cerr << "Tests data::transform:" << std::endl; 00145 std::cerr << "on int:" << std::endl; 00146 chk<int>(); 00147 std::cerr << "on unsigned:" << std::endl; 00148 chk<unsigned>(); 00149 std::cerr << "on int_u8:" << std::endl; 00150 chk<value::int_u8>(); 00151 std::cerr << "on int_u16:" << std::endl; 00152 chk<value::int_u16>(); 00153 std::cerr << "on int_s8:" << std::endl; 00154 chk<value::int_s8>(); 00155 std::cerr << "on int_s16:" << std::endl; 00156 chk<value::int_s16>(); 00157 }