# Rule-Based Scan-to-BIM Mapping Pipeline in the Plumbing System
## 4 Pipeline Component Parameter and Rule Design
### Scan-to-BIM Component Algorithm and Parameters
#### 4.1.3 Segmentation(C6), Geometry Generation(C7) Parameters  
Segmentation is processed in two stages. The first step is to perform segmentation based on the point where the curvature is sharply divided, and the second step is to calculate a point group with parameters that fit the pipe shape.  
Figure 5: Purpose-oriented Scan-to-BIM Parameters Setting related to Pipeline Component.  
The segmentation uses a region growing algorithm based on curvature similarity. This method employs the local surface normal and connectivity of the point group as shown in the following equation.  
\[\|n_{0}\cdot n_{1}\|>\cos(\theta_{th}) \tag{7}\]  
where, \(n_{0}\) is the normal of each point, \(n_{1}\) is the angle between the current point and the normal of the surrounding points, and \(\theta_{th}\) is an allowable angle. The allowable angle can be expressed as a parameter as follows.  
\[parameter_{segmentation}\ =\ \{\theta_{th}\} \tag{8}\]  
The second-stage segmentation uses RANSAC (Random Sample Consensus) algorithm. Pipe shape can be expressed by cylinder geometry. A cylinder can be defined by its axis, diameter, radius, and length. The mathematical simplification of the cylinder model is as follows.  
\[\left(x-a\right)^{2}+\left(y-b\right)^{2}\ =\ r^{2} \tag{9}\]  
This is expressed as a parameter as follows.  
\[parameter_{cylinder\_segmentation}\ =\ \{radius,\ length\} \tag{10}\]  
The pipe shape extraction algorithm model is as follows. Each step can be repeated until the points satisfy the cylinder shape.  
* C1. \(P_{1,\,2,3}=\{point\ \big{|}\ point_{random}\text{in PCD}\}\)
* C2. \(parameter_{plane}=\{plane_{a,\ b\epsilon}[\text{PCA}(P_{1,\,2,3})\}\)
* C3. \(P_{c}=\{\text{point}\ \big{|}\text{center point of circle from }P_{1,\,2,3},\ plane_{a,\ b \epsilon}\}\)
* C4. \(\text{r}=radius(P_{c},\ P_{1,\,2,3}\)
* C5. \(axis_{vector}=\text{axis}(plane_{a,\ b,\ c},P_{c}\)
* C6. \(geometry_{cylinder}=\text{cylinder}(axis_{vector},P_{c},\ r\)
* C7. \(number_{inlier}=\{\text{count}\ \big{|}\ PCD\ in\ geometry_{cylinder}\text{with tolerance}\}\)  
Here, \(P_{1,\,2,3}\) represents a seed point for cylinder search. C1 selects and returns a random point from the PCD. C2 uses principal component analysis (PCA) to obtain plane equation coefficients from a given PCD. Using the plane and seed points, a circle can be constructed, and the center point \(P_{c}\) of the circle and the radius \(\text{r}\) can be obtained together. By acquiring the axis using the plane and \(P_{c}\), the cylinder shape can be calculated. All the included points are searched by applying tolerance to the calculated cylinder shape. The number of searched points is returned as \(number_{inlier}\). Repeat steps up to C1-7 so that \(\max(number_{inlier})\).  
The Elbow pipe extracts the straight pipe extracted from the point cloud data divided by segmentation, compares the points of each end point between the straight pipes, and extracts the point of the closest pipe as the connected pipe. Elbow pipe connection information is extracted through the direction information of the extracted pipes and the calculation of the intersection point.