diff --git a/Code/Learning/otbConcatenateSampleListFilter.h b/Code/Learning/otbConcatenateSampleListFilter.h index 0662686345a15271e210d9d7cf14440d067dc27b..22b57ef7a963b8f5aa8fdd2b416079a21327356b 100644 --- a/Code/Learning/otbConcatenateSampleListFilter.h +++ b/Code/Learning/otbConcatenateSampleListFilter.h @@ -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. */ diff --git a/Code/Learning/otbConcatenateSampleListFilter.txx b/Code/Learning/otbConcatenateSampleListFilter.txx index f82a9e33ee3d2195fa0faf8fb066d1aac7691c2d..a18636143c484ca926bacde383d115c0e0401e34 100644 --- a/Code/Learning/otbConcatenateSampleListFilter.txx +++ b/Code/Learning/otbConcatenateSampleListFilter.txx @@ -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 diff --git a/Testing/Code/Learning/otbConcatenateSampleListFilter.cxx b/Testing/Code/Learning/otbConcatenateSampleListFilter.cxx index 0e60cf55e99b89e7f30e0bc15e0a052e10c8923e..3479385639a24fd22166e9b63face7799f88a320 100644 --- a/Testing/Code/Learning/otbConcatenateSampleListFilter.cxx +++ b/Testing/Code/Learning/otbConcatenateSampleListFilter.cxx @@ -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;