Orfeo Toolbox  4.0
otbAngularProjectionImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbAngularProjectionImageFilter_txx
19 #define __otbAngularProjectionImageFilter_txx
21 
22 #include <vnl/vnl_math.h>
23 
25 #include <itkImageRegionIterator.h>
26 #include <itkProgressAccumulator.h>
27 
28 namespace otb {
29 
30 template < class TInputImage, class TOutputImage, class TAngleArray, class TPrecision >
33 {
34  //this->SetNumberOfRequiredInputs(NumberOfInputImages);
35  this->SetNumberOfRequiredOutputs(1);
36 }
37 
38 template < class TInputImage, class TOutputImage, class TAngleArray, class TPrecision >
39 void
41 ::SetInput ( unsigned int i, const InputImageType * img )
42 {
44  const_cast< InputImageType * >( img ) );
45 }
46 
47 template < class TInputImage, class TOutputImage, class TAngleArray, class TPrecision >
48 const TInputImage *
50 ::GetInput ( unsigned int i ) const
51 {
52  if ( i >= this->GetNumberOfInputs() )
53  {
54  return 0;
55  }
56 
57  return static_cast<const InputImageType * >
58  (this->itk::ProcessObject::GetInput(i) );
59 }
60 
61 template < class TInputImage, class TOutputImage, class TAngleArray, class TPrecision >
62 void
65  ( const OutputImageRegionType & outputRegionForThread, itk::ThreadIdType threadId )
66 {
67  itk::ProgressReporter reporter(this, threadId,
68  outputRegionForThread.GetNumberOfPixels() );
69 
70  InputImageRegionType inputRegionForThread;
71  this->CallCopyOutputRegionToInputRegion( inputRegionForThread, outputRegionForThread );
72 
73  bool iteratorsAtEnd = false;
74  ImageRegionConstIteratorVectorType it ( this->GetNumberOfInputs() );
75  for ( unsigned int i = 0; i < this->GetNumberOfInputs(); ++i )
76  {
77  it[i] = ImageRegionConstIteratorType( this->GetInput(i), inputRegionForThread );
78  it[i].GoToBegin();
79  if ( it[i].IsAtEnd() )
80  iteratorsAtEnd = true;
81  }
82 
84  ( this->GetOutput(), outputRegionForThread );
85  outIter.GoToBegin();
86 
87  while ( !iteratorsAtEnd && !outIter.IsAtEnd() )
88  {
89  outIter.Set( GenerateData( it ) );
90 
91  ++outIter;
92  for ( unsigned int i = 0; i < this->GetNumberOfInputs(); ++i )
93  {
94  ++(it[i]);
95  if ( it[i].IsAtEnd() )
96  iteratorsAtEnd = true;
97  }
98 
99  reporter.CompletedPixel();
100  }
101 }
102 
103 template < class TInputImage, class TOutputImage, class TAngleArray, class TPrecision >
105 ::OutputImagePixelType
108 {
109  PrecisionType output = 0;
110 
111  if ( this->GetNumberOfInputs() == 2 )
112  {
113  PrecisionType alpha = static_cast<PrecisionType>( m_AngleArray[0] );
114  output = static_cast<PrecisionType>( it[0].Get() ) * vcl_cos( alpha )
115  - static_cast<PrecisionType>( it[1].Get() ) * vcl_sin( alpha );
116  }
117  else if ( this->GetNumberOfInputs() == 3 )
118  {
119  PrecisionType alpha = static_cast<PrecisionType>( m_AngleArray[0] );
120  PrecisionType beta = static_cast<PrecisionType>( m_AngleArray[1] );
121 
122  output = static_cast<PrecisionType>( it[0].Get() ) * vcl_cos( alpha )
123  - static_cast<PrecisionType>( it[1].Get() ) * vcl_sin( alpha ) * vcl_cos ( beta )
124  + static_cast<PrecisionType>( it[2].Get() ) * vcl_sin( alpha ) * vcl_sin ( beta );
125  }
126  else
127  {
128  unsigned int i = this->GetNumberOfInputs()-1;
129  output = static_cast<PrecisionType>( it[i--].Get() );
130 
131  do {
132  PrecisionType alpha = static_cast<PrecisionType>( m_AngleArray[i] );
133  output = static_cast<PrecisionType>( it[i].Get() ) * vcl_cos( alpha )
134  - output * vcl_sin( alpha );
135  } while ( i-- == 0 );
136  }
137 
138  return static_cast<OutputImagePixelType>( output );
139 }
140 
141 } // end of namespace otb
142 
143 #endif
144 
145 

Generated at Sat Mar 8 2014 15:49:57 for Orfeo Toolbox with doxygen 1.8.3.1