ctkVTKHistogramTest3.cpp 1.9 KB

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