## 3 Methodology
### Spaces Division and Extraction
#### 3.3.2 Generation of Wall Candidates
Figure 8b shows the convex hull polygon as a red solid line, the envelope of the convex hull as a blue dashed line, the points inside the polygon as green dots, and the points outside the polygon as blue dots. Second, as shown in Figure 9, an octree structure with the same leaf size is generated for two point clouds. Therefore, the problem of opening detection shifts to finding the differences between the octree structure of the current opening planes \(\text{Ps}_{\text{d}}\) and the filled point cloud \(\text{Ps}_{\text{ch}}\). Note that an appropriate leaf size is determined according to the density of the current opening planes. The vacancy in the current door plane can be found via K nearest neighbor searching on two octree structures. Figure 9c shows the schematic diagram of the point cloud \(\text{Ps}_{\text{inc}}\) after changing detection. Subsequently, the Euclidean cluster extraction algorithm is used to divide the point cloud \(\text{Ps}_{\text{inc}}\) into separated opening components (Figure 8e). Finally, door components are reconstructed by the maximum of the point cloud \(\text{Ps}_{\text{inc}}\) and the 2D fitted line of each opening component (Figure 8f). Based on the proposed method, window and door components can be reconstructed based on the point cloud of tagged RGB-D frames. Figure 8: Generation of the opening components. ### Global Optimization for Planes

Even when a high-precision calibration method is applied to improve the mapping accuracy of the RGB-D system, it inevitably causes system and mapping errors in the point cloud generated from RGB-D sequences. This can result in inconsistencies between the planes detected from different functional spaces, such as a joint wall between two spaces, an opening, and its connected wall. Therefore, a global optimization approach is used to eliminate the inconsistency between the adjacent walls, and walls and openings, and maintain the plausible connectivity between the walls and the relationships between the walls and openings. Normally, two adjacent spaces often share the same plane (called the global plane in this paper), which can be extracted from the whole model instead of individual functional spaces. The whole model is generated by merging all RGB-D sequences, and the global planes can be obtained by applying a plane segmentation algorithm to the whole model. Because wall planes are detected from the individual point cloud of each space, there can be significant discrepancies between the global planes and the corresponding wall planes. As shown in Figure 10, wall plane1 \(wP_{1}\) and wall plane2 \(wP_{2}\) share a same global plane \(gP_{1}\), so it is hard to guarantee that they will have the same plane parameters during plane segmentation. To eliminate inconsistencies between the wall planes and global planes, all of the wall planes sharing the same global plane are projected onto the corresponding global plane. To find the corresponding global plane for each wall plane, we first calculate the angle of the plane normal \(\theta_{diff}\) between the specific wall plane according to Equation (2) and the planes detected from the whole model. Once \(\theta_{diff}\) are less than the threshold \(\theta_{th}\), the global plane candidates are filtered out. We define the wall plane wP, \(\left\{a_{w}\text{x}+b_{w}\text{y}+c_{w}\text{z}+d_{w}=0\right\}\), and the global plane candidates gp, \(\left\{a_{g}\text{x}+b_{g}\text{y}+c_{g}\text{z}+d_{g}=0\right\}\). To find the optimal global plane, distance \(d_{diff}\) between the wall plane and each global plane candidates are calculated. Because the distance between two intersecting planes is 0, two compared planes are forced to have the same plane normal, which means that the plane equation of wall plane wP becomes \(\left\{a_{g}\text{x}+b_{g}\text{y}+c_{g}\text{z}+d_{w}=0\right\}\). Therefore, distance \(d_{diff}\) can be calculated according to Equation (3). The optimal global plane is found when the minimum value of the distance \(d_{diff}\) is obtained.