BRep Boundary and Junction Detection for CAD Reverse Engineering

In machining process, 3D reverse engineering of mechanical system is an integral, highly important, and yet time consuming step to obtain parametric CAD models from 3D scans. Therefore, deep learning-based Scan-to-CAD modeling can offer designers enormous editability to quickly modify CAD model, being able to parse all its structural compositions and design steps. In this paper, we propose a supervised boundary representation (BRep) detection network BRepDetNet from 3D scans of CC3D and ABC dataset. We have carefully annotated the ~50K and ~45K scans of both the datasets with appropriate topological relations (e.g., next, mate, previous) between the geometrical primitives (i.e., boundaries, junctions, loops, faces) of their BRep data structures. The proposed solution decomposes the Scan-to-CAD problem in Scan-to-BRep ensuring the right step towards feature-based modeling, and therefore, leveraging other existing BRep-to-CAD modeling methods. Our proposed Scan-to-BRep neural network learns to detect BRep boundaries and junctions by minimizing focal-loss and non-maximal sup-pression (NMS) during training time. Experimental results show that our BRepDetNet with NMS-Loss achieves impressive results.


I. INTRODUCTION
General purpose computer-aided design (CAD) modeling, using many modern APIs [2], [3], [18], [19], greatly assists in the agile process of Computer-Aided Manufacturing (CAM) and commercial applications [1] at industrial scale.Such a process requires skilled engineers and designers to aid in the creation, modification, analysis, or optimization of a design [17].The same expertise is needed when the physical object of the design is available.In this context, there has been a huge recent interest in CAD reverse engineering [7], which was made possible thanks to the availability of highly accurate 3D scanners 1 .
How important is fast track '3D Reverse Engineering (RE)' of mechanical system?While the machining process starts with ready-made CAD models and ends with component manufacturing, RE starts with 3D scanning of either damaged parts, archived components, or any spare parts and ends with deducing its parametric CAD model.However, the purpose of RE is not limited to scanning a physical object to obtain a reliable 3D scan, and then concluding the CAD model.Being able to deduce -(i) the intermediate designing steps, (ii) the history of modifications that are involved in parametric modeling of geometric primitives, (iii) designer's intent to order the CAD primitives (e.g.,, plane, cylinders, cones) along with different CAD operation steps (e.g.,, chamfer, extrusion, revolution, fillet) are the main stages of RE.Therefore, RE can fix the damaged parts of any mechanical system through fasttrack prototyping, mass manufacturing, quality analysis, and other downstream application tasks for analyzing structural compositions of real objects.
Why Boundary Representation (BRep) of CAD is ideal for deep learning-based RE? 3D scans are unstructured representations and are different from CAD models, which are generally stored in their STandard for the Exchange of Product (STEP) [4] file format and represented as Boundary-Representations (BReps) [26].Consequently, the first step towards successful CAD reverse engineering is to learn/infer BRep [26] representation from its corresponding 3D scan, namely Scan-to-BRep.This step is considered as the gateway for numerous downstream CAD modeling applications like -grouping and segmentation of BRep faces [8], [11], [14], deducing machining features [6], retrieving CAD sketches [8], predicting mating components for assembling multiple CAD models [12].
Our proposed method brings the problem of 3D scan to BRep parsing closer to real-world settings.In particular, we annotate ∼50K real 3D scans of CC3D [5] and ∼45K highresolution meshes of ABC [13] datasets with BRep edge, face, and their topological information.In particular, a pervertex annotation is considered in terms of BRep boundaries and junctions.To understand the BRep chain complex, in other words, the adjacency systems between BRep body, face, boundary, junction, co-edge/boundary loop, shell, fin, and region entities, one must parse it into different 'closed and connected loops of co-edges (CCLC)'.Therefore, once the boundary loops and junction points are detected in a given scan, the next steps like segmenting and grouping them into their respective BRep entities, fitting parametric curves and surfaces on the segmented boundaries and faces [10], [22], inferring the CAD construction steps and operation types involved at each step [8], and retrieval of base sketches [21] follow on.Parsing BRep from 3D scans can also be seen as geometric computation with its chain complexes [9].Once arXiv:2409.14087v1[cs.CV] 21 Sep 2024 the BRep representation is learned, we gain complete control BRep chain complex (refer to [10] for the definition).

Contributions. (1)
We contribute in preparing annotations (ensuring through quality measurements) for deriving BRep chain complex on industrial-level 3D scans from CC3D [5] and ABC [13] datasets.(2) Besides, we propose a new network for boudary and junction points detection from a 3D scan.(3) For this task, the existing state-of-the-art methods [20], [22] rely upon non-maximal suppression (NMS) as a post-prediction step to heuristically prune large number of incorrect predictions.In contrast, our detection network includes a novel way to marginalize false positives/negatives directly during training time.This results in impressive boundary and junction detection recall gains compared to other methods.(4) Source code is available here https://github.com/saali14/Scan-to-BRep. Formally, a BRep topology T = (B, J , F , A) is defined by sets of faces F , edges E, boundaries B, junctions J , and an adjacency system A = (N , P, M) ∈ {0, 1} |B|×|B| that ensures directed topological walk along the boundaries to traverse from current edge/face/junction to its next N , previous P, and mating M counterparts is possible.We redirect readers to [14] 1 are stored for each scan point belonging to B / J / F .Among the existing datsets [5], [13], [24] that are dedicated to feature-based CAD modeling/reconstruction purposes, typical shortfalls are -(i) unavailability of 3D scans (often substituted by CAD models), (ii) sharp-edge labels.Note that those boundaries which has with small acute angle between its adjacent BRep faces.The main difficulty of detecting boundary/junction points is that they can be smooth and seamless (see the vertical rule along the cylindrical barrel in Figure 1).(iii) CAD construction step labels per BRep entity (mainly the faces), and (iv) the CAD operations (e.g.,extrusion, fillet, cut, chamfer) involved in those construction steps, and (v) proper segmentation labels of scan points w.r.t their respective BRep entities (as well as their parameters).The previous variants of CC3D dataset [5], [8] provide annotations mentioned in (i) -(iv).We have complemented annotations in (v).We encourage the community to use our annotations in the future.We perform a crucial annotation quality assessment over all samples of CC3D dataset.For this, we compute inverse of uni-directional and density-aware Chamfer-distance [25] from parametric BRep Boundary S B to 3D real scan S in logarithmic scale as:

A. Annotation Quality Assessment
and compare the same measurement when computed from the parametric BRep Boundary S B to the parametric CAD model of the scan.The figure 2-(a) illustrates a larger percentage of models has significantly higher quality scores when annotations are compared against real scans.This re-affirms that our scan-to-BRep annotations are closer to the realworld setting.It is common that real scans are partial and noisy than their CAD versions which are regular/smooth and complete (see the color-coded Hausdorff distances from scanto-CAD in figure 2-(a)).Therefore, it is necessary to not have annotations that are overly-smoothed like parametric BRep entities.Besides, the figure 2-(b) also shows a comprehensive statistics on both CC3D and ABC models in terms of overall model complexities.For instance, it is clear that area covered under density plots for different sets parametric curves per model is several times more in CC3D than ABC.

B. BRep Boundary Detection
To formalize the problem of classifying each point as either a boundary point or an interior point of a 3D scan S ∈ R N ×3 , we learn a function f θ : R 3 → {0, 1} that maps each point p i to a label y i .Here y i = 0 indicates an interior point, and y i = 1 indicates a boundary point.The function f θ is parameterized by a neural network weights θ.We use focal loss (FL) [15] as an extension of the binary cross-entropy loss and is designed to address class imbalance.It adds a modulating factor (1 − p t ) γ to the cross-entropy loss, where p t is the true class probability and γ is the focusing parameter as: Non-Maximal Suppression (NMS) [16] technique is primarily used in object detection tasks to eliminate multiple bounding boxes that are close to each other and keep only the most probable one.We have introduced NMS loss for boundary detection L b NMS (θ) during the training time as a differentiable approximation to the actual NMS operation: (3) L b NMS (θ) represents the Non-Maximal Suppression Classification loss for a particular prediction p i = f θ (p i ) and target label t i .N is the total number of predictions, where p i is the predicted probability of a point being at the boundary of S and α is a hyperparameter that controls the balance between the two terms in the loss.It's typically set between 0.25 and 0.75.L b NMS (θ) penalizes both false positives and negatives.
This encourages the model to produce more accurate boundary scores.Therefore our total loss for boundary detection is

C. B-Rep Junction Detection
Detecting the B-Rep junction points is considered as a subordinate task after boundary detection.Let B be the set of points detected as boundary points (note, this includes false positives but not the false negative points).A second neural network g ϕ (x) is trained to classify these as either corner points or not.The loss function for this second task is also the binary cross-entropy but restricted to the boundary points: where z i denotes label values for x i being a junction or not.
Similarly, the NMS loss L J NMS and total loss L J total for junction detection are equivalent to the Eq. ( 3) and ( 4) respectively.

IV. EXPERIMENTAL RESULTS
We have used 10K randomly sampled scan points as input to out boundary detection head and 4K randomly sampled points from the detected boundaries to the junction detection head.Suppose, during inference time, if the resulting number of boundary points is below the required number of 4K input points, they are randomly up-sampled with duplicated matches.We train our network with batch size 10 and learning rate 0.001 on a 48GB NVIDIA GPU.

A. Baseline Models
We evaluate our proposed approach on ComplexGen [10] and PieNet [22].Both the baseline models and our proposed BRepDetNet are trained on ABC [13] dataset and tested on ABC [13] and CC3D [5] dataset for a consistent comparison.For PieNet, we only show the results for boundary prediction due to its unstable training and crashing during inference for junction detection.

B. Comparison with The Baseline Models
Table I provides the quantitative results on boundary and junction prediction tasks for ABC [13] and CC3D [5] dataset.We measure recall and precision metrics as  I, our method outperforms the baselines in recall and precision for both boundary and junction detection.Our method shows significantly higher accuracy in terms of precision-recall combined measure.For instance, Com-plexGen method detects fewer boundary points and miss to detect a large amount.Although, it does not detect false    positives/negatives as compared to PieNet.In contrast to boundary prediction, detecting junction points is more difficult as they are often less than ∼ 1% of the total boundary points.As in Table I, BRepDetNet shows significant improvement in recall compared to the state-of-the-art methods for junction detection tasks.We also observe that despite being trained on a clean and noise free meshes of ABC [13] dataset, our model generalizes well on real 3D scans.The result surpasses that of baseline models in cross-dataset experiments on CC3D [5].
Figure 4 shows some qualitative results between the baseline models and BrepDetNet.As shown, our model predicts more accurate boundary points (red points) compared to other methods.Furthermore, it can be seen that most of the false positive predictions for BRepDetNet are close to the groundtruth boundary points.Thanks to the NMS loss, furthest nonboundary points are not misclassified like PieNet [22].

C. Ablation Study
In this section, we showcase the effectiveness of NMS loss and .Table II reports the precision and recall for the boundary prediction using BRepDetNet with and without NMS loss.In Figure 5, some visual results are provided.To evaluate the performance, we trained both models on ABC [13] and tested on both ABC [13] and CC3D [5] datasets.We use the same strategy with CC3D [5] dataset.This results in four different experimental scenarios as shown in Table II.We observe that using NMS Loss significantly improves the precision in all four scenarios.This can be explained by the reduction of misclassified boundary points.As demonstrated in Figure 5, NMS loss leads to a lower number of false positives.

V. LIMITATION AND CONCLUSION
In this paper, we propose BRepDetNet, a supervised boundary and junction detection network as the Scan-to-BRep step for 3D reverse engineering.We offer both topological and geometrical annotations that relates 3D real scans with its BRep chain complex.Our proposed approach outperforms the baseline models on both ABC [13] and CC3D [5] datasets.As part of future extension, we plan to make our network end-toend trainable and resilient even when the annotation quality is poor.We also notice some degree of mis-classification of boundary points directly affect the subsequent junction prediction.Therefore, improving a joint learning of boundary and junction detection tasks, followed by segmentation, and grouping of BRep entities will also be part of our future work.

Fig. 1 .
Fig. 1.The left figures relate a 3D scan with its corresponding BRep topology (color-coded by unique edge and different closed-loop ids).A list of BRep annotations per scan point (on the right) covers all attributes under CCLC.
and the Figure 1 to understand how different edges form a boundary, how boundaries form closed loops, and how loops form a closed CAD manifold.Each of the BRep topological entities are parametric -e.g., edges are either spline, arc, lines, ellipse or other types of curves, whereas faces are planar, B-Spline, parabolic or other types of surfaces -with unique ids based on forward/reverse order of the topological walk along the B. The figure 1 illustrates how a 3D scan S and the aforementioned BRep topology is related.For instance, the overlaid scan points S B and S J , that are annotated as B and J , are decomposed into closed-loops sharing sharing boundaries.We do not clutter the figure by showing rest of the scan points S F that are annotated different face Ids from F .The list of attributes in figure
Positives to evaluate the performance of the baseline methods.As shown in Table

Fig. 4 .Fig. 5 .
Fig.4.Visual results for boundary (left) and junction (right) prediction on ABC[13] (top) and CC3D[5] (bottom) dataset.The red points are the boundary points and the green points are the junction points.All the models have been trained on ABC[13] dataset.

TABLE I RECALL
[13]PRECISION FOR THE BOUNDARY AND JUNCTION DETECTION ON ABC[13](LEFT) AND CC3D[5](RIGHT) DATASET.ALL THE MODELS ARE TRAINED ON ABC[13]DATASET.

TABLE II QUANTITATIVE
RESULTS FOR BREPDETNET WITH OR WITHOUT NMS LOSS.RECALL AND PRECISION FOR BOUNDARY DETECTION ON ABC [13] AND CC3D [5] DATASET ARE REPORTED.WE ALSO SHOWCASE CROSS-DATASET GENERALIZATION ABILITY OF OUR MODEL.