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_LABELING_PACK_HH
00027 # define MLN_LABELING_PACK_HH
00028
00033
00034 # include <mln/core/concept/image.hh>
00035
00036 # include <mln/make/relabelfun.hh>
00037
00038 # include <mln/data/compute.hh>
00039 # include <mln/data/transform.hh>
00040
00041 # include <mln/accu/label_used.hh>
00042
00043
00044
00045 namespace mln
00046 {
00047
00048 namespace labeling
00049 {
00050
00058
00059 template <typename I>
00060 mln_concrete(I)
00061 pack(const Image<I>& label, mln_value(I)& new_nlabels,
00062 fun::i2v::array<mln_value(I)>& repack_fun);
00063
00064
00066 template <typename I>
00067 mln_concrete(I)
00068 pack(const Image<I>& label, mln_value(I)& new_nlabels);
00069
00070
00071
00078
00079 template <typename I>
00080 void
00081 pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
00082 fun::i2v::array<mln_value(I)>& repack_fun);
00083
00084
00086 template <typename I>
00087 void
00088 pack_inplace(Image<I>& label, mln_value(I)& new_nlabels);
00089
00090
00091
00092 # ifndef MLN_INCLUDE_ONLY
00093
00094
00095 namespace internal
00096 {
00097
00098 template <typename I>
00099 void
00100 pack_tests(const Image<I>& label, mln_value(I)& new_nlabels)
00101 {
00102
00103 mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
00104 mln_precondition(exact(label).is_valid());
00105 (void) label;
00106 (void) new_nlabels;
00107 }
00108
00109 }
00110
00111
00112
00113 template <typename I>
00114 mln_concrete(I)
00115 pack(const Image<I>& label, mln_value(I)& new_nlabels)
00116 {
00117 fun::i2v::array<mln_value(I)> repack_fun;
00118 return pack(label, new_nlabels, repack_fun);
00119 }
00120
00121
00122 template <typename I>
00123 mln_concrete(I)
00124 pack(const Image<I>& label, mln_value(I)& new_nlabels,
00125 fun::i2v::array<mln_value(I)>& repack_fun)
00126 {
00127 trace::entering("labeling::pack");
00128
00129 internal::pack_tests(label, new_nlabels);
00130
00131 fun::i2v::array<bool>
00132 fv2b = data::compute(accu::meta::label_used(), label);
00133
00134 mln_value(I) tmp_nlabels = fv2b.size() - 1;
00135
00136 repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
00137
00138 mln_concrete(I)
00139 output = data::transform(label, repack_fun);
00140
00141 trace::exiting("labeling::pack");
00142 return output;
00143 }
00144
00145
00146 template <typename I>
00147 void
00148 pack_inplace(Image<I>& label, mln_value(I)& new_nlabels)
00149 {
00150 fun::i2v::array<mln_value(I)> repack_fun;
00151 pack_inplace(label, new_nlabels, repack_fun);
00152 }
00153
00154
00155 template <typename I>
00156 void
00157 pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
00158 fun::i2v::array<mln_value(I)>& repack_fun)
00159 {
00160 trace::entering("labeling::pack_inplace");
00161
00162 internal::pack_tests(label, new_nlabels);
00163
00164 fun::i2v::array<bool>
00165 fv2b = data::compute(accu::meta::label_used(), label);
00166
00167 mln_value(I) tmp_nlabels = fv2b.size() - 1;
00168 repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
00169
00170 exact(label) = data::transform(label, repack_fun);
00171
00172 trace::exiting("labeling::pack_inplace");
00173 }
00174
00175
00176 # endif // ! MLN_INCLUDE_ONLY
00177
00178 }
00179
00180 }
00181
00182
00183 #endif // ! MLN_LABELING_PACK_HH