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