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/var.hh>
00027 #include <mln/core/image/image2d.hh>
00028 #include <mln/core/alias/neighb2d.hh>
00029 #include <mln/core/image/dmorph/image_if.hh>
00030 #include <mln/core/site_set/p_array.hh>
00031
00032 #include <mln/data/sort_psites.hh>
00033 #include <mln/data/compare.hh>
00034 #include <mln/pw/value.hh>
00035 #include <mln/debug/println.hh>
00036
00037 #include <mln/morpho/tree/compute_parent.hh>
00038
00039
00040 static mln::image2d<mln::point2d> ref1()
00041 {
00042 using namespace mln;
00043
00044 image2d<point2d> ref1(make::box2d(3,3));
00045
00046 ref1(point2d(0,0)) = point2d(0,0);
00047 ref1(point2d(0,1)) = point2d(0,0);
00048 ref1(point2d(0,2)) = point2d(0,0);
00049 ref1(point2d(1,1)) = point2d(0,0);
00050 ref1(point2d(2,2)) = point2d(2,2);
00051
00052 return ref1;
00053 }
00054
00055
00056 static mln::image2d<mln::point2d> ref2()
00057 {
00058 using namespace mln;
00059
00060 image2d<point2d> ref2(make::box2d(3,3));
00061
00062 ref2(point2d(0,0)) = point2d(0,1);
00063 ref2(point2d(0,1)) = point2d(0,2);
00064 ref2(point2d(0,2)) = point2d(0,2);
00065 ref2(point2d(1,0)) = point2d(0,0);
00066 ref2(point2d(1,1)) = point2d(0,1);
00067 ref2(point2d(1,2)) = point2d(0,1);
00068 ref2(point2d(2,0)) = point2d(0,0);
00069 ref2(point2d(2,1)) = point2d(0,0);
00070 ref2(point2d(2,2)) = point2d(0,2);
00071
00072 return ref2;
00073 }
00074
00075
00076 int main()
00077 {
00078 using namespace mln;
00079
00080 {
00081 bool vals[] = { 1, 1, 1,
00082 0, 1, 0,
00083 0, 0, 1 };
00084 image2d<bool> ima = make::image2d(vals);
00085 typedef image_if<image2d<bool>, pw::value_<image2d<bool> > > sub_t;
00086 sub_t sub = ima | pw::value(ima);
00087
00088 typedef image_if<image2d<point2d>, pw::value_<image2d<bool> > > par_t;
00089 par_t par = morpho::tree::compute_parent(sub, c4(), sub.domain());
00090 mln_assertion(par == (ref1() | sub.domain()));
00091 }
00092
00093 {
00094 unsigned char vals[] = { 3, 2, 1,
00095 3, 2, 3,
00096 3, 4, 1 };
00097 image2d<unsigned char> ima = make::image2d(vals);
00098
00099 typedef p_array<point2d> S;
00100 S s = data::sort_psites_increasing(ima);
00101 image2d<point2d> par = morpho::tree::compute_parent(ima, c4(), s);
00102 mln_assertion(par == ref2());
00103 }
00104
00105 }