OTB  9.0.0
Orfeo Toolbox
otbAngularProjectionImageFilter.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 otbAngularProjectionImageFilter_hxx
22 #define otbAngularProjectionImageFilter_hxx
24 
25 #include <vnl/vnl_math.h>
26 
27 #include <itkImageRegionIterator.h>
28 #include <itkProgressAccumulator.h>
29 
30 namespace otb
31 {
32 
33 template <class TInputImage, class TOutputImage, class TAngleArray, class TPrecision>
35 {
36  // this->SetNumberOfRequiredInputs(NumberOfInputImages);
37  this->SetNumberOfRequiredOutputs(1);
38 }
39 
40 template <class TInputImage, class TOutputImage, class TAngleArray, class TPrecision>
42 {
43  this->itk::ProcessObject::SetNthInput(i, const_cast<InputImageType*>(img));
44 }
45 
46 template <class TInputImage, class TOutputImage, class TAngleArray, class TPrecision>
48 {
49  if (i >= this->GetNumberOfInputs())
50  {
51  return nullptr;
52  }
53 
54  return static_cast<const InputImageType*>(this->itk::ProcessObject::GetInput(i));
55 }
56 
57 template <class TInputImage, class TOutputImage, class TAngleArray, class TPrecision>
59  itk::ThreadIdType threadId)
60 {
61  itk::ProgressReporter reporter(this, threadId, outputRegionForThread.GetNumberOfPixels());
62 
63  InputImageRegionType inputRegionForThread;
64  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
65 
66  bool iteratorsAtEnd = false;
67  ImageRegionConstIteratorVectorType it(this->GetNumberOfInputs());
68  for (unsigned int i = 0; i < this->GetNumberOfInputs(); ++i)
69  {
70  it[i] = ImageRegionConstIteratorType(this->GetInput(i), inputRegionForThread);
71  it[i].GoToBegin();
72  if (it[i].IsAtEnd())
73  iteratorsAtEnd = true;
74  }
75 
76  itk::ImageRegionIterator<OutputImageType> outIter(this->GetOutput(), outputRegionForThread);
77  outIter.GoToBegin();
78 
79  while (!iteratorsAtEnd && !outIter.IsAtEnd())
80  {
81  outIter.Set(InternalGenerateData(it));
82 
83  ++outIter;
84  for (unsigned int i = 0; i < this->GetNumberOfInputs(); ++i)
85  {
86  ++(it[i]);
87  if (it[i].IsAtEnd())
88  iteratorsAtEnd = true;
89  }
90 
91  reporter.CompletedPixel();
92  }
93 }
94 
95 template <class TInputImage, class TOutputImage, class TAngleArray, class TPrecision>
98 {
99  PrecisionType output = 0;
100 
101  if (this->GetNumberOfInputs() == 2)
102  {
103  PrecisionType alpha = static_cast<PrecisionType>(m_AngleArray[0]);
104  output = static_cast<PrecisionType>(it[0].Get()) * std::cos(alpha) - static_cast<PrecisionType>(it[1].Get()) * std::sin(alpha);
105  }
106  else if (this->GetNumberOfInputs() == 3)
107  {
108  PrecisionType alpha = static_cast<PrecisionType>(m_AngleArray[0]);
109  PrecisionType beta = static_cast<PrecisionType>(m_AngleArray[1]);
110 
111  output = static_cast<PrecisionType>(it[0].Get()) * std::cos(alpha) - static_cast<PrecisionType>(it[1].Get()) * std::sin(alpha) * std::cos(beta) +
112  static_cast<PrecisionType>(it[2].Get()) * std::sin(alpha) * std::sin(beta);
113  }
114  else
115  {
116  unsigned int i = this->GetNumberOfInputs() - 1;
117  output = static_cast<PrecisionType>(it[i--].Get());
118 
119  do
120  {
121  PrecisionType alpha = static_cast<PrecisionType>(m_AngleArray[i]);
122  output = static_cast<PrecisionType>(it[i].Get()) * std::cos(alpha) - output * std::sin(alpha);
123  } while (i-- == 0);
124  }
125 
126  return static_cast<OutputImagePixelType>(output);
127 }
128 
129 } // end of namespace otb
130 
131 #endif
otb::AngularProjectionImageFilter::AngularProjectionImageFilter
AngularProjectionImageFilter()
Definition: otbAngularProjectionImageFilter.hxx:34
otb::AngularProjectionImageFilter::OutputImagePixelType
OutputImageType::PixelType OutputImagePixelType
Definition: otbAngularProjectionImageFilter.h:73
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::AngularProjectionImageFilter::SetInput
void SetInput(unsigned int i, const InputImageType *) override
Definition: otbAngularProjectionImageFilter.hxx:41
otb::AngularProjectionImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbAngularProjectionImageFilter.h:74
otb::AngularProjectionImageFilter::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadID) override
Definition: otbAngularProjectionImageFilter.hxx:58
otbAngularProjectionImageFilter.h
otb::AngularProjectionImageFilter::ImageRegionConstIteratorVectorType
std::vector< ImageRegionConstIteratorType > ImageRegionConstIteratorVectorType
Definition: otbAngularProjectionImageFilter.h:82
otb::AngularProjectionImageFilter::InputImageType
TInputImage InputImageType
Definition: otbAngularProjectionImageFilter.h:65
otb::AngularProjectionImageFilter::GetInput
const InputImageType * GetInput(unsigned int i) const
Definition: otbAngularProjectionImageFilter.hxx:47
otb::AngularProjectionImageFilter::InternalGenerateData
virtual OutputImagePixelType InternalGenerateData(const ImageRegionConstIteratorVectorType &) const
Definition: otbAngularProjectionImageFilter.hxx:97
otb::AngularProjectionImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbAngularProjectionImageFilter.h:67
otb::AngularProjectionImageFilter::PrecisionType
TPrecision PrecisionType
Definition: otbAngularProjectionImageFilter.h:77
otb::AngularProjectionImageFilter::ImageRegionConstIteratorType
itk::ImageRegionConstIterator< InputImageType > ImageRegionConstIteratorType
Definition: otbAngularProjectionImageFilter.h:81