diff --git a/Code/BasicFilters/otbStreamingResampleImageFilter.txx b/Code/BasicFilters/otbStreamingResampleImageFilter.txx index f57fca4a45b3a53325f901da329dd583b2440c18..bf937ec699f561783901108c158e40544b929f2a 100644 --- a/Code/BasicFilters/otbStreamingResampleImageFilter.txx +++ b/Code/BasicFilters/otbStreamingResampleImageFilter.txx @@ -53,7 +53,7 @@ StreamingResampleImageFilter<TInputImage,TOutputImage,TInterpolatorPrecisionType if ( this->GetInput() ) { - otbMsgDebugMacro(<< "-------------- GenerateInputRequestedRegion ---------------" << std::endl); + otbMsgDevMacro(<< "-------------- GenerateInputRequestedRegion ---------------" << std::endl); InputImagePointer inputImage = const_cast< typename Superclass::InputImageType *>( this->GetInput() ); OutputImagePointer outputImage = const_cast< typename Superclass::OutputImageType *>( this->GetOutput() ); @@ -66,7 +66,7 @@ StreamingResampleImageFilter<TInputImage,TOutputImage,TInterpolatorPrecisionType std::vector<IndexType> vPoints; typename std::vector<IndexType>::iterator it; - otbMsgDebugMacro(<< "Size : " << size[0] << " " << size[1]); + otbMsgDevMacro(<< "Size : " << size[0] << " " << size[1]); indexTmp[0]=index[0]; indexTmp[1]=index[1]; @@ -109,14 +109,14 @@ StreamingResampleImageFilter<TInputImage,TOutputImage,TInterpolatorPrecisionType outputImage->TransformIndexToPhysicalPoint( *it, outputPoint ); - otbMsgDebugMacro(<< "Pour l'Index Ncurrent:(" << (*it)[0]<<","<< (*it)[1] << ")"<< std::endl - << "Le point physique correspondant est: ("<< outputPoint[0]<< ","<< outputPoint[1]<< ")"); + otbMsgDevMacro(<< "Ncurrent Index :(" << (*it)[0]<<","<< (*it)[1] << ")"<< std::endl + << "Physical point: ("<< outputPoint[0]<< ","<< outputPoint[1]<< ")"); // Compute corresponding input pixel continuous index inputPoint = this->GetTransform()->TransformPoint(outputPoint); inputImage->TransformPhysicalPointToContinuousIndex(inputPoint, indexTmpTr); - otbMsgDebugMacro(<< "L'index correspondant a ce point est:" << std::endl + otbMsgDevMacro(<< " -> Point Index:" << std::endl << indexTmpTr[0] << ","<< indexTmpTr[1] ); if (indexTmpTr[0]>maxX) @@ -134,7 +134,7 @@ StreamingResampleImageFilter<TInputImage,TOutputImage,TInterpolatorPrecisionType //otbGenericMsgDebugMacro(<< "indexTr : (" << indexTmpTr[0] << "," << indexTmpTr[1] << ")"); } - otbMsgDebugMacro(<< "MinX : " << minX << " MinY : " << minY << " MaxX : " << maxX << " MaxY " << maxY); + otbMsgDevMacro(<< "MinX : " << minX << " MinY : " << minY << " MaxX : " << maxX << " MaxY " << maxY); // Create region needed in previous filter in the pipeline, which is the bounding box of previous transformed points InputImageRegionType region; @@ -143,7 +143,7 @@ StreamingResampleImageFilter<TInputImage,TOutputImage,TInterpolatorPrecisionType size[0] = static_cast<long unsigned int>(maxX - minX); size[1] = static_cast<long unsigned int>(maxY - minY); - otbMsgDebugMacro(<< "Index : (" << index[0] << "," << index[1] << ") Size : (" << size[0] << "," << size[1] << ")"); + otbMsgDevMacro(<< "Index : (" << index[0] << "," << index[1] << ") Size : (" << size[0] << "," << size[1] << ")"); region.SetSize(size); region.SetIndex(index); @@ -157,13 +157,13 @@ StreamingResampleImageFilter<TInputImage,TOutputImage,TInterpolatorPrecisionType neededRadius = m_InterpolatorNeighborhoodRadius; } - otbMsgDebugMacro(<< "Interpolation needed radius : " << neededRadius); + otbMsgDevMacro(<< "Interpolation needed radius : " << neededRadius); region.PadByRadius(neededRadius+m_AddedRadius); - otbMsgDebugMacro(<< "Initial Region : Index(" << inputImage->GetLargestPossibleRegion().GetIndex()[0] << "," << inputImage->GetLargestPossibleRegion().GetIndex()[1] << ") Size(" << inputImage->GetLargestPossibleRegion().GetSize()[0] << "," << inputImage->GetLargestPossibleRegion().GetSize()[1] << ")"); + otbMsgDevMacro(<< "Initial Region : Index(" << inputImage->GetLargestPossibleRegion().GetIndex()[0] << "," << inputImage->GetLargestPossibleRegion().GetIndex()[1] << ") Size(" << inputImage->GetLargestPossibleRegion().GetSize()[0] << "," << inputImage->GetLargestPossibleRegion().GetSize()[1] << ")"); // To be sure that requested region in pipeline is not largest than real input image - otbMsgDebugMacro(<< "Final Region (Before Crop) : Index(" << region.GetIndex()[0] << "," << region.GetIndex()[1] << ") Size(" << region.GetSize()[0] << "," << region.GetSize()[1] << ")"); + otbMsgDevMacro(<< "Final Region (Before Crop) : Index(" << region.GetIndex()[0] << "," << region.GetIndex()[1] << ") Size(" << region.GetSize()[0] << "," << region.GetSize()[1] << ")"); // If requested region is not contained in input image, then result region is null if (!region.Crop(inputImage->GetLargestPossibleRegion())) @@ -178,7 +178,7 @@ StreamingResampleImageFilter<TInputImage,TOutputImage,TInterpolatorPrecisionType inputImage->SetRequestedRegion(region); - otbMsgDebugMacro(<< "Final Region (After Crop) : Index(" << region.GetIndex()[0] << "," << region.GetIndex()[1] << ") Size(" << region.GetSize()[0] << "," << region.GetSize()[1] << ")"); + otbMsgDevMacro(<< "Final Region (After Crop) : Index(" << region.GetIndex()[0] << "," << region.GetIndex()[1] << ") Size(" << region.GetSize()[0] << "," << region.GetSize()[1] << ")"); } } @@ -190,8 +190,8 @@ StreamingResampleImageFilter<TInputImage,TOutputImage,TInterpolatorPrecisionType ::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os,indent); - - os << indent << "StreamingResampleImageFilter " << std::endl; + os << indent << "m_InterpolatorNeighborhoodRadius: " << m_InterpolatorNeighborhoodRadius<<std::endl; + os << indent << "m_AddedRadius: " <<m_AddedRadius<< std::endl; } diff --git a/Code/Projections/otbOrthoRectificationFilter.h b/Code/Projections/otbOrthoRectificationFilter.h index 2ab39b711944bd5cdef9fd6e3216d3aa45ead821..3ba1f67e087f741cbd1bfac93328087fb9fe465d 100644 --- a/Code/Projections/otbOrthoRectificationFilter.h +++ b/Code/Projections/otbOrthoRectificationFilter.h @@ -18,120 +18,149 @@ PURPOSE. See the above copyright notices for more information. #ifndef __otbOrthoRectificationFilter_h #define __otbOrthoRectificationFilter_h -#include <iostream> -#include <sstream> -#include <stdio.h> - -#include "otbMapProjection.h" -#include "otbInverseSensorModel.h" -#include "otbStreamingResampleImageFilter.h" -#include "otbCompositeTransform.h" -#include "otbInverseSensorModel.h" +#include "otbOrthoRectificationFilterBase.h" +#include "itkImageToImageFilter.h" +#include "itkChangeInformationImageFilter.h" namespace otb { - /** \class OrthoRectificationFilter - * - * \brief Class for Orthorectifying an image - * - * This class is used to apply map projection and sensor model transformation - * to orthorectify an image, with or without DEM. - * - */ +/** \class OrthoRectificationFilter + * + * \brief Class for Orthorectifying an image + * + * This class is used to apply map projection and sensor model transformation + * to orthorectify an image, with or without DEM. + * + */ + +template <class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision=double> +class ITK_EXPORT OrthoRectificationFilter : public itk::ImageToImageFilter< TInputImage, TOutputImage> +{ + public : + /** Standard class typedefs */ + typedef OrthoRectificationFilter Self; + typedef itk::ImageToImageFilter< TInputImage, TOutputImage> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + typedef OrthoRectificationFilterBase< TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision > OrthoRectificationFilterBaseType; + typedef typename OrthoRectificationFilterBaseType::Pointer OrthoRectificationFilterBasePointer; + typedef itk::ChangeInformationImageFilter<TInputImage > ChangeInfoFilterType; + typedef typename ChangeInfoFilterType::Pointer ChangeInfoFilterPointer; + + typedef typename OrthoRectificationFilterBaseType::InputImageType InputImageType; + typedef typename OrthoRectificationFilterBaseType::MapProjectionType MapProjectionType; + typedef typename OrthoRectificationFilterBaseType::InterpolatorType InterpolatorType; + typedef typename OrthoRectificationFilterBaseType::IndexType IndexType; + typedef typename OrthoRectificationFilterBaseType::SizeType SizeType; + typedef typename OrthoRectificationFilterBaseType::PointType PointType; + typedef typename OrthoRectificationFilterBaseType::OriginPointType OriginPointType; + typedef typename OrthoRectificationFilterBaseType::SpacingType SpacingType; + + + /** Method for creation through the object factory. */ + itkNewMacro( Self ); + + /** Run-time type information (and related methods). */ + itkTypeMacro( OrthoRectificationFilter, itk::ImageToImageFilter ); + + /** Accessors */ + virtual void SetMapProjection (MapProjectionType* _arg) + { + m_OrthoRectificationFilter->SetMapProjection( _arg); + } + + virtual MapProjectionType * GetMapProjection() + { + return (m_OrthoRectificationFilter->GetMapProjection()); + } + + /** Specify where are DEM files, and load useful ones */ + virtual void SetDEMDirectory(const std::string& directory) + { + m_OrthoRectificationFilter->SetDEMDirectory(directory); + } + + /** Methods to decide to use DEM */ + virtual void EnableDEM() + { + m_OrthoRectificationFilter->EnableDEM(); + } + virtual void DisableDEM() + { + m_OrthoRectificationFilter->DisableDEM(); + } + + + virtual void SetOutputStartIndex(const IndexType index) + { + m_OrthoRectificationFilter->SetOutputStartIndex(index); + } + virtual const IndexType & GetOutputStartIndex()const + { + return ( m_OrthoRectificationFilter->GetOutputStartIndex()); + } + virtual void SetOutputSpacing(const SpacingType spacing) + { + m_OrthoRectificationFilter->SetOutputSpacing(spacing); + } + virtual const SpacingType & GetOutputSpacing()const + { + return (m_OrthoRectificationFilter->GetOutputSpacing()); + } + virtual void SetOutputOrigin(const OriginPointType origin) + { + m_OrthoRectificationFilter->SetOutputOrigin(origin); + } + virtual const OriginPointType & GetOutputOrigin()const + { + return (m_OrthoRectificationFilter->GetOutputOrigin()); + } + + virtual void SetInterpolator(InterpolatorType * interpol) + { + m_OrthoRectificationFilter->SetInterpolator(interpol); + } + virtual const InterpolatorType * GetInterpolator()const + { + return (m_OrthoRectificationFilter->GetInterpolator()); + } + virtual void SetSize(const SizeType size) + { + m_OrthoRectificationFilter->SetSize(size); + } + virtual const SizeType & GetSize()const + { + return (m_OrthoRectificationFilter->GetSize()); + } + + + protected: + OrthoRectificationFilter(); + ~OrthoRectificationFilter(); + void PrintSelf(std::ostream& os, itk::Indent indent) const; + + /** Main computation method */ + virtual void GenerateData(void); + + /** Generate Output Information */ + virtual void GenerateOutputInformation(); + + private: + OrthoRectificationFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + /** Orthorectification filter */ + OrthoRectificationFilterBasePointer m_OrthoRectificationFilter; + ChangeInfoFilterPointer m_ChangeInfoFilter; - template <class TInputImage, - class TOutputImage, - class TMapProjection, - class TInterpolatorPrecision=double> - class ITK_EXPORT OrthoRectificationFilter : public StreamingResampleImageFilter<TInputImage, - TOutputImage, - TInterpolatorPrecision> - { - public : - /** Standard class typedefs */ - typedef StreamingResampleImageFilter<TInputImage, - TOutputImage, - TInterpolatorPrecision> Superclass; - typedef OrthoRectificationFilter Self; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - typedef typename TInputImage::IndexType IndexType; - typedef typename TInputImage::SizeType SizeType; - typedef typename TInputImage::SpacingType SpacingType; - typedef typename TInputImage::PointType PointType; - typedef typename TInputImage::RegionType RegionType; - - typedef typename TOutputImage::PixelType OutputPixelType; - - typedef TMapProjection MapProjectionType; - typedef typename TMapProjection::Pointer MapProjectionPointerType; - - typedef InverseSensorModel<double> SensorModelType; - typedef typename SensorModelType::Pointer SensorModelPointerType; - - typedef CompositeTransform< MapProjectionType,SensorModelType> CompositeTransformType; - typedef typename CompositeTransformType::Pointer CompositeTransformPointerType; - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - /** Run-time type information (and related methods). */ - itkTypeMacro( OrthoRectificationFilter, StreamingResampleImageFilter ); - - /** Accessors */ - virtual void SetMapProjection (MapProjectionType* _arg) - { - if (this->m_MapProjection != _arg) - { - this->m_MapProjection = _arg; - m_CompositeTransform->SetFirstTransform(_arg); - m_IsComputed = false; - this->Modified(); - } - } - - itkGetObjectMacro(MapProjection, MapProjectionType); - - /** Specify where are DEM files, and load useful ones */ - virtual void SetDEMDirectory(const std::string& directory) - { - m_SensorModel->SetDEMDirectory(directory); - this->Modified(); - } - - /** Methods to decide to use DEM */ - virtual void EnableDEM() { m_SensorModel->EnableDEM(); } - virtual void DisableDEM() { m_SensorModel->DisableDEM(); } - - protected: - OrthoRectificationFilter(); - ~OrthoRectificationFilter(); - void PrintSelf(std::ostream& os, itk::Indent indent) const; - - virtual void GenerateInputRequestedRegion(); - - - private: - OrthoRectificationFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - /** Calculate transformation model from sensor model & map projection composition */ - void ComputeResampleTransformationModel(); - - /** Boolean used to know if transformation model computation is needed */ - bool m_IsComputed; - - /** Sensor Model used to transform geographic coordinates in image sensor index */ - SensorModelPointerType m_SensorModel; - - /** Map Projection used to transform cartographic coordinates in geographic coordinates */ - MapProjectionPointerType m_MapProjection; - - /** Composite Transform of Sensor Model and Map Projection, used for Resampler */ - CompositeTransformPointerType m_CompositeTransform; - - }; +}; } // namespace otb diff --git a/Code/Projections/otbOrthoRectificationFilter.txx b/Code/Projections/otbOrthoRectificationFilter.txx index 7981ba0097db25b27e1eef5e9553068834738b1c..aa941fce5e9b36f643b62c12da51d6196b3fbab4 100644 --- a/Code/Projections/otbOrthoRectificationFilter.txx +++ b/Code/Projections/otbOrthoRectificationFilter.txx @@ -24,99 +24,98 @@ PURPOSE. See the above copyright notices for more information. namespace otb { - template <class TInputImage, - class TOutputImage, - class TMapProjection, - class TInterpolatorPrecision> - OrthoRectificationFilter<TInputImage, - TOutputImage, - TMapProjection, - TInterpolatorPrecision> - ::OrthoRectificationFilter() : StreamingResampleImageFilter<TInputImage, - TOutputImage, - TInterpolatorPrecision>() - { - m_SensorModel = SensorModelType::New(); - m_MapProjection = MapProjectionType::New(); - m_CompositeTransform = CompositeTransformType::New(); - m_IsComputed = false; - } +template < class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> +OrthoRectificationFilter< TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> +::OrthoRectificationFilter() : itk::ImageToImageFilter<TInputImage, TOutputImage>() +{ + m_OrthoRectificationFilter=OrthoRectificationFilterBaseType::New(); + m_ChangeInfoFilter = ChangeInfoFilterType::New(); + m_OrthoRectificationFilter->SetInput(m_ChangeInfoFilter->GetOutput()); + PointType originNull; + originNull.Fill(0); + m_ChangeInfoFilter->ChangeOriginOn(); + m_ChangeInfoFilter->SetOutputOrigin(originNull); + SpacingType spacing; + spacing.Fill(1); + m_ChangeInfoFilter->SetOutputSpacing(spacing); +} - template <class TInputImage, - class TOutputImage, - class TMapProjection, - class TInterpolatorPrecision> - OrthoRectificationFilter<TInputImage, - TOutputImage, - TMapProjection, - TInterpolatorPrecision> - ::~OrthoRectificationFilter() - { - } +template < class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> +OrthoRectificationFilter< TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> +::~OrthoRectificationFilter() +{ + +} - template <class TInputImage, - class TOutputImage, - class TMapProjection, - class TInterpolatorPrecision> - void OrthoRectificationFilter<TInputImage, - TOutputImage, - TMapProjection, - TInterpolatorPrecision> +template < class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> +void +OrthoRectificationFilter< TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> ::PrintSelf(std::ostream& os, itk::Indent indent) const - { - Superclass::PrintSelf(os, indent); - - os << indent << "OrthoRectification" << "\n"; - } - - - template <class TInputImage, - class TOutputImage, - class TMapProjection, - class TInterpolatorPrecision> - void - OrthoRectificationFilter<TInputImage, - TOutputImage, - TMapProjection, - TInterpolatorPrecision> - ::GenerateInputRequestedRegion() - { - this->ComputeResampleTransformationModel(); - - Superclass::GenerateInputRequestedRegion(); - } - - template <class TInputImage, - class TOutputImage, - class TMapProjection, - class TInterpolatorPrecision> - void - OrthoRectificationFilter<TInputImage, - TOutputImage, - TMapProjection, - TInterpolatorPrecision> - ::ComputeResampleTransformationModel() - { - if (m_IsComputed == false) - { - otbMsgDevMacro(<< "COMPUTE RESAMPLE TRANSFORMATION MODEL"); - typename TOutputImage::Pointer output = this->GetOutput(); - - // Get OSSIM sensor model from image keywordlist - m_SensorModel->SetImageGeometry(output->GetImageKeywordlist()); - - // Initialize Map Projection if needed -/* PointType geoPoint; - geoPoint[1] = this->GetOutputOrigin()[1] + this->GetSize()[0]*this->GetOutputSpacing()[0]/2; - geoPoint[0] = this->GetOutputOrigin()[0] + this->GetSize()[1]*this->GetOutputSpacing()[1]/2; - m_MapProjection->Initialize(geoPoint); */ - - m_CompositeTransform->SetFirstTransform(m_MapProjection); - m_CompositeTransform->SetSecondTransform(m_SensorModel); - this->SetTransform(m_CompositeTransform); - m_IsComputed = true; - } - } +{ + Superclass::PrintSelf(os, indent); + os << indent << "m_OrthoRectification:\n" << m_OrthoRectificationFilter<<"\n"; + os << indent << "m_ChangeInfoFilter:\n" << m_ChangeInfoFilter <<"\n"; +} + +template < class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> +void +OrthoRectificationFilter< TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> +::GenerateOutputInformation() +{ + // This must be done so that the orthoRectificationFilter can generate its ouptut information correctly. + m_ChangeInfoFilter->SetInput(this->GetInput()); + m_OrthoRectificationFilter->GenerateOutputInformation(); + this->GetOutput()->CopyInformation(m_OrthoRectificationFilter->GetOutput()); +} + + + + +template < class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> +void +OrthoRectificationFilter< TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> +::GenerateData(void) +{ + // This is done here instead of inside the GenerateData() method so that the pipeline negociation + // use the minipipeline instead of default ITK methods. + m_OrthoRectificationFilter->GraftOutput(this->GetOutput()); + //m_OrthoRectificationFilter->GetOutput()->UpdateOutputInformation(); + //m_OrthoRectificationFilter->GetOutput()->PropagateRequestedRegion(); + //m_OrthoRectificationFilter->GetOutput()->UpdateOutputData(); + m_OrthoRectificationFilter->Update(); + this->GraftOutput(m_OrthoRectificationFilter->GetOutput()); + //m_OrthoRectificationFilter->Update(); +} } //namespace otb diff --git a/Code/Projections/otbOrthoRectificationFilterBase.h b/Code/Projections/otbOrthoRectificationFilterBase.h new file mode 100755 index 0000000000000000000000000000000000000000..88672eed89c2d27d69ff0c1aaa3c0c3288026b93 --- /dev/null +++ b/Code/Projections/otbOrthoRectificationFilterBase.h @@ -0,0 +1,142 @@ +/*========================================================================= + +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 __otbOrthoRectificationFilterBase_h +#define __otbOrthoRectificationFilterBase_h + +#include <iostream> +#include <sstream> +#include <stdio.h> + +#include "otbMapProjection.h" +#include "otbInverseSensorModel.h" +#include "otbStreamingResampleImageFilter.h" +#include "otbCompositeTransform.h" +#include "otbInverseSensorModel.h" + +namespace otb +{ + /** \class OrthoRectificationFilterBase + * + * \brief Class for Orthorectifying an image + * + * This class is used to apply map projection and sensor model transformation + * to orthorectify an image, with or without DEM. + * + */ + + template <class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision=double> + class ITK_EXPORT OrthoRectificationFilterBase : public StreamingResampleImageFilter<TInputImage, + TOutputImage, + TInterpolatorPrecision> + { + public : + /** Standard class typedefs */ + typedef StreamingResampleImageFilter<TInputImage, + TOutputImage, + TInterpolatorPrecision> Superclass; + typedef OrthoRectificationFilterBase Self; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + typedef typename TInputImage::IndexType IndexType; + typedef typename TInputImage::SizeType SizeType; + typedef typename TInputImage::SpacingType SpacingType; + typedef typename TInputImage::PointType PointType; + typedef typename TInputImage::RegionType RegionType; + + typedef typename TOutputImage::PixelType OutputPixelType; + + typedef TMapProjection MapProjectionType; + typedef typename TMapProjection::Pointer MapProjectionPointerType; + + typedef InverseSensorModel<double> SensorModelType; + typedef typename SensorModelType::Pointer SensorModelPointerType; + + typedef CompositeTransform< MapProjectionType,SensorModelType> CompositeTransformType; + typedef typename CompositeTransformType::Pointer CompositeTransformPointerType; + + /** Method for creation through the object factory. */ + itkNewMacro( Self ); + + /** Run-time type information (and related methods). */ + itkTypeMacro( OrthoRectificationFilterBase, StreamingResampleImageFilter ); + + /** Accessors */ + virtual void SetMapProjection (MapProjectionType* _arg) + { + if (this->m_MapProjection != _arg) + { + this->m_MapProjection = _arg; + m_CompositeTransform->SetFirstTransform(_arg); + m_IsComputed = false; + this->Modified(); + } + } + + itkGetObjectMacro(MapProjection, MapProjectionType); + + /** Specify where are DEM files, and load useful ones */ + virtual void SetDEMDirectory(const std::string& directory) + { + m_SensorModel->SetDEMDirectory(directory); + this->Modified(); + } + + /** Methods to decide to use DEM */ + virtual void EnableDEM() { m_SensorModel->EnableDEM(); } + virtual void DisableDEM() { m_SensorModel->DisableDEM(); } + + protected: + OrthoRectificationFilterBase(); + ~OrthoRectificationFilterBase(); + void PrintSelf(std::ostream& os, itk::Indent indent) const; + + virtual void GenerateInputRequestedRegion(); + + + private: + OrthoRectificationFilterBase(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + /** Calculate transformation model from sensor model & map projection composition */ + void ComputeResampleTransformationModel(); + + /** Boolean used to know if transformation model computation is needed */ + bool m_IsComputed; + + /** Sensor Model used to transform geographic coordinates in image sensor index */ + SensorModelPointerType m_SensorModel; + + /** Map Projection used to transform cartographic coordinates in geographic coordinates */ + MapProjectionPointerType m_MapProjection; + + /** Composite Transform of Sensor Model and Map Projection, used for Resampler */ + CompositeTransformPointerType m_CompositeTransform; + + }; + +} // namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbOrthoRectificationFilterBase.txx" +#endif + +#endif diff --git a/Code/Projections/otbOrthoRectificationFilterBase.txx b/Code/Projections/otbOrthoRectificationFilterBase.txx new file mode 100755 index 0000000000000000000000000000000000000000..3a4cfe2678473b9243d89a751d144d2d2eefa33d --- /dev/null +++ b/Code/Projections/otbOrthoRectificationFilterBase.txx @@ -0,0 +1,123 @@ +/*========================================================================= + +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 _otbOrthoRectificationFilterBase_txx +#define _otbOrthoRectificationFilterBase_txx + +#include "otbOrthoRectificationFilterBase.h" + + +namespace otb +{ + + template <class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> + OrthoRectificationFilterBase<TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> + ::OrthoRectificationFilterBase() : StreamingResampleImageFilter<TInputImage, + TOutputImage, + TInterpolatorPrecision>() + { + m_SensorModel = SensorModelType::New(); + m_MapProjection = MapProjectionType::New(); + m_CompositeTransform = CompositeTransformType::New(); + m_IsComputed = false; + } + + template <class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> + OrthoRectificationFilterBase<TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> + ::~OrthoRectificationFilterBase() + { + } + + template <class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> + void OrthoRectificationFilterBase<TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> +::PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + + os << indent << "OrthoRectification" << "\n"; + } + + + template <class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> + void + OrthoRectificationFilterBase<TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> + ::GenerateInputRequestedRegion() + { + this->ComputeResampleTransformationModel(); + + Superclass::GenerateInputRequestedRegion(); + } + + template <class TInputImage, + class TOutputImage, + class TMapProjection, + class TInterpolatorPrecision> + void + OrthoRectificationFilterBase<TInputImage, + TOutputImage, + TMapProjection, + TInterpolatorPrecision> + ::ComputeResampleTransformationModel() + { + if (m_IsComputed == false) + { + otbMsgDevMacro(<< "COMPUTE RESAMPLE TRANSFORMATION MODEL"); + typename TOutputImage::Pointer output = this->GetOutput(); + + // Get OSSIM sensor model from image keywordlist + m_SensorModel->SetImageGeometry(output->GetImageKeywordlist()); + + // Initialize Map Projection if needed +/* PointType geoPoint; + geoPoint[1] = this->GetOutputOrigin()[1] + this->GetSize()[0]*this->GetOutputSpacing()[0]/2; + geoPoint[0] = this->GetOutputOrigin()[0] + this->GetSize()[1]*this->GetOutputSpacing()[1]/2; + m_MapProjection->Initialize(geoPoint); */ + + m_CompositeTransform->SetFirstTransform(m_MapProjection); + m_CompositeTransform->SetSecondTransform(m_SensorModel); + this->SetTransform(m_CompositeTransform); + m_IsComputed = true; + } + } + +} //namespace otb + +#endif diff --git a/Testing/Code/Projections/CMakeLists.txt b/Testing/Code/Projections/CMakeLists.txt index 270120bb02755a440edf2e6f038ffd78ea362a10..d181ee27f6744e82d908cf2ea0408178ecd1f943 100755 --- a/Testing/Code/Projections/CMakeLists.txt +++ b/Testing/Code/Projections/CMakeLists.txt @@ -60,33 +60,33 @@ ADD_TEST(prTvTestCreateInverseForwardSensorModel_Cevennes ${PROJECTIONS_TESTS} ) #======================================================================================= # TEST 10 -ADD_TEST(prTvRegionProjectionToulouse ${PROJECTIONS_TESTS} - --compare-image ${TOL} ${BASELINE}/prTvRegionProjectionToulouse.tif - ${TEMP}/prTvRegionProjectionToulouse.tif - otbRegionProjection - ${IMAGEDATA}/TOULOUSE/QuickBird/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF - ${TEMP}/prTvRegionProjectionToulouse.tif - 1.44 43.6050 # Long/Lat of Toulouse, Capitole - 500 - 500 - 10 - 0.00001 - -0.00001 - ) +# ADD_TEST(prTvRegionProjectionToulouse ${PROJECTIONS_TESTS} +# --compare-image ${TOL} ${BASELINE}/prTvRegionProjectionToulouse.tif +# ${TEMP}/prTvRegionProjectionToulouse.tif +# otbRegionProjection +# ${IMAGEDATA}/TOULOUSE/QuickBird/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF +# ${TEMP}/prTvRegionProjectionToulouse.tif +# 1.44 43.6050 # Long/Lat of Toulouse, Capitole +# 500 +# 500 +# 10 +# 0.00001 +# -0.00001 +# ) # TEST 11 -ADD_TEST(prTvRegionProjectionCevennes ${PROJECTIONS_TESTS} - --compare-image ${TOL} ${BASELINE}/prTvRegionProjectionCevennes.tif - ${TEMP}/prTvRegionProjectionCevennes.tif - otbRegionProjection - ${IMAGEDATA}/CEVENNES/06FEB12104912-P1BS-005533998070_01_P001.TIF - ${TEMP}/prTvRegionProjectionCevennes.tif - 3.7 44.08 - 500 - 500 - 10 - 0.00001 - -0.00001 - ) +# ADD_TEST(prTvRegionProjectionCevennes ${PROJECTIONS_TESTS} +# --compare-image ${TOL} ${BASELINE}/prTvRegionProjectionCevennes.tif +# ${TEMP}/prTvRegionProjectionCevennes.tif +# otbRegionProjection +# ${IMAGEDATA}/CEVENNES/06FEB12104912-P1BS-005533998070_01_P001.TIF +# ${TEMP}/prTvRegionProjectionCevennes.tif +# 3.7 44.08 +# 500 +# 500 +# 10 +# 0.00001 +# -0.00001 +# ) #======================================================================================= # TEST 12 ADD_TEST(prTvRegionProjectionResamplerToulouse ${PROJECTIONS_TESTS} @@ -149,7 +149,28 @@ ADD_TEST(prTvRegionProjectionResamplerCevennes ${PROJECTIONS_TESTS} # -0.5 # ) #======================================================================================= + +# TU pour otb::OrthoRectificationFilterBase otb::OrthoRectificationFilter +ADD_TEST(prTuOrthoRectificationFilterNew ${PROJECTIONS_TESTS} + otbOrthoRectificationFilterNew ) + # TEST 16 +ADD_TEST(prTvOrthoRectificationToulouseBase ${PROJECTIONS_TESTS} + --compare-image ${EPSILON} ${BASELINE}/prTvOrthoRectificationToulouse_UTM.tif + ${TEMP}/prTvOrthoRectificationBaseToulouse_UTM.tif + otbOrthoRectificationFilterBase + ${IMAGEDATA}/TOULOUSE/QuickBird/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF + ${TEMP}/prTvOrthoRectificationBaseToulouse_UTM.tif + 374100.8 + 4829184.8 + 500 + 500 + 220 + 0.5 + -0.5 + ) + +# TEST 16.2 ADD_TEST(prTvOrthoRectificationToulouse ${PROJECTIONS_TESTS} --compare-image ${EPSILON} ${BASELINE}/prTvOrthoRectificationToulouse_UTM.tif ${TEMP}/prTvOrthoRectificationToulouse_UTM.tif @@ -159,9 +180,9 @@ ADD_TEST(prTvOrthoRectificationToulouse ${PROJECTIONS_TESTS} 374100.8 4829184.8 500 - 500 - 220 - 0.5 + 500 + 220 + 0.5 -0.5 ) @@ -175,9 +196,9 @@ ADD_TEST(prTvOrthoRectificationCevennes ${PROJECTIONS_TESTS} 556046 4.881e+06 500 - 500 - 220 - 0.5 + 500 + 220 + 0.5 -0.5 ) #======================================================================================= @@ -216,6 +237,23 @@ ADD_TEST(prTvOrthoRectificationCevennes ${PROJECTIONS_TESTS} # ) #======================================================================================= # TEST 20 +ADD_TEST(prTvOrthoRectificationToulouseBaseWithDEM ${PROJECTIONS_TESTS} + --compare-image ${EPSILON} ${BASELINE}/prTvOrthoRectificationToulouseWithDEM_UTM.tif + ${TEMP}/prTvOrthoRectificationToulouseBaseWithDEM_UTM.tif + otbOrthoRectificationFilterBaseWithDEM + ${IMAGEDATA}/TOULOUSE/QuickBird/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF + ${TEMP}/prTvOrthoRectificationToulouseBaseWithDEM_UTM.tif + 374100.8 + 4829184.8 + 500 + 500 + 220 + 0.5 + -0.5 + ${INPUTDATA}/DEM/srtm_directory/ + ${TEMP}/prTvOrthoRectificationToulouseBaseWithDEM_UTM.tif + ) +# TEST 20.2 ADD_TEST(prTvOrthoRectificationToulouseWithDEM ${PROJECTIONS_TESTS} --compare-image ${EPSILON} ${BASELINE}/prTvOrthoRectificationToulouseWithDEM_UTM.tif ${TEMP}/prTvOrthoRectificationToulouseWithDEM_UTM.tif @@ -290,9 +328,12 @@ otbSensorModelsNew.cxx otbCreateProjectionWithOSSIM.cxx otbCreateProjectionWithOTB.cxx otbCreateInverseForwardSensorModel.cxx -otbRegionProjection.cxx +#otbRegionProjection.cxx otbRegionProjectionResampler.cxx +otbOrthoRectificationFilterNew.cxx +otbOrthoRectificationFilterBase.cxx otbOrthoRectificationFilter.cxx +otbOrthoRectificationFilterBaseWithDEM.cxx otbOrthoRectificationFilterWithDEM.cxx #otbSensorImageToCarto.cxx #otbSensorImageDEMToCarto.cxx diff --git a/Testing/Code/Projections/otbOrthoRectificationFilter.cxx b/Testing/Code/Projections/otbOrthoRectificationFilter.cxx index 5795ce165797cfdbea0073cf653530df53333d5f..03b41e0b31ad13ee3a7d657b632b0f38eb3e945a 100644 --- a/Testing/Code/Projections/otbOrthoRectificationFilter.cxx +++ b/Testing/Code/Projections/otbOrthoRectificationFilter.cxx @@ -30,25 +30,15 @@ // iostream is used for general output #include <iostream> -#include <iterator> #include <stdlib.h> #include "otbMacro.h" #include "otbImage.h" #include "otbImageFileReader.h" -#include "otbImageFileWriter.h" #include "otbStreamingImageFileWriter.h" #include "otbInverseSensorModel.h" #include "otbStreamingResampleImageFilter.h" -#include "itkExceptionObject.h" -#include "itkExtractImageFilter.h" -#include "itkResampleImageFilter.h" -#include "itkRescaleIntensityImageFilter.h" -#include "itkImageRegionIteratorWithIndex.h" -#include "itkLinearInterpolateImageFunction.h" -#include "itkChangeInformationImageFilter.h" - #include "otbOrthoRectificationFilter.h" #include "otbMapProjections.h" @@ -58,9 +48,6 @@ int otbOrthoRectificationFilter( int argc, char* argv[] ) { - try - { - ossimInit::instance()->initialize(argc, argv); if(argc!=10) @@ -74,91 +61,48 @@ int otbOrthoRectificationFilter( int argc, char* argv[] ) typedef otb::Image<double, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::StreamingImageFileWriter<ImageType> WriterType; - - typedef otb::UtmInverseProjection UtmMapProjectionType ; - typedef otb::OrthoRectificationFilter<ImageType, ImageType, UtmMapProjectionType> OrthoRectifFilterType ; - + typedef otb::UtmInverseProjection UtmMapProjectionType ; + typedef otb::OrthoRectificationFilter<ImageType, ImageType, UtmMapProjectionType> OrthoRectifFilterType ; + //Allocate pointer - ReaderType::Pointer reader=ReaderType::New(); - WriterType::Pointer writer=WriterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); - OrthoRectifFilterType::Pointer orthoRectifFilter=OrthoRectifFilterType::New(); - UtmMapProjectionType::Pointer utmMapProjection = UtmMapProjectionType::New(); - + OrthoRectifFilterType::Pointer orthoRectifFilter = OrthoRectifFilterType::New(); + UtmMapProjectionType::Pointer utmMapProjection = UtmMapProjectionType::New(); + // Set parameters ... reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); - - // Read meta data (ossimKeywordlist) -// reader->GenerateOutputInformation(); -// model->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist()); - -// std::cout << "Model1: " << model << std::endl; - - // image origin modification - typedef itk::ChangeInformationImageFilter<ImageType > ChangeInfoFilterType; - ChangeInfoFilterType::Pointer changeInfo = ChangeInfoFilterType::New(); - changeInfo->SetInput(reader->GetOutput()); - changeInfo->ChangeOriginOn(); - ImageType::PointType originNull; - originNull[0]=0; - originNull[1]=0; - changeInfo->SetOutputOrigin(originNull); - - changeInfo->GenerateOutputInformation(); - - orthoRectifFilter->SetInput(changeInfo->GetOutput()); - - ImageType::IndexType start; - start[0]=0; - start[1]=0; - orthoRectifFilter->SetOutputStartIndex(start); - - ImageType::SizeType size; - size[0]=atoi(argv[5]); //Taille en X. - size[1]=atoi(argv[6]); //Taille en Y. - orthoRectifFilter->SetSize(size); - - ImageType::SpacingType spacing; - spacing[0]=atof(argv[8]); - spacing[1]=atof(argv[9]); - orthoRectifFilter->SetOutputSpacing(spacing); - - ImageType::PointType origin; - origin[0]=strtod(argv[3], NULL); //Coord x en m�tres de l'origine. - origin[1]=strtod(argv[4], NULL); //Coord y en m�tres de l'origine. - orthoRectifFilter->SetOutputOrigin(origin); - - -// utmMapProjection->SetZone(31); -// utmMapProjection->SetHemisphere('N'); - orthoRectifFilter->SetMapProjection(utmMapProjection); - - writer->SetInput(orthoRectifFilter->GetOutput()); - - writer->SetTilingStreamDivisions(); - - otbGenericMsgDebugMacro(<< "Update writer ..." ); + + orthoRectifFilter->SetInput(reader->GetOutput()); + + ImageType::IndexType start; + start[0]=0; + start[1]=0; + orthoRectifFilter->SetOutputStartIndex(start); + + ImageType::SizeType size; + size[0]=atoi(argv[5]); //Taille en X. + size[1]=atoi(argv[6]); //Taille en Y. + orthoRectifFilter->SetSize(size); + + ImageType::SpacingType spacing; + spacing[0]=atof(argv[8]); + spacing[1]=atof(argv[9]); + orthoRectifFilter->SetOutputSpacing(spacing); + + ImageType::PointType origin; + origin[0]=strtod(argv[3], NULL); //Coord x en m�tres de l'origine. + origin[1]=strtod(argv[4], NULL); //Coord y en m�tres de l'origine. + orthoRectifFilter->SetOutputOrigin(origin); + orthoRectifFilter->SetMapProjection(utmMapProjection); + + writer->SetInput(orthoRectifFilter->GetOutput()); + + writer->SetTilingStreamDivisions(); writer->Update(); - } - catch( itk::ExceptionObject & err ) - { - std::cout << "Exception itk::ExceptionObject levee !" << std::endl; - std::cout << err << std::endl; - return EXIT_FAILURE; - } - catch( std::bad_alloc & err ) - { - std::cout << "Exception bad_alloc : "<<(char*)err.what()<< std::endl; - return EXIT_FAILURE; - } - catch( ... ) - { - std::cout << "Exception levee inconnue !" << std::endl; - return EXIT_FAILURE; - } - return EXIT_SUCCESS; - + return EXIT_SUCCESS; }//Fin main() diff --git a/Testing/Code/Projections/otbOrthoRectificationFilterBase.cxx b/Testing/Code/Projections/otbOrthoRectificationFilterBase.cxx new file mode 100755 index 0000000000000000000000000000000000000000..807eb0319a2495a17a5a638a7919fa0037ab70ae --- /dev/null +++ b/Testing/Code/Projections/otbOrthoRectificationFilterBase.cxx @@ -0,0 +1,131 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +/*! + * + * PURPOSE: + * + * Application pour projeter une r�gion d'une image en coordonn�es g�ographiques + * en utilisant un Interpolator+regionextractor et un Iterator. + * + */ + +// iostream is used for general output +#include <iostream> +#include <iterator> +#include <stdlib.h> + +#include "otbMacro.h" +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbStreamingImageFileWriter.h" +#include "otbInverseSensorModel.h" +#include "otbStreamingResampleImageFilter.h" + +#include "itkExceptionObject.h" +#include "itkExtractImageFilter.h" +#include "itkResampleImageFilter.h" +#include "itkRescaleIntensityImageFilter.h" +#include "itkImageRegionIteratorWithIndex.h" +#include "itkLinearInterpolateImageFunction.h" +#include "itkChangeInformationImageFilter.h" + +#include "otbOrthoRectificationFilterBase.h" +#include "otbMapProjections.h" + +#include "init/ossimInit.h" + + + +int otbOrthoRectificationFilterBase( int argc, char* argv[] ) +{ + ossimInit::instance()->initialize(argc, argv); + + if(argc!=10) + { + std::cout << argv[0] <<" <input filename> <output filename> <latitude de l'origine> <longitude de l'origine> <taille_x> <taille_y> <NumberOfstreamDivisions>" + << std::endl; + + return EXIT_FAILURE; + } + + typedef otb::Image<double, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::StreamingImageFileWriter<ImageType> WriterType; + typedef otb::UtmInverseProjection UtmMapProjectionType ; + typedef otb::OrthoRectificationFilterBase<ImageType, ImageType, UtmMapProjectionType> OrthoRectifFilterType ; + + //Allocate pointer + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + OrthoRectifFilterType::Pointer orthoRectifFilter = OrthoRectifFilterType::New(); + UtmMapProjectionType::Pointer utmMapProjection = UtmMapProjectionType::New(); + + // Set parameters ... + reader->SetFileName(argv[1]); + writer->SetFileName(argv[2]); + + + // image origin modification + typedef itk::ChangeInformationImageFilter<ImageType > ChangeInfoFilterType; + ChangeInfoFilterType::Pointer changeInfo = ChangeInfoFilterType::New(); + changeInfo->SetInput(reader->GetOutput()); + changeInfo->ChangeOriginOn(); + ImageType::PointType originNull; + originNull[0]=0; + originNull[1]=0; + changeInfo->SetOutputOrigin(originNull); + + changeInfo->GenerateOutputInformation(); + + orthoRectifFilter->SetInput(changeInfo->GetOutput()); + + ImageType::IndexType start; + start[0]=0; + start[1]=0; + orthoRectifFilter->SetOutputStartIndex(start); + + ImageType::SizeType size; + size[0]=atoi(argv[5]); //Taille en X. + size[1]=atoi(argv[6]); //Taille en Y. + orthoRectifFilter->SetSize(size); + + ImageType::SpacingType spacing; + spacing[0]=atof(argv[8]); + spacing[1]=atof(argv[9]); + orthoRectifFilter->SetOutputSpacing(spacing); + + ImageType::PointType origin; + origin[0]=strtod(argv[3], NULL); //Coord x en m�tres de l'origine. + origin[1]=strtod(argv[4], NULL); //Coord y en m�tres de l'origine. + orthoRectifFilter->SetOutputOrigin(origin); + orthoRectifFilter->SetMapProjection(utmMapProjection); + + writer->SetInput(orthoRectifFilter->GetOutput()); + + writer->SetTilingStreamDivisions(); + writer->Update(); + + return EXIT_SUCCESS; + }//Fin main() + diff --git a/Testing/Code/Projections/otbOrthoRectificationFilterBaseWithDEM.cxx b/Testing/Code/Projections/otbOrthoRectificationFilterBaseWithDEM.cxx new file mode 100755 index 0000000000000000000000000000000000000000..d472beaeb211a8d6b7668dae1008e6ca9c7a02b1 --- /dev/null +++ b/Testing/Code/Projections/otbOrthoRectificationFilterBaseWithDEM.cxx @@ -0,0 +1,145 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +/*! + * + * PURPOSE: + * + * Application pour projeter une r�gion d'une image en coordonn�es g�ographiques + * en utilisant un Interpolator+regionextractor et un Iterator. + * + */ + +// iostream is used for general output +#include <iostream> +#include <iterator> +#include <stdlib.h> + +#include "otbMacro.h" +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbStreamingImageFileWriter.h" +#include "otbInverseSensorModel.h" +#include "otbStreamingResampleImageFilter.h" + +#include "itkExceptionObject.h" +#include "itkExtractImageFilter.h" +#include "itkResampleImageFilter.h" +#include "itkRescaleIntensityImageFilter.h" +#include "itkImageRegionIteratorWithIndex.h" +#include "itkLinearInterpolateImageFunction.h" +#include "itkChangeInformationImageFilter.h" + +#include "otbOrthoRectificationFilterBase.h" +#include "otbMapProjections.h" + +#include "init/ossimInit.h" + + + +int otbOrthoRectificationFilterBaseWithDEM( int argc, char* argv[] ) +{ + ossimInit::instance()->initialize(argc, argv); + + if(argc!=12) + { + std::cout << argv[0] <<" <input filename> <output filename> <latitude de l'origine> <longitude de l'origine> <taille_x> <taille_y>"; + std::cout << " <NumberOfstreamDivisions> <x_spacing> <y_spacing> <srtm directory> <DEM Image Filename>" << std::endl; + + return EXIT_FAILURE; + } + + + typedef otb::Image<double, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::StreamingImageFileWriter<ImageType> WriterType; + + typedef otb::UtmInverseProjection UtmMapProjectionType ; + typedef otb::OrthoRectificationFilterBase<ImageType, ImageType, UtmMapProjectionType> OrthoRectifFilterType ; + + //Allocate pointer + ReaderType::Pointer reader=ReaderType::New(); + WriterType::Pointer writer=WriterType::New(); + + OrthoRectifFilterType::Pointer orthoRectifFilter=OrthoRectifFilterType::New(); + UtmMapProjectionType::Pointer utmMapProjection = UtmMapProjectionType::New(); + + // Set parameters ... + reader->SetFileName(argv[1]); + writer->SetFileName(argv[2]); + + // Read meta data (ossimKeywordlist) +// reader->GenerateOutputInformation(); +// model->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist()); + + // image origin modification + typedef itk::ChangeInformationImageFilter<ImageType > ChangeInfoFilterType; + ChangeInfoFilterType::Pointer changeInfo = ChangeInfoFilterType::New(); + changeInfo->SetInput(reader->GetOutput()); + changeInfo->ChangeOriginOn(); + ImageType::PointType originNull; + originNull[0]=0; + originNull[1]=0; + changeInfo->SetOutputOrigin(originNull); + + changeInfo->GenerateOutputInformation(); + + orthoRectifFilter->SetInput(changeInfo->GetOutput()); + + ImageType::IndexType start; + start[0]=0; + start[1]=0; + orthoRectifFilter->SetOutputStartIndex(start); + + ImageType::SizeType size; + size[0]=atoi(argv[5]); //Taille en X. + size[1]=atoi(argv[6]); //Taille en Y. + orthoRectifFilter->SetSize(size); + + ImageType::SpacingType spacing; + spacing[0]=atof(argv[8]); + spacing[1]=atof(argv[9]); + orthoRectifFilter->SetOutputSpacing(spacing); + + ImageType::PointType origin; + origin[0]=strtod(argv[3], NULL); //longitude de l'origine. + origin[1]=strtod(argv[4], NULL); //latitude de l'origine. + orthoRectifFilter->SetOutputOrigin(origin); + + utmMapProjection->SetZone(31); + utmMapProjection->SetHemisphere('N'); + orthoRectifFilter->SetMapProjection(utmMapProjection); + + std::string srtmDirectory(argv[10]); + orthoRectifFilter->SetDEMDirectory(srtmDirectory); + + writer->SetInput(orthoRectifFilter->GetOutput()); + + writer->SetTilingStreamDivisions(); + + otbGenericMsgDebugMacro(<< "Update writer ..." ); + writer->Update(); + + return EXIT_SUCCESS; + + } //End main() + diff --git a/Testing/Code/Projections/otbOrthoRectificationFilterNew.cxx b/Testing/Code/Projections/otbOrthoRectificationFilterNew.cxx new file mode 100755 index 0000000000000000000000000000000000000000..69da2d70bc4fc31d85e152c2d7e90034aa390065 --- /dev/null +++ b/Testing/Code/Projections/otbOrthoRectificationFilterNew.cxx @@ -0,0 +1,39 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +#include "otbMacro.h" +#include "otbImage.h" +#include "otbMapProjections.h" +#include "otbOrthoRectificationFilterBase.h" +#include "otbOrthoRectificationFilter.h" + + +int otbOrthoRectificationFilterNew( int argc, char* argv[] ) +{ + typedef otb::Image<double, 2> ImageType; + typedef otb::UtmInverseProjection UtmMapProjectionType ; + typedef otb::OrthoRectificationFilter<ImageType, ImageType, UtmMapProjectionType> OrthoRectifFilterType ; + typedef otb::OrthoRectificationFilterBase<ImageType, ImageType, UtmMapProjectionType> OrthoRectifFilterBaseType ; + + OrthoRectifFilterType::Pointer orthoRectifFilter=OrthoRectifFilterType::New(); + OrthoRectifFilterBaseType::Pointer orthoRectifFilterBase=OrthoRectifFilterBaseType::New(); + + return EXIT_SUCCESS; + + }//Fin main() + diff --git a/Testing/Code/Projections/otbOrthoRectificationFilterWithDEM.cxx b/Testing/Code/Projections/otbOrthoRectificationFilterWithDEM.cxx index 5ab8fdcbaba918fa62f36c5f1427d9eeb5322130..773f5f8335d9b32d6c4790a736d17ac5df4f7a33 100644 --- a/Testing/Code/Projections/otbOrthoRectificationFilterWithDEM.cxx +++ b/Testing/Code/Projections/otbOrthoRectificationFilterWithDEM.cxx @@ -90,23 +90,7 @@ int otbOrthoRectificationFilterWithDEM( int argc, char* argv[] ) reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); - // Read meta data (ossimKeywordlist) -// reader->GenerateOutputInformation(); -// model->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist()); - - // image origin modification - typedef itk::ChangeInformationImageFilter<ImageType > ChangeInfoFilterType; - ChangeInfoFilterType::Pointer changeInfo = ChangeInfoFilterType::New(); - changeInfo->SetInput(reader->GetOutput()); - changeInfo->ChangeOriginOn(); - ImageType::PointType originNull; - originNull[0]=0; - originNull[1]=0; - changeInfo->SetOutputOrigin(originNull); - - changeInfo->GenerateOutputInformation(); - - orthoRectifFilter->SetInput(changeInfo->GetOutput()); + orthoRectifFilter->SetInput(reader->GetOutput()); ImageType::IndexType start; start[0]=0; @@ -163,3 +147,4 @@ int otbOrthoRectificationFilterWithDEM( int argc, char* argv[] ) } //End main() + diff --git a/Testing/Code/Projections/otbProjectionsTests.cxx b/Testing/Code/Projections/otbProjectionsTests.cxx index ae0bc4b8698ef74ee6883ca10a0fdeeecdfb2704..377928088f44539d71ded32d58b2c1a076f6602e 100755 --- a/Testing/Code/Projections/otbProjectionsTests.cxx +++ b/Testing/Code/Projections/otbProjectionsTests.cxx @@ -33,9 +33,12 @@ REGISTER_TEST(otbSensorModelsNew); REGISTER_TEST(otbCreateProjectionWithOSSIM); REGISTER_TEST(otbCreateProjectionWithOTB); REGISTER_TEST(otbCreateInverseForwardSensorModel); -REGISTER_TEST(otbRegionProjection); +//REGISTER_TEST(otbRegionProjection); REGISTER_TEST(otbRegionProjectionResampler); +REGISTER_TEST(otbOrthoRectificationFilterNew); +REGISTER_TEST(otbOrthoRectificationFilterBase); REGISTER_TEST(otbOrthoRectificationFilter); +REGISTER_TEST(otbOrthoRectificationFilterBaseWithDEM); REGISTER_TEST(otbOrthoRectificationFilterWithDEM); //REGISTER_TEST(otbSensorImageToCarto); //REGISTER_TEST(otbSensorImageDEMToCarto); diff --git a/Utilities/otbossim/src/ossim/CMakeLists.txt b/Utilities/otbossim/src/ossim/CMakeLists.txt index 857fce81397bfe2a9a62eb41c81c21cfa99befd2..96a1e16c0c469f7800cdf28aef576ceae59bba95 100644 --- a/Utilities/otbossim/src/ossim/CMakeLists.txt +++ b/Utilities/otbossim/src/ossim/CMakeLists.txt @@ -15,35 +15,13 @@ FILE(GLOB_RECURSE ossim_dll_main_SRCS "dll_main/*.cpp") # Adjust the compiler flags to avoid problems with ossim code. IF(CMAKE_COMPILER_IS_GNUCXX) - # Hide warnings in ossim code. - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") - - # CMake versions before 2.4 did not put the source-file-specific flags - # after the directory-level flags. Remove optimization flags from the - # CMAKE_CXX_FLAGS* variables so they can be overridden. - IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.4) - FOREACH(c "" "_DEBUG" "_RELEASE" "_MINSIZEREL" "_RELWITHDEBINFO") - STRING(REGEX REPLACE - "-O[^ ]*( |$)" "" CMAKE_CXX_FLAGS${c} "${CMAKE_CXX_FLAGS${c}}") - ENDFOREACH(c) - ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.4) - + FOREACH(f ${ossim_base_SRCS} ${ossim_elevation_SRCS} ${ossim_font_SRCS} ${ossim_imaging_SRCS} ${ossim_matrix_SRCS} + ${ossim_parallel_SRCS} ${ossim_projection_SRCS} ${ossim_support_data_SRCS} + ${ossim_vec_SRCS} ${ossim_vpfutil_SRCS} ${ossim_plugin_SRCS} ${ossim_init_SRCS} + ${ossim_kbool_SRCS} ${ossim_dll_main_SRCS} ) + SET_SOURCE_FILES_PROPERTIES( ${f} PROPERTIES COMPILE_FLAGS -w ) + ENDFOREACH(f) ENDIF(CMAKE_COMPILER_IS_GNUCXX) -IF(CMAKE_COMPILER_IS_GNUCC) - # Hide warnings in ossim code. - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") - - # CMake versions before 2.4 did not put the source-file-specific flags - # after the directory-level flags. Remove optimization flags from the - # CMAKE_C_FLAGS* variables so they can be overridden. - IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.4) - FOREACH(c "" "_DEBUG" "_RELEASE" "_MINSIZEREL" "_RELWITHDEBINFO") - STRING(REGEX REPLACE - "-O[^ ]*( |$)" "" CMAKE_C_FLAGS${c} "${CMAKE_C_FLAGS${c}}") - ENDFOREACH(c) - ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.4) - -ENDIF(CMAKE_COMPILER_IS_GNUCC) ADD_LIBRARY(otbossimKBool ${ossim_kbool_SRCS})