ctkVTKScalarBarWidgetTest1.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. // CTK includes
  18. #include "ctkVTKScalarBarWidget.h"
  19. // VTK includes
  20. #include <vtkScalarBarActor.h>
  21. #include <vtkScalarBarWidget.h>
  22. #include <vtkSmartPointer.h>
  23. // STD includes
  24. #include <iostream>
  25. //-----------------------------------------------------------------------------
  26. int ctkVTKScalarBarWidgetTest1(int argc, char * argv [] )
  27. {
  28. QApplication app(argc, argv);
  29. vtkSmartPointer<vtkScalarBarWidget> scalarBar =
  30. vtkSmartPointer<vtkScalarBarWidget>::New();
  31. vtkScalarBarActor* actor = scalarBar->GetScalarBarActor();
  32. ctkVTKScalarBarWidget widget;
  33. widget.setScalarBarWidget(scalarBar);
  34. widget.setScalarBarWidget(0);
  35. widget.setScalarBarWidget(scalarBar);
  36. // display
  37. widget.setDisplay(false);
  38. if (scalarBar->GetEnabled() != false)
  39. {
  40. std::cerr << "ctkVTKScalarBarWidget::setDisplay() failed"
  41. << std::endl;
  42. return EXIT_FAILURE;
  43. }
  44. // it will fail as there is no interactor set to the widget
  45. scalarBar->SetEnabled(true);
  46. if (widget.display() != static_cast<bool>(scalarBar->GetEnabled()))
  47. {
  48. std::cerr << "ctkVTKScalarBarWidget::setDisplay() failed"
  49. << std::endl;
  50. return EXIT_FAILURE;
  51. }
  52. // max number of colors
  53. widget.setMaxNumberOfColors(20);
  54. if (actor->GetMaximumNumberOfColors() != 20)
  55. {
  56. std::cerr << "ctkVTKScalarBarWidget::setMaxNumberOfColors() failed"
  57. << std::endl;
  58. return EXIT_FAILURE;
  59. }
  60. actor->SetMaximumNumberOfColors(30);
  61. if (widget.maxNumberOfColors() != 30)
  62. {
  63. std::cerr << "ctkVTKScalarBarWidget::setMaxNumberOfColors() failed"
  64. << std::endl;
  65. return EXIT_FAILURE;
  66. }
  67. // number of labels
  68. widget.setNumberOfLabels(5);
  69. if (actor->GetNumberOfLabels() != 5)
  70. {
  71. std::cerr << "ctkVTKScalarBarWidget::setNumberOfLabels() failed"
  72. << std::endl;
  73. return EXIT_FAILURE;
  74. }
  75. actor->SetNumberOfLabels(10);
  76. if (widget.numberOfLabels() != 10)
  77. {
  78. std::cerr << "ctkVTKScalarBarWidget::setNumberOfLabels() failed"
  79. << std::endl;
  80. return EXIT_FAILURE;
  81. }
  82. // title
  83. widget.setTitle("title");
  84. if (QString(actor->GetTitle()) != "title")
  85. {
  86. std::cerr << "ctkVTKScalarBarWidget::setTitle() failed"
  87. << std::endl;
  88. return EXIT_FAILURE;
  89. }
  90. actor->SetTitle("title 2");
  91. if (widget.title() != "title 2")
  92. {
  93. std::cerr << "ctkVTKScalarBarWidget::setTitle() failed"
  94. << std::endl;
  95. return EXIT_FAILURE;
  96. }
  97. // labels format
  98. widget.setLabelsFormat("@#$%^&*");
  99. if (QString(actor->GetLabelFormat()) != "@#$%^&*")
  100. {
  101. std::cerr << "ctkVTKScalarBarWidget::setLabelsFormat() failed"
  102. << std::endl;
  103. return EXIT_FAILURE;
  104. }
  105. actor->SetLabelFormat("@#$%^&*@#$%^&*");
  106. if (widget.labelsFormat() != "@#$%^&*@#$%^&*")
  107. {
  108. std::cerr << "ctkVTKScalarBarWidget::setLabelsFormat() failed"
  109. << std::endl;
  110. return EXIT_FAILURE;
  111. }
  112. widget.show();
  113. if (argc < 2 || QString(argv[1]) != "-I")
  114. {
  115. QTimer::singleShot(200, &app, SLOT(quit()));
  116. }
  117. return app.exec();
  118. }