00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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 }