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

voronoi.hh

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 
00026 #ifndef MLN_MAKE_VORONOI_HH
00027 # define MLN_MAKE_VORONOI_HH
00028 
00032 
00033 # include <vector>
00034 # include <map>
00035 
00036 # include <mln/core/concept/neighborhood.hh>
00037 # include <mln/core/site_set/p_vertices.hh>
00038 # include <mln/accu/stat/mean.hh>
00039 # include <mln/estim/min_max.hh>
00040 # include <mln/util/graph.hh>
00041 
00042 namespace mln
00043 {
00044 
00045   namespace make
00046   {
00047 
00050 
00057     template <typename I, typename N>
00058     p_vertices<util::graph, fun::i2v::array<mln_site(I)> >
00059     voronoi (Image<I>& ima_,
00060              Image<I>& orig_,
00061              const Neighborhood<N>& nbh);
00062 
00063 # ifndef MLN_INCLUDE_ONLY
00064 
00065     template <typename I, typename N>
00066     inline
00067     p_vertices<util::graph, fun::i2v::array<mln_site(I)> >
00068     voronoi (Image<I>& ima_,
00069              Image<I>& orig_,
00070              const Neighborhood<N>& nbh)
00071     {
00072       typedef algebra::vec<2,float> X;
00073       typedef mln_value(I) V;
00074       typedef mln_psite(I) P;
00075 
00076       I& ima = exact(ima_);
00077       I& orig = exact(orig_);
00078       util::graph gr;
00079       V min, max;
00080       estim::min_max (ima, min, max);
00081       unsigned nb = max - min + 1;
00082       fun::i2v::array<P> v(nb);
00083       std::vector< accu::stat::mean< X > > tab_mean (nb);
00084       std::map<std::pair<V, V>, bool> m;
00085 
00087       {
00088         mln_piter(I) p(orig.domain());
00089 
00090         for_all(p)
00091           {
00092             if (orig(p) != 0)
00093               {
00094                 X x = mln_psite(I)(p);
00095                 tab_mean[orig(p) - min].take(x);
00096               }
00097           }
00098       }
00099 
00101       {
00102         mln_piter(I) p(ima.domain());
00103         mln_niter(N) n(nbh, p);
00104 
00105         for_all(p)
00106           {
00107             for_all (n) if (ima.has(n))
00108               if (ima(p) != ima(n))
00109                 m[std::pair<V, V>(ima(p) - min, ima(n) - min)] = true;
00110           }
00111       }
00112 
00114       for (unsigned i = 0; i < nb; ++i)
00115         {
00116           gr.add_vertex();
00117 
00119           v[i] = point2d ((unsigned)tab_mean[i].to_result ()[0],
00120                                 (unsigned)tab_mean[i].to_result ()[1]);
00121         }
00122 
00123       typename std::map<std::pair<V, V>, bool>::const_iterator it = m.begin ();
00124       for (; it != m.end (); ++it)
00125         gr.add_edge((*it).first.first, (*it).first.second);
00126 
00127       p_vertices<util::graph, fun::i2v::array<P> > res(gr, v);
00128       return res;
00129     }
00130 
00131 # endif // ! MLN_INCLUDE_ONLY
00132 
00133   } // end of namespace mln::make
00134 
00135 } // end of namespace mln
00136 
00137 
00138 #endif // ! MLN_MAKE_VORONOI_HH

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