4 #include <itkImageRegionConstIteratorWithIndex.h> 5 #include <itkImageRegionConstIterator.h> 6 #include <itkImageRegionIterator.h> 21 for (
unsigned int i = 0;i < m_GlobalRegionOfInterest.GetImageDimension();++i)
23 m_GlobalRegionOfInterest.SetIndex(i,0);
24 m_GlobalRegionOfInterest.SetSize(i,0);
26 m_BlockRegion.SetIndex(i,0);
27 m_BlockRegion.SetSize(i,0);
29 m_BlockRegionWithMargin.SetIndex(i,0);
30 m_BlockRegionWithMargin.SetSize(i,0);
46 m_FileNames.push_back(inputFileName);
52 std::ifstream fileIn(inputFileList.c_str());
54 if (!fileIn.is_open())
56 std::string error(
"Invalid input file list. ");
57 error += inputFileList;
58 error +=
" could not be opened...";
60 throw itk::ExceptionObject(__FILE__, __LINE__,error,ITK_LOCATION);
68 fileIn.getline(tmpStr,2048);
70 if (strcmp(tmpStr,
"") != 0)
71 m_FileNames.push_back(std::string(tmpStr));
76 m_NbImages = m_FileNames.size();
82 typedef itk::ImageRegionConstIteratorWithIndex< MaskImageType > MaskIteratorType;
84 MaskIteratorType maskIterator(m_MaskImage,m_MaskImage->GetLargestPossibleRegion());
86 bool foundOneNonNull =
false;
87 while (!maskIterator.IsAtEnd())
89 if (maskIterator.Get() == 0)
97 for (
unsigned int i = 0;i < MaskImageType::GetImageDimension();++i)
99 if (m_GlobalRegionOfInterest.GetIndex()[i] > maskIterator.GetIndex()[i])
101 unsigned int newSize = m_GlobalRegionOfInterest.GetSize()[i] - maskIterator.GetIndex()[i] + m_GlobalRegionOfInterest.GetIndex()[i];
102 m_GlobalRegionOfInterest.SetSize(i,newSize);
103 m_GlobalRegionOfInterest.SetIndex(i,maskIterator.GetIndex()[i]);
107 for (
unsigned int i = 0;i < MaskImageType::GetImageDimension();++i)
109 unsigned int tmpNum = m_GlobalRegionOfInterest.GetIndex()[i] + m_GlobalRegionOfInterest.GetSize()[i];
110 if (tmpNum <= maskIterator.GetIndex()[i])
111 m_GlobalRegionOfInterest.SetSize(i,maskIterator.GetIndex()[i] - m_GlobalRegionOfInterest.GetIndex()[i] + 1);
116 m_GlobalRegionOfInterest.SetIndex(maskIterator.GetIndex());
117 for (
unsigned int i = 0;i < m_GlobalRegionOfInterest.GetImageDimension();++i)
118 m_GlobalRegionOfInterest.SetSize(i,1);
120 foundOneNonNull =
true;
126 m_NeedsUpdate =
true;
131 if (m_NbBlocks != bNumBlocks)
133 m_NeedsUpdate =
true;
134 m_NbBlocks = bNumBlocks;
140 if (m_Block != bIndex)
142 m_NeedsUpdate =
true;
149 if (m_Margin != bMargin)
151 m_NeedsUpdate =
true;
160 for (
unsigned int i = 0;i < m_GlobalRegionOfInterest.GetImageDimension();++i)
162 tmpBlock.SetIndex(i,m_GlobalRegionOfInterest.GetIndex(i) + m_GlobalRegionOfInterest.GetSize(i)*block[i]/m_NbBlocks[i]);
163 unsigned int tmpMax = m_GlobalRegionOfInterest.GetIndex(i) + m_GlobalRegionOfInterest.GetSize(i)*(1+block[i])/m_NbBlocks[i] - tmpBlock.GetIndex(i);
164 tmpBlock.SetSize(i,tmpMax);
173 throw itk::ExceptionObject(__FILE__, __LINE__,
"No mask input. This is required. Exiting...",ITK_LOCATION);
176 itk::ImageRegionConstIteratorWithIndex < MaskImageType > maskIt(m_MaskImage,tmpBlock);
178 bool hasNonNullValue =
false;
179 while (!maskIt.IsAtEnd())
181 if (maskIt.Get() != 0)
183 hasNonNullValue =
true;
190 return (!hasNonNullValue);
201 throw itk::ExceptionObject(__FILE__, __LINE__,
"No mask input. This is required. Exiting...",ITK_LOCATION);
203 for (
unsigned int i = 0;i < m_GlobalRegionOfInterest.GetImageDimension();++i)
205 m_BlockRegion.SetIndex(i,m_GlobalRegionOfInterest.GetIndex(i) + m_GlobalRegionOfInterest.GetSize(i)*m_Block[i]/m_NbBlocks[i]);
206 unsigned int tmpMax = m_GlobalRegionOfInterest.GetIndex(i) + m_GlobalRegionOfInterest.GetSize(i)*(1+m_Block[i])/m_NbBlocks[i] - m_BlockRegion.GetIndex(i);
207 m_BlockRegion.SetSize(i,tmpMax);
210 m_BlockRegionWithMargin = m_BlockRegion;
211 for (
unsigned int i = 0;i < m_GlobalRegionOfInterest.GetImageDimension();++i)
213 if (m_Margin[i] != 0)
215 unsigned int tmpMin = m_BlockRegion.GetIndex()[i] - m_Margin[i];
216 if (tmpMin < m_MaskImage->GetLargestPossibleRegion().GetIndex()[i])
217 tmpMin = m_MaskImage->GetLargestPossibleRegion().GetIndex()[i];
218 unsigned int tmpMax = m_BlockRegion.GetIndex()[i] + m_BlockRegion.GetSize()[i] + m_Margin[i] - 1;
219 if (tmpMax >= m_MaskImage->GetLargestPossibleRegion().GetIndex()[i] + m_MaskImage->GetLargestPossibleRegion().GetSize()[i])
220 tmpMax = m_MaskImage->GetLargestPossibleRegion().GetIndex()[i] + m_MaskImage->GetLargestPossibleRegion().GetSize()[i] - 1;
222 m_BlockRegionWithMargin.SetIndex(i,tmpMin);
223 m_BlockRegionWithMargin.SetSize(i,tmpMax - tmpMin + 1);
227 MaskImageType::RegionType tmpRegion = m_BlockRegion;
228 for (
unsigned int i = 0;i < MaskImageType::GetImageDimension();++i)
229 tmpRegion.SetIndex(i,0);
231 m_SmallMask = MaskImageType::New();
232 m_SmallMask->Initialize();
233 m_SmallMask->SetRegions(tmpRegion);
234 m_SmallMask->SetOrigin(m_MaskImage->GetOrigin());
235 m_SmallMask->SetDirection(m_MaskImage->GetDirection());
236 m_SmallMask->SetSpacing(m_MaskImage->GetSpacing());
237 m_SmallMask->Allocate();
239 itk::ImageRegionIterator <MaskImageType> smallIt(m_SmallMask,tmpRegion);
240 itk::ImageRegionConstIterator <MaskImageType> maskIt(m_MaskImage,m_BlockRegion);
242 while (!maskIt.IsAtEnd())
244 smallIt.Set(maskIt.Get());
249 for (
unsigned int i = 0;i < MaskImageType::GetImageDimension();++i)
250 tmpRegion.SetSize(i,m_BlockRegionWithMargin.GetSize()[i]);
252 m_SmallMaskWithMargin = MaskImageType::New();
253 m_SmallMaskWithMargin->Initialize();
254 m_SmallMaskWithMargin->SetRegions(tmpRegion);
255 m_SmallMaskWithMargin->SetOrigin(m_MaskImage->GetOrigin());
256 m_SmallMaskWithMargin->SetDirection(m_MaskImage->GetDirection());
257 m_SmallMaskWithMargin->SetSpacing(m_MaskImage->GetSpacing());
258 m_SmallMaskWithMargin->Allocate();
260 itk::ImageRegionIterator <MaskImageType> smallItWM(m_SmallMaskWithMargin,tmpRegion);
261 itk::ImageRegionConstIterator <MaskImageType> maskItWM(m_MaskImage,m_BlockRegionWithMargin);
263 while (!maskItWM.IsAtEnd())
265 smallItWM.Set(maskItWM.Get());
270 for (
unsigned int i = 0;i < m_FileNames.size();++i)
272 std::cout <<
"Processing image file " << m_FileNames[i] <<
"..." << std::endl;
274 tmpImReader->SetFileName(m_FileNames[i]);
275 tmpImReader->Update();
277 m_Images.push_back(TInputImage::New());
278 m_Images[i]->Initialize();
279 m_Images[i]->SetRegions(tmpRegion);
280 m_Images[i]->SetOrigin(m_MaskImage->GetOrigin());
281 m_Images[i]->SetDirection(m_MaskImage->GetDirection());
282 m_Images[i]->SetSpacing(m_MaskImage->GetSpacing());
284 m_Images[i]->SetNumberOfComponentsPerPixel(tmpImReader->GetOutput()->GetNumberOfComponentsPerPixel());
286 m_Images[i]->Allocate();
288 itk::ImageRegionIterator <TInputImage> cropImIt(m_Images[i],tmpRegion);
289 itk::ImageRegionConstIterator <TInputImage> reImIt(tmpImReader->GetOutput(),m_BlockRegionWithMargin);
291 while (!cropImIt.IsAtEnd())
293 cropImIt.Set(reImIt.Get());
300 m_NeedsUpdate =
false;
310 for (
unsigned int i = 0;i < TInputImage::GetImageDimension();++i)
311 bRegInsideMargin.SetIndex(i,m_BlockRegion.GetIndex()[i] - m_BlockRegionWithMargin.GetIndex()[i]);
313 return bRegInsideMargin;
void SetUniqueFileName(std::string &inputFileName)
TInputRegionType GetBlockRegionInsideMargin()
TInputImage::RegionType TInputRegionType
void SetFileNames(std::string &inputFileList)
void SetComputationMask(MaskImageType::Pointer &maskIm)
void SetBlockMargin(TInputIndexType &bMargin)
void SetBlockIndex(TInputIndexType &bIndex)
void SetNumberOfBlocks(TInputIndexType &bNumBlocks)
InputReaderType::Pointer InputReaderPointer
TInputRegionType GetSpecificBlockRegion(TInputIndexType &block)
bool EmptyMask(TInputIndexType &bIndex)
TInputImage::IndexType TInputIndexType