From 6ad6ebeab848f043b406c8542221defed5f94fcf Mon Sep 17 00:00:00 2001 From: Manuel Grizonnet <manuel.grizonnet@orfeo-toolbox.org> Date: Wed, 14 Dec 2011 15:30:32 +0100 Subject: [PATCH] BUG:change GroundSpacingImageFunction return value type --- .../otbGroundSpacingImageFunction.h | 19 ++++++++-------- .../otbGroundSpacingImageFunction.txx | 22 ++++++++++++++----- Code/Visualization/otbImageLayer.h | 1 + Code/Visualization/otbImageLayer.txx | 6 ++--- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Code/Projections/otbGroundSpacingImageFunction.h b/Code/Projections/otbGroundSpacingImageFunction.h index 2e3ed3af98..30e706e252 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 a2b0f88613..e0311e4710 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 c019c3e0d3..fbcaafe4ba 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 2056059ea9..e73b51cfdb 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; -- GitLab