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

relabelfun.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_MAKE_RELABELFUN_HH
00027 # define MLN_MAKE_RELABELFUN_HH
00028 
00032 
00033 # include <mln/core/concept/function.hh>
00034 # include <mln/fun/i2v/array.hh>
00035 # include <mln/value/label.hh>
00036 
00037 namespace mln
00038 {
00039 
00040   namespace make
00041   {
00042 
00053     template <typename V, typename F>
00054     fun::i2v::array<V>
00055     relabelfun(const Function_v2b<F>& fv2b,
00056                const V&               nlabels,
00057                V&                     new_nlabels);
00058 
00070     template <typename V, typename F>
00071     fun::i2v::array<V>
00072     relabelfun(const Function_v2v<F>& fv2v,
00073                const V&               nlabels,
00074                V&                     new_nlabels);
00075 
00076 
00077 # ifndef MLN_INCLUDE_ONLY
00078 
00079     template <typename V, typename F>
00080     inline
00081     fun::i2v::array<V>
00082     relabelfun(const Function_v2b<F>& fv2b_,
00083                const V&               nlabels,
00084                V&                     new_nlabels)
00085     {
00086       trace::entering("make::relabelfun");
00087 
00088       const F& fv2b = exact(fv2b_);
00089 
00090       unsigned nlabels_i = static_cast<unsigned>(nlabels) + 1;
00091       V tmp_nlabels = literal::zero;
00092       fun::i2v::array<V> fi2v(nlabels_i, literal::zero);
00093       for (V i = 1; i < nlabels_i; ++i)
00094         if (fv2b(i))
00095           fi2v(i) = ++tmp_nlabels;
00096       new_nlabels = tmp_nlabels;
00097       trace::exiting("make::relabelfun");
00098       return fi2v;
00099     }
00100 
00101 
00102     template <typename V, typename F>
00103     inline
00104     fun::i2v::array<V>
00105     relabelfun(const Function_v2v<F>& fv2v_,
00106                const V&               nlabels,
00107                V&                     new_nlabels)
00108     {
00109       trace::entering("make::relabelfun");
00110 
00111       const F& fv2v = exact(fv2v_);
00112 
00113       unsigned nlabels_i = static_cast<unsigned>(nlabels) + 1;
00114       V tmp_nlabels = literal::zero;
00115       fun::i2v::array<V> fi2v(nlabels_i, literal::zero);
00116       for (V i = 1; i < nlabels_i; ++i)
00117         if (fi2v(fv2v(i)) == literal::zero)
00118         {
00119           fi2v(fv2v(i)) = ++tmp_nlabels;
00120           fi2v(i) = tmp_nlabels;
00121         }
00122         else
00123           fi2v(i) = fi2v(fv2v(i));
00124       new_nlabels = tmp_nlabels;
00125       trace::exiting("make::relabelfun");
00126       return fi2v;
00127     }
00128 
00129 # endif // ! MLN_INCLUDE_ONLY
00130 
00131   } // end of namespace mln::make
00132 
00133 } // end of namespace mln
00134 
00135 
00136 #endif // ! MLN_MAKE_RELABELFUN_HH

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