Commit 9b9c2624 authored by Guillaume Pasero's avatar Guillaume Pasero

COV: various coverity fix

parent 6f49eda8
......@@ -472,8 +472,8 @@ int main(int argc, char* argv[])
outputImage->SetPixel(currentIndexBis, pixelValue);
}
delete pixelIndexArray;
delete currentIndexArray;
delete[] pixelIndexArray;
delete[] currentIndexArray;
}
// Software Guide : EndCodeSnippet
......
......@@ -102,16 +102,15 @@ public:
ArrayType GetUniqueValues() const
{
ArrayType uniqueValues;
if( !m_Image )
{
itkExceptionMacro(<<"GetUniqueValues(): Null input image pointer.");
return uniqueValues;
}
itk::ImageRegionConstIterator< ImageType > it( m_Image,
m_Image->GetRequestedRegion() );
ArrayType uniqueValues;
uniqueValues.push_back(it.Get());
++it;
while( !it.IsAtEnd() )
......@@ -758,6 +757,11 @@ int main(int argc, char *argv[])
UniqueCalculatorType::ArrayType uniqueVals =
uniqueCalculator->GetUniqueValues();
if (uniqueVals.empty())
{
std::cerr << "No label value found!"<< std::endl;
return EXIT_FAILURE;
}
std::cout << "Labels are " << std::endl;
UniqueCalculatorType::ArrayType::const_iterator uvIt = uniqueVals.begin();
......
......@@ -261,6 +261,10 @@ private:
accNbElemPS++;
}
}
if (accNbElemPS == 0)
{
otbAppLogFATAL(<< "Error : no element found in positive vector data!");
}
TreeIteratorType itVectorNS(nsVectorData->GetDataTree());
std::vector<double> accFirstOrderNS, accSecondOrderNS, minNS, maxNS;
......@@ -300,6 +304,10 @@ private:
accNbElemNS++;
}
}
if (accNbElemNS == 0)
{
otbAppLogFATAL(<< "Error : no element found in negative vector data!");
}
otbAppLogINFO( << "Descriptors Stats : ");
otbAppLogINFO( << "Positive Samples");
for (unsigned int i = 0; i < descList.size(); ++i)
......@@ -406,11 +414,9 @@ private:
{
// An error has occurred in the optimization.
// Update the parameters
otbAppLogFATAL("ERROR: Exception Catched!" << std::endl);
otbAppLogFATAL(<< err.GetDescription() << std::endl);
const unsigned int numberOfIterations = m_Optimizer->GetOptimizer()->get_num_evaluations();
otbAppLogFATAL("numberOfIterations : " << numberOfIterations << std::endl);
otbAppLogFATAL("Results : " << m_Optimizer->GetCurrentPosition() << std::endl);
otbAppLogFATAL("ERROR: Exception Catched : "<< err.GetDescription() << std::endl
<< "numberOfIterations : " << m_Optimizer->GetOptimizer()->get_num_evaluations() << std::endl
<< "Results : " << m_Optimizer->GetCurrentPosition() << std::endl);
}
// get the results
const unsigned int numberOfIterations = m_Optimizer->GetOptimizer()->get_num_evaluations();
......
......@@ -325,8 +325,8 @@ private:
if(nbPixels[curLabel]==size)
{
edgeLabel.insert(curLabel);
for(std::set<int>::iterator itAdjLabel=adjMap[curLabel].begin();
itAdjLabel!=adjMap[curLabel].end(); ++itAdjLabel)
for(std::set<int>::iterator itAdjLabel=(adjMap[curLabel]).begin();
itAdjLabel!=(adjMap[curLabel]).end(); ++itAdjLabel)
{
double tmpError = 0;
LabelImagePixelType tmpLabel = *itAdjLabel;
......
......@@ -138,22 +138,17 @@ int otbBandMathImageFilter( int itkNotUsed(argc), char* itkNotUsed(argv) [])
error = (result - expected) * (result - expected) / (result + expected);
if ( error > 1E-9 )
{
itkGenericExceptionMacro( <<std::endl
std::cout
<< "Error = " << error << " > 1E-9 -> TEST FAILLED" << std::endl
<< "Pixel_1 = " << it1.Get()
<< " Pixel_2 = " << it2.Get()
<< " Pixel_3 = " << it3.Get()
<< " Result = " << it.Get()
<< " Expected = " << expected << std::endl );
<< " Expected = " << expected << std::endl;
FAIL_FLAG++;
break;
}
}
if(!FAIL_FLAG)
std::cout << "[PASSED]" << std::endl;
else
std::cout << "[FAILLED]" << std::endl;
FAIL_FLAG = 0;
}
/** Edge Effect Handling */
......@@ -166,14 +161,23 @@ int otbBandMathImageFilter( int itkNotUsed(argc), char* itkNotUsed(argv) [])
it1.GoToBegin(); it2.GoToBegin(); it.GoToBegin();
for(i=1; i<=50; ++i , ++it1, ++it2, ++it){}
if(vnl_math_isnan(it.Get()))
std::cout << "Pixel_1 = " << it1.Get() << " Pixel_2 = " << it2.Get() << " Result = " << it.Get() << " Expected = nan\n";
std::cout << "Pixel_1 = " << it1.Get() << " Pixel_2 = " << it2.Get() << " Result = " << it.Get() << " Expected = nan\n" << std::endl;
else
itkGenericExceptionMacro(
{
std::cout
<< "\nError > Bad Edge Effect Handling -> Test Failled\n"
<< "Pixel_1 = " << it1.Get() << " Pixel_2 = " << it2.Get()
<< " Result = " << it.Get() << " Expected = nan\n" );
std::cout << std::endl;
<< " Result = " << it.Get() << " Expected = nan\n" << std::endl;
FAIL_FLAG++;
}
if (FAIL_FLAG)
{
std::cout << "[FAILLED]" << std::endl;
return EXIT_FAILURE;
}
std::cout << "[PASSED]" << std::endl;
return EXIT_SUCCESS;
}
......
......@@ -68,7 +68,7 @@ public:
* \param imageList The analysed image at each level of the pyramid.
*/
using Superclass::SetInput;
void SetInput(InputImageListType * imageList);
void SetInput(const InputImageListType * imageList);
/**
* Set The SupFilter details
* \param imageList The brighter details extracted from the filtering operation.
......
......@@ -118,7 +118,7 @@ MRToMSConverter<TInputImage, TOutputImage>
template <class TInputImage, class TOutputImage>
void
MRToMSConverter<TInputImage, TOutputImage>
::SetInput(InputImageListType * imageList)
::SetInput(const InputImageListType * imageList)
{
this->SetNthInput(2, const_cast<InputImageListType *>(imageList));
}
......
......@@ -240,9 +240,9 @@ PersistentStatisticsImageFilter<TInputImage>
PixelType minimum;
PixelType maximum;
RealType mean;
RealType sigma;
RealType variance;
RealType mean = itk::NumericTraits<RealType>::Zero;
RealType sigma = itk::NumericTraits<RealType>::Zero;
RealType variance = itk::NumericTraits<RealType>::Zero;
RealType sum;
sum = sumOfSquares = itk::NumericTraits<RealType>::Zero;
......@@ -267,13 +267,23 @@ PersistentStatisticsImageFilter<TInputImage>
maximum = m_ThreadMax[i];
}
}
// compute statistics
mean = sum / static_cast<RealType>(count);
if (count > 0)
{
// compute statistics
mean = sum / static_cast<RealType>(count);
// unbiased estimate
variance = (sumOfSquares - (sum * sum / static_cast<RealType>(count)))
/ (static_cast<RealType>(count) - 1);
sigma = vcl_sqrt(variance);
if (count > 1)
{
// unbiased estimate
variance = (sumOfSquares - (sum * sum / static_cast<RealType>(count)))
/ static_cast<RealType>(count - 1);
sigma = vcl_sqrt(variance);
}
}
else
{
itkWarningMacro(<<"No pixel found to compute statistics!");
}
// Set the outputs
this->GetMinimumOutput()->Set(minimum);
......
......@@ -55,6 +55,7 @@ ConfusionMatrixMeasurements<TConfusionMatrix, TLabel>
m_TruePositiveValues.Fill(0);
m_TrueNegativeValues.Fill(0);
const double epsilon = 0.0000000001;
double luckyRate = 0.;
this->m_NumberOfSamples = 0;
this->m_OverallAccuracy = 0.;
......@@ -83,8 +84,6 @@ ConfusionMatrixMeasurements<TConfusionMatrix, TLabel>
luckyRate += sum_along_row_i * sum_along_column_i;
}
this->m_OverallAccuracy /= static_cast<double>(m_NumberOfSamples);
this->m_TrueNegativeValues.Fill(m_NumberOfSamples);
this->m_TrueNegativeValues -= this->m_FalseNegativeValues
+ this->m_FalsePositiveValues
......@@ -116,7 +115,27 @@ ConfusionMatrixMeasurements<TConfusionMatrix, TLabel>
m_Recalls.Fill(0.);
m_FScores.Fill(0.);
const double epsilon = 0.0000000001;
if (m_NumberOfSamples > 0)
{
this->m_OverallAccuracy /= static_cast<double>(m_NumberOfSamples);
luckyRate /= vcl_pow(m_NumberOfSamples, 2.0);
if (vcl_abs(1 - luckyRate) > epsilon)
{
m_KappaIndex = (m_OverallAccuracy - luckyRate) / (1 - luckyRate);
}
else
{
this->m_KappaIndex = 1.;
}
}
else
{
this->m_OverallAccuracy = 0.;
this->m_KappaIndex = 0.;
// no samples, no need to continue
return;
}
for (unsigned int i = 0; i < m_NumberOfClasses; ++i)
{
......@@ -155,13 +174,6 @@ ConfusionMatrixMeasurements<TConfusionMatrix, TLabel>
this->m_FScore = 2 * this->m_Recall * this->m_Precision / (this->m_Recall + this->m_Precision);
}
}
luckyRate /= vcl_pow(m_NumberOfSamples, 2.0);
if (vcl_abs(1 - luckyRate) > epsilon)
{
m_KappaIndex = (m_OverallAccuracy - luckyRate) / (1 - luckyRate);
}
}
/*
......
......@@ -337,7 +337,7 @@ SailModel
// Outputs for the case LAI = 0
if (m_LAI<0)
{
tss = 1;
//tss = 1;
too = 1;
tsstoo = 1;
rdd = 0;
......@@ -355,7 +355,7 @@ SailModel
rdot = rsoil0;
rsodt = 0;
rsost = rsoil0;
rsot = rsoil0;
//rsot = rsoil0;
}
// Other cases (LAI > 0)
......
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