Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkCalculateSegmentationVolume.h"
00019 #include "itkImageRegionConstIteratorWithIndex.h"
00020
00021 #include <limits>
00022
00023 namespace mitk
00024 {
00025
00026 CalculateSegmentationVolume::CalculateSegmentationVolume()
00027 {
00028 }
00029
00030
00031 CalculateSegmentationVolume::~CalculateSegmentationVolume()
00032 {
00033 }
00034
00035
00036 template < typename TPixel, unsigned int VImageDimension >
00037 void CalculateSegmentationVolume::ItkImageProcessing( itk::Image< TPixel, VImageDimension >* itkImage, TPixel* itkNotUsed(dummy) )
00038 {
00039 itk::ImageRegionConstIteratorWithIndex<itk::Image<TPixel, VImageDimension> > iterBinaryImage( itkImage, itkImage->GetLargestPossibleRegion() );
00040 typename itk::ImageRegionConstIteratorWithIndex<itk::Image<TPixel, VImageDimension> >::IndexType currentIndex;
00041 typename itk::ImageRegionConstIteratorWithIndex<itk::Image<TPixel, VImageDimension> >::IndexType minIndex;
00042 for (unsigned int i = 0; i < VImageDimension; ++i) minIndex[i] = std::numeric_limits<long int>::max();
00043
00044 typename itk::ImageRegionConstIteratorWithIndex<itk::Image<TPixel, VImageDimension> >::IndexType maxIndex;
00045 for (unsigned int i = 0; i < VImageDimension; ++i) maxIndex[i] = std::numeric_limits<long int>::min();
00046
00047 m_CenterOfMass.Fill(0.0);
00048
00049 m_Volume = 0;
00050 while (!iterBinaryImage.IsAtEnd())
00051 {
00052 if ( iterBinaryImage.Get() > static_cast<TPixel>(0.0) )
00053 {
00054
00055 currentIndex = iterBinaryImage.GetIndex();
00056 itk::Vector<float, VImageDimension> currentPoint;
00057 for (unsigned int i = 0; i < VImageDimension; ++i) currentPoint[i] = currentIndex[i];
00058
00059 m_CenterOfMass = (m_CenterOfMass * ( static_cast<float>(m_Volume) / static_cast<float>(m_Volume+1) ) )
00060 + currentPoint / static_cast<float>(m_Volume+1);
00061
00062
00063 ++m_Volume;
00064
00065
00066 for (unsigned int i = 0; i < VImageDimension; ++i)
00067 {
00068 if (currentIndex[i] < minIndex[i]) minIndex[i] = currentIndex[i];
00069 if (currentIndex[i] > maxIndex[i]) maxIndex[i] = currentIndex[i];
00070 }
00071 }
00072
00073 ++iterBinaryImage;
00074 }
00075
00076 m_MinIndexOfBoundingBox[2] = 0.0;
00077 m_MaxIndexOfBoundingBox[2] = 0.0;
00078 for (unsigned int i = 0; i < VImageDimension; ++i)
00079 {
00080 m_MinIndexOfBoundingBox[i] = minIndex[i];
00081 m_MaxIndexOfBoundingBox[i] = maxIndex[i];
00082 }
00083 }
00084
00085
00086 bool CalculateSegmentationVolume::ReadyToRun()
00087 {
00088 Image::Pointer image;
00089 GetPointerParameter("Input", image);
00090
00091 return image.IsNotNull() && GetGroupNode();
00092 }
00093
00094
00095 bool CalculateSegmentationVolume::ThreadedUpdateFunction()
00096 {
00097
00098 Image::Pointer image;
00099 GetPointerParameter("Input", image);
00100
00101 AccessFixedDimensionByItk( image.GetPointer(), ItkImageProcessing, 3 );
00102
00103
00104 Vector3D spacing = image->GetSlicedGeometry()->GetSpacing();
00105 float volumeML = (ScalarType) m_Volume * spacing[0] * spacing[1] * spacing[2] / 1000.0;
00106
00107 DataNode* groupNode = GetGroupNode();
00108 if (groupNode)
00109 {
00110 groupNode->SetProperty( "volume", FloatProperty::New(volumeML) );
00111 groupNode->SetProperty( "centerOfMass", Vector3DProperty::New(m_CenterOfMass) );
00112 groupNode->SetProperty( "boundingBoxMinimum", Vector3DProperty::New(m_MinIndexOfBoundingBox) );
00113 groupNode->SetProperty( "boundingBoxMaximum", Vector3DProperty::New(m_MaxIndexOfBoundingBox) );
00114 groupNode->SetProperty( "showVolume", BoolProperty::New(true) );
00115 }
00116
00117 return true;
00118 }
00119
00120
00121 }
00122
00123