Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# Common/vtkFunctionParser.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program:   Visualization Toolkit
    00004   Module:    $RCSfile: vtkFunctionParser.h,v $
    00005   Language:  C++
    00006
    00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
    00008   All rights reserved.
    00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
    00010
    00011      This software is distributed WITHOUT ANY WARRANTY; without even
    00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00013      PURPOSE.  See the above copyright notice for more information.
    00014
    00015 =========================================================================*/
    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 // supported math functions
    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
    00068 // functions involving vectors
    00069 #define VTK_PARSER_VECTOR_UNARY_MINUS 23
    00070 #define VTK_PARSER_DOT_PRODUCT 24
    00071 #define VTK_PARSER_VECTOR_ADD 25
    00072 #define VTK_PARSER_VECTOR_SUBTRACT 26
    00073 #define VTK_PARSER_SCALAR_MULTIPLE 27
    00074 #define VTK_PARSER_MAGNITUDE 28
    00075 #define VTK_PARSER_NORMALIZE 29
    00076
    00077 // codes for scalar variables come before those for vectors
    00078 #define VTK_PARSER_BEGIN_VARIABLES 30
    00079
    00080 // the value that is retuned as a result if there is an error
    00081 #define VTK_PARSER_ERROR_RESULT VTK_LARGE_FLOAT
    00082
    00083 class VTK_COMMON_EXPORT vtkFunctionParser : public vtkObject
    00084 {
    00085 public:
    00086   static vtkFunctionParser *New();
    00087   vtkTypeRevisionMacro(vtkFunctionParser, vtkObject);
    00088   void PrintSelf(ostream& os, vtkIndent indent);
    00089
    00091
    00092   void SetFunction(const char *function);
    00093   vtkGetStringMacro(Function);
    00095
    00098   int IsScalarResult();
    00099
    00102   int IsVectorResult();
    00103
    00105   double GetScalarResult();
    00106
    00108
    00109   double* GetVectorResult();
    00110   void GetVectorResult(double result[3]) {
    00111     double *r = this->GetVectorResult();
    00112     result[0] = r[0]; result[1] = r[1]; result[2] = r[2]; };
    00114
    00116
    00120   void SetScalarVariableValue(const char* variableName, double value);
    00121   void SetScalarVariableValue(int i, double value);
    00123
    00125
    00126   double GetScalarVariableValue(const char* variableName);
    00127   double GetScalarVariableValue(int i);
    00129
    00131
    00135   void SetVectorVariableValue(const char* variableName, double xValue,
    00136                               double yValue, double zValue);
    00137   void SetVectorVariableValue(const char* variableName,
    00138                               const double values[3]) {
    00139     this->SetVectorVariableValue(variableName,values[0],values[1],values[2]);};
    00140   void SetVectorVariableValue(int i, double xValue, double yValue,
    00141                               double zValue);
    00142   void SetVectorVariableValue(int i, const double values[3]) {
    00143     this->SetVectorVariableValue(i,values[0],values[1],values[2]);};
    00145
    00147
    00148   double* GetVectorVariableValue(const char* variableName);
    00149   void GetVectorVariableValue(const char* variableName, double value[3]) {
    00150     double *r = this->GetVectorVariableValue(variableName);
    00151     value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
    00152   double* GetVectorVariableValue(int i);
    00153   void GetVectorVariableValue(int i, double value[3]) {
    00154     double *r = this->GetVectorVariableValue(i);
    00155     value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
    00157
    00159
    00160   vtkGetMacro(NumberOfScalarVariables,int);
    00162
    00164
    00165   vtkGetMacro(NumberOfVectorVariables,int);
    00167
    00169   char* GetScalarVariableName(int i);
    00170
    00172   char* GetVectorVariableName(int i);
    00173
    00175   void RemoveAllVariables();
    00176
    00177 protected:
    00178   vtkFunctionParser();
    00179   ~vtkFunctionParser();
    00180
    00181   int Parse();
    00182   void Evaluate();
    00183
    00184   int CheckSyntax();
    00185   void RemoveSpaces();
    00186
    00187   int BuildInternalFunctionStructure();
    00188   void BuildInternalSubstringStructure(int beginIndex, int endIndex);
    00189   void AddInternalByte(unsigned char newByte);
    00190
    00191   int IsSubstringCompletelyEnclosed(int beginIndex, int endIndex);
    00192   int FindEndOfMathFunction(int beginIndex);
    00193
    00194   int IsVariableName(int currentIndex);
    00195   int IsElementaryOperator(int op);
    00196
    00197   int GetMathFunctionNumber(int currentIndex);
    00198   int GetMathFunctionStringLength(int mathFunctionNumber);
    00199   int GetElementaryOperatorNumber(char op);
    00200   int GetOperandNumber(int currentIndex);
    00201   int GetVariableNameLength(int variableNumber);
    00202
    00203   int DisambiguateOperators();
    00204
    00205   char* Function;
    00206   int FunctionLength;
    00207   int NumberOfScalarVariables;
    00208   int NumberOfVectorVariables;
    00209   char** ScalarVariableNames;
    00210   char** VectorVariableNames;
    00211   double* ScalarVariableValues;
    00212   double** VectorVariableValues;
    00213   unsigned char *ByteCode;
    00214   int ByteCodeSize;
    00215   double *Immediates;
    00216   int ImmediatesSize;
    00217   double *Stack;
    00218   int StackSize;
    00219   int StackPointer;
    00220
    00221   vtkTimeStamp FunctionMTime;
    00222   vtkTimeStamp ParseMTime;
    00223   vtkTimeStamp VariableMTime;
    00224   vtkTimeStamp EvaluateMTime;
    00225 private:
    00226   vtkFunctionParser(const vtkFunctionParser&);  // Not implemented.
    00227   void operator=(const vtkFunctionParser&);  // Not implemented.
    00228 };
    00229
    00230 #endif