# A Layer-Wise Strategy for Indoor As-Built Modeling Using Point Clouds
## 3 Methodology
### Planar Primitive Detection
#### 3.2.2 Planar Primitive Optimization  
Given the initial planar primitives, we apply an optimization method to solve the above-mentioned overlapping and separating problems. This process can be concluded as a label merging procedure which combines the erroneously segmented primitives to correct labels. Starting from the initial segmentation, we can utilize the RANSAC plane fitting method to gain the initial parameters of planes. The merging process can be implemented in consideration of the planes' normals and the mass centers of the planes. For instance, if a pair of planes satisfies the following conditions, we prefer to merge them to the identical plane: (1) The inconsistency of plane normals is smaller than a threshold (e.g., 10\({}^{\circ}\)), and (2) the distance between the mass centers of these two planes are smaller than a certain Euclidean distance (e.g., 0.5 m). If we consider these two conditions, we can improve the initial detection to some extent. Figure 4c indicates that these four planes (D, E, F, and G) are merged to the same plane. While the planes D, E, and F belong to the identical wall, plane G is not on the plane consisted by the other three primitives. Since these two planes are parallel and close to each other, it is difficult to find appropriate thresholds to guarantee that the wall segments on the identical wall can be merged while the nearby parallel walls can be separated. Figure 4b is another instance indicating that the parallel wall structures cannot be recognized. Because the approach considering plane directions and mass centers cannot take nearby parallel walls into account, we apply a global optimization method to refine these two conditions. Through this optimization, the parallel planes tend to be separated while the co-planar planes are expected to be merged. Thus, we convert the merging problem to a labeling problem and solve it by minimizing the multi-label energy via graph cuts [21]. The combined energy function is as follows:  
\[E(l)=\sum_{p\in\mathcal{P}}D_{p}(l_{p})+\sum_{p,q\in N}w_{pq}\cdot\delta(l_{p} \
eq l_{q})+\sum_{l\in\mathcal{L}}h_{l}\delta_{l}, \tag{2}\]  
where the three terms are data term, smoothness term and label term, respectively. The first term \(\sum_{p\in\mathcal{P}}D_{p}(l_{p})\) is the data term representing the penalty of assigning a point to a particular label. The data term is calculated using Equation (3). As illustrated in Figure 5, \(dist(p,l_{p})\) is the perpendicular distance from a point to its fitting plane. \[D_{p}(l_{p})=exp(-dist(p,l_{p})^{2}). \tag{3}\]  
Figure 3: The result of region-growing: enlarged drawings show that the co-planar walls have been separated into several parts. The second term is the smoothness term which is used to guarantee the smoothness in the neighborhood. We define the neighborhood of points as the k-nearest neighbors (e.g., \(k=20\)). The point \(p_{2}\) in Figure 5 shows an instance where the points in the circle are its neighboring points. The points \(q_{1}\) and \(q_{2}\) are assigned to the same label as \(p_{2}\). In this case, the smoothness costs are equal to 0. The points \(q_{3}\) and \(q_{4}\) are assigned to the different labels, hence the smoothness cost \(w_{pq}\) can be calculated by the following equation:  
\[w_{pq}=exp(\frac{-\|p-q\|}{\varsigma^{2}}), \tag{4}\]  
where \(\|p-q\|\) is the pairwise distance. We set \(\varsigma=0.01\) m according to the common spacing of points. The \(\delta(l_{p}\
eq l_{q})\) is an indicator function for all the same label points in the k-nearest neighbor. Because our objective is to minimize the energy function, it tends to change the labels in the neighborhood if the cost of smoothness term can be decreased by adjusting the current label of point \(p\) to its neighboring label. Since our goal is to merge the co-planar planes and retain the parallel planes, we utilized the third label term to penalize a large number of labels. We favored the fewer number of labels and encouraged the reduction of the redundant planes.