26 #ifndef MLN_DATA_SORT_PSITES_HH
27 # define MLN_DATA_SORT_PSITES_HH
37 # include <mln/core/concept/image.hh>
38 # include <mln/convert/to_p_array.hh>
39 # include <mln/histo/compute.hh>
40 # include <mln/util/ord.hh>
41 # include <mln/geom/nsites.hh>
71 # ifndef MLN_INCLUDE_ONLY
79 struct value_psite_less_
84 value_psite_less_(
const I& ima)
90 bool operator()(
const mln_psite(I)& lhs,
91 const mln_psite(I)&
rhs)
const
94 || (ima_(lhs) == ima_(rhs)
100 template <
typename I>
101 struct value_psite_greater_
106 value_psite_greater_(
const I& ima)
112 bool operator()(
const mln_psite(I)& lhs,
113 const mln_psite(I)& rhs)
const
116 || (ima_(lhs) == ima_(rhs)
125 template <
typename I>
127 p_array<mln_psite(I)>
128 sort_psites_increasing_(trait::image::quant::any,
132 std::sort(v.hook_std_vector_().begin(), v.hook_std_vector_().end(),
133 value_psite_less_<I>(input));
137 template <
typename I>
139 p_array<mln_psite(I)>
140 sort_psites_increasing_(trait::image::quant::low,
143 typedef mln_vset(I) S;
144 const S& vset = input.values_eligible();
145 const
unsigned n = vset.nvalues();
151 std::vector<
unsigned> loc(vset.nvalues());
153 for (
unsigned i = 1; i != n; ++i)
154 loc[i] = loc[i-1] + h[i-1];
157 std::vector<mln_psite(I)> vec(geom::
nsites(input));
158 mln_fwd_piter(I)
p(input.domain());
160 vec[loc[vset.index_of(input(
p))]++] =
p;
162 p_array<mln_psite(I)> v(vec);
169 template <typename I>
171 p_array<mln_psite(I)>
172 sort_psites_decreasing_(trait::image::quant::any,
176 std::sort(v.hook_std_vector_().begin(), v.hook_std_vector_().end(),
177 value_psite_greater_<I>(input));
181 template <
typename I>
183 p_array<mln_psite(I)>
184 sort_psites_decreasing_(trait::image::quant::low,
187 typedef mln_vset(I) S;
188 const S& vset = input.values_eligible();
189 const
unsigned n = vset.nvalues();
195 std::vector<
unsigned> loc(vset.nvalues());
197 for (
int i = n - 2; i >= 0; --i)
198 loc[i] = loc[i+1] + h[i+1];
201 std::vector<mln_psite(I)> vec(geom::
nsites(input));
202 mln_fwd_piter(I) p(input.domain());
204 vec[loc[vset.index_of(input(p))]++] = p;
206 p_array<mln_psite(I)> v(vec);
216 template <typename I>
218 p_array<mln_psite(I)>
221 mln_precondition(
exact(input).is_valid());
222 return impl::sort_psites_increasing_(mln_trait_image_quant(I)(),
226 template <
typename I>
228 p_array<mln_psite(I)>
231 mln_precondition(
exact(input).is_valid());
232 return impl::sort_psites_decreasing_(mln_trait_image_quant(I)(),
236 # endif // ! MLN_INCLUDE_ONLY
243 #endif // ! MLN_DATA_SORT_PSITES_HH