You are here: Start » Programming Reference » Connections
Connections
Read before: Introduction to Data Flow Programming.
Introduction
In general, connections in a program can be created between inputs and outputs of compatible types. This does not mean, however, that the types must be exactly equal. You can connect ports of different types if only it is possible to adapt the transferred data values by means of automatic conversions, array decompositions, loops or conditions. The power of this drag and drop programming model stems from the fact that the user just drags a connection and all the logic is added implicitly on the do what I mean basis.
Connection Logic
This is probably the most complicated part of the Adaptive Vision programming model as it concentrates most of its computing flexibility. You will never define any connection logic explicitly as this is done by the application automatically, but still you will need to think a lot about it.
There are 5 basic types of connection logic:
-
Basic Connection
T T
This kind of connection appears between ports of equal types. -
Automatic Conversion
A B
Automatic conversion is used when the user connects two ports having two different types, e.g. Integer and Real, and there is an appropriate filter in the Conversions category, e.g. IntegerToReal, that can be used to translate the values. -
Array Connection
TArray T
This logic creates an implicit loop on a connection from an array to a scalar type, e.g. from RegionArray to Region. All the individual results are then merged into arrays and so the outputs of the second filter turn into arrays as well (see also: Arrays).
-
Singleton Connection
T TArray
Conversely, when an output of a scalar type is connected to an array input, e.g. Point2D to Point2DArray, a singleton connection assures that the value will be converted into a single element array. This works only for some filters. -
Conditional Connection
T? T
The last connection type, conditional connection, appears when conditional data (T?) is transferred to a non-conditional input (T). This causes the second filter to be executed conditionally depending on whether the value actually exists or not (then it is NIL). The filter outputs are changed into conditional outputs accordingly, assuring that consecutive filters will be executed conditionally as well. Conditional execution ends at a filter with a conditional input. More information on this topic can be found in Conditional Execution section.
Mixed Connection Types
For maximum flexibility many combinations of the above logics can appear. Again, this is always inferred automatically.
-
Conditional Connection with Conversion
A? B
If the object exists, then it is converted and passed to the input port. If not, the filter is not invoked. -
Array Connection with Conversions
AArray B
All elements of the input array are individually converted. -
Conditional Array Connections
TArray? T
All array elements are processed or none – depending on the condition. The output is of a conditional array type. -
Conditional Array Connection with Conversions
AArray? B
All array elements are processed and converted individually or none – depending on the condition. -
Array Connection with Conditional Elements
T?Array T
The second filter is invoked conditionally for each array element and the output types turn into arrays of conditional elements. -
Array Connection with Conditional Elements and Conversions
A?Array B
As above plus conversions. -
Singleton Connection with Conversion
A BArray
A single-element array is created from a converted input value. -
Conditional Singleton Connection
T? TArray
If the object exists, then it is transformed into a single-element array. If not, the second filter is not invoked. -
Conditional Singleton Connection with Conversion
A? BArray
If the object exists, then it is converted and transformed into a single-element array. If not, the second filter is not invoked.
Each individual connection logic is a realization of one control flow pattern from C/C++. For example, Array Connection with Conditional Elements corresponds to this basic code structure:
for (int i = 0; i < arr.Size(); ++i) { if (arr[i] != atl::NIL) { ... } }
Working with Types
As can be seen above, type definitions can have a strong influence on the program logic. For this reason you should pay a lot of attention to define all the arrays and conditionals correctly, especially when changing them in an existing program. This issues arises in the following places:
- on inputs and outputs of macrofilters
- on inputs and outputs of formula blocks
- when instantiating generic filters
In case of a mistake, you may get an incorrect connection in the program (marked with red), but some tricky mistakes may remain not detected automatically.
Previous: Optional Inputs | Next: Conditional Execution |