Commit 26c80fcd authored by Cyrille Valladeau's avatar Cyrille Valladeau

ENH : add filter function values file loading

parent fe75ffc5
......@@ -19,8 +19,9 @@ PURPOSE. See the above copyright notices for more information.
#include "otbAtmosphericCorrectionParameters.h"
#include "otbAeronetFileReader.h"
#include "base/ossimFilename.h"
#include <fstream>
#include <iostream>
......@@ -41,15 +42,15 @@ void
FilterFunctionValues
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
os << indent << "Minimum spectral value: " << m_MinSpectralValue << std::endl;
os << indent << "Maximum spectral value: " << m_MaxSpectralValue << std::endl;
os << indent << "User Step between each wavelenght spectral band values: " << m_UserStep << std::endl;
os << indent << "Filter function Vector Values: " << std::endl;
os << indent << "Minimum spectral value : " << m_MinSpectralValue << std::endl;
os << indent << "Maximum spectral value : " << m_MaxSpectralValue << std::endl;
os << indent << "Wavelenght spectral band step: " << m_UserStep << std::endl;
os << indent << "Filter function values: " << std::endl;
for (unsigned int i=0; i<m_FilterFunctionValues.size(); ++i)
{
os << indent << m_FilterFunctionValues[i] <<std::endl;
}
os << indent << "Filter function Vector Values 6S: " << std::endl;
os << indent << "6S Filter function values: " << std::endl;
for (unsigned int i=0; i<m_FilterFunctionValues6S.size(); ++i)
{
os << indent << m_FilterFunctionValues6S[i] <<std::endl;
......@@ -102,6 +103,62 @@ AtmosphericCorrectionParameters
}
/** Get data from filter function file*/
void
AtmosphericCorrectionParameters
::LoadFilterFunctionValue( std::string filename )
{
m_WavelenghtSpectralBand.clear();
FilterFunctionValues::Pointer ffv = FilterFunctionValues::New();
ossimFilename fname(filename);
if(!fname.exists())
itkExceptionMacro("Filename "<<filename<<" doesn not exist.");
std::ifstream file( filename.c_str() );
if ( !file )
itkExceptionMacro("Enable to read "<<filename<<" file.");
int bandId = 0;
std::string line;
ossimString separatorList = "\ ";
FilterFunctionValues::Pointer function = FilterFunctionValues::New();
FilterFunctionValues::ValuesVectorType vect;
m_WavelenghtSpectralBand.clear();
vect.clear();
while ( std::getline( file, line ) )
{
ossimString osLine(line);
std::vector<ossimString> keywordStrings = osLine.split(separatorList);
if(keywordStrings.size() == 2 || keywordStrings.size() == 3)
{
if(bandId != 0)
{
function->SetFilterFunctionValues(vect);
m_WavelenghtSpectralBand.push_back(function);
function = FilterFunctionValues::New();
vect.clear();
}
bandId++;
function->SetMinSpectralValue(keywordStrings[0].toDouble());
function->SetMaxSpectralValue(keywordStrings[1].toDouble());
if(keywordStrings.size() == 3)
function->SetUserStep(keywordStrings[2].toDouble());
}
else if(keywordStrings.size()==1)
vect.push_back(keywordStrings[0].toDouble());
else if(keywordStrings.size()!=0)
itkExceptionMacro("File "<<filename<<" not valid.");
}
function->SetFilterFunctionValues(vect);
m_WavelenghtSpectralBand.push_back(function);
}
/**PrintSelf method */
void
AtmosphericCorrectionParameters
......@@ -120,12 +177,11 @@ AtmosphericCorrectionParameters
os << "Aerosol optical : " << m_AerosolOptical << std::endl;
// Function values print :
os << "Filter function Values: " << std::endl;
os << "Filter function values: " << std::endl;
for (unsigned int i=0; i<m_WavelenghtSpectralBand.size(); ++i)
{
os << indent << "Channel : "<< i+1 <<" : " << std::endl;
os << indent << "Channel "<< i+1 <<" : " << std::endl;
os << indent << m_WavelenghtSpectralBand[i]<< std::endl;
}
}
} // end namespace otb
......@@ -51,8 +51,8 @@ public:
/** Creation through object factory macro */
itkNewMacro(Self);
typedef double WavelenghtSpectralBandType;
typedef std::vector<WavelenghtSpectralBandType> ValuesVectorType;
typedef double WavelenghtSpectralBandType;
typedef std::vector<WavelenghtSpectralBandType> ValuesVectorType;
/** Set vector that contains the filter function value. */
void SetFilterFunctionValues(const ValuesVectorType & vect)
......@@ -147,8 +147,7 @@ public:
itkNewMacro(Self);
typedef enum {NO_AEROSOL=0,CONTINENTAL=1,MARITIME=2,URBAN=3,DESERTIC=5} AerosolModelType;
typedef std::vector<FilterFunctionValues::Pointer> WavelenghtSpectralBandVectorType;
//typedef itk::VariableSizeMatrix<WavelenghtSpectralBandType> WavelenghtSpectralBandMatrixType;
typedef std::vector<FilterFunctionValues::Pointer> WavelenghtSpectralBandVectorType;
/**
* Set/Get the solar zenithal angle.
......@@ -257,7 +256,12 @@ public:
this->UpdateAeronetData( file, year, m_Month, m_Day, hour, minute, 0.4 );
};
/** Read a file that contains filter function values.
* Format is MinSpectralValue MaxSpectralValue UserStep and then the list of coefficients for each band.
* NB : if no UserStep writen, the default value will be 0,0025nm
*/
void LoadFilterFunctionValue( std::string filename );
/** Constructor */
AtmosphericCorrectionParameters();
/** Destructor */
......
......@@ -27,13 +27,13 @@ AtmosphericRadiativeTermsSingleChannel
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os,indent);
os << indent << "Intrinsic Atmospheric Reflectance: " << m_IntrinsicAtmosphericReflectance << std::endl;
os << indent << "Shperical Albedo of the Atmosphere: " << m_SphericalAlbedo << std::endl;
os << indent << "Total Gaseous Transmission: " << m_TotalGaseousTransmission << std::endl;
os << indent << "Downward Transmittance of the Atmospher: " << m_DownwardTransmittance << std::endl;
os << indent << "Upward Transmittance of the Atmospher: " << m_UpwardTransmittance << std::endl;
os << indent << "Upward diffuse transmittance: " << m_UpwardDiffuseTransmittance << std::endl;
os << indent << "Upward direct transmittance: " << m_UpwardDirectTransmittance << std::endl;
os << indent << "Intrinsic Atmospheric Reflectance : " << m_IntrinsicAtmosphericReflectance << std::endl;
os << indent << "Shperical Albedo of the Atmosphere : " << m_SphericalAlbedo << std::endl;
os << indent << "Total Gaseous Transmission : " << m_TotalGaseousTransmission << std::endl;
os << indent << "Downward Transmittance of the Atmospher : " << m_DownwardTransmittance << std::endl;
os << indent << "Upward Transmittance of the Atmospher : " << m_UpwardTransmittance << std::endl;
os << indent << "Upward diffuse transmittance : " << m_UpwardDiffuseTransmittance << std::endl;
os << indent << "Upward direct transmittance : " << m_UpwardDirectTransmittance << std::endl;
os << indent << "Upward diffuse transmittance for rayleigh: " << m_UpwardDiffuseTransmittanceForRayleigh << std::endl;
os << indent << "Upward diffuse transmittance for aerosols: " << m_UpwardDiffuseTransmittanceForAerosol << std::endl;
}
......
......@@ -144,7 +144,6 @@ private:
/** The upward diffuse transmittance for aerosols. */
double m_UpwardDiffuseTransmittanceForAerosol;
};
......
......@@ -21,7 +21,7 @@
#include "otbReflectanceToSurfaceReflectanceImageFilter.h"
#include "otbImageMetadataInterfaceFactory.h"
#include "otbImageMetadataInterfaceBase.h"
#include "otbAeronetFileReader.h"
namespace otb
{
......@@ -48,7 +48,7 @@ ReflectanceToSurfaceReflectanceImageFilter<TInputImage,TOutputImage>
::UpdateAtmosphericRadiativeTerms()
{
MetaDataDictionaryType dict = this->GetInput()->GetMetaDataDictionary();
std::cout<<"Tu passes?"<<std::endl;
ImageMetadataInterfaceBase::Pointer imageMetadataInterface = ImageMetadataInterfaceFactory::CreateIMI(dict);
if ((m_CorrectionParameters->GetDay() == 0))
......@@ -87,24 +87,34 @@ ReflectanceToSurfaceReflectanceImageFilter<TInputImage,TOutputImage>
imageMetadataInterface->GetHour(dict),
imageMetadataInterface->GetMinute(dict) );
Parameters2RadiativeTermsPointerType param2Terms = Parameters2RadiativeTermsType::New();
if( m_FilterFunctionCoef.size() != this->GetInput()->GetNumberOfComponentsPerPixel() )
itkExceptionMacro(<<"Filter Function and image channels mismatch.");
for(unsigned int i=0; i<this->GetInput()->GetNumberOfComponentsPerPixel(); i++)
// load fiter function values
if(m_FilterFunctionValuesFileName != "")
{
FilterFunctionValuesType::Pointer functionValues = FilterFunctionValuesType::New();
functionValues->SetFilterFunctionValues(m_FilterFunctionCoef[i]);
functionValues->SetMinSpectralValue(imageMetadataInterface->GetFirstWavelengths(dict)[i]);
functionValues->SetMaxSpectralValue(imageMetadataInterface->GetLastWavelengths(dict)[i]);
m_CorrectionParameters->SetWavelenghtSpectralBandWithIndex(i, functionValues);
m_CorrectionParameters->LoadFilterFunctionValue( m_FilterFunctionValuesFileName );
}
// the user has set the filter function values
else
{
if( m_FilterFunctionCoef.size() != this->GetInput()->GetNumberOfComponentsPerPixel() )
{
itkExceptionMacro(<<"Filter Function and image channels mismatch.");
}
for(unsigned int i=0; i<this->GetInput()->GetNumberOfComponentsPerPixel(); i++)
{
FilterFunctionValuesType::Pointer functionValues = FilterFunctionValuesType::New();
functionValues->SetFilterFunctionValues(m_FilterFunctionCoef[i]);
functionValues->SetMinSpectralValue(imageMetadataInterface->GetFirstWavelengths(dict)[i]);
functionValues->SetMaxSpectralValue(imageMetadataInterface->GetLastWavelengths(dict)[i]);
m_CorrectionParameters->SetWavelenghtSpectralBandWithIndex(i, functionValues);
}
}
Parameters2RadiativeTermsPointerType param2Terms = Parameters2RadiativeTermsType::New();
param2Terms->SetInput(m_CorrectionParameters);
param2Terms->Update();
m_AtmosphericRadiativeTerms = param2Terms->GetOutput();
}
......
......@@ -28,7 +28,6 @@ int otbReflectanceToSurfaceReflectanceImageFilter(int argc, char * argv[])
const char * inputFileName = argv[1];
const char * outputFileName = argv[2];
const unsigned int Dimension = 2;
typedef double PixelType;
typedef otb::VectorImage<PixelType,Dimension> InputImageType;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment