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/alias/point2d.hh>
00027 
00029 #include <mln/core/site_set/p_edges.hh>
00030 #include <mln/core/image/graph_elt_window.hh>
00031 #include <mln/core/image/graph_elt_neighborhood.hh>
00032 #include <mln/core/image/vertex_image.hh>
00033 #include <mln/core/neighb.hh>
00034 #include <mln/core/var.hh>
00035 #include <mln/pw/all.hh>
00036 #include <mln/fun/i2v/array.hh>
00037 #include <mln/util/graph.hh>
00038 #include <mln/make/vertex_image.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 static unsigned expected_fwd_nbh[5][3] = { { 1, X, X },
00060                                            { 0, 2, 3 },
00061                                            { 1, 4, X },
00062                                            { 1, 4, X },
00063                                            { 3, 2, X } };
00064 
00065 static unsigned expected_bkd_nbh[5][3] = { { 1, 0, X },
00066                                            { 3, 2, 0 },
00067                                            { 4, 1, X },
00068                                            { 4, 1, X },
00069                                            { 2, 3, X } };
00070 
00071 
00072 int main()
00073 {
00074   using namespace mln;
00075 
00076   
00077 
00078 
00079 
00080   
00081   typedef fun::i2v::array<point2d> fsite_t;
00082   fsite_t sites(5);
00083   sites(0) = point2d(0,0); 
00084   sites(1) = point2d(2,2); 
00085   sites(2) = point2d(0,4); 
00086   sites(3) = point2d(4,3); 
00087   sites(4) = point2d(4,4); 
00088 
00089   util::graph g;
00090 
00091   
00092   g.add_vertices(sites.size());
00093 
00094   
00095   g.add_edge(0, 1);
00096   g.add_edge(1, 2);
00097   g.add_edge(1, 3);
00098   g.add_edge(3, 4);
00099   g.add_edge(4, 2);
00100 
00101   
00102 
00103 
00104 
00105   
00106   typedef fun::i2v::array<unsigned> viota_t;
00107   viota_t iota(g.v_nmax());
00108   for (unsigned i = 0; i < iota.size(); ++i)
00109     iota(i) = 10 + i;
00110 
00111   
00112   typedef vertex_image<point2d,unsigned> ima_t;
00113   ima_t ima = make::vertex_image(g, sites, iota);
00114 
00115   
00116 
00117 
00118 
00119   mln_edge_iter_(util::graph) ei(g);
00120   mln_edge_nbh_edge_iter_(util::graph) en(ei);
00121 
00122   
00123   mln_piter_(ima_t) p(ima.domain());
00124   unsigned i = 10;
00125   for_all(p)
00126     mln_assertion(ima(p) == i++);
00127 
00128   typedef ima_t::win_t win_t;
00129   win_t win;
00130 
00131   {
00132     
00133     mln_fwd_qiter_(win_t) q(win, p);
00134     for_all(p)
00135     {
00136       i = 0;
00137       for_all(q)
00138       {
00139         mln_assertion(expected_fwd_nbh[p.id()][i] == q.id());
00140         ++i;
00141       }
00142     }
00143   }
00144 
00145   {
00146     
00147     mln_bkd_qiter_(win_t) q(win, p);
00148     for_all(p)
00149     {
00150       i = 0;
00151       for_all(q)
00152       {
00153         mln_assertion(expected_bkd_nbh[p.id()][i] == q.id());
00154         ++i;
00155       }
00156     }
00157   }
00158 
00159 
00160   typedef ima_t::nbh_t neighb_t;
00161   neighb_t neigh;
00162 
00163   {
00164     
00165     mln_fwd_niter_(neighb_t) n(neigh, p);
00166     for_all(p)
00167     {
00168       i = 0;
00169       for_all(n)
00170       {
00171         mln_assertion(expected_fwd_nbh[p.id()][i] == n.id());
00172         ++i;
00173       }
00174     }
00175   }
00176 
00177   {
00178     
00179     mln_bkd_niter_(neighb_t) n(neigh, p);
00180     for_all(p)
00181     {
00182       i = 0;
00183       for_all(n)
00184       {
00185         mln_assertion(expected_bkd_nbh[p.id()][i] == n.id());
00186         ++i;
00187       }
00188     }
00189   }
00190 
00191 }