diff --git a/Code/Projections/otbGroundSpacingImageFunction.h b/Code/Projections/otbGroundSpacingImageFunction.h index 2e3ed3af986f64049f16d6ba15c92b81c7c19784..30e706e252cd9fd4fd82c604c2c77ee3413b9fba 100644 --- a/Code/Projections/otbGroundSpacingImageFunction.h +++ b/Code/Projections/otbGroundSpacingImageFunction.h @@ -40,13 +40,19 @@ namespace otb */ template <class TInputImage, class TCoordRep = float> class ITK_EXPORT GroundSpacingImageFunction : - public itk::ImageFunction<TInputImage, typename itk::NumericTraits<std::complex<float> >::FloatType, + public itk::ImageFunction<TInputImage, std::pair<float,float>, TCoordRep> { public: /** Standard class typedefs. */ typedef GroundSpacingImageFunction Self; - typedef itk::ImageFunction<TInputImage, typename itk::NumericTraits<std::complex<float> >::FloatType, + + /** Datatype used for the density */ + typedef float ValueType; + typedef std::pair<ValueType, ValueType> FloatType; + + + typedef itk::ImageFunction<TInputImage, FloatType , TCoordRep> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; @@ -66,15 +72,10 @@ public: typedef otb::GenericRSTransform<double> TransformType; - itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); - - /** Datatype used for the density */ - typedef typename itk::NumericTraits<std::complex<float> >::FloatType - FloatType; - typedef typename itk::NumericTraits<std::complex<float> >::ValueType - ValueType; typedef typename IndexType::IndexValueType IndexValueType; + itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); + /** Evalulate the function at specified index */ virtual FloatType EvaluateAtIndex(const IndexType& index) const; diff --git a/Code/Projections/otbGroundSpacingImageFunction.txx b/Code/Projections/otbGroundSpacingImageFunction.txx index a2b0f8861323ed369861f51933abb57c92419779..e0311e4710adaa9e8bd3614c98bbe0eb7ef3a547 100644 --- a/Code/Projections/otbGroundSpacingImageFunction.txx +++ b/Code/Projections/otbGroundSpacingImageFunction.txx @@ -64,7 +64,7 @@ GroundSpacingImageFunction<TInputImage, TCoordRep> { if (!this->GetInputImage()) { - return (itk::NumericTraits<FloatType>::min()); + return (std::make_pair(itk::NumericTraits<ValueType>::min(),itk::NumericTraits<ValueType>::min())); } PointType point = this->GetPixelLocation(index); @@ -104,9 +104,9 @@ GroundSpacingImageFunction<TInputImage, TCoordRep> ValueType cY = Two * vcl_atan2(vcl_sqrt(aY), vcl_sqrt(One - aY)); ValueType dY = m_R * cY; - FloatType var(dX / (vcl_fabs(static_cast<ValueType>(indexSrcX[0] - index[0]))), dY / (vcl_fabs(static_cast<ValueType>( - indexSrcY[1] - - index[1])))); + FloatType var; + var.first = dX / (vcl_fabs(static_cast<ValueType>(indexSrcX[0] - index[0]))); + var.second = dY / (vcl_fabs(static_cast<ValueType>(indexSrcY[1] - index[1]))); return var; } @@ -120,7 +120,19 @@ GroundSpacingImageFunction<TInputImage, TCoordRep> PointType inputPoint; inputPoint[0] = index[0]; inputPoint[1] = index[1]; - return m_Transform->TransformPoint(inputPoint); + if (!this->GetInputImage()) + { + itkExceptionMacro(<< "No input image!"); + } + + TransformType::Pointer transform = TransformType::New(); + const itk::MetaDataDictionary& inputDict = this->GetInputImage()->GetMetaDataDictionary(); + transform->SetInputDictionary(inputDict); + transform->SetInputOrigin(this->GetInputImage()->GetOrigin()); + transform->SetInputSpacing(this->GetInputImage()->GetSpacing()); + + transform->InstanciateTransform(); + return transform->TransformPoint(inputPoint); } } // end namespace otb diff --git a/Code/Visualization/otbImageLayer.h b/Code/Visualization/otbImageLayer.h index c019c3e0d3f3d8ac1f7d7ed03e762092da61f482..fbcaafe4baf8ed476f619b4874666d9684e07550 100644 --- a/Code/Visualization/otbImageLayer.h +++ b/Code/Visualization/otbImageLayer.h @@ -77,6 +77,7 @@ public: typedef otb::GenericRSTransform<double> TransformType; typedef otb::GroundSpacingImageFunction<ImageType> GroundSpacingImageType; typedef typename GroundSpacingImageType::FloatType FloatType; + typedef typename GroundSpacingImageType::ValueType ValueType; /** Output image typedef */ typedef TOutputImage OutputImageType; typedef typename OutputImageType::PixelType OutputPixelType; diff --git a/Code/Visualization/otbImageLayer.txx b/Code/Visualization/otbImageLayer.txx index 2056059ea9a7a0f94faea9b236377cbe34587e5d..e73b51cfdb294429cd8a1808d4ac0e945f0f3707 100644 --- a/Code/Visualization/otbImageLayer.txx +++ b/Code/Visualization/otbImageLayer.txx @@ -69,7 +69,7 @@ ImageLayer<TImage, TOutputImage> m_CountryName = ""; m_GroundSpacing = GroundSpacingImageType::New(); - m_ApproxGroundSpacing = itk::NumericTraits<FloatType>::min(); + m_ApproxGroundSpacing = std::make_pair(itk::NumericTraits<ValueType>::min(),itk::NumericTraits<ValueType>::min()); } template <class TImage, class TOutputImage> @@ -284,9 +284,9 @@ ImageLayer<TImage, TOutputImage> { if (m_Transform->GetTransformAccuracy() != Projection::UNKNOWN) { - PointType point = this->GetPixelLocation (index); + PointType point = m_GroundSpacing->GetPixelLocation (index); - oss << setiosflags(std::ios::fixed) << std::setprecision(2) << "Ground spacing(in m): " << m_ApproxGroundSpacing << + oss << setiosflags(std::ios::fixed) << std::setprecision(2) << "Ground spacing(in m): " << m_ApproxGroundSpacing.first << " " << m_ApproxGroundSpacing.second << std::endl; oss << setiosflags(std::ios::fixed) << std::setprecision(6) << "Lon: " << point[0] << " Lat: " << point[1] << std::endl;