IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Histogram.h
1 // Histogram.h:
3 // ------------
4 //
22 
23 #ifndef __IPSDKMATH_HISTOGRAM_H__
24 #define __IPSDKMATH_HISTOGRAM_H__
25 
26 #include <IPSDKMath/Statistics/BaseHistogram.h>
27 #include <boost/type_traits.hpp>
28 
29 namespace ipsdk {
30 namespace math {
31 
34 
35 template <ipBool g_bDataIntegral>
37 {
38  // declare serial class
40 
41 public:
44  Histogram();
45  ~Histogram();
47 
48 // methods
49 public:
50  //--------------------------------
53  //--------------------------------
54 
61  template <typename T>
62  typename boost::enable_if_c<boost::is_arithmetic<T>::value,
63  void>::type
64  initWithBinWidth(const T firstHistoValue, const T lastHistoValue,
65  const T binWidth,
67 
73  template <typename T>
74  typename boost::enable_if_c<boost::is_arithmetic<T>::value,
75  void>::type
76  initWithNbClasses(const T firstHistoValue, const T lastHistoValue,
77  const ipUInt32 nbClasses,
79 
90  template <typename IteratorType>
91  typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
92  ipUInt64>::type
93  initWithBinWidth(const IteratorType& iterBegin,
94  const IteratorType& iterEnd,
95  const typename std::iterator_traits<IteratorType>::value_type firstHistoValue,
96  const typename std::iterator_traits<IteratorType>::value_type lastHistoValue,
97  const typename std::iterator_traits<IteratorType>::value_type binWidth,
99 
110  template <typename ContainerType>
111  typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
112  boost::has_dereference<ContainerType>::value == false,
113  ipUInt64>::type
114  initWithBinWidth(const ContainerType& coll,
115  const typename ContainerType::value_type firstHistoValue,
116  const typename ContainerType::value_type lastHistoValue,
117  const typename ContainerType::value_type binWidth,
119 
127  template <typename IteratorType>
128  typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
129  void>::type
130  initWithBinWidth(const IteratorType& iterBegin,
131  const IteratorType& iterEnd,
132  const typename std::iterator_traits<IteratorType>::value_type binWidth);
133 
141  template <typename ContainerType>
142  typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
143  boost::has_dereference<ContainerType>::value == false,
144  void>::type
145  initWithBinWidth(const ContainerType& coll,
146  const typename ContainerType::value_type binWidth);
147 
158  template <typename IteratorType>
159  typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
160  ipUInt64>::type
161  initWithNbClasses(const IteratorType& iterBegin,
162  const IteratorType& iterEnd,
163  const typename std::iterator_traits<IteratorType>::value_type firstHistoValue,
164  const typename std::iterator_traits<IteratorType>::value_type lastHistoValue,
165  const ipUInt32 nbClasses,
167 
178  template <typename ContainerType>
179  typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
180  boost::has_dereference<ContainerType>::value == false,
181  ipUInt64>::type
182  initWithNbClasses(const ContainerType& coll,
183  const typename ContainerType::value_type firstHistoValue,
184  const typename ContainerType::value_type lastHistoValue,
185  const ipUInt32 nbClasses,
187 
195  template <typename IteratorType>
196  typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
197  void>::type
198  initWithNbClasses(const IteratorType& iterBegin,
199  const IteratorType& iterEnd,
200  const ipUInt32 nbClasses);
201 
209  template <typename ContainerType>
210  typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
211  boost::has_dereference<ContainerType>::value == false,
212  void>::type
213  initWithNbClasses(const ContainerType& coll,
214  const ipUInt32 nbClasses);
216 
217  //------------------------------------
220  //------------------------------------
221 
226  template <typename IteratorType>
227  typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
228  ipUInt64>::type
229  insertData(const IteratorType& iterBegin,
230  const IteratorType& iterEnd);
231 
236  template <typename ContainerType>
237  typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
238  boost::has_dereference<ContainerType>::value == false,
239  ipUInt64>::type
240  insertData(const ContainerType& coll);
241 
246  template <typename T>
247  typename boost::enable_if_c<boost::is_arithmetic<T>::value,
248  ipBool>::type
249  insertValue(const T value);
251 
252  //-----------------------
255  //-----------------------
256 
258  inline ipBool areDataIntegral() const;
260 
261 // attributes
262 protected:
263 
264 };
265 
268 
269 template <ipBool g_bDataIntegral>
270 template <typename T>
271 IPSDK_FORCEINLINE
272 typename boost::enable_if_c<boost::is_arithmetic<T>::value, void>::type
273 Histogram<g_bDataIntegral>::initWithBinWidth(const T firstHistoValue,
274  const T lastHistoValue,
275  const T binWidth,
276  const eHistogramOutOfBoundsPolicy& outOfBoundsPolicy)
277 {
278  // check for input type validity
279  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
280 
281  // update histogram parameters
282  updateHistogramParams(static_cast<ipReal64>(firstHistoValue),
283  static_cast<ipReal64>(lastHistoValue),
284  static_cast<ipReal64>(binWidth),
285  outOfBoundsPolicy);
286 }
287 
288 template <ipBool g_bDataIntegral>
289 template <typename T>
290 IPSDK_FORCEINLINE
291 typename boost::enable_if_c<boost::is_arithmetic<T>::value, void>::type
292 Histogram<g_bDataIntegral>::initWithNbClasses(const T firstHistoValue,
293  const T lastHistoValue,
294  const ipUInt32 nbClasses,
295  const eHistogramOutOfBoundsPolicy& outOfBoundsPolicy)
296 {
297  // check for input type validity
298  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
299 
300  // update histogram parameters
301  updateHistogramParams(static_cast<ipReal64>(firstHistoValue),
302  static_cast<ipReal64>(lastHistoValue),
303  nbClasses,
304  outOfBoundsPolicy);
305 }
306 
307 template <ipBool g_bDataIntegral>
308 template <typename IteratorType>
309 IPSDK_FORCEINLINE
310 typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
311  ipUInt64>::type
312 Histogram<g_bDataIntegral>::initWithBinWidth(const IteratorType& iterBegin,
313  const IteratorType& iterEnd,
314  const typename std::iterator_traits<IteratorType>::value_type firstHistoValue,
315  const typename std::iterator_traits<IteratorType>::value_type lastHistoValue,
316  const typename std::iterator_traits<IteratorType>::value_type binWidth,
317  const eHistogramOutOfBoundsPolicy& outOfBoundsPolicy)
318 {
319  // check for input type validity
320  typedef typename std::iterator_traits<IteratorType>::value_type T;
321  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
322  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
323 
324  // update histogram parameters
325  updateHistogramParams(static_cast<ipReal64>(firstHistoValue),
326  static_cast<ipReal64>(lastHistoValue),
327  static_cast<ipReal64>(binWidth),
328  outOfBoundsPolicy);
329 
330  // insert input data into histogram
331  return insertData(iterBegin, iterEnd);
332 }
333 
334 template <ipBool g_bDataIntegral>
335 template <typename ContainerType>
336 IPSDK_FORCEINLINE
337 typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
338  boost::has_dereference<ContainerType>::value == false,
339  ipUInt64>::type
340 Histogram<g_bDataIntegral>::initWithBinWidth(const ContainerType& coll,
341  const typename ContainerType::value_type firstHistoValue,
342  const typename ContainerType::value_type lastHistoValue,
343  const typename ContainerType::value_type binWidth,
344  const eHistogramOutOfBoundsPolicy& outOfBoundsPolicy)
345 {
346  // check for input type validity
347  typedef typename ContainerType::value_type T;
348  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
349  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
350 
351  return initWithBinWidth(coll.begin(), coll.end(), firstHistoValue, lastHistoValue, binWidth, outOfBoundsPolicy);
352 }
353 
354 template <ipBool g_bDataIntegral>
355 template <typename IteratorType>
356 IPSDK_FORCEINLINE
357 typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
358  void>::type
359 Histogram<g_bDataIntegral>::initWithBinWidth(const IteratorType& iterBegin,
360  const IteratorType& iterEnd,
361  const typename std::iterator_traits<IteratorType>::value_type binWidth)
362 {
363  // check for input type validity
364  typedef typename std::iterator_traits<IteratorType>::value_type T;
365  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
366  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
367 
368  // extract minimum and maximum value from collection
369  T firstHistoValue, lastHistoValue;
370  extractMinMax(iterBegin, iterEnd, firstHistoValue, lastHistoValue);
371 
372  // call of initialization method
373  initWithBinWidth(iterBegin, iterEnd, firstHistoValue, lastHistoValue, binWidth);
374 }
375 
376 template <ipBool g_bDataIntegral>
377 template <typename ContainerType>
378 IPSDK_FORCEINLINE
379 typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
380  boost::has_dereference<ContainerType>::value == false,
381  void>::type
382 Histogram<g_bDataIntegral>::initWithBinWidth(const ContainerType& coll,
383  const typename ContainerType::value_type binWidth)
384 {
385  // check for input type validity
386  typedef typename ContainerType::value_type T;
387  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
388  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
389 
390  initWithBinWidth(coll.begin(), coll.end(), binWidth);
391 }
392 
393 template <ipBool g_bDataIntegral>
394 template <typename IteratorType>
395 IPSDK_FORCEINLINE
396 typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
397  ipUInt64>::type
398 Histogram<g_bDataIntegral>::initWithNbClasses(const IteratorType& iterBegin,
399  const IteratorType& iterEnd,
400  const typename std::iterator_traits<IteratorType>::value_type firstHistoValue,
401  const typename std::iterator_traits<IteratorType>::value_type lastHistoValue,
402  const ipUInt32 nbClasses,
403  const eHistogramOutOfBoundsPolicy& outOfBoundsPolicy)
404 {
405  // check for input type validity
406  typedef typename std::iterator_traits<IteratorType>::value_type T;
407  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
408  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
409 
410  // update histogram parameters
411  updateHistogramParams(static_cast<ipReal64>(firstHistoValue),
412  static_cast<ipReal64>(lastHistoValue),
413  nbClasses,
414  outOfBoundsPolicy);
415 
416  // insert input data into histogram
417  return insertData(iterBegin, iterEnd);
418 }
419 
420 template <ipBool g_bDataIntegral>
421 template <typename ContainerType>
422 IPSDK_FORCEINLINE
423 typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
424  boost::has_dereference<ContainerType>::value == false,
425  ipUInt64>::type
426 Histogram<g_bDataIntegral>::initWithNbClasses(const ContainerType& coll,
427  const typename ContainerType::value_type firstHistoValue,
428  const typename ContainerType::value_type lastHistoValue,
429  const ipUInt32 nbClasses,
430  const eHistogramOutOfBoundsPolicy& outOfBoundsPolicy)
431 {
432  // check for input type validity
433  typedef typename ContainerType::value_type T;
434  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
435  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
436 
437  return initWithNbClasses(coll.begin(), coll.end(), firstHistoValue, lastHistoValue, nbClasses, outOfBoundsPolicy);
438 }
439 
440 template <ipBool g_bDataIntegral>
441 template <typename IteratorType>
442 IPSDK_FORCEINLINE
443 typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
444  void>::type
445 Histogram<g_bDataIntegral>::initWithNbClasses(const IteratorType& iterBegin,
446  const IteratorType& iterEnd,
447  const ipUInt32 nbClasses)
448 {
449  // check for input type validity
450  typedef typename std::iterator_traits<IteratorType>::value_type T;
451  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
452  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
453 
454  // extract minimum and maximum value from collection
455  T firstHistoValue, lastHistoValue;
456  extractMinMax(iterBegin, iterEnd, firstHistoValue, lastHistoValue);
457 
458  // call of initialization method
459  initWithNbClasses(iterBegin, iterEnd, firstHistoValue, lastHistoValue, nbClasses);
460 }
461 
462 template <ipBool g_bDataIntegral>
463 template <typename ContainerType>
464 IPSDK_FORCEINLINE
465 typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
466  boost::has_dereference<ContainerType>::value == false,
467  void>::type
468 Histogram<g_bDataIntegral>::initWithNbClasses(const ContainerType& coll,
469  const ipUInt32 nbClasses)
470 {
471  // check for input type validity
472  typedef typename ContainerType::value_type T;
473  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
474  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
475 
476  initWithNbClasses(coll.begin(), coll.end(), nbClasses);
477 }
478 
479 template <ipBool g_bDataIntegral>
480 template <typename IteratorType>
481 IPSDK_FORCEINLINE
482 typename boost::enable_if_c<boost::has_dereference<IteratorType>::value,
483  ipUInt64>::type
484 Histogram<g_bDataIntegral>::insertData(const IteratorType& iterBegin,
485  const IteratorType& iterEnd)
486 {
487  // check for input type validity
488  typedef typename std::iterator_traits<IteratorType>::value_type T;
489  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
490  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
491 
492  // check for initialization
493  checkInit();
494 
495  // clear of cumulated data
496  clearCumulatedData();
497 
498  // parse all data
499  ipUInt64 nbInserted = 0;
500  IteratorType iter = iterBegin;
501  while (iter != iterEnd) {
502 
503  // insert data into collection
504  if (insertDataInternal(static_cast<ipReal64>(*iter)) == true)
505  ++nbInserted;
506 
507  ++iter;
508  }
509 
510  return nbInserted;
511 }
512 
513 template <ipBool g_bDataIntegral>
514 template <typename ContainerType>
515 IPSDK_FORCEINLINE
516 typename boost::enable_if_c<boost::is_arithmetic<ContainerType>::value == false &&
517  boost::has_dereference<ContainerType>::value == false,
518  ipUInt64>::type
519 Histogram<g_bDataIntegral>::insertData(const ContainerType& coll)
520 {
521  // check for input type validity
522  typedef typename ContainerType::value_type T;
523  BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
524  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
525 
526  return insertData(coll.begin(), coll.end());
527 }
528 
529 template <ipBool g_bDataIntegral>
530 template <typename T>
531 IPSDK_FORCEINLINE
532 typename boost::enable_if_c<boost::is_arithmetic<T>::value,
533  ipBool>::type
535 {
536  // check for input type validity
537  BOOST_STATIC_ASSERT(boost::is_integral<T>::value == g_bDataIntegral);
538 
539  // check for initialization
540  checkInit();
541 
542  // clear of cumulated data
543  clearCumulatedData();
544 
545  // retrieve bin index associated to current data
546  // and insert it if needed
547  return insertDataInternal(value);
548 }
549 
550 template <ipBool g_bDataIntegral>
551 inline ipBool
553 {
554  return g_bDataIntegral;
555 }
556 
559 
560 } // end of namespace math
561 } // end of namespace ipsdk
562 
563 #endif // __IPSDKMATH_HISTOGRAM_H__
#define IPSDK_DECLARE_SERIAL_WITH_COPY(libraryName, className)
macro enabling serialization on class
Definition: SerializationHdrMacro.h:73
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
void extractMinMax(const IteratorType &iterBegin, const IteratorType &iterEnd, typename std::iterator_traits< IteratorType >::value_type &minValue, typename std::iterator_traits< IteratorType >::value_type &maxValue)
function allowing to compute minimum and maximum value for a collection
Definition: BasicStatistics.h:35
uint64_t ipUInt64
Base types definition.
Definition: BaseTypes.h:55
ipBool areDataIntegral() const
check whether histogram data are integral
Definition: Histogram.h:552
Base class for histogram data management.
Definition: BaseHistogram.h:40
boost::enable_if_c< boost::has_dereference< IteratorType >::value, ipUInt64 >::type insertData(const IteratorType &iterBegin, const IteratorType &iterEnd)
method allowing to insert a set of data into histogram
boost::enable_if_c< boost::is_arithmetic< T >::value, void >::type initWithBinWidth(const T firstHistoValue, const T lastHistoValue, const T binWidth, const eHistogramOutOfBoundsPolicy &outOfBoundsPolicy=eHistogramOutOfBoundsPolicy::eHOOBP_Ignored)
initialization of histogram with a bin with value and for data type with integral type ...
#define IPSDKMATH_API
Import/Export macro for library IPSDKMath.
Definition: IPSDKMathExports.h:27
Class allowing to encapsulated histogram data and to compute several associated indicators.
Definition: Histogram.h:36
bool ipBool
Base types definition.
Definition: BaseTypes.h:47
eHistogramOutOfBoundsPolicy
enumerate use to describe histogram policy used to process out of bounds data
Definition: HistogramTypes.h:37
boost::enable_if_c< boost::is_arithmetic< T >::value, void >::type initWithNbClasses(const T firstHistoValue, const T lastHistoValue, const ipUInt32 nbClasses, const eHistogramOutOfBoundsPolicy &outOfBoundsPolicy=eHistogramOutOfBoundsPolicy::eHOOBP_Ignored)
initialization of histogram with a number of classes
Data with values not in [firstHistoValue, lastHistoValue] are ignored.
Definition: HistogramTypes.h:39
boost::enable_if_c< boost::is_arithmetic< T >::value, ipBool >::type insertValue(const T value)
method allowing to insert a single value into histogram
uint32_t ipUInt32
Base types definition.
Definition: BaseTypes.h:53