You are here: Start » Programming Reference » Generic Filters
Generic Filters
Read before: Introduction to Data Flow Programming.
Introduction
Most of the filters available in Aurora Vision Studio have clearly defined types of inputs and outputs – they are applicable only to data of that specific types. There is however a range of operations that could be applied to data of many different types – for instance the ArraySize filter could work with arrays of any type of the items, and the TestObjectEqualTo filter could compare any two objects having the same type. For this purpose there are generic filters that can be instantiated for many different types.
Generic filters are very similar to C++ function templates.
Type Definitions
Each generic filter is defined using a type variable T that represents any valid type. For instance, the GetArrayElement filter has the following ports:
Port | Type | Description | |
---|---|---|---|
inArray | TArray | Input array | |
inIndex | Integer | Index within the array | |
outValue | T | Element from the array |
Instantiation
When a generic filter is added to the program, the user has to choose which type should be used as the T type for this filter instance. This process is called instantiation. There are two variants of the dialog window that is used for choosing the type. They differ only in the message that appears:
For example, if the GetArrayElement filter is added to the program and the user chooses the T variable to represent the Real type, then the interface of the filter takes the following form:
Port | Type | Description | |
---|---|---|---|
inArray | RealArray | Input array | |
inIndex | Integer | Index within the array | |
outValue | Real | Element from the array |
After instantiation the filter appears in the Program Editor with the instantiation type specified by the name of the filter:
A common mistake is to provide the type of the entire object, when only a type of array element is needed. For example, when instantiating the GetArrayElement filter intended for accessing arrays of reals, enter the Real type, which is the type of an element, but NOT the RealArray type, which is the type of the entire object.
Previous: Types of Filters | Next: Macrofilters |