




技术领域technical field
本申请涉及矢量绘图技术领域,尤其涉及一种卷绕数计算方法、系统及相关设备。The present application relates to the technical field of vector drawing, in particular to a method, system and related equipment for calculating the number of windings.
背景技术Background technique
矢量绘图技术领域中,矢量图形使用封闭的有向路径描述填充图形的边界,该有向路径对位图中目标像素点的卷绕数(winding number)可以表示有向路径环绕该目标像素点的圈数以及方向,可以通过计算目标像素点的卷绕数的值来确定目标像素点是否位于封闭的有向路径内部。In the field of vector drawing technology, vector graphics use closed directed paths to describe the boundaries of filled graphics, and the winding number (winding number) of the directed path to the target pixel in the bitmap can represent the direction of the directed path around the target pixel. The number of turns and the direction can be determined by calculating the value of the winding number of the target pixel to determine whether the target pixel is located inside the closed directed path.
相关技术中,计算目标点的卷绕数往往是根据定义累加有向路径中各个段起点以及终点与该目标像素点组成的夹角,最后将夹角的累加值除于2π得到目标像素点的卷绕数。现有技术中,在每个像素点处都需要完全重新计算夹角三角函数,然后用反三角函数求解角度进行累加,效率低下。In related technologies, calculating the winding number of the target point is often based on the definition of accumulating the angles formed by the starting point and end point of each segment in the directed path and the target pixel point, and finally dividing the accumulated value of the included angle by 2π to obtain the value of the target pixel point Number of windings. In the prior art, it is necessary to completely recalculate the trigonometric function of the included angle at each pixel point, and then use the inverse trigonometric function to solve the angle for accumulation, which is inefficient.
发明内容Contents of the invention
针对上述现有技术中存在的问题,本申请实施例提供了一种卷绕数计算方法,可以删除待压缩文件中的内嵌字体列表中冗余的字符,减小了内嵌字体列表的大小,从而节省了待压缩文件的占用内存。In view of the problems existing in the above-mentioned prior art, the embodiment of the present application provides a winding number calculation method, which can delete redundant characters in the embedded font list in the file to be compressed, and reduce the size of the embedded font list , thereby saving the occupied memory of the file to be compressed.
第一方面,本申请实施例提供了一种卷绕数计算方法,其中,包括:In the first aspect, the embodiment of the present application provides a winding number calculation method, which includes:
创建一个与目标位图像素点数量相同的二维数组buff[W][H],并将每个数组元素取值设置为相同的初始值;其中,W、H分别表示目标位图在行、列方向的像素点的数量;Create a two-dimensional array buff[W][H] with the same number of pixels as the target bitmap, and set the value of each array element to the same initial value; where, W and H respectively represent the target bitmap in row, The number of pixels in the column direction;
发起W个或H个并行的赋值运算过程,每个所述赋值运算过程包括:在直角坐标系中,以当前编号为横坐标x,计算当前横坐标下与闭和矢量路径交点的全部纵坐标y,并将交点buff[x][y]进行赋值操作;其中,所述赋值操作是指,按照矢量路径与交点处的纵轴线的位置关系从左到右、相切、从右到左依次将交点buff[x][y]赋值为第一标定值、第二标定值、第三标定值;其中,第一标定值、第三标定值为相反数;Initiate W or H parallel assignment operation processes, each of which includes: in the Cartesian coordinate system, use the current number as the abscissa x, and calculate all the ordinates of the intersection points of the current abscissa and the closed sum vector path y, and assign the intersection point buff[x][y]; wherein, the assignment operation refers to, according to the positional relationship between the vector path and the longitudinal axis at the intersection point, from left to right, tangent, and from right to left Assign the intersection point buff[x][y] as the first calibration value, the second calibration value, and the third calibration value; wherein, the first calibration value and the third calibration value are opposite numbers;
按列或行计算每一个数组元素的前缀和,并将每一个数组元素的前缀和作为对应像素点的卷绕数。Calculate the prefix sum of each array element by column or row, and use the prefix sum of each array element as the winding number of the corresponding pixel.
进一步地,所述按列或行计算每一个数组元素的前缀和,可包括:Further, the calculation of the prefix sum of each array element by column or row may include:
按列或行对数组进行第一组合求和操作,所述第一组合求和操作是指,按长度为2的幅度,将每列或每行数组元素依次分割为多个小组,并对每个小组中数组元素的数值进行求和,并将数组元素的和更新在每个小组中排序最大的数组元素中;Carrying out the first combined summation operation on the array by column or row, the first combined summation operation refers to dividing each column or row of array elements into multiple groups in turn according to the magnitude of the length of 2, and each Sum the values of the array elements in each group, and update the sum of the array elements in the largest array element sorted in each group;
对第一组合求和操作之后的数组元素的和进行多次组合求和操作,后一次组合求和操作将上一次组合求和操作的所得的和值按长度为2的幅度分为小组,并对每个小组中数组元素的数值进行求和,并将和值更新在每个小组中排序最大的数组元素中;Perform multiple combined summation operations on the sum of the array elements after the first combined summation operation, and the latter combined summation operation divides the sum obtained from the previous combined summation operation into small groups with a length of 2, and Sum the values of the array elements in each group, and update the sum value in the largest array element sorted in each group;
将多次组合求和操作之后的数组中排序最大的数组元素进行数值置零操作;Set the value of the largest array element in the array after multiple combined summation operations to zero;
对数值置零操作之后的数组进行多次分割求和操作,每一次分割求和操作中,将数值置零操作之后的数组等分为第一分组和第二分组,对两分组中排序最大的数组元素求和并将和值更新在第二分组中排序最大的数组元素中,同时将第二分组中排序最大的数组元素的值赋给所述第一分组中排序最大的数组元素;Perform multiple division and summation operations on the array after the value zeroing operation. In each division and summation operation, the array after the value zeroing operation is divided into the first group and the second group, and the largest sort of the two groups is The array elements are summed and the sum value is updated in the largest array element in the second grouping, and at the same time, the value of the largest array element in the second grouping is assigned to the largest array element in the first grouping;
将多次分割求和操作之后的数组中的各个数组元素的值加上其初始赋值。Add the value of each array element in the array after multiple division and sum operations to its initial assignment.
进一步地,所述按列或行计算每一个数组元素的前缀和,可包括:Further, the calculation of the prefix sum of each array element by column or row may include:
采用迭代算法按列或行依次计算每一个当前数组元素以及所述当前数组元素之前的所有数组元素的数值之和为所述数组元素的前缀和。。The sum of the values of each current array element and all array elements before the current array element is calculated sequentially by column or row by an iterative algorithm, which is the prefix sum of the array elements. .
进一步地,本申请实施例中的卷绕数计算方法还可以包括:Further, the winding number calculation method in the embodiment of the present application may also include:
若目标数组元素的前缀和大于预设值,则将所述目标数组元素对应像素点的颜色区别显示,以将闭合的闭和矢量路径内部的像素点与外部的像素点区别If the prefix sum of the target array element is greater than the preset value, the color of the pixel corresponding to the target array element will be displayed differently, so as to distinguish the pixels inside the closed vector path from the outside pixels
第二方面,本申请实施例还提供了一种卷绕数计算装置,可包括:In the second aspect, the embodiment of the present application also provides a winding number calculation device, which may include:
创建模块,用于创建一个与目标位图像素点数量相同的二维数组buff[W][H],并将每个数组元素取值设置为相同的初始值;其中,W、H分别表示目标位图在行、列方向的像素点的数量;The creation module is used to create a two-dimensional array buff[W][H] with the same number of pixels in the target bitmap, and set the value of each array element to the same initial value; where W and H respectively represent the target The number of pixels of the bitmap in the row and column directions;
第一计算模块,发起W个或H个并行的赋值运算过程,每个所述赋值运算过程包括:在直角坐标系中,以当前编号为横坐标x,计算当前横坐标下与闭和矢量路径交点的全部纵坐标y,并将交点buff[x][y]进行赋值操作;其中,所述赋值操作是指,按照矢量路径与交点处的纵轴线的位置关系从左到右、相切、从右到左依次将交点buff[x][y]赋值为第一标定值、第二标定值、第三标定值;其中,第一标定值、第三标定值为相反数;The first calculation module initiates W or H parallel assignment operation processes, each of which includes: in the Cartesian coordinate system, with the current number as the abscissa x, calculate the current abscissa lower and closed sum vector path All the vertical coordinates y of the intersection point, and assign the intersection point buff[x][y]; wherein, the assignment operation refers to, from left to right, tangent, From right to left, assign the intersection buff[x][y] as the first calibration value, the second calibration value, and the third calibration value; wherein, the first calibration value and the third calibration value are opposite numbers;
第二计算模块,按列或行计算每一个数组元素的前缀和,并将每一个数组元素的前缀和作为对应像素点的卷绕数。The second calculation module calculates the prefix sum of each array element by column or row, and uses the prefix sum of each array element as the winding number of the corresponding pixel.
第三方面,本申请实施例还提供了一种电子设备,其中,包括:存储器以及处理器,所述存储器用于存储并支持处理器执行第一方面中任一项所述方法的程序,所述处理器被配置为用于执行所述存储器中存储的程序。In the third aspect, the embodiment of the present application also provides an electronic device, which includes: a memory and a processor, the memory is used to store and support the processor to execute the program of any one of the methods in the first aspect, so The processor is configured to execute programs stored in the memory.
第四方面,本申请实施例还提供了一种具有处理器可执行的非易失的程序代码的计算机可读介质,其中,所述程序代码使所述处理器执行所述第一方面的任一所述方法。In a fourth aspect, the embodiment of the present application further provides a computer-readable medium having a processor-executable non-volatile program code, wherein the program code causes the processor to execute any of the above-mentioned first aspect. a method.
本申请实施例带来了以下有益效果:The embodiment of the present application brings the following beneficial effects:
本申请实施例中同时并行发起W个或H个并行的赋值运算过程,然后同时对目标位图中W个行或或H个列像素点的卷绕数进行计算,大大提高了目标位图像素点的卷绕数的计算效率。其次,本申请实施例中,通过多次组合求和操作和多次分割求和操作可以减少求和计算的次数,降低计算的复杂度,进一步提高了卷绕数计算的效率。In the embodiment of the present application, W or H parallel assignment operation processes are initiated in parallel at the same time, and then the winding numbers of W row or H column pixels in the target bitmap are calculated at the same time, which greatly improves the target bitmap pixel count. The calculation efficiency of the winding number of points. Secondly, in the embodiment of the present application, the number of summation calculations can be reduced through multiple combination summation operations and multiple division summation operations, reducing calculation complexity and further improving the efficiency of winding number calculation.
附图说明Description of drawings
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图示出的结构获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present application, and those skilled in the art can also obtain other drawings according to the structures shown in these drawings without creative effort.
图1为现有理论中的卷绕数计算示意图;Fig. 1 is the calculation schematic diagram of winding number in existing theory;
图2为本申请实施例中的卷绕数计算方法的一个实施例示意图;Fig. 2 is a schematic diagram of an embodiment of the winding number calculation method in the embodiment of the present application;
图3为本申请实施例中卷绕数计算方法的一个具体实施例示意图;Fig. 3 is a schematic diagram of a specific embodiment of the winding number calculation method in the embodiment of the present application;
图4为本申请实施例中卷绕数计算方法的另一个具体实施例示意图;Fig. 4 is a schematic diagram of another specific embodiment of the winding number calculation method in the embodiment of the present application;
图5为本申请实施例中的电子设备的一个实施例示意图。FIG. 5 is a schematic diagram of an embodiment of an electronic device in an embodiment of the present application.
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization, functional features and advantages of the present application will be further described in conjunction with the embodiments and with reference to the accompanying drawings.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请的一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of them. Based on the embodiments in this application, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of this application.
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分的实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本申请保护的范围。In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiment of the application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiment of the application. Obviously, the described embodiment is only It is an embodiment of a part of the application, but not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by persons of ordinary skill in the art without creative efforts shall fall within the scope of protection of this application.
本申请的说明书和权利要求书及上述附图中,术语“上”、“下”、“左”、“右”等指示的方位或位置关系为基于附图所示的方位或位置关系,仅是为了便于描述本申请和简化描述,而不是指示或暗示所指的装置或元件必须具有特定的方位、以特定的方位构造和操作,因此不能理解为对本申请的限制。In the description and claims of this application and the above drawings, the orientation or positional relationship indicated by the terms "upper", "lower", "left", "right" etc. are based on the orientation or positional relationship shown in the accompanying drawings, only It is for the convenience of describing the application and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and thus should not be construed as limiting the application.
此外,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括一个或者更多个该特征。术语“包括”及其任何变形,意图在于覆盖不排他的包含。对于本领域的普通技术人员而言,可以根据具体情况理解上述术语在本申请中的具体含义。In addition, the terms "first" and "second" are used for descriptive purposes only, and cannot be interpreted as indicating or implying relative importance or implicitly specifying the quantity of indicated technical features. Thus, a feature defined as "first" and "second" may explicitly or implicitly include one or more of these features. The term "comprise" and any variations thereof, are intended to cover non-exclusive inclusion. Those of ordinary skill in the art can understand the specific meanings of the above terms in this application according to specific situations.
为了便于理解,下面对本申请涉及的专业技术术语进行简单说明。For ease of understanding, the technical terms involved in this application are briefly explained below.
卷绕数在代数拓扑中是基本的概念,在向量分析、复分析、几何拓扑、微分几何以及物理学中也扮演了重要的角色。平面上的闭合曲线关于某个点的卷绕数(windingnumber),是一个整数,它表示了曲线绕过该点的总次数。卷绕数与曲线的定向有关,如果曲线依顺时针方向绕过某个点,则卷绕数是负数。Winding numbers are fundamental concepts in algebraic topology and also play important roles in vector analysis, complex analysis, geometric topology, differential geometry, and physics. The winding number of a closed curve on a plane about a point is an integer, which represents the total number of times the curve goes around the point. The winding number is related to the orientation of the curve and is negative if the curve goes around a point in a clockwise direction.
对于一个存放数字的数组而言,前缀就是指的数组的前k项,因此对应的前缀和就是数组前面所有项的和。例如,数组a[N]的前缀和仍是一个长度为N的数组,记为b[N],其中b[i]=a[0]+a[1]+…a[i]。For an array storing numbers, the prefix refers to the first k items of the array, so the corresponding prefix sum is the sum of all items in front of the array. For example, the prefix sum of the array a[N] is still an array of length N, denoted as b[N], where b[i]=a[0]+a[1]+...a[i].
申请人注意到,基于现有理论,以每个像素点为起点的射线与闭合矢量路径的交点的类型可以分为三类,分别为A侧到B侧,B侧到A侧,相切三类(任取一侧记为A侧,另一为B侧),分别对有向环绕数的贡献量为1、-1、0,相加即为最终的有向环绕数。示例性的,如图1所示,Q点处的射线与闭合矢量路径的交点的贡献量分别是1、1、-1、1,则Q点的有向环绕数为2。现有理论中,每个像素点发出的射线会被该像素点所在段的左边界分成段内和段外两部分,段外部分的贡献量等于该射线与边界交点处的像素的有向环绕数,将该数值加上还需计算的段内部分的贡献即得出了该像素自身的有向环绕数。申请人发现,现有理论中需要先计算各段外部分的贡献量,即先依次计算射线与边界交点所在的各个线段处的像素的有向环绕数,在依次相加,计算过程存在顺序依赖关系,不利于并行计算,效率低下。The applicant noticed that, based on existing theories, the intersection types of the ray starting from each pixel point and the closed vector path can be divided into three categories, namely A side to B side, B side to A side, and tangential three Class (one side is taken as A side, and the other is B side), the contribution to the directed surround number is 1, -1, 0 respectively, and the sum is the final directed surround number. Exemplarily, as shown in FIG. 1 , the contribution amounts of the intersections of the ray at point Q and the closed vector path are 1, 1, -1, and 1 respectively, so the directed winding number of point Q is 2. In the existing theory, the ray emitted by each pixel point will be divided into two parts inside the segment and outside the segment by the left boundary of the segment where the pixel point is located. The contribution of the part outside the segment is equal to the directed surround of the pixel at the intersection of the ray and the boundary The value is added to the contribution of the part of the segment that needs to be calculated to obtain the directed wrapping number of the pixel itself. The applicant found that in the existing theory, it is necessary to calculate the contribution of each part outside the segment first, that is, first calculate the directed wrapping numbers of the pixels at each line segment where the intersection point of the ray and the boundary is located, and then add them sequentially. The calculation process has an order dependence Relationships are not conducive to parallel computing and are inefficient.
有鉴于此,本申请可以处于同一列(或者同一行)的像素点为起点作垂直于X轴的纵向轴线(或垂直于Y轴的横向轴线)基于交点的类型,并行求解同一列(或者同一行)的像素点的卷绕数。In view of this, the application can use the pixels in the same column (or the same row) as the starting point to make a longitudinal axis perpendicular to the X axis (or a transverse axis perpendicular to the Y axis) based on the type of intersection, and solve the same column (or the same row) in parallel. Row) pixel winding number.
下面对本申请实施例中的具体流程进行描述,请参阅图2,本申请实施例中一种卷绕数计算方法的一个实施例可包括:The specific process in the embodiment of the present application is described below. Please refer to FIG. 2. An embodiment of a method for calculating the number of windings in the embodiment of the present application may include:
S201:创建一个与目标位图像素点数量相同的二维数组buff[W][H],并将每个数组元素取值设置为相同的初始值。S201: Create a two-dimensional array buff[W][H] having the same number of pixels as the target bitmap, and set the value of each array element to the same initial value.
在需要计算目标位图中平面上的闭和矢量路径关于各个像素点的卷绕数时,可以创建一个与目标位图像素点数量相同的二维数组buff[W][H]以记录各个像素点的卷绕数,并将每个数组中的各个数组元素取值设置为相同的初始值(例如,可设初始值为0)。其中,W、H分别表示目标位图在行、列方向的像素点的数量。When it is necessary to calculate the winding number of the closed and vector path on the plane in the target bitmap with respect to each pixel, a two-dimensional array buff[W][H] with the same number of pixels in the target bitmap can be created to record each pixel The winding number of the point, and set the value of each array element in each array to the same initial value (for example, the initial value can be set to 0). Wherein, W and H respectively represent the number of pixels of the target bitmap in the row and column directions.
S202:发起W个或H个并行的赋值运算过程,每个赋值运算过程包括:在直角坐标系中,以当前编号为横坐标x,计算当前横坐标下与闭和矢量路径交点的全部纵坐标y,并将交点buff[x][y]进行赋值操作。S202: Initiate W or H parallel assignment operation processes, each assignment operation process includes: in the Cartesian coordinate system, use the current number as the abscissa x, and calculate all the vertical coordinates of the intersection points of the current abscissa and the closed sum vector path y, and assign the intersection point buff[x][y].
为提高卷绕数计算的效率,可以按行或列进行并行计算。具体的,若按行进行计算时,可以发起W个并行的赋值运算过程;若按列进行计算时,可以发起H个并行的赋值运算过程。该赋值运算过程可包括:在直角坐标系中,以当前编号为横坐标x,计算当前横坐标下与闭和矢量路径交点的全部纵坐标y,并将闭和矢量路径上的交点buff[x][y]进行赋值操作。In order to improve the efficiency of winding number calculation, parallel calculation can be performed by row or column. Specifically, if calculation is performed by row, W parallel assignment operation processes may be initiated; if calculation is performed by column, H parallel assignment operation processes may be initiated. The assignment operation process may include: in the Cartesian coordinate system, use the current number as the abscissa x, calculate all the ordinates y of the intersection points with the closed sum vector path under the current abscissa coordinates, and set the intersection point buff[x on the closed sum vector path ][y] for assignment operation.
其中,赋值操作是指,按照矢量路径与交点处的纵轴线的位置关系从左到右、相切、从右到左依次将交点buff[x][y]赋值为第一标定值、第二标定值、第三标定值。其中,第一标定值、第三标定值为相反数,两者的和为0;第二标定值可以为0。示例性的,如图2所示的闭合矢量路径中,A、B点处的矢量路径与纵轴线的位置关系分别为从左到右、从右到左。Among them, the assignment operation refers to assigning the intersection point buff[x][y] as the first calibration value, the second calibration value, the third calibration value. Wherein, the first calibration value and the third calibration value are opposite numbers, and the sum of the two is 0; the second calibration value may be 0. Exemplarily, in the closed vector path shown in FIG. 2 , the positional relationship between the vector path at points A and B and the longitudinal axis is from left to right and from right to left, respectively.
S203:按列或行计算每一个数组元素的前缀和,并将每一个数组元素的前缀和作为对应像素点的卷绕数。S203: Calculate the prefix sum of each array element by column or row, and use the prefix sum of each array element as the winding number of the corresponding pixel.
对数组进行赋值操作之后,按列或行计算每一个数组元素的前缀和,并将每一个数组元素的前缀和作为对应像素点的卷绕数。具体的前缀和计算方法可以参照相关技术,例如采用迭代算法按列或行依次计算每一个当前数组元素以及当前数组元素之前的所有数组元素的数值之和为数组元素的前缀和。After the array is assigned, the prefix sum of each array element is calculated by column or row, and the prefix sum of each array element is used as the winding number of the corresponding pixel. The specific prefix and calculation method can refer to related technologies, for example, an iterative algorithm is used to calculate the sum of the values of each current array element and all array elements before the current array element sequentially by column or row as the prefix sum of the array elements.
由以上公开内容可知,本申请实施例中同时并行发起W个或H个并行的赋值运算过程,然后同时对目标位图中W个行或或H个列像素点的卷绕数进行计算,大大提高了目标位图像素点的卷绕数的计算效率。It can be seen from the above disclosure that in the embodiment of the present application, W or H parallel assignment operation processes are initiated in parallel at the same time, and then the winding numbers of W rows or H columns of pixels in the target bitmap are calculated at the same time, greatly Improved the calculation efficiency of the winding number of the target bitmap pixel.
在上述实施例的基础上,申请人发现现有的按列或行计算每一个数组元素的前缀和的过程是按照递归算法,即需要依次递归计算处于同一射线上的像素点的卷绕数。这种递归算法的复杂度为(n2)/2。尽管当某路径段与某位图段不相交时,该位图段内的像素的段内贡献量计算过程可以忽视该路径段,但现有递归算法始终还是存在一个逐像素的对不可以被忽视的路径段的遍历过程,导致运算量大效率低下。On the basis of the above embodiments, the applicant found that the existing process of calculating the prefix sum of each array element by column or row is based on a recursive algorithm, that is, it is necessary to recursively calculate the winding numbers of the pixels on the same ray in turn. The complexity of this recursive algorithm is (n2 )/2. Although when a path segment does not intersect with a bitmap segment, the calculation process of the intra-segment contribution of the pixels in the bitmap segment can ignore the path segment, but there is always a pixel-by-pixel pair in the existing recursive algorithm that cannot be The traversal process of the neglected path segment results in a large amount of calculation and low efficiency.
在上述图2所示的实施例的基础上,为提高按列(或按行)计算卷绕数的效率,作为一种可能的实时方式,本申请的一种可能的实施方式中,对按列或行计算每一个数组元素的前缀和的过程可包括:On the basis of the above-mentioned embodiment shown in Figure 2, in order to improve the efficiency of calculating the number of windings by column (or by row), as a possible real-time method, in a possible implementation of the present application, the The process of calculating the prefix sum of each array element by column or row may include:
并行按列或行对数组进行第一组合求和操作,第一组合求和操作是指,按长度为2的幅度,将每列或每行数组元素依次分割为多个小组,并对每个小组中数组元素的数值进行求和,并将数组元素的和更新在每个小组中排序最大的数组元素中;对第一组合求和操作之后的数组元素的和进行多次组合求和操作,后一次组合求和操作将上一次组合求和操作的所得的和值按长度为2的幅度分为小组,并对每个小组中数组元素的数值进行求和,并将和值更新在每个小组中排序最大的数组元素中;将多次组合求和操作之后的数组中排序最大的数组元素进行数值置零操作;对数值置零操作之后的数组进行多次分割求和操作,每一次分割求和操作中,将数值置零操作之后的数组等分为第一分组和第二分组,对两分组中排序最大的数组元素求和并将和值更新在第二分组中排序最大的数组元素中,同时将第二分组中排序最大的数组元素的值赋给第一分组中排序最大的数组元素;将多次分割求和操作之后的数组中的各个数组元素的值加上其初始赋值。这种算法的计算复杂度为{n+4log2(n)},图像中的像素点数以万计(以1080p图像为例,一英寸内一列即包含1080个像素点),相对于(n2)/2,计算量大大降低。Perform the first combined summation operation on the array by column or row in parallel. The first combined summation operation refers to dividing each column or row of array elements into multiple groups in turn according to the magnitude of the length of 2, and performing each The values of the array elements in the group are summed, and the sum of the array elements is updated in the largest array element in each group; the sum of the array elements after the first combination summation operation is performed multiple combination summation operations, In the latter combined summation operation, the sum obtained from the previous combined summation operation is divided into groups with a length of 2, and the values of the array elements in each group are summed, and the sum is updated in each Among the array elements with the largest sort in the group; the array element with the largest sort in the array after multiple combined summation operations is set to zero; the array after the numerical zeroing operation is divided and summed multiple times, each split In the summation operation, the array after the value zeroing operation is equally divided into the first group and the second group, and the sum of the largest array elements in the two groups is summed and the sum value is updated to the largest array element in the second group , at the same time assign the value of the largest array element in the second group to the largest array element in the first group; add the value of each array element in the array after multiple division and summation operations to its initial assignment. The computational complexity of this algorithm is {n+4log2 (n)}, and there are tens of thousands of pixels in the image (taking a 1080p image as an example, a column within one inch contains 1080 pixels), compared to (n2 )/2, the calculation amount is greatly reduced.
示例性的,请参阅图3和图4,以一列像素点的卷绕数为例进行说明。直角坐标系中,一列像素的横坐标X相同,而纵坐标不同,经过步骤S202中的赋值操作之后的初始数组中的数组元素的数值为如图3中最下层的分别以y0、y1…y7表示。如图3所示,经过第一组合求和操作和多次组合求和操作之后,得到最上层的数组元素的数值。如图4所示,经过置零操作、多次分割求和操作之后,得到最下层的数组元素的数值分别为0、y0、∑(y0…y1)、∑(y0…y2)、∑(y0…y3)、∑(y0…y4)、∑(y0…y5)、∑(y0…y6),最后将最下层的数组元素的数值加上各个数组元素的初始赋值即可得到数组的所有前缀和y0、∑(y0…y1)、∑(y0…y2)、∑(y0…y3)、∑(y0…y4)、∑(y0…y5)、∑(y0…y6)、∑(y0…y7)。Exemplarily, please refer to FIG. 3 and FIG. 4 , and take the winding number of a column of pixels as an example for illustration. In the Cartesian coordinate system, the abscissa X of a column of pixels is the same, but the ordinate is different. After the assignment operation in step S202, the values of the array elements in the initial array are as shown in Fig. 3, respectively represented by y0 and y1 ...y7 said. As shown in FIG. 3 , after the first combined summation operation and multiple combined summation operations, the value of the uppermost array element is obtained. As shown in Figure 4, after the zero-setting operation and multiple division and summation operations, the values of the array elements at the bottom layer are 0, y0 , ∑(y0... y1 ), ∑(y0... y2 ), ∑(y0… y3 ), ∑(y0… y4 ), ∑(y0… y5 ), ∑(y0… y6 ), and finally add the value of the lowest array element to each The initial assignment of the array elements can get all the prefixes of the array and y0 , ∑(y0… y1 ), ∑(y0… y2 ), ∑(y0… y3 ), ∑(y0… y4 ), ∑(y0… y5 ), ∑(y0… y6 ), ∑(y0… y7 ).
由以上公开内容可知,通过多次组合求和操作和多次分割求和操作可以减少求和计算的次数,降低计算的复杂度,提高卷绕数计算的效率。It can be seen from the above disclosure that the number of times of summation calculations can be reduced, the complexity of calculations can be reduced, and the efficiency of winding number calculations can be improved through multiple combined summation operations and multiple divisional summation operations.
在上述任一实施例的基础上,在矢量绘图技术领域中,获取到像素点的卷绕数之后,依次判断各个像素点对应的目标数组元素中存储的前缀和的数值是否大于预设值,若目标数组元素的前缀和大于预设值,则将目标数组元素对应像素点的颜色区别显示,以将闭合的闭和矢量路径内部的像素点与外部的像素点区别显示。On the basis of any of the above-mentioned embodiments, in the technical field of vector drawing, after obtaining the number of windings of pixels, it is sequentially judged whether the value of the prefix sum stored in the target array element corresponding to each pixel is greater than the preset value, If the prefix sum of the target array element is greater than the preset value, the color of the pixel corresponding to the target array element is displayed differently, so as to distinguish the pixel inside the closed vector path from the outside pixel.
本申请实施例还提供了一种卷绕数计算装置,可包括:The embodiment of the present application also provides a winding number calculation device, which may include:
创建模块,用于创建一个与目标位图像素点数量相同的二维数组buff[W][H],并将每个数组元素取值设置为相同的初始值;其中,W、H分别表示目标位图在行、列方向的像素点的数量;The creation module is used to create a two-dimensional array buff[W][H] with the same number of pixels in the target bitmap, and set the value of each array element to the same initial value; where W and H respectively represent the target The number of pixels of the bitmap in the row and column direction;
第一计算模块,发起W个或H个并行的赋值运算过程,每个赋值运算过程包括:在直角坐标系中,以当前编号为横坐标x,计算当前横坐标下与闭和矢量路径交点的全部纵坐标y,并将交点buff[x][y]进行赋值操作;其中,赋值操作是指,按照矢量路径与交点处的纵轴线的位置关系从左到右、相切、从右到左依次将交点buff[x][y]赋值为第一标定值、第二标定值、第三标定值;其中,第一标定值、第三标定值为相反数;The first calculation module initiates W or H parallel assignment operation processes, each assignment operation process includes: in the Cartesian coordinate system, with the current number as the abscissa x, calculate the intersection of the current abscissa and the closed sum vector path All the ordinates y, and the intersection point buff[x][y] are assigned; where, the assignment refers to, according to the positional relationship between the vector path and the longitudinal axis at the intersection, from left to right, tangent, and from right to left Assign the intersection point buff[x][y] as the first calibration value, the second calibration value, and the third calibration value in turn; wherein, the first calibration value and the third calibration value are opposite numbers;
第二计算模块,按列或行计算每一个数组元素的前缀和,并将每一个数组元素的前缀和作为对应像素点的卷绕数。The second calculation module calculates the prefix sum of each array element by column or row, and uses the prefix sum of each array element as the winding number of the corresponding pixel.
可选的,作为一种可能的实施方式,本申请实施例中的第二计算模块,可包括:Optionally, as a possible implementation manner, the second calculation module in the embodiment of the present application may include:
第一计算单元,按列或行对数组进行第一组合求和操作,第一组合求和操作是指,按长度为2的幅度,将每列或每行数组元素依次分割为多个小组,并对每个小组中数组元素的数值进行求和,并将数组元素的和更新在每个小组中排序最大的数组元素中;The first calculation unit performs the first combined summation operation on the array by column or row. The first combined summation operation refers to dividing the array elements of each column or row into multiple groups in sequence according to the length of 2. And sum the values of the array elements in each group, and update the sum of the array elements in the largest array element sorted in each group;
第二计算单元,对第一组合求和操作之后的数组元素的和进行多次组合求和操作,后一次组合求和操作将上一次组合求和操作的所得的和值按长度为2的幅度分为小组,并对每个小组中数组元素的数值进行求和,并将和值更新在每个小组中排序最大的数组元素中;The second calculation unit performs multiple combined summation operations on the sum of the array elements after the first combined summation operation, and the latter combined summation operation converts the sum value obtained by the previous combined summation operation into an amplitude of 2 in length Divide into groups, and sum the values of the array elements in each group, and update the sum value in the largest array element sorted in each group;
第三计算单元,将多次组合求和操作之后的数组中排序最大的数组元素进行数值置零操作;The third calculation unit performs a value zeroing operation on the largest array element in the array after multiple combined summation operations;
第四计算单元,对数值置零操作之后的数组进行多次分割求和操作,每一次分割求和操作中,将数值置零操作之后的数组等分为第一分组和第二分组,对两分组中排序最大的数组元素求和并将和值更新在第二分组中排序最大的数组元素中,同时将第二分组中排序最大的数组元素的值赋给第一分组中排序最大的数组元素;The fourth calculation unit performs multiple division and summation operations on the array after the value zeroing operation. In each division and summation operation, the array after the value zeroing operation is divided into the first group and the second group. Sum the largest array elements in the group and update the sum value in the largest array element in the second group, and assign the value of the largest array element in the second group to the largest array element in the first group ;
第五计算单元,将多次分割求和操作之后的数组中的各个数组元素的值加上其初始赋值。The fifth calculation unit adds the initial assigned value to the value of each array element in the array after multiple division and summation operations.
可选的,作为一种可能的实施方式,本申请实施例中的第二计算模块包括:Optionally, as a possible implementation manner, the second calculation module in the embodiment of the present application includes:
迭代计算单元,采用迭代算法按列或行依次计算每一个当前数组元素以及当前数组元素之前的所有数组元素的数值之和为数组元素的前缀和。The iterative calculation unit uses an iterative algorithm to sequentially calculate the sum of the values of each current array element and all array elements before the current array element as the prefix sum of the array elements.
可选的,作为一种可能的实施方式,本申请实施例中的卷绕数计算装置,还可以包括:Optionally, as a possible implementation manner, the device for calculating the number of windings in the embodiment of the present application may also include:
显示模块,若目标数组元素的前缀和大于预设值,则将目标数组元素对应像素点的颜色区别显示,以将闭合的闭和矢量路径内部的像素点与外部的像素点区别显示。The display module, if the prefix sum of the target array element is greater than the preset value, then display the color of the pixel corresponding to the target array element differently, so as to distinguish the pixel inside the closed vector path from the outside pixel.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
上面从模块化功能实体的角度对本申请实施例中的卷绕数计算装置进行了描述,请参阅图5,下面从硬件处理的角度对本申请实施例中的电子设备进行描述:The winding number calculation device in the embodiment of the present application has been described above from the perspective of modular functional entities. Please refer to FIG. 5. The electronic device in the embodiment of the present application is described below from the perspective of hardware processing:
该电子设备1可以包括存储器11、处理器12和输入输出总线13。处理器12执行计算机程序时实现上述图2所示的方法实施例中的步骤,例如图2所示的步骤201至203。或者,处理器执行计算机程序时实现上述各装置实施例中各模块或单元的功能。The
其中,存储器11至少包括一种类型的可读存储介质,可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器11在一些实施例中可以是电子设备1的内部存储单元,例如该电子设备1的硬盘。存储器11在另一些实施例中也可以是电子设备1的外部存储设备,例如电子设备1上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(FlashCard)等。进一步地,存储器11还可以既包括电子设备1的内部存储单元也包括外部存储设备。存储器11不仅可以用于存储安装于电子设备1的应用软件及各类数据,例如计算机程序的代码等,还可以用于暂时地存储已经输出或者将要输出的数据。Wherein, the
处理器12在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或处理数据,例如执行计算机程序等。In some embodiments, the
该输入输出总线13可以是外设部件互连标准(peripheral componentinterconnect,简称PCI)总线或扩展工业标准结构(extended industry standardarchitecture,简称EISA)总线等。该总线可以分为地址总线、数据总线、控制总线等。The I/
进一步地,电子设备还可以包括有线或无线网络接口14,网络接口14可选的可以包括有线接口和/或无线接口(如WI-FI接口、蓝牙接口等),通常用于在该电子设备1与其他电子设备之间建立通信连接。Further, the electronic device can also include a wired or
可选地,该电子设备1还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的,用户接口还可以包括标准的有线接口、无线接口。可选的,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及OLED(Organic Light-Emitting Diode,有机发光二极管)触摸器等。其中,显示器也可以适当的称为显示屏或显示单元,用于显示在电子设备1中处理的信息以及用于显示可视化的用户界面。Optionally, the
图5仅示出了具有组件11-14以及计算机程序的电子设备1,本领域技术人员可以理解的是,图5示出的结构并不构成对电子设备1的限定,可以包括比图示更少或者更多的部件,或者组合某些部件,或者不同的部件布置。FIG. 5 only shows an
本申请还提供了一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,计算机程序被处理器执行时,可以实现如图2所示的方法实施例中的步骤,例如图2所示的步骤201至203。或者,处理器执行计算机程序时实现上述各装置实施例中各模块或单元的功能。The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the method embodiment as shown in FIG. 2 can be realized, for example, as shown in FIG. Steps 201 to 203 shown in 2. Alternatively, when the processor executes the computer program, the functions of the modules or units in the above-mentioned device embodiments are realized.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated. to another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。A unit described as a separate component may or may not be physically separated, and a component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-OnlyMemory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or part of the contribution to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , including several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk, and other media that can store program codes.
以上所述仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是在本申请的发明构思下,利用本申请说明书及附图内容所作的等效结构变换,或直接/间接运用在其他相关的技术领域均包括在本申请的专利保护范围内。The above are only preferred embodiments of the present application, and are not therefore limiting the patent scope of the present application. Under the inventive concept of the present application, the equivalent structural transformations made by using the description of the application and the contents of the accompanying drawings, or direct/indirect use All other relevant technical fields are included in the patent protection scope of the present application.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211598603.7ACN116258788A (en) | 2022-12-12 | 2022-12-12 | Winding number calculation method and device and related equipment |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211598603.7ACN116258788A (en) | 2022-12-12 | 2022-12-12 | Winding number calculation method and device and related equipment |
| Publication Number | Publication Date |
|---|---|
| CN116258788Atrue CN116258788A (en) | 2023-06-13 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202211598603.7APendingCN116258788A (en) | 2022-12-12 | 2022-12-12 | Winding number calculation method and device and related equipment |
| Country | Link |
|---|---|
| CN (1) | CN116258788A (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7725518B1 (en)* | 2007-08-08 | 2010-05-25 | Nvidia Corporation | Work-efficient parallel prefix sum algorithm for graphics processing units |
| US20150022531A1 (en)* | 2013-07-16 | 2015-01-22 | Mitsubishi Electric Research Laboratories, Inc. | Method for Labeling Segments of Paths as Interior or Exterior |
| US20220366621A1 (en)* | 2021-05-04 | 2022-11-17 | Adobe Inc. | Systems for Generating Anti-Aliased Vector Objects |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7725518B1 (en)* | 2007-08-08 | 2010-05-25 | Nvidia Corporation | Work-efficient parallel prefix sum algorithm for graphics processing units |
| US20150022531A1 (en)* | 2013-07-16 | 2015-01-22 | Mitsubishi Electric Research Laboratories, Inc. | Method for Labeling Segments of Paths as Interior or Exterior |
| US20220366621A1 (en)* | 2021-05-04 | 2022-11-17 | Adobe Inc. | Systems for Generating Anti-Aliased Vector Objects |
| Title |
|---|
| GUY BLELLOCH: "Prefix Sums and Their Applications", COMPUTER SCIENCE, MATHEMATICS, 30 November 1990 (1990-11-30), pages 35 - 60* |
| 张景雄等: "地理信息系统与科学", 31 January 2010, 武汉:武汉大学出版社, pages: 184* |
| Publication | Publication Date | Title |
|---|---|---|
| CN109919311B (en) | Method for generating instruction sequence, method and device for executing neural network operation | |
| WO2021042844A1 (en) | Large-scale data clustering method and apparatus, computer device and computer-readable storage medium | |
| JP2021516382A (en) | Image conversion for machine learning | |
| JP7185044B2 (en) | Element rendering method, device, computer program and computer device | |
| WO2020248365A1 (en) | Intelligent model training memory allocation method and apparatus, and computer-readable storage medium | |
| US20220245510A1 (en) | Multi-dimensional model shape transfer | |
| CN112100795A (en) | Method and device for comparing computer aided design drawings | |
| WO2021223262A1 (en) | Method and apparatus for generating object transfer and encasement process policy, and computer device | |
| CN116912272B (en) | Method, device, electronic device and storage medium for creating candidate clipping area | |
| CN114565916A (en) | Target detection model training method, target detection method and electronic equipment | |
| CN116227209B (en) | A point cloud data multidimensional linear interpolation method, terminal device and storage medium | |
| CN108805318B (en) | Method and device for evaluating a warehouse | |
| CN113538623B (en) | Method, device, electronic equipment and storage medium for determining target image | |
| CN111339064A (en) | Data tilt correction method, device and computer readable storage medium | |
| WO2021189694A1 (en) | Intelligent user layering method and apparatus, and electronic device and readable storage medium | |
| US20170236335A1 (en) | System and method for manipulating acceleration structures | |
| JP2025071069A (en) | Method, device, medium and equipment for high-speed calculation of feature data | |
| CN116258788A (en) | Winding number calculation method and device and related equipment | |
| EP3940541A1 (en) | A computer-implemented data processing method, micro-controller system and computer program product | |
| CN114092708A (en) | Feature image processing method, device and storage medium | |
| US11163808B2 (en) | Hexagon clustering of spatial data | |
| CN113159057A (en) | Image semantic segmentation method and computer equipment | |
| CN111951342A (en) | A method, system and storage medium for back surface component culling based on off-screen rendering | |
| CN114581676B (en) | Processing method, device and storage medium for feature image | |
| CN112150380A (en) | Method and device for correcting image, electronic equipment and readable storage medium |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |