OTB  10.0.0
Orfeo Toolbox
otbAngularProjectionBinaryImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 otbAngularProjectionBinaryImageFilter_hxx
22 #define otbAngularProjectionBinaryImageFilter_hxx
24 
25 #include <vnl/vnl_math.h>
26 
27 #include "itkImageRegionIterator.h"
28 #include "itkProgressReporter.h"
29 
30 namespace otb
31 {
32 
33 template <class TInputImage, class TOutputImage, class TPrecision>
35 {
36  this->SetNumberOfRequiredInputs(2);
37  this->DynamicMultiThreadingOn();
38 }
39 
40 template <class TInputImage, class TOutputImage, class TPrecision>
42 {
43  this->SetNthInput(0, const_cast<InputImageType*>(inputPtr));
44 }
45 
46 template <class TInputImage, class TOutputImage, class TPrecision>
48 {
49  this->SetNthInput(1, const_cast<InputImageType*>(inputPtr));
50 }
51 
52 template <class TInputImage, class TOutputImage, class TPrecision>
54 {
55  if (this->GetNumberOfInputs() < 1)
56  {
57  return nullptr;
58  }
59 
60  return static_cast<const TInputImage*>(this->itk::ProcessObject::GetInput(0));
61 }
62 
63 template <class TInputImage, class TOutputImage, class TPrecision>
65 {
66  if (this->GetNumberOfInputs() < 2)
67  {
68  return nullptr;
69  }
70 
71  return static_cast<const TInputImage*>(this->itk::ProcessObject::GetInput(1));
72 }
73 
74 template <class TInputImage, class TOutputImage, class TPrecision>
76 {
77  m_AngleSet = angle;
78  this->SetNumberOfRequiredOutputs(angle.size());
79  for (unsigned int i = 0; i < this->GetNumberOfRequiredOutputs(); ++i)
80  {
81  this->SetNthOutput(i, OutputImageType::New());
82  }
83  this->Modified();
84 }
85 
86 template <class TInputImage, class TOutputImage, class TPrecision>
88 {
89  Superclass::GenerateOutputInformation();
90  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
91  {
92  this->GetOutput(i)->SetRegions(this->GetInput()->GetRequestedRegion());
93  }
94 }
95 
96 template <class TInputImage, class TOutputImage, class TPrecision>
98 {
99 
100  InputImageRegionType inputRegionForThread;
101  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
102 
103  itk::ImageRegionConstIterator<InputImageType> iter1(this->GetInput1(), inputRegionForThread);
104  iter1.GoToBegin();
105 
106  itk::ImageRegionConstIterator<InputImageType> iter2(this->GetInput2(), inputRegionForThread);
107  iter2.GoToBegin();
108 
109  std::vector<itk::ImageRegionIterator<OutputImageType>> outIter(this->GetNumberOfOutputs());
110  for (unsigned int i = 0; i < outIter.size(); ++i)
111  {
112  outIter[i] = itk::ImageRegionIterator<OutputImageType>(this->GetOutput(i), outputRegionForThread);
113  outIter[i].GoToBegin();
114  }
115 
116  while (!iter1.IsAtEnd() && !iter2.IsAtEnd())
117  {
118  for (unsigned int i = 0; i < outIter.size(); ++i)
119  {
120  outIter[i].Set(std::cos(m_AngleSet[i]) * iter1.Get() + std::sin(m_AngleSet[i]) * iter2.Get());
121  ++outIter[i];
122  }
123 
124  ++iter1;
125  ++iter2;
126  }
127 }
128 
129 } // end of namespace otb
130 
131 #endif
void SetAngleSet(std::vector< PrecisionType > &angle)
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.