23 #ifndef otbConnectedComponentMuParserFunctor_h
24 #define otbConnectedComponentMuParserFunctor_h
30 #include <vnl/algo/vnl_lsqr.h>
31 #include <vnl/vnl_sparse_matrix_linear_system.h>
32 #include <vnl/vnl_least_squares_function.h>
73 template <
class TInput>
83 return "ConnectedComponentMuParserFunctor";
86 inline bool operator()(
const TInput& p1,
const TInput& p2)
91 if (p1.GetSize() != m_NbOfBands)
93 this->SetNumberOfBands(p1.GetSize());
97 for (
unsigned int i = 0; i < m_NbOfBands; ++i)
99 m_AImageP1[i] =
static_cast<double>(p1[i]);
100 m_AImageP2[i] =
static_cast<double>(p2[i]);
107 for (
unsigned int i = 0; i < m_NbOfBands; ++i)
109 m_Distance += (p1[i] - p2[i]) * (p1[i] - p2[i]);
110 m_IntensityP1 += p1[i];
111 m_IntensityP2 += p2[i];
114 m_IntensityP1 = m_IntensityP1 / (
static_cast<double>(m_NbOfBands));
115 m_IntensityP2 = m_IntensityP2 / (
static_cast<double>(m_NbOfBands));
117 m_Distance = std::sqrt(m_Distance);
120 m_SpectralAngle = spectralAngleFunctor(p1, p2);
122 value = m_Parser->Eval();
124 return static_cast<bool>(value);
129 m_Expression = expression;
130 m_Parser->SetExpr(m_Expression);
142 return m_Parser->CheckExpr();
148 m_NbOfBands = NbOfBands;
149 std::ostringstream varName;
151 m_AImageP1.resize(NbOfBands, 0.0);
152 m_AImageP2.resize(NbOfBands, 0.0);
154 for (
unsigned int i = 0; i < NbOfBands; ++i)
156 varName <<
"p1b" << i + 1;
157 m_Parser->DefineVar(varName.str(), &(m_AImageP1[i]));
159 varName <<
"p2b" << i + 1;
160 m_Parser->DefineVar(varName.str(), &(m_AImageP2[i]));
166 m_Parser->DefineVar(
"distance", &m_Distance);
167 m_Parser->DefineVar(
"spectralAngle", &m_SpectralAngle);
168 m_Parser->DefineVar(
"intensity_p1", &m_IntensityP1);
169 m_Parser->DefineVar(
"intensity_p2", &m_IntensityP2);
173 const std::map<std::string, Parser::ValueType*>&
GetVar()
const
175 return this->m_Parser->GetVar();
180 return this->m_Parser->GetFunList();
193 void operator=(
const Self&) =
delete;