21 #ifndef otbImageToPointSetFilter_hxx
22 #define otbImageToPointSetFilter_hxx
32 template <
class TInputImage,
class TOutputPo
intSet>
35 this->ProcessObjectType::SetNumberOfRequiredInputs(1);
39 ProcessObjectType::SetNumberOfRequiredOutputs(1);
40 ProcessObjectType::SetNthOutput(0, output.GetPointer());
42 m_PointsContainerPerThread.clear();
43 m_PointDataContainerPerThread.clear();
46 m_StreamingManager = StreamingManagerType::New();
52 template <
class TInputImage,
class TOutputPo
intSet>
57 this->ProcessObjectType::SetNthInput(idx,
const_cast<InputImageType*
>(input));
63 template <
class TInputImage,
class TOutputPo
intSet>
68 this->ProcessObjectType::SetNthInput(0,
const_cast<InputImageType*
>(input));
74 template <
class TInputImage,
class TOutputPo
intSet>
79 return dynamic_cast<const InputImageType*
>(this->ProcessObjectType::GetInput(idx));
85 template <
class TInputImage,
class TOutputPo
intSet>
88 if (this->GetNumberOfInputs() < 1)
91 return dynamic_cast<const InputImageType*
>(this->ProcessObjectType::GetInput(0));
97 template <
class TInputImage,
class TOutputPo
intSet>
100 Superclass::PrintSelf(os, indent);
108 template <
class TInputImage,
class TOutputPo
intSet>
116 template <
class TInputImage,
class TOutputPo
intSet>
121 outputPointsContainer->Initialize();
124 outputPointDataContainer->Initialize();
126 typename TInputImage::RegionType inputRegion = this->GetInput()->GetLargestPossibleRegion();
132 m_StreamingManager->PrepareStreaming(input, inputRegion);
134 unsigned long numDivisions = m_StreamingManager->GetNumberOfSplits();
142 for (piece = 0; piece < numDivisions && !this->GetAbortGenerateData(); piece++)
144 streamRegion = m_StreamingManager->GetSplit(piece);
145 typedef itk::ImageToImageFilterDetail::ImageRegionCopier<itkGetStaticConstMacro(InputImageDimension), itkGetStaticConstMacro(InputImageDimension)>
146 OutputToInputRegionCopierType;
147 OutputToInputRegionCopierType regionCopier;
149 regionCopier(inputRegion2, streamRegion);
150 input->SetRequestedRegion(inputRegion2);
156 this->BeforeThreadedGenerateData();
163 typename PointsContainerType::Pointer defaultPointsContainer = PointsContainerType::New();
166 typename PointDataContainerType::Pointer defaultPointDataContainer = PointDataContainerType::New();
170 this->GetMultiThreader()->SetNumberOfThreads(this->GetNumberOfThreads());
171 this->GetMultiThreader()->SetSingleMethod(this->ThreaderCallback, &str);
174 this->GetMultiThreader()->SingleMethodExecute();
178 this->AfterThreadedGenerateData();
182 template <
class TInputImage,
class TOutputPo
intSet>
187 template <
class TInputImage,
class TOutputPo
intSet>
192 unsigned long currentIndex = outputPointsContainer->Size();
194 typedef typename PointsContainerType::ConstIterator OutputPointsContainerIterator;
195 for (
unsigned int i = 0; i < this->m_PointsContainerPerThread.size(); ++i)
197 if (this->m_PointsContainerPerThread[i].IsNotNull())
199 for (OutputPointsContainerIterator it = this->m_PointsContainerPerThread[i]->Begin(); it != this->m_PointsContainerPerThread[i]->End(); ++it)
201 outputPointsContainer->InsertElement(currentIndex, it.Value());
208 currentIndex = outputPointDataContainer->Size();
210 typedef typename PointDataContainerType::ConstIterator OutputPointDataContainerIterator;
211 for (
unsigned int i = 0; i < this->m_PointDataContainerPerThread.size(); ++i)
213 if (this->m_PointDataContainerPerThread[i].IsNotNull())
215 for (OutputPointDataContainerIterator it = this->m_PointDataContainerPerThread[i]->Begin(); it != this->m_PointDataContainerPerThread[i]->End(); ++it)
217 outputPointDataContainer->InsertElement(currentIndex, it.Value());
224 template <
class TInputImage,
class TOutputPo
intSet>
231 std::ostringstream message;
232 message <<
"itk::ERROR: " << this->GetNameOfClass() <<
"(" <<
this <<
"): "
233 <<
"Subclass should override this method!!!";
234 itk::ExceptionObject e_(__FILE__, __LINE__, message.str(), ITK_LOCATION);
238 template <
class TInputImage,
class TOutputPo
intSet>
242 unsigned int total, threadCount;
243 itk::ThreadIdType threadId;
245 threadId = ((itk::MultiThreader::ThreadInfoStruct*)(arg))->ThreadID;
246 threadCount = ((itk::MultiThreader::ThreadInfoStruct*)(arg))->NumberOfThreads;
247 str = (ThreadStruct*)(((itk::MultiThreader::ThreadInfoStruct*)(arg))->UserData);
251 typename TInputImage::RegionType splitRegion;
252 total = str->Filter->SplitRequestedRegion(threadId, threadCount, splitRegion);
254 if (threadId < total)
256 str->Filter->ThreadedGenerateData(splitRegion, threadId);
265 return ITK_THREAD_RETURN_VALUE;
268 template <
class TInputImage,
class TOutputPo
intSet>
272 typename InputImageType::ConstPointer inputPtr = this->GetInput();
273 const typename TInputImage::SizeType& requestedRegionSize = inputPtr->GetRequestedRegion().GetSize();
276 typename TInputImage::IndexType splitIndex;
277 typename TInputImage::SizeType splitSize;
280 splitRegion = inputPtr->GetRequestedRegion();
281 splitIndex = splitRegion.GetIndex();
282 splitSize = splitRegion.GetSize();
285 splitAxis = inputPtr->GetImageDimension() - 1;
286 while (requestedRegionSize[splitAxis] == 1)
291 itkDebugMacro(
" Cannot Split");
297 typename TInputImage::SizeType::SizeValueType range = requestedRegionSize[splitAxis];
298 int valuesPerThread = (int)::std::ceil(range / (
double)num);
299 int maxThreadIdUsed = (int)::std::ceil(range / (
double)valuesPerThread) - 1;
302 if (i < maxThreadIdUsed)
304 splitIndex[splitAxis] += i * valuesPerThread;
305 splitSize[splitAxis] = valuesPerThread;
307 if (i == maxThreadIdUsed)
309 splitIndex[splitAxis] += i * valuesPerThread;
311 splitSize[splitAxis] = splitSize[splitAxis] - i * valuesPerThread;
315 splitRegion.SetIndex(splitIndex);
316 splitRegion.SetSize(splitSize);
318 itkDebugMacro(
" Split Piece: " << splitRegion);
320 return maxThreadIdUsed + 1;