46#ifndef vtkFunctionParser_h
47#define vtkFunctionParser_h
49#include "vtkCommonMiscModule.h"
55#define VTK_PARSER_IMMEDIATE 1
56#define VTK_PARSER_UNARY_MINUS 2
57#define VTK_PARSER_UNARY_PLUS 3
60#define VTK_PARSER_ADD 4
61#define VTK_PARSER_SUBTRACT 5
62#define VTK_PARSER_MULTIPLY 6
63#define VTK_PARSER_DIVIDE 7
64#define VTK_PARSER_POWER 8
65#define VTK_PARSER_ABSOLUTE_VALUE 9
66#define VTK_PARSER_EXPONENT 10
67#define VTK_PARSER_CEILING 11
68#define VTK_PARSER_FLOOR 12
69#define VTK_PARSER_LOGARITHM 13
70#define VTK_PARSER_LOGARITHME 14
71#define VTK_PARSER_LOGARITHM10 15
72#define VTK_PARSER_SQUARE_ROOT 16
73#define VTK_PARSER_SINE 17
74#define VTK_PARSER_COSINE 18
75#define VTK_PARSER_TANGENT 19
76#define VTK_PARSER_ARCSINE 20
77#define VTK_PARSER_ARCCOSINE 21
78#define VTK_PARSER_ARCTANGENT 22
79#define VTK_PARSER_HYPERBOLIC_SINE 23
80#define VTK_PARSER_HYPERBOLIC_COSINE 24
81#define VTK_PARSER_HYPERBOLIC_TANGENT 25
82#define VTK_PARSER_MIN 26
83#define VTK_PARSER_MAX 27
84#define VTK_PARSER_SIGN 29
87#define VTK_PARSER_CROSS 28
88#define VTK_PARSER_VECTOR_UNARY_MINUS 30
89#define VTK_PARSER_VECTOR_UNARY_PLUS 31
90#define VTK_PARSER_DOT_PRODUCT 32
91#define VTK_PARSER_VECTOR_ADD 33
92#define VTK_PARSER_VECTOR_SUBTRACT 34
93#define VTK_PARSER_SCALAR_TIMES_VECTOR 35
94#define VTK_PARSER_VECTOR_TIMES_SCALAR 36
95#define VTK_PARSER_VECTOR_OVER_SCALAR 37
96#define VTK_PARSER_MAGNITUDE 38
97#define VTK_PARSER_NORMALIZE 39
100#define VTK_PARSER_IHAT 40
101#define VTK_PARSER_JHAT 41
102#define VTK_PARSER_KHAT 42
105#define VTK_PARSER_IF 43
108#define VTK_PARSER_VECTOR_IF 44
111#define VTK_PARSER_LESS_THAN 45
114#define VTK_PARSER_GREATER_THAN 46
117#define VTK_PARSER_EQUAL_TO 47
120#define VTK_PARSER_AND 48
123#define VTK_PARSER_OR 49
128#define VTK_PARSER_BEGIN_VARIABLES 50
131#define VTK_PARSER_ERROR_RESULT VTK_FLOAT_MAX
150 vtkGetStringMacro(Function);
175 void GetVectorResult(
double result[3])
177 double* r = this->GetVectorResult();
194 this->SetScalarVariableValue(variableName.c_str(),
value);
206 return this->GetScalarVariableValue(variableName.c_str());
219 const char* variableName,
double xValue,
double yValue,
double zValue);
221 const std::string& variableName,
double xValue,
double yValue,
double zValue)
223 this->SetVectorVariableValue(variableName.c_str(), xValue, yValue, zValue);
227 this->SetVectorVariableValue(variableName, values[0], values[1], values[2]);
231 this->SetVectorVariableValue(variableName.c_str(), values[0], values[1], values[2]);
236 this->SetVectorVariableValue(i, values[0], values[1], values[2]);
247 return this->GetVectorVariableValue(variableName.c_str());
251 double* r = this->GetVectorVariableValue(variableName);
258 this->GetVectorVariableValue(variableName.c_str(),
value);
263 double* r = this->GetVectorVariableValue(i);
281 return this->GetScalarVariableIndex(
name.c_str());
295 return this->GetVectorVariableIndex(
name.c_str());
318 return GetScalarVariableNeeded(variableName.c_str());
332 return this->GetVectorVariableNeeded(variableName.c_str());
361 vtkSetMacro(ReplacementValue,
double);
362 vtkGetMacro(ReplacementValue,
double);
422 vtkSetStringMacro(ParseError);
Parse and evaluate a mathematical expression.
void SetScalarVariableValue(int i, double value)
Set the value of a scalar variable.
int BuildInternalFunctionStructure()
double GetScalarVariableValue(const std::string &variableName)
Get the value of a scalar variable.
int DisambiguateOperators()
std::vector< std::string > VectorVariableNames
~vtkFunctionParser() override
bool GetScalarVariableNeeded(const std::string &variableName)
Returns whether a scalar variable is needed for the function evaluation.
void SetVectorVariableValue(int i, const double values[3])
Set the value of a vector variable.
vtkTimeStamp EvaluateMTime
void SetFunction(const char *function)
Set/Get input string to evaluate.
double * GetVectorVariableValue(int i)
Get the value of a vector variable.
vtkTimeStamp FunctionMTime
int IsScalarResult()
Check whether the result is a scalar result.
double * GetVectorResult()
Get a vector result from evaluating the input function.
static vtkFunctionParser * New()
double * GetVectorVariableValue(const std::string &variableName)
Get the value of a vector variable.
int GetScalarVariableIndex(const char *name)
Get scalar variable index or -1 if not found.
int GetNumberOfVectorVariables()
Get the number of vector variables.
void RemoveVectorVariables()
Remove all the vector variables.
void GetVectorVariableValue(const char *variableName, double value[3])
Get the value of a vector variable.
double GetScalarResult()
Get a scalar result from evaluating the input function.
int GetMathFunctionStringLength(int mathFunctionNumber)
char * RemoveSpacesFrom(const char *variableName)
int GetNumberOfScalarVariables()
Get the number of scalar variables.
int GetMathConstantNumber(int currentIndex)
int GetVectorVariableIndex(const char *name)
Get scalar variable index or -1 if not found.
void SetVectorVariableValue(const char *variableName, const double values[3])
Set the value of a vector variable.
int GetMathFunctionNumber(int currentIndex)
int IsElementaryOperator(int op)
int FindPositionInOriginalFunction(const int &pos)
const char * GetVectorVariableName(int i)
Get the ith vector variable name.
unsigned int GetOperandNumber(int currentIndex)
void AddInternalByte(unsigned int newByte)
void SetVectorVariableValue(const std::string &variableName, const double values[3])
Set the value of a vector variable.
vtkMTimeType GetMTime() override
Return parser's MTime.
void UpdateNeededVariables()
Collects meta-data about which variables are needed by the current function.
bool GetVectorVariableNeeded(const std::string &variableName)
Returns whether a vector variable is needed for the function evaluation.
void GetVectorVariableValue(int i, double value[3])
Get the value of a vector variable.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetVectorVariableValue(int i, double xValue, double yValue, double zValue)
Set the value of a vector variable.
std::vector< bool > ScalarVariableNeeded
bool Evaluate()
Evaluate the function, returning true on success, false on failure.
const char * GetScalarVariableName(int i)
Get the ith scalar variable name.
std::vector< unsigned int > ByteCode
int GetMathFunctionNumberByCheckingParenthesis(int currentIndex)
double GetScalarVariableValue(const char *variableName)
Get the value of a scalar variable.
int IsVariableName(int currentIndex)
void CheckExpression(int &pos, char **error)
Check the validity of the function expression.
int FindEndOfMathConstant(int beginIndex)
double GetScalarVariableValue(int i)
Get the value of a scalar variable.
void SetVectorVariableValue(const std::string &variableName, double xValue, double yValue, double zValue)
Set the value of a vector variable.
std::vector< double > ScalarVariableValues
bool GetScalarVariableNeeded(const char *variableName)
Returns whether a scalar variable is needed for the function evaluation.
bool GetScalarVariableNeeded(int i)
Returns whether a scalar variable is needed for the function evaluation.
unsigned char GetElementaryOperatorNumber(char op)
int GetVectorVariableIndex(const std::string &name)
int GetVariableNameLength(int variableNumber)
double * GetVectorVariableValue(const char *variableName)
Get the value of a vector variable.
std::vector< vtkTuple< double, 3 > > VectorVariableValues
void GetVectorVariableValue(const std::string &variableName, double value[3])
Get the value of a vector variable.
vtkTypeBool ReplaceInvalidValues
int IsVectorResult()
Check whether the result is a vector result.
void RemoveScalarVariables()
Remove all the scalar variables.
int IsSubstringCompletelyEnclosed(int beginIndex, int endIndex)
bool GetVectorVariableNeeded(int i)
Returns whether a vector variable is needed for the function evaluation.
void BuildInternalSubstringStructure(int beginIndex, int endIndex)
vtkTimeStamp VariableMTime
void RemoveAllVariables()
Remove all the current variables.
void CopyParseError(int &position, char **error)
void InvalidateFunction()
Allow the user to force the function to be re-parsed.
void SetScalarVariableValue(const std::string &variableName, double value)
Set the value of a scalar variable.
int OperatorWithinVariable(int idx)
bool GetVectorVariableNeeded(const char *variableName)
Returns whether a vector variable is needed for the function evaluation.
char * FunctionWithSpaces
int GetMathConstantStringLength(int mathConstantNumber)
std::vector< bool > VectorVariableNeeded
std::vector< std::string > ScalarVariableNames
int GetScalarVariableIndex(const std::string &name)
void SetVectorVariableValue(const char *variableName, double xValue, double yValue, double zValue)
Set the value of a vector variable.
void SetScalarVariableValue(const char *variableName, double value)
Set the value of a scalar variable.
int FindEndOfMathFunction(int beginIndex)
a simple class to control print indentation
abstract base class for most VTK objects
record modification and/or execution time
vtkTypeUInt32 vtkMTimeType
#define VTK_SIZEHINT(...)