00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00026
#ifndef __vtkFunctionParser_h
00027
#define __vtkFunctionParser_h
00028
00029
#include "vtkObject.h"
00030
00031 #define VTK_PARSER_IMMEDIATE 1
00032 #define VTK_PARSER_UNARY_MINUS 2
00033
00034
00035 #define VTK_PARSER_ADD 3
00036 #define VTK_PARSER_SUBTRACT 4
00037 #define VTK_PARSER_MULTIPLY 5
00038 #define VTK_PARSER_DIVIDE 6
00039 #define VTK_PARSER_POWER 7
00040 #define VTK_PARSER_ABSOLUTE_VALUE 8
00041 #define VTK_PARSER_EXPONENT 9
00042 #define VTK_PARSER_CEILING 10
00043 #define VTK_PARSER_FLOOR 11
00044 #define VTK_PARSER_LOGARITHM 12
00045 #define VTK_PARSER_SQUARE_ROOT 13
00046 #define VTK_PARSER_SINE 14
00047 #define VTK_PARSER_COSINE 15
00048 #define VTK_PARSER_TANGENT 16
00049 #define VTK_PARSER_ARCSINE 17
00050 #define VTK_PARSER_ARCCOSINE 18
00051 #define VTK_PARSER_ARCTANGENT 19
00052 #define VTK_PARSER_HYPERBOLIC_SINE 20
00053 #define VTK_PARSER_HYPERBOLIC_COSINE 21
00054 #define VTK_PARSER_HYPERBOLIC_TANGENT 22
00055 #define VTK_PARSER_MIN 23
00056 #define VTK_PARSER_MAX 24
00057 #define VTK_PARSER_SIGN 25
00058
00059
00060 #define VTK_PARSER_VECTOR_UNARY_MINUS 26
00061 #define VTK_PARSER_DOT_PRODUCT 27
00062 #define VTK_PARSER_VECTOR_ADD 28
00063 #define VTK_PARSER_VECTOR_SUBTRACT 29
00064 #define VTK_PARSER_SCALAR_TIMES_VECTOR 30
00065 #define VTK_PARSER_VECTOR_TIMES_SCALAR 31
00066 #define VTK_PARSER_MAGNITUDE 32
00067 #define VTK_PARSER_NORMALIZE 33
00068
00069
00070 #define VTK_PARSER_IHAT 34
00071 #define VTK_PARSER_JHAT 35
00072 #define VTK_PARSER_KHAT 36
00073
00074
00075 #define VTK_PARSER_BEGIN_VARIABLES 37
00076
00077
00078 #define VTK_PARSER_ERROR_RESULT VTK_LARGE_FLOAT
00079
00080 class VTK_COMMON_EXPORT vtkFunctionParser :
public vtkObject
00081 {
00082
public:
00083
static vtkFunctionParser *
New();
00084 vtkTypeRevisionMacro(vtkFunctionParser,
vtkObject);
00085
void PrintSelf(ostream& os,
vtkIndent indent);
00086
00088
00089
void SetFunction(
const char *function);
00090 vtkGetStringMacro(Function);
00092
00095
int IsScalarResult();
00096
00099
int IsVectorResult();
00100
00102
double GetScalarResult();
00103
00105
00106
double* GetVectorResult();
00107 void GetVectorResult(
double result[3]) {
00108
double *r = this->GetVectorResult();
00109 result[0] = r[0]; result[1] = r[1]; result[2] = r[2]; };
00111
00113
00117
void SetScalarVariableValue(
const char* variableName,
double value);
00118
void SetScalarVariableValue(
int i,
double value);
00120
00122
00123
double GetScalarVariableValue(
const char* variableName);
00124
double GetScalarVariableValue(
int i);
00126
00128
00132
void SetVectorVariableValue(
const char* variableName,
double xValue,
00133
double yValue,
double zValue);
00134 void SetVectorVariableValue(
const char* variableName,
00135
const double values[3]) {
00136 this->SetVectorVariableValue(variableName,values[0],values[1],values[2]);};
00137
void SetVectorVariableValue(
int i,
double xValue,
double yValue,
00138
double zValue);
00139 void SetVectorVariableValue(
int i,
const double values[3]) {
00140 this->SetVectorVariableValue(i,values[0],values[1],values[2]);};
00142
00144
00145
double* GetVectorVariableValue(
const char* variableName);
00146 void GetVectorVariableValue(
const char* variableName,
double value[3]) {
00147
double *r = this->GetVectorVariableValue(variableName);
00148 value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00149
double* GetVectorVariableValue(
int i);
00150 void GetVectorVariableValue(
int i,
double value[3]) {
00151
double *r = this->GetVectorVariableValue(i);
00152 value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00154
00156
00157 vtkGetMacro(NumberOfScalarVariables,
int);
00159
00161
00162 vtkGetMacro(NumberOfVectorVariables,
int);
00164
00166
char* GetScalarVariableName(
int i);
00167
00169
char* GetVectorVariableName(
int i);
00170
00172
void RemoveAllVariables();
00173
00174
protected:
00175 vtkFunctionParser();
00176 ~vtkFunctionParser();
00177
00178
int Parse();
00179
void Evaluate();
00180
00181
int CheckSyntax();
00182
void RemoveSpaces();
00183
char* RemoveSpacesFrom(
const char* variableName);
00184
00185
int BuildInternalFunctionStructure();
00186
void BuildInternalSubstringStructure(
int beginIndex,
int endIndex);
00187
void AddInternalByte(
unsigned char newByte);
00188
00189
int IsSubstringCompletelyEnclosed(
int beginIndex,
int endIndex);
00190
int FindEndOfMathFunction(
int beginIndex);
00191
int FindEndOfMathConstant(
int beginIndex);
00192
00193
int IsVariableName(
int currentIndex);
00194
int IsElementaryOperator(
int op);
00195
00196
int GetMathFunctionNumber(
int currentIndex);
00197
int GetMathFunctionStringLength(
int mathFunctionNumber);
00198
int GetMathConstantNumber(
int currentIndex);
00199
int GetMathConstantStringLength(
int mathConstantNumber);
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