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/image/graph_elt_mixed_window.hh>
00029 #include <mln/core/image/vertex_image.hh>
00030 #include <mln/core/image/edge_image.hh>
00031 #include <mln/fun/i2v/array.hh>
00032 #include <mln/util/graph.hh>
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 static const unsigned X = mln_max(unsigned); 
00050 
00051 
00052 static unsigned expected_fwd_nb[5][3] = { { 0, X, X },
00053                                           { 0, 1, 2 },
00054                                           { 1, 4, X },
00055                                           { 2, 3, X },
00056                                           { 3, 4, X } };
00057 
00058 
00059 static unsigned expected_bkd_nb[5][3] = { { 0, X, X },
00060                                           { 2, 1, 0 },
00061                                           { 4, 1, X },
00062                                           { 3, 2, X },
00063                                           { 4, 3, X } };
00064 
00065 
00066 int main()
00067 {
00068   using namespace mln;
00069 
00070   
00071 
00072 
00073 
00074   
00075   typedef fun::i2v::array<point2d> fsite_t;
00076   fsite_t sites(5);
00077   sites(0) = point2d(0,0); 
00078   sites(1) = point2d(2,2); 
00079   sites(2) = point2d(0,4); 
00080   sites(3) = point2d(4,3); 
00081   sites(4) = point2d(4,4); 
00082 
00083   
00084   util::graph g;
00085 
00086   
00087   g.add_vertices(sites.size());
00088 
00089   
00090   g.add_edge(0, 1);
00091   g.add_edge(1, 2);
00092   g.add_edge(1, 3);
00093   g.add_edge(3, 4);
00094   g.add_edge(4, 2);
00095 
00096   
00097 
00098   
00099 
00100 
00101 
00102   
00103   typedef fun::i2v::array<unsigned> viota_t;
00104   viota_t iota(g.v_nmax());
00105   for (unsigned i = 0; i < iota.size(); ++i)
00106     iota(i) = 10 + i;
00107 
00108 
00109   
00110   typedef fun::i2v::array<unsigned> eiota_t;
00111   eiota_t eiota(g.e_nmax());
00112   for (unsigned i = 0; i < eiota.size(); ++i)
00113     eiota(i) = 20 + i;
00114 
00115 
00116   typedef vertex_image<void,unsigned> v_ima_t;
00117   v_ima_t v_ima(g, iota);
00118 
00119   typedef edge_image<void,unsigned> e_ima_t;
00120   e_ima_t e_ima(g, eiota);
00121 
00122 
00123   
00124   mln_piter_(v_ima_t) v(v_ima.domain());
00125 
00126 
00127   typedef graph_elt_mixed_window<util::graph,
00128     v_ima_t::domain_t,
00129     e_ima_t::domain_t> edge_win_t;
00130   edge_win_t win;
00131 
00132   
00133   {
00134     for_all(v)
00135     {
00136       int i = 0;
00137       
00138       mln_qiter_(edge_win_t) e(win, e_ima.domain(), v);
00139       for_all(e)
00140       {
00141         mln_assertion(expected_fwd_nb[v.id()][i++] == e.id());
00142         mln_assertion((e.id() + 20) == e_ima(e));
00143       }
00144     }
00145   }
00146 
00147   
00148   {
00149     for_all(v)
00150     {
00151       int i = 0;
00152       
00153       mln_bkd_qiter_(edge_win_t) e(win, e_ima.domain(), v);
00154       for_all(e)
00155       {
00156         mln_assertion(expected_bkd_nb[v.id()][i++] == e.id());
00157         mln_assertion((e.id() + 20) == e_ima(e));
00158       }
00159     }
00160   }
00161 
00162 
00163 
00164 
00165 
00166 
00167 }