ctkVTKMagnifyWidgetTest1.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.commontk.org/LICENSE
  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. // CTK includes
  17. #include "ctkVTKMagnifyWidget.h"
  18. // VTK includes
  19. #include <QVTKWidget.h>
  20. // STD includes
  21. #include <cstdlib>
  22. #include <iostream>
  23. //-----------------------------------------------------------------------------
  24. int ctkVTKMagnifyWidgetTest1(int argc, char * argv [] )
  25. {
  26. QApplication app(argc, argv);
  27. ctkVTKMagnifyWidget magnify;
  28. // check default values
  29. if (!magnify.showCursor() ||
  30. magnify.cursorColor() != magnify.palette().color(QPalette::Highlight) ||
  31. magnify.cursorType() != ctkCursorPixmapWidget::CrossHairCursor ||
  32. magnify.marginColor() != magnify.palette().color(QPalette::Window) ||
  33. magnify.bullsEyeWidth() != 15 ||
  34. magnify.magnification() != 1.0 ||
  35. magnify.numberObserved() != 0)
  36. {
  37. std::cerr << "ctkVTKMagnifyWidget: Wrong default values. " << std::endl
  38. << " " << magnify.showCursor()
  39. << " " << qPrintable(magnify.cursorColor().name())
  40. << " " << magnify.cursorType()
  41. << " " << qPrintable(magnify.marginColor().name())
  42. << " " << magnify.bullsEyeWidth()
  43. << " " << magnify.magnification()
  44. << " " << magnify.numberObserved() << std::endl;
  45. return EXIT_FAILURE;
  46. }
  47. // Magnification
  48. magnify.setMagnification(10.5);
  49. if (magnify.magnification() != 10.5)
  50. {
  51. std::cerr << "ctkVTKMagnifyWidget:setMagnification failed. "
  52. << magnify.magnification() << std::endl;
  53. return EXIT_FAILURE;
  54. }
  55. // Adding / removing observed QVTKWidgets
  56. QList<QVTKWidget *> allVTKWidgets;
  57. int numVTKWidgets = 3;
  58. for (int i = 0; i < numVTKWidgets; i++)
  59. {
  60. allVTKWidgets.append(new QVTKWidget());
  61. }
  62. // Observe one widget
  63. magnify.observe(allVTKWidgets[0]);
  64. if (!magnify.isObserved(allVTKWidgets[0]) || magnify.isObserved(allVTKWidgets[1]) ||
  65. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 1)
  66. {
  67. std::cerr << "ctkVTKMagnifyWidget:observe(QVTKWidget*) failed. "
  68. << "Number observed = " << magnify.numberObserved() << std::endl;
  69. return EXIT_FAILURE;
  70. }
  71. // Observe two more widgets
  72. magnify.observe(allVTKWidgets.mid(1,2));
  73. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  74. !magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 3)
  75. {
  76. std::cerr << "ctkVTKMagnifyWidget:observe(QList<QVTKWidget*>) failed. "
  77. << "Number observed = " << magnify.numberObserved() << std::endl;
  78. return EXIT_FAILURE;
  79. }
  80. // Re-observe a widget
  81. magnify.observe(allVTKWidgets[2]);
  82. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  83. !magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 3)
  84. {
  85. std::cerr << "ctkVTKMagnifyWidget:observe(QVTKWidget*) failed on re-observe. "
  86. << "Number observed = " << magnify.numberObserved() << std::endl;
  87. return EXIT_FAILURE;
  88. }
  89. // Re-observe a list of widgets
  90. magnify.observe(allVTKWidgets.mid(0,2));
  91. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  92. !magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 3)
  93. {
  94. std::cerr << "ctkVTKMagnifyWidget:observe(QList<QVTKWidget*>) failed on re-observe. "
  95. << "Number observed = " << magnify.numberObserved() << std::endl;
  96. return EXIT_FAILURE;
  97. }
  98. // Remove a widget
  99. magnify.remove(allVTKWidgets[2]);
  100. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  101. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 2)
  102. {
  103. std::cerr << "ctkVTKMagnifyWidget:remove(QVTKWidget*) failed. "
  104. << "Number observed = " << magnify.numberObserved() << std::endl;
  105. return EXIT_FAILURE;
  106. }
  107. // Re-remove a widget
  108. magnify.remove(allVTKWidgets[2]);
  109. if (!magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  110. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 2)
  111. {
  112. std::cerr << "ctkVTKMagnifyWidget:remove(QVTKWidget*) failed on re-remove. "
  113. << "Number observed = " << magnify.numberObserved() << std::endl;
  114. return EXIT_FAILURE;
  115. }
  116. // Remove a list of widgets
  117. magnify.remove(allVTKWidgets.mid(0,2));
  118. if (magnify.isObserved(allVTKWidgets[0]) || magnify.isObserved(allVTKWidgets[1]) ||
  119. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 0)
  120. {
  121. std::cerr << "ctkVTKMagnifyWidget:remove(QList<QVTKWidget*>) failed. "
  122. << "Number observed = " << magnify.numberObserved() << std::endl;
  123. return EXIT_FAILURE;
  124. }
  125. // Re-remove a list of widgets
  126. magnify.remove(allVTKWidgets.mid(1,2));
  127. if (magnify.isObserved(allVTKWidgets[0]) || magnify.isObserved(allVTKWidgets[1]) ||
  128. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 0)
  129. {
  130. std::cerr << "ctkVTKMagnifyWidget:remove(QList<QVTKWidget*>) failed on re-remove. "
  131. << "Number observed = " << magnify.numberObserved() << std::endl;
  132. return EXIT_FAILURE;
  133. }
  134. // Observe a list of widgets of length one
  135. magnify.observe(allVTKWidgets.mid(1,1));
  136. if (magnify.isObserved(allVTKWidgets[0]) || !magnify.isObserved(allVTKWidgets[1]) ||
  137. magnify.isObserved(allVTKWidgets[2]) || magnify.numberObserved() != 1)
  138. {
  139. std::cerr << "ctkVTKMagnifyWidget:observe(QList<QVTKWidget*>) failed on lists of "
  140. << "length 1. Number observed = " << magnify.numberObserved() << std::endl;
  141. return EXIT_FAILURE;
  142. }
  143. return EXIT_SUCCESS;
  144. }