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_neighborhood_if.hh>
00030
00031 #include <mln/data/fill.hh>
00032
00033 #include <mln/util/graph.hh>
00034
00035 #include <mln/value/label_8.hh>
00036
00037 #include <mln/fun/i2v/array.hh>
00038
00039 #include <mln/graph/labeling.hh>
00040 #include <mln/graph/to_neighb.hh>
00041
00042
00043
00044 static const unsigned result[] = { 1, 2, 2, 3, 2, 3 };
00045
00046
00047
00048 int main()
00049 {
00050 using namespace mln;
00051
00052 typedef util::graph G;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 util::graph gr;
00069 gr.add_vertices(6);
00070 gr.add_edge(1,3);
00071 gr.add_edge(1,4);
00072 gr.add_edge(2,3);
00073 gr.add_edge(2,4);
00074 gr.add_edge(2,5);
00075 gr.add_edge(3,5);
00076 gr.add_edge(4,5);
00077
00078
00079 typedef fun::i2v::array<point2d> fsite_t;
00080 fsite_t fsite(6);
00081 fsite(0) = point2d(0,0);
00082 fsite(1) = point2d(2,2);
00083 fsite(2) = point2d(4,2);
00084 fsite(3) = point2d(6,2);
00085 fsite(4) = point2d(2,4);
00086 fsite(5) = point2d(2,6);
00087
00088
00089 typedef p_vertices<G,fsite_t> pv_t;
00090 pv_t pv(gr, fsite);
00091 typedef vertex_image<point2d,unsigned> v_ima_t;
00092 v_ima_t v_ima(pv);
00093 data::fill(v_ima, 4);
00094
00095
00096 typedef p_edges<G> pe_t;
00097 pe_t pe(gr);
00098 typedef edge_image<void,bool> e_mask_t;
00099 e_mask_t e_mask(pe);
00100 mln_piter_(e_mask_t) em(e_mask.domain());
00101 for_all(em)
00102 e_mask(em) = em.id()%2;
00103
00104 typedef graph_elt_neighborhood_if<util::graph, pv_t, e_mask_t> nbh_t;
00105 nbh_t nbh = graph::to_neighb(v_ima, e_mask);
00106
00107 value::label_8 nlabels;
00108 typedef mln_ch_value_(v_ima_t,value::label_8) lbl_t;
00109 lbl_t lbl = graph::labeling(v_ima, nbh, nlabels);
00110
00111 unsigned i = 0;
00112 mln_piter_(lbl_t) p(lbl.domain());
00113 for_all(p)
00114 mln_assertion(result[i++] == lbl(p));
00115 }