2 #include <itkImageFileReader.h> 3 #include <itkImageFileWriter.h> 11 m_NumThreads = itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads();
14 m_ComputationMask = NULL;
22 delete m_DatabaseImages;
27 itk::ImageFileReader <MaskImageType>::Pointer tmpRead = itk::ImageFileReader <MaskImageType>::New();
28 tmpRead->SetFileName(cMask);
31 m_ComputationMask = tmpRead->GetOutput();
38 if (!m_ComputationMask)
39 itkExceptionMacro(
"No computation mask... Exiting...");
42 for (
unsigned int i = 0;i < MaskImageType::GetImageDimension();++i)
43 tmpInd[i] = m_NbSplits;
47 for (
unsigned int i = 0;i < MaskImageType::GetImageDimension();++i)
48 marginBlock[i] = m_PatchHalfSize;
53 std::vector < ImageSplitterType::TInputIndexType > splitIndexesToProcess;
55 if (specificSplitToDo != -1)
57 tmpInd[0] = (
unsigned int)floor((
double)(specificSplitToDo/(m_NbSplits*m_NbSplits)));
58 unsigned int tmpVal = specificSplitToDo - tmpInd[0]*m_NbSplits*m_NbSplits;
59 tmpInd[1] = (
unsigned int)floor((
double)(tmpVal/m_NbSplits));
60 tmpInd[2] = tmpVal - tmpInd[1]*m_NbSplits;
63 splitIndexesToProcess.push_back(tmpInd);
67 for (
unsigned int i = 0;i < m_NbSplits;++i)
70 for (
unsigned int j = 0;j < m_NbSplits;++j)
73 for (
unsigned int k = 0;k < m_NbSplits;++k)
78 splitIndexesToProcess.push_back(tmpInd);
84 for (
unsigned int i = 0;i < splitIndexesToProcess.size();++i)
86 std::cout <<
"Processing block : " << splitIndexesToProcess[i][0] <<
" " 87 << splitIndexesToProcess[i][1] <<
" " << splitIndexesToProcess[i][2] << std::endl;
90 m_DatabaseImages->
Update();
94 for (
unsigned int j = 0;j < m_DatabaseImages->
GetNbImages();++j)
95 mainFilter->SetInput(j,m_DatabaseImages->
GetOutput(j));
98 mainFilter->SetNumberOfWorkUnits(m_NumThreads);
100 mainFilter->SetPatchHalfSize(m_PatchHalfSize);
102 mainFilter->Update();
104 std::cout <<
"Results computed... Writing output parcel..." << std::endl;
107 sprintf(numSplit,
"_%ld_%ld_%ld.nrrd",splitIndexesToProcess[i][0],splitIndexesToProcess[i][1],splitIndexesToProcess[i][2]);
110 std::string outputMeanName = m_OutputMeanName + numSplit;
111 std::string outputStdName = m_OutputStdName + numSplit;
114 if (m_OutputStdName !=
"")
118 if (genOutputDescriptionData)
120 std::vector <std::ofstream> mainOutFiles;
122 std::string tmpOutStdName = m_OutputStdName +
".txt";
123 std::ofstream tmpFileStdOut;
125 if (m_OutputStdName !=
"")
126 tmpFileStdOut.open(tmpOutStdName.c_str());
128 std::string tmpOutMeanName = m_OutputMeanName +
".txt";
129 std::ofstream tmpFileMeanOut(tmpOutMeanName.c_str());
131 for (
unsigned int i = 0;i < m_NbSplits;++i)
134 for (
unsigned int j = 0;j < m_NbSplits;++j)
137 for (
unsigned int k = 0;k < m_NbSplits;++k)
141 if (!m_DatabaseImages->
EmptyMask(tmpInd))
145 sprintf(numSplit,
"_%ld_%ld_%ld.nrrd",tmpInd[0],tmpInd[1],tmpInd[2]);
147 if (tmpFileStdOut.is_open())
149 tmpFileStdOut <<
"<BLOCK>" << std::endl;
150 tmpFileStdOut <<
"BLOCK_FILE=" << m_OutputStdName + numSplit << std::endl;
151 tmpFileStdOut <<
"STARTING_INDEX=" << tmpBlRegion.GetIndex()[0] <<
" " 152 << tmpBlRegion.GetIndex()[1] <<
" " << tmpBlRegion.GetIndex()[2] << std::endl;
153 tmpFileStdOut <<
"</BLOCK>" << std::endl;
156 tmpFileMeanOut <<
"<BLOCK>" << std::endl;
157 tmpFileMeanOut <<
"BLOCK_FILE=" << m_OutputMeanName + numSplit << std::endl;
158 tmpFileMeanOut <<
"STARTING_INDEX=" << tmpBlRegion.GetIndex()[0] <<
" " 159 << tmpBlRegion.GetIndex()[1] <<
" " << tmpBlRegion.GetIndex()[2] << std::endl;
160 tmpFileMeanOut <<
"</BLOCK>" << std::endl;
166 tmpFileMeanOut.close();
167 tmpFileStdOut.close();
172 OutputImageType::RegionType finalROI)
174 OutputImageType::RegionType tmpRegion = finalROI;
175 for (
unsigned int i = 0;i < OutputImageType::GetImageDimension();++i)
176 tmpRegion.SetIndex(i,0);
178 OutputImageType::Pointer tmpRes = OutputImageType::New();
179 tmpRes->Initialize();
181 tmpRes->SetOrigin(m_ComputationMask->GetOrigin());
182 tmpRes->SetRegions(tmpRegion);
183 tmpRes->SetDirection(m_ComputationMask->GetDirection());
184 tmpRes->SetSpacing(m_ComputationMask->GetSpacing());
188 itk::ImageRegionIterator <OutputImageType> tmpImIt (tmpIm,finalROI);
189 itk::ImageRegionIterator <OutputImageType> tmpResIt (tmpRes,tmpRegion);
191 while (!tmpImIt.IsAtEnd())
193 tmpResIt.Set(tmpImIt.Get());
199 itk::ImageFileWriter <OutputImageType>::Pointer outWriter = itk::ImageFileWriter <OutputImageType>::New();
200 outWriter->SetInput(tmpRes);
201 outWriter->SetFileName(resName);
202 outWriter->SetUseCompression(
true);
void Update(int specificSplitToDo=-1, bool genOutputDescriptionData=false)
TInputRegionType GetBlockRegionInsideMargin()
unsigned int GetNbImages()
MaskImageType * GetSmallMaskWithMargin()
~LowMemoryLocalPatchCovarianceDistanceBridge()
LocalPatchCovarianceDistanceImageFilter< double >::OutputImageType OutputImageType
void BuildAndWrite(OutputImageType *tmpIm, std::string resName, OutputImageType::RegionType finalROI)
void SetComputationMask(MaskImageType::Pointer &maskIm)
void SetBlockMargin(TInputIndexType &bMargin)
void SetBlockIndex(TInputIndexType &bIndex)
void SetNumberOfBlocks(TInputIndexType &bNumBlocks)
void SetComputationMask(std::string &cMask)
itk::SmartPointer< Self > Pointer
TInputImage * GetOutput(unsigned int i)
TInputRegionType GetSpecificBlockRegion(TInputIndexType &block)
bool EmptyMask(TInputIndexType &bIndex)
LowMemoryLocalPatchCovarianceDistanceBridge()
anima::ImageDataSplitter< InputImageType > ImageSplitterType
TInputImage::IndexType TInputIndexType