Evaluate Expression

Use this tool if you want to evaluate expressions, i.e., to check results of your application. The expressions can contain numeric and string results of previous tools or values that have been specified manually. You may use a wide range of expressions for the evaluation. See the section Expression for a detailed description of possible expressions.

In contrast to other MERLIC tools, this tool has no default parameters when it is inserted. If you want to use parameters in your expressions, you need to add them manually to the tool. See the section Adding Parameters for more information.

Instead of a graphics window, this tool shows input fields in which the expressions can be defined. The results of the evaluated expressions are returned at the bottom of the tool. The tool has no default parameters when it is inserted.

Entering an Expression

When you type into the expression input field, an auto-completion list with possible functions and operators that match your entry pops up. The list also contains manually added parameters and former defined results. This means that you can use the result of previous expressions in this tool in your following expressions in this tool, e.g., the result of your first expression in your third expression. However, it is not possible to use the result of a latter expression in a previous one, e.g., the result of your third expression in your first expression.

To browse directly from the entire list, open the pop-up manually with the shortcut CTRL+Space. Find out more about the possible functions and operators in the section Types of Operations.

In this image you can see the pop-up list with all possible functions and operators after it was opened manually via CTRL+Space. At the top of the list you can see the result of the first expression, "NumberMissing", and the parameter "Region_Accepted".

Adding, Removing, and Moving Expressions

You can manually add and remove additional expressions. To add an expression, click the " Add expression" button at the bottom of the Tool Workspace. You can remove an expression by clicking the button on the right side of the input field.

Alternatively, right-clicking on the result on the bottom of the Tool Workspace also allows you to remove the result and its respective expression by selecting "Remove".

You can use drag-and-drop to move the expressions you have added to change the order of your expressions, e.g., so you can use the result of a previous expression in a following expression. To do so, select the expression you wish to move, drag it to the desired position, and drop it at the new place.

For each new expression, a new result is created and returned at the bottom of the tool. Optionally rename the result by double-clicking on the result name at the bottom of the tool. To get information about the allowed naming conventions for tool parameters and results see the topic Renaming Tools, Parameters, and Results.

You can hide results, e.g., if there are intermediate results that are not connected to any other tool and that are only used in an expression further down the Tool Flow. Right-click on the result you wish to hide and select "Hide". To show a hidden result, use the button on the right side of the results.

Parameters

This tool has no default parameters. Thus, there are no parameters displayed, when the tool is inserted. If you want to use a parameter value in your expression, you can either use the result value of a previous tool or you can define a new parameter for the tool.

Supported Semantic Types

This tool supports the following semantic types for the parameters:

  • any
  • double
  • long
  • string

Although not all semantic types available in MERLIC are supported for this tool, you can still use any numeric or string result of a previous tool, even if the semantic type of this result is not supported, e.g., "Tool State". However, if a connection to such a result is created, the semantic type of the respective new parameter is converted and set to "any".

Since the semantic type "long" represents integers but with a larger value range, we will still refer to them as integers in the following description.

Adding Parameters

Using a Result of a Previous Tool as Parameter

To use a result of a previous tool in your expression, you need to connect the result to the "Evaluate Expression" tool.

  1. Go to the previous tool whose result you want to use as a parameter in the "Evaluate Expression" tool.
  2. Drag the arrow of the connection from the desired tool result to the drop target for connections. Alternatively, you may open the context menu and click on the menu entry "Connect to".
  3. Select the tool "Evaluate Expression" and click on the menu entry "< add connection >".

The connected result is instantly added as a new parameter for the "Evaluate Expression" tool. The name and semantic type of the parameter is automatically adopted from the connected result. In case the semantic type of the connected result value is not supported in this tool, it is automatically set to "any" for the new parameter.

Alternatively, you may also define a new parameter at the tool as described below and then connect the new parameter to the result of a previous tool.

Defining a New Parameter

