22 #ifndef otbGroundSpacingImageFunction_hxx
23 #define otbGroundSpacingImageFunction_hxx
26 #include "itkConstNeighborhoodIterator.h"
35 template <
class TInputImage,
class TCoordRep>
45 template <
class TInputImage,
class TCoordRep>
48 this->Superclass::PrintSelf(os, indent);
54 template <
class TInputImage,
class TCoordRep>
60 if (!this->GetInputImage())
62 var.Fill(itk::NumericTraits<ValueType>::min());
66 PointType point = this->GetPixelLocation(index);
70 static_cast<IndexValueType>(std::fabs(
static_cast<ValueType>(this->GetInputImage()->GetLargestPossibleRegion().GetSize()[0] - index[0])));
71 indexSrcX[1] = index[1];
73 indexSrcY[0] = index[0];
74 indexSrcY[1] =
static_cast<IndexValueType>(std::fabs(
static_cast<ValueType>(this->GetInputImage()->GetLargestPossibleRegion().GetSize()[1] - index[1])));
76 PointType pointSrcX = this->GetPixelLocation(indexSrcX);
77 PointType pointSrcY = this->GetPixelLocation(indexSrcY);
79 ValueType dLatX = (std::fabs(pointSrcX[1] - point[1])) * m_Deg2radCoef;
80 ValueType dLonX = (std::fabs(pointSrcX[0] - point[0])) * m_Deg2radCoef;
82 const ValueType One = itk::NumericTraits<ValueType>::One;
85 ValueType aX = std::sin(dLatX / Two) * std::sin(dLatX / Two) +
86 std::cos(point[1] * m_Deg2radCoef) * std::cos(pointSrcX[1] * m_Deg2radCoef) * std::sin(dLonX / Two) * std::sin(dLonX / Two);
87 ValueType cX = Two * std::atan2(std::sqrt(aX), std::sqrt(One - aX));
90 ValueType dLatY = (std::fabs(pointSrcY[1] - point[1])) * m_Deg2radCoef;
91 ValueType dLonY = (std::fabs(pointSrcY[0] - point[0])) * m_Deg2radCoef;
93 ValueType aY = std::sin(dLatY / Two) * std::sin(dLatY / Two) +
94 std::cos(point[1] * m_Deg2radCoef) * std::cos(pointSrcY[1] * m_Deg2radCoef) * std::sin(dLonY / Two) * std::sin(dLonY / Two);
95 ValueType cY = Two * std::atan2(std::sqrt(aY), std::sqrt(One - aY));
99 var[0] = dX / (std::fabs(
static_cast<ValueType>(indexSrcX[0] - index[0])));
100 var[1] = dY / (std::fabs(
static_cast<ValueType>(indexSrcY[1] - index[1])));
105 template <
class TInputImage,
class TCoordRep>
110 inputPoint[0] = index[0];
111 inputPoint[1] = index[1];
113 if (!this->GetInputImage())
115 itkExceptionMacro(<<
"No input image!");
119 transform->SetInputImageMetadata(&(this->GetInputImage()->GetImageMetadata()));
120 transform->SetInputOrigin(this->GetInputImage()->GetOrigin());
123 transform->InstantiateTransform();
125 return transform->TransformPoint(inputPoint);