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/pw/image.hh> 00030 #include <mln/core/image/flat_image.hh> 00031 #include <mln/core/image/vmorph/cast_image.hh> 00032 #include <mln/core/image/dmorph/image_if.hh> 00033 #include <mln/core/image/dmorph/sub_image.hh> 00034 #include <mln/core/image/dmorph/extension_val.hh> 00035 00036 #include <mln/data/fill.hh> 00037 #include <mln/data/paste.hh> 00038 #include <mln/data/compare.hh> 00039 00040 #include <mln/fun/p2b/chess.hh> 00041 #include <mln/fun/p2v/iota.hh> 00042 00043 #include <mln/debug/iota.hh> 00044 #include <mln/debug/println.hh> 00045 #include <mln/trace/all.hh> 00046 00047 00048 int main() 00049 { 00050 using namespace mln; 00051 const unsigned size = 50; 00052 00053 // tests in two dimension 00054 { 00055 box2d b(point2d(1,2), point2d(2,4)); 00056 image2d<int> ima(b, 2); 00057 debug::iota(ima); 00058 00059 box2d b2(point2d(-1,-2), point2d(3,6)); 00060 image2d<int> ima2(b2, 0); 00061 debug::iota(ima2); 00062 00063 image2d<int> ima3(b, 2); 00064 00065 data::paste(ima, ima2); // Not so fast version... 00066 mln_assertion(ima == (ima2 | b)); 00067 00068 data::paste(ima, ima3); // Fast version... 00069 mln_assertion(ima == ima3); 00070 } 00071 00072 // tests in three dimension 00073 { 00074 box3d b(point3d(1,2, 1), point3d(2,4, 3)); 00075 image3d<int> ima(b, 2); 00076 debug::iota(ima); 00077 00078 box3d b2(point3d(-1,-2, -1), point3d(3,6, 3)); 00079 image3d<int> ima2(b2, 2); 00080 debug::iota(ima2); 00081 00082 image3d<int> ima3(b, 2); 00083 00084 data::paste(ima, ima2); // Not so fast version... 00085 mln_assertion(ima == (ima2 | b)); 00086 00087 data::paste(ima, ima3); // Fast version... 00088 mln_assertion(ima == ima3); 00089 } 00090 00092 { 00093 image1d<unsigned short> ima(size); 00094 image1d<unsigned short> out(size); 00095 00096 debug::iota(ima); 00097 data::paste(ima, out); 00098 00099 mln_assertion(ima == out); 00100 } 00101 00102 00104 { 00105 fun::p2v::iota f; 00106 const pw::image<fun::p2v::iota, box2d> ima(f, make::box2d(2,2, 5,5)); 00107 image2d<short unsigned int> out(8, 8); 00108 00109 data::fill(out, (short unsigned int)0); 00110 data::paste(ima, out); 00111 } 00112 00113 // flat image test 00114 { 00115 flat_image<short, box2d> ima(5, make::box2d(size, size)); 00116 image2d<unsigned short> out(size, size); 00117 00118 data::fill_with_value(ima, 51); 00119 data::paste(ima, out); 00120 00121 mln_assertion(ima == out); 00122 } 00123 00124 // image if test 00125 { 00126 typedef image2d<unsigned short> I; 00127 typedef fun::p2b::chess F; 00128 F f; 00129 typedef image_if<I, F> II; 00130 00131 I ima(size, size); 00132 I out(size, size); 00133 II ima_if = ima | f; 00134 00135 data::fill_with_value(ima, 0); 00136 debug::iota(ima); 00137 data::paste(ima_if, out); 00138 00139 mln_assertion(ima_if == (out | f)); 00140 } 00141 00142 // cast image test 00143 { 00144 typedef image2d<unsigned short> I; 00145 typedef cast_image_<int, I> II; 00146 typedef image2d<unsigned short> III; 00147 00148 I in(size, size); 00149 II cast(in); 00150 III out(size, size); 00151 00152 data::fill(in, (unsigned short)51); 00153 data::fill(out, (unsigned short)42); 00154 00155 data::paste(cast, out); 00156 00157 mln_assertion(cast == out); 00158 } 00159 00160 // sub_image test 00161 { 00162 typedef image2d<int> I; 00163 typedef sub_image< image2d<int>, box2d > II; 00164 typedef image2d<unsigned short> III; 00165 00166 I ima(size, size); 00167 II sub_ima(ima, make::box2d(4,4, 10,10)); 00168 III out(size, size); 00169 00170 data::fill(ima, 51); 00171 data::paste(sub_ima, out); 00172 00173 II::piter p(sub_ima.domain()); 00174 for_all(p) 00175 mln_assertion(sub_ima(p) == out(p)); 00176 } 00177 00178 // extended image test 00179 { 00180 typedef image2d<int> I; 00181 typedef extension_val< image2d<int> > II; 00182 typedef image2d<unsigned short> III; 00183 00184 I ima(size, size); 00185 II extend_ima(ima, 5); 00186 III out(size, size); 00187 00188 data::fill(ima, 51); 00189 data::paste(extend_ima, out); 00190 00191 II::piter p(extend_ima.domain()); 00192 for_all(p) 00193 mln_assertion(extend_ima(p) == out(p)); 00194 } 00195 }