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 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00051 #ifndef __vtkFunctionParser_h
00052 #define __vtkFunctionParser_h
00053 
00054 #include "vtkObject.h"
00055 
00056 #define VTK_PARSER_IMMEDIATE 1
00057 #define VTK_PARSER_UNARY_MINUS 2
00058 
00059 // supported math functions
00060 #define VTK_PARSER_ADD 3
00061 #define VTK_PARSER_SUBTRACT 4
00062 #define VTK_PARSER_MULTIPLY 5
00063 #define VTK_PARSER_DIVIDE 6
00064 #define VTK_PARSER_POWER 7
00065 #define VTK_PARSER_ABSOLUTE_VALUE 8
00066 #define VTK_PARSER_EXPONENT 9
00067 #define VTK_PARSER_CEILING 10
00068 #define VTK_PARSER_FLOOR 11
00069 #define VTK_PARSER_LOGARITHM 12
00070 #define VTK_PARSER_SQUARE_ROOT 13
00071 #define VTK_PARSER_SINE 14
00072 #define VTK_PARSER_COSINE 15
00073 #define VTK_PARSER_TANGENT 16
00074 #define VTK_PARSER_ARCSINE 17
00075 #define VTK_PARSER_ARCCOSINE 18
00076 #define VTK_PARSER_ARCTANGENT 19
00077 #define VTK_PARSER_HYPERBOLIC_SINE 20
00078 #define VTK_PARSER_HYPERBOLIC_COSINE 21
00079 #define VTK_PARSER_HYPERBOLIC_TANGENT 22
00080 
00081 // functions involving vectors
00082 #define VTK_PARSER_VECTOR_UNARY_MINUS 23
00083 #define VTK_PARSER_DOT_PRODUCT 24
00084 #define VTK_PARSER_VECTOR_ADD 25
00085 #define VTK_PARSER_VECTOR_SUBTRACT 26
00086 #define VTK_PARSER_SCALAR_MULTIPLE 27
00087 #define VTK_PARSER_MAGNITUDE 28
00088 #define VTK_PARSER_NORMALIZE 29
00089 
00090 // codes for scalar variables come before those for vectors
00091 #define VTK_PARSER_BEGIN_VARIABLES 30
00092 
00093 // the value that is retuned as a result if there is an error
00094 #define VTK_PARSER_ERROR_RESULT VTK_LARGE_FLOAT
00095 
00096 class VTK_COMMON_EXPORT vtkFunctionParser : public vtkObject
00097 {
00098 public:
00099   static vtkFunctionParser *New();
00100   vtkTypeMacro(vtkFunctionParser, vtkObject);
00101   void PrintSelf(ostream& os, vtkIndent indent);
00102   
00104 
00105   void SetFunction(const char *function);
00106   vtkGetStringMacro(Function);
00108 
00111   int IsScalarResult();
00112 
00115   int IsVectorResult();
00116 
00118   double GetScalarResult();
00119 
00121 
00122   double* GetVectorResult();
00123   void GetVectorResult(double result[3]) {
00124     double *r = this->GetVectorResult();
00125     result[0] = r[0]; result[1] = r[1]; result[2] = r[2]; };
00127 
00129 
00133   void SetScalarVariableValue(const char* variableName, double value);
00134   void SetScalarVariableValue(int i, double value);
00136 
00138 
00139   double GetScalarVariableValue(const char* variableName);
00140   double GetScalarVariableValue(int i);
00142 
00144 
00148   void SetVectorVariableValue(const char* variableName, double xValue,
00149                               double yValue, double zValue);
00150   void SetVectorVariableValue(const char* variableName, 
00151                               const double values[3]) {
00152     this->SetVectorVariableValue(variableName,values[0],values[1],values[2]);};
00153   void SetVectorVariableValue(int i, double xValue, double yValue,
00154                               double zValue);
00155   void SetVectorVariableValue(int i, const double values[3]) {
00156     this->SetVectorVariableValue(i,values[0],values[1],values[2]);};
00158   
00160 
00161   double* GetVectorVariableValue(const char* variableName);
00162   void GetVectorVariableValue(const char* variableName, double value[3]) {
00163     double *r = this->GetVectorVariableValue(variableName);
00164     value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00165   double* GetVectorVariableValue(int i);
00166   void GetVectorVariableValue(int i, double value[3]) {
00167     double *r = this->GetVectorVariableValue(i);
00168     value[0] = r[0]; value[1] = r[1]; value[2] = r[2]; };
00170   
00172 
00173   vtkGetMacro(NumberOfScalarVariables,int);
00175 
00177 
00178   vtkGetMacro(NumberOfVectorVariables,int);
00180 
00182   char* GetScalarVariableName(int i);
00183   
00185   char* GetVectorVariableName(int i);
00186 
00187 protected:
00188   vtkFunctionParser();
00189   ~vtkFunctionParser();
00190   
00191   int Parse();
00192   void Evaluate();
00193 
00194   int CheckSyntax();
00195   void RemoveSpaces();
00196   
00197   int BuildInternalFunctionStructure();
00198   void BuildInternalSubstringStructure(int beginIndex, int endIndex);
00199   void AddInternalByte(unsigned char newByte);
00200   
00201   int IsSubstringCompletelyEnclosed(int beginIndex, int endIndex);
00202   int FindEndOfMathFunction(int beginIndex);
00203   
00204   int IsVariableName(int currentIndex);
00205   int IsElementaryOperator(int op);
00206   
00207   int GetMathFunctionNumber(int currentIndex);
00208   int GetMathFunctionStringLength(int mathFunctionNumber);
00209   int GetElementaryOperatorNumber(char op);
00210   int GetOperandNumber(int currentIndex);
00211   int GetVariableNameLength(int variableNumber);
00212   
00213   int DisambiguateOperators();
00214   
00215   char* Function;
00216   int FunctionLength;
00217   int NumberOfScalarVariables;
00218   int NumberOfVectorVariables;
00219   char** ScalarVariableNames;
00220   char** VectorVariableNames;
00221   double* ScalarVariableValues;
00222   double** VectorVariableValues;
00223   unsigned char *ByteCode;
00224   int ByteCodeSize;
00225   double *Immediates;
00226   int ImmediatesSize;
00227   double *Stack;
00228   int StackSize;
00229   int StackPointer;
00230 
00231   vtkTimeStamp FunctionMTime;
00232   vtkTimeStamp ParseMTime;
00233   vtkTimeStamp VariableMTime;
00234   vtkTimeStamp EvaluateMTime;
00235 private:
00236   vtkFunctionParser(const vtkFunctionParser&);  // Not implemented.
00237   void operator=(const vtkFunctionParser&);  // Not implemented.
00238 };
00239 
00240 #endif

Generated on Thu Mar 28 14:19:15 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001