oln 10.59: Add distributed sort inverted

Index: olena/ChangeLog from Niels Van Vliet <niels@lrde.epita.fr> * oln/utils/histogram.hh: Add revert sort. * tests/utils/tests/histogram: Add tests. Index: olena/oln/utils/histogram.hh --- olena/oln/utils/histogram.hh Mon, 02 Feb 2004 10:57:28 +0100 van-vl_n (oln/10_histogram. 1.6.1.14.1.1 646) +++ olena/oln/utils/histogram.hh Mon, 02 Feb 2004 14:43:02 +0100 van-vl_n (oln/10_histogram. 1.6.1.14.1.1 646) @@ -394,7 +394,7 @@ const ntg_cumul_type(val) card = ntg_max_val(val) - ntg_min_val(val) + 1; std::vector<oln_point_type(I)* > ptr(card); ptr[0] = &(v[0]); - for (ntg_cumul_type(val) i = 1; i < card; i++) + for (ntg_cumul_type(val) i = 1; i < card; ++i) ptr[i] = ptr[i - 1] + histo[i - 1 + ntg_min_val(val)]; // Now iterate on the image to sort point in the order of their @@ -404,6 +404,31 @@ *(ptr[unsigned(im[p] - ntg_min_val(val))]++) = p; } + template<class I> + void + distrib_sort_inv(const abstract::image<I>& im, + std::vector<oln_point_type(I)> &v) + { + typedef oln_value_type(I) val; + + typedef typename ntg_is_a(val, ntg::non_vectorial)::ensure_type ensure_type; + + precondition(v.size() == im.npoints()); + + utils::histogram<val> histo(im); + + const ntg_cumul_type(val) card = ntg_max_val(val) - ntg_min_val(val) + 1; + std::vector<oln_point_type(I)* > ptr(card); + ptr[card - 1] = &(v[0]); + + for (ntg_signed_cumul_type(val) i = card - 2; i >= 0; --i) + ptr[i] = ptr[i + 1] + histo[i + 1 + ntg_min_val(val)]; + + oln_iter_type(I) p(im); + for_all(p) + *(ptr[unsigned(im[p] - ntg_min_val(val))]++) = p; + } + } // end of namespace utils } // end of namespace oln Index: olena/tests/utils/tests/histogram --- olena/tests/utils/tests/histogram Mon, 02 Feb 2004 10:57:28 +0100 van-vl_n (oln/u/27_histogram. 1.2.1.1 606) +++ olena/tests/utils/tests/histogram Mon, 02 Feb 2004 15:26:50 +0100 van-vl_n (oln/u/27_histogram. 1.2.1.1 606) @@ -63,8 +63,18 @@ res = res && (v1[0] == point1d(0) || v1[0] == point1d(1)) && (v1[1] == point1d(0) || v1[1] == point1d(1)) && - v1[2] == point1d(3) & + v1[2] == point1d(3) && v1[3] == point1d(2); + + std::vector<point1d> v2(is4.npoints()); + + distrib_sort_inv(is4, v2); + + res = res && + v2[0] == point1d(2) && + v2[1] == point1d(3) && + (v2[2] == point1d(0) || v2[2] == point1d(1)) && + (v2[3] == point1d(0) || v2[3] == point1d(1)); return res; }
participants (1)
-
Niels Van Vliet