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 #ifndef MLN_GEOM_SEEDS2TILING_HH
00027 # define MLN_GEOM_SEEDS2TILING_HH
00028 
00032 
00033 # include <map>
00034 
00035 # include <mln/core/concept/neighborhood.hh>
00036 # include <mln/core/site_set/p_queue.hh>
00037 # include <mln/core/routine/duplicate.hh>
00038 # include <mln/accu/stat/mean.hh>
00039 # include <mln/estim/min_max.hh>
00040 # include <mln/algebra/vec.hh>
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   namespace geom
00047   {
00048 
00058     
00059     template <typename I, typename N>
00060     mln_concrete(I) seeds2tiling (const Image<I>& ima_,
00061                                   const Neighborhood<N>& nbh);
00062 
00063 
00064 # ifndef MLN_INCLUDE_ONLY
00065 
00066     namespace impl
00067     {
00068 
00073       
00074       template <typename I, typename N>
00075       inline
00076       mln_concrete(I)
00077       seeds2tiling (const Image<I>& ima_,
00078                     const Neighborhood<N>& nbh_)
00079       {
00080         trace::entering("geom::impl::seed2tiling");
00081 
00082         mln_precondition(exact(ima_).is_valid());
00083         mln_precondition(exact(nbh_).is_valid());
00084 
00085         const I& ima = exact(ima_);
00086         mln_concrete(I) out = duplicate(ima_);
00087         const N& nbh = exact(nbh_);
00088         p_queue<mln_psite(I)> q;
00089 
00090         
00091         {
00092           mln_piter(I) p(ima.domain());
00093           mln_niter(N) n(nbh, p);
00094 
00095           for_all(p) if (ima(p) == 0)
00096             for_all(n) if (ima(n) != 0)
00097               {
00098                 q.push(p);
00099                 break;
00100               }
00101         }
00102 
00103         
00104         {
00105           while (! q.is_empty())
00106             {
00107               mln_psite(I) p = q.front();
00108               q.pop();
00109               if (out(p) != 0) 
00110                 continue;
00111 
00112               mln_niter(N) n(nbh, p);
00113               for_all(n) if (ima.has(n))
00114                 {
00115                   if (out(n) != 0)
00116                     out(p) = out(n);
00117                   else
00118                     q.push(n); 
00119                                
00120                 }
00121             }
00122         }
00123 
00124         trace::exiting("geom::impl::seed2tiling");
00125         return out;
00126       }
00127 
00128     } 
00129 
00130 
00131 
00132     
00133 
00134     template <typename I, typename N>
00135     inline
00136     mln_concrete(I) seeds2tiling(const Image<I>& ima_, const Neighborhood<N>& nbh)
00137     {
00138       trace::entering("geom::seed2tiling");
00139 
00140       mln_precondition(exact(ima_).is_valid());
00141       mln_precondition(exact(nbh).is_valid());
00142 
00143       mln_concrete(I) output = impl::seeds2tiling(ima_, nbh);
00144 
00145       trace::exiting("geom::seed2tiling");
00146       return output;
00147     }
00148 
00149 
00150 # endif // ! MLN_INCLUDE_ONLY
00151 
00152   } 
00153 
00154 } 
00155 
00156 
00157 #endif // ! MLN_GEOM_SEEDS2TILING_HH