Because you know exactly what you’re going to get if you use vectors.
Starting with version 12 Halcon introduced vectors that can either contain tuples or other vectors. This allows us to use them as structures and in this case categorize donuts:
Data.at(0).at(0) := ['UID', 1]
Data.at(0).at(1) := ['Frosting', 'Chocolate']
Data.at(0).at(2) := ['Topping', 'Sprinkles']
Data.at(0).at(3) := ['Hole', 1]
Of course, this input could be replaced with a simple function:
add_new_object (Data, 2, ['Frosting','Topping','Hole'], ['Strawberry','Sprinkles', 1], Data)
Properties := ['Frosting','Topping','Hole']
add_new_object (Data, 3, Properties, ['Chocolate', 'None', 1], Data)
add_new_object (Data, 4, Properties, ['None', 'None', 1], Data)
add_new_object (Data, 5, Properties, ['Raspberry', 'None', 1], Data)
...
Structuring data like this allows us to have a clear overview of data…
…and writing of simple queries:
** get_all_property_values (Data, PropertyName, OutputValues)
convert_vector_to_tuple (Data, Result)
tuple_find (Result, PropertyName, Indices)
OutputValues := Result[Indices+1]
return ()
** get_all_property_values (Data, 'UID', IDs)
** Result:
** [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Like getting all of the possible donut toppings:
** get_all_unique_property_values (Data, PropertyName, OutputValues)
get_all_property_values (Data, PropertyName, ValuesAll)
tuple_sort (ValuesAll, Sorted)
tuple_uniq (Sorted, OutputValues)
return ()
** get_all_unique_property_values (Data, 'Topping', Toppings)
** Result:
** ['Chocolate', 'None', 'Sprinkles', 'Sugar']
Or getting donut indices (starting from one from top left corner) with chocolate frosting:
** get_all_where_property_equals_X (Data, PropertyName, X, OutputValues)
get_all_property_values (Data, 'UID', IDs)
get_all_property_values (Data, PropertyName, Frostings)
tuple_find (Frostings, X, Indices)
OutputValues := IDs[Indices]
return ()
** get_all_where_property_equals_X (Data, 'Frosting', 'Chocolate', OutputValues)
** Result:
** [1, 3, 8, 11]
You can find the sample code here: Example