00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "QmitkRegisterClasses.h" 00019 #include "QmitkRenderWindow.h" 00020 00021 #include <mitkDataNodeFactory.h> 00022 #include <mitkStandaloneDataStorage.h> 00023 00024 #include <itksys/SystemTools.hxx> 00025 #include <QApplication> 00026 00027 //##Documentation 00028 //## @brief Load one or more data sets (many image, surface 00029 //## and other formats) and display it in a 2D view 00030 //## 00031 //## Only very slightly different to Step1: Use DataNodeFactory 00032 //## instead of PicFileReader, and read more than one data set. 00033 int main(int argc, char* argv[]) 00034 { 00035 QApplication qtapplication( argc, argv ); 00036 00037 if(argc<2) 00038 { 00039 fprintf( stderr, "Usage: %s [filename1] [filename2] ...\n\n", 00040 itksys::SystemTools::GetFilenameName(argv[0]).c_str() ); 00041 return 1; 00042 } 00043 00044 // Register Qmitk-dependent global instances 00045 QmitkRegisterClasses(); 00046 00047 //************************************************************************* 00048 // Part I: Basic initialization 00049 //************************************************************************* 00050 00051 // Create a data storage object. We will use it as a singleton 00052 mitk::StandaloneDataStorage::Pointer storage = mitk::StandaloneDataStorage::New(); 00053 00054 //************************************************************************* 00055 // Part II: Create some data by reading files 00056 //************************************************************************* 00057 int i; 00058 for(i=1; i<argc; ++i) 00059 { 00060 // For testing 00061 if(strcmp(argv[i], "-testing")==0) continue; 00062 00063 // Create a DataNodeFactory to read a data format supported 00064 // by the DataNodeFactory (many image formats, surface formats, etc.) 00065 mitk::DataNodeFactory::Pointer nodeReader=mitk::DataNodeFactory::New(); 00066 const char * filename = argv[i]; 00067 try 00068 { 00069 nodeReader->SetFileName(filename); 00070 nodeReader->Update(); 00071 //********************************************************************* 00072 // Part III: Put the data into the datastorage 00073 //********************************************************************* 00074 00075 // Since the DataNodeFactory directly creates a node, 00076 // use the datastorage to add the read node 00077 storage->Add(nodeReader->GetOutput()); 00078 } 00079 catch(...) 00080 { 00081 fprintf( stderr, "Could not open file %s \n\n", filename ); 00082 exit(2); 00083 } 00084 } 00085 00086 //************************************************************************* 00087 // Part IV: Create window and pass the datastorage to it 00088 //************************************************************************* 00089 00090 // Create a RenderWindow 00091 QmitkRenderWindow renderWindow; 00092 00093 // Tell the RenderWindow which (part of) the datastorage to render 00094 renderWindow.GetRenderer()->SetDataStorage(storage); 00095 00096 // Initialize the RenderWindow 00097 mitk::TimeSlicedGeometry::Pointer geo = storage->ComputeBoundingGeometry3D(storage->GetAll()); 00098 mitk::RenderingManager::GetInstance()->InitializeViews( geo ); 00099 00100 // Select a slice 00101 mitk::SliceNavigationController::Pointer sliceNaviController = renderWindow.GetSliceNavigationController(); 00102 if (sliceNaviController) 00103 sliceNaviController->GetSlice()->SetPos( 2 ); 00104 00105 00106 //************************************************************************* 00107 // Part V: Qt-specific initialization 00108 //************************************************************************* 00109 renderWindow.show(); 00110 renderWindow.resize( 256, 256 ); 00111 00112 // for testing 00113 #include "QtTesting.h" 00114 if(strcmp(argv[argc-1], "-testing")!=0) 00115 return qtapplication.exec(); 00116 else 00117 return QtTesting(); 00118 } 00119