Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vtkFunctionParser.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkFunctionParser.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
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 // supported math functions
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_LOGARITHME 13
00046 #define VTK_PARSER_LOGARITHM10 14 
00047 #define VTK_PARSER_SQUARE_ROOT 15 
00048 #define VTK_PARSER_SINE 16
00049 #define VTK_PARSER_COSINE 17
00050 #define VTK_PARSER_TANGENT 18
00051 #define VTK_PARSER_ARCSINE 19
00052 #define VTK_PARSER_ARCCOSINE 20
00053 #define VTK_PARSER_ARCTANGENT 21
00054 #define VTK_PARSER_HYPERBOLIC_SINE 22
00055 #define VTK_PARSER_HYPERBOLIC_COSINE 23
00056 #define VTK_PARSER_HYPERBOLIC_TANGENT 24
00057 #define VTK_PARSER_MIN 25
00058 #define VTK_PARSER_MAX 26
00059 #define VTK_PARSER_SIGN 27
00060 
00061 // functions involving vectors
00062 #define VTK_PARSER_VECTOR_UNARY_MINUS 28
00063 #define VTK_PARSER_DOT_PRODUCT 29
00064 #define VTK_PARSER_VECTOR_ADD 30
00065 #define VTK_PARSER_VECTOR_SUBTRACT 31
00066 #define VTK_PARSER_SCALAR_TIMES_VECTOR 32
00067 #define VTK_PARSER_VECTOR_TIMES_SCALAR 33
00068 #define VTK_PARSER_MAGNITUDE 34
00069 #define VTK_PARSER_NORMALIZE 35
00070 
00071 // constants involving vectors
00072 #define VTK_PARSER_IHAT 36
00073 #define VTK_PARSER_JHAT 37
00074 #define VTK_PARSER_KHAT 38
00075 
00076 // codes for scalar variables come before those for vectors
00077 #define VTK_PARSER_BEGIN_VARIABLES 39
00078 
00079 // the value that is retuned as a result if there is an error
00080 #define VTK_PARSER_ERROR_RESULT VTK_LARGE_FLOAT
00081 
00082 class VTK_COMMON_EXPORT vtkFunctionParser : public vtkObject
00083 {
00084 public:
00085   static vtkFunctionParser *New();
00086   vtkTypeRevisionMacro(vtkFunctionParser, vtkObject);
00087   void PrintSelf(ostream& os, vtkIndent indent);
00088   
00090 
00091   void SetFunction(const char *function);
00092   vtkGetStringMacro(Function);
00094 
00097   int IsScalarResult();
00098 
00101   int IsVectorResult();
00102 
00104   double GetScalarResult();
00105 
00107 
00108   double* GetVectorResult();
00109   void GetVectorResult(double result[3]) {
00110     double *r = this->GetVectorResult();
00111     result[0] = r[0]; result[1] = r[1]; result[2] = r[2]; };
00113 
00115 
00119   void SetScalarVariableValue(const char* variableName, double value);
00120   void SetScalarVariableValue(int i, double value);
00122 
00124 
00125   double GetScalarVariableValue(const char* variableName);
00126   double GetScalarVariableValue(int i);
00128 
00130 
00134   void SetVectorVariableValue(const char* variableName, double xValue,
00135                               double yValue, double zValue);
00136   void SetVectorVariableValue(const char* variableName, 
00137                               const double values[3]) {
00138     this->SetVectorVariableValue(variableName,values[0],values[1],values[2]);};
00139   void SetVectorVariableValue(int i, double xValue, double yValue,
00140                               double zValue);
00141   void SetVectorVariableValue(int i, const double values[3]) {
00142     this->SetVectorVariableValue(i,values[0],values[1],values[2]);};
00144   
00146 
00147   double* GetVectorVariableValue(const char* variableName);
00148   void GetVectorVariableValue(const char* variableName, double value[3]) {
00149     double *r = this->GetVectorVariableValue(variableName);
00150     value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00151   double* GetVectorVariableValue(int i);
00152   void GetVectorVariableValue(int i, double value[3]) {
00153     double *r = this->GetVectorVariableValue(i);
00154     value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00156   
00158 
00159   vtkGetMacro(NumberOfScalarVariables,int);
00161 
00163 
00164   vtkGetMacro(NumberOfVectorVariables,int);
00166 
00168   char* GetScalarVariableName(int i);
00169   
00171   char* GetVectorVariableName(int i);
00172 
00174   void RemoveAllVariables();
00175 
00177 
00181   vtkSetMacro(ReplaceInvalidValues,int);
00182   vtkGetMacro(ReplaceInvalidValues,int);
00183   vtkBooleanMacro(ReplaceInvalidValues,int);
00184   vtkSetMacro(ReplacementValue,double);
00185   vtkGetMacro(ReplacementValue,double);
00187   
00188 protected:
00189   vtkFunctionParser();
00190   ~vtkFunctionParser();
00191   
00192   int Parse();
00193   void Evaluate();
00194 
00195   int CheckSyntax();
00196   void RemoveSpaces();
00197   char* RemoveSpacesFrom(const char* variableName);
00198   int OperatorWithinVariable(int idx);
00199   
00200   int BuildInternalFunctionStructure();
00201   void BuildInternalSubstringStructure(int beginIndex, int endIndex);
00202   void AddInternalByte(unsigned char newByte);
00203   
00204   int IsSubstringCompletelyEnclosed(int beginIndex, int endIndex);
00205   int FindEndOfMathFunction(int beginIndex);
00206   int FindEndOfMathConstant(int beginIndex);
00207   
00208   int IsVariableName(int currentIndex);
00209   int IsElementaryOperator(int op);
00210   
00211   int GetMathFunctionNumber(int currentIndex);
00212   int GetMathFunctionStringLength(int mathFunctionNumber);
00213   int GetMathConstantNumber(int currentIndex);
00214   int GetMathConstantStringLength(int mathConstantNumber);
00215   int GetElementaryOperatorNumber(char op);
00216   int GetOperandNumber(int currentIndex);
00217   int GetVariableNameLength(int variableNumber);
00218   
00219   int DisambiguateOperators();
00220   
00221   char* Function;
00222   int FunctionLength;
00223   int NumberOfScalarVariables;
00224   int NumberOfVectorVariables;
00225   char** ScalarVariableNames;
00226   char** VectorVariableNames;
00227   double* ScalarVariableValues;
00228   double** VectorVariableValues;
00229   unsigned char *ByteCode;
00230   int ByteCodeSize;
00231   double *Immediates;
00232   int ImmediatesSize;
00233   double *Stack;
00234   int StackSize;
00235   int StackPointer;
00236 
00237   vtkTimeStamp FunctionMTime;
00238   vtkTimeStamp ParseMTime;
00239   vtkTimeStamp VariableMTime;
00240   vtkTimeStamp EvaluateMTime;
00241 
00242   int ReplaceInvalidValues;
00243   double ReplacementValue;
00244 
00245 private:
00246   vtkFunctionParser(const vtkFunctionParser&);  // Not implemented.
00247   void operator=(const vtkFunctionParser&);  // Not implemented.
00248 };
00249 
00250 #endif

Generated on Mon Jan 21 23:07:17 2008 for VTK by  doxygen 1.4.3-20050530