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

relabel.hh

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

Generated on Thu Sep 8 2011 18:32:23 for Milena (Olena) by  doxygen 1.7.1