Image-assisted collision detection for calculation of an assembly interference matrix

The assembly interference matrix is a foundational information model for assembly process planning such as assembly sequence and assembly path planning, and supports digital assembly simulation, intelligent assembly, digital twin-based assembly, and so on. The assembly interference matrix represents two parts which are collision or not when they move along specific directions. Traditional assembly interference matrix construction adopts geometric collision detection on the approximate swept volume of parts which are composed by moving step by step. This not only leads to a heavy computational load because of the small moving steps but it is also easy to misjudge the contact as collision as well as missing collision due to discrete spatial movement of the part. To overcome these drawbacks, this work equivalent the collision detection of parts during the establishment of the assembly interference matrix as visibility judgment, and develops an image-assisted calculation method to process the collision between the part’s swept volume as the occlusion of images via computer graphics rendering. This method is implemented on OpenGL to ensure its generalizability, and the implicit calculation is completed in a computer graphics rendering process by setting proper rendering conditions by adopting depth testing and stencil testing. Furthermore, the erosion operation of the image process is employed to distinguish whether contact or collision. Lastly, an example for a gear box assembly confirms the effectiveness of this method.


Introduction
As the last step of product manufacturing, the assembly process has significant effects on product performance and quality [1]. Assembly sequence planning is the basis for implementing the assembly process. According to the assembly sequence of parts and components, specifying reasonable inspection, process operations, assembly fix and material are the foundation to obtain high assembly efficiency and guarantee assembly quality [2,3]. As a powerful digital technology, virtual assembly is capable of validating the accessibility and evaluating the performance of the assembly process in the early assembly design stage, ensuring the feasibility of the assembly sequence by simulating the assembly process with collision detection, which helps to avoid assembly interference due to assembly process errors and shortens the assembly process design [4].
The interference matrix is an important information model for assembly sequence planning that works via a relationship matrix. It represents the relative spatial position between parts, which is an important basis for determining the feasibility for parts assembly [5]. Normally, the interference matrix indicates whether or not interference is present for each part moving out of the whole assembly room along the positive/ negative directions of three coordinate frame axes with the other parts. For interference matrix A D in direction D, element A D [i,j] stores the interference result for the moving part i along direction D with part j, which includes three cases, i.e., interference-free, contact, and hard-collision [6].
Identifying the interference element values is normally undertaken by adopting the classic triangle-based rigid object collision detection method. The object part moves stepwise with specific step length, and collision detection is performed for each position between the object part and the opposite part to determine whether any interference occurred. However, it is inefficient, particularly in the case of numerous parts with complex geometry, since the detection of collisions leads to heavy computational load and huge memory and time requirements. It is also critical to accurately distinguish interference and contact for establishing an interference matrix since contact commonly occurs in mechanical parts assembly such as shaft-hole and panel alignment, which increases the computational difficulty for collision detection algorithms and heavier computational load.
Actually, the establishment of the interference matrix is met by only checking whether or not interference occurs for the object part moving linearly with respect to the opposite part. Therefore, efforts have been made to improve the computation efficiency by dimension-reduction in view of the image-space where the swept volume of the object part is represented by the projection area of view volume for the object part along the moving direction. Additionally, with the performance enhancement of the graphics processing unit (GPU), image-based collision detection methods achieve excellent performance by utilizing the powerful parallel computation capability of the GPU to accelerate task calculation [7]. As two of the most common methods, the classic RECODE [8] and CULLIDE [9] algorithms employ a depth buffer, stencil buffer, and occlusion query in the image space to perform collision detection computation. On this basis, according to the dimension reduction ideology, Zhou et al. [10] proposed a fast collision detection method based on the Z-buffer, which is capable of producing a realtime collision report for the first person roaming in a virtual scene by providing the spatial coordinate values of specific pixels to perform collision detection. To deal with the collision detection during kinematic simulation of mechanical systems, Sun et al. [11] developed a dual-view and semitransparent color overlap collision detection algorithm, which transforms the problem into panel pixel judgment by projection-based dimension reduction, making it possible to meet the real-time requirement during virtual assembly simulation. With respect to the characteristic of stream computation for the GPU, Liu et al. [12] presented a collision detection method that combined both model space and image space for the purpose of employing accelerated GPU parallel computing without loss of the real-time capability and accuracy of the algorithm. Kim et al. [13] developed a hybrid parallel continuous collision detection (HPCCD) to achieve significant improvement in efficiency by utilizing the computation capability of both the GPU and many-CPU. These methods have shown that image-based collision detection provides extraordinary efficiency improvement by reducing the dimensions of the mathematical model for the collision detection task. However, establishing the interference matrix for complex mechanical systems by directly adopting imagebased collision detection algorithms is still subject to computationally heavy tasks, resulting in low efficiency.
To overcome this drawback, a collision detection algorithm combining geometry space and image space is developed with respect to the special requirement of collision detection for interference matrix element establishment. It identifies the obvious interference-free element by a spatial boundary box based on conservatism in a rough stage, and performs precise interference checking by a delicate algorithm, adopting Z-buffer and stencil buffer through OpenGL. Finally, it not only reaches high computational efficiency but also is capable of reporting interference and contact cases for assembly interference matrix establishment. The remainder of this article is organized as follows: Section 2 presents the rough stage of the interference matrix calculation by the boundary box. The complete image-based collision detection algorithm performed by OpenGL, including both the calculation principle and concrete algorithms, is described in Section 3. In Section 4, examples are provided and discussed, and finally, the paper is concluded.

Rough stage for interference matrix establishment
The identification of the presence of interference for each part along six directions with other parts is the basic operation to establish the interference matrix. The nonoverlap between parts of the assembly indicates that most of the parts are free of interference with each other in their separate directions. Therefore, taking a simple but robust method to firstly identify these non-interference elements is a significant strategy to improve the computational efficiency of the interference matrix, since the detailed interference checking is only performed with the remaining elements [14,15].
As an easy-to-obtain geometric structure, the axis-aligned bounding box (AABB) expresses the coordinate ranges of all the geometric elements of parts in a specific coordinate frame UVW. As shown in Fig. 1, it facilities the identification of non-interference for moving part i relative to part j along direction D ∈ {+ U, -U, + V, -V, + W, -W}, as follows: (i) if condition D i,min > D j,max is satisfied, interferencefree conditions in +D and the other directions except −D are met since it indicates that part i is completely on the +D side of part j; (ii) similarly, condition D i,max < D j,min reports interference-free conditions in −D and the other directions except +D because part i is completely located in the -D side of part j.
On this basis, delicate collision detections are evoked for the remaining elements which have the possibility of noninterference. Meanwhile, considering the relative movement between parts, only the upright elements of the interference matrix are calculated. The complete calculation schema is shown in Fig. 2.

Image-assisted collision detection for interference matrix element identification
With regard to the special collision detection requirement of the interference matrix, the image-assisted interference checking method is detailed in principle and implementation procedure as well as distinguishing contact.

Principle of image-assisted collision detection
The element M D , i , j of the interference matrix indicates whether the swept volume of part i along direction D is interference to part j. In view of computer graphics rendering, this kind of swept volume can be expressed as the occlusion room with the help of the Z-buffer when taking the view as direction D and the depthtest strategy as greater than through [15]. As demonstrated in Fig. 3, the spatial line segments of corresponding pixels from z far (1.0) to their minimum value consist of the part swept volume once taking orthogonal projection mode. Obviously, the rendering of part i instead of the traditional discrete part swept volume by a serial of part solid along a moving path.
On this basis, when the depth-test strategy is reset as smaller than passing for part j rendering, as shown in Fig. 4, (i), there is no pixel passing the depth-test if all the pixels of part j are completely on the -D side of their corresponding pixels of part i, and (ii) only the pixels corresponding to the overlap areas of the interference room between part j and the swept volume of part i pass the depth-test. Consequently, whether or not interference exists for element M D , i , j can be reported by the existing rendered pixels of part j or not, respectively.
All these calculations implicitly comply with the graphics rendering process by discrete pixels. Essentially, this kind of discretization on geometric objects produced by rasterization not only provides the ability to process complex geometry but also ensures the generalizability, robustness, and practicality of this calculation principle.

Detailed calculation model based on OpenGL
The detailed computation is performed by OpenGL because of its excellent characteristics including a cross-platform, industrial graphics programming interface. It is arranged in three stages, i.e., preparation of rendering, implicit calculation by graphics rendering, and identification of contact condition. In addition, optimization operations including face culling, stencil buffer, and occlusion testing are used to improve the computational efficiency.

Preparation of rendering
The proper preparation of the rendering environment according to the interference calculation model is the foundation for OpenGL-based calculation. It includes two sides, i.e., view direction setting and view volume setting. As shown in Fig. 5, the view direction is consistent with where C is the center of view volume, F is a point in front of view volume along D; T is a vector that points in the up direction of the view volume from C.

Procedure of OpenGL-assisted implicit calculation
The calculation principle indicates that the key for the rendering calculation is to determine whether the rendered pixels of part j pass the depth test. With respect to the functions of OpenGL, the stencil test and occlusion query are used to help accelerate this judgment. As shown in Fig. 6, the implicit calculation is arranged in six steps via OpenGL functions according to the calculation principle. The detailed process is presented as follows: gluLookAt 1×3 , 1×3, 1×3 ; glOrtho(left, right, bottom, up, near, far); Step I: Initializing Z-buffer and stencil buffer as 1.0 and 0, respectively.
Step II: Setting the judgment conditions of the depth test and stencil test for part i rendering. (i) Depth test: less than passing; (ii) Stencil test: ensuring that all pixels participate in the stencil test, and assigning a stencil value of 1 if the pixel passes the depth test.
Step III: Rendering of part i. Herein, the back faces of part i are culled since the maximum value of pixels is determined by the front faces. After rendering, the corresponding pixels of the stencil values of part i are set as 1, and the remaining ones, 0.
Step IV: Resetting the judgment conditions for the depth test and stencil test, and preparing the occlusion test for part j rendering. (i) Depth test: greater than passing; (ii) Stencil test: only the pixels with stencil value equal to 1 are used for the stencil test, and further, the stencil value is increasing 1 of the pixel passed depth test.
Step V: Rendering of part j. Similarly, the front faces are expelled because only the back faces generate the minimum depth value. In this process, only the pixels of part j that overlap part i pass the stencil test, since the stencil value of these pixels is equal to 1. Further, the occlusion query monitors the pixels that pass the depth test.
Step VI: Obtain results. It is interference-free if no pixels pass the depth test. Otherwise, the stencil buffer is extracted for further distinguishing collision or contact between part j and the swept volume of part i.

Identification of contact condition
In practical assembly, adjacent parts with positioning relationships such as shaft-hole and plane-fitting might be mistaken as interference by collision detection due to its geometric precision representation [16]. Essentially, the key to avoid this kind of error is to correctly distinguish the two parts in contact.
According to the rendering principle, it is known that if two parts are in contact, only their contact boundary geometries might pass through the depth test and stencil test. As demonstrated in Fig. 7, after rendering, the geometries are transformed as pixels by rasterization. Then, the pixels with stencil values not less than 2 are pixels that pass the depth testing corresponding to the potential collision areas with the shape of lines or curves. Furthermore, the classic image corrosion operation [17] is adopted to process the image composed stencil buffer after binary segmentation with threshold 2. As a result, it is interference-free if all the pixels are eliminated after one image corrosion operation; otherwise, collision is reported.

Case study and discussion
In order to confirm the effectiveness of this method, an example for distinguishing interference and contact for the shaft-hole is tested first, and a complete calculation for the worm gear box is performed. Through a programming algorithm developed by VS2017 C + + and OpenGL (2.0), all the computations are run on a laptop with Win10, CPU   Intel Core i7 × 12, GPU NVIDIA GeForce GTX 1050 Ti. In addition, all the part models are stored in STL format for rendering, and the viewport size is given as 800 × 800.

Example of shaft-hole assembly
The shaft-hole is a common assembly form where contact exists in practical assembly. A shaft and a bearing assembly shown in Fig. 8(a) are taken for interference checking along their axial direction as demonstrated in Fig. 8(b). According to the calculation procedure developed in this work, the stencil buffer results of step I, steps II/III, and steps IV/V are rendered as an image composed of pixels in Fig. 8(c), where blue, green, and red indicate a pixel stencil value of 0, 1, and no less than 1, respectively. Clearly, the red circle produced after steps IV/V in Fig. 7(c) indicates that the shaft and bearing take potential interference as a cylindrical surface, while no residual pixel after erosion operation for the output stencil buffer indicates that the shaft and holes are interferencefree. This example shows that this method is capable of identifying contact and interference conditions.

Example of worm gear box
The developed interference matrix calculation method based on OpenGL is performed on a worm gear box to confirm its effectiveness. As shown in Fig. 9, this assembly includes 16 parts, of which the sequence numbers are listed in an exploded diagram, most of them taking the shaft-hold assembly relationship. The right-up elements of interference matrices for six directions are listed in Fig. 10, where "0" indicates interference-free, "1" indicates contact, and "2" indicates collision. Herein, the element (i,j) is just the element of (j,i) in the opposite direction. The time-cost statistic of image-assisted calculation is investigated by implementing this task 10 times. For a single calculation, the image-assisted algorithm is called 720 times, indicating interference-free 492 times and collision 228 times, of which the average accumulated time costs are 14,287.85 and 9005.168 ms, respectively, and the average single calculation times are 28.837 and 39.496 ms, respectively.
In addition, to demonstrate the computational efficiency of this method, a time/cost comparison with the traditional collision detection-based method is carried out by adopting  The exploded diagram of the worm gear box assembly. The parts are as follows: 1-cover; 2-bearing; 3-worm shaft; 4-cover; 5-bearing; 6-gear box body; 7-bearing; 8-oil seal; 9-cover; 10-plug; 11-worm gear rim; 12-worm gear hub; 13-output shaft; 14-bearing; 15-oil seal; 16-cover the OBBTree hierarchical structure for rapid detection [18] for the second stage of the interference matrix. A step length of 0.2 mm is implemented for each part to escape the spatial range of its coupled part. Tests are carried out 10 times for the OBBTree and image-assisted methods, and average lengths of 4328 ms and 8481 ms are obtained. Even though the image-assisted method shows longer time cost, the result is still acceptable, particularly as it provides additional contact identification capability.

Discussion
Although this method can effectively identify collisions, it still has two drawbacks related to the computational principle. One is the inability to distinguish the contact for boltconnects since the overlap area of threads is not a curved shape. The other is that it might identify the contact as interference-free, which due to the contact area might be divided into non-overlap pixels during the rasterization of OpenGL. For instance, the actual contact of 5-13 (bearing on output shaft) is judged as interference-free as shown in Fig. 9. Normally, this kind of misjudgment will not disturb the correct working of the interference matrix in practical application.

Conclusions
This work developed an image-based interference collision detection algorithm for interference matrix establishment utilized for assembly process planning. The main contributions are concluded as follows.
(i) Firstly, a mathematical model of collision detection based on the visibility principle is developed for establishing an interference matrix element. Compared with the traditional geometric collision detection method in which one object is fixed, with the other object moving in small steps, the visibility of the image-assisted method ensures the completeness of the swept volume of the moving object and completes collision detection by one computation. (ii) Secondly, the complete procedure and parameter specification model of the image-assisted method is performed by OpenGL to ensure its generalizability and portability. Several skills are adopted to improve the computational efficiency, i.e., the relative spatial position calculation is performed by depth testing and a stencil test with orthogonal projection, unnecessary geometries are culled to reduce rendering loading, and an occlusion query function is involved to judge interference-free conditions by avoiding slow stencil buffer data translation.
(iii) Unlike traditional geometric collision detection, which can only identify whether interference occurs between two parts, the image-assisted method can further distinguish whether the two assembly parts are surface contact or entity collision. It is easy to complete by transforming the stencil buffer as an image and performing an erosion process with a specific threshold. (iv) The shaft-bearing assembly example confirms that the developed method can identify whether contact or collision exists for the interference case, while the assembly interference matrix establishment for the gear box demonstrates the effectiveness of this method. However, the method still suffers from drawbacks that might cause some contacts to be judged as interference-free.