OTB  9.0.0
Orfeo Toolbox
otbVectorImageToImageListFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbVectorImageToImageListFilter_hxx
22 #define otbVectorImageToImageListFilter_hxx
23 
25 #include "itkImageRegionIteratorWithIndex.h"
26 #include <vector>
27 #include "otbMacro.h"
28 #include "itkProgressReporter.h"
29 
30 namespace otb
31 {
33 template <class TVectorImageType, class TImageList>
35 {
36  OutputImageListPointerType outputPtr = this->GetOutput();
37  InputVectorImagePointerType inputPtr = this->GetInput();
39 
40  if (inputPtr)
41  {
42  if (outputPtr->Size() != inputPtr->GetNumberOfComponentsPerPixel())
43  {
44  // if the number of components does not match, clear the list
45  outputPtr->Clear();
46  for (unsigned int i = 0; i < inputPtr->GetNumberOfComponentsPerPixel(); ++i)
47  {
48  typename OutputImageType::Pointer tmpImagePtr = OutputImageType::New();
49  this->AddOutput(tmpImagePtr);
50  outputPtr->PushBack(tmpImagePtr);
51  }
52  }
53  for (unsigned int i = 0; i < inputPtr->GetNumberOfComponentsPerPixel(); ++i)
54  {
55  typename OutputImageType::Pointer tmpImagePtr = outputPtr->GetNthElement(i);
56  tmpImagePtr->CopyInformation(inputPtr);
57  tmpImagePtr->SetLargestPossibleRegion(inputPtr->GetLargestPossibleRegion());
58  tmpImagePtr->SetRequestedRegion(inputPtr->GetLargestPossibleRegion());
59  }
60  }
61 }
63 template <class TVectorImageType, class TImageList>
65 {
66  OutputImageListPointerType outputPtr = this->GetOutput();
67  InputVectorImagePointerType inputPtr = this->GetInput();
69 
70  if (inputPtr)
71  {
72  if (outputPtr->Size() > 0)
73  {
74  inputPtr->SetRequestedRegion(outputPtr->GetNthElement(0)->GetRequestedRegion());
75  }
76  }
77 }
81 template <class TVectorImageType, class TImageList>
83 {
84  OutputImageListPointerType outputPtr = this->GetOutput();
85  InputVectorImagePointerType inputPtr = this->GetInput();
87 
88  typedef itk::ImageRegionConstIteratorWithIndex<InputVectorImageType> InputIteratorType;
89  typedef itk::ImageRegionIteratorWithIndex<OutputImageType> OutputIteratorType;
90 
91  std::vector<OutputIteratorType> outputIteratorList;
92 
93  typename OutputImageListType::ConstIterator outputListIt = outputPtr->Begin();
94  for (; outputListIt != outputPtr->End(); ++outputListIt)
95  {
96  outputListIt.Get()->SetBufferedRegion(outputListIt.Get()->GetRequestedRegion());
97  outputListIt.Get()->Allocate();
98  OutputIteratorType tmpIt = OutputIteratorType(outputListIt.Get(), outputListIt.Get()->GetRequestedRegion());
99  tmpIt.GoToBegin();
100  outputIteratorList.push_back(tmpIt);
101  }
102 
103  InputIteratorType inputIt(inputPtr, outputPtr->GetNthElement(0)->GetRequestedRegion());
104 
105  itk::ProgressReporter progress(this, 0, outputPtr->GetNthElement(0)->GetRequestedRegion().GetNumberOfPixels());
106 
107  inputIt.GoToBegin();
108  while (!inputIt.IsAtEnd())
109  {
110  unsigned int counter = 0;
111  for (typename std::vector<OutputIteratorType>::iterator it = outputIteratorList.begin(); it != outputIteratorList.end(); ++it)
112  {
113  if (!(*it).IsAtEnd())
114  {
115  (*it).Set(static_cast<typename OutputImageType::PixelType>(inputIt.Get()[counter]));
116  ++(*it);
117  ++counter;
118  }
119  else
120  {
121  itkGenericExceptionMacro("End of image for band " << counter << " at index " << (*it).GetIndex() << " !");
122  }
123  }
124  progress.CompletedPixel();
125  ++inputIt;
126  }
127 }
otb::VectorImageToImageListFilter::GenerateData
void GenerateData(void) override
otb::VectorImageToImageListFilter::GenerateInputRequestedRegion
void GenerateInputRequestedRegion(void) override
otb::VectorImageToImageListFilter::GenerateOutputInformation
void GenerateOutputInformation(void) override
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otbVectorImageToImageListFilter.h