ctkVTKHistogramTest4.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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;
  22. dataArray.TakeReference(vtkDataArray::CreateDataArray(VTK_FLOAT));
  23. dataArray->InsertNextTuple1( 10.001);
  24. dataArray->InsertNextTuple1( -0.231);
  25. dataArray->InsertNextTuple1( 220.0001);
  26. dataArray->InsertNextTuple1(1234.0);
  27. dataArray->InsertNextTuple1(220.0);
  28. if(std::numeric_limits<float>::has_quiet_NaN)
  29. {
  30. // These should be ignored.
  31. const float positiveNaN = std::numeric_limits<float>::quiet_NaN();
  32. dataArray->InsertNextTuple1(positiveNaN);
  33. const float negativeNaN = - positiveNaN;
  34. dataArray->InsertNextTuple1(negativeNaN);
  35. }
  36. histogram.setDataArray(dataArray);
  37. if (histogram.dataArray() != dataArray)
  38. {
  39. std::cerr << "Line : " << __LINE__
  40. << " - Problem with ctkVTKHistogram::setDataArray "
  41. << std::endl;
  42. return EXIT_FAILURE;
  43. }
  44. histogram.setNumberOfBins(256);
  45. //------Test build---------------------------------
  46. histogram.build();
  47. if (histogram.count() != 256)
  48. {
  49. std::cerr << "Failed to build histogram" << histogram.count()
  50. << std::endl;
  51. return EXIT_FAILURE;
  52. }
  53. if (histogram.value(-0.231).toInt() != 1)
  54. {
  55. std::cerr << "Failed to build histogram" << histogram.value(-0.231).toInt()
  56. << std::endl;
  57. return EXIT_FAILURE;
  58. }
  59. if (histogram.value(10.001).toInt() != 1)
  60. {
  61. std::cerr << "Failed to build histogram" << histogram.value(10.001).toInt()
  62. << std::endl;
  63. return EXIT_FAILURE;
  64. }
  65. if (histogram.value(220).toInt() != 2)
  66. {
  67. std::cerr << "Failed to build histogram" << histogram.value(220).toInt()
  68. << std::endl;
  69. return EXIT_FAILURE;
  70. }
  71. if (histogram.value(500).toInt() != 0)
  72. {
  73. std::cerr << "Failed to build histogram" << histogram.value(500).toInt()
  74. << std::endl;
  75. return EXIT_FAILURE;
  76. }
  77. return EXIT_SUCCESS;
  78. }