19 #include <itkImageRegionConstIterator.h>
23 template <
typename TPixel,
unsigned int VImageDimension>
26 itk::ImageRegionConstIterator<itk::Image<TPixel, VImageDimension>> imageIt(itkImage,
27 itkImage->GetLargestPossibleRegion());
28 unsigned long int count = 0;
30 for (imageIt.GoToBegin(); !imageIt.IsAtEnd(); ++imageIt)
37 if (itkImage->GetLargestPossibleRegion().GetImageDimension() == 3)
39 m_Volume = count / 1000.0 * itkImage->GetSpacing()[0] * itkImage->GetSpacing()[1] * itkImage->GetSpacing()[2];
41 else if (itkImage->GetLargestPossibleRegion().GetImageDimension() == 2)
43 m_Volume = count / 100.0 * itkImage->GetSpacing()[0] * itkImage->GetSpacing()[1];
64 const_cast<Image *
>(m_Image.GetPointer())->SetRequestedRegionToLargestPossibleRegion();
65 if (m_Image->GetDimension() == 4)
67 m_TimeSelector->SetInput(m_Image);
68 m_Volumes.resize(m_Image->GetDimension(3));
69 for (
unsigned int timeStep = 0; timeStep < m_Image->GetDimension(3); ++timeStep)
71 m_TimeSelector->SetTimeNr(timeStep);
72 m_TimeSelector->Update();
74 m_Volumes[timeStep] = m_Volume;
77 else if (m_Image->GetDimension() == 3)
79 const_cast<Image *
>(m_Image.GetPointer())->
Update();
82 else if (m_Image->GetDimension() == 2)
84 const_cast<Image *
>(m_Image.GetPointer())->
Update();
91 unsigned int dim = m_Image->GetDimension();
95 m_Volumes.resize(m_Image->GetDimension(3), 0);
96 Vector3D spacing = m_Image->GetSlicedGeometry()->GetSpacing();
98 for (
unsigned int t = 0; t < m_Image->GetDimension(3); ++t)
101 m_Image->GetStatistics()->GetCountOfMaxValuedVoxels(t) / 1000.0 * spacing[0] * spacing[1] * spacing[2];
106 Vector3D spacing = m_Image->GetSlicedGeometry()->GetSpacing();
107 m_Volume = m_Image->GetStatistics()->GetCountOfMaxValuedVoxels() / 1000.0 * spacing[0] * spacing[1] * spacing[2];
111 Vector3D spacing = m_Image->GetGeometry()->GetSpacing();
112 m_Volume = m_Image->GetStatistics()->GetCountOfMaxValuedVoxels() / 100.0 * spacing[0] * spacing[1];
115 itkExceptionMacro(<<
"Wrong image dimension...");
120 return (voxelCount / 1000.0 * spacing[0] * spacing[1] * spacing[2]);
ImageTimeSelector::Pointer m_TimeSelector
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
static void Update(vtkPolyData *)
virtual ~VolumeCalculator()
void InternalCompute(itk::Image< TPixel, VImageDimension > *itkImage, const mitk::HistogramGenerator *mitkHistoGenerator, mitk::HistogramGenerator::HistogramType::ConstPointer &histogram)
Image class for storing images.
void InternalCompute(const itk::Image< TPixel, VImageDimension > *itkImage)
unsigned long int m_VoxelCount
std::vector< float > GetVolumes()
void ComputeVolumeFromImageStatistics()