Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
graph_elt_window.cc
1 // Copyright (C) 2007, 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 <iostream>
27 
28 #include <vector>
29 
30 #include <mln/core/alias/point2d.hh>
31 #include <mln/core/image/graph_elt_window.hh>
32 #include <mln/core/site_set/p_vertices.hh>
33 
34 #include <mln/util/graph.hh>
35 
36 unsigned fwd_neighb[] = { 0, 2, 3 };
37 unsigned bkd_neighb[] = { 3, 2, 0 };
38 
39 
40 int main()
41 {
42  using namespace mln;
43 
44  typedef point2d p_t;
45 
46  /*--------.
47  | Graph. |
48  `--------*/
49 
50  /* The graph is as follows:
51 
52  0 1 2 3 4
53  .-----------
54  |
55  0 | 0 2
56  1 | \ / |
57  2 | 1 |
58  3 | \ |
59  4 | 3-4
60 
61  */
62 
63  // Points associated to vertices.
64  typedef fun::i2v::array<p_t> F;
65  F points(5);
66  points(0) = point2d(0,0); // Point associated to vertex 0.
67  points(1) = point2d(2,2); // Point associated to vertex 1.
68  points(2) = point2d(0,4); // Point associated to vertex 2.
69  points(3) = point2d(4,3); // Point associated to vertex 3.
70  points(4) = point2d(4,4); // Point associated to vertex 4.
71 
72  // Edges.
73  typedef mln::util::graph G;
74  G g;
75 
76  // Populate the graph with vertices.
77  g.add_vertices(points.size());
78 
79  // Populate the graph with edges.
80  g.add_edge(0, 1);
81  g.add_edge(1, 2);
82  g.add_edge(1, 3);
83  g.add_edge(3, 4);
84  g.add_edge(4, 2);
85 
86  /*------------------.
87  | Graph and window. |
88  `------------------*/
89 
90  // Graph psite set.
91  typedef p_vertices<G, F> pg_t;
92  pg_t pg(g, points);
93 
94  // Graph point site.
95  mln_psite_(pg_t) p(pg, 1);
96 
97  // ``Sliding'' window of a psite of PG.
98  typedef graph_elt_window<G, pg_t> win_t;
99  win_t win;
100 
101  unsigned i = 0;
102  mln_fwd_qiter_(win_t) fq(win, p);
103  for_all(fq)
104  mln_assertion(fq.element().id() == fwd_neighb[i++]);
105 
106  i = 0;
107  mln_bkd_qiter_(win_t) bq(win, p);
108  for_all(bq)
109  mln_assertion(bq.element().id() == bkd_neighb[i++]);
110 }