7 template <
typename TInputImage,
typename TOutputImage>
9 NumberedThreadImageToImageFilter <TInputImage, TOutputImage>
10 ::BeforeThreadedGenerateData()
12 m_ThreadIdsVector.clear();
13 Superclass::BeforeThreadedGenerateData();
15 if (m_ComputationRegion.GetSize(0) == 0)
17 m_ComputationRegion = this->GetOutput(0)->GetRequestedRegion();
18 m_NumberOfPointsToProcess = m_ComputationRegion.GetNumberOfPixels();
21 unsigned int maxNumSlices = m_ComputationRegion.GetSize()[0];
22 m_ProcessedDimension = 0;
23 for (
unsigned int i = 1;i < OutputImageRegionType::ImageDimension;++i)
25 if (maxNumSlices <= m_ComputationRegion.GetSize()[i])
27 maxNumSlices = m_ComputationRegion.GetSize()[i];
28 m_ProcessedDimension = i;
32 m_NumberOfProcessedPoints = 0;
33 this->UpdateProgress(0.0);
36 typedef typename TOutputImage::PixelType OutputPixelType;
38 for (
unsigned int i = 0;i < this->GetNumberOfOutputs();++i)
40 OutputPixelType zeroPixel;
41 this->InitializeZeroPixel(this->GetOutput(i),zeroPixel);
42 this->GetOutput(i)->FillBuffer(zeroPixel);
46 template<
typename TInputImage,
typename TOutputImage >
51 this->AllocateOutputs();
52 this->BeforeThreadedGenerateData();
54 m_HighestProcessedSlice = 0;
59 this->GetMultiThreader()->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
60 this->GetMultiThreader()->SetSingleMethod(this->ThreaderMultiSplitCallback, &str);
62 this->GetMultiThreader()->SingleMethodExecute();
64 this->AfterThreadedGenerateData();
67 template<
typename TInputImage,
typename TOutputImage >
68 ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
70 ::ThreaderMultiSplitCallback(
void *arg)
74 str = (
ThreadStruct *)( ( (itk::MultiThreaderBase::WorkUnitInfo *)( arg ) )->UserData );
76 Self *filterPtr = dynamic_cast <
Self *> (str->Filter.GetPointer());
79 return ITK_THREAD_RETURN_DEFAULT_VALUE;
82 template<
typename TInputImage,
typename TOutputImage >
85 ::ThreadProcessSlices()
88 processedRegion.SetSize(m_ProcessedDimension,1);
89 int highestToleratedSliceValue = m_ComputationRegion.GetSize()[m_ProcessedDimension] - 1;
91 bool continueLoop =
true;
94 m_LockHighestProcessedSlice.lock();
96 if (m_HighestProcessedSlice > highestToleratedSliceValue)
98 m_LockHighestProcessedSlice.unlock();
103 processedRegion.SetIndex(m_ProcessedDimension, m_ComputationRegion.GetIndex()[m_ProcessedDimension] + m_HighestProcessedSlice);
104 m_HighestProcessedSlice++;
106 m_LockHighestProcessedSlice.unlock();
108 this->DynamicThreadedGenerateData(processedRegion);
112 template <
typename TInputImage,
typename TOutputImage>
115 ::IncrementNumberOfProcessedPoints()
117 m_LockProcessedPoints.lock();
119 ++m_NumberOfProcessedPoints;
121 double ratio = std::floor(m_NumberOfProcessedPoints * 100.0 / m_NumberOfPointsToProcess) / 100.0;
122 ratio = this->progressFixedToFloat(this->progressFloatToFixed(ratio));
124 if (ratio != this->GetProgress())
125 this->UpdateProgress(ratio);
127 m_LockProcessedPoints.unlock();
130 template <
typename TInputImage,
typename TOutputImage>
135 m_LockThreadIdNumber.lock();
137 unsigned int threadId = 0;
138 bool presentInIdsVector =
true;
139 while (presentInIdsVector)
141 presentInIdsVector =
false;
142 for (
unsigned int i = 0;i < m_ThreadIdsVector.size();++i)
144 if (m_ThreadIdsVector[i] == threadId)
146 presentInIdsVector =
true;
151 if (presentInIdsVector)
155 m_ThreadIdsVector.push_back(threadId);
157 m_LockThreadIdNumber.unlock();
162 template <
typename TInputImage,
typename TOutputImage>
165 ::SafeReleaseThreadId(
unsigned int threadId)
167 m_LockThreadIdNumber.lock();
169 unsigned int indexThreadId = 0;
170 for (
unsigned int i = 0;i < m_ThreadIdsVector.size();++i)
172 if (threadId == m_ThreadIdsVector[i])
179 m_ThreadIdsVector.erase(m_ThreadIdsVector.begin() + indexThreadId);
181 m_LockThreadIdNumber.unlock();
Implements a class to handle thread number in a dynamic way for multithreaded methods needing thread ...
Superclass::OutputImageRegionType OutputImageRegionType
itk::ImageSource< itk::Image< PixelScalarType, 3 > >::ThreadStruct ThreadStruct
virtual void ThreadProcessSlices()