Skip to content
Snippets Groups Projects
Commit ab8ac21e authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: add streaming capabilities to ImageToPointSetFilter

parent fc4bcc4e
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#define __otbImageToPointSetFilter_h #define __otbImageToPointSetFilter_h
#include "otbPointSetSource.h" #include "otbPointSetSource.h"
#include "itkImageRegionSplitter.h"
#include "otbStreamingTraits.h"
namespace otb namespace otb
{ {
...@@ -51,6 +53,8 @@ public: ...@@ -51,6 +53,8 @@ public:
typedef typename InputImageType::ConstPointer InputImageConstPointer; typedef typename InputImageType::ConstPointer InputImageConstPointer;
typedef typename InputImageType::RegionType InputImageRegionType; typedef typename InputImageType::RegionType InputImageRegionType;
typedef typename InputImageType::PixelType InputImagePixelType; typedef typename InputImageType::PixelType InputImagePixelType;
itkStaticConstMacro(InputImageDimension, unsigned int,
TInputImage::ImageDimension);
/** Some PointSet related typedefs. */ /** Some PointSet related typedefs. */
typedef typename Superclass::OutputPointSetType OutputPointSetType; typedef typename Superclass::OutputPointSetType OutputPointSetType;
...@@ -103,6 +107,12 @@ protected: ...@@ -103,6 +107,12 @@ protected:
/** End Multi-threading implementation */ /** End Multi-threading implementation */
/** Setup for streaming */
typedef StreamingTraits<InputImageType> StreamingTraitsType;
typedef itk::ImageRegionSplitter<itkGetStaticConstMacro(InputImageDimension)> SplitterType;
typedef typename SplitterType::Pointer RegionSplitterPointer;
RegionSplitterPointer m_RegionSplitter;
private: private:
ImageToPointSetFilter(const ImageToPointSetFilter&); //purposely not implemented ImageToPointSetFilter(const ImageToPointSetFilter&); //purposely not implemented
void operator=(const ImageToPointSetFilter&); //purposely not implemented void operator=(const ImageToPointSetFilter&); //purposely not implemented
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "otbImageToPointSetFilter.h" #include "otbImageToPointSetFilter.h"
namespace otb namespace otb
{ {
...@@ -39,6 +38,10 @@ ImageToPointSetFilter<TInputImage,TOutputPointSet> ...@@ -39,6 +38,10 @@ ImageToPointSetFilter<TInputImage,TOutputPointSet>
ProcessObjectType::SetNumberOfRequiredOutputs(1); ProcessObjectType::SetNumberOfRequiredOutputs(1);
ProcessObjectType::SetNthOutput(0, output.GetPointer()); ProcessObjectType::SetNthOutput(0, output.GetPointer());
// create default region splitter
m_RegionSplitter = itk::ImageRegionSplitter<itkGetStaticConstMacro(InputImageDimension)>::New();
} }
/** /**
...@@ -128,31 +131,69 @@ void ...@@ -128,31 +131,69 @@ void
ImageToPointSetFilter<TInputImage,TOutputPointSet> ImageToPointSetFilter<TInputImage,TOutputPointSet>
::GenerateData(void) ::GenerateData(void)
{ {
// Call a method that can be overridden by a subclass to perform
// some calculations prior to splitting the main computations into
// separate threads
this->BeforeThreadedGenerateData();
// Set up the multithreaded processing PointsContainerType * outputPointsContainer = this->GetOutput()->GetPoints();
ThreadStruct str; outputPointsContainer->Initialize();
str.Filter = this;
typename TInputImage::RegionType inputRegion = this->GetInput()->GetLargestPossibleRegion();
unsigned int numDivisions;
numDivisions = StreamingTraitsType
::CalculateNumberOfStreamDivisions(this->GetInput(),
this->GetInput()->GetLargestPossibleRegion(),
m_RegionSplitter,
SET_AUTOMATIC_NUMBER_OF_STREAM_DIVISIONS,
0, 0, 0);
// Input is an image, cast away the constness so we can set
// the requested region.
InputImagePointer input = const_cast<TInputImage *> (this->GetInput());
/**
* Loop over the number of pieces, execute the upstream pipeline on each
* piece, and copy the results into the output image.
*/
unsigned int piece;
InputImageRegionType streamRegion;
for (piece = 0;
piece < numDivisions && !this->GetAbortGenerateData();
piece++)
{
streamRegion = m_RegionSplitter->GetSplit(piece, numDivisions, inputRegion);
typedef itk::ImageToImageFilterDetail::ImageRegionCopier<itkGetStaticConstMacro(InputImageDimension),
itkGetStaticConstMacro(InputImageDimension)> OutputToInputRegionCopierType;
OutputToInputRegionCopierType regionCopier;
InputImageRegionType inputRegion;
regionCopier(inputRegion, streamRegion);
input->SetRequestedRegion( inputRegion );
// Call a method that can be overridden by a subclass to perform
// some calculations prior to splitting the main computations into
// separate threads
this->BeforeThreadedGenerateData();
// Initializing object per thread // Set up the multithreaded processing
typename PointsContainerType::Pointer defaultPointsContainer = PointsContainerType::New(); ThreadStruct str;
this->m_PointsContainerPerThread str.Filter = this;
= OutputPointsContainerForThreadType(this->GetNumberOfThreads(),defaultPointsContainer);
// Initializing object per thread
typename PointsContainerType::Pointer defaultPointsContainer = PointsContainerType::New();
this->m_PointsContainerPerThread
= OutputPointsContainerForThreadType(this->GetNumberOfThreads(),defaultPointsContainer);
// Setting up multithreader
this->GetMultiThreader()->SetNumberOfThreads(this->GetNumberOfThreads());
this->GetMultiThreader()->SetSingleMethod(this->ThreaderCallback, &str);
// multithread the execution // Setting up multithreader
this->GetMultiThreader()->SingleMethodExecute(); this->GetMultiThreader()->SetNumberOfThreads(this->GetNumberOfThreads());
this->GetMultiThreader()->SetSingleMethod(this->ThreaderCallback, &str);
// Call a method that can be overridden by a subclass to perform // multithread the execution
// some calculations after all the threads have completed this->GetMultiThreader()->SingleMethodExecute();
this->AfterThreadedGenerateData();
// Call a method that can be overridden by a subclass to perform
// some calculations after all the threads have completed
this->AfterThreadedGenerateData();
}
} }
...@@ -161,7 +202,7 @@ void ...@@ -161,7 +202,7 @@ void
ImageToPointSetFilter<TInputImage,TOutputPointSet> ImageToPointSetFilter<TInputImage,TOutputPointSet>
::BeforeThreadedGenerateData(void) ::BeforeThreadedGenerateData(void)
{ {
// this->AllocateOutputs();
} }
template <class TInputImage, class TOutputPointSet> template <class TInputImage, class TOutputPointSet>
...@@ -171,7 +212,7 @@ ImageToPointSetFilter<TInputImage,TOutputPointSet> ...@@ -171,7 +212,7 @@ ImageToPointSetFilter<TInputImage,TOutputPointSet>
{ {
// copy the lists to the output // copy the lists to the output
PointsContainerType * outputPointsContainer = this->GetOutput()->GetPoints(); PointsContainerType * outputPointsContainer = this->GetOutput()->GetPoints();
outputPointsContainer->Initialize();
typedef typename PointsContainerType::ConstIterator OutputPointsContainerIterator; typedef typename PointsContainerType::ConstIterator OutputPointsContainerIterator;
for (unsigned int i=0; i< this->m_PointsContainerPerThread.size(); ++i) for (unsigned int i=0; i< this->m_PointsContainerPerThread.size(); ++i)
{ {
...@@ -245,14 +286,14 @@ ImageToPointSetFilter<TInputImage,TOutputPointSet> ...@@ -245,14 +286,14 @@ ImageToPointSetFilter<TInputImage,TOutputPointSet>
// Get the output pointer // Get the output pointer
typename InputImageType::ConstPointer inputPtr = this->GetInput(); typename InputImageType::ConstPointer inputPtr = this->GetInput();
const typename TInputImage::SizeType& requestedRegionSize const typename TInputImage::SizeType& requestedRegionSize
= inputPtr->GetLargestPossibleRegion().GetSize(); = inputPtr->GetRequestedRegion().GetSize();
int splitAxis; int splitAxis;
typename TInputImage::IndexType splitIndex; typename TInputImage::IndexType splitIndex;
typename TInputImage::SizeType splitSize; typename TInputImage::SizeType splitSize;
// Initialize the splitRegion to the output requested region // Initialize the splitRegion to the output requested region
splitRegion = inputPtr->GetLargestPossibleRegion(); splitRegion = inputPtr->GetRequestedRegion();
splitIndex = splitRegion.GetIndex(); splitIndex = splitRegion.GetIndex();
splitSize = splitRegion.GetSize(); splitSize = splitRegion.GetSize();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment