21 #ifndef otbImageListToVectorImageFilter_hxx
22 #define otbImageListToVectorImageFilter_hxx
25 #include "itkImageRegionIterator.h"
28 #include "itkProgressReporter.h"
36 template <
class TImageList,
class TVectorImage>
39 if (this->GetOutput())
41 if (this->GetInput()->Size() > 0)
43 this->GetOutput()->CopyInformation(this->GetInput()->GetNthElement(0));
44 this->GetOutput()->SetNumberOfComponentsPerPixel(this->GetInput()->Size());
45 this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetNthElement(0)->GetLargestPossibleRegion());
50 InputImageListPointerType inputPtr = this->GetInput();
51 typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
53 while (inputListIt != inputPtr->End())
55 const auto & imd = inputListIt.Get()->GetImageMetadata();
58 bandsImd.push_back(imd.Bands[0]);
62 bandsImd.push_back({});
67 this->GetOutput()->SetBandImageMetadata(bandsImd);
74 template <
class TImageList,
class TVectorImage>
77 InputImageListPointerType inputPtr = this->GetInput();
78 typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
79 while (inputListIt != inputPtr->End())
81 inputListIt.Get()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
89 template <
class TImageList,
class TVectorImage>
93 InputImageListPointerType inputPtr = this->GetInput();
94 OutputVectorImagePointerType outputPtr = this->GetOutput();
96 itk::ProgressReporter progress(
this, 0, outputPtr->GetRequestedRegion().GetNumberOfPixels());
99 typename OutputVectorImageType::PixelType black;
100 black.SetSize(inputPtr->Size());
102 outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
103 outputPtr->Allocate();
104 outputPtr->FillBuffer(black);
107 typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
108 typedef itk::ImageRegionIterator<OutputVectorImageType> OutputIteratorType;
110 typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
113 typedef std::vector<InputIteratorType> InputIteratorListType;
114 InputIteratorListType inputIteratorList;
117 for (; inputListIt != inputPtr->End(); ++inputListIt)
119 inputIteratorList.push_back(InputIteratorType(inputListIt.Get(), outputPtr->GetRequestedRegion()));
120 inputIteratorList.back().GoToBegin();
124 OutputIteratorType outputIt(outputPtr, outputPtr->GetRequestedRegion());
125 outputIt.GoToBegin();
127 while (!outputIt.IsAtEnd())
129 typename OutputVectorImageType::PixelType pixel = outputIt.Get();
130 unsigned int counter = 0;
132 for (
typename InputIteratorListType::iterator it = inputIteratorList.begin(); it != inputIteratorList.end(); ++it)
136 pixel[counter] =
static_cast<typename OutputVectorImageType::InternalPixelType
>(it->Get());
142 progress.CompletedPixel();