From 7d3655a1b6d5fae2953d5e6869e8f34486b9585c Mon Sep 17 00:00:00 2001
From: Cyrille Valladeau <cyrille.valladeau@c-s.fr>
Date: Fri, 21 Aug 2009 18:21:39 +0200
Subject: [PATCH] ENH : TOAToTOC automatization in progress

---
 .../otbAtmosphericCorrectionParameters.cxx    | 11 +++
 ...flectanceToSurfaceReflectanceImageFilter.h | 79 ++++++++++---------
 2 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/Code/Radiometry/otbAtmosphericCorrectionParameters.cxx b/Code/Radiometry/otbAtmosphericCorrectionParameters.cxx
index 3ef2a925ef..f7539476f4 100644
--- a/Code/Radiometry/otbAtmosphericCorrectionParameters.cxx
+++ b/Code/Radiometry/otbAtmosphericCorrectionParameters.cxx
@@ -59,7 +59,18 @@ FilterFunctionValues
 AtmosphericCorrectionParameters
 ::AtmosphericCorrectionParameters()
 {
+  m_SolarZenithalAngle = 361.;
+  m_SolarAzimutalAngle = 361.;
+  m_ViewingZenithalAngle = 361.;
+  m_ViewingAzimutalAngle = 361.;
+  m_Month = 0;
+  m_Day = 0;
+  m_AtmosphericPressure = 1030.;
+  m_WaterVaporAmount = 2.5;
+  m_OzoneAmount = 0.28;
   m_AerosolModel = CONTINENTAL;
+  m_AerosolOptical = 0.2;
+
 }
 
 /**PrintSelf method */
diff --git a/Code/Radiometry/otbReflectanceToSurfaceReflectanceImageFilter.h b/Code/Radiometry/otbReflectanceToSurfaceReflectanceImageFilter.h
index 251cd9393f..7c2a41be29 100644
--- a/Code/Radiometry/otbReflectanceToSurfaceReflectanceImageFilter.h
+++ b/Code/Radiometry/otbReflectanceToSurfaceReflectanceImageFilter.h
@@ -23,9 +23,11 @@
 #define __otbReflectanceToSurfaceReflectanceImageFilter_h
 
 
-#include "otbAtmosphericRadiativeTerms.h"
 #include "otbUnaryImageFunctorWithVectorImageFilter.h"
 
