Module: Arithmetic ()
The Arithmetic module performs calculations on up to three input data objects according to a user-defined arithmetic expression. The result is stored in a new data object called Result. The calculations are triggered by the Apply button. The arithmetic expression is evaluated either on the grid of the first data object (in case of regular, tetrahedral, or hexahedral grids or surfaces) or on a regular 3D uniform grid for which the number of points can be set by the Resolution port. If the data connected to the Arithmetic module is updated, whereas the ports values have not changed, the grid is not recomputed, only a new probing is done.The module is able to process input fields with up to 6 different channels. Scalar input fields are referenced by the variables A, B, and C. The values of multi-component input fields are referenced for example by Ax, Ay, Az (if input A is a vector field) or Br, Bg, Bb, Ba (if input B is an RGBA color field).
In any case the expressions are evaluated per point, i.e., the result for a point (X,Y,Z) depends on input values at the same point only. If the resulting object is based on a regular grid, grid indices I, J, or K may also appear in the arithmetic expression. This means that for each grid point its associated I, J, or K index value will be substituted in the arithmetic expression on evaluation. This is useful in connection with comparison operators which produce a result of either zero or one. Computations may be confined to a specific sub-grid this way.
An expression consists of variables and mathematical and logical operators. The syntax is basically the same as for C expressions. The following variables are defined:
- A: The values of a scalar field at input A.
- B: The values of a scalar field at input B.
- C: The values of a scalar field at input C.
- Ar: The real part of a complex scalar field at input A.
- Ai: The imaginary part of a complex scalar field at input A.
- Ax: The x-component of a vector field at input A.
- Ay: The y-component of a vector field at input A.
- Az: The z-component of a vector field at input A.
- Ar: The red component of a color field at input A.
- Ag: The green component of a color field at input A.
- Ab: The blue component of a color field at input A.
- Aa: The alpha component of a color field at input A.
- Arx: Real part of the x-component of a complex vector field.
- Aix: Imaginary part of the x-component of a complex vector field.
- Ary: Real part of the y-component of a complex vector field.
- Aiy: Imaginary part of the y-component of a complex vector field.
- Arz: Real part of the z-component of a complex vector field.
- Aiz: Imaginary part of the z-component of a complex vector field.
- Aii: Index ii of a symmetric second order tensor.
- Aij: Index ij of a symmetric second order tensor.
- Aik: Index ik of a symmetric second order tensor.
- Ajj: Index jj of a symmetric second order tensor.
- Ajk: Index jk of a symmetric second order tensor.
- Akk: Index kk of a symmetric second order tensor.
- The same variables as above for fields at input B or C, but with A replaced by B or C.
- I: First index of a point (i,j,k) in a regular grid, or index of a point in an unstructured grid.
- J: Second index of a point (i,j,k) in a regular grid, undefined for unstructured grids.
- K: Third index of a point (i,j,k) in a regular grid, undefined for unstructured grids.
- X: The x-coordinate of the current point.
- Y: The y-coordinate of the current point.
- Z: The z-coordinate of the current point.
- R: The radius .
This is a list of available mathematical and logical operators:
- + - / * The basic mathematical operators.
- ! Unary negation.
- - Unary minus.
- % The modulo operator.
- > < <= >= != == The comparison operators greater, less, less or equal, greater or equal, not equal, and equal. If the comparison is true the result is 1, otherwise it is 0.
- && || ^ The logical operators and, or, and xor. A non-zero operand is interpreted as true, while a zero operand is false. The result is either 1 (true) or 0 (false).
- & | The bitwise operations and and or. For bitwise and, the bits in the result are set to 1 if the corresponding bits in the two operands are both 1. For bitwise or, the bits in the result are set to 1 if at least one of the corresponding bits in the two operands is 1.
There are also some built-in functions:
- pow(x,a) Power function. Note that there is no power operator (the ^ operator exists but means logical xor).
- sin(x) cos(x) tan(x) Trigonometric functions.
- asin(x) acos(x) atan(x) atan2(x,y) Inverse trigonometric functions.
- sinh(x) cosh(x) tanh(x) Hyperbolic trigonometric functions.
- asinh(x) acosh(x) atanh(x) Hyperbolic inverse trigonometric functions.
- sqrt(x) Square root.
- floor(x) ceil(x) Next largest or smallest integer number.
- ln(x) log10(x) exp(x) Logarithm and exponent.
- rand() Pseudo-random variable uniformly distributed between 0 and 1.
- gauss() Pseudo-random variable with Gaussian distribution (mean value 0, standard deviation 1).
- erf(x) erfc(x) Error function.
- abs(x) fabs(x) Absolute value.
- min(x,y) max(x,y) Minimum or maximum values.
For better understanding some examples of how to use the Arithmetic module follow:
Expression: A
The result is a copy of input object A. If A is defined on a tetrahedral or hexahedral grid and the result type is set to regular together with an appropriate resolution, the expression leads to a conversion from an unstructured grid to a structured regular grid. The same trick can also be used to resample a regular field with stacked coordinates onto a uniform grid.Expression: A-B
The result is the difference between input objects A and B. This expression is sometimes useful in order to compare to different data sets.Expression: 255*(A>127)
Simple thresholding: For every value of A the result is set to 255 if the value is greater than 127. Otherwise the result is 0.Expression: A*(B>0)
Simple masking operation: If B is zero, the result is also set to zero. Otherwise, the result is set to A. For example, if A is a 3D image and B is a corresponding label image, the exterior parts of the object (where B is zero) are masked out by this expression.
Input A [required]
The input is an Unstructured Model Field containing an arbitrary data set.Input B [optional]
Second input, can be any 3D data field.Input C [optional]
Thrid input, can be any 3D data field.
Min Box
Port to set the minimum x-, y-, z-coordinates of a bounding box around the output data object. If one or more input data objects are connected, the bounding box of the first input data object is also taken as the output bounding box.Max Box
Port to set maximum x-, y-, z-coordinates of the bounding box around the output data object.
Output Data Type
Output Data Type
This port determines the number of channels of the result. By default, the result has the same number of channels as input A. Alternatively, you can specify that the result should have 2 channels (complex scalar field), 3 channels (vector field), 4 channels (RGBA color field), 6 channels (either a complex vector or a symmetric tensor field of second order) or 9 channels (a generic tensor field).Expression
This port specifies the mathematical expression used to compute the result. If the result has more than one channel, more expression ports will be shown.
Output Grid Type
Output Grid Type
With this radio box the grid type of the result can be set either to the same as input A , to a regular grid with uniform coordinates, or a regular grid with rectilinear coordinates. Resampling onto a regular or a rectilinear grid is useful in order to use display modules that take only regular inputs, such as the Volume Rendering volume rendering module. Resampling onto a rectilinear offers more refinement than the uniform grid.Resolution
If port Result Type is set to regular , the resolution of the regular field to be generated is set to the values given here. If port Result Type is set to rectilinear, the resolution is also set to the values given here. However, if the height resolution is equal to 0, it means that the unstructured model is uniform in Z axis and that the process of generating a rectilinear grid on this is not wanted.Max Size
If port Result Type is set to rectilinear, the max size of rectilinear cells is set to the factor given here multiplied by one half of the cell size. Note that with a factor of one for the max size, the rectilinear cell will be at least one half of the initial cell. With a factor of 2, the rectilinear cell will be at least one quarter of the initial cell.Ideal Resolution
If port Result Type is set to rectilinear, the ideal resolution can be chosen for displaying the result. That means that the resolution given in Resolution port will not be used for simplifying the result grid and the Resolution values will be updated with the ideal resolution. Otherwise, the ideal grid will be simplified with an histogram equalization process. By default, the rectilinear grid is simplified with the resolution given.