ctkVTKHistogramTest4.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. int ctkVTKHistogramTest4( int argc, char * argv [])
  12. {
  13. Q_UNUSED(argc);
  14. Q_UNUSED(argv);
  15. //---------------------------------------------------
  16. // test 4 :
  17. //---------------------------------------------------
  18. //------Test build--------------------------------
  19. ctkVTKHistogram histogram;
  20. vtkSmartPointer<vtkDataArray> dataArray = vtkDataArray::CreateDataArray(VTK_FLOAT);
  21. dataArray->InsertNextTuple1( 10.001);
  22. dataArray->InsertNextTuple1( -0.231);
  23. dataArray->InsertNextTuple1( 220.0001);
  24. dataArray->InsertNextTuple1(1234.0);
  25. dataArray->InsertNextTuple1(220.0);
  26. histogram.setDataArray(dataArray);
  27. if (histogram.dataArray() != dataArray)
  28. {
  29. std::cerr << "Line : " << __LINE__
  30. << " - Problem with ctkVTKHistogram::setDataArray "
  31. << std::endl;
  32. return EXIT_FAILURE;
  33. }
  34. histogram.setNumberOfBins(256);
  35. //------Test build---------------------------------
  36. histogram.build();
  37. if (histogram.count() != 256)
  38. {
  39. std::cerr << "Failed to build histogram" << histogram.count()
  40. << std::endl;
  41. return EXIT_FAILURE;
  42. }
  43. if (histogram.value(-0.231).toInt() != 1)
  44. {
  45. std::cerr << "Failed to build histogram" << histogram.value(-0.231).toInt()
  46. << std::endl;
  47. return EXIT_FAILURE;
  48. }
  49. if (histogram.value(10.001).toInt() != 1)
  50. {
  51. std::cerr << "Failed to build histogram" << histogram.value(10.001).toInt()
  52. << std::endl;
  53. return EXIT_FAILURE;
  54. }
  55. if (histogram.value(220).toInt() != 2)
  56. {
  57. std::cerr << "Failed to build histogram" << histogram.value(220).toInt()
  58. << std::endl;
  59. return EXIT_FAILURE;
  60. }
  61. if (histogram.value(500).toInt() != 0)
  62. {
  63. std::cerr << "Failed to build histogram" << histogram.value(500).toInt()
  64. << std::endl;
  65. return EXIT_FAILURE;
  66. }
  67. return EXIT_SUCCESS;
  68. }