FunctionParser

VTKExamples/Java/Utilities/FunctionParser

Description

vtkFunctionParser object that takes in a mathematical expression as a char string, parses it, and evaluates it at the specified values of the variables in the input string.

Other Languages

See (Cxx)

Question

If you have a simple question about this example contact us at VTKExamplesProject If your question is more complex and may require extended discussion, please use the VTK Discourse Forum

Code

FunctionParser.java

import vtk.vtkNativeLibrary;
import vtk.vtkFunctionParser;

public class FunctionParser 
{
  // -----------------------------------------------------------------
  // Load VTK library and print which library was not properly loaded
  static 
  {
    if (!vtkNativeLibrary.LoadAllNativeLibraries()) 
    {
      for (vtkNativeLibrary lib : vtkNativeLibrary.values()) 
      {
        if (!lib.IsLoaded()) 
        {
          System.out.println(lib.GetLibraryName() + " not loaded");
        }
      }
    }
    vtkNativeLibrary.DisableOutputWindow(null);
  }
  // -----------------------------------------------------------------

  public static void main(String args[]) 
  {
   vtkFunctionParser functionParser = new vtkFunctionParser();
   functionParser.SetFunction("a+b");
   functionParser.SetScalarVariableValue( "a", 2);
   functionParser.SetScalarVariableValue( "b", 3);

   double result = functionParser.GetScalarResult();

   System.out.println("Result:" +" " +result);
  }
}