Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkVolumeCalculator.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkVolumeCalculator.h"
14 #include "mitkImageAccessByItk.h"
15 #include <itkImageRegionConstIterator.h>
16 
18 
19 template <typename TPixel, unsigned int VImageDimension>
20 void mitk::VolumeCalculator::InternalCompute(const itk::Image<TPixel, VImageDimension> *itkImage)
21 {
22  itk::ImageRegionConstIterator<itk::Image<TPixel, VImageDimension>> imageIt(itkImage,
23  itkImage->GetLargestPossibleRegion());
24  unsigned long int count = 0;
25 
26  for (imageIt.GoToBegin(); !imageIt.IsAtEnd(); ++imageIt)
27  {
28  if ((int)(imageIt.Get()) >= m_Threshold)
29  {
30  count++;
31  }
32  }
33  if (itkImage->GetLargestPossibleRegion().GetImageDimension() == 3)
34  {
35  m_Volume = count / 1000.0 * itkImage->GetSpacing()[0] * itkImage->GetSpacing()[1] * itkImage->GetSpacing()[2];
36  }
37  else if (itkImage->GetLargestPossibleRegion().GetImageDimension() == 2)
38  {
39  m_Volume = count / 100.0 * itkImage->GetSpacing()[0] * itkImage->GetSpacing()[1];
40  }
41  m_VoxelCount = count;
42 }
43 
45 {
47 }
48 
50 {
51 }
52 
54 {
55  return m_Volumes;
56 }
57 
59 {
60  const_cast<Image *>(m_Image.GetPointer())->SetRequestedRegionToLargestPossibleRegion();
61  if (m_Image->GetDimension() == 4)
62  {
63  m_TimeSelector->SetInput(m_Image);
64  m_Volumes.resize(m_Image->GetDimension(3));
65  for (unsigned int timeStep = 0; timeStep < m_Image->GetDimension(3); ++timeStep)
66  {
67  m_TimeSelector->SetTimeNr(timeStep);
68  m_TimeSelector->Update();
70  m_Volumes[timeStep] = m_Volume;
71  }
72  }
73  else if (m_Image->GetDimension() == 3)
74  {
75  const_cast<Image *>(m_Image.GetPointer())->Update();
77  }
78  else if (m_Image->GetDimension() == 2)
79  {
80  const_cast<Image *>(m_Image.GetPointer())->Update();
82  }
83 }
84 
86 {
87  unsigned int dim = m_Image->GetDimension();
88 
89  if (dim == 4)
90  {
91  m_Volumes.resize(m_Image->GetDimension(3), 0);
92  Vector3D spacing = m_Image->GetSlicedGeometry()->GetSpacing();
93 
94  for (unsigned int t = 0; t < m_Image->GetDimension(3); ++t)
95  {
96  m_Volumes[t] =
97  m_Image->GetStatistics()->GetCountOfMaxValuedVoxels(t) / 1000.0 * spacing[0] * spacing[1] * spacing[2];
98  }
99  }
100  else if (dim == 3)
101  {
102  Vector3D spacing = m_Image->GetSlicedGeometry()->GetSpacing();
103  m_Volume = m_Image->GetStatistics()->GetCountOfMaxValuedVoxels() / 1000.0 * spacing[0] * spacing[1] * spacing[2];
104  }
105  else if (dim == 2)
106  {
107  Vector3D spacing = m_Image->GetGeometry()->GetSpacing();
108  m_Volume = m_Image->GetStatistics()->GetCountOfMaxValuedVoxels() / 100.0 * spacing[0] * spacing[1];
109  }
110  else
111  itkExceptionMacro(<< "Wrong image dimension...");
112 }
113 
114 float mitk::VolumeCalculator::ComputeVolume(Vector3D spacing, unsigned int voxelCount)
115 {
116  return (voxelCount / 1000.0 * spacing[0] * spacing[1] * spacing[2]);
117 }
ImageTimeSelector::Pointer m_TimeSelector
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
static void Update(vtkPolyData *)
Definition: mitkSurface.cpp:31
Image::ConstPointer m_Image
std::vector< float > m_Volumes
Image class for storing images.
Definition: mitkImage.h:72
void InternalCompute(const itk::Image< TPixel, VImageDimension > *itkImage)
unsigned long int m_VoxelCount
std::vector< float > GetVolumes()
static Pointer New()