00001 // Copyright (C) 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 <mln/core/alias/point2d.hh> 00027 00028 #include <mln/core/site_set/p_array.hh> 00029 #include <mln/core/site_set/p_set.hh> 00030 #include <mln/core/site_set/p_vertices.hh> 00031 #include <mln/util/graph.hh> 00032 00033 00034 int main() 00035 { 00036 using namespace mln; 00037 00038 /*--------------------------------------------------------. 00039 | Compatibility of mln::graph_psite with mln::p_array and | 00040 | mln::p_array_piter. | 00041 `--------------------------------------------------------*/ 00042 00043 // Graph 00044 00045 //Vertices 00046 typedef fun::i2v::array<point2d> fpoint_t; 00047 fpoint_t points(5); 00048 points(0) = point2d(0,0); // Point associated to vertex 0. 00049 points(1) = point2d(2,2); // Point associated to vertex 1. 00050 points(2) = point2d(0,4); // Point associated to vertex 2. 00051 points(3) = point2d(4,3); // Point associated to vertex 3. 00052 points(4) = point2d(4,4); // Point associated to vertex 4. 00053 00054 // Edges. 00055 util::graph g; 00056 // Populate the graph with vertices. 00057 for (unsigned i = 0; i < points.size(); ++i) 00058 g.add_vertex(); 00059 // Populate the graph with edges. 00060 g.add_edge(0, 1); 00061 g.add_edge(1, 2); 00062 g.add_edge(1, 3); 00063 g.add_edge(3, 4); 00064 g.add_edge(4, 2); 00065 00066 00067 00068 // Graph point set. 00069 typedef p_vertices<util::graph, fpoint_t> pv_t; 00070 typedef mln_psite_(pv_t) gpsite_t; 00071 pv_t pv(g, points); 00072 00073 { 00074 // Array of graph point sites. 00075 typedef p_array<gpsite_t> pa_t; 00076 pa_t pa; 00077 00078 // Tests: copying all psites from PG to PA. 00079 mln_piter_(pv_t) p(pv); 00080 for_all (p) 00081 pa.append(p); 00082 00083 // Test: create and use an iterator over PA. 00084 mln_piter_(pa_t) p2(pa); 00085 for_all (p2) 00086 std::cout << p2 << ' '; 00087 std::cout << std::endl; 00088 } 00089 00090 { 00091 // Set of graph point sites. 00092 typedef p_set<gpsite_t> ps_t; 00093 ps_t ps; 00094 00095 // Tests: copying all psites from PG to PS. 00096 mln_piter_(pv_t) p(pv); 00097 for_all (p) 00098 ps.insert(p); 00099 00100 // Test: create and use an iterator over PS. 00101 mln_piter_(ps_t) p2(ps); 00102 for_all (p2) 00103 std::cout << p2 << ' '; 00104 std::cout << std::endl; 00105 } 00106 }