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 #include <mitkProperties.h> 00024 #include <mitkTransferFunction.h> 00025 #include <mitkTransferFunctionProperty.h> 00026 #include <mitkRenderingManager.h> 00027 00028 #include <itksys/SystemTools.hxx> 00029 00030 #include <QApplication> 00031 00032 00033 //##Documentation 00034 //## @brief Change the type of display to 3D 00035 //## 00036 //## As in Step2, load one or more data sets (many image, surface 00037 //## and other formats), but display it in a 3D view. 00038 //## The QmitkRenderWindow is now used for displaying a 3D view, by 00039 //## setting the used mapper-slot to Standard3D. 00040 //## Since volume-rendering is a (rather) slow procedure, the default 00041 //## is that images are not displayed in the 3D view. For this example, 00042 //## we want volume-rendering, thus we switch it on by setting 00043 //## the Boolean-property "volumerendering" to "true". 00044 int main(int argc, char* argv[]) 00045 { 00046 QApplication qtapplication( argc, argv ); 00047 if(argc<2) 00048 { 00049 fprintf( stderr, "Usage: %s [filename1] [filename2] ...\n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str() ); 00050 return 1; 00051 } 00052 00053 // Register Qmitk-dependent global instances 00054 QmitkRegisterClasses(); 00055 00056 //************************************************************************* 00057 // Part I: Basic initialization 00058 //************************************************************************* 00059 00060 // Create a DataStorage 00061 mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); 00062 00063 //************************************************************************* 00064 // Part II: Create some data by reading files 00065 //************************************************************************* 00066 int i; 00067 for(i=1; i<argc; ++i) 00068 { 00069 // For testing 00070 if(strcmp(argv[i], "-testing")==0) continue; 00071 00072 // Create a DataNodeFactory to read a data format supported 00073 // by the DataNodeFactory (many image formats, surface formats, etc.) 00074 mitk::DataNodeFactory::Pointer nodeReader=mitk::DataNodeFactory::New(); 00075 const char * filename = argv[i]; 00076 try 00077 { 00078 nodeReader->SetFileName(filename); 00079 nodeReader->Update(); 00080 00081 //********************************************************************* 00082 // Part III: Put the data into the datastorage 00083 //********************************************************************* 00084 00085 // Since the DataNodeFactory directly creates a node, 00086 // use the datastorage to add the read node 00087 mitk::DataNode::Pointer node = nodeReader->GetOutput(); 00088 ds->Add(node); 00089 00090 // ********************************************************* 00091 // ****************** START OF NEW PART 1 ****************** 00092 // ********************************************************* 00093 00094 //********************************************************************* 00095 // Part IV: We want all images to be volume-rendered 00096 //********************************************************************* 00097 00098 // Check if the data is an image by dynamic_cast-ing the data 00099 // contained in the node. Warning: dynamic_cast's are rather slow, 00100 // do not use it too often! 00101 mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(node->GetData()); 00102 if(image.IsNotNull()) 00103 { 00104 // Set the property "volumerendering" to the Boolean value "true" 00105 node->SetProperty("volumerendering", mitk::BoolProperty::New(true)); 00106 00107 // Create a transfer function to assign optical properties (color and opacity) to grey-values of the data 00108 mitk::TransferFunction::Pointer tf = mitk::TransferFunction::New(); 00109 tf->InitializeByMitkImage ( image ); 00110 00111 // Set the color transfer function AddRGBPoint(double x, double r, double g, double b) 00112 tf->GetColorTransferFunction()->AddRGBPoint ( tf->GetColorTransferFunction()->GetRange() [0], 1.0, 0.0, 0.0 ); 00113 tf->GetColorTransferFunction()->AddRGBPoint ( tf->GetColorTransferFunction()->GetRange() [1], 1.0, 1.0, 0.0 ); 00114 00115 // Set the piecewise opacity transfer function AddPoint(double x, double y) 00116 tf->GetScalarOpacityFunction()->AddPoint ( 0, 0 ); 00117 tf->GetScalarOpacityFunction()->AddPoint ( tf->GetColorTransferFunction()->GetRange() [1], 1 ); 00118 00119 node->SetProperty ( "TransferFunction", mitk::TransferFunctionProperty::New ( tf.GetPointer() ) ); 00120 } 00121 00122 00123 // ********************************************************* 00124 // ******************* END OF NEW PART 1 ******************* 00125 // ********************************************************* 00126 } 00127 catch(...) 00128 { 00129 fprintf( stderr, "Could not open file %s \n\n", filename ); 00130 exit(2); 00131 } 00132 } 00133 00134 //************************************************************************* 00135 // Part V: Create window and pass the tree to it 00136 //************************************************************************* 00137 00138 // Create a renderwindow 00139 QmitkRenderWindow renderWindow; 00140 00141 // Tell the renderwindow which (part of) the datastorage to render 00142 renderWindow.GetRenderer()->SetDataStorage(ds); 00143 00144 // ********************************************************* 00145 // ****************** START OF NEW PART 2 ****************** 00146 // ********************************************************* 00147 // Use it as a 3D view! 00148 renderWindow.GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D); 00149 00150 // ********************************************************* 00151 // ******************* END OF NEW PART 2 ******************* 00152 // ********************************************************* 00153 00154 //************************************************************************* 00155 // Part VI: Qt-specific initialization 00156 //************************************************************************* 00157 renderWindow.show(); 00158 renderWindow.resize( 256, 256 ); 00159 00160 mitk::RenderingManager::GetInstance()->RequestUpdateAll(); 00161 00162 // for testing 00163 #include "QtTesting.h" 00164 if(strcmp(argv[argc-1], "-testing")!=0) 00165 return qtapplication.exec(); 00166 else 00167 return QtTesting(); 00168 } 00169