Commit c4be05b9 authored by Julien Michel's avatar Julien Michel

TEST: Fix failing tests and fix band index convention (always start at 1)

parent 9da9922e
Pipeline #1022 failed with stages
in 65 minutes and 41 seconds
......@@ -134,7 +134,7 @@ int main(int argc, char* argv[])
// The three used index bands (red, blue and NIR) are declared.
filter->GetFunctor().SetBandIndex(CommonBandNames::RED,::atoi(argv[5]));
filter->GetFunctor().SetBandIndex(CommonBandNames::GREEN,::atoi(argv[6]));
filter->GetFunctor().SetBandIndex(CommonBandNames::BLUE,::atoi(argv[6]));
filter->GetFunctor().SetBandIndex(CommonBandNames::NIR,::atoi(argv[7]));
// The filter input is linked to the reader output and
......
......@@ -94,18 +94,27 @@ private:
AddParameter(ParameterType_Int, "channels.blue", "Blue Channel");
SetParameterDescription("channels.blue", "Blue channel index");
SetDefaultParameterInt("channels.blue", 1);
SetMinimumParameterIntValue("channels.blue",1);
AddParameter(ParameterType_Int, "channels.green", "Green Channel");
SetParameterDescription("channels.green", "Green channel index");
SetDefaultParameterInt("channels.green", 1);
SetMinimumParameterIntValue("channels.green",1);
AddParameter(ParameterType_Int, "channels.red", "Red Channel");
SetParameterDescription("channels.red", "Red channel index");
SetDefaultParameterInt("channels.red", 1);
SetMinimumParameterIntValue("channels.red",1);
AddParameter(ParameterType_Int, "channels.nir", "NIR Channel");
SetParameterDescription("channels.nir", "NIR channel index");
SetDefaultParameterInt("channels.nir", 1);
SetMinimumParameterIntValue("channels.nir",1);
AddParameter(ParameterType_Int, "channels.mir", "Mir Channel");
SetParameterDescription("channels.mir", "Mir channel index");
SetDefaultParameterInt("channels.mir", 1);
SetMinimumParameterIntValue("channels.mir",1);
AddParameter(ParameterType_ListView, "list", "Available Radiometric Indices");
SetParameterDescription("list",
......@@ -212,7 +221,7 @@ private:
}
else
{
indicesMap[band] = idx-1;
indicesMap[band] = idx;
}
}
};
......
......@@ -97,22 +97,22 @@ public:
//TODO replace by metadata parsing
unsigned int GetREDChannelIndex() const
{
return m_NDVIFunctor.GetBandIndex(CommonBandNames::RED)+1;
return m_NDVIFunctor.GetBandIndex(CommonBandNames::RED);
}
void SetREDChannelIndex(unsigned int id)
{
m_NDVIFunctor.SetBandIndex(CommonBandNames::RED,id-1);
m_NDVIFunctor.SetBandIndex(CommonBandNames::RED,id);
}
unsigned int GetNIRChannelIndex() const
{
return m_NDVIFunctor.GetBandIndex(CommonBandNames::NIR)+1;
return m_NDVIFunctor.GetBandIndex(CommonBandNames::NIR);
}
void SetNIRChannelIndex(unsigned int id)
{
m_NDVIFunctor.SetBandIndex(CommonBandNames::NIR,id-1);
m_NDVIFunctor.SetBandIndex(CommonBandNames::NIR,id);
}
protected:
......
......@@ -117,7 +117,7 @@ public:
/**
* \param band The band to set (value in TBandNameEnum)
* \param index The index of the band to set
* \param index The index of the band to set (starts at 1 for first band)
* \throw runtime_error if band is TBandNameEnum::MAX
*/
void SetBandIndex(const BandNameType & band, const size_t & index)
......@@ -131,7 +131,7 @@ public:
/**
* \param indicesMap a std::map<TBandNameEnum,size_t> containing all
* bands indices to set
* bands indices to set (starts at 1 for first band)
* \throw runtime_error if indicesMap contains TBandNameEnum::MAX
*/
void SetBandsIndices(const std::map<BandNameType,size_t> & indicesMap)
......@@ -160,7 +160,7 @@ public:
* Astract method which will compute the radiometric indice
* \param input A itk::VariableLengthVector<TInput> holding the
* pixel values for each band
* \return The indice value as TOutput
* \return The indice value as TOutput (starts at 1 for first band)
*/
virtual TOutput operator()(const itk::VariableLengthVector<TInput> & input) const = 0;
......@@ -201,7 +201,7 @@ protected:
double Value(const BandNameType & band, const itk::VariableLengthVector<TInput> & input) const
{
assert(m_RequiredBands[band] && "Retrieving value for a band that is not in the required bands list");
return static_cast<double>(input[UncheckedBandIndex(band)]);
return static_cast<double>(input[UncheckedBandIndex(band)-1]);
}
private:
......
......@@ -737,8 +737,7 @@ public:
{
return static_cast<TOutput>(0.);
}
return static_cast<TOutput>(A*((std::exp((nir-red)/((red+nir)*B))-std::exp(C*B))));
return static_cast<TOutput>(A*(std::exp((nir-red)/(red+nir)*B)-std::exp(C*B)));
}
static constexpr double A = 0.1519;
......
......@@ -68,7 +68,7 @@ using namespace otb::Functor;
int otbVegetationIndicesTest(int, char**)
{
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}};
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}};
// Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result)
bool res = CheckResult< NDVI<int,double> >("ndvi_null ",bandMap,{0,0,0,0},0.);
......@@ -90,7 +90,7 @@ int otbVegetationIndicesTest(int, char**)
res = res & CheckResult< IPVI<int,double> >("ipvi_pixel",bandMap,{0,0,1,2},0.6666666667);
res = res & CheckResult< LAIFromNDVILogarithmic<int,double> >("lailog_pixel",bandMap,{0,0,1,2},0.4930511672);
res = res & CheckResult< LAIFromReflectancesLinear<int,double> >("lailog_pixel",bandMap,{0,0,1,2},6.61);
res = res & CheckResult< LAIFromNDVIFormosat2Functor<int,double> >("laifrom_pixel",bandMap,{0,0,1,2},-0.08836147592);
res = res & CheckResult< LAIFromNDVIFormosat2Functor<int,double> >("laifrom_pixel",bandMap,{0,0,1,2},0.3120010659);
if(res)
{
......@@ -104,7 +104,7 @@ int otbVegetationIndicesTest(int, char**)
int otbWaterIndicesTest(int, char**)
{
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}, {CommonBandNames::MIR,4}};
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}};
// Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result)
bool res = CheckResult< NDWI<int,double> >("ndwi_null ",bandMap,{0,0,0,0,0},0.);
......@@ -128,7 +128,7 @@ int otbWaterIndicesTest(int, char**)
int otbSoilIndicesTest(int, char**)
{
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}, {CommonBandNames::MIR,4}};
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}};
// Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result)
bool res = CheckResult< CI<int,double> >("ci_null ",bandMap,{0,0,0,0,0},0.);
......@@ -148,7 +148,7 @@ int otbSoilIndicesTest(int, char**)
int otbBuiltUpIndicesTest(int, char**)
{
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}, {CommonBandNames::MIR,4}};
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}};
// Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result)
bool res = CheckResult< ISU<int,double> >("isu_null",bandMap,{0,0,0,0,0},0.);
......@@ -237,7 +237,7 @@ int otbIndicesStackFunctorTest(int, char**)
success = false;
}
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}, {CommonBandNames::MIR,4}};
const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}};
ndvi.SetBandsIndices(bandMap);
ndwi.SetBandsIndices(bandMap);
......
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