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 00036 #include <mln/core/routine/duplicate.hh> 00037 #include <mln/data/saturate.hh> 00038 #include <mln/debug/iota.hh> 00039 00040 #include <mln/debug/println.hh> 00041 00042 00043 namespace mln 00044 { 00045 00046 /* 00047 00048 template <typename I, typename J> 00049 void 00050 chck(I& ref, J& out, mln_value(I) min, mln_value(I) max) 00051 { 00052 mln_value(J) min2 = min; 00053 mln_value(J) max2 = max; 00054 00055 mln_piter(I) p (ref.domain ()); 00056 00057 { 00058 data::saturate(ref, min, max, out); 00059 00060 for_all(p) 00061 { 00062 if (ref(p) <= min) 00063 { 00064 mln_assertion(out(p) == min2); 00065 continue; 00066 } 00067 if (ref(p) >= max) 00068 { 00069 mln_assertion(out(p) == max2); 00070 continue; 00071 } 00072 mln_assertion(ref(p) == (mln_value(I)) out(p)); 00073 } 00074 } 00075 00076 { 00077 data::saturate_inplace(ref, min, max); 00078 00079 for_all(p) 00080 { 00081 mln_assertion(ref(p) == (mln_value(I)) out(p)); 00082 } 00083 } 00084 } 00085 00086 template <typename I, typename J> 00087 void 00088 chk1d(unsigned cols, 00089 int min, 00090 int max) 00091 { 00092 image1d<I> ima (cols); 00093 image1d<J> out (cols); 00094 debug::iota (ima); 00095 chck(ima, out, min, max); 00096 } 00097 00098 template <typename I, typename J> 00099 void 00100 chk2d(unsigned rows, 00101 unsigned cols, 00102 int min, 00103 int max) 00104 { 00105 image2d<I> ima (rows, cols); 00106 image2d<J> out (rows, cols); 00107 debug::iota (ima); 00108 chck(ima, out, min, max); 00109 } 00110 00111 template <typename I, typename J> 00112 void 00113 chk3d(unsigned slis, 00114 unsigned rows, 00115 unsigned cols, 00116 int min, 00117 int max) 00118 { 00119 image3d<I> ima (slis, rows, cols); 00120 image3d<J> out (slis, rows, cols); 00121 debug::iota (ima); 00122 chck(ima, out, min, max); 00123 } 00124 00125 */ 00126 00127 } 00128 00129 00130 int main() 00131 { 00132 using namespace mln; 00133 00134 /* 00135 00136 unsigned slis_start = 1; 00137 unsigned slis_end = 3; 00138 00139 unsigned rows_start = 1; 00140 unsigned rows_end = 5; 00141 00142 unsigned cols_start = 2; 00143 unsigned cols_end = 6; 00144 00145 00146 std::cerr << "Tests data::saturate" << std::endl; 00147 00148 (std::cerr << "in 1d ... ").flush (); 00149 { 00150 for (unsigned i = cols_start; i < cols_end; ++i) 00151 for (unsigned j = 1; j < i; ++j) 00152 for (unsigned k = j + 1; k <= i; ++k) 00153 { 00154 chk1d<int, int>(i, j, k); 00155 chk1d<unsigned, unsigned>(i, j, k); 00156 chk1d<int, unsigned>(i, j, k); 00157 chk1d<unsigned, int>(i, j, k); 00158 00159 chk1d<value::int_u8, value::int_u8>(i, j, k); 00160 chk1d<value::int_u16, value::int_u16>(i, j, k); 00161 chk1d<value::int_s8, value::int_s8>(i, j, k); 00162 chk1d<value::int_s16, value::int_s16>(i, j, k); 00163 00164 chk1d<unsigned, value::int_u8>(i, j, k); 00165 chk1d<unsigned, value::int_u16>(i, j, k); 00166 chk1d<int, value::int_s8>(i, j, k); 00167 chk1d<int, value::int_s16>(i, j, k); 00168 00169 chk1d<value::int_u8, unsigned>(i, j, k); 00170 chk1d<value::int_u16, unsigned>(i, j, k); 00171 chk1d<value::int_s8, int>(i, j, k); 00172 chk1d<value::int_s16, int>(i, j, k); 00173 } 00174 } 00175 std::cerr << "OK" << std::endl; 00176 00177 (std::cerr << "in 2d ... ").flush (); 00178 { 00179 for (unsigned h = rows_start; h < rows_end; ++h) 00180 for (unsigned i = cols_start; i < cols_end; ++i) 00181 for (unsigned j = 1; j < i; ++j) 00182 for (unsigned k = j + 1; k <= i; ++k) 00183 { 00184 chk2d<int, int>(h, i, j, k); 00185 chk2d<unsigned, unsigned>(h, i, j, k); 00186 chk2d<int, unsigned>(h, i, j, k); 00187 chk2d<unsigned, int>(h, i, j, k); 00188 00189 chk2d<value::int_u8, value::int_u8>(h, i, j, k); 00190 chk2d<value::int_u16, value::int_u16>(h, i, j, k); 00191 chk2d<value::int_s8, value::int_s8>(h, i, j, k); 00192 chk2d<value::int_s16, value::int_s16>(h, i, j, k); 00193 00194 chk2d<unsigned, value::int_u8>(h, i, j, k); 00195 chk2d<unsigned, value::int_u16>(h, i, j, k); 00196 chk2d<int, value::int_s8>(h, i, j, k); 00197 chk2d<int, value::int_s16>(h, i, j, k); 00198 00199 chk2d<value::int_u8, unsigned>(h, i, j, k); 00200 chk2d<value::int_u16, unsigned>(h, i, j, k); 00201 chk2d<value::int_s8, int>(h, i, j, k); 00202 chk2d<value::int_s16, int>(h, i, j, k); 00203 } 00204 } 00205 std::cerr << "OK" << std::endl; 00206 00207 00208 (std::cerr << "in 3d ... ").flush (); 00209 { 00210 for (unsigned g = slis_start; g < slis_end; ++g) 00211 for (unsigned h = rows_start; h < rows_end; ++h) 00212 for (unsigned i = cols_start; i < cols_end; ++i) 00213 for (unsigned j = 1; j < i; ++j) 00214 for (unsigned k = j + 1; k <= i; ++k) 00215 { 00216 chk3d<int, int>(g, h, i, j, k); 00217 chk3d<unsigned, unsigned>(g, h, i, j, k); 00218 chk3d<int, unsigned>(g, h, i, j, k); 00219 chk3d<unsigned, int>(g, h, i, j, k); 00220 00221 chk3d<value::int_u8, value::int_u8>(g, h, i, j, k); 00222 chk3d<value::int_u16, value::int_u16>(g, h, i, j, k); 00223 chk3d<value::int_s8, value::int_s8>(g, h, i, j, k); 00224 chk3d<value::int_s16, value::int_s16>(g, h, i, j, k); 00225 00226 chk3d<unsigned, value::int_u8>(g, h, i, j, k); 00227 chk3d<unsigned, value::int_u16>(g, h, i, j, k); 00228 chk3d<int, value::int_s8>(g, h, i, j, k); 00229 chk3d<int, value::int_s16>(g, h, i, j, k); 00230 00231 chk3d<value::int_u8, unsigned>(g, h, i, j, k); 00232 chk3d<value::int_u16, unsigned>(g, h, i, j, k); 00233 chk3d<value::int_s8, int>(g, h, i, j, k); 00234 chk3d<value::int_s16, int>(g, h, i, j, k); 00235 } 00236 } 00237 std::cerr << "OK" << std::endl; 00238 00239 */ 00240 00241 }