OTB  9.0.0
Orfeo Toolbox
otbProfileDerivativeToMultiScaleCharacteristicsFilter.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 otbProfileDerivativeToMultiScaleCharacteristicsFilter_hxx
22 #define otbProfileDerivativeToMultiScaleCharacteristicsFilter_hxx
23 
25 #include "itkImageRegionIterator.h"
26 #include <vector>
27 #include "otbMacro.h"
28 
29 namespace otb
30 {
31 template <class TInputImage, class TOutputImage, class TLabeledImage>
33 {
34  this->SetNumberOfRequiredOutputs(2);
35  this->SetNthOutput(0, OutputImageType::New());
36  this->SetNthOutput(1, LabeledImageType::New());
37  m_InitialValue = 0;
38  m_Step = 1;
39 }
40 
41 template <class TInputImage, class TOutputImage, class TLabeledImage>
43 {
44  if (this->GetNumberOfOutputs() < 2)
45  {
46  return nullptr;
47  }
48  return static_cast<LabeledImageType*>(this->itk::ProcessObject::GetOutput(1));
49 }
53 template <class TInputImage, class TOutputImage, class TLabeledImage>
55 {
56  InputImageListPointerType inputPtr = this->GetInput();
57  OutputImagePointerType outputPtr = this->GetOutput();
58  LabeledImagePointerType outputLabeledPtr = this->GetOutputCharacteristics();
59  if (inputPtr->Size() > 0)
60  {
61  typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
62  outputPtr->CopyInformation(inputListIt.Get());
63  outputLabeledPtr->CopyInformation(inputListIt.Get());
64  }
65 }
66 
70 template <class TInputImage, class TOutputImage, class TLabeledImage>
72 {
73  InputImageListPointerType inputPtr = this->GetInput();
74  typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
76 
77  RegionType region1 = this->GetOutput()->GetRequestedRegion();
78  RegionType region2 = this->GetOutputCharacteristics()->GetRequestedRegion();
79  RegionType region;
84  if (region1 == this->GetOutput()->GetLargestPossibleRegion() && region2 != this->GetOutputCharacteristics()->GetLargestPossibleRegion())
85  {
86  region = region2;
87  }
88  else if (region1 != this->GetOutput()->GetLargestPossibleRegion() && region2 == this->GetOutputCharacteristics()->GetLargestPossibleRegion())
89  {
90  region = region1;
91  }
92  else
93  {
94  int xul1 = region1.GetIndex()[0];
95  int xul2 = region2.GetIndex()[0];
96  int yul1 = region1.GetIndex()[1];
97  int yul2 = region2.GetIndex()[1];
98  int xlr1 = region1.GetIndex()[0] + region1.GetSize()[0];
99  int xlr2 = region2.GetIndex()[0] + region2.GetSize()[0];
100  int ylr1 = region1.GetIndex()[1] + region1.GetSize()[1];
101  int ylr2 = region2.GetIndex()[1] + region2.GetSize()[1];
103 
104  int xul = std::min(xul1, xul2);
105  int yul = std::min(yul1, yul2);
106  int xlr = std::max(xlr1, xlr2);
107  int ylr = std::max(ylr1, ylr2);
108 
109  typename RegionType::IndexType index;
110  index[0] = xul;
111  index[1] = yul;
112 
113  typename RegionType::SizeType size;
114  size[0] = static_cast<unsigned int>(xlr - xul);
115  size[1] = static_cast<unsigned int>(ylr - yul);
116 
117  region.SetIndex(index);
118  region.SetSize(size);
119  }
120 
121  while (inputListIt != inputPtr->End())
122  {
123  inputListIt.Get()->SetRequestedRegion(region);
124  ++inputListIt;
125  }
126 }
130 template <class TInputImage, class TOutputImage, class TLabeledImage>
132 {
133  OutputImagePointerType outputPtr = this->GetOutput();
134  LabeledImagePointerType outputLabeledPtr = this->GetOutputCharacteristics();
135  InputImageListPointerType inputPtr = this->GetInput();
137 
138  // Output image initializations
139  outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
140  outputPtr->Allocate();
141  outputPtr->FillBuffer(0);
142 
143  outputLabeledPtr->SetBufferedRegion(outputLabeledPtr->GetRequestedRegion());
144  outputLabeledPtr->Allocate();
145  outputLabeledPtr->FillBuffer(0);
146 
147  // defines input and output iterators
148  typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
149  typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
150  typedef itk::ImageRegionIterator<LabeledImageType> LabeledIteratorType;
151 
152  typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
153 
154  // defines a vector of input iterators
155  typedef std::vector<InputIteratorType> InputIteratorListType;
156  InputIteratorListType inputIteratorList;
157 
158  // fills the vector of input iterators
159  for (; inputListIt != inputPtr->End(); ++inputListIt)
160  {
161  inputIteratorList.push_back(InputIteratorType(inputListIt.Get(), inputListIt.Get()->GetRequestedRegion()));
162  inputIteratorList.back().GoToBegin();
163  }
164 
165  // walk through the output images
166  OutputIteratorType outputIt(outputPtr, outputPtr->GetRequestedRegion());
167  outputIt.GoToBegin();
168  LabeledIteratorType labeledIt(outputLabeledPtr, outputLabeledPtr->GetRequestedRegion());
169  labeledIt.GoToBegin();
170 
171  bool inputIteratorsAtEnd = false;
172  for (typename InputIteratorListType::iterator it = inputIteratorList.begin(); it != inputIteratorList.end(); ++it)
173  {
174  inputIteratorsAtEnd = inputIteratorsAtEnd || it->IsAtEnd();
175  }
176 
177  while (!outputIt.IsAtEnd() && !labeledIt.IsAtEnd() && !inputIteratorsAtEnd)
178  {
179  unsigned int index = 0;
180  OutputPixelType outputPixel = 0;
181  LabeledPixelType outputChar = 0;
182 
183  // for each input iterator, check the output and characteristics
184  for (typename InputIteratorListType::iterator it = inputIteratorList.begin(); it != inputIteratorList.end(); ++it)
185  {
186  if (it->Get() > outputPixel)
187  {
188  outputPixel = it->Get();
189  outputChar = m_InitialValue + m_Step * (static_cast<LabeledPixelType>(index));
190  }
191  ++index;
192  }
193  outputIt.Set(outputPixel);
194  labeledIt.Set(outputChar);
195  ++outputIt;
196  ++labeledIt;
197  for (typename InputIteratorListType::iterator it = inputIteratorList.begin(); it != inputIteratorList.end(); ++it)
198  {
199  ++(*it);
200  inputIteratorsAtEnd = inputIteratorsAtEnd || it->IsAtEnd();
201  }
202  }
203 }
otbProfileDerivativeToMultiScaleCharacteristicsFilter.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otb::ProfileDerivativeToMultiScaleCharacteristicsFilter::ProfileDerivativeToMultiScaleCharacteristicsFilter
ProfileDerivativeToMultiScaleCharacteristicsFilter()
otb::ProfileDerivativeToMultiScaleCharacteristicsFilter::GetOutputCharacteristics
virtual TLabeledImage * GetOutputCharacteristics(void)
otb::ProfileDerivativeToMultiScaleCharacteristicsFilter::GenerateData
void GenerateData(void) override
otb::ProfileDerivativeToMultiScaleCharacteristicsFilter::GenerateInputRequestedRegion
void GenerateInputRequestedRegion(void) override
otb::ProfileDerivativeToMultiScaleCharacteristicsFilter::GenerateOutputInformation
void GenerateOutputInformation(void) override