75 #ifndef SLIP_HISTO_HPP
76 #define SLIP_HISTO_HPP
111 template<
typename InputIterator,
typename RandomAccessIterator>
115 RandomAccessIterator histo_first,
116 RandomAccessIterator histo_last,
117 typename std::iterator_traits<InputIterator>::value_type minval,
118 typename std::iterator_traits<InputIterator>::value_type maxval,
119 typename std::iterator_traits<InputIterator>::value_type step = 1)
121 typedef typename std::iterator_traits<InputIterator>::value_type T;
122 typedef typename std::iterator_traits<RandomAccessIterator>::value_type histo_T;
124 assert(first != last);
126 assert((histo_last - histo_first) == (
int)((maxval - minval + 1)/step));
129 std::fill(histo_first,histo_last,histo_T());
130 int maxi =
static_cast<int>((histo_last-histo_first) - 1);
132 InputIterator first2 = first;
134 for (; !error && first2 != last; ++first2)
136 if ( (*first2 < minval) || (*first2 > maxval) )
143 std::cerr <<
"Some values of the input datas are outside the defined interval: ["<<minval<<
","<<maxval<<
"]"<<std::endl;
148 int i = (int) trunc((*first - minval) / step);
149 if ((i > maxi) || (i < 0))
151 if (*first == maxval)
153 (*(histo_first + maxi))++;
159 (*(histo_first + i))++;
204 template<
typename InputIterator,
205 typename RandomAccessIterator,
206 typename MaskIterator>
210 MaskIterator mask_first,
211 RandomAccessIterator histo_first,
212 RandomAccessIterator histo_last,
213 typename std::iterator_traits<InputIterator>::value_type minval,
214 typename std::iterator_traits<InputIterator>::value_type maxval,
215 typename std::iterator_traits<InputIterator>::value_type step = 1,
216 typename std::iterator_traits<MaskIterator>::value_type value=
typename std::iterator_traits<MaskIterator>::value_type(1))
218 assert(first != last);
220 assert((histo_last - histo_first) == (
int)((maxval - minval + 1)/step));
222 typedef typename std::iterator_traits<InputIterator>::value_type T;
223 typedef typename std::iterator_traits<RandomAccessIterator>::value_type histo_T;
226 std::fill(histo_first,histo_last,histo_T());
227 int maxi =
static_cast<int>((histo_last-histo_first) - 1);
229 InputIterator first2 = first;
230 MaskIterator mask_first2 = mask_first;
232 for (; !error && first2 != last; ++first2, ++mask_first2)
234 if(*mask_first2 == value)
236 if ( (*first2 < minval) || (*first2 > maxval) )
244 std::cerr <<
"Some values of the input datas are outside the defined interval: ["<<minval<<
","<<maxval<<
"]"<<std::endl;
250 if(*mask_first==value)
252 int i = (int) trunc((*first - minval) / step);
254 if ((i > maxi) || (i < 0))
256 if (*first == maxval)
258 (*(histo_first + maxi))++;
265 (*(histo_first + i))++;
314 template<
typename InputIterator,
315 typename RandomAccessIterator,
320 RandomAccessIterator histo_first,
321 RandomAccessIterator histo_last,
323 typename std::iterator_traits<InputIterator>::value_type minval,
324 typename std::iterator_traits<InputIterator>::value_type maxval,
325 typename std::iterator_traits<InputIterator>::value_type step = 1
328 assert(first != last);
330 assert((histo_last - histo_first) == (
int)((maxval - minval + 1)/step));
331 typedef typename std::iterator_traits<InputIterator>::value_type T;
332 typedef typename std::iterator_traits<RandomAccessIterator>::value_type histo_T;
338 std::fill(histo_first,histo_last,histo_T());
339 int maxi =
static_cast<int>((histo_last-histo_first) - 1);
341 InputIterator first2 = first;
343 for (; !error && first2 != last; ++first2)
347 if ( (*first2 < minval) || (*first2 > maxval) )
355 std::cerr <<
"Some values of the input datas are outside the defined interval: ["<<minval<<
","<<maxval<<
"]"<<std::endl;
362 int i = (int) trunc((*first - minval) / step);
364 if ((i > maxi) || (i < 0))
366 if (*first == maxval)
368 (*(histo_first + maxi))++;
375 (*(histo_first + i))++;
404 template<
typename InputIterator,
typename InputIterator2,
typename OutputIterator>
408 InputIterator2 stepfirst,
409 InputIterator2 steplast,
410 OutputIterator result)
412 assert(first != last);
413 assert(stepfirst != steplast);
415 InputIterator2 runsteps;
416 InputIterator first2 = first;
422 for (runsteps=stepfirst+1,i=0;runsteps!=steplast;i++,runsteps++)
427 for (; !error && (first2 != last); ++first2){
428 if ( (*first2 < *stepfirst) || (*first2 > *(steplast-1)))
435 std::cerr <<
"Some values of the input datas are outside the defined interval: ["<<*stepfirst<<
","<<*(steplast-1)<<
"]"<<std::endl;
445 for (runsteps=stepfirst;!end && runsteps != steplast; runsteps++)
447 if (*first >= *runsteps)
457 if (!end && (*first >= *(steplast-1)))
460 if (*first == *(steplast-1))
506 template<
typename RandomAccessIterator1,
typename RandomAccessIterator2>
509 RandomAccessIterator1 histo_last,
510 RandomAccessIterator2 cum_histo_first,
511 RandomAccessIterator2 cum_histo_last)
514 assert(histo_last != histo_first);
515 assert((histo_last - histo_first) == (cum_histo_last - cum_histo_first));
517 typedef typename std::iterator_traits<RandomAccessIterator2>::value_type value_type;
519 *cum_histo_first++ = *histo_first++;
520 for(; histo_first != histo_last; ++histo_first, ++cum_histo_first)
522 *cum_histo_first = *(cum_histo_first-1) + *histo_first;
529 #endif //SLIP_HISTO_HPP
void histogram(InputIterator first, InputIterator last, RandomAccessIterator histo_first, RandomAccessIterator histo_last, typename std::iterator_traits< InputIterator >::value_type minval, typename std::iterator_traits< InputIterator >::value_type maxval, typename std::iterator_traits< InputIterator >::value_type step=1)
Simple histogram algorithm (uniform step)
Computes the maximum value between two values.
void histogram_mask(InputIterator first, InputIterator last, MaskIterator mask_first, RandomAccessIterator histo_first, RandomAccessIterator histo_last, typename std::iterator_traits< InputIterator >::value_type minval, typename std::iterator_traits< InputIterator >::value_type maxval, typename std::iterator_traits< InputIterator >::value_type step=1, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Simple histogram algorithm (uniform step) according to a mask sequence.
void real_histogram(InputIterator first, InputIterator last, InputIterator2 stepfirst, InputIterator2 steplast, OutputIterator result)
Complex histogram algorithm (variable step)
void cumulative_histogram(RandomAccessIterator1 histo_first, RandomAccessIterator1 histo_last, RandomAccessIterator2 cum_histo_first, RandomAccessIterator2 cum_histo_last)
Computes the cumulative histogram from a histogram.
void histogram_if(InputIterator first, InputIterator last, RandomAccessIterator histo_first, RandomAccessIterator histo_last, Predicate pred, typename std::iterator_traits< InputIterator >::value_type minval, typename std::iterator_traits< InputIterator >::value_type maxval, typename std::iterator_traits< InputIterator >::value_type step=1)
Simple histogram algorithm (uniform step) according to a predicate.