Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory 00002 // (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #ifndef MLN_LABELING_BLOBS_AND_COMPUTE_HH 00028 # define MLN_LABELING_BLOBS_AND_COMPUTE_HH 00029 00033 00034 00035 # include <mln/core/concept/image.hh> 00036 # include <mln/core/concept/neighborhood.hh> 00037 00038 # include <mln/labeling/blobs.hh> 00039 # include <mln/labeling/compute.hh> 00040 00041 00042 namespace mln 00043 { 00044 00045 namespace labeling 00046 { 00047 00059 template <typename I, typename N, typename L, typename A> 00060 util::couple<mln_ch_value(I,L), 00061 util::couple<util::array<mln_result(A)>, 00062 util::array<A> > > 00063 blobs_and_compute(const Image<I>& input, const Neighborhood<N>& nbh, 00064 L& nlabels, const Accumulator<A>& accu); 00065 00066 00067 00068 # ifndef MLN_INCLUDE_ONLY 00069 00070 00071 namespace internal 00072 { 00073 00076 template <typename L, typename A> 00077 struct compute_functor 00078 { 00079 typedef mln_result(A) accu_result; 00080 typedef mln_argument(A) accu_argument; 00081 typedef util::couple<util::array<accu_result>, 00082 util::array<A> > result; 00083 00084 compute_functor(const mln_value(L)& nlabels) 00085 : nlabels_(nlabels) 00086 { 00087 } 00088 00089 inline 00090 void init() 00091 { 00092 accus_.reserve(1000); 00093 accus_.append(A()); 00094 } 00095 00096 inline 00097 void new_label(const mln_value(L)& l) 00098 { 00099 current_lbl_ = l; 00100 accus_.append(A()); 00101 } 00102 00103 inline 00104 void process_p(const mln_site(L)& p) 00105 { 00106 process__(accu_argument(), p); 00107 } 00108 00109 inline 00110 void process_n(const mln_site(L)& n) 00111 { 00112 process__(accu_argument(), n); 00113 } 00114 00115 inline 00116 void finalize() 00117 { 00118 convert::from_to(accus_, result_); 00119 } 00120 00121 00122 private: 00123 inline 00124 void process__(const mln_psite(L)&, const mln_site(L)& p) 00125 { 00126 accus_[current_lbl_].take(p); 00127 } 00128 00129 inline 00130 void process__(const mln_value(L)&, const mln_site(L)&) 00131 { 00132 accus_[current_lbl_].take(current_lbl_); 00133 } 00134 00135 template <typename V> 00136 inline 00137 void process__(const V&, const mln_site(L)&) 00138 { 00139 mlc_abort(V)::check(); 00140 } 00141 00142 public: 00143 util::array<mln_result(A)> result_; 00144 util::array<A> accus_; 00145 mln_value(L) current_lbl_; 00146 mln_value(L) nlabels_; 00147 }; 00148 00149 } // end of namespace mln::labeling::internal 00150 00151 00152 00153 // Facade. 00154 00155 00156 template <typename I, typename N, typename L, typename A> 00157 util::couple<mln_ch_value(I,L), 00158 util::couple<util::array<mln_result(A)>, 00159 util::array<A> > > 00160 blobs_and_compute(const Image<I>& input, const Neighborhood<N>& nbh, 00161 L& nlabels, const Accumulator<A>& accu) 00162 { 00163 trace::entering("labeling::blobs_and_compute"); 00164 00165 (void) accu; 00166 mlc_equal(mln_trait_image_kind(I), 00167 mln::trait::image::kind::binary)::check(); 00168 mln_precondition(exact(input).is_valid()); 00169 00170 typedef mln_ch_value(I,L) out_t; 00171 typedef internal::compute_functor<out_t,A> func_t; 00172 func_t functor(nlabels); 00173 out_t 00174 output = canvas::labeling::blobs(input, nbh, nlabels, functor); 00175 00176 util::couple<out_t, typename func_t::result> 00177 result = make::couple(output, 00178 make::couple(functor.result_, functor.accus_)); 00179 00180 trace::exiting("labeling::blobs_and_compute"); 00181 return result; 00182 } 00183 00184 00185 # endif // ! MLN_INCLUDE_ONLY 00186 00187 00188 } // end of namespace mln::labeling 00189 00190 } // end of namespace mln 00191 00192 00193 #endif // ! MLN_LABELING_BLOBS_AND_COMPUTE_HH