A Multilevel Point Cloud Classification Method for Underground Tunnels Based on Three-Dimensional Moving LiDAR Measurements
Table 4
Pseudocode of K-means clustering algorithm based on Euclidean distance.
Step 1
Initialize the prototype specify K values and K clustering centers. KMeans test (4, 10); test.centre_points_- > points.push_back (pcl :: PointXYZ (x1, y1, z1)); … … test.centre_points_- > points.push_back (pcl :: PointXYZ (xn, yn, zn));
Step 2
Clustering. Traverse all data points and calculate the Euclidean distance to the K cluster centers from each data point. std :: sqrt((p1.x-p2.x) (p1.x-p2.x) + (p1.y-p2.y) (p1.y-p2.y) + (p1.z-p2.z) (p1.z-p2.z)); std :: vector<double> :: const_iterator min_dist = std :: min_element (dists.cbegin (), dists.cend ()); unsigned int it = std :: distance (dists.cbegin (), min_dist);
Step 3
Each data point is assigned to the category of the nearest cluster center until the last data point. cluster_cloud [it].points.push_back (cloud- > points [i]);
Step 4
Update the cluster center. That is to calculate the centroid of each class and compare the calculated cluster center with the previous cluster center. pcl :: compute3DCentroid (cluster_cloud [k], centroid); sum_diff+ = pointsDist (new_centre.points [s], centre_points_- > points [s]);
Step 5
If all clustering centers do not change, stop. If there is any change, take the current cluster center as the new cluster center, and repeat the above processes 2, 3, and 4 until all cluster centers do not change.