21 #ifndef otbVectorImageToImageListFilter_hxx
22 #define otbVectorImageToImageListFilter_hxx
25 #include "itkImageRegionIteratorWithIndex.h"
28 #include "itkProgressReporter.h"
33 template <
class TVectorImageType,
class TImageList>
36 OutputImageListPointerType outputPtr = this->GetOutput();
37 InputVectorImagePointerType inputPtr = this->GetInput();
42 if (outputPtr->Size() != inputPtr->GetNumberOfComponentsPerPixel())
46 for (
unsigned int i = 0; i < inputPtr->GetNumberOfComponentsPerPixel(); ++i)
48 typename OutputImageType::Pointer tmpImagePtr = OutputImageType::New();
49 this->AddOutput(tmpImagePtr);
50 outputPtr->PushBack(tmpImagePtr);
53 for (
unsigned int i = 0; i < inputPtr->GetNumberOfComponentsPerPixel(); ++i)
55 typename OutputImageType::Pointer tmpImagePtr = outputPtr->GetNthElement(i);
56 tmpImagePtr->CopyInformation(inputPtr);
57 tmpImagePtr->SetLargestPossibleRegion(inputPtr->GetLargestPossibleRegion());
58 tmpImagePtr->SetRequestedRegion(inputPtr->GetLargestPossibleRegion());
63 template <
class TVectorImageType,
class TImageList>
66 OutputImageListPointerType outputPtr = this->GetOutput();
67 InputVectorImagePointerType inputPtr = this->GetInput();
72 if (outputPtr->Size() > 0)
74 inputPtr->SetRequestedRegion(outputPtr->GetNthElement(0)->GetRequestedRegion());
81 template <
class TVectorImageType,
class TImageList>
84 OutputImageListPointerType outputPtr = this->GetOutput();
85 InputVectorImagePointerType inputPtr = this->GetInput();
88 typedef itk::ImageRegionConstIteratorWithIndex<InputVectorImageType> InputIteratorType;
89 typedef itk::ImageRegionIteratorWithIndex<OutputImageType> OutputIteratorType;
91 std::vector<OutputIteratorType> outputIteratorList;
93 typename OutputImageListType::ConstIterator outputListIt = outputPtr->Begin();
94 for (; outputListIt != outputPtr->End(); ++outputListIt)
96 outputListIt.Get()->SetBufferedRegion(outputListIt.Get()->GetRequestedRegion());
97 outputListIt.Get()->Allocate();
98 OutputIteratorType tmpIt = OutputIteratorType(outputListIt.Get(), outputListIt.Get()->GetRequestedRegion());
100 outputIteratorList.push_back(tmpIt);
103 InputIteratorType inputIt(inputPtr, outputPtr->GetNthElement(0)->GetRequestedRegion());
105 itk::ProgressReporter progress(
this, 0, outputPtr->GetNthElement(0)->GetRequestedRegion().GetNumberOfPixels());
108 while (!inputIt.IsAtEnd())
110 unsigned int counter = 0;
111 for (
typename std::vector<OutputIteratorType>::iterator it = outputIteratorList.begin(); it != outputIteratorList.end(); ++it)
113 if (!(*it).IsAtEnd())
115 (*it).Set(
static_cast<typename OutputImageType::PixelType
>(inputIt.Get()[counter]));
121 itkGenericExceptionMacro(
"End of image for band " << counter <<
" at index " << (*it).GetIndex() <<
" !");
124 progress.CompletedPixel();