Skip to content
Snippets Groups Projects
Commit e94da76a authored by Jonathan Guinet's avatar Jonathan Guinet
Browse files

STYLE: indent correction.

parent 2da33ef5
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
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.
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 __otbSatelliteRSR_h
#define __otbSatelliteRSR_h
#include "itkDataObject.h"
#include <itkObjectFactory.h>
#include <vector>
......@@ -31,122 +30,129 @@
namespace otb
{
/** \class SatelliteRSR
* \brief This class represents a hierarchy of vector data.
*
* This class contains an std::vector of spectral response, class otb::SpectralResponse (one for each band of the satellite).
*
*
* The two templates indicate:
* - the precision of the wavelength (X) (by default: double)
* - the precision of the gain associated to the wavelength (Y) (by default: double)
* \sa SpectralResponse
* \sa itk::DataObject
* \brief This class represents a hierarchy of vector data.
*
* This class contains an std::vector of spectral response, class otb::SpectralResponse (one for each band of the satellite).
*
*
* The two templates indicate:
* - the precision of the wavelength (X) (by default: double)
* - the precision of the gain associated to the wavelength (Y) (by default: double)
* \sa SpectralResponse
* \sa itk::DataObject
*/
template <class TPrecision = double, class TValuePrecision = double>
class SatelliteRSR : public itk::DataObject
template<class TPrecision = double, class TValuePrecision = double>
class SatelliteRSR: public itk::DataObject
{
public:
/** Standard class typedefs */
typedef SatelliteRSR Self;
typedef itk::DataObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macros */
itkNewMacro(Self);
itkTypeMacro(SatelliteRSR, DataObject);
/** Set the number of band of the satellite from an ASCII file
* Need to parse first all the file to determine the number of columns */
itkGetConstMacro(NbBands, unsigned int);
itkSetMacro(NbBands, unsigned int);
itkSetMacro(SortBands, bool);
/** Template parameters typedef */
typedef TPrecision PrecisionType;
typedef TValuePrecision ValuePrecisionType;
typedef SpectralResponse <TPrecision, TValuePrecision> SpectralResponseType;
typedef typename SpectralResponseType::Pointer SpectralResponsePointerType;
typedef std::vector <SpectralResponsePointerType> RSRVectorType;
typedef typename SpectralResponseType::VectorPairType VectorPairType;
/** Clear the vector data */
virtual bool Clear();
/** Return the number of element in the vector (nb bands) */
virtual int Size() const;
/** Fill from a ASCII file (spectral gauge)*/
void Load( const std::string & filename , ValuePrecisionType coefNormalization = 1.0 );
/** Fill from user defined criteria (sampling band from lambdaMin to lambdaMax with Bandwidth width) */
void Load(PrecisionType lambdaMin, PrecisionType lambdaMax , PrecisionType sampling, ValuePrecisionType coefNormalization = 1.0 );
/** Compare RSR response (order bands from high to low frequency)*/
struct sort_band {
bool operator() ( SpectralResponsePointerType a , SpectralResponsePointerType b )
{
PrecisionType aFirstNotNull;
PrecisionType bFirstNotNull;
typename VectorPairType::const_iterator it = a->GetResponse().begin();
while ((*it).second == 0)
{
++it;
}
aFirstNotNull = (*it).first;
typename VectorPairType::const_iterator it2 = b->GetResponse().begin();
while ((*it2).second == 0)
{
++it2;
}
bFirstNotNull = (*it2).first;
return aFirstNotNull < bFirstNotNull;
}
};
/**
* \param PrecisionType
* \param Band
* \return The interpolate value of the SR for the numBand (band num 0 to band num (m_NbBands-1)).
*/
inline ValuePrecisionType operator()(const PrecisionType & lambda, const unsigned int numBand);
/** PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** get vector of RSR */
RSRVectorType & GetRSR()
{
return m_RSR;
}
protected:
/** Constructor */
SatelliteRSR();
/** Constructor from a ASCII file */
//SatelliteRSR( const std::string & filename );
/** Destructor */
virtual ~SatelliteRSR() {};
public:
/** Standard class typedefs */
typedef SatelliteRSR Self;
typedef itk::DataObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macros */
itkNewMacro(Self)
;itkTypeMacro(SatelliteRSR, DataObject)
;
/** Set the number of band of the satellite from an ASCII file
* Need to parse first all the file to determine the number of columns */
itkGetConstMacro(NbBands, unsigned int)
;itkSetMacro(NbBands, unsigned int)
;
itkSetMacro(SortBands, bool)
;
/** Template parameters typedef */
typedef TPrecision PrecisionType;
typedef TValuePrecision ValuePrecisionType;
typedef SpectralResponse<TPrecision, TValuePrecision> SpectralResponseType;
typedef typename SpectralResponseType::Pointer SpectralResponsePointerType;
typedef std::vector<SpectralResponsePointerType> RSRVectorType;
typedef typename SpectralResponseType::VectorPairType VectorPairType;
/** Clear the vector data */
virtual bool Clear();
/** Return the number of element in the vector (nb bands) */
virtual int Size() const;
/** Fill from a ASCII file (spectral gauge)*/
void Load(const std::string & filename, ValuePrecisionType coefNormalization = 1.0);
/** Fill from user defined criteria (sampling band from lambdaMin to lambdaMax with Bandwidth width) */
void Load(PrecisionType lambdaMin, PrecisionType lambdaMax, PrecisionType sampling,
ValuePrecisionType coefNormalization = 1.0);
/** Compare RSR response (order bands from high to low frequency)*/
struct sort_band
{
bool operator()(SpectralResponsePointerType a, SpectralResponsePointerType b)
{
PrecisionType aFirstNotNull;
PrecisionType bFirstNotNull;
typename VectorPairType::const_iterator it = a->GetResponse().begin();
while ((*it).second == 0)
{
++it;
}
aFirstNotNull = (*it).first;
typename VectorPairType::const_iterator it2 = b->GetResponse().begin();
while ((*it2).second == 0)
{
++it2;
}
bFirstNotNull = (*it2).first;
return aFirstNotNull < bFirstNotNull;
}
};
/**
* \param PrecisionType
* \param Band
* \return The interpolate value of the SR for the numBand (band num 0 to band num (m_NbBands-1)).
*/
inline ValuePrecisionType operator()(const PrecisionType & lambda, const unsigned int numBand);
/** PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** get vector of RSR */
RSRVectorType & GetRSR()
{
return m_RSR;
}
protected:
/** Constructor */
SatelliteRSR();
/** Constructor from a ASCII file */
//SatelliteRSR( const std::string & filename );
/** Destructor */
virtual ~SatelliteRSR()
{
}
;
bool m_SortBands;
private:
SatelliteRSR(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
private:
SatelliteRSR(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/** Vector of SpectralResponse */
RSRVectorType m_RSR;
/** Number of bands*/
unsigned int m_NbBands;
/** Vector of SpectralResponse */
RSRVectorType m_RSR;
/** Number of bands*/
unsigned int m_NbBands;
};
}// end namespace otb
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
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.
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 __otbSatelliteRSR_txx
#define __otbSatelliteRSR_txx
#include "otbSatelliteRSR.h"
namespace otb
{
template <class TPrecision, class TValuePrecision>
SatelliteRSR<TPrecision, TValuePrecision>
::SatelliteRSR()
template<class TPrecision, class TValuePrecision>
SatelliteRSR<TPrecision, TValuePrecision>::SatelliteRSR()
{
//m_RSR = VectorType::New();
//m_RSR = VectorType::New();
m_SortBands = true;
}
template <class TPrecision, class TValuePrecision>
void
SatelliteRSR<TPrecision, TValuePrecision>
::Load(const std::string & filename, ValuePrecisionType coefNormalization)
template<class TPrecision, class TValuePrecision>
void SatelliteRSR<TPrecision, TValuePrecision>::Load(const std::string & filename, ValuePrecisionType coefNormalization)
{
//Parse 6S file Reduce spectral response
//Begin by getting the number of band of the satellite
//unsigned int nbBands= this->SetNbBands ( filename );
std::ifstream fin(filename.c_str());
if ( fin.fail() )
{
itkExceptionMacro(<<"Error opening file" << filename);
}
// For each band
for (unsigned int i=0; i < m_NbBands; ++i)
{
//Create a SpectralResponse for the band i
SpectralResponsePointerType RSRBand = SpectralResponseType::New();
m_RSR.push_back (RSRBand);
}
PrecisionType currentLambda;
PrecisionType zenithalAngle;
while(! fin.eof() )
{
//Parse the 6S.txt file
fin >> currentLambda;
fin >> zenithalAngle;
//for each band add a pair of values (wavelength and % response)
for (unsigned int i=0; i < m_NbBands; ++i)
//Parse 6S file Reduce spectral response
//Begin by getting the number of band of the satellite
//unsigned int nbBands= this->SetNbBands ( filename );
std::ifstream fin(filename.c_str());
if (fin.fail())
{
itkExceptionMacro(<<"Error opening file" << filename);
}
// For each band
for (unsigned int i = 0; i < m_NbBands; ++i)
{
//Create a SpectralResponse for the band i
SpectralResponsePointerType RSRBand = SpectralResponseType::New();
m_RSR.push_back(RSRBand);
}
PrecisionType currentLambda;
PrecisionType zenithalAngle;
while (!fin.eof())
{
//Parse the 6S.txt file
fin >> currentLambda;
fin >> zenithalAngle;
//for each band add a pair of values (wavelength and % response)
for (unsigned int i = 0; i < m_NbBands; ++i)
{
std::pair <TPrecision, TValuePrecision > currentPair;
currentPair.first = currentLambda;
fin >> currentPair.second;
currentPair.second = currentPair.second / coefNormalization;
//Include only non null value //TODO
m_RSR[i]->GetResponse().push_back(currentPair);
std::pair<TPrecision, TValuePrecision> currentPair;
currentPair.first = currentLambda;
fin >> currentPair.second;
currentPair.second = currentPair.second / coefNormalization;
//Include only non null value //TODO
m_RSR[i]->GetResponse().push_back(currentPair);
}
}
fin.close();
if(m_SortBands)
{
//Sort the vector of SpectralResponse (band order by minimum wavelength first not null response
std::sort(m_RSR.begin(), m_RSR.end(), sort_band());
}
}
fin.close();
if (m_SortBands)
{
//Sort the vector of SpectralResponse (band order by minimum wavelength first not null response
std::sort(m_RSR.begin(), m_RSR.end(), sort_band());
}
}
template <class TPrecision, class TValuePrecision>
void
SatelliteRSR<TPrecision, TValuePrecision>
::Load(PrecisionType lambdaMin, PrecisionType lambdaMax , PrecisionType sampling, ValuePrecisionType coefNormalization )
template<class TPrecision, class TValuePrecision>
void SatelliteRSR<TPrecision, TValuePrecision>::Load(PrecisionType lambdaMin, PrecisionType lambdaMax,
PrecisionType sampling, ValuePrecisionType coefNormalization)
{
m_NbBands = 1;
const double wavelengthPrecision = 0.0025; //in um
......@@ -117,59 +111,50 @@ SatelliteRSR<TPrecision, TValuePrecision>
}
template <class TPrecision, class TValuePrecision>
bool
SatelliteRSR<TPrecision, TValuePrecision>
::Clear()
template<class TPrecision, class TValuePrecision>
bool SatelliteRSR<TPrecision, TValuePrecision>::Clear()
{
m_RSR.clear();
return true;
m_RSR.clear();
return true;
}
template <class TPrecision, class TValuePrecision>
int
SatelliteRSR<TPrecision, TValuePrecision>
::Size() const
template<class TPrecision, class TValuePrecision>
int SatelliteRSR<TPrecision, TValuePrecision>::Size() const
{
return m_RSR.size();
return m_RSR.size();
}
template <class TPrecision, class TValuePrecision>
inline typename SatelliteRSR<TPrecision, TValuePrecision>::ValuePrecisionType
SatelliteRSR<TPrecision, TValuePrecision>
::operator()(const PrecisionType & lambda, const unsigned int numBand)
template<class TPrecision, class TValuePrecision>
inline typename SatelliteRSR<TPrecision, TValuePrecision>::ValuePrecisionType SatelliteRSR<TPrecision, TValuePrecision>::operator()(
const PrecisionType & lambda,
const unsigned int numBand)
{
//Get the response of the band number numBand at the wavelenght lambda
if ( numBand >= m_NbBands )
{
itkExceptionMacro(<<"There is no band num " << numBand<< " in the RSR vector!(Size of the current RSR vector is " << m_NbBands <<")");
}
else
{
return (*(m_RSR[numBand]))(lambda);
}
//Get the response of the band number numBand at the wavelenght lambda
if (numBand >= m_NbBands)
{
itkExceptionMacro(<<"There is no band num " << numBand<< " in the RSR vector!(Size of the current RSR vector is " << m_NbBands <<")");
}
else
{
return (*(m_RSR[numBand]))(lambda);
}
}
template <class TPrecision, class TValuePrecision>
void
SatelliteRSR<TPrecision, TValuePrecision>
::PrintSelf(std::ostream& os, itk::Indent indent) const
template<class TPrecision, class TValuePrecision>
void SatelliteRSR<TPrecision, TValuePrecision>::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os<<std::endl;
//typename VectorPairType::iterator it = m_RSR.begin();
//it = m_RSR.at(0);
for(typename RSRVectorType::const_iterator it = m_RSR.begin(); it != m_RSR.end(); ++it)
{
os << indent << "Band Number " << it - m_RSR.begin() << std::endl;
(*it)->PrintSelf (os, indent);
os << std::endl;
}
Superclass::PrintSelf(os, indent);
os << std::endl;
//typename VectorPairType::iterator it = m_RSR.begin();
//it = m_RSR.at(0);
for (typename RSRVectorType::const_iterator it = m_RSR.begin(); it != m_RSR.end(); ++it)
{
os << indent << "Band Number " << it - m_RSR.begin() << std::endl;
(*it)->PrintSelf(os, indent);
os << std::endl;
}
}
} // end namespace otb
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment