ctkVTKThresholdWidgetTest1.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // QT includes
  15. #include <QApplication>
  16. #include <QTimer>
  17. // qMRML includes
  18. #ifdef CTK_USE_CHARTS
  19. #include "ctkVTKScalarsToColorsView.h"
  20. #endif
  21. #include "ctkVTKThresholdWidget.h"
  22. // VTK includes
  23. #include <vtkNew.h>
  24. #include <vtkPiecewiseFunction.h>
  25. // STD includes
  26. #include <cstdlib>
  27. #include <iostream>
  28. int ctkVTKThresholdWidgetTest1(int argc, char * argv [] )
  29. {
  30. QApplication app(argc, argv);
  31. vtkNew<vtkPiecewiseFunction> function;
  32. ctkVTKThresholdWidget thresholdWidget;
  33. thresholdWidget.setPiecewiseFunction(function.GetPointer());
  34. if (thresholdWidget.piecewiseFunction() != function.GetPointer())
  35. {
  36. std::cerr << "ctkVTKThresholdWidget::setPiecewiseFunction() failed"
  37. << std::endl;
  38. return EXIT_FAILURE;
  39. }
  40. thresholdWidget.setRange(10., 20.);
  41. double range[2];
  42. thresholdWidget.range(range);
  43. if (range[0] != 10. || range[1] != 20.)
  44. {
  45. std::cerr << "ctkVTKThresholdWidget::setRange() failed: "
  46. << range[0] << " " << range[1] << std::endl;
  47. return EXIT_FAILURE;
  48. }
  49. thresholdWidget.setOpacity(1.);
  50. if (thresholdWidget.opacity() != 1.)
  51. {
  52. std::cerr << "ctkVTKThresholdWidget::setOpacity() failed: "
  53. << thresholdWidget.opacity() << std::endl;
  54. return EXIT_FAILURE;
  55. }
  56. thresholdWidget.setThresholdValues(11., 19.);
  57. double values[2];
  58. thresholdWidget.thresholdValues(values);
  59. if (values[0] != 11. || values[1] != 19.)
  60. {
  61. std::cerr << "ctkVTKThresholdWidget::setThresholdValues() failed: "
  62. << values[0] << " " << values[1] << std::endl;
  63. return EXIT_FAILURE;
  64. }
  65. thresholdWidget.show();
  66. #ifdef CTK_USE_CHARTS
  67. ctkVTKScalarsToColorsView view;
  68. view.addOpacityFunction(function.GetPointer());
  69. view.show();
  70. #endif
  71. if (argc < 2 || QString(argv[1]) != "-I" )
  72. {
  73. QTimer::singleShot(200, &app, SLOT(quit()));
  74. }
  75. return app.exec();
  76. }