00001 // Copyright (C) 2007, 2008, 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 <iostream> 00027 00028 #include <vector> 00029 00030 #include <mln/core/alias/point2d.hh> 00031 #include <mln/core/image/graph_elt_window.hh> 00032 #include <mln/core/site_set/p_vertices.hh> 00033 00034 #include <mln/util/graph.hh> 00035 00036 unsigned fwd_neighb[] = { 0, 2, 3 }; 00037 unsigned bkd_neighb[] = { 3, 2, 0 }; 00038 00039 00040 int main() 00041 { 00042 using namespace mln; 00043 00044 typedef point2d p_t; 00045 00046 /*--------. 00047 | Graph. | 00048 `--------*/ 00049 00050 /* The graph is as follows: 00051 00052 0 1 2 3 4 00053 .----------- 00054 | 00055 0 | 0 2 00056 1 | \ / | 00057 2 | 1 | 00058 3 | \ | 00059 4 | 3-4 00060 00061 */ 00062 00063 // Points associated to vertices. 00064 typedef fun::i2v::array<p_t> F; 00065 F points(5); 00066 points(0) = point2d(0,0); // Point associated to vertex 0. 00067 points(1) = point2d(2,2); // Point associated to vertex 1. 00068 points(2) = point2d(0,4); // Point associated to vertex 2. 00069 points(3) = point2d(4,3); // Point associated to vertex 3. 00070 points(4) = point2d(4,4); // Point associated to vertex 4. 00071 00072 // Edges. 00073 typedef mln::util::graph G; 00074 G g; 00075 00076 // Populate the graph with vertices. 00077 g.add_vertices(points.size()); 00078 00079 // Populate the graph with edges. 00080 g.add_edge(0, 1); 00081 g.add_edge(1, 2); 00082 g.add_edge(1, 3); 00083 g.add_edge(3, 4); 00084 g.add_edge(4, 2); 00085 00086 /*------------------. 00087 | Graph and window. | 00088 `------------------*/ 00089 00090 // Graph psite set. 00091 typedef p_vertices<G, F> pg_t; 00092 pg_t pg(g, points); 00093 00094 // Graph point site. 00095 mln_psite_(pg_t) p(pg, 1); 00096 00097 // ``Sliding'' window of a psite of PG. 00098 typedef graph_elt_window<G, pg_t> win_t; 00099 win_t win; 00100 00101 unsigned i = 0; 00102 mln_fwd_qiter_(win_t) fq(win, p); 00103 for_all(fq) 00104 mln_assertion(fq.element().id() == fwd_neighb[i++]); 00105 00106 i = 0; 00107 mln_bkd_qiter_(win_t) bq(win, p); 00108 for_all(bq) 00109 mln_assertion(bq.element().id() == bkd_neighb[i++]); 00110 }