ctkVTKHistogramTest3.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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;
  21. dataArray.TakeReference(vtkDataArray::CreateDataArray(VTK_CHAR));
  22. dataArray->InsertNextTuple1(0);
  23. dataArray->InsertNextTuple1(0);
  24. dataArray->InsertNextTuple1(0);
  25. dataArray->InsertNextTuple1(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. //------Test build---------------------------------
  35. histogram.build();
  36. if (histogram.count() != 256)
  37. {
  38. std::cerr << "Failed to build histogram" << histogram.count()
  39. << std::endl;
  40. return EXIT_FAILURE;
  41. }
  42. if (histogram.value(0).toInt() != 4)
  43. {
  44. std::cerr << "Failed to build histogram" << histogram.value(0).toInt()
  45. << std::endl;
  46. return EXIT_FAILURE;
  47. }
  48. if (histogram.value(1).toInt() != 0)
  49. {
  50. std::cerr << "Failed to build histogram" << histogram.value(1).toInt()
  51. << std::endl;
  52. return EXIT_FAILURE;
  53. }
  54. if (histogram.value(255).toInt() != 0)
  55. {
  56. std::cerr << "Failed to build histogram" << histogram.value(255).toInt()
  57. << std::endl;
  58. return EXIT_FAILURE;
  59. }
  60. if (histogram.value(1024).toInt() != 0)
  61. {
  62. std::cerr << "Failed to build histogram" << histogram.value(1024).toInt()
  63. << std::endl;
  64. return EXIT_FAILURE;
  65. }
  66. return EXIT_SUCCESS;
  67. }