Skip to content
Snippets Groups Projects
Commit 7cc97b49 authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Modifying interface of concatenate sample list filter to allow better...

ENH: Modifying interface of concatenate sample list filter to allow better genericity on the MeasurementVector type
parent 8db4271d
Branches
Tags
No related merge requests found
......@@ -26,20 +26,20 @@ namespace Statistics {
/** \class ConcatenateSampleListFilter
* \brief This class concatenates several sample list into a single one.
*
* Standard casting is applied between input and output type.
*
* For the sake of genericity on the MeasurementVector type, no casting is applied so
* this filter does not allow different input/output SampleList.
*
* \sa ListSampleToListSampleFilter
*/
template < class TInputSampleList, class TOutputSampleList = TInputSampleList >
template < class TSampleList >
class ITK_EXPORT ConcatenateSampleListFilter :
public otb::Statistics::ListSampleToListSampleFilter<TInputSampleList,TOutputSampleList>
public otb::Statistics::ListSampleToListSampleFilter<TSampleList,TSampleList>
{
public:
/** Standard class typedefs */
typedef ConcatenateSampleListFilter Self;
typedef otb::Statistics::ListSampleToListSampleFilter
<TInputSampleList,TOutputSampleList> Superclass;
<TSampleList,TSampleList> Superclass;
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
......@@ -49,26 +49,18 @@ public:
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** InputSampleList typedefs */
typedef TInputSampleList InputSampleListType;
typedef typename InputSampleListType::Pointer InputSampleListPointer;
typedef typename InputSampleListType::ConstPointer InputSampleListConstPointer;
typedef typename InputSampleListType::MeasurementVectorType InputMeasurementVectorType;
typedef typename InputMeasurementVectorType::ValueType InputValueType;
/** OutputSampleList typedefs */
typedef TOutputSampleList OutputSampleListType;
typedef typename OutputSampleListType::Pointer OutputSampleListPointer;
typedef typename OutputSampleListType::ConstPointer OutputSampleListConstPointer;
typedef typename OutputSampleListType::MeasurementVectorType OutputMeasurementVectorType;
typedef typename OutputMeasurementVectorType::ValueType OutputValueType;
/** SampleList typedefs */
typedef TSampleList SampleListType;
typedef typename SampleListType::Pointer SampleListPointer;
typedef typename SampleListType::ConstPointer SampleListConstPointer;
typedef typename SampleListType::MeasurementVectorType MeasurementVectorType;
typedef typename MeasurementVectorType::ValueType ValueType;
typedef typename Superclass::InputSampleListObjectType InputSampleListObjectType;
typedef typename Superclass::OutputSampleListObjectType OutputSampleListObjectType;
typedef typename Superclass::InputSampleListObjectType SampleListObjectType;
/** Method to set/get the input list sample */
void AddInput( const InputSampleListType * inputPtr );
void AddInput( const InputSampleListObjectType * inputPtr );
void AddInput( const SampleListType * inputPtr );
void AddInput( const SampleListObjectType * inputPtr );
protected:
/** This method causes the filter to generate its output. */
......
......@@ -24,39 +24,39 @@
namespace otb {
namespace Statistics {
template < class TInputSampleList, class TOutputSampleList >
ConcatenateSampleListFilter<TInputSampleList,TOutputSampleList>
template < class TSampleList>
ConcatenateSampleListFilter<TSampleList>
::ConcatenateSampleListFilter()
{}
template < class TInputSampleList, class TOutputSampleList >
template <class TSampleList>
void
ConcatenateSampleListFilter<TInputSampleList,TOutputSampleList>
::AddInput( const InputSampleListType * input )
ConcatenateSampleListFilter<TSampleList>
::AddInput( const SampleListType * input )
{
typename InputSampleListObjectType::Pointer inputPtr = InputSampleListObjectType::New();
typename SampleListObjectType::Pointer inputPtr = SampleListObjectType::New();
inputPtr->Set(input);
this->AddInput(inputPtr);
}
template < class TInputSampleList, class TOutputSampleList >
template <class TSampleList>
void
ConcatenateSampleListFilter<TInputSampleList,TOutputSampleList>
::AddInput( const InputSampleListObjectType * inputPtr )
ConcatenateSampleListFilter<TSampleList>
::AddInput( const SampleListObjectType * inputPtr )
{
// Process object is not const-correct so the const_cast is required here
Superclass::ProcessObject::AddInput(const_cast< InputSampleListObjectType* >( inputPtr ) );
Superclass::ProcessObject::AddInput(const_cast< SampleListObjectType* >( inputPtr ) );
}
template < class TInputSampleList, class TOutputSampleList >
template <class TSampleList>
void
ConcatenateSampleListFilter<TInputSampleList,TOutputSampleList>
ConcatenateSampleListFilter<TSampleList>
::GenerateData()
{
// Retrieve output pointers
typename OutputSampleListObjectType::Pointer outputPtr = this->GetOutput();
OutputSampleListPointer outputSampleListPtr = const_cast<OutputSampleListType *>(outputPtr->Get());
typename SampleListObjectType::Pointer outputPtr = this->GetOutput();
SampleListPointer outputSampleListPtr = const_cast<SampleListType *>(outputPtr->Get());
// Clear any previous output
outputSampleListPtr->Clear();
......@@ -67,8 +67,8 @@ ConcatenateSampleListFilter<TInputSampleList,TOutputSampleList>
for(unsigned int inputIndex = 0; inputIndex<this->GetNumberOfInputs();++inputIndex)
{
// Retrieve the ListSample
typename InputSampleListObjectType::ConstPointer inputPtr =
static_cast<InputSampleListObjectType *>(Superclass::ProcessObject::GetInput(inputIndex));
typename SampleListObjectType::ConstPointer inputPtr =
static_cast<SampleListObjectType *>(Superclass::ProcessObject::GetInput(inputIndex));
totalNumberOfSamples += inputPtr->Get()->Size();
}
......@@ -78,31 +78,17 @@ ConcatenateSampleListFilter<TInputSampleList,TOutputSampleList>
for(unsigned int inputIndex = 0; inputIndex<this->GetNumberOfInputs();++inputIndex)
{
// Retrieve the ListSample
typename InputSampleListObjectType::ConstPointer inputPtr =
static_cast<InputSampleListObjectType *>(Superclass::ProcessObject::GetInput(inputIndex));
InputSampleListConstPointer inputSampleListPtr = inputPtr->Get();
typename SampleListObjectType::ConstPointer inputPtr =
static_cast<SampleListObjectType *>(Superclass::ProcessObject::GetInput(inputIndex));
SampleListConstPointer inputSampleListPtr = inputPtr->Get();
typename InputSampleListType::ConstIterator inputIt = inputSampleListPtr->Begin();
typename SampleListType::ConstIterator inputIt = inputSampleListPtr->Begin();
// Iterate on the InputSampleList
while(inputIt != inputSampleListPtr->End())
{
// Retrieve current input sample
InputMeasurementVectorType currentInputMeasurement = inputIt.GetMeasurementVector();
// Build current output sample
OutputMeasurementVectorType currentOutputMeasurement;
currentOutputMeasurement.SetSize(currentInputMeasurement.GetSize());
// Center and reduce each component
for(unsigned int idx = 0;idx < currentInputMeasurement.Size();++idx)
{
currentOutputMeasurement[idx] = static_cast<OutputValueType>(
currentInputMeasurement[idx]);
}
// Add the current output sample to the output SampleList
outputSampleListPtr->PushBack(currentOutputMeasurement);
outputSampleListPtr->PushBack(inputIt.GetMeasurementVector());
// Update progress
progress.CompletedPixel();
......@@ -112,9 +98,9 @@ ConcatenateSampleListFilter<TInputSampleList,TOutputSampleList>
}
}
template < class TInputSampleList, class TOutputSampleList >
template <class TSampleList>
void
ConcatenateSampleListFilter<TInputSampleList,TOutputSampleList>
ConcatenateSampleListFilter<TSampleList>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
// Call superclass implementation
......
......@@ -29,10 +29,7 @@
typedef itk::VariableLengthVector<double> DoubleSampleType;
typedef itk::Statistics::ListSample<DoubleSampleType> DoubleSampleListType;
typedef itk::VariableLengthVector<float> FloatSampleType;
typedef itk::Statistics::ListSample<FloatSampleType> FloatSampleListType;
typedef otb::Statistics::ConcatenateSampleListFilter<FloatSampleListType,DoubleSampleListType> ConcatenateFilterType;
typedef otb::Statistics::ConcatenateSampleListFilter<DoubleSampleListType> ConcatenateFilterType;
int otbConcatenateSampleListFilterNew(int argc, char * argv[])
{
......@@ -49,17 +46,17 @@ int otbConcatenateSampleListFilter(int argc, char * argv[])
unsigned int nbSamples1 = atoi(argv[3]);
unsigned int nbSamples2 = atoi(argv[4]);
FloatSampleListType::Pointer inputSampleList1 = FloatSampleListType::New();
DoubleSampleListType::Pointer inputSampleList1 = DoubleSampleListType::New();
inputSampleList1->SetMeasurementVectorSize(sampleSize);
FloatSampleListType::Pointer inputSampleList2 = FloatSampleListType::New();
DoubleSampleListType::Pointer inputSampleList2 = DoubleSampleListType::New();
inputSampleList2->SetMeasurementVectorSize(sampleSize);
ConcatenateFilterType::Pointer filter = ConcatenateFilterType::New();
filter->AddInput(inputSampleList1);
filter->AddInput(inputSampleList2);
FloatSampleType sample(sampleSize);
DoubleSampleType sample(sampleSize);
unsigned int index = 5;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment