Milena (Olena)
User documentation 2.0a Id
|
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_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 // Init. 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 // Body. 00104 { 00105 while (! q.is_empty()) 00106 { 00107 mln_psite(I) p = q.front(); 00108 q.pop(); 00109 if (out(p) != 0) // p has already been processed so ignore 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); // n may already be in the queue, 00119 // yet we then queue again this psite 00120 } 00121 } 00122 } 00123 00124 trace::exiting("geom::impl::seed2tiling"); 00125 return out; 00126 } 00127 00128 } // end of namespace mln::geom::impl 00129 00130 00131 00132 // Facade 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 } // end of namespace mln::geom 00153 00154 } // end of namespace mln 00155 00156 00157 #endif // ! MLN_GEOM_SEEDS2TILING_HH