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_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 | Graph. | 00049 `--------*/ 00050 00051 /* The graph is as follows: 00052 00053 _____ 00054 / \ 00055 0 1 2 - 3 00056 \ / \ / 00057 4 - 5 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 // Create a vertex image. 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 // Create a mask on vertices. 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 // Create an edge image. 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 // Create a mask on edges. 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 // Iterate on edges neighborhood according to the given mask. 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 // Create an edge image. 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 // Create a mask on vertices. 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 // Create a vertex image. 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 // Create a mask on edges. 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 }