Commit fce6febd authored by Luc Hermitte's avatar Luc Hermitte

COMP: Add missing include

`std::runtime_error` usage requires `<stdexcept>`
parent 10934b48
Pipeline #5727 failed with stages
in 82 minutes and 52 seconds
......@@ -25,6 +25,7 @@
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdexcept>
namespace otb
{
......@@ -37,7 +38,7 @@ namespace Functor
* Du, Yingzi & Chang, Chein-I & Ren, Hsuan & Chang, Chein-Chi & Jensen, James & D'Amico, Francis. (2004). "
"New Hyperspectral Discrimination Measure for Spectral Characterization. Optical Engineering - OPT ENG. 43."
" 1777-1786. 10.1117/1.1766301.
*
*
* \ingroup OTBImageManipulation
*/
template <class TInput, class TReference, class TOutput>
......@@ -46,17 +47,17 @@ class SpectralInformationDivergenceFunctor
public:
SpectralInformationDivergenceFunctor() = default;
virtual ~SpectralInformationDivergenceFunctor() = default;
using OutputValueType = typename TOutput::ValueType;
// Binary operator
inline TOutput operator()(const TInput& input) const
{
TOutput res;
res.SetSize(m_ReferenceProbabilities.size());
auto inputProbability = ComputeProbabilityMassFunction(input);
for (unsigned int i = 0; i< m_ReferenceProbabilities.size(); i++)
{
res[i] = ComputeSpectralInformationDivergence(inputProbability, m_ReferenceProbabilities[i]);
......@@ -80,19 +81,19 @@ public:
m_ReferenceProbabilities.push_back(ComputeProbabilityMassFunction(pixel));
}
}
private:
inline TInput ComputeProbabilityMassFunction(TInput const & input) const
{
for (unsigned int i = 0; i < input.Size(); i++)
{
// Input pixel should be non negative (e.g. reflectance, radiance)
if (input[i] <= 0)
if (input[i] <= 0)
{
throw std::runtime_error("Input pixels of the spectral information divergence algorithm should be strictly positive.");
}
}
return input / std::accumulate(&input[0], &input[input.Size()], 0.0);
}
......@@ -108,7 +109,7 @@ private:
return sid;
}
/** Probability mass function associated with the reference pixel */
/** Probability mass function associated with the reference pixel */
std::vector<TReference> m_ReferenceProbabilities;
};
......
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