As described above, the existing second method does not consider the features of different area and utilizes all point cloud data in the process of determining the initial plane. It causes poor accuracy of initial plane, but also needs extra workload to meet the requirements of preprocessing including the removal of redundant point clouds, such as parapet walls, drainage outlets and ground.
To reduce or eliminate the effect of building areas (noise data) on the initial plane and improve the performance, one strategy of point cloud slicing is firstly introduced in this study. Slicing the point cloud of the city wall can sample the points at the specified height of the city wall, and fitting these points can obtain ordered discrete points representing the bulging change of the city wall at the corresponding height. Then, the discrete points in the nonbulging region are identified based on the curved spatial geometric features in the sliced data. Thirdly, plane fitting was performed on the points of the nonbulging parts to obtain the initial plane of the city wall surface, the wall bulging disease information is extracted by comparing the initial plane with the original point cloud of the wall, and an accuracy evaluation is performed. Finally, the disease information is visualized. The main workflow is shown in Fig. 1.
In general, the method includes four main parts: point cloud slicing and fitting, feature points identification, fitting of the city wall initial plane and bulging disease information extraction, and accuracy evaluation.
Point cloud data slicing
Usually, the coordinate system of the 3D point cloud data collected in the field is the instrument coordinate system, which cannot be directly input into the algorithm. For the convenience, an independent coordinate system is necessary to be established according to the structural characteristics of city walls, illustrated in Fig. 2, where the Xaxis is the intersection line between the base of the wall and the ground as determined through both endpoints of the wall using the right direction (facing the wall) as the positive direction. the Zaxis trends upwards vertically, the Yaxis is perpendicular to the XOZ plane and points towards the wall. The origin of the coordinates is selected at any point on the Xaxis. The 3D point cloud data are converted into an independent coordinate system to facilitate point cloud data processing and algorithm description.
When a plane passes through the point cloud data, all points in a certain neighbourhood of the plane location are extracted and projected to the plane, these projection points are called the slice of point cloud data, and the width of neighbourhood is called the slice width. The slice of the point cloud data can be viewed as the point set located on a certain plane in the point cloud data. Assuming that several planes with equal intervals that are parallel to the horizontal plane pass through the wall point cloud data, several corresponding slices are obtained (Fig. 2). Let the slice width be w, the slice interval be d_{1}, and the upper and lower limits of the slice height be h_{max} and h_{min}, respectively. Then, a total of L sections can be obtained. The Zcoordinates range of the Jth section containing discrete points is expressed as follows:
$$ \left[ {h_{min} + d_{1} \times \left( {J  1} \right)  \frac{w}{2},h_{min} + d_{1} \times \left( {J  1} \right) + \frac{w}{2}} \right],\;\;J = 1,2, \ldots L,L = \frac{{h_{max}  h_{min} }}{{d_{1} }} + 1. $$
(1)
The 2D discrete points of the Jth section are resampled at an interval of d_{2} to obtain N_{J} discrete points, and the discrete points are sorted in descending order according to the Xaxis values. Each section is resampled and sorted, and a point set Q is formed as follows:
$$ Q = \left\{ {\left. {q_{JK} } \rightq_{JK} = \left( {x_{JK} ,y_{JK} } \right),\;\;J = 1,2,3, \ldots L,\;\;K = 1,2,3, \ldots N_{J} } \right\}. $$
(2)
where K represents the Kth discrete point in the Jth section. The schematic diagram of point cloud slice is shown in Fig. 2.
Piecewise fitting of slice contours
If there is no bulging on the outer surface of the city wall, then the discrete points in the successively connected slices can be approximated as a straight line. otherwise, they can be represented as a curve, and the curved section can be considered a representation of the bulging area on the slice [20]. Therefore, the key to bulge extraction is to identify the curved part of the line that connects the discrete points. Due to the presence of weathering or damage to the exterior clad bricks of ancient city walls (Fig. 3), the discrete points in the connected slices can also have many small local depressions. Therefore, to obtain the part of the curve that represents the bulge in the sliced data, it is necessary to fit the discrete points in the slice to a continuous smooth curve and, at the same time, remove the small local depressions as noise points. The actual masonry spalling and missing of the wall is shown in Fig. 3.
For curve fitting of the slice discrete points, only an appropriate algorithm can fit the curve to reflect the curved characteristics. otherwise, too much detail could be retained or necessary detail could be removed [21]. Here, a piecewise fitting strategy is adopted. The discrete points are first segmented, and then a polynomial is combined with the cubic Hermite interpolation function for fitting. At the same time, the improved Kmeans clustering algorithm is used to eliminate the noise points to ensure that the curved characteristics of the curve can be expressed, and reliable fitting accuracy can be obtained.
The discrete points of the section J in the point set Q form a point set Q_{1}, which is expressed as follows:
$$ Q_{1} { = }\left\{ {q_{JK} \left {q_{JK} { = }\left( {x_{JK} ,y_{JK} } \right),\;1 \le J \le L,\;K = 1,2,3 \ldots N_{J} } \right.} \right\}. $$
(3)
The discrete curvature of each point in the point set is calculated, and Kmeans clustering is performed on the discrete points according to the curvature value. According to the clustering results, the noise points are filtered through a neighbourhood search. The specific method is as follows.
Calculation of the discrete curvature of a point set
The three consecutive points in the point set Q_{1} are q_{JK1}, q_{JK}, q_{JK+1}, and t_{1}, t_{2} represent the lengths of the vectors between q_{JK} and two nearby points, as shown in Fig. 4.
The curve parameter equation composed of three points is obtained as follows:
$$ \left\{ {\begin{array}{*{20}c} {x = a_{1} + a_{2} t + a_{3} t^{2} } \\ {y = b_{1} + b_{2} t + b_{3} t^{2} } \\ \end{array} } \right.. $$
(4)
The length of two segments is:
$$ \left\{ {\begin{array}{*{20}c} {t_{1} = \sqrt {\left( {x_{JK}  x_{JK  1} } \right)^{2} + \left( {y_{JK}  y_{JK  1} } \right)^{2} } } \\ {t_{2} = \sqrt {\left( {x_{JK + 1}  x_{JK} } \right)^{2} + \left( {y_{JK + 1}  y_{JK} } \right)^{2} } } \\ \end{array} } \right.. $$
(5)
If the following conditions are met, then the expression becomes:
$$ \left\{ {\begin{array}{*{20}l} {\left( {x,y} \right)\left {_{{t =  t_{1} }} = \left( {x_{JK  1} ,y_{JK  1} } \right)} \right.} \hfill \\ {\left( {x,y} \right)\left {_{t = 0} = \left( {x_{JK} ,y_{JK} } \right)} \right.} \hfill \\ {\left( {x,y} \right)\left {_{{t = t_{2} }} = \left( {x_{JK + 1} ,y_{JK + 1} } \right)} \right.} \hfill \\ \end{array} } \right.. $$
(6)
Then a_{1}, a_{2}, a_{3}, b_{1}, b_{2}, b_{3} can be solved according to the following equation:
$$ \left\{ {\begin{array}{*{20}l} {x_{JK  1} = a_{1}  a_{2} t_{1} + a_{3} t_{1}^{2} ,y_{JK  1} = b_{1}  b_{2} t_{1} + b_{3} t_{1}^{2} } \hfill \\ {x_{JK} = a_{1} ,y_{JK} = b_{1} } \hfill \\ {x_{JK + 1} = a_{1} + a_{2} t_{2} + a_{3} t_{2}^{2} ,y_{JK + 1} = b_{1} + b_{2} t_{2} + b_{3} t_{2}^{2} } \hfill \\ \end{array} } \right.. $$
(7)
Discrete curvature \(\kappa \) at point q_{JK} is expressed [22] as follows:
$$ \kappa = \frac{{x^{\prime\prime}y^{\prime}  x^{\prime}y^{\prime\prime}}}{{\left( {\left( {x^{\prime}} \right)^{2} + \left( {y^{\prime}} \right)^{2} } \right)^{3/2} }} = \frac{{2\left( {a_{3} b_{2}  a_{2} b_{3} } \right)}}{{\left( {a_{2}^{2} + b_{2}^{2} } \right)^{3/2} }}. $$
(8)
Noise filtering
Noise filtering mainly removes the small local depressions in the slice caused by damage to the city wall. Considering that these small depressions have a small range and large curvature value at the bottommost point of the depression, this area can be searched by setting the curvature threshold of the discrete points, and at the same time, the width and depth range of the small depressions can be limited to find other points inside the depressions, thus facilitating their identification. Because the curvature of the discrete points at the bottom of these small depressions is similar, it can be obtained by the Kmeans clustering method. Kmeans clustering is a classic unsupervised clustering algorithm, and its main idea is to group similar samples together to form clusters according to the distance between samples [23]. This approach is performed on the point set according to the discrete curvature, and the cluster with the largest discrete curvature is obtained, that is, the set of the bottom points of all small depressions. Then, the two thresholds, the depth and width, of the small depression are set and defined by the difference S of the Yaxis between adjacent points and the range coefficient \(R^{\prime}\) to determine the adjacent area. The specific noise filtering algorithm is obtained as follows:

(1)
The discrete points contained in the cluster with the largest discrete curvature are extracted as seed points to form a seed point set O.

(2)
Centerd at the seed point, within the range \(R^{\prime}\), a search is performed on both sides of the Xaxis. If the absolute value of the difference between the Ycoordinate of the seed point and the neighbouring point on one side is less than S, the neighbouring point is considered a noise point, and the search continues until the edge point of one side (at distance \(R^{\prime}\)) is determined. If the absolute value of the difference between the Ycoordinate of the seed point and the neighbouring point on one side is greater than S, the iteration is stopped on that side, as shown in Fig. 5. The search on both sides is complete.

(3)
The seed point set O and obtained noise points are removed, and the remaining points forms the point set Q_{2}, which is expressed as follows
$$ Q_{2} = \left\{ {q_{JF} \left {q_{JF} = \left( {x_{JF} ,y_{JF} } \right),\;\;F = 1,2,3, \ldots N_{J} } \right.} \right\}. $$
(9)
Piecewise curve fitting of point sets
To accurately represent the curved characteristics of the slice contours, it is necessary to adopt a reasonable fitting strategy and function model [24]. Piecewise fitting is a method that divides a segment of complex discrete points into several segments of simple discrete points for curve fitting. this strategy has high fitting accuracy but maintains the curved characteristics of the curve. In this study, a cubic polynomial function is used to achieve piecewise fitting of the sliced data after the noise is removed, but the fitting curve of each segment is not continuous at the breakpoints. For a segment of discrete points, the endpoint condition of the cubic Hermite interpolation can satisfy the firstorder continuity of the interpolation function at the endpoints [25, 26]. In this study, cubic Hermite interpolation is used to achieve connection between the polynomial fitting curves.
Let the function expression of the cubic polynomial be expressed as follows:
$$ f\left( x \right) = \sum\limits_{c = 0}^{b} {a_{c} x^{c} } . $$
(10)
In Eq. (10), b is the number of curve fittings, and a_{0}, a_{1}, a_{2}, … a_{b} are the undetermined regression coefficients of polynomial fitting.
Let the function expression of cubic Hermite interpolation be expressed as follows:
$$ G = \alpha_{1} x^{3} + \alpha_{2} x^{2} + \alpha_{3} x + \alpha_{4} $$
(11)
In Eq. (11),\(\alpha_{1} ,\alpha_{2} ,\alpha_{3} ,\alpha_{4}\) are the undetermined regression coefficients of the interpolation function. If the coordinates of two endpoints are (x_{L},y_{L}), (x_{R},y_{R}) in the interpolation function, then the expression of constraint (12) exists and is unique [27]:
$$ \left\{ {\begin{array}{*{20}l} {\left. {\frac{\partial G}{{\partial x}}} \right_{{x = x_{L} }} = \left. {\frac{\partial f\left( x \right)}{{\partial x}}} \right_{{x = x_{L} }} } \hfill \\ {\left. {\frac{{\partial^{2} G}}{{\partial x^{2} }}} \right_{{x = x_{R} }} = \left. {\frac{{\partial^{2} f\left( x \right)}}{{\partial x^{2} }}} \right_{{x = x_{R} }} } \hfill \\ {y_{L} = \alpha_{1} x_{L}^{3} + \alpha_{2} x_{L}^{2} + \alpha_{3} x_{L} + \alpha_{4} } \hfill \\ {y_{R} = \alpha_{1} x_{R}^{3} + \alpha_{2} x_{R}^{2} + \alpha_{3} x_{R} + \alpha_{4} .} \hfill \\ \end{array} } \right. $$
(12)
Piecewise fitting is performed on the discrete points in point set Q_{2}, and the fitting method is as follows:

(1)
The number of segments u for piecewise fitting of point set Q_{2} is determined, the points are evenly distributed to each segment, and the number of discrete points in each segment is recorded as n_{1},n_{2},n_{3},…,n_{u}.

(2)
Cubic polynomial fitting is performed on the first segment of discrete points (x_{i},y_{i}), i = 1,2,3,…n_{1}, and the obtained polynomial equation is f_{1}(x). Discretization of f_{1}(x) at x = x_{i}, i = 1,2,3,…n_{1} obtains discrete points (\({\text{x}}_{{\text{l}}_{1}}\), \({y}_{{\text{l}}_{1}}\)), l_{1} = 1,2,3,…n_{1}.

(3)
For (\({\text{x}}_{{\text{l}}_{1}}\), \({y}_{{\text{l}}_{1}}\)), l_{1} = n_{1} − 4, n_{1} − 3, n_{1}2,…n_{1}, weighting on the point (\({\text{x}}_{{\text{n}}_{1}\text{4}}\), \({\text{y}}_{{\text{n}}_{1}\text{4}}\)) is performed, and the number of times the point is weighted is generally 0.2n_{1}. Both (\({\text{x}}_{{\text{l}}_{1}}\), \({y}_{{\text{l}}_{1}}\)), l_{1} = n_{1} − 4, n_{1} − 3, n_{1} − 2,…n_{1} and (x_{i}, y_{i}), i = n_{1}, n_{1} + 1, n_{1} + 2,…2n are fitted with cubic polynomials, and the obtained polynomial equation is denoted as f_{2}(x). Discretization f_{2}(x) at x = x_{i}, x = n_{1} − 4, n_{1} − 3, n_{1} − 2,…2n_{1} obtains discrete points (\({\text{x}}_{{\text{l}}_{2}}\), \({y}_{{\text{l}}_{2}}\)), l_{2} = 1, 2, 3,…n_{2}.

(4)
For (\({\text{x}}_{{\text{l}}_{1}}\), \({y}_{{\text{l}}_{1}}\)), l_{1} = 1, 2, 3,…n_{1} and (\({\text{x}}_{{\text{l}}_{2}}\), \({y}_{{\text{l}}_{2}}\)), l_{2} = 1, 2, 3,…n_{2}, (\({\text{x}}_{{\text{l}}_{1}}\), \({y}_{{\text{l}}_{1}}\)), l_{1} = n_{1} − 4, n_{1} − 3, n_{1} − 2,…n_{1} and (\({\text{x}}_{{\text{l}}_{2}}\), \({y}_{{\text{l}}_{2}}\)), l_{2} = 1, 2, 3,…5 represent overlapping sections of two discrete data segments in the Xdirection. This overlapping part is represented by an interpolation curve that employs (\({\text{x}}_{{\text{n}}_{1}\text{4}}\), \({\text{y}}_{{\text{n}}_{1}\text{4}}\)) and (\({x}_{5}\), \({y}_{5}\)) as the two endpoints of the interpolation curve, and the equation of the interpolation curve is obtained through the constraint in Eq. (12).

(5)
Steps (3) to (4) are repeated to obtain a complete, continuous and derivable curve for the discrete points of one section.
At the Xcoordinate of each discrete point in point set Q_{2}, the fitted curve is discretized, and the corrected coordinates obtained from the discretization form the overall point set P, which is expressed as follows:
$$ P = \left\{ {p_{JF} \left {p_{JF} = \left( {x_{JF} ,y_{JF} } \right),\;\;F = 1,2,3 \cdots N_{J} } \right.} \right\}. $$
(13)
Extraction of nonbulging points
To extract the nonbulging points more accurately from the sliced data, it is necessary to consider the spatial geometric characteristics of either the bulging area or the nonbulging area on the slice contour line. If there is no bulging of the city wall, the slice contour line may be a straight line, and the points in the sliced data can be directly extracted as nonbulging points. When there is only one bulging point, there may be a local bending and three inflection points (the two ends and the apex of the curve) on the slice contour line. If there are multiple bulging points in the section, there may be multiple bendings in the slice contour line, and the corresponding inflection points may also increase. For simplicity, the discrete points at the inflection points (both ends of the bending) and in a certain neighbourhood range can be treated as nonbulging points when the slope of the line formed between adjacent discrete points is small, as shown in Fig. 6. Therefore, the identification of nonbulging points can be achieved by identifying the inflection points and its type in the sliced data and determining the bending of the contour lines at the inflection points within a certain range on both sides. The identification of the type of inflection point is mainly based on the direction of the Ycomponent of the tangent vectors of the discrete points on the left and right sides of the inflection point. For an inflection point at one endpoint of the bending, the direction of the Ycomponent of the tangent vector of the discrete point on the left side is towards the wall, and the opposite direction corresponds to the discrete point on the right side. After the inflection points at the two ends of the bending are identified, the nonbulging points is determined by the slope of the connecting line between the two adjacent points. This study sets the threshold of the line slope between two adjacent points as \(\delta\) and the specific algorithm for identifying nonbulging points is obtained as follows, the form of identifying nonbulging areas is shown in Fig. 6.
Inflection point identification
For the point p_{JF}(x_{JF},y_{JF}) in point set P, the slope of tangent at x = x_{JF} is \({\varepsilon}\) _{JF}. then, the Ycomponent of the unit tangent vector at this point is:
$$ T\left( {x_{JF} } \right) = sin\left( {arctan\left( {\varepsilon_{JF} } \right)} \right). $$
(14)
If point p_{JF} satisfies condition (15), then point p_{JF} can be considered the inflection point at the endpoint of a bending. This relationship is expressed as follows:
$$ \left\{ {\begin{array}{*{20}l} {T\left( {x_{JF  1} } \right) > 0,T\left( {x_{JF + 1} } \right) < 0} \hfill \\ {y_{JF} > y_{JF  1} ,y_{JF + 1} .} \hfill \\ \end{array} } \right. $$
(15)
The slope between point p_{JF}(x_{JF}, y_{JF}) and point p_{JF1}(x_{JF−1}, y_{JF−1}) is expressed as follows:
$$ k_{JF}^{JF  1} = \frac{{y_{JF}  y_{JF  1} }}{{x_{JF}  x_{JF  1} }}. $$
(16)
In Eq. (15), T(x_{JF−1}) represents the Ycomponent of the tangent vector at the adjacent discrete point on the left side of point p_{JF}, and T(x_{JF+1}) represents the Ycomponent of the tangent vector at the adjacent discrete point on the right side of point p_{JF}. The positive direction moves toward the wall, and the negative direction moves in the opposite direction.
Although some inflection points after the above treatment are closer to the initial plane than neighborhood points, but they are at the intersection of two bulging areas and still on the bulging area. In order to reduce the influence of these points on the fitting result, when the absolute value of the slope of an inflection point and other inflection points is greater than threshold \({\delta}\), this point is no longer regarded as an inflection point.
Extraction of nonbulging points
Using the retained inflection points as the center, calculates the slope of the retained inflection points and discrete points on both sides. If the slope is less than \({\delta}\), the discrete point is retained, and the search continues for the next discrete point on the same side. If the slope is greater than \({\delta}\), the calculation on this side is complete. If two points \({\text{p}}_{{\text{JF}}_{1}}\), \({\text{p}}_{{\text{JF}}_{2}}\)(\({\text{x}}_{{\text{JF}}_{1}}\text{<}{\text{x}}_{{\text{JF}}_{2}}\)) on both sides of the inflection point p_{JF} satisfy Eq. (17) as follows:
$$ \left\{ {\begin{array}{*{20}c} {\left {k_{JF}^{{JF_{1}  1}} } \right > \delta ,\left {k_{JF}^{x} } \right < \delta ,\;x = JF_{1} ,JF + 1 \cdots JF} \\ {\left {k_{JF}^{{JF_{2} + 1}} } \right > \delta ,\left {k_{JF}^{x} } \right < \delta ,\;x = JF,JF + 1 \cdots JF_{2} } \\ \end{array} } \right.. $$
(17)
Then the discrete points in the interval [\({\text{x}}_{{\text{JF}}_{1}},{\text{x}}_{{\text{JF}}_{2}}\)] are denoted as nonbulging points. Each inflection points and the discrete points in its neighbourhood are identified to complete the identification of the nonbulging points in the sliced data.
Steps 1–2 are repeated to extract the nonbulging points in each section. All nonbulging points form a 3D point set P*(expression (18)), and the Zcoordinates correspond to the Zcoordinates of the original point cloud associated with each point.
$$ P^{ * } = \left\{ {p_{j} \left {p_{j} = \left( {x_{j} ,y_{j} ,z_{j} } \right),\;\;j = 1,2,3 \ldots ns} \right.} \right\}. $$
(18)
Plane fitting and bulging extraction
The robust eigenvalue method is used to fit the plane comprising the nonbulging points and is based on the eigenvalue method. The calculated unit normal vector of the fitting plane and the distance from the origin to the plane are used as parameters, all the points are divided into inner points and outliers, and the final fitted spatial plane equation is obtained by iteration [28]. This method is widely used to eliminate noise points during the fitting process [29,30,31], can reduce the extraction error of nonbulging points, and can remove the few discrete points that lie on the bulging area but are arranged in parallel with the Xaxis.
The specific calculation method for fitting initial planes is described as follows:

(1)
Plane fitting is performed for all points in point set P* through the eigenvalue method, and the obtained equation that approximates the city wall initial plane is Ax + By + Cz + D = 0. The orthogonal distance from each point along the normal line to the plane is expressed as follows:
$$ H_{j} = \frac{{\left {Ax_{j} + By_{j} + Cz_{j} + D} \right}}{{\sqrt {A^{2} + B^{2} + C^{2} } }}\left( {j = 1,2,3 \ldots ns} \right). $$
(19)

(2)
The calculation of the standard deviation (SD) of the orthogonal distance H_{j} is obtained as follows:
$$ \sigma = \sqrt {\frac{{\left( {H_{j}  \overline{H}} \right)^{T} \left( {H_{j}  \overline{H}} \right)}}{ns  1}}, $$
(20)
where:
$$ \overline{H} = \frac{1}{ns}\sum\limits_{j = 1}^{ns} {H_{j} }. $$
(21)

(3)
When the H_{j} of a certain point is less than \(2\sigma\), the point is retained. otherwise, the point is considered an abnormal point and eliminated.

(4)
All of the retained points are fitted using the eigenvalue method, the orthogonal distance from each point to the fitting plane is calculated, and Steps 1 to 2 are repeated. If the orthogonal distances from all retained points to the plane are within the threshold, iteration ends, and the final fitting plane equation is obtained.
After the initial plane is obtained, the proceeded operation is to detect possible bulging areas. As described in "Piecewise fitting of slice contours", contour lines can be obtained within the slices at different heights of the city wall. However, the contour lines can only represent the horizontal bulge variation at the corresponding height of the city wall. Moreover, there are slice intervals between the contour lines, the “bulges” obtained only by the contour lines is discrete and cannot accurately reflect the degree and extent of the bulge in the vertical direction. Moreover, unlike initial plane, bulging surfaces vary from one to another without predefined wellknown mathematical forms to express them; therefore, it is not able or difficult to use the same fitting method to determine all bulging areas only from the sampled discrete bulging points. Therefore, in order to obtain accurately a complete bulge situation, the initial plane of the wall is taken as the reference and then the comparative analysis is performed between the initial plane and the whole point cloud of the wall. During the process of comparison, those points which are above the initial plane will be marked as bulging. Simultaneously, the offset distance between each original wall point and the initial plane is calculated. The offset distance is defined as the orthogonal distance from each point of the wall to the initial plane along the normal line. The offset distance is also recorded as the relative height of each wall point to the initial plane.
Error evaluation
The accuracy of the bulging extraction method was evaluated from two aspects: the accuracy of curve fitting and the angle and distance deviation between fitting planes.
The accuracy of curve fitting is usually evaluated using posterior variance, small error probability, and the mean absolute percentage error (MAPE) [32, 33]. The accuracy analysis method for the curve fitting used in this paper is as follows:
Point set P is obtained by curve fitting and discretization as follows:
$$ P = \left\{ {p_{JF} \left {p_{JF} = \left( {x_{JF} ,y_{JF} } \right),\;F = 1,2,3 \ldots N_{J} } \right.} \right\}. $$
(22)
Point set‾P is obtained by correlating each point in set P to the point before fitting as follows:
$$ \overline{P} = \left\{ {\overline{p}_{JF} \left {\overline{p}_{JF} = \left( {x_{JF} ,\overline{y}_{JF} } \right),\;F = 1,2,3 \ldots N_{J} } \right.} \right\}. $$
(23)
According to the residual error \(e_{JF} = y_{JF}  \overline{y}_{JF}\) at any point in point set P, the SD of the fitted original sequence is as follows:
$$ S_{1} = \sqrt {\frac{{\sum {\left[ {y_{JF}  \overline{y}_{JF} } \right]^{2} } }}{{N_{J}  1}}} . $$
(24)
The SD of the absolute error is expressed as follows:
$$ S_{2} { = }\sqrt {\frac{{\sum {\left[ {e_{JF}  \overline{e}_{JF} } \right]}^{2} }}{{N_{J}  1}}} , $$
(25)
where
$$ \overline{y}_{JF} = \frac{1}{{N_{J} }}\left( {\sum\limits_{F = 1}^{{N_{J} }} {y_{JF} } } \right). $$
(26)
$$ \overline{e}_{JF} = \frac{1}{{N_{J} }}\left( {\sum\limits_{F = 1}^{{N_{J} }} {e_{JF} } } \right). $$
(27)
Then, the posterior error ratio is as follows:
$$ C = \frac{{S_{2} }}{{S_{1} }}. $$
(28)
The small error probability is expressed by:
$$ p\left\{ {\left {e_{JF}  \overline{e}_{JF} } \right < 0.6745S_{1} } \right\}. $$
(29)
The MAPE is calculated as follows:
$$ MAPE = \frac{1}{{N_{J} }}\left( {\sum\limits_{F = 1}^{{N_{J} }} {\frac{{\left {e_{JF} } \right}}{{y_{JF} }}} } \right) \times 100. $$
(30)
Based on the above calculation results, the piecewise curve fitting grade and the fitting accuracy can be determined.
The algorithm robustness is verified by calculating the inclination of the fitting plane, which is obtained by processing the point clouds of each city wall segment in the same global coordinate system. The calculation of the plane inclination is shown in Fig. 7.
In the figure, \(\vec{A}\left( {x,y,z} \right)\) is the unit normal vector of the fitting plane, and \(\vec{B}\left( {0,0,1} \right)\) is the unit normal vector in the Zdirection. Then, the inclination angle \(\alpha\) formed by the fitting plane and the XOZ plane is obtained as follows:
$$ \alpha = arccos\left( {\vec{A} \cdot \vec{B}} \right). $$
(31)
In the same way, the inclination angle formed by the fitting plane and the YOZ plane can be obtained.