33#define _USE_MATH_DEFINES
61 virtual void evaluate(std::stack<double>&) = 0;
113 const double right =
rpnStack.top();
219 while (!
input.empty())
221 delete input.front();
235 output.push_back(tolower(c));
335 const std::string op(
it.first);
378 val = std::stod(expression.substr(
pos), &index);
380 catch (std::invalid_argument)
384 catch (std::out_of_range)
397 const size_t found = expression.find_first_not_of(
"abcdefghijklmnopqrstuvwxyz0123456789_",
pos);
399 if (
found != std::string::npos)
404 if (expression[
found] ==
'(')
426 const std::string
s =
"Unknown variable: " +
subString;
553 std::stack<double> stack;
556 while (!
input.empty())
570 if (stack.size() == 1)
572 result = stack.top();
582 std::queue<ShuntingYard::RPNTokens::TokenBase*>
rpn;
617 error = std::string(exception.what());
628 std::size_t
pos =
s.find_first_of(
"0123456789");
629 if (
pos == std::string::npos)
646#define image_variable( name, type, default_value ) \
647 if (HuginBase::PTOVariableConverterFor##name::checkApplicability(var.varname))\
660 const std::size_t
pos =
s.find_first_of(
"=", 0);
661 if (
pos != std::string::npos &&
pos > 0 &&
pos <
s.length() - 1)
667 errorStream <<
"The expression \"" <<
s <<
"\" does not contain a result." << std::endl;
679 if (
tempString.find_first_of(
"0123456789") == std::string::npos)
687 errorStream <<
"The expression \"" <<
tempString <<
"\" is not a valid image variable or constant." << std::endl;
694 errorStream <<
"The expression \"" <<
s <<
"\" is incomplete." << std::endl;
731 errorStream <<
"Could not parse given expression \"" <<
parseVar.expression <<
"\" for variable " <<
parseVar.varname <<
" on image " << imgNr <<
"." << std::endl;
734 errorStream <<
"(Error: " << error <<
")" << std::endl;
759 errorStream <<
"Could not parse given expression \"" <<
parseVar.expression <<
"\" for constant " <<
parseVar.varname <<
"." << std::endl;
762 errorStream <<
"(Error: " << error <<
")" << std::endl;
781 if (!
l0.empty() &&
l0[0] !=
'#')
794 const std::string imgNr = std::to_string(
i);
796#define image_variable( name, type, default_value ) \
797 HuginBase::PTOVariableConverterFor##name::addToVariableMap(img.get##name##IV(), vars);
800 for (
auto& var : vars)
802 constants[var.first + imgNr] = var.second.getValue();
838#define image_variable( name, type, default_value ) \
839 if (HuginBase::PTOVariableConverterFor##name::checkApplicability(var.varname))\
841 if(img1.name##isLinked())\
843 for(size_t k=j+1; k<pano.getNrOfImages(); k++)\
845 if(img1.name##isLinkedWith(pano.getImage(k)))\
847 updatedImgs.insert(k);\
870 errorStream <<
"Expression is empty." << std::endl;
Convenience functions for SrcPanoImage to use on the image variables.
function to parse expressions from strings
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
virtual void updateVariable(unsigned int imgNr, const Variable &var)
update a single variable
std::size_t getNrOfImages() const
number of images.
All variables of a source image.
double getVar(const std::string &name) const
a variable has a value and a name.
binary operator on stack on shunting yards operator stack
RPNTokens::TokenBase * GetTokenBase()
std::function< double(double, double)> m_function
BinaryOperator(std::function< double(double, double)> func, int prec, bool rightAssoc=false)
function or unary operator on shunting yards operator stack
std::function< double(double)> m_function
FunctionOperator(std::function< double(double)> func, int prec=-2, bool rightAssoc=false)
RPNTokens::TokenBase * GetTokenBase()
if operator on operator stack, used only for ':' token
RPNTokens::TokenBase * GetTokenBase()
base class for operator on shunting yards operator stack
virtual RPNTokens::TokenBase * GetTokenBase()
OperatorBase(int prec, bool rightAssoc=false)
const bool IsRightAssociative() const
bool ComparePrecedence(const OperatorBase *other)
const int GetPrecedence() const
internal exception class for all errors
ParseException(const char *message)
binary operator on rpn stack
void evaluate(std::stack< double > &rpnStack)
BinaryToken(std::function< double(double, double)> func)
std::function< double(double, double)> m_function
unary operator or function on rpn queue
void evaluate(std::stack< double > &rpnStack)
std::function< double(double)> m_function
FunctionToken(std::function< double(double)> func)
void evaluate(std::stack< double > &rpnStack)
single numeric token on rpn queue
void evaluate(std::stack< double > &rpnStack)
virtual void evaluate(std::stack< double > &)=0
This file specifies what image variables SrcPanoImg should have.
std::set< unsigned int > UIntSet
std::map< std::string, Variable > VariableMap
std::string RemoveWhiteSpaces(const std::string &text)
remove all whitespaces and convert to lowercase
static Operators::OperatorBase * ifOperator
static Operators::OperatorBase * parenthesesOperator
void CleanUpParser()
clean up some internal static variables
void InitParser()
initialize some internal variables
bool EvaluateRPN(std::queue< RPNTokens::TokenBase * > &input, double &result)
evaluate RPN in input
bool ConvertToRPN(const std::string &expression, const ConstantMap &constants, std::queue< RPNTokens::TokenBase * > &rpn)
convert expression to RPN *
std::string FindOperator(const std::string &searchString)
compare the first characters in string with supportedBinaryOperations, return longest match
static std::map< std::string, Operators::FunctionOperator * > supportedFunctions
static Operators::OperatorBase * ifOperatorClose
static std::map< std::string, Operators::OperatorBase * > supportedBinaryOperations
void ClearQueue(std::queue< RPNTokens::TokenBase * > &input)
clear the queue
bool UpdateSingleVar(HuginBase::Panorama &pano, const Parser::ParseVar &parseVar, const Parser::ConstantMap &constants, size_t imgNr, std::ostream &statusStream, std::ostream &errorStream)
bool CalculateConstant(HuginBase::Panorama &pano, const Parser::ParseVar &parseVar, Parser::ConstantMap &constants, std::ostream &statusStream, std::ostream &errorStream)
std::vector< ParseVar > ParseVarVec
void PanoParseExpression(HuginBase::Panorama &pano, const std::string &expression, std::ostream &statusStream, std::ostream &errorStream)
parses the given expression and apply the changes to the Panorama
bool ParseExpression(const std::string &expression, double &result, const ConstantMap &constants, std::string &error)
parse complete expression in 2 steps
void ParseSingleVar(ParseVarVec &varVec, const std::string &s, std::ostream &errorStream)
void ParseVariableString(ParseVarVec &parseVec, const std::string &input, std::ostream &errorStream, void(*func)(ParseVarVec &, const std::string &, std::ostream &))
parse complete variables string
bool ParseVarNumber(const std::string &s, Parser::ParseVar &var)
parse string s and store result in ParseVar var
std::map< std::string, double > ConstantMap
std::vector< std::string > SplitString(const std::string &s, const std::string &sep)
split string s at given sep, returns vector of strings
std::string StrTrim(const std::string &str)
remove trailing and leading white spaces and tabs
std::string tolower(const std::string &s)
convert a string to lowercase
bool stringToInt(const std::string &s, int &val)
convert string to integer value, returns true, if sucessful
bool set_contains(const _Container &c, const typename _Container::key_type &key)
struct to save parsed variables and optional image numbers
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.