From 5f2ddadac34395ac6207042b80d9b752450796d7 Mon Sep 17 00:00:00 2001
From: Cyrille Valladeau <cyrille.valladeau@c-s.fr>
Date: Thu, 14 Jan 2010 19:10:50 +0100
Subject: [PATCH] ENH : correct SGFT on calib

---
 Code/IO/otbTerraSarImageMetadataInterface.cxx | 29 ++++++++++++-
 Code/IO/otbTerraSarImageMetadataInterface.h   |  3 ++
 .../otbTerraSarCalibrationImageFilter.txx     | 42 ++++++++++++++-----
 3 files changed, 62 insertions(+), 12 deletions(-)

diff --git a/Code/IO/otbTerraSarImageMetadataInterface.cxx b/Code/IO/otbTerraSarImageMetadataInterface.cxx
index 8915cb4a7b..08fd6773e6 100644
--- a/Code/IO/otbTerraSarImageMetadataInterface.cxx
+++ b/Code/IO/otbTerraSarImageMetadataInterface.cxx
@@ -88,7 +88,7 @@ TerraSarImageMetadataInterface::GetDay( const MetaDataDictionaryType & dict ) co
 
   ossimKeywordlist kwl;
   imageKeywordlist.convertToOSSIMKeywordlist(kwl);
-
+std::cout<<kwl<<std::endl;
   std::string key;
   ossimString separatorList;
   key = "azimuth_start_time";
@@ -678,8 +678,33 @@ TerraSarImageMetadataInterface::GetRadarFrequency( const MetaDataDictionaryType
 
   ossimKeywordlist kwl;
   imageKeywordlist.convertToOSSIMKeywordlist(kwl);
-
+ 
   ossimString tempVal = kwl.find("radarFrequency");
+  double freq =tempVal.toDouble();
+
+  return freq;
+}
+
+
+double
+TerraSarImageMetadataInterface::GetPRF( const MetaDataDictionaryType & dict ) const
+{
+  if( !this->CanRead( dict ) )
+  {
+    itkExceptionMacro(<<"Invalid Metadata, no TerraSar Image");
+  }
+
+  ImageKeywordlistType imageKeywordlist;
+
+  if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
+  {
+    itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
+  }
+
+  ossimKeywordlist kwl;
+  imageKeywordlist.convertToOSSIMKeywordlist(kwl);
+
+  ossimString tempVal = kwl.find("sensor_params.prf");
   double freq = tempVal.toDouble();
 
   return freq;
diff --git a/Code/IO/otbTerraSarImageMetadataInterface.h b/Code/IO/otbTerraSarImageMetadataInterface.h
index 7f763f895a..3a4ca993c8 100644
--- a/Code/IO/otbTerraSarImageMetadataInterface.h
+++ b/Code/IO/otbTerraSarImageMetadataInterface.h
@@ -126,6 +126,9 @@ public:
 
    /** Get the radar frequency */
    double GetRadarFrequency( const MetaDataDictionaryType & ) const;
+ 
+   /** Get the PRF */
+   double GetPRF( const MetaDataDictionaryType & ) const;
    
    /** Get the incidence angles structure */
    ossimplugins::IncidenceAngles* GetIncidenceAngles( const MetaDataDictionaryType & ) const;
diff --git a/Code/Radiometry/otbTerraSarCalibrationImageFilter.txx b/Code/Radiometry/otbTerraSarCalibrationImageFilter.txx
index 9233a2aca7..8cb40cd27a 100644
--- a/Code/Radiometry/otbTerraSarCalibrationImageFilter.txx
+++ b/Code/Radiometry/otbTerraSarCalibrationImageFilter.txx
@@ -19,6 +19,7 @@
 #define __otbTerraSarCalibrationImageFilter_txx
 
 #include <algorithm>
+#include <iomanip>
 
 #include "otbTerraSarCalibrationImageFilter.h"
 #include "otbTerraSarImageMetadataInterface.h"
@@ -147,12 +148,12 @@ TerraSarCalibrationImageFilter<TInputImage,TOutputImage>
       }
     }
   
