OTB  6.7.0
Orfeo Toolbox
otbImageListToSingleImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 
27 #include "itkProgressReporter.h"
29 
30 namespace otb
31 {
35 template <class TImageType>
38  :m_ExtractedImagePosition(0)
39 {
40  this->SetNumberOfRequiredInputs(1);
41  this->SetNumberOfRequiredOutputs(1);
42 }
44 
45 template <class TImageType>
49 {
50  // If there is no input
51  if (this->GetNumberOfInputs() != 1)
52  {
53  // exit
54  return nullptr;
55  }
56  // else return the first input
57  return static_cast<OutputImagePointerType>(
58  this->GetInput()->GetNthElement(m_ExtractedImagePosition));
59 }
60 
64 template <class TImageType>
65 void
68 {
69  OutputImagePointerType outputPtr = this->GetOutput();
70  InputImagePointerType inputPtr = this->GetInput()->GetNthElement(m_ExtractedImagePosition);
72 
74  typedef itk::ImageRegionIteratorWithIndex<OutputImageType> OutputIteratorType;
75 
76  outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
77  outputPtr->Allocate();
78 
79  itk::ProgressReporter progress(this, 0, outputPtr->GetRequestedRegion().GetNumberOfPixels());
80 
81  OutputIteratorType outputIt(outputPtr, outputPtr->GetRequestedRegion());
82  outputIt.GoToBegin();
83 
84  InputIteratorType inputIt(inputPtr, outputPtr->GetRequestedRegion());
85  inputIt.GoToBegin();
86  while (!inputIt.IsAtEnd())
87  {
88 
89  if ( !(outputIt).IsAtEnd())
90  {
91  outputIt.Set(inputIt.Get());
92  ++outputIt;
93  }
94  else
95  {
96  itkGenericExceptionMacro("End of image at index " << outputIt.GetIndex() << " !");
97  }
98  ++inputIt;
99  }
100 }
101 
105 template <class TImageType>
106 void
108 ::PrintSelf(std::ostream& os, itk::Indent indent) const
109 {
110  Superclass::PrintSelf(os, indent);
111 }
112 
113 } // End namespace otb
114 #endif
void PrintSelf(std::ostream &os, itk::Indent indent) const override