OTB  6.7.0
Orfeo Toolbox
otbROIdataConversion.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 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>
36 {
37  this->SetNumberOfRequiredInputs(2);
38  this->SetNumberOfRequiredInputs(2);
39 }
40 
41 template <class TInputImage, class TInputROIImage>
42 void
45 {
46  typename OutputImageType::Pointer outputPtr = this->GetOutput();
47  typename OutputImageType::SizeType outputSize = outputPtr->GetRequestedRegion().GetSize();
48  outputSize[0] = GetNumberOfSample();
49  outputPtr->SetRegions(outputSize);
50 }
51 
52 template <class TInputImage, class TInputROIImage>
53 void
56 {
57  typename InputImageType::Pointer inputImagePtr = const_cast<InputImageType *>(this->GetInputImage());
58  typename InputROIImageType::Pointer inputROIPtr = this->GetROIImage();
59  inputImagePtr->SetRequestedRegion(inputImagePtr->GetLargestPossibleRegion());
60  inputROIPtr->SetRequestedRegion(inputROIPtr->GetLargestPossibleRegion());
61 }
62 
63 template <class TInputImage, class TInputROIImage>
64 void
67 {
68  typename InputImageType::Pointer inputImagePtr = const_cast<InputImageType *>(this->GetInputImage());
69  typename InputROIImageType::ConstPointer inputROIPtr = this->GetROIImage();
70  typename OutputImageType::Pointer outputPtr = this->GetOutput();
71 
72  outputPtr->Allocate();
73  typename InputImageType::PixelType zero;
74  itk::NumericTraits<typename InputImageType::PixelType>::SetLength(zero, outputPtr->GetNumberOfComponentsPerPixel());
75  outputPtr->FillBuffer(zero);
76 
78  (inputImagePtr, inputImagePtr->GetRequestedRegion());
80  (inputROIPtr, inputROIPtr->GetRequestedRegion());
82  (outputPtr, outputPtr->GetRequestedRegion());
83 
84  inputIter.GoToBegin();
85  trainingIter.GoToBegin();
86  outputIter.GoToBegin();
87 
88  while (!trainingIter.IsAtEnd())
89  {
90  if (trainingIter.Get() != 0)
91  {
92  outputIter.Set(inputIter.Get());
93  ++outputIter;
94  }
95 
96  ++inputIter;
97  ++trainingIter;
98  }
99 }
100 
101 template <class TInputImage, class TInputROIImage>
105 {
106  InputROIImagePointerType inputROIPtr = GetROIImage();
107  itk::ImageRegionConstIterator<InputROIImageType> trainingIter(inputROIPtr, inputROIPtr->GetRequestedRegion());
108 
109  trainingIter.GoToBegin();
110 
111  SizeValueType count = 0L;
112  while (!trainingIter.IsAtEnd())
113  {
114  if (trainingIter.Get() != 0) count++;
115  ++trainingIter;
116  }
117 
118  return count;
119 }
120 
121 } // end of namespace otb
122 
123 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
void GenerateInputRequestedRegion() override
OutputImageType::SizeType::SizeValueType SizeValueType
void GenerateOutputInformation() override
TInputROIImage::Pointer InputROIImagePointerType
static void SetLength(T &m, const unsigned int s)
const SizeValueType * GetSize() const