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 00030 #include <mln/win/segment1d.hh> 00031 #include <mln/win/rectangle2d.hh> 00032 #include <mln/win/cuboid3d.hh> 00033 00034 #include <mln/make/pixel.hh> 00035 00036 00037 template <typename I, typename W> 00038 void test_fill(I& ima, const W& win, unsigned nsites) 00039 { 00040 mln_piter(I) p(ima.domain()); 00041 mln_fwd_qixter(I, W) fq(ima, win, p); 00042 for_all(p) 00043 { 00044 unsigned i = 0; 00045 for_all(fq) 00046 ++i, fq.val() = 51; 00047 mln_assertion(i == nsites); 00048 } 00049 mln_bkd_qixter(I, W) bq(ima, win, p); 00050 for_all(p) 00051 { 00052 unsigned i = 0; 00053 for_all(bq) 00054 ++i, bq.val() = 42; 00055 mln_assertion(i == nsites); 00056 } 00057 } 00058 00059 // FIXME: Test promotion and other constructions. 00060 00061 template <typename P, typename W> 00062 void test_pixel(const P& pxl, const W& win) 00063 { 00064 mln_fwd_qixter(mln_image(P), W) fq(pxl, win); 00065 for_all(fq) 00066 fq.val() = 2 * fq.val(); 00067 mln_bkd_qixter(mln_image(P), W) bq(pxl, win); 00068 for_all(bq) 00069 bq.val() = bq.val() + 1; 00070 } 00071 00072 int main() 00073 { 00074 using namespace mln; 00075 00076 border::thickness = 1; 00077 00078 // 1-D case. 00079 { 00080 typedef image1d<int> I; 00081 I ima(6); 00082 00083 win::segment1d seg(3); 00084 point1d p = point1d(3); 00085 00086 test_fill(ima, seg, 3); 00087 test_pixel(make::pixel(ima, p), seg); 00088 } 00089 00090 // 2-D case. 00091 { 00092 typedef image2d<int> I; 00093 I ima(5, 5); 00094 00095 win::rectangle2d rect(3, 3); 00096 point2d p = point2d(1, 1); 00097 00098 test_fill(ima, rect, 3 * 3); 00099 test_pixel(make::pixel(ima, p), rect); 00100 } 00101 00102 // 3-D case. 00103 { 00104 typedef image3d<int> I; 00105 I ima(3, 4, 5); 00106 00107 win::cuboid3d cuboid(3, 3, 3); 00108 point3d p = point3d(2, 1, 3); 00109 00110 test_fill(ima, cuboid, 3 * 3 * 3); 00111 test_pixel(make::pixel(ima, p), cuboid); 00112 } 00113 00114 }