/usr/include/OTB-5.8/otbOBIAMuParserFunctor.h is in libotb-dev 5.8.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | /*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from ITK. See ITKCopyright.txt
for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbOBIAMuParserFunctor_h
#define otbOBIAMuParserFunctor_h
#include "otbParser.h"
#include "otbMacro.h"
namespace otb
{
/** \class OBIAMuParserFunctor
* \brief use MuParser criteria to accept/reject LabelObject given his shape and radiometrics statistics.
* This functor is based on the mathematical parser library muParser.
* The built in functions and operators list is available at:
* http://muparser.sourceforge.net/mup_features.html#idDef2
*
* OTB additional functions:
* ndvi(r, niri)
*
* OTB additional constants:
* e - log2e - log10e - ln2 - ln10 - pi - euler
*
* \sa Parser
*
*
* \ingroup OTBMathParser
*/
/** \class OBIAMuParserFunctor
* \brief This functor use MuParser to evaluate and process mathematical expression
*
* \ingroup OTBMathParser
*/
namespace Functor
{
template<class TLabelObject>
//class ITK_EXPORT OBIAMuParserFunctor : public itk::LightObject
class ITK_EXPORT OBIAMuParserFunctor
{
public:
typedef Parser ParserType;
typedef OBIAMuParserFunctor Self;
std::string GetNameOfClass()
{
return "OBIAMuParserFunctor";
}
inline bool operator()(const TLabelObject &a)
{
double value;
if (a.GetNumberOfAttributes() != m_AAttributes.size())
{
this->SetAttributes(a);
}
for (unsigned int i = 0; i < m_AAttributes.size(); ++i)
{
std::string name = (m_AttributesName[i]);
m_AAttributes[i] = a.GetAttribute(name.c_str());
}
try
{
value = m_Parser->Eval();
}
catch (itk::ExceptionObject& err)
{
itkExceptionMacro(<< err);
}
return static_cast<bool> (value);
}
void SetExpression(const std::string expression)
{
m_Expression = expression;
m_Parser->SetExpr(m_Expression);
}
/** Return the expression to be parsed */
std::string GetExpression() const
{
return m_Expression;
}
void ParseAttributeName(std::string &attributeName)
{
for (unsigned int i = 0; i < attributeName.size(); ++i)
{
if (attributeName[i] == ':')
{
attributeName.erase(i, 1);
attributeName[i] = '_';
}
}
// TODO JGU
// replace "Band" by "b" for homogeneity with other functors
}
void SetAttributes(const TLabelObject &a)
{
unsigned int nbOfAttributes = a.GetNumberOfAttributes();
m_AAttributes.resize(nbOfAttributes, 0.0);
m_AttributesName.resize(nbOfAttributes, "");
m_AttributesName = a.GetAvailableAttributes();
for (unsigned int i = 0; i < nbOfAttributes; ++i)
{
std::string attributeName = m_AttributesName.at(i);
ParseAttributeName(attributeName); //eliminate '::' from string name
m_Parser->DefineVar(attributeName, &(m_AAttributes[i]));
}
}
void SetAttributes(std::vector<std::string> shapeAttributes, std::vector<std::string> statAttributes,
unsigned int nbOfBands)
{
int index = 0;
unsigned int nbOfAttributes = shapeAttributes.size() + statAttributes.size() * nbOfBands;
m_AAttributes.resize(nbOfAttributes, 0.0);
m_AttributesName.resize(nbOfAttributes, "");
std::ostringstream varName;
for (unsigned int i = 0; i < shapeAttributes.size(); ++i)
{
varName << "SHAPE::" << shapeAttributes.at(i);
m_AttributesName.at(index) = varName.str();
varName.str("");
varName << "SHAPE_" << shapeAttributes.at(i);
m_Parser->DefineVar(varName.str(), &(m_AAttributes[index]));
varName.str("");
index++;
}
for (unsigned int i = 0; i < statAttributes.size(); ++i)
{
for (unsigned int bandIndex = 1; bandIndex <= nbOfBands; bandIndex++)
{
varName << "STATS::Band" << bandIndex << "::" << statAttributes.at(i);
m_AttributesName.at(index) = varName.str();
varName.str("");
varName << "STATS_Band" << bandIndex << "_" << statAttributes.at(i);
m_Parser->DefineVar(varName.str(), &(m_AAttributes[index]));
varName.str("");
index++;
}
}
}
/** Check the expression */
bool CheckExpression()
{
return m_Parser->CheckExpr();
}
const std::map<std::string, Parser::ValueType*>& GetVar() const
{
return this->m_Parser->GetVar();
}
Parser::FunctionMapType GetFunList() const
{
return this->m_Parser->GetFunList();
}
OBIAMuParserFunctor()
{
m_Parser = ParserType::New();
m_AAttributes.resize(0);
}
;
~OBIAMuParserFunctor()
{
}
;
protected:
private:
OBIAMuParserFunctor(const Self &); //purposely not implemented
void operator =(const Self &); //purposely not implemented
std::string m_Expression;
ParserType::Pointer m_Parser;
std::vector<double> m_AAttributes;
std::vector<std::string> m_AttributesName;
double m_ParserResult;
};
} // end of Functor namespace
}//end namespace otb
#endif
|