OTB  9.0.0
Orfeo Toolbox
otbVectorImageTo3DScalarImageFilter.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 otbVectorImageTo3DScalarImageFilter_hxx
22 #define otbVectorImageTo3DScalarImageFilter_hxx
23 
25 #include "itkImageRegionConstIterator.h"
26 #include "itkImageSliceIteratorWithIndex.h"
27 
28 namespace otb
29 {
33 template <class TInputImage, class TOutputImage>
35 {
36 }
37 
39 template <class TInputImage, class TOutputImage>
41 {
42 
43  const InputImageType* inputPtr = this->GetInput();
44  OutputImageType* outputPtr = this->GetOutput();
45 
46  InputImageRegionType inputLargestRegion = this->GetInput()->GetLargestPossibleRegion();
47  OutputImageSizeType size;
48  OutputImageIndexType index;
49  for (unsigned int i = 0; i < InputImageType::ImageDimension; ++i)
50  {
51  size[i] = inputLargestRegion.GetSize()[i];
52  index[i] = inputLargestRegion.GetIndex()[i];
53  }
54  size[OutputImageType::ImageDimension - 1] = inputPtr->GetNumberOfComponentsPerPixel();
55  index[OutputImageType::ImageDimension - 1] = 0;
56 
57  OutputImageRegionType outputRegion;
58  outputRegion.SetSize(size);
59  outputRegion.SetIndex(index);
60  outputPtr->SetLargestPossibleRegion(outputRegion);
61 }
63 template <class TInputImage, class TOutputImage>
65 {
66  InputImageType* inputPtr = const_cast<InputImageType*>(this->GetInput());
67  OutputImageType* outputPtr = this->GetOutput();
69 
70  OutputImageRegionType requestedRegion = outputPtr->GetRequestedRegion();
71  InputImageRegionType inputRequestedRegion;
72  InputImageSizeType size;
73  InputImageIndexType index;
74 
75  for (unsigned int i = 0; i < InputImageType::ImageDimension; ++i)
76  {
77  size[i] = requestedRegion.GetSize()[i];
78  index[i] = requestedRegion.GetIndex()[i];
79  }
80  inputRequestedRegion.SetSize(size);
81  inputRequestedRegion.SetIndex(index);
82  inputPtr->SetRequestedRegion(inputRequestedRegion);
83 }
84 template <class TInputImage, class TOutputImage>
85 void VectorImageTo3DScalarImageFilter<TInputImage, TOutputImage>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
86  itk::ThreadIdType itkNotUsed(threadId))
87 {
88  const InputImageType* inputPtr = this->GetInput();
89  OutputImageType* outputPtr = this->GetOutput();
90 
91  typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
92  typedef itk::ImageSliceIteratorWithIndex<OutputImageType> OutputIteratorType;
93 
94  InputImageRegionType inputRegion;
95  InputImageSizeType size;
96  InputImageIndexType index;
97 
98  for (unsigned int i = 0; i < InputImageType::ImageDimension; ++i)
99  {
100  size[i] = outputRegionForThread.GetSize()[i];
101  index[i] = outputRegionForThread.GetIndex()[i];
102  }
103  inputRegion.SetSize(size);
104  inputRegion.SetIndex(index);
105 
106  InputIteratorType inIt(inputPtr, inputRegion);
107 
108  OutputIteratorType outIt(outputPtr, outputRegionForThread);
109  outIt.SetFirstDirection(0);
110  outIt.SetSecondDirection(1);
111 
112  outIt.GoToBegin();
113  inIt.GoToBegin();
114 
115  while (!outIt.IsAtEnd())
116  {
117  outIt.Set(static_cast<OutputPixelType>(inIt.Get()[outIt.GetIndex()[InputImageType::ImageDimension]]));
118  ++inIt;
119  if (inIt.IsAtEnd())
120  {
121  inIt.GoToBegin();
122  }
123  ++outIt;
124  if (outIt.IsAtEndOfLine())
125  {
126  outIt.NextLine();
127  }
128  if (outIt.IsAtEndOfSlice())
129  {
130  outIt.NextSlice();
131  }
132  }
133 }
otb::VectorImageTo3DScalarImageFilter::VectorImageTo3DScalarImageFilter
VectorImageTo3DScalarImageFilter()
otb::VectorImageTo3DScalarImageFilter::GenerateOutputInformation
void GenerateOutputInformation(void) override
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbVectorImageTo3DScalarImageFilter.h
otb::VectorImageTo3DScalarImageFilter::GenerateInputRequestedRegion
void GenerateInputRequestedRegion(void) override
otb::VectorImageTo3DScalarImageFilter::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override