VTK
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
vtkFunctionParser Class Reference

Parse and evaluate a mathematical expression. More...

#include <vtkFunctionParser.h>

Inheritance diagram for vtkFunctionParser:
Inheritance graph
[legend]
Collaboration diagram for vtkFunctionParser:
Collaboration graph
[legend]

List of all members.

Public Types

typedef vtkObject Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkFunctionParserNewInstance () const
void PrintSelf (ostream &os, vtkIndent indent)
int IsScalarResult ()
int IsVectorResult ()
double GetScalarResult ()
char * GetScalarVariableName (int i)
char * GetVectorVariableName (int i)
void RemoveAllVariables ()
void RemoveScalarVariables ()
void RemoveVectorVariables ()
void CheckExpression (int &pos, char **error)
void InvalidateFunction ()
void SetFunction (const char *function)
virtual char * GetFunction ()
doubleGetVectorResult ()
void GetVectorResult (double result[3])
void SetScalarVariableValue (const char *variableName, double value)
void SetScalarVariableValue (int i, double value)
double GetScalarVariableValue (const char *variableName)
double GetScalarVariableValue (int i)
void SetVectorVariableValue (const char *variableName, double xValue, double yValue, double zValue)
void SetVectorVariableValue (const char *variableName, const double values[3])
void SetVectorVariableValue (int i, double xValue, double yValue, double zValue)
void SetVectorVariableValue (int i, const double values[3])
doubleGetVectorVariableValue (const char *variableName)
void GetVectorVariableValue (const char *variableName, double value[3])
doubleGetVectorVariableValue (int i)
void GetVectorVariableValue (int i, double value[3])
virtual int GetNumberOfScalarVariables ()
virtual int GetNumberOfVectorVariables ()
virtual void SetReplaceInvalidValues (int)
virtual int GetReplaceInvalidValues ()
virtual void ReplaceInvalidValuesOn ()
virtual void ReplaceInvalidValuesOff ()
virtual void SetReplacementValue (double)
virtual double GetReplacementValue ()

Static Public Member Functions

static vtkFunctionParserNew ()
static int IsTypeOf (const char *type)
static vtkFunctionParserSafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBaseNewInstanceInternal () const
 vtkFunctionParser ()
 ~vtkFunctionParser ()
int Parse ()
bool Evaluate ()
int CheckSyntax ()
void CopyParseError (int &position, char **error)
void RemoveSpaces ()
char * RemoveSpacesFrom (const char *variableName)
int OperatorWithinVariable (int idx)
int BuildInternalFunctionStructure ()
void BuildInternalSubstringStructure (int beginIndex, int endIndex)
void AddInternalByte (unsigned char newByte)
int IsSubstringCompletelyEnclosed (int beginIndex, int endIndex)
int FindEndOfMathFunction (int beginIndex)
int FindEndOfMathConstant (int beginIndex)
int IsVariableName (int currentIndex)
int IsElementaryOperator (int op)
int GetMathFunctionNumber (int currentIndex)
int GetMathFunctionNumberByCheckingParenthesis (int currentIndex)
int GetMathFunctionStringLength (int mathFunctionNumber)
int GetMathConstantNumber (int currentIndex)
int GetMathConstantStringLength (int mathConstantNumber)
unsigned char GetElementaryOperatorNumber (char op)
unsigned char GetOperandNumber (int currentIndex)
int GetVariableNameLength (int variableNumber)
int DisambiguateOperators ()
virtual void SetParseError (const char *)
int FindPositionInOriginalFunction (const int &pos)

Protected Attributes

char * Function
char * FunctionWithSpaces
int FunctionLength
int NumberOfScalarVariables
int NumberOfVectorVariables
char ** ScalarVariableNames
char ** VectorVariableNames
doubleScalarVariableValues
double ** VectorVariableValues
unsigned char * ByteCode
int ByteCodeSize
doubleImmediates
int ImmediatesSize
doubleStack
int StackSize
int StackPointer
vtkTimeStamp FunctionMTime
vtkTimeStamp ParseMTime
vtkTimeStamp VariableMTime
vtkTimeStamp EvaluateMTime
vtkTimeStamp CheckMTime
int ReplaceInvalidValues
double ReplacementValue
int ParseErrorPositon
char * ParseError

Detailed Description

Parse and evaluate a mathematical expression.

vtkFunctionParser is a class that takes in a mathematical expression as a char string, parses it, and evaluates it at the specified values of the variables in the input string.

You can use the "if" operator to create conditional expressions such as if ( test, trueresult, falseresult). These evaluate the boolean valued test expression and then evaluate either the trueresult or the falseresult expression to produce a final (scalar or vector valued) value. "test" may contain <,>,=,|,&, and () and all three subexpressions can evaluate arbitrary function operators (ln, cos, +, if, etc)

Thanks:
Juha Nieminen (juha..nosp@m.niem.nosp@m.inen@.nosp@m.gmai.nosp@m.l.com) for relicensing this branch of the function parser code that this class is based upon under the new BSD license so that it could be used in VTK. Note, the BSD license applies to this version of the function parser only (by permission of the author), and not the original library.
Thanks:
Thomas Dunne (thoma.nosp@m.s.du.nosp@m.nne@i.nosp@m.wr.u.nosp@m.ni-he.nosp@m.idel.nosp@m.berg..nosp@m.de) for adding code for two-parameter-parsing and a few functions (sign, min, max).
Thanks:
Sid Sydoriak (sxs@l.nosp@m.anl..nosp@m.gov) for adding boolean operations and conditional expressions and for fixing a variety of bugs.

Definition at line 127 of file vtkFunctionParser.h.


Member Typedef Documentation

Reimplemented from vtkObject.

Definition at line 131 of file vtkFunctionParser.h.


Constructor & Destructor Documentation


Member Function Documentation

Create an object with Debug turned off, modified time initialized to zero, and reference counting on.

Reimplemented from vtkObject.

static int vtkFunctionParser::IsTypeOf ( const char *  name) [static]

Return 1 if this class type is the same type of (or a subclass of) the named class. Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.

Reimplemented from vtkObject.

virtual int vtkFunctionParser::IsA ( const char *  name) [virtual]

Return 1 if this class is the same type of (or a subclass of) the named class. Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.

Reimplemented from vtkObject.

Reimplemented from vtkObject.

virtual vtkObjectBase* vtkFunctionParser::NewInstanceInternal ( ) const [protected, virtual]

Reimplemented from vtkObject.

Reimplemented from vtkObject.

void vtkFunctionParser::PrintSelf ( ostream &  os,
vtkIndent  indent 
) [virtual]

Methods invoked by print to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from vtkObject.

void vtkFunctionParser::SetFunction ( const char *  function)

Set/Get input string to evaluate.

virtual char* vtkFunctionParser::GetFunction ( ) [virtual]

Set/Get input string to evaluate.

Check whether the result is a scalar result. If it isn't, then either the result is a vector or an error has occurred.

Check whether the result is a vector result. If it isn't, then either the result is scalar or an error has occurred.

Get a scalar result from evaluating the input function.

Get a vector result from evaluating the input function.

void vtkFunctionParser::GetVectorResult ( double  result[3]) [inline]

Get a vector result from evaluating the input function.

Definition at line 154 of file vtkFunctionParser.h.

void vtkFunctionParser::SetScalarVariableValue ( const char *  variableName,
double  value 
)

Set the value of a scalar variable. If a variable with this name exists, then its value will be set to the new value. If there is not already a variable with this name, variableName will be added to the list of variables, and its value will be set to the new value.

Set the value of a scalar variable. If a variable with this name exists, then its value will be set to the new value. If there is not already a variable with this name, variableName will be added to the list of variables, and its value will be set to the new value.

double vtkFunctionParser::GetScalarVariableValue ( const char *  variableName)

Get the value of a scalar variable.

Get the value of a scalar variable.

void vtkFunctionParser::SetVectorVariableValue ( const char *  variableName,
double  xValue,
double  yValue,
double  zValue 
)

Set the value of a vector variable. If a variable with this name exists, then its value will be set to the new value. If there is not already a variable with this name, variableName will be added to the list of variables, and its value will be set to the new value.

void vtkFunctionParser::SetVectorVariableValue ( const char *  variableName,
const double  values[3] 
) [inline]

Set the value of a vector variable. If a variable with this name exists, then its value will be set to the new value. If there is not already a variable with this name, variableName will be added to the list of variables, and its value will be set to the new value.

Definition at line 181 of file vtkFunctionParser.h.

void vtkFunctionParser::SetVectorVariableValue ( int  i,
double  xValue,
double  yValue,
double  zValue 
)

Set the value of a vector variable. If a variable with this name exists, then its value will be set to the new value. If there is not already a variable with this name, variableName will be added to the list of variables, and its value will be set to the new value.

void vtkFunctionParser::SetVectorVariableValue ( int  i,
const double  values[3] 
) [inline]

Set the value of a vector variable. If a variable with this name exists, then its value will be set to the new value. If there is not already a variable with this name, variableName will be added to the list of variables, and its value will be set to the new value.

Definition at line 186 of file vtkFunctionParser.h.

double* vtkFunctionParser::GetVectorVariableValue ( const char *  variableName)

Get the value of a vector variable.

void vtkFunctionParser::GetVectorVariableValue ( const char *  variableName,
double  value[3] 
) [inline]

Get the value of a vector variable.

Definition at line 193 of file vtkFunctionParser.h.

Get the value of a vector variable.

void vtkFunctionParser::GetVectorVariableValue ( int  i,
double  value[3] 
) [inline]

Get the value of a vector variable.

Definition at line 197 of file vtkFunctionParser.h.

Get the number of scalar variables.

Get the number of vector variables.

Get the ith scalar variable name.

Get the ith vector variable name.

Remove all the current variables.

Remove all the scalar variables.

Remove all the vector variables.

virtual void vtkFunctionParser::SetReplaceInvalidValues ( int  ) [virtual]

