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 00031 #include <mln/core/image/dmorph/image_if.hh> 00032 #include <mln/fun/p2b/chess.hh> 00033 #include <mln/border/find.hh> 00034 #include <mln/literal/origin.hh> 00035 #include <mln/value/int_u8.hh> 00036 #include <mln/value/rgb8.hh> 00037 00038 00039 #include <mln/debug/iota.hh> 00040 #include <mln/border/find.hh> 00041 #include <mln/core/routine/duplicate.hh> 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 int main() 00085 { 00086 using namespace mln; 00087 00088 box1d b1(literal::origin, point1d(1)); 00089 box2d b2(literal::origin, point2d(1,1)); 00090 box3d b3(literal::origin, point3d(1,1,1)); 00091 f_box1d_t f_b1(b1); 00092 f_box2d_t f_b2(b2); 00093 f_box3d_t f_b3(b3); 00094 mln::fun::p2b::chess c_b; 00095 00096 { 00097 typedef image1d<int> I; 00098 (std::cerr << "Tests border::find on int in 1d ... ").flush (); 00099 I ima(3, 51); 00100 debug::iota(ima); 00101 mln_assertion(border::find(ima) == 51); 00102 sub_image<I, box1d> sub(ima, b1); 00103 mln_assertion(border::find(sub) == 51); 00104 00105 image_if<I, f_box1d_t> imaif(ima, f_b1); 00106 mln_assertion(border::find(imaif) == 51); 00107 00108 mln_assertion(border::find( (ima | b1) ) == 51); 00109 mln_assertion(border::find( (ima | b1) | f_b1 ) == 51); 00110 std::cerr << "OK" << std::endl; 00111 } 00112 00113 { 00114 typedef image2d<value::int_u8> I; 00115 (std::cerr << "Tests border::find on int_u8 in 2d ... ").flush (); 00116 I ima(10, 10, 42); 00117 debug::iota(ima); 00118 mln_assertion(border::find(ima) == 42); 00119 sub_image<I, box2d> sub(ima, b2); 00120 mln_assertion(border::find(sub) == 42); 00121 00122 image_if<I, f_box2d_t > imaif(ima, f_b2); 00123 mln_assertion(border::find(imaif) == 42); 00124 00125 image_if<I, fun::p2b::chess > imaif_chess(ima, c_b); 00126 mln_assertion(border::find(imaif_chess) == 42); 00127 00128 00129 mln_assertion(border::find( (ima | b2) ) == 42); 00130 mln_assertion(border::find( (ima | b2) | f_b2 ) == 42); 00131 mln_assertion(border::find( (ima | b2) | c_b ) == 42); 00132 mln_assertion(border::find( (ima | b2) | c_b | f_b2 ) == 42); 00133 mln_assertion(border::find( (ima | b2) | f_b2 | c_b ) == 42); 00134 00135 std::cerr << "OK" << std::endl; 00136 } 00137 00138 { 00139 typedef image3d<value::rgb8> I; 00140 (std::cerr << "Tests border::find on rgb8 in 3d ... ").flush (); 00141 I ima(10, 10, 10, 36); 00142 mln_assertion(border::find(ima) == 36); 00143 mln_assertion( ima.has(point3d(2,2,2)) == true ); 00144 sub_image<I, box3d> sub(ima, b3); 00145 mln_assertion(border::find(sub) == 36); 00146 00147 image_if<I, f_box3d_t> imaif(ima, f_b3); 00148 mln_assertion(border::find(imaif) == 36); 00149 mln_assertion(border::find( (ima | b3) ) == 36); 00150 mln_assertion(border::find( (ima | b3) | f_b3 ) == 36); 00151 std::cerr << "OK" << std::endl; 00152 } 00153 }