Commit ab8ac21e authored by Emmanuel Christophe's avatar Emmanuel Christophe

ENH: add streaming capabilities to ImageToPointSetFilter

parent fc4bcc4e
......@@ -19,6 +19,8 @@
#define __otbImageToPointSetFilter_h
#include "otbPointSetSource.h"
#include "itkImageRegionSplitter.h"
#include "otbStreamingTraits.h"
namespace otb
{
......@@ -51,6 +53,8 @@ public:
typedef typename InputImageType::ConstPointer InputImageConstPointer;
typedef typename InputImageType::RegionType InputImageRegionType;
typedef typename InputImageType::PixelType InputImagePixelType;
itkStaticConstMacro(InputImageDimension, unsigned int,
TInputImage::ImageDimension);
/** Some PointSet related typedefs. */
typedef typename Superclass::OutputPointSetType OutputPointSetType;
......@@ -103,6 +107,12 @@ protected:
/** 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:
ImageToPointSetFilter(const ImageToPointSetFilter&); //purposely not implemented
void operator=(const ImageToPointSetFilter&); //purposely not implemented
......
......@@ -20,7 +20,6 @@
#include "otbImageToPointSetFilter.h"
namespace otb
{
......@@ -39,6 +38,10 @@ ImageToPointSetFilter<TInputImage,TOutputPointSet>
ProcessObjectType::SetNumberOfRequiredOutputs(1);
ProcessObjectType::SetNthOutput(0, output.GetPointer());
// create default region splitter
m_RegionSplitter = itk::ImageRegionSplitter<itkGetStaticConstMacro(InputImageDimension)>::New();
}
/**
......@@ -128,31 +131,69 @@ void
ImageToPointSetFilter<TInputImage,TOutputPointSet>
::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
ThreadStruct str;
str.Filter = this;
PointsContainerType * outputPointsContainer = this->GetOutput()->GetPoints();
outputPointsContainer->Initialize();
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
typename PointsContainerType::Pointer defaultPointsContainer = PointsContainerType::New();
this->m_PointsContainerPerThread
= OutputPointsContainerForThreadType(this->GetNumberOfThreads(),defaultPointsContainer);
// Set up the multithreaded processing
ThreadStruct str;
str.Filter = this;
// 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
this->GetMultiThreader()->SingleMethodExecute();
// Setting up multithreader
this->GetMultiThreader()->SetNumberOfThreads(this->GetNumberOfThreads());
this->GetMultiThreader()->SetSingleMethod(this->ThreaderCallback, &str);
// Call a method that can be overridden by a subclass to perform
// some calculations after all the threads have completed
this->AfterThreadedGenerateData();
// multithread the execution
this->GetMultiThreader()->SingleMethodExecute();
// 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
ImageToPointSetFilter<TInputImage,TOutputPointSet>
::BeforeThreadedGenerateData(void)
{
// this->AllocateOutputs();
}
template <class TInputImage, class TOutputPointSet>
......@@ -171,7 +212,7 @@ ImageToPointSetFilter<TInputImage,TOutputPointSet>
{
// copy the lists to the output
PointsContainerType * outputPointsContainer = this->GetOutput()->GetPoints();
outputPointsContainer->Initialize();
typedef typename PointsContainerType::ConstIterator OutputPointsContainerIterator;
for (unsigned int i=0; i< this->m_PointsContainerPerThread.size(); ++i)
{
......@@ -245,14 +286,14 @@ ImageToPointSetFilter<TInputImage,TOutputPointSet>
// Get the output pointer
typename InputImageType::ConstPointer inputPtr = this->GetInput();
const typename TInputImage::SizeType& requestedRegionSize
= inputPtr->GetLargestPossibleRegion().GetSize();
= inputPtr->GetRequestedRegion().GetSize();
int splitAxis;
typename TInputImage::IndexType splitIndex;
typename TInputImage::SizeType splitSize;
// Initialize the splitRegion to the output requested region
splitRegion = inputPtr->GetLargestPossibleRegion();
splitRegion = inputPtr->GetRequestedRegion();
splitIndex = splitRegion.GetIndex();
splitSize = splitRegion.GetSize();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment