Print

发布时间: 2020-08-16
摘要点击次数:
全文下载次数:
DOI: 10.11834/jig.190548
2020 | Volume 25 | Number 8




    计算机图形学    




  <<上一篇 




  下一篇>> 





融合DNN与AABB—圆形包围盒自碰撞检测
expand article info 靳雁霞, 程琦甫, 张晋瑞, 齐欣, 马博, 贾瑶
中北大学大数据学院, 太原 030051

摘要

目的 为了解决自碰撞检测剔除率低和检测速度慢的问题,提出一种AABB(aixe align bounding box)—圆形包围盒树结构和具有二分类功能的深度神经网络(deep neural network,DNN)加速包围盒相交检测的方法。方法 对变形体构建AABB—圆形包围盒树,即对内部节点构建AABB包围盒,对叶子节点构建圆形包围盒。根据AABB—圆形包围盒生成包围盒测试树(bounding volume test tree,BVTT),采用深度神经网络优化BVTT的包围盒相交测试和法向锥测试,输出碰撞三角形对。结果 在确定最优隐含层数和每层最优节点数保证深度神经网络达到最佳准确率的情况下,实验结果表明,在没有自碰撞的情况下,本文方法与AABB-OBB方法、经典包围盒方法耗时相同,但在自碰撞足够多的模拟场景中,融合深度神经网络的AABB-圆形包围盒方法比AABB-OBB(oriented bounding box)方法和经典的包围盒方法速度更快,整体耗时缩短了21%~37%。同时,对5种方法的更新率、检测效率和图元相交测试时间进行实验对比,发现本文方法比AABB-OBB方法和经典的方法具有更好的贴合性和更快的相交测试速度。结论 本文方法相对于AABB-OBB方法、经典包围盒方法的测试速度更快,不仅提高了自碰撞检测高层剔除率,同时降低了模拟整体耗时,更适用于实时变形体自碰撞检测领域。

关键词

自碰撞检测; 混合层次包围盒; 圆形包围盒; 深度神经网络; 图元相交测试

Self-collision detection algorithm based on fused DNN and AABB-circular bounding box
expand article info Jin Yanxia, Cheng Qifu, Zhang Jinrui, Qi Xin, Ma Bo, Jia Yao
School of Big Data, North University of China, Taiyuan 030051, China

Abstract

Objective The deformation body simulation technology has been continuously developed in recent years and has been widely investigated in virtual simulation. It has been widely used in animation, design, and games. In the computer virtual environment, rapid and accurate self-collision detection can immensely enhance the realistic sense of deformation body simulation. A cloth is a representative deformable body composed of a large number of geometric elements, which is characterized by thin and soft, and easy to deform, squeeze, and wrinkle. Therefore, fabric self-collision should be detected and penetration should be prevented to ensure the reality of fabric simulation. Data analysis shows that self-collision detection takes 60% 80% of the time in the simulated scene of a deformed body. Self-collision detection of cloth frequently consumes considerable time resources. For the deformation model without thickness, such as cloth, whether the fabric itself has a collision is difficult to determine through traditional collision detection in real time. Therefore, self-collision detection is a cutting-edge problem in cloth simulation. The self-collision detection effect of a deformed body, such as cloth, largely determines the authenticity of virtual simulation. Real-time is a difficult point in self-collision detection. Self-collision detection consumes considerable time because the cloth model consists of many primitives. Most existing self-collision detection algorithms focus on improving the test speed. The traditional self-collision detection algorithm uses bounding box test, which is extremely large and complex. It cannot meet the accuracy and real-time requirements at the same time. In other words, the pursuit of accuracy will prolong the time consumed by calculation, and the pursuit of real-time will reduce the detection accuracy. The above conditions will make the simulation effect insufficiently real. A previous work combined the normal cone test with traditional collision detection method, reduced the computation of intersection detection, and improved the detection speed to improve the speed of self-collision detection without affecting the detection accuracy. The calculation of the intersection test of the primitives is reduced by constructing a hybrid hierarchy composed of various bounding boxes to improve the fit of the bounding box. However, the improved algorithm cannot meet the real-time and accuracy requirements. This paper proposes a method combining the aixe align bounding box (AABB)-circular hybrid hierarchy of deep neural networks to solve the above problems. Method This paper proposes an AABB-circular hybrid hierarchical bounding box that integrates deep neural networks. The working principle is described as follows. First, an AABB-circular hybrid hierarchical bounding box tree is built for the clothing model. The AABB hierarchical boundary box tree is constructed for the model, and the three vertices of the triangle are used to calculate the circular boundary frame of the leaf nodes. Second, a bounding volume test tree (BVTT) is generated in accordance with the AABB-circular hierarchical bounding box. Third, the corresponding normal cone is calculated for the nodes in the constructed BVTT tree. Fourth, a bounding box test is performed first, followed by a normal cone test, and multiple pairs of potential collision primitives are outputted. Finally, multiple pairs of collision triangles are outputted by performing a primitive intersection test on the potential collision primitive. Result Experimental results shows that the proposed method achieves a balance between accuracy and time consumption on the premise of finding the optimal number of hidden layers in the deep neural network and the optimal number of nodes in each layer. The AABB-oriented bounding box(OBB) algorithm takes 19% to 33% less time than the classic self-collision detection algorithm. We compared the proposed method with the AABB-OBB method and three classical methods in terms of time consumption of updating, detecting, and primitive testing to verify the advantages of the proposed method in computation time. Experimental results show that the proposed method consumes a small amount of update time, optimizes the speed of primitive crossover testing, and reduces the overall time consumption. We compared the proposed method with the AABB-OBB method and three classic methods in the primitive intersection test to verify its superiority in terms of fit. The proposed method has the least number of pattern intersection tests and the best fit. Conclusion An AABB-circular hybrid hierarchical self-collision detection method based on deep neural network is proposed. The AABB and the round form a hybrid layer bounding box to perform self-collision detection on the cloth. The intersection of the circular bounding box is detected using a deep neural network. Compared with the classic AABB-OBB bounding box and the classic three bounding boxes, the accuracy and timeliness of the AABB-circular hybrid hierarchical bounding box with fusion deep neural network are verified from multiple indicators.

Key words

self-collision detection; hybrid bounding volume hierarchy; circular bounding volume; deep neural network(DNN); graph element intersection test

0 引言

自碰撞检测是增强变形体模拟真实感的关键,也是计算量最大的环节,提高自碰撞检测效率是虚拟仿真领域的前沿问题。最早的自碰撞检测只进行层次包围盒测试,然而,层次包围盒测试无法剔除相邻图元。针对这一问题,Volino和Thalmann(1995)提出了两个优化方法:基于曲率的测试和轮廓测试。之后的研究(Provot,1997Schvartzman等,2010Wang等,2017, 2018Wong和Cheng, 2016, 2014)大多是通过对这两个优化方法进行改进来提升自碰撞检测的效率。基于曲率的测试和轮廓测试对邻近图元有良好的剔除效果,但无法剔除由于包围盒冗余空间保留下来的非相交图元。使用紧密的包围盒可以提高剔除准确率,但测试和更新计算会变复杂,反而增加了渲染耗时(Wang等,2018)。

混合层次包围盒将多种包围盒结合在一起,解决贴合性和整体耗时导致的速度瓶颈,使碰撞检测的精度更高、速度更快(Liu等,2017)。随着图元数量的增加,混合层次包围盒的效率明显提升(孙敬荣和卢新明,2018Wang等,2018刘超,2018)。然而,在混合层次包围盒遍历过程中,存在影响算法效率的复杂计算。

机器学习方法擅长逼近复杂计算过程(Schmidhuber,2015Mammadli等,2019),大量研究将机器学习方法应用到变形体模拟中来改进算法效率。Oh等人(2018)提出了一种将传统的基于物理的仿真方法与深度神经网络相结合的布料仿真方法。石敏等人(2017)通过机器学习模型,建立了人体运动与服装变形之间的关系。Chen等人(2018)提出了一种基于深度学习的网格超分辨率方法,用来丰富低分辨率织物的褶皱网格。

针对上述问题,本文提出融合深度神经网络的AABB(Aixe align bounding box)—圆形包围盒方法。首先,采用AABB剔除不相交的图元;其次,采用圆形包围盒再次剔除不相交的图元,减少图元相交测试次数。最后,采用深度神经网络优化圆形包围盒的相交检测复杂度,提升检测速度。

1 本文方法

在自碰撞检测中,诸如AABB、Sphere与$k$-DOP(discrete orientation polytopes)等包围盒在三角形的法向矢量方向上会产生冗余空间,导致BVTT(bounding volume test tree)树的叶子节点的剔除率降低。针对这一问题,本文提出了一种融合深度神经网络的AABB-圆形包围盒方法。提升BVTT在叶子节点的剔除率,降低图元相交测试次数,提升自碰撞检测的整体速度。具体步骤如下:

1) 对变形体构建AABB—圆形包围盒;

2) 根据AABB—圆形包围盒构建BVTT;

3) 基于深度神经网络优化BVTT树进行包围盒测试和法向锥测试,输出三角形碰撞对。

2 AABB—圆形包围盒

2.1 一种无厚度的新型包围盒

法向锥测试后,需要使用经典包围盒对候选集进行二次剔除。由于经典包围盒在图元的法向量的方向上具有厚度,导致三角形对的剔除效率低。针对以上问题,本文提出没有厚度的圆形包围盒。圆形包围盒与三角形面片处于同一个平面上,并且三角形面片处于圆形包围盒内部,如图 1所示。

图 1 圆形包围盒的俯视效果图
Fig. 1 Circular bounding box from top view

圆形包围盒的参数定义如下:

1) 圆心坐标$ \boldsymbol{C}$。将三角形的质心作为圆形的圆心。具体为

$ \mathit{\boldsymbol{C}} = \frac{1}{3}(\sum\limits_{i = 1}^3 {p_x^i} ,\sum\limits_{i = 1}^3 {p_y^i} ,\sum\limits_{i = 1}^3 {p_z^i} ) $ (1)

式中,三角形顶点坐标$ \boldsymbol{P}^{i}=(p^{i}_{x}, p^{i}_{y}, p^{i}_{z}), i=1, 2, 3$

2) 半径$r$。选用圆心到顶点距离的最大值,即

$ r = {\rm{max}}\{ |\mathit{\boldsymbol{C}} - {\mathit{\boldsymbol{P}}^1}|,|\mathit{\boldsymbol{C}} - {\mathit{\boldsymbol{P}}^2}|,|\mathit{\boldsymbol{C}} - {\mathit{\boldsymbol{P}}^3}|\} $ (2)

3) 法向矢量$ \boldsymbol{n}$。圆形法向矢量即三角形的法向矢量,即

$ \mathit{\boldsymbol{n}} = \frac{{({\mathit{\boldsymbol{P}}^1} - {\mathit{\boldsymbol{P}}^2}) \times ({\mathit{\boldsymbol{P}}^1} - {\mathit{\boldsymbol{P}}^3})}}{{|({\mathit{\boldsymbol{P}}^1} - {\mathit{\boldsymbol{P}}^2}) \times ({\mathit{\boldsymbol{P}}^1} - {\mathit{\boldsymbol{P}}^3})|}} $ (3)

2.2 构建AABB-圆形包围盒

由于AABB对图元的贴合性差,而圆形包围盒对图元贴合性好,使得检测、更新速度快,相交检测计算、更新计算简便,所以本文提出AABB与圆形包围盒混合的层次包围盒。对叶子节点构建圆形包围盒,对根节点以及内部节点构建AABB包围盒,如图 2所示,正方形代表AABB,圆形代表圆形包围盒。

图 2 AABB—圆形包围盒
Fig. 2 AABB-circular bounding box

3 AABB—圆形包围盒的相交测试

3.1 AABB与圆形包围盒的相交测试算法

AABB与圆形包围盒的相交测试算法的具体步骤如下:

输入:圆形和AABB的参数。

输出:两个包围盒相交状态。

1) 判断圆心$ \boldsymbol{C}$是否在AABB内,若在,则返回“相交”,结束算法;若不在,执行步骤2);

2) 计算圆形所在平面$\boldsymbol{\pi }_{c}: \boldsymbol{n}_{c}×X=d_{c}$与AABB其中一个矩形所在平面$\boldsymbol{\pi }_{r}: \boldsymbol{n}_{r}×X=d_{r}$的交线$L$,检测$ \boldsymbol{C}$$L$的距离$l_{C-L}$是否大于$r$,若是,执行步骤3)。其中,$ \boldsymbol{n}_{c}$$\boldsymbol{n}_{r}$分别为平面$\boldsymbol{\pi }_{c}$$\boldsymbol{\pi }_{r}$的法向量。否则,执行步骤4)。交线$L$和距离$l_{C-L}$的计算公式为

$ {L = ({d_c}{\mathit{\boldsymbol{n}}_r} - {d_r}{\mathit{\boldsymbol{n}}_c}) \times \mathit{\boldsymbol{d}}/(\mathit{\boldsymbol{d}} \cdot \mathit{\boldsymbol{d}}) + t\mathit{\boldsymbol{d}}} $ (4)

$ {{l_{C - L}} = \frac{{(\mathit{\boldsymbol{C}} - ({d_c}{\mathit{\boldsymbol{n}}_r} - {d_r}{\mathit{\boldsymbol{n}}_c}) \times \mathit{\boldsymbol{d}}/(\mathit{\boldsymbol{d}} \cdot \mathit{\boldsymbol{d}})) \times \mathit{\boldsymbol{d}}}}{{|\mathit{\boldsymbol{d}}|}}} $ (5)

式中,$\boldsymbol{d}=\boldsymbol{n}_{c}×\boldsymbol{n}_{r}$, 表示$\boldsymbol{n}_{c}$$\boldsymbol{n}_{r}$的叉积。

3) 计算圆形所在平面$\boldsymbol{\pi }_{c}$与下一个AABB矩形面所在平面$\boldsymbol{\pi }_{r+1}$的交线$L$,执行步骤2),直到检测完AABB的6个面,返回“未相交”,结束算法;

4) 计算$L$是否与对应矩形的四条边发生相交,若与任意边发生相交,返回“相交”,结束算法;否则,返回步骤3)。

3.2 基于几何的圆形包围盒之间相交测试算法

基于几何的圆形包围盒之间相交测试算法的具体步骤如下:

输入:两个圆形的圆心位置坐标$\boldsymbol{C}_{1}$$\boldsymbol{C}_{2}$及法向量$\boldsymbol{n}_{1}$$\boldsymbol{n}_{2}$

输出:两个圆形相交状态。

1) 通过$\boldsymbol{C}_{1}$$\boldsymbol{C}_{2}$求向量$ \boldsymbol{m}$,计算$\boldsymbol{n}_{1}$$\boldsymbol{n}_{2}$之间的点积$a$,以及$ \boldsymbol{m}$$\boldsymbol{n}_{1}$之间的点积$b$,具体为

$ {\mathit{\boldsymbol{m}} = {\mathit{\boldsymbol{C}}_1} - {\mathit{\boldsymbol{C}}_2}} $ (6)

$ {a = {\mathit{\boldsymbol{n}}_1} \cdot {\mathit{\boldsymbol{n}}_2}} $ (7)

$ {b = \mathit{\boldsymbol{m}} \cdot {\mathit{\boldsymbol{n}}_1}} $ (8)

2) 当$a=1$$-1$并且$b=0$时,$|\boldsymbol{m}|$大于两圆形的半径之和,退出测试,返回“不相交”;否则,退出测试,并返回“相交”。当$a=-1$$1$$b=0$,退出测试,并返回“不相交”。当$a=-1$$1$时,执行步骤3);

3) 假设两个圆形所在平面分别为$\boldsymbol{\pi }_{1}:\boldsymbol{n}_{1}×X=d_{1}$$\boldsymbol{\pi }_{2}:\boldsymbol{n}_{2}×X=d_{2}$。根据式(4)和式(5),求两个圆形所在平面的交线$L$和圆心$\boldsymbol{C}_{1}$$\boldsymbol{C}_{2}$$L$的距离$l_{1}$$l_{2}$,若$l_{1} < r_{2}$$l_{2} < r_{2}$,退出测试,返回“相交”;否则,退出测试,返回“不相交”。

圆形包围盒之间的相交测试流程如图 3所示,基于几何的圆形包围盒相交测试俯视效果如图 4所示,图中$\boldsymbol{\pi }_{1}$$\boldsymbol{\pi }_{2}$分别为两个圆形所在平面,$L$为两平面的交线。

图 3 基于几何的圆形包围盒相交测试流程图
Fig. 3 Flow chart of intersection test of geometry-based circular bounding box
图 4 基于几何的圆形包围盒相交测试俯视效果图
Fig. 4 Top view rendering of intersection test of geometry-based circular bounding box

3.3 基于深度神经网络的圆形包围盒相交测试

两个圆形的姿态保持不变,圆形CB1沿向量$ \boldsymbol{m}$的反方向平移,当$| \boldsymbol{m}|$距离小于阈值$δ$时,两个圆形发生相交。图 5为两个圆形在它们的法向量构成的平面上投影的侧视效果图,图中CB1和CB2分别为两个圆形的投影,CB1′为CB1平移后的投影,CB1与CB2没有发生相交,CB1′与CB2发生了相交。

图 5 圆心距离对圆形相交的影响
Fig. 5 The influence of the distance from the center of a circle on the intersection of circles

两个圆形的圆心距离不变,它们夹角越大,阈值$δ$越小。图 6为两个圆形在它们的法向量构成的平面上的投影的侧视效果图,图中CB1和CB2分别为两个圆形的投影,CB1′为CB1绕圆心反转一定角度后的投影,CB1与CB2没有发生相交,CB1′与CB2发生了相交。

图 6 夹角对圆形相交的影响
Fig. 6 The influence of angle on circle intersection

为了保持圆心之间的距离和圆形之间的夹角不变,移动圆形CB1,阈值$δ$也会随之发生变化,这一影响因素称为圆形之间的“相对方位”。图 7为两个圆形在它们的法向量构成的平面上投影的侧视效果图,图中CB1和CB2分别为两个圆形的投影,CB1′为CB1保持圆心距离和夹角不变情况下平移后的位置,即“相对方位”发生了变化,CB1与CB2没有发生相交,CB1′与CB2发生了相交。

图 7 “相对方位”对圆形相交的影响
Fig. 7 The influence of "relative orientation" on the intersection of circles

由上述可知,圆形的圆心距离、夹角以及相对方位都影响着两个圆形是否相交。本文用圆形的圆心距离向量的模长$|\boldsymbol{m}|$、两个圆形的法向量点积$a$$ \boldsymbol{m}$的单位矢量和圆形法向矢量的点积$s$分别表示圆形的圆心距离、夹角以及相对方位。

1) 圆形的圆心距离向量的模长$|\boldsymbol{m}|$,计算为

$ |\mathit{\boldsymbol{m}}| = \sqrt {m_x^2 + m_y^2 + m_z^2} $ (9)

式中,$\boldsymbol{m}=(m_{x}, m_{y}, m_{z})$

2) 两个圆形的法向量点积$a$,计算为

$ a = {\mathit{\boldsymbol{n}}_1} \cdot {\mathit{\boldsymbol{n}}_2} $ (10)

$a$越大,两个圆形的夹角越小。因为$\boldsymbol{n}_{1}$$\boldsymbol{n}_{2}$均为单位向量,且两个圆形之间的夹角$α∈[0, \mathsf{π}]$,所以$a∈[-1, 1]$

3)$ \boldsymbol{m}$的单位矢量和圆形法向矢量的点积$s$,计算为

$ s = \frac{\mathit{\boldsymbol{m}}}{{|\mathit{\boldsymbol{m}}|}} \cdot {\mathit{\boldsymbol{n}}_1} $ (11)

式中,$ \frac{{\boldsymbol{m}}}{{|\boldsymbol{m}|}}$为单位矢量,$s∈[-1, 1]$

$a$$s$的变化影响阈值$δ$的大小。保持$s$不变,$a$越大,则$δ$越大;保持$a$不变,当$s∈\{-1, 0, 1\}$时,$δ$达到最小值。而$|\boldsymbol{m}|$$δ$之间的大小关系决定圆形是否相交。由于深度神经网络具有拟合任意函数的特性,本文建立深度神经网络,如图 8所示。

图 8 本文建立的深度神经网络
Fig. 8 Our deep neural network

$a$, $s$$|\boldsymbol{m}|$作为输入量;在输出层求$|\boldsymbol{m}|$和最后一个隐含层输出值之和的差值$h_{f}$,具体为

$ {h_f} = o(|\mathit{\boldsymbol{m}}| - \sum\limits_{j = 1}^{{j_{{\rm{max}}}}} {a_j^{{l_{{\rm{max}}}}}} ) $ (12)

若输出层的函数$o(·)$为tanh函数,则

$ o(z) = \frac{{{{\rm{e}}^z} - {{\rm{e}}^{ - z}}}}{{{{\rm{e}}^z} + {{\rm{e}}^{ - z}}}} $ (13)

由于该模型主要解决在0处的分类问题,所以对于tanh函数,当$z$值很大或者很小时产生的梯度消失问题并不会影响训练结果。

深度神经网络圆形包围盒相交测试过程如下:

1) 深度神经网络训练阶段。首先,对提取的数据进行预处理,将发生相交的圆形标记为-1,未发生相交的圆形标记为1;其次,对各层进行全连接。输入层有3个神经元,依次对应特征值$a$, $s$, $|\boldsymbol{m}|$,输出层的结果为$h_{f}$,隐含层数和每层隐含层中神经元数量分别预设为3和5。隐含层中激活函数选用PReLU函数,具体为

$ \sigma (x) = {\rm{max}}(ax,x),a \in [0,1] $ (14)

隐含层之间利用上层输出计算下层输入,具体为

$ {{z^{l + 1}} = {\mathit{\boldsymbol{W}}^l}{a^l} + {\mathit{\boldsymbol{b}}^l}} $ (15)

$ {{a^{l + 1}} = \sigma ({z^{l + 1}})} $ (16)

式中,$z^{l+1}$$l$层输出值的加权和,$\boldsymbol{W}^{l}$$l$层到$l+1$层的权重矩阵,$\boldsymbol{b}^{l}$$l$层的偏置向量,$σ(·)$为隐含层的激活函数。

输出层接受最后一层隐含层的值后,利用输出函数输出结果,具体为

$ {h_f} = o(a_j^{{l_{{\rm{max}}}}}) $ (17)

式中,$o(·)$为输出层函数,$a^{l_{\max}}_{j}$为输出层接受的输入值。

输出结果的好坏通过损失函数来判断。本文通过深度神经网络对圆形之间是否发生相交作出判断,即解决二分类问题,所以采用交叉熵函数作为损失函数,计算预测值和标签值之间的距离,具体为

$ \begin{array}{*{20}{c}} {J(\mathit{\boldsymbol{W}},\mathit{\boldsymbol{b}}) = }\\ { - \left[ {\frac{1}{m}\sum\limits_{i = 1} { m } ({y^{(i)}}{\rm{log}}{\kern 1pt} {\kern 1pt} {o^{(i)}} + (1 - {y^{(i)}}){\rm{log}}(1 - {o^{(i)}}))} \right]} \end{array} $ (18)

式中,$J(\boldsymbol{W}, \boldsymbol{b})$为交叉熵,$m$为数据容量,$y^{(i)}$为标签值,$o^{(i)}$为标签值$y^{(i)}$对应的概率。

根据损失函数计算预测值与真实值之间的距离,通过反向传播算法对模型中的权重进行调整,直到输出满足要求,计算为

$ ({\mathit{\boldsymbol{W}}^l},{\mathit{\boldsymbol{b}}^l}) \leftarrow ({\mathit{\boldsymbol{W}}^l},{\mathit{\boldsymbol{b}}^l}) - \lambda \frac{{\partial J(\mathit{\boldsymbol{W}},\mathit{\boldsymbol{b}})}}{{\partial ({\mathit{\boldsymbol{W}}^l},{\mathit{\boldsymbol{b}}^l})}} $ (19)

式中,$λ$为学习率。

2) 实时模拟阶段。在自碰撞检测过程中,通过式(9)—(11)计算候选集中每组潜在碰撞对的$a$, $s$, $|\boldsymbol{m}|$,输入到模型中;由式(12)得到结果$h_{f}$,若$h_{f}≥0$,两个圆形没有相交,反之则相交。

基于深度神经网络的圆形包围盒相交检测流程如图 9所示。

图 9 基于深度神经网络的圆形包围盒相交测试流程
Fig. 9 Flow chart of the intersection of circular bounding boxes based on deep neural network

3.4 圆形与三角形之间相交测试的替代方案

由于三角形与圆形之间的相交检测剔除效果不如三角形之间的相交检测,但计算复杂度相似,而且圆形内仅包含单个三角形,所以,当圆形之间发生相交后,对相应三角形进行相交测试,而不检测圆形与三角形之间是否相交。

4 布料仿真实验及对比分析

4.1 优化深度神经网络隐含层数和每层的节点数

为了在保持算法的剔除率基本不变的情况下满足实时性的要求,优化深度神经网络的隐藏层数和每层节点数。首先测试不同隐含层数对准确率和计算效率的影响,如图 10所示,图中的测试率和计算耗时是对10组样本集进行测试后取平均值的结果,每个隐含层的节点个数为5。可以看出,准确率和测试耗时都随着隐含层数的增加而增加,但准确率的增长率逐渐降低,测试耗时的增长率逐渐增高,为满足实时自碰撞检测的要求,需要将测试耗时限制在30 ms内,当隐含层数为5时,耗时首次超过30 ms,当隐含层数为4时,准确率曲线开始趋于平缓,所以将4作为最优隐含层数。

图 10 隐含层数对测试准确率和计算耗时的影响
Fig. 10 The influence of the number of hidden layers on test accuracy and calculation time

通过改变每层节点数(悬垂布料),比较对应的准确率和计算耗时,得出每个隐含层中的最优节点数,如图 11所示。可以看出,当每层节点数增加,准确率与测试耗时逐渐升高,与选取最佳隐含层数标准一样,当每层节点数达到7时,测试耗时首次超过30 ms。因此,本文将6作为每个隐含层最佳节点数。

图 11 隐含层节点数对准确率和计算耗时的影响
Fig. 11 The influence of the number of hidden layer nodes on the accuracy and calculation time

4.2 AABB-圆形包围盒与AABB-OBB、经典包围盒层次结构模拟耗时比较

实验在3个场景下进行,如图 12所示。1)悬垂布料, 布料固定左上角,自然下垂;2)从实体间下落, 布料从两个胶囊体间的空隙滑落至地面;3)布料与小球碰撞,布料垂直下落在小球上。

图 12 3个场景的实验截图
Fig. 12 Experimental screenshot of three scenes ((a) overhanging cloth; (b) falling from the entity; (c) cloth colliding with the ball)

为了阐述本文方法的时效性,与AABB-OBB、Sphere-tree、OBB、10-DOP方法进行比较,分别对3个场景中的模拟耗时及耗时缩减率进行实验,结果如表 1表 2所示。

表 1 3个场景的模拟耗时
Table 1 Simulation time consumption of three scenes  

下载CSV
/s
方法 场景
悬垂布料 从实体间下落 布与小球碰撞
AABB-OBB 9.08 4.75 6.56
Sphere-tree 9.23 4.81 6.75
OBB 9.37 4.92 6.83
10-DOP 9.55 4.98 6.92
本文(未融合DNN) 7.39 4.13 5.97
本文(融合DNN) 6.05 3.54 5.28
注:加粗字体为各列最优结果。

表 2 本文方法耗时缩减率
Table 2 Time-consuming reduction rate of the method

下载CSV
方法 场景
悬垂布料 从实体间下落 布与小球碰撞
AABB-OBB 0.33 0.25 0.19
Sphere-tree 0.34 0.26 0.22
OBB 0.35 0.28 0.23
10-DOP 0.37 0.29 0.24
本文(未融合DNN) 0.18 0.14 0.11
注:加粗字体为各列最优结果。

耗时缩减率计算为

$ \eta = \frac{{{T_{{\rm{com}}}} - {T_{{\rm{our}}}}}}{{{T_{{\rm{com}}}}}} $ (20)

式中,$η$为耗时缩减率,$T_{\rm com}$为对比方法耗时,$T_{\rm our}$为本文方法耗时。

表 1可以看出,在3个场景中,本文方法耗时比其他4种方法少,并且融合DNN方法比未融合DNN方法耗时少,说明本文方法更具有高效性。

表 2可以看出,由于AABB-OBB方法是混合层次结构,在速度上优于Sphere-tree、OBB和10-DOP方法,而本文算法作为一种融合DNN的改进混合层次结构,耗时比AABB-OBB缩减了19%~33%,比本文未融合DNN的方法(即3.2节基于几何的圆形包围盒相交检测方法)耗时缩减11%~18%(表 2最后一行数据),说明本文方法更适合布料的实时模拟。

为了验证本文方法的计算复杂度,以悬垂的布料为基准,比较了6种方法在每帧的测试耗时,结果如图 13所示。由图 13可以看出,在模拟开始阶段,没有发生自碰撞时,6种方法的自碰撞检测耗时没有太大区别,当抽样帧数为第5帧时,布料发生了自碰撞,本文方法的每帧计算耗时明显低于其他方法,并且,本文融合DNN的方法(图 13中浅蓝色折线)每帧计算耗时低于本文未融合DNN的方法(图 13中红色折线),说明本文方法在频繁发生自碰撞的场景中,计算更具简便性,计算速度更快。

图 13 悬垂布料场景时自碰撞检测抽取连续帧耗时变化
Fig. 13 The time of continuous frame extraction from collision detection in draping scene varies

为了表明本文方法在包围盒的贴合性以及相交检测方面的优势,以悬垂布料为基准进行实验,比较了6种方法的更新率、检测效率和图元测试时间,实验结果如图 14所示。

图 14 悬垂布料场景6种算法的更新率、检测效率和图元测试时间
Fig. 14 Update rate, detection efficiency and graph testing time of the 6 algorithms are analyzed in the drape cloth scene

图 14可以看出,AABB-OBB方法的更新耗时比Sphere-tree方法多,比OBB和10-DOP方法少;图元相交测试耗时低于Sphere-tree、OBB和10-DOP方法。本文方法的更新耗时低于AABB-OBB方法,图元相交测试耗时更少,总耗时比AABB-OBB方法缩减了19%。在检测耗时上,本文方法融合DNN比未融合DNN时缩减了17%。

4.3 AABB-圆形包围盒与AABB-OBB、经典包围盒层次结构模拟剔除率比较

剔除率计算为

$ {r_{{\rm{ cull }}}} = 1 - \frac{{{n_{{\rm{ pot }}}}}}{{{n_{{\rm{ pri }}}}}} $ (21)

式中,$r_{\rm cull}$为剔除率,$n_{\rm pot}$为经过包围盒层次结构剔除后剩下的有发生碰撞可能的图元对数量,$n_{\rm pri}$为图元对总数量。贴合性好的包围盒剔除率高。

因为3个场景中布料的三角形面片数量相同,根据式(21),只需要比较$n_{\rm pot}$即可知道各种方法贴合性的优劣。由于经过层次包围盒结构剔除剩下的潜在碰撞图元对必然经过图元相交测试,因此通过统计图元相交测试的次数即可知道$n_{\rm pot}$的大小。从3个场景中各抽取1个关键帧,统计同一关键帧下6种方法的图元相交测试的次数,结果如表 3所示。可以看出,3种场景下本文方法的图元相交测试次数最少,因此间接论证了本文方法在贴合性方面的优越性。

表 3 3个场景下6种方法的图元相交测试的次数
Table 3 The graph intersection test times of 6 methods in 3 scenarios

下载CSV
方法 场景
悬垂布料 从实体间下落 布与小球碰撞
AABB-OBB 1 424 64 162
Sphere-tree 1 702 72 195
OBB 1 424 64 162
10-DOP 974 45 112
本文(未融合DNN) 873 43 104
本文(融合DNN) 873 43 104

5 结论

针对包围盒冗余空间导致自碰撞检测速率低的问题,本文提出了AABB-圆形包围盒方法的自碰撞检测算法。通过利用AABB-圆形包围盒快速剔除不碰撞的图元对,然后利用圆形良好的紧密性,大量剔除潜在碰撞集中的图元对,减少图元相交测试计算量。通过使用深度神经网络对圆形包围盒进行相交检测,加速了圆形包围盒之间的相交检测速度。与3种经典的包围盒及AABB-OBB混合包围盒进行对比,从多项评价指标上验证了融合深度神经网络的AABB-圆形包围盒方法的可行性与有效性。在未来的工作中,可以尝试对AABB包围盒构建神经网络模型来进一步提升算法效率。

参考文献

  • Chen L, Ye J T, Jiang L G, Ma C C, Cheng Z L, Zhang X P. 2018. Synthesizing cloth wrinkles by CNN-based geometry image superresolution. Computer Animation and Virtual Worlds, 29: 3-4 [DOI:10.1002/cav.1810]
  • Liu C. 2018. Research and Implementation of Collision Detection Algorithm in Virtual Environment. Nanjing: Nanjing University of Aeronautics and Astronautics (刘超. 2018. 虚拟环境中碰撞检测算法的研究和实现. 南京: 南京航空航天大学)
  • Liu Y C, Wang H X and Yang P. 2017. A three-layer hybrid bounding volume hierarchy for collision detection//Proceedings of the 7th International Conference on Computer Engineering and Networks. Shanghai: SISSA Medialab: 73-81[DOI: 10.22323/1.299.0053]
  • Mammadli R, Wolf F, Jannesari A. 2019. The art of getting deep neural networks in shape. ACM Transactions on Architecture and Code Optimization, 15(4): #62 [DOI:10.1145/3291053]
  • Oh Y J, Lee T M and Lee I K. 2018. Hierarchical cloth simulation using deep neural networks//Proceedings of Computer Graphics International 2018. Bintan Island Indonesia: ACM: 139-146[DOI: 10.1145/3208159.3208162]
  • Provot X. 1997. Collision and self-collision handling in cloth model dedicated to design garments//Proceedings of Eurographics Workshop in Budapest Computer Animation and Simulation'97. Hungary: Springer: 177-189[DOI: 10.1007/978-3-7091-6874-5_13]
  • Schmidhuber J. 2015. Deep learning in neural networks:an overview. Neural Networks, 61: 85-117 [DOI:10.1016/j.neunet.2014.09.003]
  • Schvartzman S C, Pérez A G and Otaduy M A. 2010. Star-contours for efficient hierarchical self-collision detection//Proceedings of SIGGRAPH'10: ACM SIGGRAPH. Los Angeles: ACM: #80[DOI: 10.1145/1833349.1778817]
  • Shi M, Yang L, Mao T L, Deng Y W, Wang S Q. 2017. Study on the correlation between human motion and garment deformation in cloth animation. Journal of Computer-Aided Design and Computer Graphics, 29(10): 1941-1951 (石敏, 杨柳, 毛天露, 邓一文, 王素琴. 2017. 服装动画中人体运动与服装变形的相关性学习. 计算机辅助设计与图形学学报, 29(10): 1941-1951) [DOI:10.3969/j.issn.1003-9775.2017.10.021]
  • Sun J R, Lu X M. 2018. Optimized collision detection algorithm based on hybrid bounding box and intersection of triangles. Compu-ter Engineering and Applications, 54(19): 198-203 (孙敬荣, 卢新明. 2018. 基于混合包围盒与三角形相交的碰撞检测优化算法. 计算机工程与应用, 54(19): 198-203) [DOI:10.3778/j.issn.1002-8331.1803-0262]
  • Volino P and Thalmann N M. 1995. Collision and self-collision detection: efficient and robust solutions for highly deformable Surfaces//Proceedings of the Eurographics Workshop in Maastricht Computer Animation and Simulation'95. The Netherlands: Springer: 55-65[DOI: 10.1007/978-3-7091-9435-5_5]
  • Wang C, Zhang Z L, Long Y, Wang S D. 2018. Improved hybrid bounding box collision detection algorithm. Journal of System Simulation, 30(11): 4236-4243 (王超, 张志利, 龙勇, 王韶迪. 2018. 改进的混合包围盒碰撞检测算法研究. 系统仿真学报, 30(11): 4236-4243) [DOI:10.16182/j.issn1004731x.joss.201811023]
  • Wang T T, Liu Z H, Tang M, Tong R F, Manocha D. 2017. Efficient and reliable self-collision culling using unprojected normal cones. Computer Graphics Forum, 36(8): 487-498 [DOI:10.1111/cgf.13095]
  • Wang T T, Tang M, Wang Z D, Tong R F. 2018. Accurate self-collision detection using enhanced dual-cone method. Computers and Graphics, 73: 70-79 [DOI:10.1016/j.cag.2018.04.001]
  • Wong S K, Cheng Y C. 2014. Continuous self-collision detection for deformable surfaces interacting with solid models. Computer Graphics Forum, 33(6): 143-153 [DOI:10.1111/cgf.12284]
  • Wong S K, Cheng Y C. 2016. GPU-based radial view-based culling for continuous self-collision detection of deformable surfaces. The Visual Computer, 32(1): 67-81 [DOI:10.1007/s00371-014-1056-9]