00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision: 1.12 $ 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 "mitkCalculateVolumetryTool.h" 00019 00020 #include "mitkCalculateVolumetryTool.xpm" 00021 00022 #include "mitkVolumeCalculator.h" 00023 #include "mitkProperties.h" 00024 #include "mitkToolManager.h" 00025 00026 namespace mitk { 00027 MITK_TOOL_MACRO(MitkExt_EXPORT, CalculateVolumetryTool, "Volumetry tool"); 00028 } 00029 00030 mitk::CalculateVolumetryTool::CalculateVolumetryTool() 00031 { 00032 } 00033 00034 mitk::CalculateVolumetryTool::~CalculateVolumetryTool() 00035 { 00036 } 00037 00038 const char** mitk::CalculateVolumetryTool::GetXPM() const 00039 { 00040 return mitkCalculateVolumetryTool_xpm; 00041 } 00042 00043 const char* mitk::CalculateVolumetryTool::GetName() const 00044 { 00045 return "Volumetry"; 00046 } 00047 00048 std::string mitk::CalculateVolumetryTool::GetErrorMessage() 00049 { 00050 return "Volume could not be calculated for these nodes:"; 00051 } 00052 00053 bool mitk::CalculateVolumetryTool::ProcessOneWorkingData( DataNode* node ) 00054 { 00055 if (node) 00056 { 00057 Image::Pointer image = dynamic_cast<Image*>( node->GetData() ); 00058 if (image.IsNull()) return false; 00059 00060 if (image->GetDimension() == 4) 00061 { 00062 Tool::ErrorMessage("Volumetry only valid for timestep 0! Bug #1280"); 00063 } 00064 00065 VolumeCalculator::Pointer volumetryFilter = VolumeCalculator::New(); 00066 volumetryFilter->SetImage( image ); 00067 volumetryFilter->SetThreshold( 1 ); // comparison is >= 00068 try 00069 { 00070 volumetryFilter->ComputeVolume(); 00071 00072 float volumeInTimeStep0 = volumetryFilter->GetVolume(); 00073 00074 node->SetProperty( "volume", FloatProperty::New(volumeInTimeStep0) ); 00075 } 00076 catch(...) 00077 { 00078 return false; 00079 } 00080 } 00081 00082 return true; 00083 } 00084 00085 void mitk::CalculateVolumetryTool::FinishProcessingAllData() 00086 { 00087 Superclass::FinishProcessingAllData(); 00088 m_ToolManager->NodePropertiesChanged(); 00089 } 00090