6 #include <itkImageRegionIterator.h> 7 #include <itkImageRegionConstIterator.h> 12 template <
class ImageType>
20 unsigned int prevNum = this->GetNumberOfOutputs();
22 this->SetNumberOfIndexedOutputs(m_NumberOfReplicates);
24 for (
unsigned int i = prevNum;i < m_NumberOfReplicates;++i)
26 this->SetNthOutput(i,this->MakeOutput(i).GetPointer());
32 Superclass::GenerateOutputInformation();
35 template <
class ImageType>
40 Superclass::BeforeThreadedGenerateData();
43 std::mt19937 motherGenerator(time(ITK_NULLPTR));
44 for (
int i = 0;i < this->GetNumberOfWorkUnits();++i)
45 m_Generators.push_back(std::mt19937(motherGenerator()));
48 template <
class ImageType>
53 typedef itk::ImageRegionConstIterator<InputImageType> InputImageIteratorType;
54 typedef itk::ImageRegionIterator<OutputImageType> OutputImageIteratorType;
56 InputImageIteratorType inputIterator(this->GetInput(), outputRegionForThread);
58 std::vector<OutputImageIteratorType> outIterators(m_NumberOfReplicates);
59 for (
unsigned int i = 0;i < m_NumberOfReplicates;++i)
60 outIterators[i] = OutputImageIteratorType(this->GetOutput(i), outputRegionForThread);
62 unsigned int threadId = this->GetSafeThreadId();
64 while (!inputIterator.IsAtEnd())
66 double refData = inputIterator.Get();
68 for (
unsigned int i = 0;i < m_NumberOfReplicates;++i)
71 double data = refData + realNoise;
73 if (!m_UseGaussianDistribution)
76 data = std::sqrt(data * data + imagNoise * imagNoise);
79 if ((std::isnan(data)) || (!std::isfinite(data)))
82 outIterators[i].Set(data);
89 this->SafeReleaseThreadId(threadId);
void GenerateOutputInformation() ITK_OVERRIDE
Superclass::OutputImageRegionType OutputImageRegionType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE
double SampleFromGaussianDistribution(const T &mean, const T &std, std::mt19937 &generator)
void BeforeThreadedGenerateData() ITK_OVERRIDE