Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 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 | Graph. | 00056 `--------*/ 00057 00058 /* The graph is as follows: 00059 00060 _____ 00061 / \ 00062 0 1 2 - 3 00063 \ / \ / 00064 4 - 5 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 // Create a vertex image. 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 // Create a mask on edges. 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 }