OTB  6.7.0
Orfeo Toolbox
otbDecimateImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 
23 #ifndef otbDecimateImageFilter_hxx
24 #define otbDecimateImageFilter_hxx
25 
26 #include "otbDecimateImageFilter.h"
27 
28 #include "otbMacro.h"
30 #include "itkImageRegionIterator.h"
31 #include "itkProgressReporter.h"
32 
33 namespace otb {
34 
35 template <class TInputImage, class TOutputImage>
36 void
38 ::PrintSelf(std::ostream& os, itk::Indent indent) const
39 {
40  Superclass::PrintSelf(os, indent);
41  os << indent << "DecimationFactor = " << m_DecimationFactor << "\n";
42 }
43 
44 template <class TInputImage, class TOutputImage>
45 void
48 {
49  Superclass::GenerateOutputInformation();
50 
51  if (GetDecimationFactor() > 1)
52  {
53  this->GetOutput()->CopyInformation(this->GetInput());
54 
55  OutputImageRegionType newRegion;
56  this->CallCopyInputRegionToOutputRegion(newRegion, this->GetInput()->GetLargestPossibleRegion());
57  this->GetOutput()->SetRegions(newRegion);
58 
59  for (unsigned int i = 0; i < OutputImageDimension; ++i)
60  {
61  otbGenericMsgDebugMacro(<< "Image Output size [" << i << "] = " << newRegion.GetSize(i));
62  }
63  }
64 }
65 
66 template <class TInputImage, class TOutputImage>
67 void
70  (InputImageRegionType& destRegion, const OutputImageRegionType& srcRegion)
71 {
72  Superclass::CallCopyOutputRegionToInputRegion(destRegion, srcRegion);
73 
74  typename OutputImageRegionType::IndexType srcIndex = srcRegion.GetIndex();
75  typename OutputImageRegionType::SizeType srcSize = srcRegion.GetSize();
76 
77  typename InputImageRegionType::IndexType destIndex;
78  typename InputImageRegionType::SizeType destSize;
79 
80  for (unsigned int i = 0; i < InputImageDimension; ++i)
81  {
82  destIndex[i] = srcIndex[i] * GetDecimationFactor();
83  destSize[i] = (srcSize[i] - 1) * GetDecimationFactor() + 1;
84  }
85 
86  destRegion.SetIndex(destIndex);
87  destRegion.SetSize(destSize);
88 }
89 
90 template <class TInputImage, class TOutputImage>
91 void
94  (OutputImageRegionType& destRegion, const InputImageRegionType& srcRegion)
95 {
96  Superclass::CallCopyInputRegionToOutputRegion(destRegion, srcRegion);
97 
98  typename InputImageRegionType::IndexType srcIndex = srcRegion.GetIndex();
99  typename InputImageRegionType::SizeType srcSize = srcRegion.GetSize();
100 
101  typename OutputImageRegionType::IndexType destIndex;
102  typename OutputImageRegionType::SizeType destSize;
103 
104  for (unsigned int i = 0; i < InputImageDimension; ++i)
105  {
106  destIndex[i] = srcIndex[i] / GetDecimationFactor();
107  destSize[i] = (srcSize[i] - 1) / GetDecimationFactor() + 1;
108  }
109 
110  destRegion.SetIndex(destIndex);
111  destRegion.SetSize(destSize);
112 }
113 
114 template <class TInputImage, class TOutputImage>
115 void
117 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
118  itk::ThreadIdType itkNotUsed(threadId))
119 {
120  InputImageRegionType inputRegionForThread;
121  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
122 
124  (this->GetInput(), inputRegionForThread);
125  decimationIterator.SetSubsampleFactor(GetDecimationFactor());
126  decimationIterator.GoToBegin();
127 
129  (this->GetOutput(), outputRegionForThread);
130  outputIter.GoToBegin();
131 
132  while (!decimationIterator.IsAtEnd() && !outputIter.IsAtEnd())
133  {
134  outputIter.Set(static_cast<OutputPixelType>(decimationIterator.Get()));
135 
136  ++outputIter;
137  ++decimationIterator;
138  }
139 }
140 
141 } // end of namespace otb
142 
143 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
void Set(const PixelType &value) const
virtual void CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion, const OutputImageRegionType &srcRegion)
#define otbGenericMsgDebugMacro(x)
Definition: otbMacro.h:65
Regular subsample iterator over an image.
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
InputImageType::RegionType InputImageRegionType
virtual void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
unsigned int ThreadIdType
OutputImageType::RegionType OutputImageRegionType
bool IsAtEnd(void) const
virtual void CallCopyInputRegionToOutputRegion(OutputImageRegionType &destRegion, const InputImageRegionType &srcRegion)
PixelType Get(void) const
const SizeValueType * GetSize() const