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