Orfeo Toolbox  3.16
otbNNearestPointsLinearInterpolateDeformationFieldGenerator.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 __otbNNearestPointsLinearInterpolateDeformationFieldGenerator_txx
19 #define __otbNNearestPointsLinearInterpolateDeformationFieldGenerator_txx
20 
21 #define EPSILON 1e-15
22 
25 #include "otbMacro.h"
26 
27 namespace otb
28 {
30 template <class TPointSet, class TDeformationField>
31 void
34 {
35  DeformationFieldPointerType outputPtr = this->GetOutput();
36  PixelType defaultValue(2);
37  defaultValue.Fill(this->GetDefaultValue());
38  outputPtr->Allocate();
39  outputPtr->FillBuffer(defaultValue);
40 
42  IteratorType it(outputPtr, outputPtr->GetRequestedRegion());
43 
44  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
45  {
46  IndexType index = it.GetIndex();
47  IndexVectorType indexVector = this->GenerateNearestValidPointsPointSet(it.GetIndex(), m_NumberOfPoints);
48  PixelType pixel(2);
49  double xdeformation, ydeformation, normalization;
50  xdeformation = 0;
51  ydeformation = 0;
52  normalization = 0;
53 
54  for (typename IndexVectorType::iterator indexIt = indexVector.begin(); indexIt != indexVector.end(); ++indexIt)
55  {
56  PointType point;
57  point[0] = static_cast<double>(this->GetPointSet()->GetPoints()->GetElement(*indexIt)[0]);
58  point[1] = static_cast<double>(this->GetPointSet()->GetPoints()->GetElement(*indexIt)[1]);
59  double distance = this->EuclideanDistance(index, point);
60  if (distance < EPSILON)
61  {
62  distance = EPSILON;
63  }
64  xdeformation += this->GetPointSet()->GetPointData()->GetElement((*indexIt))[1] / distance;
65  ydeformation += this->GetPointSet()->GetPointData()->GetElement((*indexIt))[2] / distance;
66  normalization += 1 / distance;
67  }
68 
69  if (normalization > 0)
70  {
71  pixel[0] = static_cast<ValueType>(xdeformation / normalization);
72  pixel[1] = static_cast<ValueType>(ydeformation / normalization);
73  }
74  else
75  {
76  pixel = defaultValue;
77  }
78  it.Set(pixel);
79  }
80 }
84 template <class TPointSet, class TDeformationField>
85 void
87 ::PrintSelf(std::ostream& os, itk::Indent indent) const
88 {
89  Superclass::PrintSelf(os, indent);
90 }
91 } // End namespace otb
92 #endif

Generated at Sun May 19 2013 00:41:58 for Orfeo Toolbox with doxygen 1.8.3.1