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