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