00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <vector>
00027 #include <utility>
00028
00029 #include <mln/core/image/image2d.hh>
00030 #include <mln/core/alias/point2d.hh>
00031 #include <mln/debug/println.hh>
00032 #include <mln/util/graph.hh>
00033 #include <mln/core/site_set/p_vertices.hh>
00034 #include <mln/core/site_set/p_vertices_psite.hh>
00035 #include <mln/debug/draw_graph.hh>
00036 #include <mln/data/compare.hh>
00037
00038
00040 typedef std::vector< mln::point2d > points_type;
00042 typedef std::vector< std::pair<int,int> > edges_type;
00043
00044 using namespace mln;
00045
00046
00047
00048 void do_test(points_type& points, const edges_type& edges,
00049 unsigned nrows, unsigned ncols, const mln::image2d<int>& ref)
00050 {
00051
00052 typedef util::graph G;
00053 G g;
00054
00055 g.add_vertices(points.size());
00056
00057 for (edges_type::const_iterator i = edges.begin(); i != edges.end(); ++i)
00058 g.add_edge(i->first, i->second);
00059
00060
00061 typedef fun::i2v::array<mln::point2d> F;
00062 F fpoints(points);
00063
00064 mln::p_vertices<G, F> pg(g, fpoints);
00065
00066 image2d<int> ima(nrows, ncols);
00067 data::fill(ima, 0);
00068 debug::draw_graph(ima, pg, 2, 1);
00069 mln_assertion(ima == ref);
00070 }
00071
00072 int
00073 main()
00074 {
00075
00076
00077
00078
00079 {
00080
00081 int vs[3][3] = {
00082 {2, 0, 0},
00083 {0, 1, 0},
00084 {0, 0, 2}
00085 };
00086 image2d<int> ref(make::image(vs));
00087
00088
00089 points_type points;
00090 points.push_back(point2d(0,0));
00091 points.push_back(point2d(2,2));
00092
00093
00094 edges_type edges;
00095 edges.push_back(std::make_pair(0, 1));
00096
00097 do_test(points, edges, 3, 3, ref);
00098 }
00099
00100
00101
00102
00103
00104
00105 {
00106 int vs[5][5] = {
00107 {2, 0, 0, 0, 2},
00108 {0, 1, 0, 1, 1},
00109 {0, 0, 2, 0, 1},
00110 {0, 0, 0, 1, 1},
00111 {0, 0, 0, 2, 2},
00112 };
00113 image2d<int> ref(make::image(vs));
00114
00115
00116 points_type points;
00117 points.push_back(point2d(0,0));
00118 points.push_back(point2d(2,2));
00119 points.push_back(point2d(0,4));
00120 points.push_back(point2d(4,3));
00121 points.push_back(point2d(4,4));
00122
00123
00124 edges_type edges;
00125 edges.push_back(std::make_pair(0, 1));
00126 edges.push_back(std::make_pair(1, 2));
00127 edges.push_back(std::make_pair(1, 3));
00128 edges.push_back(std::make_pair(3, 4));
00129 edges.push_back(std::make_pair(4, 2));
00130
00131 do_test(points, edges, 5, 5, ref);
00132 }
00133 }