diff --git a/Code/IO/otbDEMHandler.cxx b/Code/IO/otbDEMHandler.cxx index 7b13c8f829ad7b5427ee8df728428d2d934922f7..57584a531249e3dbc8632d9a8a9e56b39c90ef12 100644 --- a/Code/IO/otbDEMHandler.cxx +++ b/Code/IO/otbDEMHandler.cxx @@ -62,7 +62,7 @@ double DEMHandler ::GetHeightAboveMSL(const PointType& geoPoint) { - float height; + double height; ossimGpt ossimWorldPoint; ossimWorldPoint.lat=geoPoint[0]; ossimWorldPoint.lon=geoPoint[1]; diff --git a/Code/IO/otbDEMHandler.h b/Code/IO/otbDEMHandler.h index b9a8a97b02fbca0a208872a185eb14358638bb52..23cd4098a15610705e2f83970c6e8ebae9388920 100755 --- a/Code/IO/otbDEMHandler.h +++ b/Code/IO/otbDEMHandler.h @@ -30,51 +30,51 @@ namespace otb { -/** \class DEMHandler - * - * \brief Class for Reading a DEM data - * - * This class is based on ossimElevManager. - * It allows to obtain height above MSL(Mean Sea Level) of a geographic point - * Handle DTED and SRTM formats. - * \ingroup Images - * - */ - -class ITK_EXPORT DEMHandler: public itk::Object -{ -public : -/** Standard class typedefs. */ - typedef itk::Indent Indent; - typedef DEMHandler Self; - typedef itk::Object Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - typedef itk::Point<double, 2> PointType; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); + /** \class DEMHandler + * + * \brief Class for Reading a DEM data + * + * This class is based on ossimElevManager. + * It allows to obtain height above MSL(Mean Sea Level) of a geographic point + * Handle DTED and SRTM formats. + * \ingroup Images + * + */ + + class ITK_EXPORT DEMHandler: public itk::Object + { + public : + /** Standard class typedefs. */ + typedef itk::Indent Indent; + typedef DEMHandler Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + typedef itk::Point<double, 2> PointType; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(DEMHandler,Object); + + /** Try to open the DEM directory. */ + bool OpenDEMDirectory(const char* DEMDirectory); + + /** Compute the height above MSL(Mean Sea Level) of a geographic point. */ + virtual double GetHeightAboveMSL(const PointType& geoPoint); + + protected: + DEMHandler(); + ~DEMHandler(); + + void PrintSelf(std::ostream& os, Indent indent) const; + + ossimElevManager* m_ElevManager; + + }; - /** Run-time type information (and related methods). */ - itkTypeMacro(DEMHandler,Object); - - /** Try to open the DEM directory. */ - bool OpenDEMDirectory(const char* DEMDirectory); - - /** Compute the height above MSL(Mean Sea Level) of a geographic point. */ - virtual double GetHeightAboveMSL(const PointType& geoPoint); - -protected: - DEMHandler(); - ~DEMHandler(); - - void PrintSelf(std::ostream& os, Indent indent) const; - - ossimElevManager* m_ElevManager; - -}; - } // namespace otb diff --git a/Code/IO/otbDEMReaderFilter.txx b/Code/IO/otbDEMReaderFilter.txx index 144a68e5c4d2cc72b5061ddf2e4ba292daad4e7c..c281d4ed90d5a4a0e3d036635217729ae8a181c5 100755 --- a/Code/IO/otbDEMReaderFilter.txx +++ b/Code/IO/otbDEMReaderFilter.txx @@ -29,13 +29,13 @@ template<class TDEMImage> DEMReaderFilter<TDEMImage> ::DEMReaderFilter() { - m_ElevManager=ossimElevManager::instance(); -//m_DEMImage = DEMImageType::New(); - m_Spacing[0]=0; + m_ElevManager=ossimElevManager::instance(); + //m_DEMImage = DEMImageType::New(); + m_Spacing[0]=0; m_Spacing[1]=0; - m_Ul[0]=0; + m_Ul[0]=0; m_Ul[1]=0; - m_Lr[0]=0; + m_Lr[0]=0; m_Lr[1]=0; } diff --git a/Code/IO/otbDEMToImageGenerator.h b/Code/IO/otbDEMToImageGenerator.h new file mode 100644 index 0000000000000000000000000000000000000000..8fe19521be5d6581d6ff6dabdbfd4ba1d98b13c6 --- /dev/null +++ b/Code/IO/otbDEMToImageGenerator.h @@ -0,0 +1,113 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbDEMToImageGenerator_h +#define __otbDEMToImageGenerator_h + +#include "itkIndent.h" +#include "itkImageSource.h" +#include "otbImage.h" +#include <iostream> +#include <stdio.h> +//#include "elevation/ossimElevManager.h" +#include "otbDEMHandler.h" +#include "base/ossimFilename.h" +#include "itkImageRegionIteratorWithIndex.h" +#include "itkIndent.h" + + +namespace otb +{ + /** \class DEMToImageGenerator + * + * \brief Class for Reading a DEM data + * + * This class is based on ossimElevManager. It takes in input the UL and LR geographic coordinates and the spacing. + * Handle DTED and SRTM formats. + * \ingroup Images + * + */ + template <class TDEMImage> + class ITK_EXPORT DEMToImageGenerator: + public itk::ImageSource<Image<typename TDEMImage::PixelType,2, 0> > + { + public : + /** Standard class typedefs. */ + typedef itk::Indent Indent; + typedef TDEMImage DEMImageType; + typedef typename DEMImageType::Pointer DEMImagePointerType; + typedef typename DEMImageType::PixelType PixelType; + + typedef DEMToImageGenerator Self; + typedef itk::ImageSource<Image<typename DEMImageType::PixelType,2, 0> > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + typedef Image<PixelType,2> OutputImageType; + + typedef typename Superclass::Pointer OutputImagePointer; + typedef typename OutputImageType::SpacingType SpacingType; + typedef typename OutputImageType::SizeType SizeType; + typedef typename OutputImageType::PointType PointType; + typedef typename OutputImageType::IndexType IndexType; + typedef typename Superclass::OutputImageRegionType OutputImageRegionType; + typedef itk::ImageRegionIteratorWithIndex< Image<PixelType,2, 0> > ImageIteratorType; + + typedef otb::DEMHandler DEMHandlerType; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(DEMToImageGenerator,ImageSource); + + /** Set/Get the Output Origin coordinates. */ + itkSetMacro(OutputOrigin,PointType); + itkGetConstReferenceMacro(OutputOrigin,PointType); + + /** Set/Get the Output Size. */ + itkSetMacro(OutputSize,SizeType); + itkGetConstReferenceMacro(OutputSize,SizeType); + + /** Set/Get the Output Spacing. */ + itkSetMacro(OutputSpacing,SpacingType); + itkGetConstReferenceMacro(OutputSpacing,SpacingType); + + /** Set the DEM directory. */ + bool SetDEMDirectoryPath(const char* DEMDirectory); + + + protected: + DEMToImageGenerator(); + ~DEMToImageGenerator(); + + void PrintSelf(std::ostream& os, Indent indent) const; + void GenerateData(); + virtual void GenerateOutputInformation(); + + DEMHandlerType::Pointer m_DEMHandler; + PointType m_OutputOrigin; + SpacingType m_OutputSpacing; + SizeType m_OutputSize; + }; + +} // namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbDEMToImageGenerator.txx" +#endif + +#endif diff --git a/Code/IO/otbDEMToImageGenerator.txx b/Code/IO/otbDEMToImageGenerator.txx new file mode 100644 index 0000000000000000000000000000000000000000..5233629a95e5b8498d99736112ee9b362f9f9f54 --- /dev/null +++ b/Code/IO/otbDEMToImageGenerator.txx @@ -0,0 +1,137 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbDEMToImageGenerator_txx +#define __otbDEMToImageGenerator_txx + +#include "otbDEMToImageGenerator.h" +#include "otbMacro.h" + +namespace otb +{ + + + template<class TDEMImage> + DEMToImageGenerator<TDEMImage> + ::DEMToImageGenerator() + { + m_DEMHandler = DEMHandlerType::New(); + m_OutputSpacing[0]=0.0001; + m_OutputSpacing[1]=0.0001; + m_OutputSize[0]=1; + m_OutputSize[1]=1; + m_OutputOrigin[0]=0; + m_OutputOrigin[1]=0; + } + + template<class TDEMImage> + DEMToImageGenerator<TDEMImage> + ::~DEMToImageGenerator() + { + // Nothing to be done... + } + + // DEM folder specification method + template<class TDEMImage> + bool + DEMToImageGenerator<TDEMImage>:: + SetDEMDirectoryPath(const char* DEMDirectory) + { + bool result = false; + result = m_DEMHandler->OpenDEMDirectory(DEMDirectory); + return result; + } + + // GenerateOutputInformation method + template <class TDEMImage> + void DEMToImageGenerator<TDEMImage> + ::GenerateOutputInformation() + { + DEMImageType *output; + output = this->GetOutput(0); + + IndexType start; + start[0]=0; + start[1]=0; + + // Specify region parameters + OutputImageRegionType largestPossibleRegion; + largestPossibleRegion.SetSize( m_OutputSize ); + largestPossibleRegion.SetIndex( start ); + + output->SetLargestPossibleRegion( largestPossibleRegion ); + output->SetSpacing(m_OutputSpacing); + output->SetOrigin(m_OutputOrigin); + } + + // GenerateData method + template <class TDEMImage> + void + DEMToImageGenerator<TDEMImage> + ::GenerateData() + { + DEMImagePointerType DEMImage = this->GetOutput(); + + // allocate the output buffer + DEMImage->SetBufferedRegion( DEMImage->GetRequestedRegion() ); + DEMImage->Allocate(); + DEMImage->FillBuffer(0); + // Create an iterator that will walk the output region + ImageIteratorType outIt = ImageIteratorType(DEMImage,DEMImage->GetRequestedRegion()); + + // Walk the output image, evaluating the height at each pixel + IndexType currentindex; + PointType phyPoint; + double height; + + for (outIt.GoToBegin(); !outIt.IsAtEnd(); ++outIt) + { + currentindex=outIt.GetIndex(); + DEMImage->TransformIndexToPhysicalPoint(currentindex, phyPoint); + + height=m_DEMHandler->GetHeightAboveMSL(phyPoint); // Altitude calculation + + // MNT sets a default value (-32768) at point where it doesn't have altitude information. + // OSSIM has chosen to change this default value in OSSIM_DBL_NAN (-4.5036e15). + if (height!=static_cast<double>(OSSIM_DBL_NAN)) + { + // Fill the image + DEMImage->SetPixel(currentindex, static_cast<PixelType>(height) ); + } + else + { + // Back to the MNT default value + DEMImage->SetPixel(currentindex, static_cast<PixelType>(-32768) ); + } + } + } + + template <class TDEMImage> + void + DEMToImageGenerator<TDEMImage> + ::PrintSelf(std::ostream& os, Indent indent) const + { + Superclass::PrintSelf(os,indent); + + os << indent << "Output Spacing:"<< m_OutputSpacing[0] << ","<< m_OutputSpacing[1] << std::endl; + os << indent << "Output Origin:"<< m_OutputOrigin[0] << ","<< m_OutputOrigin[1] << std::endl; + os << indent << "Output Size:"<< m_OutputSize[0] << ","<< m_OutputSize[1] << std::endl; + } + +} // namespace otb + +#endif