Orfeo Toolbox  3.16
otbSparseWvltToAngleMapperListFilter.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 __otbSparseWvltToAngleMapperListFilter_txx
19 #define __otbSparseWvltToAngleMapperListFilter_txx
21 
22 #include <vnl/vnl_math.h>
23 
24 #include "itkProgressReporter.h"
25 
26 namespace otb {
27 
28 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
31 {
32  this->SetNumberOfRequiredInputs(NumberOfInputImages);
33 
34  // Generate the output sample list
35  typename OutputSampleListObjectType::Pointer outputPtr =
36  static_cast< OutputSampleListObjectType * >(this->MakeOutput(0).GetPointer());
37  this->ProcessObject::SetNthOutput(0, outputPtr.GetPointer());
38 
39  m_ThresholdValue = static_cast<ValueType>( 10. );
40 }
41 
42 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
43 void
45 ::SetInput ( unsigned int i, const InputImageListType * img )
46 {
48  const_cast< InputImageListType * >( img ) );
49 }
50 
51 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
52 const TInputImageList *
54 ::GetInput ( unsigned int i ) const
55 {
56  if ( i >= this->GetNumberOfInputs() )
57  {
58  return 0;
59  }
60 
61  return static_cast<const InputImageListType * >
62  (this->itk::ProcessObject::GetInput(i) );
63 }
64 
65 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
67 ::DataObjectPointer
69 ::MakeOutput(unsigned int itkNotUsed(idx))
70 {
71  typename OutputSampleListObjectType::Pointer outputPtr = OutputSampleListObjectType::New();
72  OutputSampleListPointer outputSampleList = OutputSampleListType::New();
73  outputPtr->Set(outputSampleList);
74  return static_cast<DataObjectPointer>(outputPtr);
75 }
76 
77 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
79 ::OutputSampleListType *
82 {
83  typename OutputSampleListObjectType::Pointer dataObjectPointer
84  = static_cast<OutputSampleListObjectType * > (this->ProcessObject::GetOutput(0) );
85  return const_cast<OutputSampleListType *>(dataObjectPointer->Get());
86 }
87 
88 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
90 ::OutputSampleListObjectType *
93 {
94  return static_cast<OutputSampleListObjectType * >
95  (this->ProcessObject::GetOutput(0) );
96 }
97 
98 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
99 void
101 ::PrintSelf(std::ostream& os, itk::Indent indent) const
102 {
103  Superclass::PrintSelf(os, indent);
104  os << indent << "Threshold : " << m_ThresholdValue << "\n";
105 }
106 
107 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
108 void
111 {
112  InputImageListConstIteratorVectorType it ( NumberOfInputImages );
113  for ( unsigned int i = 0; i < NumberOfInputImages; ++i )
114  it[i] = this->GetInput(i)->Begin();
115 
116  OutputSampleListType * outputList = this->GetOutputSampleList();
117 
118  // Set-up progress reporting
119  itk::ProgressReporter progress(this, 0, this->GetInput(0)->Size());
120 
121  bool iteratorsNotAtEnd = true;
122  while ( iteratorsNotAtEnd )
123  {
124  ImageConstIteratorVectorType imgIt ( NumberOfInputImages );
125  for ( unsigned int i = 0; i < NumberOfInputImages; ++i )
126  {
127  imgIt[i] = ImageConstIteratorType( it[i].Get(), it[i].Get()->GetLargestPossibleRegion() );
128  imgIt[i].GoToBegin();
129  }
130 
131  bool localIteratorsNotAtEnd = true;
132  while ( localIteratorsNotAtEnd )
133  {
134  if ( IsToGenerate( imgIt ) )
135  {
136  outputList->PushBack( GenerateData( imgIt ) );
137  }
138 
139  for ( unsigned int i = 0; i < NumberOfInputImages; ++i )
140  {
141  ++(imgIt[i]);
142  if ( imgIt[i].IsAtEnd() )
143  localIteratorsNotAtEnd = false;
144  }
145  }
146 
147  for ( unsigned int i = 0; i < NumberOfInputImages; ++i )
148  {
149  ++(it[i]);
150  if ( it[i] != this->GetInput(i)->End() )
151  iteratorsNotAtEnd = false;
152  }
153 
154  progress.CompletedPixel();
155  }
156 }
157 
158 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
159 bool
162 {
163  for ( unsigned int i = 0; i < NumberOfInputImages; ++i )
164  {
165  if ( it[i].Get() < m_ThresholdValue )
166  return false;
167  }
168 
169  return true;
170 }
171 
172 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
174 ::OutputMeasurementVectorType
177 {
178  return FromEuclideanToSphericalSpace( it );
179 }
180 
181 template < class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages >
183 ::OutputMeasurementVectorType
186 ( const ImageConstIteratorVectorType & it ) const
187 {
188  // First, get the modulus of the vector
189  double modulus = 0;
190  for ( unsigned int i = 0; i < NumberOfInputImages; ++i )
191  {
192  modulus += vcl_pow( static_cast<double>( it[i].Get() ), 2. );
193  }
194  // The modulus cannot be nul since it is over the threshold...
195  modulus = vcl_sqrt( modulus );
196 
197  // FIXME test if NaN nor infinite
198 
200  angle.Fill( static_cast< OutputValueType >( 0. ) );
201 
202  if ( NumberOfInputImages == 2 )
203  {
204  if ( it[1].Get() < 0 )
205  {
206  angle[0] = vcl_acos( it[0].Get() / modulus );
207  }
208  else
209  {
210  angle[0] = - vcl_acos( it[0].Get() / modulus );
211  }
212  }
213  else
214  {
215  for ( unsigned int k = 0; k < angle.Size()-1; ++k )
216  {
217  double phase = vcl_acos( it[k].Get() / modulus );
218  angle[k] = phase;
219  modulus *= vcl_sin( phase );
220 
221  // FIXME test also if not finite
222  if ( modulus < 1e-5 )
223  {
224  while ( ++k < angle.Size() )
225  angle[k] = 0.;
226  return angle;
227  }
228  }
229 
230  /*
231  * With this sign modification, we can put the same
232  * images for all the components and recover the good direction
233  */
234  double sign = NumberOfInputImages == 3 ? -1. : 1.;
235  if ( it[ NumberOfInputImages-1 ].Get() < 0 )
236  {
237  angle[ angle.Size()-1 ] = sign * vcl_acos( it[ NumberOfInputImages-2 ].Get() / modulus );
238  }
239  else
240  {
241  angle[ angle.Size()-1 ] = - sign * vcl_acos( it[ NumberOfInputImages-2 ].Get() / modulus );
242  }
243  }
244 
245  return angle;
246 }
247 
248 } // end of namespace otb
249 
250 #endif
251 

Generated at Sun Jun 16 2013 00:50:45 for Orfeo Toolbox with doxygen 1.8.3.1