A basic tuple operation may be selecting one or more values, combining tuples (concatenation) or getting the number of elements (see table 8.6 for operations on tuples containing control data).
| Operation | Meaning | HALCON operator |
| t := [t1,t2] | concatenate tuples | tuple_concat |
| i := |t| | get number of elements of tuple t | tuple_length |
| v := t1[t2] | select elements t2 of tuple t1 | tuple_select |
| t := t[i1:i2] | select from element i1 to element i2 of tuple t | tuple_select_range |
| t := subset(t1,t2) | select elements specified in t2 from t1 | tuple_select |
| t := firstn(t,i) | select first elements from t up to index i | tuple_first_n |
| t := lastn(t,i) | select elements from t from index i to the end | tuple_last_n |
| t := select_mask(t1,t2) | select all elements from t1 where the corresponding mask value in t2 is greater than 0 | tuple_select_mask |
| t := remove(t,i) | remove elements specified in i from t | tuple_remove |
| i := find(t1,t2) | get indices of all occurrences of t2 within t1 (or -1 if no match) | tuple_find |
| i := replace(t1,t2,t3) | replace elements | tuple_replace |
| i := find_first(t1,t2) | get indices of the first occurrences of t2 within t1 (or -1 if no match) | tuple_find_first |
| i := find_last(t1,t2) | get indices of the last occurrences of t2 within t1 (or -1 if no match) | tuple_find_last |
| t := uniq(t) | discard all but one of successive identical elements from t | tuple_uniq |
| t := [i1:i2:i3] | generate a sequence of values from i1 to i3 with an increment value of i2 | tuple_gen_sequence |
| t := [i1:i2] | generate a sequence of values from i1 to i2 with an increment value of one | tuple_gen_sequence |
| t := gen_tuple_const(i,t) | generate a tuple with i values set to t | tuple_gen_const |
Table 8.6: Basic operations on tuples (control data) and the corresponding HALCON operators.
The concatenation accepts one or more variables or constants as input. They are all listed between the brackets, separated by commas. The result again is a tuple. Please note the following: [[t]] = [t] = t.
|t| returns the number of elements of a tuple. The indices of elements range from zero to the number of elements minus one (i.e., |t|-1). Therefore, the selection index has to be within this range. 2)
Tuple := [V1,V2,V3,V4]
for i := 0 to |Tuple|-1 by 1
fwrite_string (FileHandle,Tuple[i]+'\n')
endfor
In the following examples the variable Var contains [2,4,8,16,16,32]:
| [1,Var,[64,128]] | [1,2,4,8,16,16,32,64,128] |
| |Var| | 6 |
| Var[4] | 16 |
| Var[2:4] | [8,16,16] |
| subset(Var,[0,2,4]) | [2,8,16] |
| select_mask(Var,[1,0,0,1,1,1]) | [2,16,16,32] |
| remove(Var,[2,3]) | [2,4,16,32] |
| find(Var,[8,16]) | 2 |
| uniq(Var) | [2,4,8,16,32] |
Further examples can be found in the program tuple.hdev. The HALCON operators that correspond to the basic tuple operations are listed in table 8.6.
Note that these direct operations cannot be used for iconic tuples, i.e., iconic objects cannot be selected from a tuple using [] and their number cannot be directly determined using ||. For this purpose, however, HALCON operators are offered that carry out the equivalent tasks. In table 8.7 you can see tuple operations that work on control data (and which are applied via assign or assign_at) and their counterparts that work on iconic data (and which are independent operators). In the table the symbol t represents a control tuple, and the symbols p and q represent iconic tuples.
| control | iconic |
| [] | gen_empty_obj() |
| [t1,t2] | concat_obj(p1, p2, q) |
| |t| | count_obj(p, num) |
| t[i] | select_obj(p, q, i+1) |
| t[i1:i2] | copy_obj(p, q, i1+1, i2-i1+1) |
Table 8.7: Equivalent tuple operations for control and iconic data.
| 2)
Please note that the index of objects (e.g., select_obj) ranges from 1 to
the number of elements.
|