Browse Source

ENH: Add ctkVTKSliceView test skeleton

Jean-Christophe Fillion-Robin 15 years ago
parent
commit
83640064a7

+ 5 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/CMakeLists.txt

@@ -16,6 +16,9 @@ SET(TEST_SOURCES
 # Tests expecting CTKData to be set
 #
 IF(EXISTS "${CTKData_DIR}")
+  LIST(APPEND TEST_SOURCES
+    ctkVTKSliceViewTest1.cpp
+    )
 ENDIF()
 
 CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cpp
@@ -56,4 +59,6 @@ SIMPLE_TEST( ctkTransferFunctionViewTest5 )
 # Add Tests expecting CTKData to be set
 #
 IF(EXISTS "${CTKData_DIR}")
+  #
+  SIMPLE_TEST( ctkVTKSliceViewTest1 )
 ENDIF()

+ 96 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKSliceViewTest1.cpp

@@ -0,0 +1,96 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QApplication>
+#include <QTimer>
+#include <QDebug>
+
+// CTK includes
+#include "ctkCommandLineParser.h"
+#include "ctkVTKSliceView.h"
+
+// VTK includes
+#include <vtkImageReader2Factory.h>
+#include <vtkImageReader2.h>
+#include <vtkImageData.h>
+#include <vtkSmartPointer.h>
+#include <vtkInteractorStyleImage.h>
+#include <vtkRenderWindowInteractor.h>
+
+// STD includes
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkVTKSliceViewTest1(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  // Test arguments
+  bool interactive = false;
+  QString data_directory;
+  QString filename = "HeadMRVolume.mhd";
+
+  // Command line parser
+  ctkCommandLineParser parser;
+  parser.addBooleanArgument(0, "-I", &interactive);
+  parser.addStringArgument(0, "-D", &data_directory);
+  if (!parser.parseArguments(app.arguments()))
+    {
+    std::cerr << qPrintable(parser.errorString()) << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  QString imageFilename = data_directory + "/" + filename;
+
+  // Instanciate the reader factory
+  vtkSmartPointer<vtkImageReader2Factory> imageFactory =
+      vtkSmartPointer<vtkImageReader2Factory>::New();
+
+  // Instanciate an image reader
+  vtkSmartPointer<vtkImageReader2> imageReader;
+  imageReader.TakeReference(imageFactory->CreateImageReader2(imageFilename.toLatin1()));
+  if (!imageReader)
+    {
+    std::cerr << "Failed to instanciate image reader using: " 
+              << qPrintable(imageFilename) << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  // Read image
+  imageReader->SetFileName(imageFilename.toLatin1());
+  imageReader->Update();
+  vtkSmartPointer<vtkImageData> image = imageReader->GetOutput();
+
+  ctkVTKSliceView sliceView;
+  sliceView.resize(300, 300);
+  sliceView.setImageData(image);
+  sliceView.setRenderWindowLayout(4, 4);
+  sliceView.setHighlighted(0, 0, true);
+  sliceView.setCornerAnnotationText("CTK");
+  sliceView.scheduleRender();
+  sliceView.show();
+
+  if (!interactive)
+    {
+    QTimer::singleShot(1000, &app, SLOT(quit()));
+    }
+  return app.exec();
+}