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
00029
00030 #include <mln/core/alias/point2d.hh>
00031
00033 #include <mln/core/image/vertex_image.hh>
00034 #include <mln/pw/all.hh>
00035 #include <mln/fun/i2v/array.hh>
00036 #include <mln/util/graph.hh>
00037 #include <mln/util/line_graph.hh>
00038 #include <mln/util/site_pair.hh>
00039 #include <mln/make/vertex_image.hh>
00040
00041 #include <mln/morpho/watershed/flooding.hh>
00042
00043 static const unsigned ima_ref[] = { 0, 10, 5, 2, 4, 6, 0, 3, 5, 2 };
00044 static const unsigned ima_wst[] = { 2, 0, 1, 2, 2, 1, 1, 2, 0, 1 };
00045
00046 int main()
00047 {
00048 using namespace mln;
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 util::graph g;
00070
00071
00072 g.add_vertices(8);
00073
00074
00075 g.add_edge(0, 1);
00076 g.add_edge(1, 2);
00077 g.add_edge(2, 3);
00078
00079 g.add_edge(0, 4);
00080 g.add_edge(1, 5);
00081 g.add_edge(2, 6);
00082 g.add_edge(3, 7);
00083
00084 g.add_edge(4, 5);
00085 g.add_edge(5, 6);
00086 g.add_edge(6, 7);
00087
00088 util::line_graph<util::graph> lg(g);
00089
00090
00091 typedef util::site_pair<point2d> P;
00092 typedef fun::i2v::array<P> fsite_t;
00093 fsite_t sites(10);
00094 sites(0) = P(point2d(0,0), point2d(0,1));
00095 sites(1) = P(point2d(0,1), point2d(0,2));
00096 sites(2) = P(point2d(0,2), point2d(0,3));
00097 sites(3) = P(point2d(0,0), point2d(1,0));
00098 sites(4) = P(point2d(0,1), point2d(1,1));
00099 sites(5) = P(point2d(0,2), point2d(1,2));
00100 sites(6) = P(point2d(0,3), point2d(1,3));
00101 sites(7) = P(point2d(1,0), point2d(1,1));
00102 sites(8) = P(point2d(1,1), point2d(1,2));
00103 sites(9) = P(point2d(1,2), point2d(1,3));
00104
00105
00106 typedef fun::i2v::array<unsigned> edge_values_t;
00107 edge_values_t edge_values(10);
00108
00109 static const unsigned values[] = { 0, 10, 5, 2, 4, 6, 0, 3, 5, 2 };
00110 for (unsigned i = 0; i < edge_values.size(); ++i)
00111 edge_values(i) = values[i];
00112
00113 typedef vertex_image< P, unsigned, util::line_graph<util::graph> > ima_t;
00114 ima_t ima = make::vertex_image(lg, sites, edge_values);
00115
00116
00117
00118
00119
00120
00121 unsigned i = 0;
00122
00123
00124 mln_piter_(ima_t) p(ima.domain());
00125 for_all (p)
00126 mln_assertion(ima_ref[i++] == ima(p));
00127
00128 typedef ima_t::nbh_t nbh_t;
00129 nbh_t nbh;
00130 unsigned nbasins;
00131 typedef mln_ch_value_(ima_t,unsigned) wshed_t;
00132 wshed_t wshed = morpho::watershed::flooding(ima, nbh, nbasins);
00133 mln_assertion(nbasins == 2);
00134
00135 i = 0;
00136
00137 mln_piter_(wshed_t) pw(wshed.domain());
00138 for_all (pw)
00139 mln_assertion(ima_wst[i++] == wshed(pw));
00140 }