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 <vector>
00027
00028 #include <mln/core/site_set/p_vertices.hh>
00029 #include <mln/core/image/graph_elt_window.hh>
00030 #include <mln/core/image/graph_elt_neighborhood.hh>
00031 #include <mln/core/concept/function.hh>
00032 #include <mln/core/neighb.hh>
00033 #include <mln/core/var.hh>
00034 #include <mln/accu/shape/bbox.hh>
00035 #include <mln/fun/i2v/array.hh>
00036 #include <mln/util/graph.hh>
00037 #include <mln/debug/draw_graph.hh>
00038 #include <mln/debug/println.hh>
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 static const unsigned X = mln_max(unsigned);
00056
00057
00058
00059
00060 static unsigned expected_fwd_nb[5][3] = { { 1, X, X },
00061 { 0, 2, 3 },
00062 { 1, 4, X },
00063 { 1, 4, X },
00064 { 3, 2, X } };
00065
00066 static unsigned expected_bkd_nb[5][3] = { { 1, X, X },
00067 { 3, 2, 0 },
00068 { 4, 1, X },
00069 { 4, 1, X },
00070 { 2, 3, X } };
00071
00072
00073 int main()
00074 {
00075 using namespace mln;
00076
00077
00078
00079
00080
00081
00082 typedef fun::i2v::array<point2d> fsite_t;
00083 fsite_t sites(5);
00084 sites(0) = point2d(0,0);
00085 sites(1) = point2d(2,2);
00086 sites(2) = point2d(0,4);
00087 sites(3) = point2d(4,3);
00088 sites(4) = point2d(4,4);
00089
00090
00091 util::graph g;
00092
00093
00094 g.add_vertices(sites.size());
00095
00096
00097 g.add_edge(0, 1);
00098 g.add_edge(1, 2);
00099 g.add_edge(1, 3);
00100 g.add_edge(3, 4);
00101 g.add_edge(4, 2);
00102
00103
00104
00105
00106
00107
00108
00109 typedef p_vertices<util::graph, fsite_t> S;
00110 S pv(g, sites);
00111
00112
00113
00114
00115
00116
00117 typedef fun::i2v::array<unsigned> viota_t;
00118 viota_t iota(pv.nsites());
00119 for (unsigned i = 0; i < iota.size(); ++i)
00120 iota(i) = 10 + i;
00121
00122
00123 mln_const_VAR(ima, (iota | pv));
00124
00125 {
00126
00127
00128
00129 accu::shape::bbox<point2d> a;
00130 mln_piter_(ima_t) p(ima.domain());
00131 for_all(p)
00132 a.take(p);
00133 box2d bbox = a.to_result();
00134 mln_assertion(bbox == make::box2d(5, 5));
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 image2d<int> ima_rep(bbox);
00155
00156
00157
00158 debug::draw_graph(ima_rep, pv, 1, 9);
00159 }
00160
00161
00162
00163
00164
00165
00166 mln_piter_(ima_t) p(ima.domain());
00167 unsigned i = 10;
00168 for_all(p)
00169 mln_assertion(ima(p) == i++);
00170
00171 typedef graph_elt_window<util::graph,S> win_t;
00172 win_t win;
00173
00174 {
00175
00176 mln_qiter_(win_t) q(win, p);
00177 for_all(p)
00178 {
00179 i = 0;
00180 for_all(q)
00181 {
00182 mln_assertion(expected_fwd_nb[p.id()][i] == q.id());
00183 ++i;
00184 }
00185 }
00186 }
00187
00188 {
00189
00190 mln_bkd_qiter_(win_t) q(win, p);
00191 for_all(p)
00192 {
00193 i = 0;
00194 for_all(q)
00195 {
00196 mln_assertion(expected_bkd_nb[p.id()][i] == q.id());
00197 ++i;
00198 }
00199 }
00200 }
00201
00202 typedef graph_elt_neighborhood<util::graph,S> neighb_t;
00203 neighb_t neigh;
00204 {
00205
00206 mln_niter_(neighb_t) n(neigh, p);
00207
00208 for_all(p)
00209 {
00210 i = 0;
00211 for_all(n)
00212 {
00213 mln_assertion(expected_fwd_nb[p.id()][i] == n.id());
00214 ++i;
00215 }
00216 }
00217 }
00218
00219 {
00220
00221 mln_bkd_niter_(neighb_t) n(neigh, p);
00222 for_all(p)
00223 {
00224 i = 0;
00225 for_all(n)
00226 {
00227 mln_assertion(expected_bkd_nb[p.id()][i] == n.id());
00228 ++i;
00229 }
00230 }
00231 }
00232 }