Skip to content
Snippets Groups Projects
Commit 61228813 authored by Julien Malik's avatar Julien Malik
Browse files

ENH: add neighborhood support for DescriptorsListSampleGenerator

parent eb2797d5
Branches
Tags
No related merge requests found
......@@ -80,15 +80,16 @@ protected:
virtual void GenerateData(void);
private:
PersistentFilterStreamingDecorator(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
/// Object responsible for streaming
StreamerPointerType m_Streamer;
/// Object responsible for computation
FilterPointerType m_Filter;
private:
PersistentFilterStreamingDecorator(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
};
} // End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
......
......@@ -21,6 +21,7 @@
#include <vector>
#include "itkFixedArray.h"
#include "itkImageRegion.h"
#include "otbListSampleSource.h"
#include "otbVectorData.h"
......@@ -145,6 +146,8 @@ public:
SamplesPositionType& GetSamplesPositions();
SamplesPositionObjectType* GetSamplesPositionsObject();
itkSetMacro( NeighborhoodRadius, unsigned int );
itkGetConstReferenceMacro( NeighborhoodRadius, unsigned int );
/** Make a DataObject of the correct type to be used as the specified
* output. */
......@@ -160,17 +163,51 @@ protected:
virtual ~PersistentDescriptorsListSampleGenerator();
void PrintSelf(std::ostream& os, itk::Indent indent) const;
void GenerateInputRequestedRegion();
void BeforeThreadedGenerateData();
/** Multi-thread version GenerateData. */
void ThreadedGenerateData(const RegionType&
outputRegionForThread,
void ThreadedGenerateData(const RegionType& outputRegionForThread,
int threadId);
private:
PersistentDescriptorsListSampleGenerator(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
template <typename TCoordRepType>
bool
IsInsideWithNeighborhoodRadius(const RegionType& region, const ContinuousIndexType &index) const
{
typedef typename RegionType::IndexType IndexType;
typedef typename IndexType::IndexValueType IndexValueType;
for(unsigned int i=0; i<ImageDimension; i++)
{
#ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
if( itk::Math::RoundHalfIntegerUp<IndexValueType>(index[i]) < static_cast<IndexValueType>( region.GetIndex(i) ) + m_NeighborhoodRadius + 1 )
#else
if( index[i] < static_cast<TCoordRepType>( region.GetIndex(i) ) + m_NeighborhoodRadius )
#endif
{
return false;
}
// bound is the last valid pixel location
#ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
const TCoordRepType bound = static_cast<TCoordRepType>(
region.GetIndex(i) + region.GetSize(i) - 0.5);
#else
const TCoordRepType bound = static_cast<TCoordRepType>(
region.GetIndex(i) + static_cast<IndexValueType>(region.GetSize(i)) - 1);
#endif
if( index[i] > bound - m_NeighborhoodRadius - 1 )
{
return false;
}
}
return true;
}
typedef std::vector<ListSamplePointerType> ListSampleArray;
typedef std::vector<LabelListSamplePointerType> LabelListSampleArray;
typedef std::vector<SamplesPositionType> SamplesPositionArray;
......@@ -180,6 +217,8 @@ private:
SamplesPositionArray m_ThreadSamplesPosition;
DescriptorsFunctionPointerType m_DescriptorsFunction;
unsigned int m_NeighborhoodRadius;
};
......@@ -311,6 +350,9 @@ public:
return this->GetFilter()->GetSamplesPositionsObject();
}
otbSetObjectMemberMacro(Filter, NeighborhoodRadius, unsigned int);
otbGetObjectMemberMacro(Filter, NeighborhoodRadius, unsigned int);
protected:
/** Constructor */
DescriptorsListSampleGenerator();
......
......@@ -28,6 +28,7 @@ namespace otb
template <class TInputImage, class TVectorData, class TFunctionType, class TListSample, class TLabelListSample>
PersistentDescriptorsListSampleGenerator<TInputImage,TVectorData,TFunctionType,TListSample,TLabelListSample>
::PersistentDescriptorsListSampleGenerator()
: m_NeighborhoodRadius(0)
{
// Need 2 inputs : a vector image and a vectordata
this->SetNumberOfRequiredInputs(2);
......@@ -237,11 +238,53 @@ PersistentDescriptorsListSampleGenerator<TInputImage,TVectorData,TFunctionType,T
Superclass::PrintSelf(os, indent);
}
template <class TInputImage, class TVectorData, class TFunctionType, class TListSample, class TLabelListSample>
void
PersistentDescriptorsListSampleGenerator<TInputImage,TVectorData,TFunctionType,TListSample,TLabelListSample>
::GenerateInputRequestedRegion()
{
Superclass::GenerateInputRequestedRegion();
// get pointers to the input and output
typename Superclass::InputImagePointer inputPtr =
const_cast< TInputImage * >( this->GetInput() );
typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
if ( !inputPtr || !outputPtr )
{
return;
}
// get a copy of the input requested region (should equal the output
// requested region)
typename TInputImage::RegionType inputRequestedRegion;
inputRequestedRegion = inputPtr->GetRequestedRegion();
// pad the input requested region by the operator radius
inputRequestedRegion.PadByRadius( m_NeighborhoodRadius );
// crop the input requested region at the input's largest possible region
if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
{
inputPtr->SetRequestedRegion( inputRequestedRegion );
return;
}
else
{
// Couldn't crop the region (requested region is outside the largest
// possible region). Throw an exception.
// store what we tried to request (prior to trying to crop)
inputPtr->SetRequestedRegion( inputRequestedRegion );
}
}
template <class TInputImage, class TVectorData, class TFunctionType, class TListSample, class TLabelListSample>
void
PersistentDescriptorsListSampleGenerator<TInputImage,TVectorData,TFunctionType,TListSample,TLabelListSample>
::BeforeThreadedGenerateData()
{
std::cout << "Buffered Region : " << this->GetInput()->GetBufferedRegion() << std::endl;
}
......
......@@ -135,6 +135,7 @@ int otbDescriptorsListSampleGenerator(int argc, char* argv[])
descriptorsGenerator->SetInputImage(imageReader->GetOutput());
descriptorsGenerator->SetSamplesLocations(vectorDataReader->GetOutput());
descriptorsGenerator->SetDescriptorsFunction(descriptorsFunction.GetPointer());
descriptorsGenerator->SetNeighborhoodRadius(5);
if (streaming == 0)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment