00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date: 2010-04-07 16:36:18 +0200 (Mi, 07 Apr 2010) $ 00006 Version: $Revision: 22088 $ 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 <mitkSTLFileReader.h> 00022 #include <mitkSurface.h> 00023 #include <mitkStandaloneDataStorage.h> 00024 00025 #include <itksys/SystemTools.hxx> 00026 #include <QApplication> 00027 00028 //for the interaction 00029 #include <mitkMoveSurfaceInteractor.h> 00030 #include "mitkGlobalInteraction.h" 00031 00032 //##Documentation 00033 //## @brief Load two or more surfaces (stl format, see e.g. Core/Code/Testing/data directory for binary.stl) and display it in a 3D view. 00034 //## The MoveSurfaceInteractor explained in tutorial Step10.dox is used to move the surfaces in 3D by arrow keys in combination 00035 //## with and without Shift key. Use two surfaces to see that the objects and not the camera are moving. 00036 int main(int argc, char* argv[]) 00037 { 00038 QApplication qtapplication( argc, argv ); 00039 00040 if (argc < 2) 00041 { 00042 fprintf( stderr, "Usage: %s [filename_1] ... [filename_n] \n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str() ); 00043 return 1; 00044 } 00045 00046 // Register Qmitk-dependent global instances 00047 QmitkRegisterClasses(); 00048 00049 //************************************************************************* 00050 // Part I: Basic initialization 00051 //************************************************************************* 00052 00053 // Create a DataStorage 00054 // The DataStorage manages all data objects. It is used by the 00055 // rendering mechanism to render all data objects 00056 // We use the standard implementation mitk::StandaloneDataStorage. 00057 00058 mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); 00059 00060 00061 //************************************************************************* 00062 // Part II: Create surface data by reading an stl file 00063 //************************************************************************* 00064 00065 for(int i=1; i<argc; ++i) 00066 { 00067 // For testing 00068 if(strcmp(argv[i], "-testing")==0) continue; 00069 00070 // Create a STLFileReader to read a .stl-file 00071 mitk::STLFileReader::Pointer reader = mitk::STLFileReader::New(); 00072 const char * filename = argv[i]; 00073 try 00074 { 00075 reader->SetFileName(filename); 00076 reader->Update(); 00077 } 00078 catch(...) 00079 { 00080 fprintf( stderr, "Could not open file %s \n\n", filename ); 00081 exit(2); 00082 } 00083 00084 //************************************************************************* 00085 // Part III: Put the data into the datastorage 00086 //************************************************************************* 00087 00088 // Create a node and add the Image (which is read from the file) to it 00089 mitk::DataNode::Pointer node = mitk::DataNode::New(); 00090 node->SetData(reader->GetOutput()); 00091 00092 // ******************************************************* 00093 // ****************** START OF NEW PART ****************** 00094 // ******************************************************* 00095 00096 // create interactor 00097 // use it with up, down (->z direction), left and right (x-direction) arrow keys. Also hold Shift to translate in y direction. 00098 // see state machine pattern SelectAndMoveObjectWithArrowKeys in file StateMachine.xml for definition of interaction or use the StatemachineEditor. 00099 mitk::MoveSurfaceInteractor::Pointer surfaceInteractor = 00100 mitk::MoveSurfaceInteractor::New("SelectAndMoveObjectWithArrowKeys",node); 00101 00102 //activate interactor at interaction controller: 00103 mitk::GlobalInteraction::GetInstance()->AddInteractor(surfaceInteractor); 00104 00105 // ******************************************************* 00106 // ******************* END OF NEW PART ******************* 00107 // ******************************************************* 00108 00109 // Add the node to the DataStorage 00110 ds->Add(node); 00111 00112 //doesn't have to be done, but nicer! Is destroyed when leaving the sccope anyway 00113 reader = NULL; 00114 surfaceInteractor = NULL; 00115 } 00116 00117 //************************************************************************* 00118 // Part IV: Create window and pass the datastorage to it 00119 //************************************************************************* 00120 00121 // Create a RenderWindow 00122 QmitkRenderWindow renderWindow; 00123 00124 // Tell the RenderWindow which (part of) the datastorage to render 00125 renderWindow.GetRenderer()->SetDataStorage(ds); 00126 00127 // Use it as a 3D view 00128 renderWindow.GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D); 00129 00130 // Initialize the RenderWindow 00131 mitk::TimeSlicedGeometry::Pointer geo = ds->ComputeBoundingGeometry3D(ds->GetAll()); 00132 mitk::RenderingManager::GetInstance()->InitializeViews( geo ); 00133 00134 //************************************************************************* 00135 // Part V: Qt-specific initialization 00136 //************************************************************************* 00137 renderWindow.show(); 00138 renderWindow.resize( 256, 256 ); 00139 00140 MITK_INFO<<"Select an object with a mouse click. Use arrow keys (also with shift-key) to move the surface.\n"; 00141 MITK_INFO<<"Deselecting and selecting an other surface by clicking onto it. Selected surfaces turn yellow, deselected blue.\n"; 00142 00143 // for testing 00144 #include "QtTesting.h" 00145 if (strcmp(argv[argc-1], "-testing") != 0) 00146 return qtapplication.exec(); 00147 else 00148 return QtTesting(); 00149 00150 // cleanup: Remove References 00151 ds = NULL; 00152 }