ctkVTKSliceViewTest1.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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. #include <QTimer>
  17. #include <QDebug>
  18. // CTK includes
  19. #include "ctkCommandLineParser.h"
  20. #include "ctkVTKSliceView.h"
  21. // VTK includes
  22. #include <vtkImageReader2Factory.h>
  23. #include <vtkImageReader2.h>
  24. #include <vtkImageData.h>
  25. #include <vtkSmartPointer.h>
  26. #include <vtkInteractorStyleImage.h>
  27. #include <vtkRenderWindowInteractor.h>
  28. #include <vtkLightBoxRendererManager.h>
  29. // STD includes
  30. #include <iostream>
  31. //-----------------------------------------------------------------------------
  32. int ctkVTKSliceViewTest1(int argc, char * argv [] )
  33. {
  34. QApplication app(argc, argv);
  35. // Test arguments
  36. bool interactive = false;
  37. QString data_directory;
  38. QString filename = "HeadMRVolume.mhd";
  39. // Command line parser
  40. ctkCommandLineParser parser;
  41. parser.addBooleanArgument(0, "-I", &interactive);
  42. parser.addStringArgument(0, "-D", &data_directory);
  43. if (!parser.parseArguments(app.arguments()))
  44. {
  45. std::cerr << qPrintable(parser.errorString()) << std::endl;
  46. return EXIT_FAILURE;
  47. }
  48. QString imageFilename = data_directory + "/" + filename;
  49. // Instanciate the reader factory
  50. vtkSmartPointer<vtkImageReader2Factory> imageFactory =
  51. vtkSmartPointer<vtkImageReader2Factory>::New();
  52. // Instanciate an image reader
  53. vtkSmartPointer<vtkImageReader2> imageReader;
  54. imageReader.TakeReference(imageFactory->CreateImageReader2(imageFilename.toLatin1()));
  55. if (!imageReader)
  56. {
  57. std::cerr << "Failed to instanciate image reader using: "
  58. << qPrintable(imageFilename) << std::endl;
  59. return EXIT_FAILURE;
  60. }
  61. // Read image
  62. imageReader->SetFileName(imageFilename.toLatin1());
  63. imageReader->Update();
  64. vtkSmartPointer<vtkImageData> image = imageReader->GetOutput();
  65. ctkVTKSliceView sliceView;
  66. sliceView.resize(300, 300);
  67. sliceView.setImageData(image);
  68. sliceView.lightBoxRendererManager()->SetRenderWindowLayout(4, 3);
  69. sliceView.lightBoxRendererManager()->SetHighlighted(1, 1, true);
  70. sliceView.setCornerAnnotationText("CTK");
  71. sliceView.scheduleRender();
  72. sliceView.show();
  73. if (!interactive)
  74. {
  75. QTimer::singleShot(1000, &app, SLOT(quit()));
  76. }
  77. return app.exec();
  78. }