# A Multivariate Local Descriptor Registration Method for Surface Topography Evaluation
## 2 Generation of Functional Surfaces and Point Cloud Based on STEP File
### The Generation and Trimming of Point Cloud
#### 2.2.2 The Filling and Trim of the Curved Surface Point Cloud  
Compared with a plane, the curved surfaces in STEP files consist of cylindrical surfaces, conical surfaces, b-spline surfaces with knots and non-uniform b-spline. In this study, all curved surfaces were transformed into NURBS surfaces [28]. Similar to the planar point cloud process, the point cloud of curved surfaces needs to be trimmed. It is difficult to trim surfaces in a 3D form directly, and it also cannot follow the trimming steps of the plane, which is trimming by mapping into the 2D space domain. NURBS surfaces can be trimmed by reverse-mapping the boundary to the 2D parameter field of NURBS surfaces. As shown in Equation (6), each point in the 3D domain corresponds to the \(u\), \(v\) parameter of the NURBS surface. Supposing a point \(P\) (\(x,y,z\)), a BFGS method can be used to approximate its corresponding parameters \(u_{0}\) and \(v_{0}\) in the parameter domain. The BFGS method [29; 30] is a quasi-newton method. Thus, a better initial value of the parameter should be chosen to avoid calculating a wrong result. The trimming steps of the curved surface point cloud based on the BFGS method are as follows:  
Input Curved point cloud.  
Output Trimmed curved point cloud.  
Figure 5: The procedure of plane point cloud trimming: (**a**) The point cloud of the plane before trimming; (**b**) The trimmed point cloud through the ray casting method.  
Figure 6: The illustration of the ray casing method. (**a**) A polygon includes a curve; (**b**) A curve is reduced to a polygon with multiple straight lines.  
Step 1 Supposing a set of boundary points [31], find their nearest points in the NURBS surface and take their corresponding values \(u_{i}\) and \(v_{i}\) in the parametric domain as the initial values of the Newton iterative method.  
Step 2 To define the objective optimisation function:  
\[l(u,v)=[p(u,v)-P][p(u,v)-P]^{T} \tag{6}\]  
When \(l\) equals zero, the \(P\) is obtained as the optimal value in the parametric domain. Then, determine the initial parameter \(x_{0}=[u_{0},v_{0}]^{T}\) and initial a symmetric positive definite matrix \(B_{0}\), which is the identity matrix.  
Step 3 Computation of the first-order partial derivative:  
\[g_{0}=\begin{bmatrix}l_{u}(u_{0},v_{0})\\ l_{v}(u_{0},v_{0})\end{bmatrix} \tag{7}\]  
Step 4 Calculation of the \(x_{i+1}\):  
\[x_{i+1}=x_{i}+\lambda_{i}B_{i}^{-1}g_{i} \tag{8}\]  
where \(\lambda_{i}\) denotes the step size, continue to calculate the \(s_{i}=x_{i+1}-x_{i}\), \(y_{i}=g_{i+1}-g_{i}\). Computation of the \(B_{k}\):  
\[B_{i+1}=B_{i}+\frac{yy^{T}}{y^{T}s}-\frac{B_{i}s^{T}B_{i}}{s^{T}B_{i}s} \tag{9}\]  
Step 5 Repeating the above step until the \(\|g_{i+1}\|<\epsilon\).  
The optimal parameters \(u\), \(v\) in \(P\), and the value of boundary points in the parameter domain can be obtained according to the above steps; the parameters can be clipped by the ray casting method, and then the clipped parameters can be converted into the spatial domain by Equation (10), and the clipped surface can be obtained. In Equation (10), the \(u\) and \(v\) represent the parameters in a different direction; the \(N\) is the basis function whose details are in Equation (3), \(w\) is the weight, \(P\) is the control point, and \(m\) and \(n\) are the order in a different direction. Figure 7 shows the flowchart of the trimmed NURBS surface.  
\[p(u,v)=\frac{\sum\limits_{i=0}\sum\limits_{j=0}N_{i,m}(u)N_{j,n}(v)w_{i,j}P_ {i,j}}{\sum\limits_{i=0}\sum\limits_{j=0}N_{i,m}(u)N_{j,n}(v)w_{i,j}} \tag{10}\]