23 #ifndef otbOBIAMuParserFunctor_h
24 #define otbOBIAMuParserFunctor_h
59 template <
class TLabelObject>
69 return "OBIAMuParserFunctor";
77 if (a.GetNumberOfAttributes() != m_AAttributes.size())
79 this->SetAttributes(a);
82 for (
unsigned int i = 0; i < m_AAttributes.size(); ++i)
85 std::string name = (m_AttributesName[i]);
86 m_AAttributes[i] = a.GetAttribute(name.c_str());
91 value = m_Parser->Eval();
93 catch (itk::ExceptionObject& err)
95 itkExceptionMacro(<< err);
97 return static_cast<bool>(value);
102 m_Expression = expression;
103 m_Parser->SetExpr(m_Expression);
115 for (
unsigned int i = 0; i < attributeName.size(); ++i)
117 if (attributeName[i] ==
':')
119 attributeName.erase(i, 1);
120 attributeName[i] =
'_';
130 unsigned int nbOfAttributes = a.GetNumberOfAttributes();
132 m_AAttributes.resize(nbOfAttributes, 0.0);
133 m_AttributesName.resize(nbOfAttributes,
"");
134 m_AttributesName = a.GetAvailableAttributes();
135 for (
unsigned int i = 0; i < nbOfAttributes; ++i)
137 std::string attributeName = m_AttributesName.at(i);
138 ParseAttributeName(attributeName);
139 m_Parser->DefineVar(attributeName, &(m_AAttributes[i]));
143 void SetAttributes(std::vector<std::string> shapeAttributes, std::vector<std::string> statAttributes,
unsigned int nbOfBands)
146 unsigned int nbOfAttributes = shapeAttributes.size() + statAttributes.size() * nbOfBands;
148 m_AAttributes.resize(nbOfAttributes, 0.0);
149 m_AttributesName.resize(nbOfAttributes,
"");
150 std::ostringstream varName;
151 for (
unsigned int i = 0; i < shapeAttributes.size(); ++i)
154 varName <<
"SHAPE::" << shapeAttributes.at(i);
155 m_AttributesName.at(index) = varName.str();
157 varName <<
"SHAPE_" << shapeAttributes.at(i);
159 m_Parser->DefineVar(varName.str(), &(m_AAttributes[index]));
163 for (
unsigned int i = 0; i < statAttributes.size(); ++i)
165 for (
unsigned int bandIndex = 1; bandIndex <= nbOfBands; bandIndex++)
167 varName <<
"STATS::Band" << bandIndex <<
"::" << statAttributes.at(i);
168 m_AttributesName.at(index) = varName.str();
170 varName <<
"STATS_Band" << bandIndex <<
"_" << statAttributes.at(i);
171 m_Parser->DefineVar(varName.str(), &(m_AAttributes[index]));
181 return m_Parser->CheckExpr();
184 const std::map<std::string, Parser::ValueType*>&
GetVar()
const
186 return this->m_Parser->GetVar();
191 return this->m_Parser->GetFunList();
196 m_Parser = ParserType::New();
197 m_AAttributes.resize(0);
205 void operator=(
const Self&) =
delete;