Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
point_set_compatibility.cc
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #include <mln/core/alias/point2d.hh>
27 
28 #include <mln/core/site_set/p_array.hh>
29 #include <mln/core/site_set/p_set.hh>
30 #include <mln/core/site_set/p_vertices.hh>
31 #include <mln/util/graph.hh>
32 
33 
34 int main()
35 {
36  using namespace mln;
37 
38  /*--------------------------------------------------------.
39  | Compatibility of mln::graph_psite with mln::p_array and |
40  | mln::p_array_piter. |
41  `--------------------------------------------------------*/
42 
43  // Graph
44 
45  //Vertices
46  typedef fun::i2v::array<point2d> fpoint_t;
47  fpoint_t points(5);
48  points(0) = point2d(0,0); // Point associated to vertex 0.
49  points(1) = point2d(2,2); // Point associated to vertex 1.
50  points(2) = point2d(0,4); // Point associated to vertex 2.
51  points(3) = point2d(4,3); // Point associated to vertex 3.
52  points(4) = point2d(4,4); // Point associated to vertex 4.
53 
54  // Edges.
55  util::graph g;
56  // Populate the graph with vertices.
57  for (unsigned i = 0; i < points.size(); ++i)
58  g.add_vertex();
59  // Populate the graph with edges.
60  g.add_edge(0, 1);
61  g.add_edge(1, 2);
62  g.add_edge(1, 3);
63  g.add_edge(3, 4);
64  g.add_edge(4, 2);
65 
66 
67 
68  // Graph point set.
70  typedef mln_psite_(pv_t) gpsite_t;
71  pv_t pv(g, points);
72 
73  {
74  // Array of graph point sites.
75  typedef p_array<gpsite_t> pa_t;
76  pa_t pa;
77 
78  // Tests: copying all psites from PG to PA.
79  mln_piter_(pv_t) p(pv);
80  for_all (p)
81  pa.append(p);
82 
83  // Test: create and use an iterator over PA.
84  mln_piter_(pa_t) p2(pa);
85  for_all (p2)
86  std::cout << p2 << ' ';
87  std::cout << std::endl;
88  }
89 
90  {
91  // Set of graph point sites.
92  typedef p_set<gpsite_t> ps_t;
93  ps_t ps;
94 
95  // Tests: copying all psites from PG to PS.
96  mln_piter_(pv_t) p(pv);
97  for_all (p)
98  ps.insert(p);
99 
100  // Test: create and use an iterator over PS.
101  mln_piter_(ps_t) p2(ps);
102  for_all (p2)
103  std::cout << p2 << ' ';
104  std::cout << std::endl;
105  }
106 }