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/image/edge_image.hh>
00027 #include <mln/core/image/vertex_image.hh>
00028 
00029 #include <mln/core/image/graph_elt_window_if.hh>
00030 
00031 #include <mln/make/dummy_p_vertices.hh>
00032 #include <mln/make/p_vertices_with_mass_centers.hh>
00033 #include <mln/make/dummy_p_edges.hh>
00034 #include <mln/make/p_edges_with_mass_centers.hh>
00035 
00036 #include <mln/data/fill.hh>
00037 
00038 #include <mln/util/graph.hh>
00039 #include <mln/util/site_pair.hh>
00040 
00041 int main()
00042 {
00043   using namespace mln;
00044 
00045   typedef util::graph G;
00046 
00047   
00048 
00049 
00050 
00051   
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061   util::graph gr;
00062   gr.add_vertices(6);
00063   gr.add_edge(1,3);
00064   gr.add_edge(1,4);
00065   gr.add_edge(2,3);
00066   gr.add_edge(2,4);
00067   gr.add_edge(2,5);
00068   gr.add_edge(3,5);
00069   gr.add_edge(4,5);
00070 
00072   {
00073     static const unsigned result[] = { 3, 3, 5, 1, 5, 1, 5, 3 };
00074 
00075     
00076     typedef p_vertices<G> pv_t;
00077     pv_t pv = make::dummy_p_vertices(gr);
00078     typedef vertex_image<void,unsigned> v_ima_t;
00079     v_ima_t v_ima(pv);
00080     data::fill(v_ima, 4);
00081 
00082     
00083     typedef mln_ch_value_(v_ima_t, bool) v_mask_t;
00084     v_mask_t v_mask(pv);
00085     mln_piter_(v_mask_t) vm(v_mask.domain());
00086     for_all(vm)
00087       v_mask(vm) = vm.id()%2;
00088 
00089     mln_piter_(v_ima_t) v(v_ima.domain());
00090     typedef graph_elt_window_if<util::graph, pv_t, v_mask_t> win_t;
00091     win_t win(v_mask);
00092     mln_qiter_(win_t) q(win, v);
00093     unsigned i = 0;
00094     for_all(v)
00095       for_all(q)
00096       {
00097         mln_assertion(result[i++] == q.id());
00098         mln_assertion(q.id()%2);
00099       }
00100   }
00101 
00103   {
00104     
00105     typedef p_edges<G> pe_t;
00106     pe_t pe = make::dummy_p_edges(gr);
00107     typedef edge_image<void,unsigned> e_ima_t;
00108     e_ima_t e_ima(pe);
00109     data::fill(e_ima, 3);
00110 
00111     
00112     typedef mln_ch_value_(e_ima_t, bool) e_mask_t;
00113     e_mask_t e_mask(pe);
00114     mln_piter_(e_mask_t) em(e_mask.domain());
00115     for_all(em)
00116       e_mask(em) = em.id()%2;
00117 
00118     
00119     mln_piter_(e_ima_t) e(e_ima.domain());
00120     typedef graph_elt_window_if<util::graph, pe_t, e_mask_t> win_t;
00121     win_t win(e_mask);
00122     mln_qiter_(win_t) q(win, e);
00123     for_all(e)
00124       for_all(q)
00125         mln_assertion(q.id()%2);
00126   }
00127 
00128 
00130   {
00131     
00132     typedef p_edges<G> pe_t;
00133     pe_t pe = make::dummy_p_edges(gr);
00134     typedef edge_image<void,unsigned> e_ima_t;
00135     e_ima_t e_ima(pe);
00136     data::fill(e_ima, 3);
00137 
00138 
00139     
00140     typedef p_vertices<G> pv_t;
00141     pv_t pv = make::dummy_p_vertices(gr);
00142     typedef vertex_image<void,unsigned> v_ima_t;
00143     v_ima_t v_ima(pv);
00144     typedef mln_ch_value_(v_ima_t, bool) v_mask_t;
00145     v_mask_t v_mask(pv);
00146     mln_piter_(v_mask_t) vm(v_mask.domain());
00147     for_all(vm)
00148       v_mask(vm) = vm.id()%2;
00149 
00150     mln_piter_(e_ima_t) e(e_ima.domain());
00151     typedef graph_elt_window_if<util::graph, pe_t, v_mask_t> win_t;
00152     win_t win(v_mask);
00153     mln_qiter_(win_t) q(win, e);
00154     for_all(e)
00155       for_all(q)
00156         mln_assertion(v_mask(q.v1()) || v_mask(q.v2()));
00157   }
00158 
00159 
00161   {
00162     static const unsigned result[] = { 4, 4, 5, 1, 2, 3 };
00163 
00164     
00165     typedef p_vertices<G> pv_t;
00166     pv_t pv = make::dummy_p_vertices(gr);
00167     typedef vertex_image<void,unsigned> v_ima_t;
00168     v_ima_t v_ima(pv);
00169     data::fill(v_ima, 4);
00170 
00171     
00172     typedef p_edges<G> pe_t;
00173     pe_t pe = make::dummy_p_edges(gr);
00174     typedef edge_image<void,bool> e_mask_t;
00175     e_mask_t e_mask(pe);
00176     mln_piter_(e_mask_t) em(e_mask.domain());
00177     for_all(em)
00178       e_mask(em) = em.id()%2;
00179 
00180     mln_piter_(v_ima_t) v(v_ima.domain());
00181     typedef graph_elt_window_if<util::graph, pv_t, e_mask_t> win_t;
00182     win_t win(e_mask);
00183     mln_qiter_(win_t) q(win, v);
00184     unsigned i = 0;
00185     for_all(v)
00186       for_all(q)
00187       {
00188         mln_assertion(result[i++] == q.id());
00189         mln_assertion(e_mask(v.edge_with(q).id()));
00190       }
00191   }
00192 }