Milena (Olena)
User documentation 2.0a Id
|
00001 #include <mln/core/site_set/p_vertices.hh> 00002 #include <mln/core/alias/point2d.hh> 00003 #include <mln/core/concept/function.hh> 00004 #include <mln/core/var.hh> 00005 00006 #include <mln/fun/i2v/array.hh> 00007 #include <mln/util/graph.hh> 00008 #include <mln/pw/all.hh> 00009 00010 #include <vector> 00011 00012 00013 // \{ 00014 template <typename S> 00015 struct viota_t : public mln::Function_v2v< viota_t<S> > 00016 { 00017 typedef unsigned result; 00018 00019 viota_t(unsigned size) 00020 { 00021 v_.resize(size); 00022 for(unsigned i = 0; i < size; ++i) 00023 v_[i] = 10 + i; 00024 } 00025 00026 unsigned 00027 operator()(const mln_psite(S)& p) const 00028 { 00029 return v_[p.v().id()]; 00030 } 00031 00032 protected: 00033 std::vector<result> v_; 00034 }; 00035 // \} 00036 00037 int main() 00038 { 00039 using namespace mln; 00040 00041 // \{ 00042 util::graph g; 00043 00044 for (unsigned i = 0; i < 5; ++i) 00045 g.add_vertex(); // Add vertex 'i'; 00046 // \} 00047 00048 // \{ 00049 g.add_edge(0, 1); // Associated to edge 0. 00050 g.add_edge(1, 2); // Associated to edge 1. 00051 g.add_edge(1, 3); // Associated to edge 2. 00052 g.add_edge(3, 4); // Associated to edge 3. 00053 g.add_edge(4, 2); // Associated to edge 4. 00054 // \} 00055 00056 // \{ 00057 typedef fun::i2v::array<point2d> F; 00058 F f(5); // We need to map 5 vertices. 00059 f(0) = point2d(0, 0); 00060 f(1) = point2d(2, 2); 00061 f(2) = point2d(0, 4); 00062 f(3) = point2d(4, 3); 00063 f(4) = point2d(4, 4); 00064 // \} 00065 00066 // \{ 00067 typedef p_vertices<util::graph, F> pv_t; 00068 pv_t pv(g, f); 00069 // \} 00070 00071 // \{ 00072 00073 // Constructs an image 00074 viota_t<pv_t> viota(pv.nsites()); 00075 mln_VAR(graph_vertices_ima, viota | pv); 00076 00077 //Prints each vertex and its associated data. 00078 mln_piter_(graph_vertices_ima_t) p(graph_vertices_ima.domain()); 00079 for_all(p) 00080 std::cout << "graph_vertices_ima(" << p << ") = " 00081 << graph_vertices_ima(p) << std::endl; 00082 00083 // \} 00084 } 00085