【halcon向量】

文章目录


除了HDevelop中两种公认的变量类型,元组和图标对象之外,还有第三种变量类型:向量。

向量是可以容纳任意数量元素的容器,所有元素都必须具有完全相同的变量类型(即元组、图标对象或向量)。关于内存管理等,HDevelop中的矢量与C++标准模板库中的矢量实现方式相同。

命名法:元组向量(或图标对象向量)称为一维,元组向量称为二维,依此类推。 (因此,元组或图标对象的维数为零)。

在这里插入图片描述

* In addition to the two well established variable types in HDevelop,
* tuples and iconic objects, there is a third variable type: the vector.
* A vector is a container that can hold an arbitrary number of elements,
* all of which must have the exact same variable type (i.e., tuple,
* iconic object, or vector). Regarding memory management and the like,
* vectors in HDevelop are implemented the same way as vectors in the
* C++ Standard Template Library.
* Nomenclature: A vector of tuples (or of iconic objects) is called
* one dimensional, a vector of vectors of tuples two dimensional, and so on.
* (Hence, tuples or iconic objects have a dimension of zero).
* 
dev_close_window ()
dev_update_off ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
Message := 'This program gives an overview of'
Message[1] := 'vector variables and how to use them.'
Message[2] := 'Please'
Message[3] := ' - step through the program,'
Message[4] := ' - read the comments,'
Message[5] := ' - and check the variable view.'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
stop ()
* 
* Construction of vectors:
* 
* The easiest way to write down a vector is to put a (comma separated)
* list of its elements between curly brackets.
Vector1 := {1,2}
* Note, that {[1,2]} is NOT the same as {1,2}:
Vector2 := {[1,2]}
* Vector elements may be constant (expressions) as well as variables.
Tuple1 := [5,6]
Tuple2 := 'eight'
Vector3 := {Tuple1,Tuple2}
* Vectors can also contain iconic objects:
read_image (ImageFabrik, 'fabrik')
read_image (ImagePatras, 'patras')
ImageVector := {ImageFabrik,ImagePatras}
* It is possible to use multidimensional vectors:
Vector2dim := {{1,2},Vector3}
Vector3dim := {Vector2dim,{Vector1,Vector2}}
* Note, that all elements of a vector must have the same type.
* E.g., the following does not work:
* InvalidExpression := {Vector1,Vector2dim}
* 
* Element access:
* Vector elements are accessed via the .at() expression
Tuple := Vector3.at(0)
Image := ImageVector.at(1)
* .at() expressions may as well serve as l-values.
* E.g., they can be used as output parameters.
Vector4.at(0) := Tuple
* Writing to a non existing vector element is allowed. If necessary,
* the vector is automatically filled with empty elements.
Vector5.at(4) := Tuple
* Vector elements can be used as parameters for operators or procedures
* (as long as they have the required type).
for I := 0 to ImageVector.length() - 1 by 1
    sobel_amp (ImageVector.at(I), ImageVectorSobel.at(I), 'sum_abs', 3)
endfor
* 
* It is also possible to combine several .at() expressions to access the
* subelements of multidimensional vectors.
Vector3dim.at(1).at(0) := {5,6}
* Even the following is possible (though not exactly recommended).
Vector3dim.at(0).at(1).at(1)[0] := 8
* 
* Vector length:
* The number of elements of a vector can be accessed with .length()
Length := Vector1.length()
* 
* Vector manipulation:
* .clear() clears a vector, i.e., removes all its elements:
Vector3dimCopy := Vector3dim
Vector3dimCopy.clear()
* Note, that the cleared vectors still keep their variable type. The
* following assignments cause a type conflict and, therefore, are invalid!
* Vector3dimCopy.at(0) := 1
* Vector3dimCopy.at(0) := {1}
* .remove() removes an element with given index from a vector.
Vector5.remove(0)
* 
* .insert() inserts at the given position one vector element into a vector.
Vector5.insert(1,2)
* Again, the vector gets filled up with empty elements where necessary.
Vector5.insert(8,10)
* 
* Vector conversion:
* Convert a tuple into a one-dimensional vector
Tuple3 := [1,2,3,4,5,6,7,8]
convert_tuple_to_vector_1d (Tuple3, 1, Vector1FromTuple3)
convert_tuple_to_vector_1d (Tuple3, 2, Vector2FromTuple3)
* convert_vector_to_tuple concatenates all tuples that are contained in the
* input vector of arbitrary dimension and stores them in the single
* output tuple.
convert_vector_to_tuple (Vector5, TupleFromVector5)
convert_vector_to_tuple (Vector2dim, TupleFromVector2dim)
* 
* The variable view can be used to inspect vector variables
dev_inspect_ctrl ([Tuple3,Vector1FromTuple3,Vector2FromTuple3,Vector5,TupleFromVector5,Vector2dim,TupleFromVector2dim,Vector3dim])

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

【网络星空】

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值