You are here: Start » Programming Reference » Generic Filters

Generic Filters

Read before: Introduction to Data Flow Programming.

Introduction

Most of the filters available in Adaptive 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:

This window appears for filters related to arrays, e.g. GetArrayElement or JoinArrays. The user has to choose the type of the array elements.

This window appears for filters not related to arrays, e.g. MergeDefault. The user has to choose the type of the entire object.

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:

An example of two generic filters in the Program Editor: MergeDefault instantiated for replacing Nils in arrays of real numbers and GetArrayElement instantiated for getting an single element from them. Please note that the type parameter specified is different.

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