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