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
00029
00030 #include <mln/core/alias/point2d.hh>
00031
00033 #include <mln/core/image/vertex_image.hh>
00034 #include <mln/fun/i2v/array.hh>
00035 #include <mln/util/line_graph.hh>
00036 #include <mln/util/graph.hh>
00037 #include <mln/util/site_pair.hh>
00038 #include <mln/make/vertex_image.hh>
00039
00040 #include <mln/morpho/erosion.hh>
00041 #include <mln/morpho/dilation.hh>
00042
00043 static const unsigned dil_ref[] = { 12, 14, 13, 14, 13 };
00044 static const unsigned ero_ref[] = { 11, 10, 10, 12, 11 };
00045
00046 int main()
00047 {
00048 using namespace mln;
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 util::graph g;
00069
00070
00071 g.add_vertices(5);
00072
00073
00074 g.add_edge(0, 1);
00075 g.add_edge(1, 2);
00076 g.add_edge(1, 3);
00077 g.add_edge(3, 4);
00078 g.add_edge(4, 2);
00079
00082 util::line_graph<util::graph> lg(g);
00083
00084
00085 typedef util::site_pair<point2d> P;
00086 typedef fun::i2v::array<P> fsite_t;
00087 fsite_t sites(5);
00088 sites(0) = P(point2d(0,0), point2d(2,2));
00089 sites(1) = P(point2d(2,2), point2d(0,4));
00090 sites(2) = P(point2d(2,2), point2d(4,3));
00091 sites(3) = P(point2d(4,3), point2d(4,4));
00092 sites(4) = P(point2d(0,4), point2d(4,4));
00093
00094
00095
00096
00097
00098
00099 typedef fun::i2v::array<unsigned> viota_t;
00100 viota_t iota(lg.v_nmax());
00101 for (unsigned i = 0; i < iota.size(); ++i)
00102 iota(i) = 10 + i;
00103
00104 typedef vertex_image< P, unsigned, util::line_graph<util::graph> > ima_t;
00105 ima_t ima = make::vertex_image(lg, sites, iota);
00106
00107
00108
00109
00110
00111
00112 ima_t::win_t win;
00113 unsigned i = 0;
00114
00115 ima_t ima_dil = morpho::dilation(ima, win);
00116
00117 mln_piter_(ima_t) p_dil(ima_dil.domain());
00118 for_all (p_dil)
00119 mln_assertion(dil_ref[i++] == ima_dil(p_dil));
00120
00121 ima_t ima_ero = morpho::erosion(ima, win);
00122
00123 mln_piter_(ima_t) p_ero(ima_ero.domain());
00124 i = 0;
00125 for_all (p_ero)
00126 mln_assertion(ero_ref[i++] == ima_ero(p_ero));
00127 }