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 #include "QmitkSliceWidget.h" 00021 00022 #include "mitkDataNodeFactory.h" 00023 #include "mitkProperties.h" 00024 #include "mitkRenderingManager.h" 00025 #include "mitkStandaloneDataStorage.h" 00026 00027 #include <itksys/SystemTools.hxx> 00028 #include <QApplication> 00029 #include <QHBoxLayout> 00030 00031 //##Documentation 00032 //## @brief Use several views to explore data 00033 //## 00034 //## As in Step2 and Step3, load one or more data sets (many image, 00035 //## surface and other formats), but create 3 views on the data. 00036 //## The QmitkRenderWindow is used for displaying a 3D view as in Step3, 00037 //## but without volume-rendering. 00038 //## Furthermore, we create two 2D views for slicing through the data. 00039 //## We use the class QmitkSliceWidget, which is based on the class 00040 //## QmitkRenderWindow, but additionally provides sliders 00041 //## to slice through the data. We create two instances of 00042 //## QmitkSliceWidget, one for transversal and one for sagittal slicing. 00043 //## The two slices are also shown at their correct position in 3D as 00044 //## well as intersection-line, each in the other 2D view. 00045 int main(int argc, char* argv[]) 00046 { 00047 QApplication qtapplication( argc, argv ); 00048 00049 if(argc<2) 00050 { 00051 fprintf( stderr, "Usage: %s [filename1] [filename2] ...\n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str() ); 00052 return 1; 00053 } 00054 00055 // Register Qmitk-dependent global instances 00056 QmitkRegisterClasses(); 00057 00058 //************************************************************************* 00059 // Part I: Basic initialization 00060 //************************************************************************* 00061 00062 // Create a DataStorage 00063 mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); 00064 00065 00066 //************************************************************************* 00067 // Part II: Create some data by reading files 00068 //************************************************************************* 00069 int i; 00070 for(i=1; i<argc; ++i) 00071 { 00072 // For testing 00073 if(strcmp(argv[i], "-testing")==0) continue; 00074 00075 // Create a DataNodeFactory to read a data format supported 00076 // by the DataNodeFactory (many image formats, surface formats, etc.) 00077 mitk::DataNodeFactory::Pointer nodeReader=mitk::DataNodeFactory::New(); 00078 const char * filename = argv[i]; 00079 try 00080 { 00081 nodeReader->SetFileName(filename); 00082 nodeReader->Update(); 00083 //********************************************************************* 00084 //Part III: Put the data into the datastorage 00085 //********************************************************************* 00086 00087 // Since the DataNodeFactory directly creates a node, 00088 // use the datastorage to add the read node 00089 mitk::DataNode::Pointer node = nodeReader->GetOutput(); 00090 ds->Add(node); 00091 } 00092 catch(...) 00093 { 00094 fprintf( stderr, "Could not open file %s \n\n", filename ); 00095 exit(2); 00096 } 00097 } 00098 00099 //************************************************************************* 00100 // Part IV: Create windows and pass the tree to it 00101 //************************************************************************* 00102 00103 // Create toplevel widget with horizontal layout 00104 QWidget toplevelWidget; 00105 QHBoxLayout layout; 00106 layout.setSpacing(2); 00107 layout.setMargin(0); 00108 toplevelWidget.setLayout(&layout); 00109 00110 //************************************************************************* 00111 // Part IVa: 3D view 00112 //************************************************************************* 00113 00114 // Create a renderwindow 00115 QmitkRenderWindow renderWindow(&toplevelWidget); 00116 layout.addWidget(&renderWindow); 00117 00118 // Tell the renderwindow which (part of) the datastorage to render 00119 renderWindow.GetRenderer()->SetDataStorage(ds); 00120 00121 // Use it as a 3D view 00122 renderWindow.GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D); 00123 00124 // ******************************************************* 00125 // ****************** START OF NEW PART ****************** 00126 // ******************************************************* 00127 00128 //************************************************************************* 00129 // Part IVb: 2D view for slicing transversally 00130 //************************************************************************* 00131 00132 // Create QmitkSliceWidget, which is based on the class 00133 // QmitkRenderWindow, but additionally provides sliders 00134 QmitkSliceWidget view2(&toplevelWidget); 00135 layout.addWidget(&view2); 00136 view2.SetLevelWindowEnabled(true); 00137 // Tell the QmitkSliceWidget which (part of) the tree to render. 00138 // By default, it slices the data transversally 00139 view2.SetDataStorage(ds); 00140 mitk::DataStorage::SetOfObjects::ConstPointer rs = ds->GetAll(); 00141 view2.SetData(rs->Begin(),mitk::SliceNavigationController::Transversal); 00142 // We want to see the position of the slice in 2D and the 00143 // slice itself in 3D: add it to the datastorage! 00144 ds->Add(view2.GetRenderer()->GetCurrentWorldGeometry2DNode()); 00145 00146 //************************************************************************* 00147 // Part IVc: 2D view for slicing sagitally 00148 //************************************************************************* 00149 00150 // Create QmitkSliceWidget, which is based on the class 00151 // QmitkRenderWindow, but additionally provides sliders 00152 QmitkSliceWidget view3(&toplevelWidget); 00153 layout.addWidget(&view3); 00154 view3.SetDataStorage(ds); 00155 // Tell the QmitkSliceWidget which (part of) the datastorage to render 00156 // and to slice sagitally 00157 view3.SetData(rs->Begin(), mitk::SliceNavigationController::Sagittal); 00158 // We want to see the position of the slice in 2D and the 00159 // slice itself in 3D: add it to the datastorage! 00160 ds->Add(view3.GetRenderer()->GetCurrentWorldGeometry2DNode()); 00161 00162 // ******************************************************* 00163 // ******************* END OF NEW PART ******************* 00164 // ******************************************************* 00165 00166 //************************************************************************* 00167 // Part V: Qt-specific initialization 00168 //************************************************************************* 00169 toplevelWidget.show(); 00170 00171 // for testing 00172 #include "QtTesting.h" 00173 if(strcmp(argv[argc-1], "-testing")!=0) 00174 return qtapplication.exec(); 00175 else 00176 return QtTesting(); 00177 } 00178