When ReplaceInvalidValues is on, all invalid values (such as sqrt(-2), note that function parser does not handle complex numbers) will be replaced by ReplacementValue. Otherwise an error will be reported

When ReplaceInvalidValues is on, all invalid values (such as sqrt(-2), note that function parser does not handle complex numbers) will be replaced by ReplacementValue. Otherwise an error will be reported

virtual void vtkFunctionParser::ReplaceInvalidValuesOn ( ) [virtual]

When ReplaceInvalidValues is on, all invalid values (such as sqrt(-2), note that function parser does not handle complex numbers) will be replaced by ReplacementValue. Otherwise an error will be reported

virtual void vtkFunctionParser::ReplaceInvalidValuesOff ( ) [virtual]

When ReplaceInvalidValues is on, all invalid values (such as sqrt(-2), note that function parser does not handle complex numbers) will be replaced by ReplacementValue. Otherwise an error will be reported

virtual void vtkFunctionParser::SetReplacementValue ( double  ) [virtual]

When ReplaceInvalidValues is on, all invalid values (such as sqrt(-2), note that function parser does not handle complex numbers) will be replaced by ReplacementValue. Otherwise an error will be reported

When ReplaceInvalidValues is on, all invalid values (such as sqrt(-2), note that function parser does not handle complex numbers) will be replaced by ReplacementValue. Otherwise an error will be reported

void vtkFunctionParser::CheckExpression ( int pos,
char **  error 
)

Check the validity of the function expression.

Allow the user to force the function to be re-parsed

int vtkFunctionParser::Parse ( ) [protected]
bool vtkFunctionParser::Evaluate ( ) [protected]

Evaluate the function, returning true on success, false on failure.

void vtkFunctionParser::CopyParseError ( int position,
char **  error 
) [protected]
void vtkFunctionParser::RemoveSpaces ( ) [protected]
char* vtkFunctionParser::RemoveSpacesFrom ( const char *  variableName) [protected]
void vtkFunctionParser::BuildInternalSubstringStructure ( int  beginIndex,
int  endIndex 
) [protected]
void vtkFunctionParser::AddInternalByte ( unsigned char  newByte) [protected]
int vtkFunctionParser::IsSubstringCompletelyEnclosed ( int  beginIndex,
int  endIndex 
) [protected]
int vtkFunctionParser::FindEndOfMathFunction ( int  beginIndex) [protected]
int vtkFunctionParser::FindEndOfMathConstant ( int  beginIndex) [protected]
int vtkFunctionParser::IsVariableName ( int  currentIndex) [protected]
int vtkFunctionParser::GetMathFunctionNumber ( int  currentIndex) [protected]
int vtkFunctionParser::GetMathFunctionStringLength ( int  mathFunctionNumber) [protected]
int vtkFunctionParser::GetMathConstantNumber ( int  currentIndex) [protected]
int vtkFunctionParser::GetMathConstantStringLength ( int  mathConstantNumber) [protected]
unsigned char vtkFunctionParser::GetElementaryOperatorNumber ( char  op) [protected]
unsigned char vtkFunctionParser::GetOperandNumber ( int  currentIndex) [protected]
int vtkFunctionParser::GetVariableNameLength ( int  variableNumber) [protected]
virtual void vtkFunctionParser::SetParseError ( const char *  ) [protected, virtual]

Member Data Documentation

char* vtkFunctionParser::Function [protected]

Definition at line 288 of file vtkFunctionParser.h.

Definition at line 289 of file vtkFunctionParser.h.

Definition at line 291 of file vtkFunctionParser.h.

Definition at line 292 of file vtkFunctionParser.h.

Definition at line 293 of file vtkFunctionParser.h.

Definition at line 294 of file vtkFunctionParser.h.

Definition at line 295 of file vtkFunctionParser.h.

Definition at line 296 of file vtkFunctionParser.h.

Definition at line 297 of file vtkFunctionParser.h.

unsigned char* vtkFunctionParser::ByteCode [protected]

Definition at line 298 of file vtkFunctionParser.h.

Definition at line 299 of file vtkFunctionParser.h.

Definition at line 300 of file vtkFunctionParser.h.

Definition at line 301 of file vtkFunctionParser.h.

Definition at line 302 of file vtkFunctionParser.h.

Definition at line 303 of file vtkFunctionParser.h.

Definition at line 304 of file vtkFunctionParser.h.

Definition at line 306 of file vtkFunctionParser.h.

Definition at line 307 of file vtkFunctionParser.h.

Definition at line 308 of file vtkFunctionParser.h.

Definition at line 309 of file vtkFunctionParser.h.

Definition at line 310 of file vtkFunctionParser.h.

Definition at line 312 of file vtkFunctionParser.h.

Definition at line 313 of file vtkFunctionParser.h.

Definition at line 315 of file vtkFunctionParser.h.

char* vtkFunctionParser::ParseError [protected]

Definition at line 316 of file vtkFunctionParser.h.


The documentation for this class was generated from the following file: