4 #include <itkImageRegionConstIterator.h> 5 #include <itkImageRegionIterator.h> 10 template <
class TPixelType>
12 MCMAverageImagesImageFilter <TPixelType>
13 ::BeforeThreadedGenerateData()
15 this->Superclass::BeforeThreadedGenerateData();
17 m_ReferenceInputModels.resize(this->GetNumberOfIndexedInputs());
21 unsigned int numIsoCompartments = tmpMCM->GetNumberOfIsotropicCompartments();
23 std::vector <anima::DiffusionModelCompartmentType> refIsoVec(numIsoCompartments);
24 for (
unsigned int j = 0;j < numIsoCompartments;++j)
25 refIsoVec[j] = m_ReferenceOutputModel->GetCompartment(j)->GetCompartmentType();
27 for (
unsigned int i = 0;i < this->GetNumberOfIndexedInputs();++i)
32 if (model->GetNumberOfIsotropicCompartments() != numIsoCompartments)
33 itkExceptionMacro(
"All input images should have the same isotropic compartment structure as the output model");
35 for (
unsigned int j = 0;j < numIsoCompartments;++j)
37 if (refIsoVec[j] != model->GetCompartment(j)->GetCompartmentType())
38 itkExceptionMacro(
"All input images should have the same isotropic compartment structure as the output model");
41 m_ReferenceInputModels[i] = model;
44 this->GetOutput()->SetDescriptionModel(m_ReferenceOutputModel);
47 template <
class TPixelType>
52 m_ReferenceOutputModel = model;
55 template <
class TPixelType>
61 mcmAverager->SetOutputModel(m_ReferenceOutputModel);
66 template <
class TPixelType>
71 unsigned int numInputs = this->GetNumberOfIndexedInputs();
73 typedef itk::ImageRegionConstIterator <InputImageType> InputIteratorType;
74 typedef itk::ImageRegionIterator <OutputImageType> OutputIteratorType;
76 std::vector<InputIteratorType> inputIterators (numInputs);
78 for (
unsigned int i = 0; i < numInputs; ++i)
79 inputIterators[i] = InputIteratorType (this->GetInput(i), region);
81 OutputIteratorType outputIterator (this->GetOutput(), region);
85 std::vector <MCModelPointer> workInputModels(numInputs);
86 for (
unsigned int i = 0;i < numInputs;++i)
87 workInputModels[i] = m_ReferenceInputModels[i]->Clone();
89 std::vector <double> workInputWeights(numInputs,0.0);
90 PixelType voxelOutputValue(m_ReferenceOutputModel->GetSize());
92 using MaskIteratorType = itk::ImageRegionConstIterator <MaskImageType>;
93 std::vector <MaskIteratorType> maskIterators;
94 if (m_MaskImages.size() == numInputs)
96 for (
unsigned int i = 0; i < numInputs; ++i)
97 maskIterators.push_back(MaskIteratorType (m_MaskImages[i], region));
100 unsigned int numMasks = maskIterators.size();
101 while (!inputIterators[0].IsAtEnd())
103 voxelOutputValue.Fill(0.0);
104 std::fill(workInputWeights.begin(),workInputWeights.end(),0.0);
106 unsigned int trueInputNumber = 0;
107 for (
unsigned int i = 0;i < numInputs;++i)
109 if (isZero(inputIterators[i].Get()))
112 if (numMasks == numInputs)
114 if (maskIterators[i].Get() == 0)
118 workInputModels[i]->SetModelVector(inputIterators[i].Get());
119 workInputWeights[i] = 1.0;
124 if (trueInputNumber == 0)
126 outputIterator.Set(voxelOutputValue);
127 for (
unsigned int i = 0;i < numInputs;++i)
131 for (
unsigned int i = 0;i < numMasks;++i)
137 mcmAverager->SetInputModels(workInputModels);
138 mcmAverager->SetInputWeights(workInputWeights);
141 mcmAverager->Update();
143 voxelOutputValue = mcmAverager->GetOutputModel()->GetModelVector();
146 outputIterator.Set(voxelOutputValue);
147 for (
unsigned int i = 0;i < numInputs;++i)
151 for (
unsigned int i = 0;i < numMasks;++i)
MCMPointer & GetDescriptionModel()
InputImageType::RegionType InputRegionType
InputImageType::PixelType PixelType
MCMAveragerType::Pointer MCMAveragerPointer
MCModelType::Pointer MCModelPointer