**1. Introduction**

In recent years, the railway industry has developed rapidly in China. The frequency and degree of rail rolling have increased sharply, and rail-surface scratches have become more and more aggravated [1,2]. A rail-surface scratch is a common rail defect caused by the metal plastic deformation due to the friction between wheels and rails and could lead to other surface defects such as peeling and fracture, which may seriously affect the safety of the train [3,4]. Rapid recognition and online-repair of rail-surface scratches is key to ensuring rails remain in good working condition, which is of grea<sup>t</sup> importance to safety maintenance in the railway industry [5–7].

According to the provisions of the TG/GW102-2019 in China [8], the existing ways to deal with damaged rails are presented below. Grinding [9,10] and welding [11,12] are the regular maintenance methods for rails with surface scratch depths of less than 1 mm. However, the direct replacement of the damaged rail with a brand-new one is mandatory according to the provisions mentioned above when the surface scratch depth is larger than 1 mm, which is a complicated engineering undertaking with the disadvantages of long operation time, high manpower and material costs, seriously restricting the rapid progress of the railway industry.

Recently, laser cladding, as a novel metal additive manufacturing technology, has achieved marked progress [13,14], showing the capability of repairing damaged rails online [15–20] with the advantages of convenience, high quality of the repair layer and low cost compared with the traditional replacement method. However, the precondition for online rail-repair using the laser cladding technology is to acquire the complete closed mesh model of the scratch data. The existing related works focus mostly on the detection of the damaged rail surface. Min et al. [21] and Wei et al. [22] proposed a rail surface detection system based on machine vision. Jang et al. [23] Shang et al. [24] Faghih-Roohi et al. [25] and Song et al. [26] detected the rail surface damage by using the deep learning methods. In recent years, measurement methods based on 3D laser vison have become widely used for rail surface detection. Zhimin et al. [27] proposed a 3D laser profiling system for detecting the defects on rail surface which integrated a laser scanner, odometer, inertial measurement unit (IMU) and global position system (GPS). Wang et al. [28] presented a novel method based on the local a ffine invariant feature descriptor for the calibration of distorted profiles obtained by traditional rail measurement system. Cao et al. [29] proposed a defect inspection method of rail surface based on the line-structured light. Santur et al. [30] described a computer-vision based approach allowing for a fast-contactless detection of the rail surface and lateral defects such as fracture, scouring and wear with high accuracy. However, so far very few studies have reported methods for establishing a complete closed mesh model of scratch data which is the precondition of online rail-repair as mentioned above.

In this paper, a method for establishing a complete closed mesh model of the rail-surface scratch data is presented. The process of the method is shown in Figure 1.

**Figure 1.** Flowchart of the proposed method.

The main contributions of this paper are presented below:


(4) Experiments for verifying the proposed method are carried out. Experimental results show that our method performs well for the acquisition of a complete closed mesh model of the rail-surface scratch data.

The rest of this paper is organized as follows: Section 2 introduces the 3D-laser vision-based procedure for constructing the PCM. Section 3 describes the algorithm for calculating the scratch-data PCM. Section 4 presents the triangulation algorithm based on the point-cloud topology. Section 5 explains the experiments for verifying the proposed method. Section 6 discusses the experimental results. Finally, Section 7 draws the conclusions of the study.

#### **2. 3D Modeling of Rail Surface**

The principle of the 3D laser vision adopted in our paper is shown in Figure 2. The laser line moves linearly along the measured object and scans its surface, simultaneously acquiring the point cloud. The details of the procedure are described below.

**Figure 2.** The principle of 3D laser vision. (**a**) The measurement module comprising the camera and the laser; (**b**) The laser line on the measured object located on the laser plane; (**c**) The single point-cloud profile obtained by the calculation using Equations (1) and (2); (**d**) The PCM formed with a series of point-cloud profiles schemed as in (**c**).

In order to acquire the single point-cloud profile of the measured object, the calibration is first performed on the laser vision system. The camera model is given by the following equation:

$$Z\_{\mathbb{C}}\begin{bmatrix}u\\v\\1\end{bmatrix} = K \begin{bmatrix}X\_{\mathbb{C}}\\Y\_{\mathbb{C}}\\Z\_{\mathbb{C}}\end{bmatrix} \text{with } K = \begin{bmatrix}f\_{\mathbb{X}} & 0 & c\_{\mathbb{X}}\\0 & f\_{\mathbb{Y}} & c\_{\mathbb{y}}\\0 & 0 & 1\end{bmatrix} \tag{1}$$

where (*<sup>u</sup>*, *v*) is the pixel coordinates in the pixel coordinate system, and (*XC*,*YC*,*ZC*) is the 3D coordinates in the camera coordinate system (C-CS). The parameters in matrix *K* are obtained by the classical calibration method described in [32]. Distortion parameters are ignored since a distortionless camera [33] is used in this research.

Additional constraints imposed on the laser line must be considered, since Equation (1) is not su fficient for calculating the 3D coordinates. All points on the laser line are located on the laser plane as shown in Figure 2b, thus the points on the laser line in the C-CS satisfy:

$$aX\_{\mathbb{C}} + bY\_{\mathbb{C}} + cZ\_{\mathbb{C}} + d = 0 \tag{2}$$

where *a*, *b*, *c* and *d* are the parameters of the laser plane equation in the C-CS, which can be obtained by the planar target calibration method [34].

After the above calibration of the laser vision system, the 3D coordinates in the C-CS of a single point-cloud profile of the measured object (Figure 2c) can be calculated using Equations (1) and (2). A series of point-cloud profiles corresponding to camera frames can also be acquired when the measurement module comprising the camera and the laser (Figure 2a) moves from the origin of the world coordinate system at a constant speed, *v*, and samples 1 frame every *t* seconds along the X-axis of the C-CS. The 3D coordinates (*Xw*,*Yw*,*Zw*) in the world coordinate system can be converted from the ones in the C-CS as follows:

$$
\begin{bmatrix} X\_w \\ Y\_w \\ Z\_w \end{bmatrix} = \begin{bmatrix} X\_{ci} \\ Y\_{ci} \\ Z\_{ci} \end{bmatrix} + \begin{bmatrix} vti \\ 0 \\ 0 \end{bmatrix} \tag{3}
$$

where (*Xci*,*Yci*,*Zci*) is the 3D coordinates of frame *i* in the C-CS. The 3D PCM of the entire measured object is acquired after the above operations (Figure 2d).

#### **3. Calculation of the Scratch Data PCM**

The first step of acquiring the scratch-data PCM is to accurately recognize the scratch-area of the rail surface PCM, which can differentiate between the damaged and undamaged areas. In this paper, a novel algorithm for the scratch-recognition on rail surface is proposed by combining RANSAC with the geometric features of the rail profile.

According to the hot-rolled rails for railway technology standard GB2585-2007 [35], the geometry of all types of the original undamaged rail can be illustrated as Figure 3. The fixed geometry of the cross section (Figure 3a) can be extended in the direction perpendicular to itself to form the entire rail (Figure 3b).

**Figure 3.** The geometry of the undamaged rail. (**a**) The cross section of the rail; (**b**) 3D model of the rail.

As represented in Figure 4, the PCM obtained by 3D scanning of the physical rail using the procedure described in Section 2 comprises a series of equidistant point-cloud profiles. An analysis reveals that all the point-cloud profiles corresponding to the undamaged portions of the rail-surface have the same geometric features as illustrated in Figure 4a, but the ones corresponding to the damaged areas have varying shapes and no uniform geometric features as indicated in Figure 4b. Thus, the point-cloud profiles corresponding to the undamaged areas can be easily and accurately filtered out by using the above observation, resulting in the recognition of scratch-areas.

**Figure 4.** Geometric features of the rail profiles. (**a**) The point-cloud profiles of the undamaged areas with the same geometric features; (**b**) The point-cloud profiles of the damaged areas with a variety of shapes and no uniform geometric features.

The mathematical method based on the RANSAC fused with the geometric features of the rail for filtering out the point-cloud profiles on undamaged areas is described as follows. Figure 5 presents an idealized approximation of the geometric features (Figure 5a, Table S1b) by fitting a line segmen<sup>t</sup> and two 14 -arcs of the same radii (Figure 5c) using the RANSAC algorithm. A subset of points from the entire point-cloud profile of the rail are randomly selected as the start of RANSAC flow. The selected point-subset is fitted to mathematical models using a least square's procedure to obtain preliminary model parameters, which are subsequently used to calculate the deviation of all 3D points in the point-cloud profile. If the deviation is less than a predetermined threshold, the 3D point is classified to an inlier, otherwise, an outlier. After performing a finite number of iterations of the aforementioned process, the model parameters corresponding to the largest number of inliers can be selected as the best model parameter estimates [36].

**Figure 5.** The uniform geometry of the laser profile of the undamaged rail. (**a**) The laser line on the model; (**b**) The single profile acquired from (**a**); (**c**) The idealized approximation of the profile indicated with the red circle in (**b**).

In order to recognize the scratch-area of the rail surface PCM, the algorithm is developed based on the above mathematical method as follows:

(1) Filter the rail surface PCM to remove the noise points and outliers for improving its quality [37] by the method based on the neighborhood radius as shown in Figure 6. Set the radius of the neighborhood as *rn* and the minimum number of points in a neighborhood as *n*. If the minimum number of points in a neighborhood with the radius of *rn* is less than *n*, the point will be filtered out. As shown in Figure 6, the red point and the green point will be filtered out when *n* = 2.


**Figure 6.** The point cloud filtering method based on the neighborhood radius.

**Figure 7.** Flowchart of the method for classifying the point-cloud profiles.

**Figure 8.** The method for re-classifying profiles by the sliding window with a certain threshold width. The red lines represent the profiles in scratched areas and the blue lines represent the profiles in undamaged areas.

The scratch-surface PCM can be accurately acquired by recognizing the scratch area of the rail-surface PCM with the above-mentioned algorithm, which is subsequently used to calculate the difference with the reference PCM constructed by the method described below.

According to the geometry of the rail presented in Figure 3, the reference PCM can be constructed by extending the undamaged profile in the certain direction. The mathematical formulation is as follows:

$$
\begin{bmatrix} X\_{SS} \\ Y\_{SS} \\ Z\_{SS} \end{bmatrix} = \begin{bmatrix} X\_S \\ Y\_S \\ Z\_S \end{bmatrix} + \begin{bmatrix} x\_{\Lambda} \\ x\_{\Lambda} \frac{n\_y}{n\_x} \\ x\_{\Lambda} \frac{n\_x}{n\_x} \end{bmatrix} \tag{4}
$$

where *x*Δ is the extended step length, →*v* = (*nx*, *ny*, *nz*) is the extension vector, (*XS*,*YS*,*ZS*) is the point of the undamaged profile, and (*XSS*,*YSS*,*ZSS*) is the constructed point in the reference PCM.

The most critical step for constructing the reference PCM is to accurately calculate the extension vector: → *v* = (*nx*, *ny*, *nz*). In Figure 9, the point-cloud profiles on unscratched region are approximated with a line segmen<sup>t</sup> of equal length and two 1/4 arcs of equal radii as described previously. The two sets of corresponding endpoints of line segments are fitted respectively with a model of line whose direction is defined as the preliminary extension vector. Thus, two preliminary vectors, →*v*1 = (*nx*1, *ny*1, *nz*1) and →*v*2 = (*nx*2, *ny*2, *nz*2) are obtained for the calculation of final extension vector, →*v* , by using the following equation:

$$
\stackrel{\rightarrow}{w} = \begin{bmatrix} n\_{\chi} \\ n\_{y} \\ n\_{z} \end{bmatrix} = \theta\_{1} \begin{bmatrix} n\_{\chi1} \\ n\_{y1} \\ n\_{z1} \end{bmatrix} + \theta\_{2} \begin{bmatrix} n\_{\chi2} \\ n\_{y2} \\ n\_{z2} \end{bmatrix} \\ \text{with } \theta\_{1} + \theta\_{2} = 1 \tag{5}
$$

where θ1 and θ2 are the weighting parameters.

After the final extension vector →*v* = (*nx*, *ny*, *nz*) is acquired, the reference PCM can be constructed. Finally, the differences between the reference PCM and the scratch-surface PCM can be calculated and the PCM pair with a difference larger than a certain threshold will be selected to form the PCM of scratch-data.

**Figure 9.** Fitting the endpoints of line segments with a model of line to acquire the preliminary extension vectors → *v*1 and →*v*2.

#### **4. 3D Point-Cloud Triangulation**

The PCM of scratch data obtained in Section 3 cannot be used directly for the online rail-repair relying on the laser cladding technology since it is not a complete closed mesh model and does not meet the requirements for layering of 3D printing [38]. In order to quickly and efficiently achieve a complete closed mesh model, a novel triangulation-algorithm [39] based on the topological features of the PCM is proposed in this section.

Firstly, filtering of the PCM is performed to remove the noise points and outliers caused by the calculation errors using the method presented in Figure 6. Secondly, the filtered-PCM is decomposed into a series of line-profiles equidistant in the X-axis direction since the obtained PCM has an ordered structure (Figure 10) according to the 3D modeling procedure proposed in Section 2. Finally, the triangulation algorithm is implemented as illustrated in Figure 11.

Each point-cloud profile is concatenated with lines as shown in Figure 11a. Then the trianglemeshes between the adjacent point-cloud profiles are sequentially constructed following Figure 11b–d. In Figure 11b, the quadrilaterals are constructed first, then in Figure 11c, triangle-meshes are formed within the above quadrilaterals. In Figure 11d, the remaining points in one of the point-cloud profiles are connected with the end point of the counterpart, finishing the triangulation of the adjacent point-cloud profiles. By carrying out the similar procedure described above between all adjacent point-cloud profiles, the triangulation algorithm for the PCM is completed with a result of Figure 11e.

**Figure 10.** The topological features of the 3D surface PCM labelled with the index numbers.

**Figure 11.** The schematized flow of the triangulation algorithm of 3D point-cloud. (**a**) Concatenate each point-cloud profile with lines; (**b**) Constructe the quadrilaterals; (**c**) Form the triangle-meshes; (**d**) Finish the triangulation of the adjacent point-cloud profiles; (**e**) Complete the triangulation algorithm for the PCM.

Thus, the triangulation of scratch-data PCM can be done by separately triangulating the reference PCM (Figure 12b) and the scratch-surface PCM (Figure 12c) using the algorithm described above since they compose scratch-data PCM as illustrated in Figure 12a, which also can be found in Section 3. Subsequently, the final complete closed mesh model of the scratch-data (Figure 13c) can be successfully achieved by stitching the triangle-meshes of the reference PCM (Figure 13a) and the scratch-surface PCM (Figure 13b) through the boundary mesh as schemed in Figure 13.

**Figure 12.** The composition of the scratch-data PCM. (**a**) The scratch-data PCM; (**b**) The reference PCM; (**c**) The scratch-surface PCM.

**Figure 13.** The process of constructing the complete closed mesh model of scratch data. (**a**) The mesh of reference PCM; (**b**) The mesh of scratch-surface PCM; (**c**) The complete closed mesh model of scratch data stitched by (**<sup>a</sup>**,**b**) through the boundary mesh.
