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