Common/vtkFunctionParser.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00039 #ifndef __vtkFunctionParser_h
00040 #define __vtkFunctionParser_h
00041
00042 #include "vtkObject.h"
00043
00044 #define VTK_PARSER_IMMEDIATE 1
00045 #define VTK_PARSER_UNARY_MINUS 2
00046
00047
00048 #define VTK_PARSER_ADD 3
00049 #define VTK_PARSER_SUBTRACT 4
00050 #define VTK_PARSER_MULTIPLY 5
00051 #define VTK_PARSER_DIVIDE 6
00052 #define VTK_PARSER_POWER 7
00053 #define VTK_PARSER_ABSOLUTE_VALUE 8
00054 #define VTK_PARSER_EXPONENT 9
00055 #define VTK_PARSER_CEILING 10
00056 #define VTK_PARSER_FLOOR 11
00057 #define VTK_PARSER_LOGARITHM 12
00058 #define VTK_PARSER_SQUARE_ROOT 13
00059 #define VTK_PARSER_SINE 14
00060 #define VTK_PARSER_COSINE 15
00061 #define VTK_PARSER_TANGENT 16
00062 #define VTK_PARSER_ARCSINE 17
00063 #define VTK_PARSER_ARCCOSINE 18
00064 #define VTK_PARSER_ARCTANGENT 19
00065 #define VTK_PARSER_HYPERBOLIC_SINE 20
00066 #define VTK_PARSER_HYPERBOLIC_COSINE 21
00067 #define VTK_PARSER_HYPERBOLIC_TANGENT 22
00068
00069
00070 #define VTK_PARSER_VECTOR_UNARY_MINUS 23
00071 #define VTK_PARSER_DOT_PRODUCT 24
00072 #define VTK_PARSER_VECTOR_ADD 25
00073 #define VTK_PARSER_VECTOR_SUBTRACT 26
00074 #define VTK_PARSER_SCALAR_MULTIPLE 27
00075 #define VTK_PARSER_MAGNITUDE 28
00076 #define VTK_PARSER_NORMALIZE 29
00077
00078
00079 #define VTK_PARSER_BEGIN_VARIABLES 30
00080
00081
00082 #define VTK_PARSER_ERROR_RESULT VTK_LARGE_FLOAT
00083
00084 class VTK_COMMON_EXPORT vtkFunctionParser : public vtkObject
00085 {
00086 public:
00087 static vtkFunctionParser *New();
00088 vtkTypeRevisionMacro(vtkFunctionParser, vtkObject);
00089 void PrintSelf(ostream& os, vtkIndent indent);
00090
00092
00093 void SetFunction(const char *function);
00094 vtkGetStringMacro(Function);
00096
00099 int IsScalarResult();
00100
00103 int IsVectorResult();
00104
00106 double GetScalarResult();
00107
00109
00110 double* GetVectorResult();
00111 void GetVectorResult(double result[3]) {
00112 double *r = this->GetVectorResult();
00113 result[0] = r[0]; result[1] = r[1]; result[2] = r[2]; };
00115
00117
00121 void SetScalarVariableValue(const char* variableName, double value);
00122 void SetScalarVariableValue(int i, double value);
00124
00126
00127 double GetScalarVariableValue(const char* variableName);
00128 double GetScalarVariableValue(int i);
00130
00132
00136 void SetVectorVariableValue(const char* variableName, double xValue,
00137 double yValue, double zValue);
00138 void SetVectorVariableValue(const char* variableName,
00139 const double values[3]) {
00140 this->SetVectorVariableValue(variableName,values[0],values[1],values[2]);};
00141 void SetVectorVariableValue(int i, double xValue, double yValue,
00142 double zValue);
00143 void SetVectorVariableValue(int i, const double values[3]) {
00144 this->SetVectorVariableValue(i,values[0],values[1],values[2]);};
00146
00148
00149 double* GetVectorVariableValue(const char* variableName);
00150 void GetVectorVariableValue(const char* variableName, double value[3]) {
00151 double *r = this->GetVectorVariableValue(variableName);
00152 value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00153 double* GetVectorVariableValue(int i);
00154 void GetVectorVariableValue(int i, double value[3]) {
00155 double *r = this->GetVectorVariableValue(i);
00156 value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00158
00160
00161 vtkGetMacro(NumberOfScalarVariables,int);
00163
00165
00166 vtkGetMacro(NumberOfVectorVariables,int);
00168
00170 char* GetScalarVariableName(int i);
00171
00173 char* GetVectorVariableName(int i);
00174
00176 void RemoveAllVariables();
00177
00178 protected:
00179 vtkFunctionParser();
00180 ~vtkFunctionParser();
00181
00182 int Parse();
00183 void Evaluate();
00184
00185 int CheckSyntax();
00186 void RemoveSpaces();
00187
00188 int BuildInternalFunctionStructure();
00189 void BuildInternalSubstringStructure(int beginIndex, int endIndex);
00190 void AddInternalByte(unsigned char newByte);
00191
00192 int IsSubstringCompletelyEnclosed(int beginIndex, int endIndex);
00193 int FindEndOfMathFunction(int beginIndex);
00194
00195 int IsVariableName(int currentIndex);
00196 int IsElementaryOperator(int op);
00197
00198 int GetMathFunctionNumber(int currentIndex);
00199 int GetMathFunctionStringLength(int mathFunctionNumber);
00200 int GetElementaryOperatorNumber(char op);
00201 int GetOperandNumber(int currentIndex);
00202 int GetVariableNameLength(int variableNumber);
00203
00204 int DisambiguateOperators();
00205
00206 char* Function;
00207 int FunctionLength;
00208 int NumberOfScalarVariables;
00209 int NumberOfVectorVariables;
00210 char** ScalarVariableNames;
00211 char** VectorVariableNames;
00212 double* ScalarVariableValues;
00213 double** VectorVariableValues;
00214 unsigned char *ByteCode;
00215 int ByteCodeSize;
00216 double *Immediates;
00217 int ImmediatesSize;
00218 double *Stack;
00219 int StackSize;
00220 int StackPointer;
00221
00222 vtkTimeStamp FunctionMTime;
00223 vtkTimeStamp ParseMTime;
00224 vtkTimeStamp VariableMTime;
00225 vtkTimeStamp EvaluateMTime;
00226 private:
00227 vtkFunctionParser(const vtkFunctionParser&);
00228 void operator=(const vtkFunctionParser&);
00229 };
00230
00231 #endif