00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development 00002 // Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #include <iostream> 00028 00029 #include <vector> 00030 00031 #include <mln/core/alias/point2d.hh> 00032 #include <mln/core/site_set/p_vertices.hh> 00033 00034 #include <mln/util/graph.hh> 00035 #include <mln/core/image/graph_elt_neighborhood.hh> 00036 00037 00038 unsigned fwd_neighb[] = { 0, 2, 3 }; 00039 unsigned bkd_neighb[] = { 3, 2, 0 }; 00040 00041 int main() 00042 { 00043 using namespace mln; 00044 00045 typedef point2d p_t; 00046 00047 /*--------. 00048 | Graph. | 00049 `--------*/ 00050 00051 /* The graph is as follows: 00052 00053 0 1 2 3 4 00054 .----------- 00055 | 00056 0 | 0 2 00057 1 | \ / | 00058 2 | 1 | 00059 3 | \ | 00060 4 | 3-4 00061 00062 */ 00063 00064 // Points associated to vertices. 00065 typedef fun::i2v::array<p_t> F; 00066 F points(5); 00067 points(0) = point2d(0,0); // Point associated to vertex 0. 00068 points(1) = point2d(2,2); // Point associated to vertex 1. 00069 points(2) = point2d(0,4); // Point associated to vertex 2. 00070 points(3) = point2d(4,3); // Point associated to vertex 3. 00071 points(4) = point2d(4,4); // Point associated to vertex 4. 00072 00073 // Edges. 00074 typedef mln::util::graph G; 00075 G g; 00076 00077 // Populate the graph with vertices. 00078 g.add_vertices(points.size()); 00079 00080 // Populate the graph with edges. 00081 g.add_edge(0, 1); 00082 g.add_edge(1, 2); 00083 g.add_edge(1, 3); 00084 g.add_edge(3, 4); 00085 g.add_edge(4, 2); 00086 00087 /*-------------------------. 00088 | Graph and neighborhood. | 00089 `-------------------------*/ 00090 00091 // Graph psite set. 00092 typedef p_vertices<G, F> pv_t; 00093 pv_t pg(g, points); 00094 00095 // Graph point site. 00096 mln_psite_(pv_t) p(pg, 1); 00097 00098 // ``Sliding'' neighborhood of a psite of PG. 00099 typedef graph_elt_neighborhood<G, pv_t> nbh_t; 00100 nbh_t nbh; 00101 00102 unsigned i = 0; 00103 mln_fwd_niter_(nbh_t) fq(nbh, p); 00104 for_all(fq) 00105 mln_assertion(fq.element().id() == fwd_neighb[i++]); 00106 00107 i = 0; 00108 mln_bkd_niter_(nbh_t) bq(nbh, p); 00109 for_all(bq) 00110 mln_assertion(bq.element().id() == bkd_neighb[i++]); 00111 }