OTB  9.0.0
Orfeo Toolbox
otbImageListToSingleImageFilter.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 
22 #ifndef otbImageListToSingleImageFilter_hxx
23 #define otbImageListToSingleImageFilter_hxx
24 
25 #include "itkImageRegionConstIteratorWithIndex.h"
26 #include "itkImageRegionIteratorWithIndex.h"
27 #include "itkProgressReporter.h"
29 
30 namespace otb
31 {
35 template <class TImageType>
37 {
38  this->SetNumberOfRequiredInputs(1);
39  this->SetNumberOfRequiredOutputs(1);
40 }
42 
43 template <class TImageType>
45 {
46  // If there is no input
47  if (this->GetNumberOfInputs() != 1)
48  {
49  // exit
50  return nullptr;
51  }
52  // else return the first input
53  return static_cast<OutputImagePointerType>(this->GetInput()->GetNthElement(m_ExtractedImagePosition));
54 }
55 
59 template <class TImageType>
61 {
62  OutputImagePointerType outputPtr = this->GetOutput();
63  InputImagePointerType inputPtr = this->GetInput()->GetNthElement(m_ExtractedImagePosition);
65 
66  typedef itk::ImageRegionConstIteratorWithIndex<InputImageType> InputIteratorType;
67  typedef itk::ImageRegionIteratorWithIndex<OutputImageType> OutputIteratorType;
68 
69  outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
70  outputPtr->Allocate();
71 
72  itk::ProgressReporter progress(this, 0, outputPtr->GetRequestedRegion().GetNumberOfPixels());
73 
74  OutputIteratorType outputIt(outputPtr, outputPtr->GetRequestedRegion());
75  outputIt.GoToBegin();
76 
77  InputIteratorType inputIt(inputPtr, outputPtr->GetRequestedRegion());
78  inputIt.GoToBegin();
79  while (!inputIt.IsAtEnd())
80  {
81 
82  if (!(outputIt).IsAtEnd())
83  {
84  outputIt.Set(inputIt.Get());
85  ++outputIt;
86  }
87  else
88  {
89  itkGenericExceptionMacro("End of image at index " << outputIt.GetIndex() << " !");
90  }
91  ++inputIt;
92  }
93 }
94 
98 template <class TImageType>
99 void ImageListToSingleImageFilter<TImageType>::PrintSelf(std::ostream& os, itk::Indent indent) const
100 {
101  Superclass::PrintSelf(os, indent);
102 }
103 
104 } // End namespace otb
105 #endif
otb::ImageListToSingleImageFilter::GenerateData
void GenerateData() override
Definition: otbImageListToSingleImageFilter.hxx:60
otb::ImageListToSingleImageFilter::OutputImagePointerType
OutputImageType::Pointer OutputImagePointerType
Definition: otbImageListToSingleImageFilter.h:56
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbImageListToSingleImageFilter.h
otb::ImageListToSingleImageFilter::ImageListToSingleImageFilter
ImageListToSingleImageFilter()
Definition: otbImageListToSingleImageFilter.hxx:36
otb::ImageListToSingleImageFilter::InputImagePointerType
InputImageType::Pointer InputImagePointerType
Definition: otbImageListToSingleImageFilter.h:53
otb::ImageListToSingleImageFilter::GetOutput
InputImagePointerType GetOutput(void)
Definition: otbImageListToSingleImageFilter.hxx:44
otb::ImageListToSingleImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbImageListToSingleImageFilter.hxx:99