Python Calculator

From KitwarePublic
Revision as of 15:39, 16 August 2010 by Meng.zhu (talk | contribs) (→‎Comments)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The python calculator is a programmable calculator that provides common mathematical operations and apply them on the point data, cell data or the input datasets directly. It is similar to the python programmable filter and utilizes its functionality to build python scripts for execution. For efficiency, the actual computation is delegated either to corresponding VTK filters or to the numpy library.

Supported Function List

Below is a list of mathematical functions currently supported by this python calculator. Notice that these functions are also available in the python programmable filter.

  • Functions working on data arrays
Name Supported Operand Types # Operands Data Association
abs scalar vector tensor 1 point cell
cross vector 2 point cell
curl vector 1 point cell
det tensor 1 point cell
determinant tensor 1 point cell
dot scalar vector 2 point cell
eigenvalue tensor 1 point cell
eigenvector tensor 1 point cell
global_mean scalar vector tensor 1 point cell
global_max scalar vector tensor 1 point cell
global_min scalar vector tensor 1 point cell
gradient scalar vector 1 point cell
inverse tensor 1 point cell
laplacian scalar 1 point cell
ln scalar vector tensor 1 point cell
log(==ln) scalar vector tensor 1 point cell
log10 scalar vector tensor 1 point cell
max scalar vector tensor 1 point cell
min scalar vector tensor 1 point cell
mean scalar vector tensor 1 point cell
mag scalar vector 1 point cell
norm scalar vector 1 point cell
strain vector 1 point cell
trace tensor 1 point cell
vorticity vector 1 point cell


  • Functions working on dataset
Name Supported Cell Types Data Association
area trig quad cell
aspect trig quad tet cell
aspect_gamma tet cell
diagonal hex cell
jacobian quad tet hex cell
max_angle trig quad cell
min_angle trig quad cell
shear quad cell
skew quad hex cell
surface_normal trig cell
volume tet hex cell
vertex_normal trig point

Comments

The first list gives all the math functions that work with point data or cell data. The general calling signature is function_name(array) for functions taking one operand or function_name(array1, array2) for functions taking two operands. For example, abs(Normals) computes the component-wise absolute value for all normals associated with the dataset. The array association must be given throuth the GUI interface of the python calculator.

The second list gives all the math functions that directly work with a dataset. Most of them work on the cells of a dataset, with only one exception vertex_normal which computes the normal for each point in a dataset. The calling signature of this category is function_name(inputs[0]) where inputs[0] is defined within the calling context by paraview to be your first input dataset.

In the lists, vector means 3D vectors and tensor stands for 3 by 3 matrix. trig is triangle, quad is quadrilateral, tet is tetrahedron and hex is hexahedron.

Examples

Compute area for each cell

   area(inputs[0]) and array association set to Cell Data
   Area.png

Compute vector length for each point

   sqrt(dot(BrownianVectors,BrownianVectors)) or equivalently mag(BrownianVectors)

where BrownianVectors is an array of 3D vectors that are associated with each point in the dataset. Array association set to Point Data.

A more complex example

   max(abs(trace(inverse(gradient(Normals)))))
   Abs.png

Normals is an array of 3D vectors that are associated to each point in the dataset. The expression first computes for each component of the normal vector its gradient, therefore effectively generates a tensor and then it takes the inverse of the generated matrix and then sum everything on the diagonal of the inverse matrix and then computes the absolute value of the sum and then looks for the maximum of all the absolute values.