vtkFunctionParser.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00038 #ifndef __vtkFunctionParser_h
00039 #define __vtkFunctionParser_h
00040
00041 #include "vtkObject.h"
00042
00043 #define VTK_PARSER_IMMEDIATE 1
00044 #define VTK_PARSER_UNARY_MINUS 2
00045
00046
00047 #define VTK_PARSER_ADD 3
00048 #define VTK_PARSER_SUBTRACT 4
00049 #define VTK_PARSER_MULTIPLY 5
00050 #define VTK_PARSER_DIVIDE 6
00051 #define VTK_PARSER_POWER 7
00052 #define VTK_PARSER_ABSOLUTE_VALUE 8
00053 #define VTK_PARSER_EXPONENT 9
00054 #define VTK_PARSER_CEILING 10
00055 #define VTK_PARSER_FLOOR 11
00056 #define VTK_PARSER_LOGARITHM 12
00057 #define VTK_PARSER_SQUARE_ROOT 13
00058 #define VTK_PARSER_SINE 14
00059 #define VTK_PARSER_COSINE 15
00060 #define VTK_PARSER_TANGENT 16
00061 #define VTK_PARSER_ARCSINE 17
00062 #define VTK_PARSER_ARCCOSINE 18
00063 #define VTK_PARSER_ARCTANGENT 19
00064 #define VTK_PARSER_HYPERBOLIC_SINE 20
00065 #define VTK_PARSER_HYPERBOLIC_COSINE 21
00066 #define VTK_PARSER_HYPERBOLIC_TANGENT 22
00067 #define VTK_PARSER_MIN 23
00068 #define VTK_PARSER_MAX 24
00069 #define VTK_PARSER_SIGN 25
00070
00071
00072 #define VTK_PARSER_VECTOR_UNARY_MINUS 26
00073 #define VTK_PARSER_DOT_PRODUCT 27
00074 #define VTK_PARSER_VECTOR_ADD 28
00075 #define VTK_PARSER_VECTOR_SUBTRACT 29
00076 #define VTK_PARSER_SCALAR_TIMES_VECTOR 30
00077 #define VTK_PARSER_VECTOR_TIMES_SCALAR 31
00078 #define VTK_PARSER_MAGNITUDE 32
00079 #define VTK_PARSER_NORMALIZE 33
00080
00081
00082 #define VTK_PARSER_IHAT 34
00083 #define VTK_PARSER_JHAT 35
00084 #define VTK_PARSER_KHAT 36
00085
00086
00087 #define VTK_PARSER_BEGIN_VARIABLES 37
00088
00089
00090 #define VTK_PARSER_ERROR_RESULT VTK_LARGE_FLOAT
00091
00092 class VTK_COMMON_EXPORT vtkFunctionParser : public vtkObject
00093 {
00094 public:
00095 static vtkFunctionParser *New();
00096 vtkTypeRevisionMacro(vtkFunctionParser, vtkObject);
00097 void PrintSelf(ostream& os, vtkIndent indent);
00098
00100
00101 void SetFunction(const char *function);
00102 vtkGetStringMacro(Function);
00104
00107 int IsScalarResult();
00108
00111 int IsVectorResult();
00112
00114 double GetScalarResult();
00115
00117
00118 double* GetVectorResult();
00119 void GetVectorResult(double result[3]) {
00120 double *r = this->GetVectorResult();
00121 result[0] = r[0]; result[1] = r[1]; result[2] = r[2]; };
00123
00125
00129 void SetScalarVariableValue(const char* variableName, double value);
00130 void SetScalarVariableValue(int i, double value);
00132
00134
00135 double GetScalarVariableValue(const char* variableName);
00136 double GetScalarVariableValue(int i);
00138
00140
00144 void SetVectorVariableValue(const char* variableName, double xValue,
00145 double yValue, double zValue);
00146 void SetVectorVariableValue(const char* variableName,
00147 const double values[3]) {
00148 this->SetVectorVariableValue(variableName,values[0],values[1],values[2]);};
00149 void SetVectorVariableValue(int i, double xValue, double yValue,
00150 double zValue);
00151 void SetVectorVariableValue(int i, const double values[3]) {
00152 this->SetVectorVariableValue(i,values[0],values[1],values[2]);};
00154
00156
00157 double* GetVectorVariableValue(const char* variableName);
00158 void GetVectorVariableValue(const char* variableName, double value[3]) {
00159 double *r = this->GetVectorVariableValue(variableName);
00160 value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00161 double* GetVectorVariableValue(int i);
00162 void GetVectorVariableValue(int i, double value[3]) {
00163 double *r = this->GetVectorVariableValue(i);
00164 value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00166
00168
00169 vtkGetMacro(NumberOfScalarVariables,int);
00171
00173
00174 vtkGetMacro(NumberOfVectorVariables,int);
00176
00178 char* GetScalarVariableName(int i);
00179
00181 char* GetVectorVariableName(int i);
00182
00184 void RemoveAllVariables();
00185
00186 protected:
00187 vtkFunctionParser();
00188 ~vtkFunctionParser();
00189
00190 int Parse();
00191 void Evaluate();
00192
00193 int CheckSyntax();
00194 void RemoveSpaces();
00195 char* RemoveSpacesFrom(const char* variableName);
00196 int OperatorWithinVariable(int idx);
00197
00198 int BuildInternalFunctionStructure();
00199 void BuildInternalSubstringStructure(int beginIndex, int endIndex);
00200 void AddInternalByte(unsigned char newByte);
00201
00202 int IsSubstringCompletelyEnclosed(int beginIndex, int endIndex);
00203 int FindEndOfMathFunction(int beginIndex);
00204 int FindEndOfMathConstant(int beginIndex);
00205
00206 int IsVariableName(int currentIndex);
00207 int IsElementaryOperator(int op);
00208
00209 int GetMathFunctionNumber(int currentIndex);
00210 int GetMathFunctionStringLength(int mathFunctionNumber);
00211 int GetMathConstantNumber(int currentIndex);
00212 int GetMathConstantStringLength(int mathConstantNumber);
00213 int GetElementaryOperatorNumber(char op);
00214 int GetOperandNumber(int currentIndex);
00215 int GetVariableNameLength(int variableNumber);
00216
00217 int DisambiguateOperators();
00218
00219 char* Function;
00220 int FunctionLength;
00221 int NumberOfScalarVariables;
00222 int NumberOfVectorVariables;
00223 char** ScalarVariableNames;
00224 char** VectorVariableNames;
00225 double* ScalarVariableValues;
00226 double** VectorVariableValues;
00227 unsigned char *ByteCode;
00228 int ByteCodeSize;
00229 double *Immediates;
00230 int ImmediatesSize;
00231 double *Stack;
00232 int StackSize;
00233 int StackPointer;
00234
00235 vtkTimeStamp FunctionMTime;
00236 vtkTimeStamp ParseMTime;
00237 vtkTimeStamp VariableMTime;
00238 vtkTimeStamp EvaluateMTime;
00239 private:
00240 vtkFunctionParser(const vtkFunctionParser&);
00241 void operator=(const vtkFunctionParser&);
00242 };
00243
00244 #endif