vtkLightBoxRendererManagerTest1.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. // CTKVTK includes
  15. #include "vtkLightBoxRendererManager.h"
  16. // CTKCore includes
  17. #include "ctkCommandLineParser.h"
  18. // VTK includes
  19. #include <vtkSmartPointer.h>
  20. #include <vtkRenderer.h>
  21. #include <vtkRenderWindowInteractor.h>
  22. #include <vtkRenderWindow.h>
  23. #include <vtkInteractorStyleImage.h>
  24. #include <vtkImageReader2Factory.h>
  25. #include <vtkImageReader2.h>
  26. #include <vtkImageData.h>
  27. #include <vtkRegressionTestImage.h>
  28. #include <vtkTestUtilities.h>
  29. // STD includes
  30. #include <cstdlib>
  31. // Convenient macro
  32. #define VTK_CREATE(type, name) \
  33. vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
  34. //----------------------------------------------------------------------------
  35. int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
  36. {
  37. const char * imageFilename = vtkTestUtilities::ExpandDataFileName(argc, argv, "HeadMRVolume.mhd");
  38. //----------------------------------------------------------------------------
  39. // Read Image
  40. //----------------------------------------------------------------------------
  41. // Instanciate the reader factory
  42. VTK_CREATE(vtkImageReader2Factory, imageFactory);
  43. // Instanciate an image reader
  44. vtkSmartPointer<vtkImageReader2> imageReader;
  45. imageReader.TakeReference(imageFactory->CreateImageReader2(imageFilename));
  46. if (!imageReader)
  47. {
  48. std::cerr << "Failed to instanciate image reader using: " << imageFilename << std::endl;
  49. return EXIT_FAILURE;
  50. }
  51. // Read image
  52. imageReader->SetFileName(imageFilename);
  53. imageReader->Update();
  54. vtkSmartPointer<vtkImageData> image = imageReader->GetOutput();
  55. //----------------------------------------------------------------------------
  56. // Renderer, RenderWindow and Interactor
  57. //----------------------------------------------------------------------------
  58. VTK_CREATE(vtkRenderer, rr);
  59. VTK_CREATE(vtkRenderWindow, rw);
  60. VTK_CREATE(vtkRenderWindowInteractor, ri);
  61. rw->SetSize(600, 600);
  62. rw->SetMultiSamples(0); // Ensure to have the same test image everywhere
  63. rw->AddRenderer(rr);
  64. rw->SetInteractor(ri);
  65. // Set Interactor Style
  66. VTK_CREATE(vtkInteractorStyleImage, iStyle);
  67. ri->SetInteractorStyle(iStyle);
  68. VTK_CREATE(vtkLightBoxRendererManager, lightBoxRendererManager);
  69. //----------------------------------------------------------------------------
  70. // Check if non initialized case is handled properly / Check default value
  71. //----------------------------------------------------------------------------
  72. if (lightBoxRendererManager->IsInitialized() != 0)
  73. {
  74. std::cerr << "line " << __LINE__ << " - Problem with IsInitialized()" << std::endl;
  75. std::cerr << " expected: 0" << std::endl;
  76. std::cerr << " current:" << lightBoxRendererManager->IsInitialized() << std::endl;
  77. return EXIT_FAILURE;
  78. }
  79. if (lightBoxRendererManager->GetRenderWindow() != 0)
  80. {
  81. std::cerr << "line " << __LINE__ << " - Problem with GetRenderWindow()" << std::endl;
  82. std::cerr << " expected: 0" << std::endl;
  83. std::cerr << " current:" << lightBoxRendererManager->GetRenderWindow() << std::endl;
  84. return EXIT_FAILURE;
  85. }
  86. if (lightBoxRendererManager->GetActiveCamera() != 0)
  87. {
  88. std::cerr << "line " << __LINE__ << " - Problem with GetActiveCamera()" << std::endl;
  89. std::cerr << " expected: 0" << std::endl;
  90. std::cerr << " current:" << lightBoxRendererManager->GetActiveCamera() << std::endl;
  91. return EXIT_FAILURE;
  92. }
  93. if (lightBoxRendererManager->GetRenderWindowItemCount() != 0)
  94. {
  95. std::cerr << "line " << __LINE__ << " - Problem with GetRenderWindowItemCount()" << std::endl;
  96. std::cerr << " expected: 0" << std::endl;
  97. std::cerr << " current:" << lightBoxRendererManager->GetRenderWindowItemCount() << std::endl;
  98. return EXIT_FAILURE;
  99. }
  100. if (lightBoxRendererManager->GetRenderer(4) != 0)
  101. {
  102. std::cerr << "line " << __LINE__ << " - Problem with GetRenderer()" << std::endl;
  103. std::cerr << " expected: 0" << std::endl;
  104. std::cerr << " current:" << lightBoxRendererManager->GetRenderer(4) << std::endl;
  105. return EXIT_FAILURE;
  106. }
  107. if (lightBoxRendererManager->GetRenderer(1,1) != 0)
  108. {
  109. std::cerr << "line " << __LINE__ << " - Problem with GetRenderer()" << std::endl;
  110. std::cerr << " expected: 0" << std::endl;
  111. std::cerr << " current:" << lightBoxRendererManager->GetRenderer(1,1) << std::endl;
  112. return EXIT_FAILURE;
  113. }
  114. if (lightBoxRendererManager->GetCornerAnnotationText().compare("") != 0)
  115. {
  116. std::cerr << "line " << __LINE__ << " - Problem with GetCornerAnnotationText()" << std::endl;
  117. std::cerr << " expected: Empty" << std::endl;
  118. std::cerr << " current:" << lightBoxRendererManager->GetCornerAnnotationText() << std::endl;
  119. return EXIT_FAILURE;
  120. }
  121. if (lightBoxRendererManager->GetRenderWindowLayoutType() !=
  122. vtkLightBoxRendererManager::LeftRightTopBottom)
  123. {
  124. std::cerr << "line " << __LINE__ << " - Problem with GetRenderWindowLayoutType()" << std::endl;
  125. std::cerr << " expected: " <<
  126. static_cast<int>(vtkLightBoxRendererManager::LeftRightTopBottom) << std::endl;
  127. std::cerr << " current:" <<
  128. static_cast<int>(lightBoxRendererManager->GetRenderWindowLayoutType()) << std::endl;
  129. return EXIT_FAILURE;
  130. }
  131. unsigned long mtime = lightBoxRendererManager->GetMTime();
  132. lightBoxRendererManager->ResetCamera();
  133. if (mtime != lightBoxRendererManager->GetMTime())
  134. {
  135. std::cerr << "line " << __LINE__ << " - Problem with ResetCamera()" << std::endl;
  136. return EXIT_FAILURE;
  137. }
  138. lightBoxRendererManager->SetActiveCamera(0);
  139. if (mtime != lightBoxRendererManager->GetMTime())
  140. {
  141. std::cerr << "line " << __LINE__ << " - Problem with SetActiveCamera()" << std::endl;
  142. return EXIT_FAILURE;
  143. }
  144. lightBoxRendererManager->SetImageData(image);
  145. if (mtime != lightBoxRendererManager->GetMTime())
  146. {
  147. std::cerr << "line " << __LINE__ << " - Problem with SetImageData()" << std::endl;
  148. return EXIT_FAILURE;
  149. }
  150. double highlightedboxColor[3] = {0.0, 1.0, 0.0};
  151. lightBoxRendererManager->SetHighlightedBoxColor(highlightedboxColor);
  152. if (mtime != lightBoxRendererManager->GetMTime())
  153. {
  154. std::cerr << "line " << __LINE__ << " - Problem with SetHighlightedBoxColor()" << std::endl;
  155. return EXIT_FAILURE;
  156. }
  157. //----------------------------------------------------------------------------
  158. // Initialize
  159. //----------------------------------------------------------------------------
  160. lightBoxRendererManager->Initialize(rw);
  161. if (lightBoxRendererManager->IsInitialized() != 1)
  162. {
  163. std::cerr << "line " << __LINE__ << " - Problem with IsInitialized()" << std::endl;
  164. std::cerr << " expected: 1" << std::endl;
  165. std::cerr << " current:" << lightBoxRendererManager->IsInitialized() << std::endl;
  166. return EXIT_FAILURE;
  167. }
  168. if (mtime == lightBoxRendererManager->GetMTime())
  169. {
  170. std::cerr << "line " << __LINE__ << " - Problem with IsInitialized()" << std::endl;
  171. return EXIT_FAILURE;
  172. }
  173. lightBoxRendererManager->SetImageData(image);
  174. lightBoxRendererManager->SetRenderWindowLayout(4, 5);
  175. lightBoxRendererManager->SetHighlighted(2,2,true);
  176. lightBoxRendererManager->SetColorWindowAndLevel(100, 100);
  177. double backgroundColor[3] = {0.5, 0.5, 0.5};
  178. lightBoxRendererManager->SetBackgroundColor(backgroundColor);
  179. double highlightedBoxColor[3] = {1.0, 1.0, 0.0};
  180. lightBoxRendererManager->SetHighlightedBoxColor(highlightedBoxColor);
  181. int retval = vtkRegressionTestImage(rw);
  182. if (retval == vtkRegressionTester::DO_INTERACTOR)
  183. {
  184. rw->GetInteractor()->Initialize();
  185. rw->GetInteractor()->Start();
  186. }
  187. return !retval;
  188. }