OTB  6.7.0
Orfeo Toolbox
otbAngularProjectionImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 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 >
41 void
43 ::SetInput ( unsigned int i, const InputImageType * img )
44 {
46  const_cast< InputImageType * >( img ) );
47 }
48 
49 template < class TInputImage, class TOutputImage, class TAngleArray, class TPrecision >
50 const TInputImage *
52 ::GetInput ( unsigned int i ) const
53 {
54  if ( i >= this->GetNumberOfInputs() )
55  {
56  return nullptr;
57  }
58 
59  return static_cast<const InputImageType * >
60  (this->itk::ProcessObject::GetInput(i) );
61 }
62 
63 template < class TInputImage, class TOutputImage, class TAngleArray, class TPrecision >
64 void
67  ( const OutputImageRegionType & outputRegionForThread, itk::ThreadIdType threadId )
68 {
69  itk::ProgressReporter reporter(this, threadId,
70  outputRegionForThread.GetNumberOfPixels() );
71 
72  InputImageRegionType inputRegionForThread;
73  this->CallCopyOutputRegionToInputRegion( inputRegionForThread, outputRegionForThread );
74 
75  bool iteratorsAtEnd = false;
76  ImageRegionConstIteratorVectorType it ( this->GetNumberOfInputs() );
77  for ( unsigned int i = 0; i < this->GetNumberOfInputs(); ++i )
78  {
79  it[i] = ImageRegionConstIteratorType( this->GetInput(i), inputRegionForThread );
80  it[i].GoToBegin();
81  if ( it[i].IsAtEnd() )
82  iteratorsAtEnd = true;
83  }
84 
86  ( this->GetOutput(), outputRegionForThread );
87  outIter.GoToBegin();
88 
89  while ( !iteratorsAtEnd && !outIter.IsAtEnd() )
90  {
91  outIter.Set( InternalGenerateData( it ) );
92 
93  ++outIter;
94  for ( unsigned int i = 0; i < this->GetNumberOfInputs(); ++i )
95  {
96  ++(it[i]);
97  if ( it[i].IsAtEnd() )
98  iteratorsAtEnd = true;
99  }
100 
101  reporter.CompletedPixel();
102  }
103 }
104 
105 template < class TInputImage, class TOutputImage, class TAngleArray, class TPrecision >
107 ::OutputImagePixelType
110 {
111  PrecisionType output = 0;
112 
113  if ( this->GetNumberOfInputs() == 2 )
114  {
115  PrecisionType alpha = static_cast<PrecisionType>( m_AngleArray[0] );
116  output = static_cast<PrecisionType>( it[0].Get() ) * std::cos( alpha )
117  - static_cast<PrecisionType>( it[1].Get() ) * std::sin( alpha );
118  }
119  else if ( this->GetNumberOfInputs() == 3 )
120  {
121  PrecisionType alpha = static_cast<PrecisionType>( m_AngleArray[0] );
122  PrecisionType beta = static_cast<PrecisionType>( m_AngleArray[1] );
123 
124  output = static_cast<PrecisionType>( it[0].Get() ) * std::cos( alpha )
125  - static_cast<PrecisionType>( it[1].Get() ) * std::sin( alpha ) * std::cos ( beta )
126  + static_cast<PrecisionType>( it[2].Get() ) * std::sin( alpha ) * std::sin ( beta );
127  }
128  else
129  {
130  unsigned int i = this->GetNumberOfInputs()-1;
131  output = static_cast<PrecisionType>( it[i--].Get() );
132 
133  do {
134  PrecisionType alpha = static_cast<PrecisionType>( m_AngleArray[i] );
135  output = static_cast<PrecisionType>( it[i].Get() ) * std::cos( alpha )
136  - output * std::sin( alpha );
137  } while ( i-- == 0 );
138  }
139 
140  return static_cast<OutputImagePixelType>( output );
141 }
142 
143 } // end of namespace otb
144 
145 #endif
146 
147 
void Set(const PixelType &value) const
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadID) override
InputImageType::RegionType InputImageRegionType
TInputImage InputImageType
Performs spherical transformation in ND space.
const InputImageType * GetInput() const
OutputImageType::PixelType OutputImagePixelType
void SetInput(unsigned int i, const InputImageType *) override
virtual OutputImagePixelType InternalGenerateData(const ImageRegionConstIteratorVectorType &) const
unsigned int ThreadIdType
DataObject * GetInput(const DataObjectIdentifierType &key)
std::vector< ImageRegionConstIteratorType > ImageRegionConstIteratorVectorType
OutputImageType::RegionType OutputImageRegionType
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
bool IsAtEnd(void) const