OTB  9.0.0
Orfeo Toolbox
otbROIdataConversion.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 otbROIdataConversion_hxx
23 #define otbROIdataConversion_hxx
24 
25 #include "itkVector.h"
26 
27 #include "otbROIdataConversion.h"
28 #include "itkImageRegionIterator.h"
29 
30 namespace otb
31 {
32 
33 template <class TInputImage, class TInputROIImage>
35 {
36  this->SetNumberOfRequiredInputs(2);
37  this->SetNumberOfRequiredInputs(2);
38 }
39 
40 template <class TInputImage, class TInputROIImage>
42 {
43  typename OutputImageType::Pointer outputPtr = this->GetOutput();
44  typename OutputImageType::SizeType outputSize = outputPtr->GetRequestedRegion().GetSize();
45  outputSize[0] = GetNumberOfSample();
46  outputPtr->SetRegions(outputSize);
47 }
48 
49 template <class TInputImage, class TInputROIImage>
51 {
52  typename InputImageType::Pointer inputImagePtr = const_cast<InputImageType*>(this->GetInputImage());
53  typename InputROIImageType::Pointer inputROIPtr = this->GetROIImage();
54  inputImagePtr->SetRequestedRegion(inputImagePtr->GetLargestPossibleRegion());
55  inputROIPtr->SetRequestedRegion(inputROIPtr->GetLargestPossibleRegion());
56 }
57 
58 template <class TInputImage, class TInputROIImage>
60 {
61  typename InputImageType::Pointer inputImagePtr = const_cast<InputImageType*>(this->GetInputImage());
62  typename InputROIImageType::ConstPointer inputROIPtr = this->GetROIImage();
63  typename OutputImageType::Pointer outputPtr = this->GetOutput();
64 
65  outputPtr->Allocate();
66  typename InputImageType::PixelType zero;
67  itk::NumericTraits<typename InputImageType::PixelType>::SetLength(zero, outputPtr->GetNumberOfComponentsPerPixel());
68  outputPtr->FillBuffer(zero);
69 
70  itk::ImageRegionConstIterator<InputImageType> inputIter(inputImagePtr, inputImagePtr->GetRequestedRegion());
71  itk::ImageRegionConstIterator<InputROIImageType> trainingIter(inputROIPtr, inputROIPtr->GetRequestedRegion());
72  itk::ImageRegionIterator<OutputImageType> outputIter(outputPtr, outputPtr->GetRequestedRegion());
73 
74  inputIter.GoToBegin();
75  trainingIter.GoToBegin();
76  outputIter.GoToBegin();
77 
78  while (!trainingIter.IsAtEnd())
79  {
80  if (trainingIter.Get() != 0)
81  {
82  outputIter.Set(inputIter.Get());
83  ++outputIter;
84  }
85 
86  ++inputIter;
87  ++trainingIter;
88  }
89 }
90 
91 template <class TInputImage, class TInputROIImage>
93 {
94  InputROIImagePointerType inputROIPtr = GetROIImage();
95  itk::ImageRegionConstIterator<InputROIImageType> trainingIter(inputROIPtr, inputROIPtr->GetRequestedRegion());
96 
97  trainingIter.GoToBegin();
98 
99  SizeValueType count = 0L;
100  while (!trainingIter.IsAtEnd())
101  {
102  if (trainingIter.Get() != 0)
103  count++;
104  ++trainingIter;
105  }
106 
107  return count;
108 }
109 
110 } // end of namespace otb
111 
112 #endif
otb::ROIdataConversion::SizeValueType
OutputImageType::SizeType::SizeValueType SizeValueType
Definition: otbROIdataConversion.h:60
otb::ROIdataConversion::GenerateData
void GenerateData() override
Definition: otbROIdataConversion.hxx:59
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ROIdataConversion::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbROIdataConversion.hxx:41
otb::ROIdataConversion::InputROIImagePointerType
TInputROIImage::Pointer InputROIImagePointerType
Definition: otbROIdataConversion.h:56
otb::ROIdataConversion::ROIdataConversion
ROIdataConversion()
Definition: otbROIdataConversion.hxx:34
otb::ROIdataConversion::GetNumberOfSample
SizeValueType GetNumberOfSample()
Definition: otbROIdataConversion.hxx:92
otbROIdataConversion.h
otb::ROIdataConversion::InputImageType
TInputImage InputImageType
Definition: otbROIdataConversion.h:50
otb::ROIdataConversion::GenerateInputRequestedRegion
void GenerateInputRequestedRegion() override
Definition: otbROIdataConversion.hxx:50