Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009, 2010 EPITA Research and Development 00002 // Laboratory (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_RELABEL_HH 00028 # define MLN_LABELING_RELABEL_HH 00029 00033 00034 00035 # include <mln/core/concept/image.hh> 00036 00037 # include <mln/make/relabelfun.hh> 00038 00039 # include <mln/data/transform.hh> 00040 # include <mln/data/transform_inplace.hh> 00041 00042 00043 00044 namespace mln 00045 { 00046 00047 namespace labeling 00048 { 00049 00058 // 00059 template <typename I, typename F> 00060 mln_concrete(I) 00061 relabel(const Image<I>& label, 00062 const mln_value(I)& nlabels, 00063 mln_value(I)& new_nlabels, 00064 const Function_v2b<F>& fv2b); 00065 00066 00074 // 00075 template <typename I, typename F> 00076 mln_concrete(I) 00077 relabel(const Image<I>& label, 00078 const mln_value(I)& nlabels, 00079 const Function_v2v<F>& fv2v); 00080 00081 00087 // 00088 template <typename I, typename F> 00089 void 00090 relabel_inplace(Image<I>& label, 00091 const mln_value(I)& nlabels, 00092 const Function_v2b<F>& fv2b); 00093 00094 00100 // 00101 template <typename I, typename F> 00102 void 00103 relabel_inplace(Image<I>& label, 00104 const mln_value(I)& nlabels, 00105 const Function_v2v<F>& fv2v); 00106 00107 00108 # ifndef MLN_INCLUDE_ONLY 00109 00110 00111 00112 namespace internal 00113 { 00114 00115 template <typename I> 00116 void 00117 relabel_tests(const Image<I>& label, 00118 mln_value(I)& new_nlabels) 00119 { 00120 // FIXME: we may want to check that it is exactly a label. 00121 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check(); 00122 mln_precondition(exact(label).is_valid()); 00123 (void) label; 00124 (void) new_nlabels; 00125 } 00126 00127 template <typename I, typename F> 00128 void 00129 relabel_tests(const Image<I>& label, 00130 const mln_value(I)& nlabels, 00131 mln_value(I)& new_nlabels, 00132 const Function<F>& f) 00133 { 00134 // FIXME: we may want to check that it is exactly a label. 00135 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check(); 00136 mln_precondition(exact(label).is_valid()); 00137 (void) label; 00138 (void) nlabels; 00139 (void) new_nlabels; 00140 (void) f; 00141 } 00142 00143 template <typename I, typename F> 00144 void 00145 relabel_tests(const Image<I>& label, 00146 const mln_value(I)& nlabels, 00147 const Function<F>& f) 00148 { 00149 // FIXME: we may want to check that it is exactly a label. 00150 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check(); 00151 mln_precondition(exact(label).is_valid()); 00152 (void) label; 00153 (void) nlabels; 00154 (void) f; 00155 } 00156 00157 template <typename I, typename F> 00158 inline 00159 void 00160 relabel_inplace_tests(Image<I>& label, 00161 const mln_value(I)& nlabels, 00162 const Function<F>& f) 00163 { 00164 // FIXME: we may want to check that it is exactly a label. 00165 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check(); 00166 mln_precondition(exact(label).is_valid()); 00167 (void) label; 00168 (void) nlabels; 00169 (void) f; 00170 } 00171 00172 } // end of namespace mln::labeling::internal 00173 00174 00175 00176 template <typename I, typename F> 00177 inline 00178 mln_concrete(I) 00179 relabel(const Image<I>& label, 00180 const mln_value(I)& nlabels, 00181 const Function_v2v<F>& fv2v) 00182 { 00183 trace::entering("labeling::relabel"); 00184 00185 00186 mlc_not_equal(mln_result(F),bool)::check(); 00187 internal::relabel_tests(label, nlabels, fv2v); 00188 00189 mln_concrete(I) output = data::transform(label, fv2v); 00190 00191 trace::exiting("labeling::relabel"); 00192 return output; 00193 } 00194 00195 00196 00197 template <typename I, typename F> 00198 inline 00199 mln_concrete(I) 00200 relabel(const Image<I>& label, 00201 const mln_value(I)& nlabels, 00202 mln_value(I)& new_nlabels, 00203 const Function_v2b<F>& fv2b) 00204 { 00205 trace::entering("labeling::relabel"); 00206 00207 internal::relabel_tests(label, nlabels, new_nlabels, fv2b); 00208 00209 typedef fun::i2v::array<mln_value(I)> fv2v_t; 00210 fv2v_t fv2v = make::relabelfun(fv2b, nlabels, new_nlabels); 00211 mln_concrete(I) output = labeling::relabel(label, new_nlabels, fv2v); 00212 00213 trace::exiting("labeling::relabel"); 00214 return output; 00215 } 00216 00217 00218 template <typename I, typename F> 00219 inline 00220 void 00221 relabel_inplace(Image<I>& label, 00222 const mln_value(I)& nlabels, 00223 const Function_v2v<F>& fv2v) 00224 { 00225 trace::entering("labeling::relabel_inplace"); 00226 00227 mlc_not_equal(mln_result(F),bool)::check(); 00228 internal::relabel_inplace_tests(label, nlabels, fv2v); 00229 00230 data::transform_inplace(label, fv2v); 00231 00232 trace::exiting("labeling::relabel_inplace"); 00233 } 00234 00235 00236 00237 template <typename I, typename F> 00238 inline 00239 void 00240 relabel_inplace(Image<I>& label, 00241 const mln_value(I)& nlabels, 00242 const Function_v2b<F>& fv2b) 00243 { 00244 trace::entering("labeling::relabel_inplace"); 00245 00246 internal::relabel_inplace_tests(label, nlabels, fv2b); 00247 00248 typedef fun::i2v::array<mln_value(I)> fv2v_t; 00249 mln_value(I) tmp; 00250 fv2v_t fv2v = make::relabelfun(fv2b, nlabels, tmp); 00251 labeling::relabel_inplace(label, tmp, fv2v); 00252 00253 trace::exiting("labeling::relabel_inplace"); 00254 } 00255 00256 # endif // ! MLN_INCLUDE_ONLY 00257 00258 } // end of namespace mln::labeling 00259 00260 } // end of namespace mln 00261 00262 00263 #endif // ! MLN_LABELING_RELABEL_HH