+#include "otbAtmosphericRadiativeTerms.h"
+#include "otbAtmosphericCorrectionParametersTo6SAtmosphericRadiativeTerms.h"
+#include "itkMetaDataDictionary.h"
 
 namespace otb
 {
@@ -144,64 +146,65 @@ public:
   itkTypeMacro(ReflectanceToSurfaceReflectanceImageFilter, UnaryImageFunctorWithVectorImageFilter);
 
   /** Supported images definition. */
-  typedef typename InputImageType::PixelType                           InputPixelType;
-  typedef typename InputImageType::InternalPixelType                   InputInternalPixelType;
-  typedef typename InputImageType::RegionType                          InputImageRegionType;
-  typedef typename OutputImageType::PixelType                          OutputPixelType;
-  typedef typename OutputImageType::InternalPixelType                  OutputInternalPixelType;
-  typedef typename OutputImageType::RegionType                         OutputImageRegionType;
+  typedef typename InputImageType::PixelType                            InputPixelType;
+  typedef typename InputImageType::InternalPixelType                    InputInternalPixelType;
+  typedef typename InputImageType::RegionType                           InputImageRegionType;
+  typedef typename OutputImageType::PixelType                           OutputPixelType;
+  typedef typename OutputImageType::InternalPixelType                   OutputInternalPixelType;
+  typedef typename OutputImageType::RegionType                          OutputImageRegionType;
 
-  typedef AtmosphericRadiativeTerms::Pointer                           AtmosphericRadiativeTermsPointerType;
+  typedef AtmosphericCorrectionParametersTo6SAtmosphericRadiativeTerms  Parameters2RadiativeTermsType;
+  typedef Parameters2RadiativeTermsType::Pointer                        Parameters2RadiativeTermsPointerType;
+  typedef AtmosphericCorrectionParameters::Pointer                      CorrectionParametersPointerType;
+  typedef AtmosphericRadiativeTerms::Pointer                            AtmosphericRadiativeTermsPointerType;
+
+  typedef itk::MetaDataDictionary                                       MetaDataDictionaryType;
 
   /** Get/Set Atmospheric Radiative Terms. */
   void SetAtmosphericRadiativeTerms(AtmosphericRadiativeTermsPointerType atmo)
   {
     m_AtmosphericRadiativeTerms = atmo;
     this->SetNthInput(1, m_AtmosphericRadiativeTerms);
+    m_IsSetAtmosphericRadiativeTerms = true;
     this->Modified();
   }
-  AtmosphericRadiativeTermsPointerType GetAtmosphericRadiativeTerms()
-  {
-    return m_AtmosphericRadiativeTerms;
-  }
 
+  /** Get/Set Atmospheric Correction Parameters. */
+  itkGetConstObjectMacro(AtmosphericRadiativeTerms, AtmosphericRadiativeTerms);
+  itkGetObjectMacro(CorrectionParameters, AtmosphericCorrectionParameters);
+
+  /** Get/Set Aeronet file name. */
+  itkSetMacro(AeronetFileName, std::string);
+  itkGetMacro(AeronetFileName, std::string);
 
 protected:
   /** Constructor */
-  ReflectanceToSurfaceReflectanceImageFilter()
-  {
-    m_AtmosphericRadiativeTerms = AtmosphericRadiativeTerms::New();
-  };
+  ReflectanceToSurfaceReflectanceImageFilter();
   /** Destructor */
   virtual ~ReflectanceToSurfaceReflectanceImageFilter() {};
 
-  /** Initialize the functor vector */
-  void BeforeThreadedGenerateData ()
-  {
-    this->GetFunctorVector().clear();
-    for (unsigned int i = 0;i<this->GetInput()->GetNumberOfComponentsPerPixel();++i)
-    {
-      double coef;
-      double res;
-      coef = static_cast<double>(m_AtmosphericRadiativeTerms->GetTotalGaseousTransmission(i)
-                                 * m_AtmosphericRadiativeTerms->GetDownwardTransmittance(i)
-                                 * m_AtmosphericRadiativeTerms->GetUpwardTransmittance(i)     );
-      coef = 1. / coef;
-      res = -m_AtmosphericRadiativeTerms->GetIntrinsicAtmosphericReflectance(i) * coef;
-
-      FunctorType functor;
-      functor.SetCoefficient(coef);
-      functor.SetResidu(res);
-      functor.SetSphericalAlbedo(static_cast<double>(m_AtmosphericRadiativeTerms->GetSphericalAlbedo(i)));
-
-      this->GetFunctorVector().push_back(functor);
-    }
-  }
+  /** If empty, fill AtmosphericRadiativeTerms using image metadata*/
+  void UpdateAtmosphericRadiativeTerms( const MetaDataDictionaryType dict );
+
+  /** Read the aeronet data and extract aerosol optical and water vapor amount. */
+  void UpdateAeronetData( const MetaDataDictionaryType dict );
 
+  /** Initialize the functor vector */
+  void BeforeThreadedGenerateData();
+ 
+  
 private:
   AtmosphericRadiativeTermsPointerType m_AtmosphericRadiativeTerms;
+  CorrectionParametersPointerType      m_CorrectionParameters;
+  bool m_IsSetAtmosphericRadiativeTerms;
+  /** Path to an Aeronet data file, allows to compute aerosol optical and water vapor amounts. */
+  std::string m_AeronetFileName;
 };
 
 } // end namespace otb
 
+#ifndef OTB_MANUAL_INSTANTIATION
+#include "otbReflectanceToSurfaceReflectanceImageFilter.txx"
+#endif
+
 #endif
-- 
GitLab