## 3 Methodology
### Floorplan Extraction and Regularization
#### 3.2.2 Line Global Optimization  
Figure 7c shows that the extracted initial lines are able to preserve detailed features. However, due to laser point clouds with information loss, holes, noise, etc., the extracted results mainly have four kinds of errors: angle deviation, distance deviation, excessive redundancy, and incomplete boundaries. Inspired the method [38], the angle and distance deviations of the line-segments are corrected by global optimization, as shown in Figure 8a,b. The problem is expressed as an energy function, as shown in Equation (5), which is minimized by g2o that called a general framework for graph optimization [47]. The weight parameter \(\lambda\) is used for balancing the different terms.  
\[E(x)=(1-\lambda)\cdot D(x)+\lambda\cdot B(x) \tag{5}\]  
For angle correction, the data term \(D(x)\) is used to correct the angle deviations corresponding to the initial orientation, as expressed by:  
\[D(x)=\frac{1}{n}\sum_{i=1}^{n}\left(\frac{x_{i}}{\theta_{\max}}\right)^{2} \tag{6}\]  
where the correction value \(x_{i}\in[-\theta_{\max},\theta_{\max}]\) can be added to the initial orientation of the line \(i\) with respect to its center; clockwise direction indicates positive value; \(\theta_{\max}\) is the angle threshold adjustable based on the quality of point clouds; and \(n\) is the number of extracted initial lines.  
The smooth term \(B(x)\) is used to correct the geometric relationship of the adjacent lines, as expressed by:  
\[B(x)=\frac{1}{\sum_{i=1}^{n}\sum_{j=1}^{k}u_{ij}}\sum_{i=1}^{n}\sum_{j=1}^{k}u _{ij}\frac{\left|\theta_{ij}-\left(\left|x_{j}\right|+\left|x_{i}\right|\right) \right|}{4\theta_{\max}} \tag{7}\]  
\[\theta_{ij}=\left\{\begin{array}{ll}\theta_{ij}\pm 2\pi&if\ (\frac{7}{4}\pi \leq\left|\theta_{ij}\right|\leq 2\pi)\\ \theta_{ij}\pm\frac{3}{2}\pi&if\ (\frac{5}{4}\pi\leq\left|\theta_{ij} \right|\leq\frac{7}{4}\pi)\\ \theta_{ij}\pm\pi&if\ (\frac{3}{4}\pi\leq\left|\theta_{ij}\right|\leq\frac{ 3}{4}\pi)\\ \theta_{ij}&otherwise\end{array}\right. \tag{8}\]  
\[u_{ij}=\left\{\begin{array}{ll}1&if\ (\left|\theta_{ij}\right|<2\theta_{ \max})\\ 0&otherwise\end{array}\right.\]  
where \(\theta_{ij}\) is the angle between adjacent lines \(s_{i},s_{j}\) (such that \(\theta_{ij}\in[-2\pi,2\pi]\)). The adjacent lines are encouraged which are nearly-parallel or nearly-orthogonal or nearly-themselves. The angle \(\theta_{ij}\) is adjusted to close to the coordinate axis, as expressed by Equation (8). In addition, the following conditions are satisfied: if \(\left|\theta_{ij}\right|<2*\theta_{\max}\), \(u_{ij}=1\), otherwise \(u_{ij}=0\). \(k\) is the number of lines adjacent to line \(s_{i}\); which can be obtained that \(s_{i}\) is as the center and search its KNN from all other lines. The distance correction is similar to the angle, as expressed by:  
\[D(x)=\frac{1}{n}\sum_{i=1}^{n}\left(\frac{x_{i}}{\theta_{\max}} \right)^{2} \tag{9}\] \[B(x)=\frac{1}{\sum_{i=1}^{n}\sum_{j=1}^{k}u_{ij}}\sum_{i=1}^{n} \sum_{j=1}^{k}u_{ij}\frac{\left|\theta_{ij}-\left(\left|x_{j}\right|+\left|x_ {i}\right|\right)\right|}{4\theta_{\max}}\] \[u_{ij}=\left\{\begin{array}{ll}1&if\ (\left|d_{ij}\right|<2d_{ \max})\\ 0&otherwise\end{array}\right.\]where \(x_{i}\in[-d_{\max},d_{\max}]\) is added on the line \(s_{i}\) along its normal direction; and, \(d_{ij}\) is the distance between adjacent parallel lines \(s_{i},s_{j}\). If \(\left|d_{ij}\right|<2*d_{\max}\), then \(u_{ij}=1\), otherwise \(u_{ij}=0\). The global optimization results for the lines are shown in Figure 8c, which contains the correct geometric information.