To define a new parameter, you have to add a new connector and define the parameter settings.

  1. Click on the button on the top left of the tool board. The dialog window for defining the parameter settings opens.
  2. Select the semantic type for the new parameter in the dialog window.
  3. Optionally define the minimum and maximum value for your new parameter.
  4. Click "Ok" to confirm your settings. The new parameter is instantly added with a default name.
  5. Optionally rename the parameter by double-clicking on the parameter name. To get information about the allowed naming conventions for tool parameters and results see the chapter Renaming Tools, Parameters, and Results.
  6. Define the value of the new parameter at the connector.

Once the semantic type and value range have been saved for a parameter, it is not possible to change these settings again. If you need to adjust the semantic type or the value range of your parameter, you have to add another new parameter with the desired settings.

Example

The following example video shows how to use a result of a previous tool and a newly defined parameter value in the expression.

Expressions

The expressions to be evaluated must be defined within the input field of the tool board. As long as no expression has been defined yet or if an invalid expression has been defined, MERLIC shows an error at the Tool Board and the Tool Flow panel. However, this error is only thrown due to a missing or wrong expression. It does not indicate a critical workspace error. Therefore, the "Tool State" result still returns "[0; OK]" in this case.

The expressions can be applied to numeric values, string values, and also mixed tuples. To use a value of a tool parameter for the evaluation, type the name of the parameter into the input field of the expression. It is also possible to define an expression without any parameter.

Direction of the Evaluation

The evaluation of the expressions is usually done from left to right. However, if parentheses are used in the expressions, they can change the order of evaluation.

Types of Operations

Operations are normally described assuming atomic tuples A tuple is a list of elements, e.g., numeric values and strings., i.e., tuples of length 1. If the tuple contains more than one element, most operators work as follows:

  • If one of the tuples is of length one, all elements of the other tuples are combined with that single value for the chosen operation.
  • If both tuples have a length greater than one, both tuples must have the same length (otherwise an error occurs). In this case, the selected operation is applied to all elements with the same index. The length of the resulting tuples is identical to the length of the input tuples.
  • If one of the tuples is of length 0 ([]), an error occurs.

In the following, we describe the different types of operations that can be used in an expression.

Using Special Characters

This tool uses single quotation marks to represent strings. However, if special characters are used with single quotation marks, the characters are escaped with the backslash, e.g., '\t' is handled as a tab.

Results

Basic Results

Result:

This result returns the resulting values of the expression. As a default, this is the result of the first expression. Each additional expression returns an additional result.The semantic type of the result is set to "any".

Tool State:

"Tool State" returns information about the state of the tool and thus can be used for error handling. For more information, see Tool State Result

Additional Results

Processing Time:

This result returns the duration of the most recent execution of the tool in milliseconds. The result is provided as additional result. Therefore, it is hidden by default but it can be displayed via the button beside the tool results. For more information see the section Processing Time in the tool reference overview.

Application Examples

This tool is used in the following MERLIC Vision App examples:

  • adapt_brightness_for_measuring.mvapp
  • calibrate_for_ruler_changed_distance.mvapp
  • calibrate_for_ruler_distorted.mvapp
  • calibrate_for_ruler_simple.mvapp
  • check_bent_leads.mvapp
  • check_correct_filling_on_3d_height_images.mvapp
  • check_pen_parts.mvapp
  • check_presence_of_fuses.mvapp
  • check_saw_angles.mvapp
  • check_single_switches.mvapp
  • classify_pills.mvapp
  • count_bottles_with_deep_learning.mvapp
  • demonstrate_evaluate_expression.mvapp
  • detect_only_scratches_with_photometric_stereo.mvapp
  • detect_scratches_on_metal.mvapp
  • determine_circle_quality.mvapp
  • evaluate_ecc_200_print_quality.mvapp
  • find_and_count_screw_types.mvapp
  • measure_distance_segment_circle_calibrated.mvapp
  • measure_distance_to_center_led.mvapp
  • recognize_color_of_cables.mvapp
  • segment_pill_defects.mvapp
  • segment_pills_by_shape.mvapp