ctkVTKHistogramTest4.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Qt includes
  2. #include <QCoreApplication>
  3. // CTKVTK includes
  4. #include "ctkVTKHistogram.h"
  5. // VTK includes
  6. #include <vtkSmartPointer.h>
  7. #include <vtkDataArray.h>
  8. // STD includes
  9. #include <cstdlib>
  10. #include <iostream>
  11. #include <limits>
  12. int ctkVTKHistogramTest4( int argc, char * argv [])
  13. {
  14. Q_UNUSED(argc);
  15. Q_UNUSED(argv);
  16. //---------------------------------------------------
  17. // test 4 :
  18. //---------------------------------------------------
  19. //------Test build--------------------------------
  20. ctkVTKHistogram histogram;
  21. vtkSmartPointer<vtkDataArray> dataArray = vtkDataArray::CreateDataArray(VTK_FLOAT);
  22. dataArray->InsertNextTuple1( 10.001);
  23. dataArray->InsertNextTuple1( -0.231);
  24. dataArray->InsertNextTuple1( 220.0001);
  25. dataArray->InsertNextTuple1(1234.0);
  26. dataArray->InsertNextTuple1(220.0);
  27. if(std::numeric_limits<float>::has_quiet_NaN)
  28. {
  29. // These should be ignored.
  30. const float positiveNaN = std::numeric_limits<float>::quiet_NaN();
  31. dataArray->InsertNextTuple1(positiveNaN);
  32. const float negativeNaN = - positiveNaN;
  33. dataArray->InsertNextTuple1(negativeNaN);
  34. }
  35. histogram.setDataArray(dataArray);
  36. if (histogram.dataArray() != dataArray)
  37. {
  38. std::cerr << "Line : " << __LINE__
  39. << " - Problem with ctkVTKHistogram::setDataArray "
  40. << std::endl;
  41. return EXIT_FAILURE;
  42. }
  43. histogram.setNumberOfBins(256);
  44. //------Test build---------------------------------
  45. histogram.build();
  46. if (histogram.count() != 256)
  47. {
  48. std::cerr << "Failed to build histogram" << histogram.count()
  49. << std::endl;
  50. return EXIT_FAILURE;
  51. }
  52. if (histogram.value(-0.231).toInt() != 1)
  53. {
  54. std::cerr << "Failed to build histogram" << histogram.value(-0.231).toInt()
  55. << std::endl;
  56. return EXIT_FAILURE;
  57. }
  58. if (histogram.value(10.001).toInt() != 1)
  59. {
  60. std::cerr << "Failed to build histogram" << histogram.value(10.001).toInt()
  61. << std::endl;
  62. return EXIT_FAILURE;
  63. }
  64. if (histogram.value(220).toInt() != 2)
  65. {
  66. std::cerr << "Failed to build histogram" << histogram.value(220).toInt()
  67. << std::endl;
  68. return EXIT_FAILURE;
  69. }
  70. if (histogram.value(500).toInt() != 0)
  71. {
  72. std::cerr << "Failed to build histogram" << histogram.value(500).toInt()
  73. << std::endl;
  74. return EXIT_FAILURE;
  75. }
  76. return EXIT_SUCCESS;
  77. }