4 #include <itkImageRegionConstIterator.h> 8 template<
typename TInputImage,
typename TOutputImage >
10 MaskedImageToImageFilter < TInputImage, TOutputImage >
11 ::CheckComputationMask()
13 if (!m_ComputationMask)
15 m_ComputationMask = MaskImageType::New();
16 m_ComputationMask->Initialize();
18 m_ComputationMask->SetRegions (this->GetOutput(0)->GetLargestPossibleRegion());
19 m_ComputationMask->SetSpacing (this->GetOutput(0)->GetSpacing());
20 m_ComputationMask->SetOrigin (this->GetOutput(0)->GetOrigin());
21 m_ComputationMask->SetDirection (this->GetOutput(0)->GetDirection());
23 m_ComputationMask->Allocate();
25 m_ComputationMask->FillBuffer(1);
29 template<
typename TInputImage,
typename TOutputImage >
32 ::BeforeThreadedGenerateData()
34 if (this->GetComputationRegion().GetSize(0) == 0)
35 this->InitializeComputationRegionFromMask();
37 Superclass::BeforeThreadedGenerateData();
41 template<
typename TInputImage,
typename TOutputImage >
44 ::InitializeComputationRegionFromMask()
46 this->CheckComputationMask();
48 typedef itk::ImageRegionConstIterator< MaskImageType > MaskRegionIteratorType;
50 MaskRegionIteratorType maskItr(m_ComputationMask,m_ComputationMask->GetLargestPossibleRegion());
55 for (
unsigned int i = 0;i < m_ComputationMask->GetImageDimension();++i)
57 minPos[i] = m_ComputationMask->GetLargestPossibleRegion().GetIndex()[i] + m_ComputationMask->GetLargestPossibleRegion().GetSize()[i];
61 unsigned int numPoints = 0;
62 while (!maskItr.IsAtEnd())
64 if (maskItr.Get() != 0)
69 for (
unsigned int i = 0;i < m_ComputationMask->GetImageDimension();++i)
71 if (minPos[i] > tmpInd[i])
72 minPos[i] = tmpInd[i];
74 if (maxPos[i] < tmpInd[i])
75 maxPos[i] = tmpInd[i];
82 this->SetNumberOfPointsToProcess(numPoints);
85 computationRegion.SetIndex(minPos);
88 for (
unsigned int i = 0;i < m_ComputationMask->GetImageDimension();++i)
89 tmpSize[i] = maxPos[i] - minPos[i] + 1;
91 computationRegion.SetSize(tmpSize);
92 this->SetComputationRegion(computationRegion);
Superclass::OutputImageRegionType OutputImageRegionType
MaskImageType::SizeType MaskSizeType
MaskImageType::IndexType MaskIndexType