diff --git a/app/otbSARFineMetadata.cxx b/app/otbSARFineMetadata.cxx index fb6069706f7c9727ad4b206a907ad6576b20097a..0896951f599a111bc34a1253b7a005e1df87ce15 100644 --- a/app/otbSARFineMetadata.cxx +++ b/app/otbSARFineMetadata.cxx @@ -22,6 +22,7 @@ #include "otbWrapperApplicationFactory.h" #include "otbSARStreamingGridHistogramFilter.h" +#include "otbSARUpdateMetadataImageFilter.h" #include <iostream> #include <string> @@ -52,6 +53,7 @@ public: // Filter typedef otb::SARStreamingGridHistogramFilter<FloatVectorImageType> GridHistogramType; + typedef otb::SARUpdateMetadataImageFilter<ComplexFloatImageType> UpdateMetadataeFilter; // Time/Date ossim typedef ossimplugins::time::ModifiedJulianDate TimeType; @@ -101,6 +103,9 @@ private: AddParameter(ParameterType_Float,"slantrange","Slant near range (output of this application)"); SetParameterDescription("slantrange", "Slant near range (output of this application)."); SetParameterRole("slantrange", Role_Output); + + AddParameter(ParameterType_OutputImage, "out", "Output image with precise metadata"); + SetParameterDescription("out","Output image with precise metadata."); AddRAMParameter(); @@ -214,7 +219,15 @@ private: SetParameterString("timefirstline", fineTimeFirstLine); SetParameterFloat("slantrange", fineSlantRange); - + + // Copie input image and update the metadata into a naw geom file + UpdateMetadataeFilter::Pointer updateMetadataFilter = UpdateMetadataeFilter::New(); + m_Ref.push_back(updateMetadataFilter.GetPointer()); + updateMetadataFilter->SetTimeFirstLine(fineTimeFirstLine); + updateMetadataFilter->SetSlantRange(fineSlantRange); + updateMetadataFilter->SetInput(SARPtr); + + SetParameterOutputImage("out", updateMetadataFilter->GetOutput()); } // Vector for filters diff --git a/include/otbSARUpdateMetadataImageFilter.h b/include/otbSARUpdateMetadataImageFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..1784d496d7641209e94f3b33fe51a8bb7564aa0f --- /dev/null +++ b/include/otbSARUpdateMetadataImageFilter.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2005-2018 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otbSARUpdateMetadataImageFilter_h +#define otbSARUpdateMetadataImageFilter_h + +#include "itkImageToImageFilter.h" +#include "itkSmartPointer.h" +#include "itkPoint.h" + +#include "itkImageScanlineConstIterator.h" +#include "itkImageScanlineIterator.h" + +#include "otbImageKeywordlist.h" +#include "otbSarSensorModelAdapter.h" + +#if defined(__GNUC__) || defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-parameter" +# pragma GCC diagnostic ignored "-Woverloaded-virtual" +# pragma GCC diagnostic ignored "-Wshadow" +# include "ossim/ossimTimeUtilities.h" + +# pragma GCC diagnostic pop + +#else +# include "ossim/ossimTimeUtilities.h" +#endif + +#if defined(USE_BOOST_TIME) +# include <boost/date_time/posix_time/posix_time.hpp> +#include <ostream> +#endif + +namespace otb +{ +/** \class SARUpdateMetadataImageFilter + * \brief Update some metadata after a correction chain. + * + * This filter updates some metadata (only metadata, input image remains the same). + * + * \ingroup DiapOTBModule + */ + + template <typename TImage> + class ITK_EXPORT SARUpdateMetadataImageFilter : + public itk::ImageToImageFilter<TImage,TImage> +{ +public: + + // Standard class typedefs + typedef SARUpdateMetadataImageFilter Self; + typedef itk::ImageToImageFilter<TImage,TImage> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Typedef to image input/output type */ + typedef TImage ImageType; + /** Typedef to describe the inout image pointer type. */ + typedef typename ImageType::Pointer ImagePointer; + typedef typename ImageType::RegionType ImageRegionType; + + // Method for creation through object factory + itkNewMacro(Self); + // Run-time type information + itkTypeMacro(SARUpdateMetadataImageFilter,ImageToImageFilter); + + // Setter + itkSetMacro(TimeFirstLine, std::string); + itkSetMacro(SlantRange, double); + + // Getter + itkGetMacro(TimeFirstLine, std::string); + itkGetMacro(SlantRange, double); + + +protected: + // Constructor + SARUpdateMetadataImageFilter() + { + m_TimeFirstLine = ""; + m_SlantRange = 0.; + }; + + // Destructor + virtual ~SARUpdateMetadataImageFilter() {}; + + // Print + void PrintSelf(std::ostream & os, itk::Indent indent) const ITK_OVERRIDE; + + /** SARUpdateMetadataImageFilter updates the imagekeywordlist for new output metadata. + * As such, SARUpdateMetadataImageFilter needs to provide an implementation for + * GenerateOutputInformation() in order to inform the pipeline execution model. + */ + virtual void GenerateOutputInformation() ITK_OVERRIDE; + + void ThreadedGenerateData(const ImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) + ITK_OVERRIDE; + + private: + SARUpdateMetadataImageFilter(const Self&); // purposely not implemented + void operator=(const Self &); // purposely not + + // Precise metadata + std::string m_TimeFirstLine; + double m_SlantRange; + +}; + +} // End namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbSARUpdateMetadataImageFilter.txx" +#endif + + + +#endif diff --git a/include/otbSARUpdateMetadataImageFilter.txx b/include/otbSARUpdateMetadataImageFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..13bbffbe204bb4d2da2195555902fe767ae19ff0 --- /dev/null +++ b/include/otbSARUpdateMetadataImageFilter.txx @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2005-2018 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otbSARUpdateMetadataImageFilter_txx +#define otbSARUpdateMetadataImageFilter_txx + +#include "otbSARUpdateMetadataImageFilter.h" + +#include "itkImageRegionConstIterator.h" +#include "itkImageRegionIterator.h" + +#include <cmath> +#include <algorithm> + +namespace otb +{ + /** + * Print + */ + template<class TImage> + void + SARUpdateMetadataImageFilter< TImage > + ::PrintSelf(std::ostream & os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + + os << indent << "Precise first line time : " << m_TimeFirstLine << std::endl; + os << indent << "Precise Slant range : " << m_SlantRange << std::endl; + } + + + /** + * Method GenerateOutputInformaton() + **/ + template<class TImage> + void + SARUpdateMetadataImageFilter< TImage > + ::GenerateOutputInformation() + { + // Call superclass implementation + Superclass::GenerateOutputInformation(); + + // Get Input and Output ptr + ImagePointer outputPtr = this->GetOutput(); + ImagePointer inputPtr = const_cast< ImageType * >(this->GetInput()); + + // Set new keyword list to output image with precise metadata + ImageKeywordlist outputKWL = inputPtr->GetImageKeywordlist(); + //outputKWL.SetMetadataByKey("support_data.first_line_time", m_TimeFirstLine); + //outputKWL.SetMetadataByKey("support_data.slant_range_to_first_pixel", m_SlantRange); + + std::ostringstream str_slantRange; + str_slantRange.precision(14); + str_slantRange << std::fixed << m_SlantRange; + + std::cout << "str_slantRange = " << str_slantRange.str() << std::endl; + + outputKWL.AddKey("support_data.first_line_time", m_TimeFirstLine); + outputKWL.AddKey("support_data.slant_range_to_first_pixel", str_slantRange.str()); + outputPtr->SetImageKeywordList(outputKWL); + } + + + template<class TImage> + void + SARUpdateMetadataImageFilter< TImage > + ::ThreadedGenerateData(const ImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) + { + // Get Input and Output ptr + ImagePointer outputPtr = this->GetOutput(); + ImagePointer inputPtr = const_cast< ImageType * >(this->GetInput()); + + // Same region + ImageRegionType inputRegion = outputRegionForThread; + + // Iterators + typedef itk::ImageRegionConstIterator<ImageType> InItType; + typedef itk::ImageRegionIterator<ImageType> OutItType; + + InItType InIt(inputPtr, inputRegion); + InIt.GoToBegin(); + + OutItType OutIt(outputPtr, outputRegionForThread); + OutIt.GoToBegin(); + + // Copy input image into output + while (!InIt.IsAtEnd()) + { + OutIt.Set(InIt.Get()); + + ++OutIt; + ++InIt; + } + } + +} /*namespace otb*/ + +#endif