• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

line_graph_image_morpho.cc

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
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   | Graph.  |
00052   `--------*/
00053 
00054   /* The graph and its corresponding line graph are as follows:
00055 
00056             0 1 2 3 4               0 1 2 3 4
00057          .-----------            .-----------
00058          |                       |
00059        0 |  0       2          0 |  *       *
00060        1 |    \   / |          1 |    0   1 |
00061        2 |      1   |          2 |      *   4
00062        3 |       \  |          3 |       2  |
00063        4 |        3-4          4 |        *3*
00064 
00065   */
00066 
00067   // Graph.
00068   util::graph g;
00069 
00070   // Populate the graph with vertices.
00071   g.add_vertices(5);
00072 
00073   // Populate the graph with edges.
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 
00080   // Create the corresponding line graph.
00081   // Edges are now considered as vertices.
00082   util::line_graph<util::graph> lg(g);
00083 
00084   // Points associated to the line graph vertices (edges in the graph).
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)); // Site associated to vertex 0.
00089   sites(1) = P(point2d(2,2), point2d(0,4)); // Site associated to vertex 1.
00090   sites(2) = P(point2d(2,2), point2d(4,3)); // Site associated to vertex 2.
00091   sites(3) = P(point2d(4,3), point2d(4,4)); // Site associated to vertex 3.
00092   sites(4) = P(point2d(0,4), point2d(4,4)); // Site associated to vertex 4.
00093 
00094   /*-------------------.
00095   | Line graph image.  |
00096   `-------------------*/
00097 
00098   // Line graph values.
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   | Processing line graph images.  |
00110   `-------------------------------*/
00111 
00112   ima_t::win_t win;
00113   unsigned i = 0;
00114 
00115   ima_t ima_dil = morpho::dilation(ima, win);
00116   // Manual iteration over the domain of IMA_DIL.
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   // Manual iteration over the domain of IMA_ERO.
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 }

Generated on Tue Oct 4 2011 15:24:02 for Milena (Olena) by  doxygen 1.7.1