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 <mitkPicFileReader.h> 00022 #include <mitkStandaloneDataStorage.h> 00023 00024 #include <itksys/SystemTools.hxx> 00025 #include <QApplication> 00026 00027 //##Documentation 00028 //## @brief Load image (pic format) and display it in a 2D view 00029 int main(int argc, char* argv[]) 00030 { 00031 QApplication qtapplication( argc, argv ); 00032 00033 if (argc < 2) 00034 { 00035 fprintf( stderr, "Usage: %s [filename] \n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str() ); 00036 return 1; 00037 } 00038 00039 // Register Qmitk-dependent global instances 00040 QmitkRegisterClasses(); 00041 00042 //************************************************************************* 00043 // Part I: Basic initialization 00044 //************************************************************************* 00045 00046 // Create a DataStorage 00047 // The DataStorage manages all data objects. It is used by the 00048 // rendering mechanism to render all data objects 00049 // We use the standard implementation mitk::StandaloneDataStorage. 00050 mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); 00051 00052 00053 //************************************************************************* 00054 // Part II: Create some data by reading a file 00055 //************************************************************************* 00056 00057 // Create a PicFileReader to read a .pic-file 00058 mitk::PicFileReader::Pointer reader = mitk::PicFileReader::New(); 00059 const char * filename = argv[1]; 00060 try 00061 { 00062 reader->SetFileName(filename); 00063 reader->Update(); 00064 } 00065 catch(...) 00066 { 00067 fprintf( stderr, "Could not open file %s \n\n", filename ); 00068 exit(2); 00069 } 00070 00071 //************************************************************************* 00072 // Part III: Put the data into the datastorage 00073 //************************************************************************* 00074 00075 // Create a node and add the Image (which is read from the file) to it 00076 mitk::DataNode::Pointer node = mitk::DataNode::New(); 00077 node->SetData(reader->GetOutput()); 00078 00079 // Add the node to the DataStorage 00080 ds->Add(node); 00081 00082 00083 //************************************************************************* 00084 // Part IV: Create window and pass the datastorage to it 00085 //************************************************************************* 00086 00087 // Create a RenderWindow 00088 QmitkRenderWindow renderWindow; 00089 00090 // Tell the RenderWindow which (part of) the datastorage to render 00091 renderWindow.GetRenderer()->SetDataStorage(ds); 00092 00093 // Initialize the RenderWindow 00094 mitk::TimeSlicedGeometry::Pointer geo = ds->ComputeBoundingGeometry3D(ds->GetAll()); 00095 mitk::RenderingManager::GetInstance()->InitializeViews( geo ); 00096 //mitk::RenderingManager::GetInstance()->InitializeViews(); 00097 00098 // Select a slice 00099 mitk::SliceNavigationController::Pointer sliceNaviController = renderWindow.GetSliceNavigationController(); 00100 if (sliceNaviController) 00101 sliceNaviController->GetSlice()->SetPos( 0 ); 00102 00103 //************************************************************************* 00104 // Part V: Qt-specific initialization 00105 //************************************************************************* 00106 renderWindow.show(); 00107 renderWindow.resize( 256, 256 ); 00108 00109 // for testing 00110 #include "QtTesting.h" 00111 if (strcmp(argv[argc-1], "-testing") != 0) 00112 return qtapplication.exec(); 00113 else 00114 return QtTesting(); 00115 00116 // cleanup: Remove References to node and DataStorage. This will delete the two objects 00117 node = NULL; 00118 ds = NULL; 00119 }