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

relabelfun.hh

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

Generated on Tue Oct 4 2011 15:24:21 for Milena (Olena) by  doxygen 1.7.1