-  // Radar frequency (PRF)
+  // PRF
   if (this->GetPRF() == 1.) 
   {
     if (mdIsAvailable)
     {
-      m_PRF = lImageMetadata->GetRadarFrequency(this->GetInput()->GetMetaDataDictionary());
+      m_PRF = lImageMetadata->GetPRF(this->GetInput()->GetMetaDataDictionary());
     }
     else
     {
@@ -213,27 +214,46 @@ TerraSarCalibrationImageFilter<TInputImage,TOutputImage>
   // Set up progress reporting
   itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
   
+  
+  for(unsigned int i = 0; i < m_NoiseRecords.size();++i)
+    {
+      std::cout<<std::fixed<<std::setprecision(10)<<"t"<<i<<": "<<  m_NoiseRecords[i].first << std::endl;
+    }
+
+  assert(!m_NoiseRecords.empty());
+
   // The acquisition time of the first line of OutputRegionForThread.
-  double invPRF = 1/m_PRF;
-  double currentAzimuthPosition = m_NoiseRecords.back().first = invPRF 
+  //double PRFJulian = m_PRF * (0.864 / 1e-5);
+  double invPRF = /*(0.864/1e-5) * */1/m_PRF;
+  double currentAzimuthPosition = m_NoiseRecords.back().first + invPRF 
     * (m_OriginalProductSize[1]- inputIt.GetIndex()[1] -1);
-
-  // Local variable to store the current noise record
-  NoiseRecordType currentNoiseRecord;
    
+  std::cout<<"Product size: "<<m_OriginalProductSize<<std::endl;
+  std::cout<<"Start index: "<<inputIt.GetIndex()<<std::endl;
+  std::cout<<"Current position: "<<currentAzimuthPosition<<std::endl;
+  std::cout<<"PRF: "<<m_PRF<<std::endl;
+
+
   // Look for the first noise record to be used (remember we sorted
   // m_NoiseRecords by decreasing time)
   NoiseRecordVectorType::const_iterator currentNoiseRecordIt = m_NoiseRecords.begin();
   
+  unsigned int nrIndex = 0;
+
   // Iterate until we find it
   while(currentNoiseRecordIt != m_NoiseRecords.end() && currentNoiseRecordIt->first > currentAzimuthPosition)
     {
-    ++currentNoiseRecordIt;
+      ++nrIndex;
+      ++currentNoiseRecordIt;
     }
 
+  assert(currentNoiseRecordIt != m_NoiseRecords.end());
+
   // Store the current noise record azimuth position
   double currentNoiseRecordAzimuthPosition = currentNoiseRecordIt->first;
-  
+  calibrationFunctor.SetNoiseRecord(currentNoiseRecordIt->second);
+  std::cout<<nrIndex<<" degree: "<<currentNoiseRecordIt->second.get_polynomialDegree()<<std::endl;
+
   // Store current line index
   typename OutputImageRegionType::IndexType::IndexValueType currentLine = inputIt.GetIndex()[1];
  
@@ -254,13 +274,15 @@ TerraSarCalibrationImageFilter<TInputImage,TOutputImage>
        {
        // Update the iterator
        ++currentNoiseRecordIt;
-
+       ++nrIndex;
+       std::cout<<"NrIndex increment"<<std::endl;
        // If we are not at the last record
        if(currentNoiseRecordIt != m_NoiseRecords.end())
          {
          // Update the functor noise record
          currentNoiseRecordAzimuthPosition = currentNoiseRecordIt->first;
          calibrationFunctor.SetNoiseRecord(currentNoiseRecordIt->second);
+	 std::cout<<nrIndex<<" degree: "<<currentNoiseRecordIt->second.get_polynomialDegree()<<std::endl;
          }
        }
       }
-- 
GitLab