Commit 407d266d authored by Mickael Savinaud's avatar Mickael Savinaud

ENH: new filter to select one output of an image list

parent bb5473e0
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbImageListToSingleImageFilter_h
#define __otbImageListToSingleImageFilter_h
#include "otbImageListToImageFilter.h"
#include "otbImageList.h"
namespace otb
{
/** \class ImageListToSingleImageFilter
* \brief This class aims at converting a image list to one (scalar or vector) image.
*
* This class takes a image list image represented as an otb::ImageList and produces a
* output which contains of scalar/vector images corresponding to the element selected.
* This filter avoid to break the pipeline after the use of an filter which derive
* from ImageToImagelistFilter class.
*
*
* \ingroup Streamed
*/
template <class TInputImageType>
class ITK_EXPORT ImageListToSingleImageFilter
: public ImageListToImageFilter<TInputImageType, TInputImageType>
{
public:
/** Standard typedefs */
typedef ImageListToSingleImageFilter Self;
typedef ImageListToImageFilter
<TInputImageType, TInputImageType> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef TInputImageType InputImageType;
typedef typename InputImageType::Pointer InputImagePointerType;
typedef ImageList<InputImageType> InputImageListType;
typedef TInputImageType OutputImageType;
typedef typename OutputImageType::Pointer OutputImagePointerType;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(ImageListToSingleImageFilter, ImageListToImageFilter);
/** Set/Get the position of the extracted image from the image list */
itkGetMacro(ExtractedImagePosition, unsigned int);
itkSetMacro(ExtractedImagePosition, unsigned int);
InputImagePointerType GetOutput(void);
protected:
/** Constructor */
ImageListToSingleImageFilter();
/** Destructor */
virtual ~ImageListToSingleImageFilter() {}
/** Main computation method */
virtual void GenerateData();
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
ImageListToSingleImageFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
unsigned int m_ExtractedImagePosition;
}; // end of class
} // end of namespace
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbImageListToSingleImageFilter.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbImageListToSingleImageFilter_txx
#define __otbImageListToSingleImageFilter_txx
#include "otbImageListToSingleImageFilter.h"
namespace otb
{
/**
* Constructor
*/
template <class TImageType>
ImageListToSingleImageFilter<TImageType>
::ImageListToSingleImageFilter()
:m_ExtractedImagePosition(0)
{
this->SetNumberOfRequiredInputs(1);
this->SetNumberOfRequiredOutputs(1);
}
template <class TImageType>
typename ImageListToSingleImageFilter<TImageType>::OutputImagePointerType
ImageListToSingleImageFilter<TImageType>
::GetOutput()
{
// If there is no input
if (this->GetNumberOfInputs() != 1)
{
// exit
return 0;
}
// else return the first input
return static_cast<OutputImagePointerType>(
this->GetInput()->GetNthElement(m_ExtractedImagePosition));
}
/**
* Main computation method
*/
template <class TImageType>
void
ImageListToSingleImageFilter<TImageType>
::GenerateData(void)
{
std::cout << "ImageListToSingleImageFilter::GenerateData" << std::endl;
OutputImagePointerType outputPtr = this->GetOutput();
InputImagePointerType inputPtr = this->GetInput()->GetNthElement(m_ExtractedImagePosition);
typedef itk::ImageRegionConstIteratorWithIndex<InputImageType> InputIteratorType;
typedef itk::ImageRegionIteratorWithIndex<OutputImageType> OutputIteratorType;
outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
outputPtr->Allocate();
itk::ProgressReporter progress(this, 0, outputPtr->GetRequestedRegion().GetNumberOfPixels());
OutputIteratorType outputIt(outputPtr, outputPtr->GetRequestedRegion());
outputIt.GoToBegin();
InputIteratorType inputIt(inputPtr, outputPtr->GetRequestedRegion());
inputIt.GoToBegin();
while (!inputIt.IsAtEnd())
{
if ( !(outputIt).IsAtEnd())
{
outputIt.Set(inputIt.Get());
++outputIt;
}
else
{
itkGenericExceptionMacro("End of image at index " << outputIt.GetIndex() << " !");
}
++inputIt;
}
std::cout << "VectorImageToImagesFilter::GenerateData END" << std::endl;
}
/**
* PrintSelf Method
*/
template <class TImageType>
void
ImageListToSingleImageFilter<TImageType>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // End namespace otb
#endif
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