00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00115 util::array<V> new_labels(nlabels_i, mln_max(V));
00116 new_labels(0) = literal::zero;
00117 V tmp_nlabels = literal::zero;
00118 fun::i2v::array<V> fi2v(nlabels_i, mln_max(V));
00119 fi2v(0) = literal::zero;
00120
00121 for (V i = 1; i < nlabels_i; ++i)
00122 {
00123 mln_assertion(fv2v(i) <= nlabels);
00124 if (new_labels(fv2v(i)) == mln_max(V))
00125 {
00126 new_labels(fv2v(i)) = ++tmp_nlabels;
00127 fi2v(i) = tmp_nlabels;
00128 }
00129 else
00130 fi2v(i) = new_labels(fv2v(i));
00131 }
00132 new_nlabels = tmp_nlabels;
00133 trace::exiting("make::relabelfun");
00134 return fi2v;
00135 }
00136
00137 # endif // ! MLN_INCLUDE_ONLY
00138
00139 }
00140
00141 }
00142
00143
00144 #endif // ! MLN_MAKE_RELABELFUN_HH