OTB  9.0.0
Orfeo Toolbox
otbWaveletsSynopsisImageToWaveletsBandsListFilter.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 otbWaveletsSynopsisImageToWaveletsBandsListFilter_hxx
22 #define otbWaveletsSynopsisImageToWaveletsBandsListFilter_hxx
23 
25 
26 namespace otb
27 {
29 template <class TImage, class TImageList>
31  : m_NumberOfLevels(1), m_DecimationRatio(2), m_ExtractFilters(), m_ExtractFiltersUpToDate(false)
32 {
33 }
34 
36 template <class TImage, class TImageList>
38 {
39  m_ExtractFilters.clear();
40 }
41 
43 template <class TImage, class TImageList>
45 {
46  // Call superclass implementation
47  Superclass::Modified();
48  m_ExtractFiltersUpToDate = false;
49 }
51 
53 template <class TImage, class TImageList>
55 {
56  typename OutputImageListType::Pointer outputPtr = this->GetOutput();
57  typename InputImageType::ConstPointer inputPtr = this->GetInput();
59 
60  // Check if we need to regenerate the extract filters
61  if (inputPtr && !m_ExtractFiltersUpToDate)
62  {
63  // Retrieve image size
64  typename RegionType::SizeType largestSize = inputPtr->GetLargestPossibleRegion().GetSize();
65 
66  // Compute the number of output images
67  unsigned int numberOfOutputImages = m_NumberOfLevels * 3 + 1;
68 
69  // Clear the output image list
70  outputPtr->Clear();
71 
72  // Clear the extract filter vector
73  m_ExtractFilters.clear();
74 
75  // For each output image
76  for (unsigned int i = 0; i < numberOfOutputImages; ++i)
77  {
78  // Build the current extract filter
79  typename ExtractFilterType::Pointer currentExtract = ExtractFilterType::New();
80  currentExtract->SetInput(inputPtr);
81 
82  // Add it to the filter list
83  m_ExtractFilters.push_back(currentExtract);
84 
85  // Add its output to the filter's output
86  outputPtr->PushBack(currentExtract->GetOutput());
87 
88  // Build the corresponding region
89  RegionType currentRegion;
90  typename RegionType::IndexType currentIndex;
91  typename RegionType::SizeType currentSize;
92  currentIndex.Fill(0);
93 
94  // If this is not the first sub-band
95  if (i > 0)
96  {
97  // Compute current sub-band and level
98  unsigned int currentLevel = (i - 1) / 3;
99  unsigned int currentSubBand = (i - 1) % 3;
100 
101  unsigned int offsetX = largestSize[0] / (unsigned int)std::pow((double)m_DecimationRatio, (double)m_NumberOfLevels - currentLevel);
102  unsigned int offsetY = largestSize[1] / (unsigned int)std::pow((double)m_DecimationRatio, (double)m_NumberOfLevels - currentLevel);
103 
104  // Compute current size
105  currentSize[0] = offsetX;
106  currentSize[1] = offsetY;
107 
108  // Compute current index
109  if (currentSubBand == 0)
110  {
111  currentIndex[0] += offsetX;
112  }
113  else if (currentSubBand == 1)
114  {
115  currentIndex[1] = offsetY;
116  }
117  else
118  {
119  currentIndex[0] = offsetX;
120  currentIndex[1] = offsetY;
121  }
122  }
123  else
124  {
125  // The coarsest scale size
126  currentSize[0] = largestSize[0] / (unsigned int)std::pow((double)m_DecimationRatio, (double)m_NumberOfLevels);
127  currentSize[1] = largestSize[1] / (unsigned int)std::pow((double)m_DecimationRatio, (double)m_NumberOfLevels);
128  }
129  // Build current region
130  currentRegion.SetIndex(currentIndex);
131  currentRegion.SetSize(currentSize);
132  // std::cout<<"Band: "<<i<<", region "<<currentRegion<<std::endl;
133  currentExtract->SetRegionOfInterest(currentRegion);
134  }
135  m_ExtractFiltersUpToDate = true;
136  }
137 }
139 template <class TImage, class TImageList>
141 {
142  typename InputImageType::Pointer inputPtr = this->GetInput();
143 
144  if (inputPtr)
145  {
146  inputPtr->SetRequestedRegionToLargestPossibleRegion();
147  }
148 }
152 template <class TImage, class TImageList>
154 {
155  // Update each extract fillter
156  for (typename ExtractFilterVectorType::iterator it = m_ExtractFilters.begin(); it != m_ExtractFilters.end(); ++it)
157  {
158  (*it)->Update();
159  }
160 }
161 
otb::WaveletsSynopsisImageToWaveletsBandsListFilter::GenerateInputRequestedRegion
virtual void GenerateInputRequestedRegion(void) override
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbWaveletsSynopsisImageToWaveletsBandsListFilter.h
otb::WaveletsSynopsisImageToWaveletsBandsListFilter::GenerateData
virtual void GenerateData(void) override
otb::WaveletsSynopsisImageToWaveletsBandsListFilter::~WaveletsSynopsisImageToWaveletsBandsListFilter
virtual ~WaveletsSynopsisImageToWaveletsBandsListFilter()
otb::WaveletsSynopsisImageToWaveletsBandsListFilter::GenerateOutputInformation
virtual void GenerateOutputInformation(void) override
otb::WaveletsSynopsisImageToWaveletsBandsListFilter::Modified
virtual void Modified() const override
otb::WaveletsSynopsisImageToWaveletsBandsListFilter::WaveletsSynopsisImageToWaveletsBandsListFilter
WaveletsSynopsisImageToWaveletsBandsListFilter()