4 #include <itkImageRegionIterator.h> 5 #include <itkImageRegionIteratorWithIndex.h> 6 #include <itkImageRegionConstIterator.h> 11 template <
class PixelScalarType>
16 if (i == m_GradientDirections.size())
17 m_GradientDirections.push_back(grad);
18 else if (i > m_GradientDirections.size())
19 std::cerr <<
"Trying to add a direction not contiguous... Add directions contiguously (0,1,2,3,...)..." << std::endl;
21 m_GradientDirections[i] = grad;
24 template <
class PixelScalarType>
32 this->Superclass::GenerateOutputInformation();
35 output->SetVectorLength(m_GradientDirections.size());
38 template <
class PixelScalarType>
43 if (this->GetInput()->GetNumberOfComponentsPerPixel() != m_NumberOfComponents)
44 throw itk::ExceptionObject(__FILE__, __LINE__,
"Input image should have 6 dimensions...",ITK_LOCATION);
46 Superclass::BeforeThreadedGenerateData();
50 m_S0Image = S0ImageType::New();
51 m_S0Image->Initialize();
52 m_S0Image->SetRegions(this->GetInput()->GetLargestPossibleRegion());
53 m_S0Image->SetSpacing (this->GetInput()->GetSpacing());
54 m_S0Image->SetOrigin (this->GetInput()->GetOrigin());
55 m_S0Image->SetDirection (this->GetInput()->GetDirection());
56 m_S0Image->Allocate();
58 m_S0Image->FillBuffer(m_S0Value);
62 template <
class PixelScalarType>
67 typedef itk::ImageRegionConstIterator <InputImageType> ImageIteratorType;
69 ImageIteratorType inIterator(this->GetInput(),outputRegionForThread);
71 typedef itk::ImageRegionIterator <OutputImageType> OutImageIteratorType;
72 OutImageIteratorType outIterator(this->GetOutput(),outputRegionForThread);
74 typedef itk::ImageRegionIterator <S0ImageType> S0ImageIteratorType;
75 S0ImageIteratorType s0Iterator(m_S0Image,outputRegionForThread);
77 typedef typename OutputImageType::PixelType OutputPixelType;
79 unsigned int outputSize = m_GradientDirections.size();
81 OutputPixelType resVec(outputSize);
83 while (!outIterator.IsAtEnd())
85 for (
unsigned int i = 0;i < outputSize;++i)
88 inVecTens = inIterator.Get();
89 if (this->isZero(inVecTens))
91 outIterator.Set(resVec);
99 for (
unsigned int i = 0;i < outputSize;++i)
101 unsigned int pos = 0;
102 for (
unsigned int j = 0;j < 3;++j)
103 for (
unsigned int k = 0;k <= j;++k)
106 resVec[i] += 2.0 * m_GradientDirections[i][j] * m_GradientDirections[i][k] * inVecTens[pos];
108 resVec[i] += m_GradientDirections[i][j] * m_GradientDirections[i][j] * inVecTens[pos];
113 resVec[i] *= - m_BValuesList[i];
114 resVec[i] = s0Iterator.Get() * std::exp(resVec[i]);
117 outIterator.Set(resVec);
125 template <
class PixelScalarType>
130 unsigned int sizeVec = vec.GetSize();
132 for (
unsigned int i = 0;i < sizeVec;++i)
141 template <
class PixelScalarType>
148 typename OutputImageType::Pointer outPtr = this->GetOutput();
149 unsigned int ndim = outPtr->GetNumberOfComponentsPerPixel();
151 typename Image4DType::RegionType region4d;
152 typename InputImageType::RegionType region3d = outPtr->GetLargestPossibleRegion();
153 typename Image4DType::SizeType size4d;
154 typename Image4DType::SpacingType spacing4d;
155 typename Image4DType::PointType origin4d;
156 typename Image4DType::DirectionType direction4d;
158 region4d.SetIndex(3,0);
159 region4d.SetSize(3,ndim);
163 direction4d(3,3) = 1;
165 for (
unsigned int i = 0;i < 3;++i)
167 region4d.SetIndex(i,region3d.GetIndex()[i]);
168 region4d.SetSize(i,region3d.GetSize()[i]);
170 size4d[i] = region3d.GetSize()[i];
171 spacing4d[i] = outPtr->GetSpacing()[i];
172 origin4d[i] = outPtr->GetOrigin()[i];
173 for (
unsigned int j = 0;j < 3;++j)
174 direction4d(i,j) = (outPtr->GetDirection())(i,j);
176 direction4d(i,3) = 0;
177 direction4d(3,i) = 0;
180 m_Output4D = Image4DType::New();
181 m_Output4D->Initialize();
182 m_Output4D->SetRegions(region4d);
183 m_Output4D->SetSpacing (spacing4d);
184 m_Output4D->SetOrigin (origin4d);
185 m_Output4D->SetDirection (direction4d);
186 m_Output4D->Allocate();
188 typedef itk::ImageRegionConstIterator <OutputImageType> OutImageIteratorType;
189 typedef itk::ImageRegionIterator <Image4DType> Image4DIteratorType;
191 for (
unsigned int i = 0;i < ndim;++i)
193 region4d.SetIndex(3,i);
194 region4d.SetSize(3,1);
196 OutImageIteratorType outItr(outPtr,region3d);
197 Image4DIteratorType fillItr(m_Output4D,region4d);
199 while (!fillItr.IsAtEnd())
201 fillItr.Set(outItr.Get()[i]);
Superclass::OutputImageRegionType OutputImageRegionType
bool isZero(InputPixelType &vec)
Image4DType * GetOutputAs4DImage()
void AddGradientDirection(unsigned int i, std::vector< double > &grad)
TOutputImage OutputImageType
void GenerateOutputInformation() ITK_OVERRIDE
void BeforeThreadedGenerateData() ITK_OVERRIDE
itk::Image< PixelScalarType, 4 > Image4DType
InputImageType::PixelType InputPixelType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE