Dxf three-dimensional reconstruction method based on scan line clustering and multi-layer topological measurement
The DXF 3D reconstruction method based on scanline clustering and multi-layer topology calculation solves the problems of low efficiency and poor adaptability in existing 3D reconstruction technologies, and achieves efficient and robust 3D reconstruction and lightweight generation, which is suitable for reverse engineering of mechanical structures.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-17
- Publication Date
- 2026-07-10
AI Technical Summary
Existing technologies suffer from problems in 3D reconstruction, including low efficiency, large human error, inability to adapt to non-standard layouts, insufficient support for entity types, poor robustness of view segmentation, insufficient coordinate mapping accuracy, inability to filter non-target content, lack of topological connectivity and surface information in point cloud data, and high computational resource consumption of traditional methods.
A DXF 3D reconstruction method based on scanline clustering and multi-layer topology calculation is adopted. The view point set is segmented by scanline gap analysis and density clustering algorithm. Combined with a topology connection calculation model with multi-layer spatial traversal and distance threshold screening, a 3D closed mesh is generated. The topology data of triangular patches is verified by vector cross product.
It achieves efficient and robust 3D reconstruction, adapts to various CAD entity types, supports non-standard layouts, generates high-precision 3D point clouds, reduces computing resource requirements, and is suitable for lightweight deployment and reverse engineering of mechanical structures.
Smart Images

Figure CN122368334A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer-aided design technology, and in particular to a DXF three-dimensional reconstruction method based on scan-line clustering and multi-layer topology calculation. Background Technology
[0002] DXF (Drawing Exchange Format) is a universal CAD file format developed by Autodesk, widely used for delivering two-dimensional engineering drawings in fields such as mechanical manufacturing, automotive engineering, and aerospace. In industrial product design and production processes, the design of many parts (such as vehicle radar brackets and mechanical structural components) still relies on the standard three-view drawing, consisting of a front view, a top view, and a left view, as the core carrier. However, the digital simulation, 3D printing, and reverse modeling of products all require converting the two-dimensional three-view drawing into a three-dimensional digital model.
[0003] Currently, there are two main types of 3D reconstruction technologies for engineering drawings: one is manual 3D modeling based on three-view drawings. This method relies on the professional experience of designers, is extremely inefficient, and prone to human error, making it unsuitable for processing batches of engineering drawings. The other is rule-based automatic reconstruction algorithms. These algorithms mostly only support three-view drawings with standard four-quadrant layouts, exhibiting extremely poor compatibility with non-standard layouts. Furthermore, existing methods suffer from the following core defects: insufficient support for entity types, failing to adapt to curved entities such as arcs and polylines; poor robustness in view segmentation, easily leading to missegmentation and omissions; failure to consider scaling and coordinate offset between three-view drawings, resulting in insufficient coordinate mapping accuracy; and lack of filtering capability for non-target content in the drawings, easily introducing noise.
[0004] Furthermore, with the development of 3D scanning technology and algorithms, acquiring 3D point cloud data of object surfaces has become increasingly convenient. However, the original discrete 3D point cloud data, whether acquired or generated from the aforementioned 2D drawings, only contains spatial coordinate information (X, Y, Z), lacking topological connections and surface information between points. This scattered point cloud cannot be directly applied to subsequent industrial processes such as lighting rendering and physics collision simulation. Traditional point cloud meshing methods (such as Poisson surface reconstruction or Delaunay triangulation) can generate smooth surfaces, but the algorithms are extremely complex, consume a large amount of computational resources, and are highly dependent on large third-party graphics libraries (such as PCL and CGAL). For lightweight deployment environments or basic mechanical parts with regular geometric features, traditional methods have long processing times, high computational costs, and high environmental configuration barriers.
[0005] Therefore, developing an efficient 3D surface reconstruction method that adapts to multiple entity types, supports non-standard layouts, does not rely on external complex operators, and is purely based on spatial geometric feature calculations has significant engineering application value. Summary of the Invention
[0006] The purpose of this invention is to overcome the above-mentioned shortcomings of the prior art and provide a DXF 3D reconstruction method based on scan line clustering and multi-layer topology calculation that is highly versatile, robust, lightweight, easy to deploy, and independent of third-party environments. It is compatible with various CAD entity types, realizes intelligent segmentation of non-standard layout three-view and high-precision 3D point cloud generation, and completes the reconstruction of 3D closed mesh.
[0007] The technical solution of this invention is: a DXF three-dimensional reconstruction method based on scan-line clustering and multi-layer topology calculation, comprising the following steps:
[0008] S1: Obtain the target engineering drawing, extract the two-dimensional point set from the preset target layer and preprocess it to obtain the preprocessed two-dimensional point set;
[0009] S2: Using the scan line gap analysis method and density clustering algorithm, the preprocessed two-dimensional point set is automatically identified and segmented into view point sets corresponding to multiple sets of different projection directions;
[0010] S3: Based on the orthographic projection rules, convert multiple sets of view point sets into a three-dimensional spatial point cloud, and standardize the three-dimensional spatial point cloud through spatial range calibration to obtain a standardized input point set;
[0011] S4: Construct a preliminary topology connectivity calculation model based on multi-level spatial traversal and distance threshold filtering;
[0012] S5: Using the standardized input point set, perform geometric feature matching and vector cross product verification on the preliminary topological connectivity calculation model to generate triangular patch topological data and output a three-dimensional model file.
[0013] Furthermore, the specific steps include:
[0014] S1: Obtain the target engineering drawing, perform equidistant sampling of the preset target layer in the drawing for multi-entity adaptation, extract a two-dimensional point set, and perform noise filtering on the two-dimensional point set;
[0015] S2: The scanning line gap analysis method is used to determine the segmentation boundary between views. The two-dimensional point set is clustered into multiple clusters by combining the density clustering algorithm. Based on the relative positional relationship between the center of each cluster and the segmentation boundary, and combined with the projection layout rules, the views corresponding to each cluster are assigned.
[0016] S3: Construct a 2D-3D coordinate transformation model to establish a mapping relationship. Based on the orthographic projection rule, generate a 3D spatial point cloud from multiple sets of view points. Then, standardize the 3D spatial point cloud through bounding box calibration to obtain a standardized input point set.
[0017] S4: Construct a multi-layer spatial traversal calculation mechanism, and calculate any three points in the standardized input point set as a detection combination. This includes: selecting any reference point and target point to calculate the spatial distance and comparing it with a preset threshold, retaining point pairs that meet the conditions, and then introducing a third point for adjacency determination. The point group consisting of three points that are determined to have adjacency characteristics is used as the preliminary topology connection calculation model.
[0018] S5: Use the standardized input point set to perform geometric feature matching on the point group in the preliminary topology connection calculation model, and combine the vector cross product operation to verify whether the three points are collinear. Output the valid triangular facet topology data that has passed the verification as a standard polygon file format to complete the 3D model reconstruction.
[0019] Furthermore, S1 specifically includes the following steps:
[0020] S1-1: Read the DXF file, obtain all entities in the model space, filter them according to the preset target layer, retain only entities in the target layer, exclude noise data from non-target layers, and obtain the target entity set.
[0021] S1-2: Traverse the target entity set, and extract two-dimensional coordinate points from the entity at fixed sampling intervals according to the type of each entity using the corresponding equidistant sampling method.
[0022] S1-3: Summarize all extracted 2D coordinate points to obtain the 2D point set of the target layer.
[0023] Furthermore, in S1, the equidistant sampling method of the entity includes at least one of the following:
[0024] Straight line entity: Equidistant sampling of the line segment between the start and end points;
[0025] Polyline entity: The polyline is split into straight line segments that are connected end to end. Each straight line segment is sampled using the sampling method of the straight line entity, and then spliced together to obtain a complete set of points.
[0026] Arc entity: Perform equidistant angular sampling on the arc;
[0027] Point entities: Directly extract the coordinates of the points and add them to the point set.
[0028] Furthermore, S2 specifically includes the following steps:
[0029] S2-1: Scan line gap analysis method: Set tolerance parameters, and perform binning statistics on the X and Y coordinates of the two-dimensional point set according to the tolerance parameters to obtain a point density histogram; find blank areas, and calculate the width of areas with adjacent index differences greater than 1; select the blank area with the largest width to calculate the dividing line, including vertical dividing lines and horizontal dividing lines;
[0030] S2-2: Density clustering algorithm: Set the neighborhood radius and minimum number of samples, use the DBSCAN clustering algorithm to cluster the two-dimensional point set to obtain multiple clusters, calculate the center coordinates of each cluster; according to the orthographic projection layout rules, based on the vertical and horizontal positional relationship of each cluster center relative to the vertical and horizontal dividing lines, determine the clusters as the front view, top view or left view respectively, and remove clusters that do not conform to the layout.
[0031] S2-3: Output the point set of the front view, the point set of the top view, and the point set of the left view.
[0032] Furthermore, S3 specifically includes the following steps:
[0033] S3-1: Perform offset normalization based on the minimum coordinates of each view to establish the mapping relationship between the coordinates of different views;
[0034] S3-2: Based on the orthographic projection law, traverse the point set of one view and perform coordinate matching and verification in the other two views. Restore the verified points to three-dimensional coordinate points, and obtain the three-dimensional spatial point cloud after deduplication.
[0035] S3-3: The spatial range calibration includes: extracting the minimum extreme points of the three-dimensional spatial point cloud in the X, Y, and Z directions, performing centering offset preprocessing on the original point cloud to center the model and obtain a standardized input point set.
[0036] Furthermore, S4 specifically includes the following steps:
[0037] S4-1: Select any point in the standardized input point set as the reference point, select another point as the target point, calculate the spatial distance between the two points using the Euclidean distance formula, set the lower and upper thresholds of the effective connection distance as the threshold interval, and retain the candidate connection between the two points only when the calculated spatial distance is within the threshold interval.
[0038] S4-2: Introduce a third candidate point and calculate the spatial distance from the candidate point to the reference point and the target point respectively. Only when both distances are less than the upper limit threshold, it is determined that the three points have close adjacency in space and form a potential triangular patch.
[0039] Furthermore, S5 specifically includes the following steps:
[0040] S5-1: For the three vertices of the potential triangular facet, starting from the first vertex, construct a first spatial vector pointing to the second vertex and a second spatial vector pointing to the third vertex;
[0041] S5-2: Calculate the spatial cross product of the first spatial vector and the second spatial vector, and calculate the magnitude of the spatial cross product;
[0042] S5-3: Set a collinearity rejection threshold. If the cross product modulus is greater than the threshold, it is determined that the three points are not collinear. The index values of the three vertices are output as valid triangle patches and stored in the topological face set.
[0043] S5-4: According to the general 3D graphics standard specifications, write the total number of vertices and the total number of faces into the file header, and generate a standard polygon file in PLY format by outputting the vertex spatial coordinate matrix first and then the triangular face index sequence, thus completing the 3D model reconstruction.
[0044] Further, in S2, the scan line gap analysis method specifically includes: setting a tolerance parameter t, and performing binning statistics on the X and Y coordinates of the two-dimensional point set according to the tolerance parameter t to obtain a point density histogram; wherein, the binning index in the X direction is... The Y-direction binning index is The vertical dividing line Horizontal dividing line ;
[0045] In the formula, This is the floor function; The starting bin index for the widest blank area along the X-axis; The end bin index of the widest blank area along the X-axis; The starting bin index for the widest blank area along the Y-axis; This is the end bin index for the widest blank area along the Y-axis.
[0046] Furthermore, in S2, the density clustering algorithm specifically includes: setting the neighborhood radius. With minimum sample size For a two-dimensional point set Perform clustering to obtain clusters. ; Calculate the center coordinates of each cluster: , ,in Number of points within a cluster; allocate views according to the orthographic projection layout rules:
[0047] Main view: Cluster center satisfies and ;
[0048] Top view: Cluster center satisfies and ;
[0049] Left view: Cluster center satisfies and ;
[0050] The remaining clusters were removed.
[0051] The beneficial effects of this invention are as follows: It solves the problem of extracting information from non-standard two-dimensional drawings by using a multi-entity adaptation sampling method and intelligent view segmentation; at the same time, it adopts a mechanism of multi-layer spatial traversal and distance threshold combined with vector cross product collinearity detection, which can independently generate three-dimensional closed meshes without the need for a large third-party algorithm library; it has good versatility, clear structure, and high lightweightness, and has strong applicability in rapid preview and reverse engineering of mechanical structures. Attached Figure Description
[0052] Figure 1 This is a schematic diagram of the method flow of an embodiment of the present invention, which uses engineering drawings of a vehicle-mounted radar bracket as the processing object;
[0053] Figure 2 This is a visualization of the segmentation result of the three-view drawing of the DXF drawing of the vehicle-mounted radar bracket in this embodiment. Detailed Implementation
[0054] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0055] The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation includes the following steps:
[0056] S101: Obtain the target engineering drawing, extract the two-dimensional point set from the preset target layer and preprocess it to obtain the preprocessed two-dimensional point set.
[0057] (1) DXF file reading and layer filtering: The target DXF file is read through the ezdxf library to obtain all entities in the model space. The target layer name (the default layer is "0") is used for filtering to retain only entities in the target layer and exclude noise data such as dimension lines, title blocks and title blocks that are not part of the target layer.
[0058] (2) Iso-distance sampling adapted for multiple entity types: For common entity types in engineering drawings, corresponding iso-distance sampling methods are designed to extract two-dimensional coordinate points at fixed sampling intervals, mainly including:
[0059] Line (LINE) entity sampling: This involves sampling the line segment between the start and end points of the line at equal intervals. Let the coordinates of the start point of the line be... The endpoint coordinates are The sampling interval is Then the length of the line segment is The number of sampling points is . No. The coordinates of the sampling points are , ,in , This is the floor function.
[0060] Polyline (LWPOLYLINE / POLYLINE) entity sampling: The polyline is split into straight line segments connected end to end. Each straight line segment is sampled at equal intervals using the above-mentioned straight line entity sampling method, and then spliced together to obtain a complete point set.
[0061] Arc Array (ARC) entity sampling: This involves sampling the arc at equal angular intervals. Let the center coordinates be... , radius is The starting angle is The termination angle is (Angle system), sampling interval is Convert to radians: , .like ,but Arc length Number of sampling points . No. The coordinates of the sampling points are ; , ,in .
[0062] Point entity sampling: directly extracting the coordinates of points. Join the dot set.
[0063] (3) Point set output: Summarize the sampled points to obtain the two-dimensional point set of the target layer. Complete data preprocessing.
[0064] The steps described above in this embodiment, by employing a multi-entity adaptation sampling method, can widely support curved entities such as arcs and polylines, automatically adapt to various complex geometric shapes, significantly reduce the risk of data loss or parsing failure due to limitations in entity types, and significantly reduce the workload of manual proofreading and redrawing, thereby improving the overall efficiency of digital drawing processing.
[0065] S102: Using the scan line gap analysis method and the DBSCAN density clustering algorithm, the preprocessed two-dimensional point set is automatically identified and segmented into view point sets corresponding to three different projection directions.
[0066] (1) Scan line gap analysis method:
[0067] Set tolerance parameters Adjust the X and Y coordinates according to tolerance Perform binning statistics; X-direction binning index , Y direction This yields the point density histogram;
[0068] Find blank areas and calculate the width of areas where the difference between adjacent indices is greater than 1.
[0069] Calculate the dividing line by selecting the widest blank area: Vertical dividing line Horizontal dividing line .
[0070] In the formula, The starting bin index for the widest blank area along the X-axis; The end bin index of the widest blank area along the X-axis; The starting bin index for the widest blank area along the Y-axis; This is the end bin index for the widest blank area along the Y-axis.
[0071] (2) DBSCAN density clustering algorithm:
[0072] Set neighborhood radius With minimum sample size Point set Perform clustering to obtain clusters. ;
[0073] Calculate the center coordinates of each cluster: , ( (Number of points within the cluster);
[0074] Views are allocated according to the orthographic projection layout rules:
[0075] Main view: Cluster center satisfies and ;
[0076] Top view: Cluster center satisfies and ;
[0077] Left view: Cluster center satisfies and The remaining clusters were removed.
[0078] (3) Output of view segmentation results: Output the main view point set Top view point set Left view point set .
[0079] The steps described in this embodiment, employing a dual-path view segmentation mechanism that combines scan line gap analysis and density clustering, significantly improve segmentation adaptability, anti-interference ability, extraction accuracy, and completeness compared to traditional fixed threshold segmentation, single scan line analysis, and single density clustering methods. The core advantages are as follows:
[0080] ① Complementary global prior and local distribution improve boundary segmentation accuracy: Traditional fixed threshold methods lack generalization ability, and single scan line methods are prone to misclassification of features such as arcs and protrusions at the view edges due to "one-size-fits-all" straight-line segmentation. Single clustering methods lack prior knowledge of drafting standards and cannot assign correct view semantics to clusters. This method first establishes a global segmentation benchmark that conforms to engineering drafting standards through the scan line method, providing a priori basis for view semantic allocation; then, it uses a clustering algorithm to characterize the actual outline of the view based on the spatial clustering of points, avoiding misclassification of edge geometric features. For example, in this embodiment, the arc protrusions at the edge of the main view that cross the segmentation line are correctly classified into the main view through clustering clustering determination, ensuring the integrity of the view boundary.
[0081] ② Breaking through the limitations of standard layouts and adapting to non-standard engineering drawings: Traditional rule-based methods strictly rely on the standard four-quadrant layout of "top left front view, bottom left top view, and top right left view," which is prone to omissions and misidentifications when view positions are offset or layouts are adjusted. This method outputs relative segmentation benchmarks using the scan line method, rather than being limited by absolute coordinates; it automatically identifies independent geometric point clusters within the drawing through clustering, and assigns view semantics based on the relative position of the cluster center and the segmentation benchmark, as well as the orthographic projection rules, without the need to preset the number and position of views. For example, in this embodiment, the top view located in the right-center region is still correctly identified, solving the industry pain point of failure in processing non-standard layout drawings.
[0082] ③ Balancing noise filtering and view integrity, adapting to complex drawing processing: Engineering drawings often contain noise such as isolated points and broken lines, and uneven point density can occur due to hollow structures. The single scanline method is easily affected by noise interference, leading to segmentation datum shifts, while the single clustering method easily splits an unevenly dense complete view into multiple sub-clusters, causing view fragmentation. This method uses DBSCAN outlier detection to remove discrete noise, ensuring the accuracy of the segmentation datum; simultaneously, it uses the global datum of the scanline method to constrain the clustering results, merging sub-clusters within the same segmentation region, avoiding view fragmentation and ensuring the integrity of views with complex structures such as hollow structures.
[0083] ④ Strong adaptability and engineering suitability, supporting batch automated processing: Traditional methods require manual adjustment of segmentation coordinates and core parameters for each drawing, making batch processing impossible. The core parameters of this method are set based on general mechanical engineering drawing standards, ensuring strong versatility; the calculation of segmentation datum and the allocation of cluster views are dynamically completed based on the point distribution characteristics of the drawing itself, requiring no manual intervention. It can adapt to mechanical part drawings of different sizes, scales, and layouts, meeting the automated processing needs of batch 3D reconstruction of drawings in industrial scenarios and significantly reducing labor costs.
[0084] S103: Based on the orthographic projection rules, the three sets of view point sets are converted into a three-dimensional spatial point cloud, and the three-dimensional spatial point cloud is standardized by bounding box calibration to obtain a standardized input point set.
[0085] (1) Coordinate normalization and mapping: offset is performed based on the minimum coordinate of the view.
[0086] Offset reference: , ;
[0087] Normalized coordinates: , ;
[0088] Establish mapping relationships between coordinates of different views, for example, establishing a mapping relationship from the Y coordinate of the top view to the X coordinate of the left view: , ;
[0089] In the formula, The maximum Y-coordinate of all points in the top view point set; For the point set in the top view
[0090] The minimum y-coordinate of a point; The maximum X-coordinate of all points in the left view point set; It is the minimum X-coordinate of all points in the left view point set.
[0091] Scaling ratio: Offset: ;
[0092] Mapping formula: ;
[0093] Constructing a system based on matching tolerance Fast lookup index With verification set .
[0094] (2) 3D point matching: Based on the rule of "length aligned, height aligned, and width equal", the point set of the main view is traversed. Search for the matching condition in the top view index. candidate points Convert its Y-coordinate to the X-coordinate of the left view. Verify that the following conditions are met in the left view. and If the verification passes, the DXF coordinates are restored to obtain the 3D point. After deduplication, unique three-dimensional points are retained to form a three-dimensional point cloud.
[0095] (3) Bounding box analysis and preprocessing: Extracting the generated bounding box Given a set of three-dimensional coordinate points, iterate through the data to find the set of minimum and extreme points in the three-dimensional space. The original point cloud is preprocessed with a centering offset to center the model, as calculated below:
[0096]
[0097]
[0098]
[0099] The processed data is used to construct a standardized set of input points.
[0100] The steps described above in this embodiment convert the three sets of view point sets into a three-dimensional spatial point cloud according to the orthographic projection rules. This strictly maintains the geometric correspondence between the original views and avoids projection distortion or coordinate misalignment. Furthermore, the three-dimensional spatial point cloud is standardized through bounding box calibration, which can achieve scale normalization and coordinate alignment of the point cloud, eliminating inconsistencies caused by different view scales and placement positions. This results in a standardized input point set, providing unified and reliable input data for subsequent topology calculations or mesh generation.
[0101] S104: Construct a preliminary topology connectivity calculation model based on multi-level spatial traversal and distance threshold filtering.
[0102] Specifically, a multi-layer spatial traversal calculation block is constructed so that any three points in space are used as a detection combination for calculation; the workflow of each combination includes: a first-layer spatial distance calculation module and a second-layer triangular closure calculation module.
[0103] (1) First-level spatial distance calculation module: adopts a standardized input point set and selects any reference point. With the target point Their spatial proximity is calculated using the Euclidean distance formula:
[0104]
[0105] Set valid connection threshold range Only when If the candidate connection is not found, retain it and proceed to the next module.
[0106] (2) Second-layer triangular closure calculation module: Introducing a third candidate point To find coplanar points to form a valid polygonal surface, calculate respectively arrive and spatial distance and Only when and When the three points are determined to be closely adjacent in space, forming a potential triangular patch, a preliminary topological connection calculation model is obtained.
[0107] The above steps in this embodiment, by constructing a multi-layered spatial traversal calculation block, have the core advantage of achieving reliable local topology construction with the lowest computational environment threshold. While ensuring the legality of the model, it greatly reduces computational costs and environment configuration difficulties. By combining distance calculation with triangular closure calculation, it can avoid the algorithm from incorrectly connecting the endpoints at both ends of the model; on the other hand, it can automatically filter out self-intersection points and far endpoints, ensuring that the calculation is only performed within the local neighborhood, thereby improving the accuracy of triangulation matching; furthermore, the multi-layered nested module design ensures the rationality of topological connections: that is, by distance calculation, it can filter out candidate line segments that are spatially close; by triangular closure, it can further introduce a third point, and by using distance constraints to determine whether the three points have the "closely adjacent characteristic", thereby initially locking in potential triangular faces.
[0108] The steps described above in this embodiment, through a mechanism based on geometric feature matching, make the algorithm highly applicable in rapid previewing and reverse engineering of mechanical structures, enabling rapid data visualization.
[0109] S105: Using the standardized input point set, perform geometric feature matching and vector cross product verification on the preliminary topological connectivity calculation model to generate triangular patch topological data and output a three-dimensional model file.
[0110] (1) Using a third-layer vector cross product and collinearity detection module: To prevent degenerate surfaces caused by three points being collinear, a spatial vector cross product algorithm is used for geometric validity verification. Constructing spatial vectors: , Calculate the spatial cross product of two vectors. The components are represented as:
[0111]
[0112]
[0113]
[0114] Then calculate the modulus of the cross product: Set a collinearity rejection threshold. (like ).like If the three points are not collinear, then their corresponding index values are determined. As valid triangular facets, they are output and stored in the topological facet set.
[0115] (2) Model Reconstruction Output: According to the general 3D graphics standard specifications, the total number of vertices and the total number of faces are written into the file header. Following the order of outputting the vertex spatial coordinate matrix first and then the triangular face index sequence, a PLY (Polygon File Format) standard model file with face attributes and geometric features is generated, completing the conversion from discrete point cloud to solid surface mesh, thereby completing the 3D model reconstruction.
[0116] The above steps in this embodiment, by employing a vector cross product and collinearity detection module, mainly address the topology quality issue during the reconstruction process, and have the following advantages:
[0117] ① It can effectively identify and remove "linear" patches with an area of zero or close to zero caused by three points being collinear;
[0118] ② Ensure the generated mesh conforms to the standards of the computer graphics rendering pipeline to avoid problems in subsequent lighting rendering or physical simulation.
[0119] An error occurred;
[0120] ③ By calculating the magnitude of the cross product of vectors and setting a threshold, we can use quantitative methods to accurately determine whether three points meet the conditions for forming a surface;
[0121] ④ Ensure the output index value All of these are valid geometric features, providing a high-quality data foundation for generating standard PLY model files.
[0122] The above steps in this embodiment, by combining two-layer calculation with cross product detection, have the following advantages:
[0123] ① By combining the first and second layers (distance and closure calculation) with the third layer (cross product detection), a complete screening system from spatial proximity to geometric validity is constructed;
[0124] ② No complex partial differential equations need to be solved or a large third-party algorithm library (such as PCL, CGAL) is required; three-dimensional closed meshes can be generated independently using only pure geometric features.
[0125] ③Threshold intervals through effective connections It can quickly filter out self-intersections and far endpoints, narrowing the search range;
[0126] ④ Performing fine-grained verification within a local neighborhood ensures that each retained facet has actual physical meaning;
[0127] ⑤ This combination method has a clear structure and good versatility, making it particularly suitable for rapid previewing in reverse engineering of mechanical structures. It can efficiently convert the original discrete point cloud into a PLY model with solid surface features, and has strong industrial applicability.
[0128] ⑥ Through the progressive coordination of these three layers of logic, the algorithm achieves highly reliable model reconstruction while ensuring low computing power cost.
[0129] like Figure 1 As shown: This embodiment uses the vehicle-mounted radar bracket engineering drawing "radar bracket.dxf" as the processing object to describe the specific implementation of the present invention in detail:
[0130] Step S1. DXF file parsing and point set sampling:
[0131] In this embodiment, a sampling interval is set. The target layer is the default layer "0". The file is read using the ezdxf library. LINE entities within the layer are sampled at 1.0mm intervals; LWPOLYLINE entities are split into single straight lines and sampled segment by segment; ARC entities are sampled at 1.0mm arc length intervals. The final result is a two-dimensional point set with a total of 1095 points, completing the data preprocessing.
[0132] Step S2. Intelligent segmentation of three views, such as... Figure 2 As shown:
[0133] In this embodiment, a tolerance is set. DBSCAN clustering parameters , .
[0134] (1) Scan line gap analysis method: The vertical dividing line is obtained by statistical analysis of the X and Y directions. Horizontal dividing line .
[0135] (2) DBSCAN clustering and assignment: Four valid clusters were found. Cluster 0 center (2650.2, 1150.7) was assigned to the main view (225 points); Cluster 2 center (2948.6, 1180.2) was assigned to the left view (124 points); Cluster 1 center (2950.5, 1050.3) was assigned to the top view (475 points); Cluster 3 was determined to be the title bar and was removed.
[0136] Step S3. 3D point cloud matching and bounding box centering processing
[0137] (1) Coordinate mapping: Normalize the front view offset datum (2500.0, 1025.0), top view (2850.0, 1025.0), and left view (2850.0, 1100.0); calculate the Y coordinate mapping relationship and obtain the scaling ratio. Offset And build a binned fast index.
[0138] (2) Set matching tolerance Traverse the point set of the main view, verify the coordinate matching at the intersection of the top view and the left view, and generate a total of 862 valid 3D points after deduplication.
[0139] (3) Call the analyzePoints module to analyze the boundaries of the 862 points and obtain the results. Maximum and minimum values for each dimension; subtract the minimum value from each point to center the model, construct a standardized set of input points, and prevent the generated model from falling out of view in the 3D viewer.
[0140] Step S4. Multi-layer spatial topology calculation: Construct a spatial retrieval mechanism based on a three-layer nested loop, and set upper and lower thresholds for spatial distance. Filter out self-intersections and far endpoints to lock local neighborhood candidate points. .
[0141] Step S5. Geometric verification and PLY output:
[0142] (1) To eliminate the degenerate feature surface, a local direction vector is constructed. and And solve for its cross product modulus; when the modulus is greater than the set collinearity exclusion parameter When the triangle is valid, its index is recorded.
[0143] (2) Call the vector cross product and collinearity detection module, strictly adhering to the standard PLY file structure. Declare PLY and Format ascii 1.0; write the Element vertex and its coordinate attributes; write the Element face and its index list (in 3 abc format). The final exported file can be directly previewed in mainstream 3D software such as MeshLab, completing the full-link reconstruction from DXF drawing to 3D surface mesh.
[0144] In summary, this invention solves the problem of extracting information from non-standard two-dimensional drawings through a multi-entity adaptation sampling method and intelligent view segmentation; at the same time, it adopts a mechanism that combines multi-layer spatial traversal with distance thresholding and vector cross product collinearity detection, which can independently generate three-dimensional closed meshes without the need for a large third-party algorithm library; it has good versatility, clear structure, and high lightweightness, and has strong applicability in rapid preview and reverse engineering of mechanical structures.
Claims
1. A DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation, characterized in that, Includes the following steps: S1: Obtain the target engineering drawing, extract the two-dimensional point set from the preset target layer and preprocess it to obtain the preprocessed two-dimensional point set; S2: Using the scan line gap analysis method and density clustering algorithm, the preprocessed two-dimensional point set is automatically identified and segmented into view point sets corresponding to multiple sets of different projection directions; S3: Based on the orthographic projection rules, convert multiple sets of view point sets into a three-dimensional spatial point cloud, and standardize the three-dimensional spatial point cloud through spatial range calibration to obtain a standardized input point set; S4: Construct a preliminary topology connectivity calculation model based on multi-level spatial traversal and distance threshold filtering; S5: Using the standardized input point set, perform geometric feature matching and vector cross product verification on the preliminary topological connectivity calculation model to generate triangular patch topological data and output a three-dimensional model file.
2. The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation according to claim 1, characterized in that, Specifically, the following steps are included: S1: Obtain the target engineering drawing, perform equidistant sampling of the preset target layer in the drawing for multi-entity adaptation, extract a two-dimensional point set, and perform noise filtering on the two-dimensional point set; S2: The scanning line gap analysis method is used to determine the segmentation boundary between views. The two-dimensional point set is clustered into multiple clusters by combining the density clustering algorithm. Based on the relative positional relationship between the center of each cluster and the segmentation boundary, and combined with the projection layout rules, the views corresponding to each cluster are assigned. S3: Construct a 2D-3D coordinate transformation model to establish a mapping relationship. Based on the orthographic projection rule, generate a 3D spatial point cloud from multiple sets of view points. Then, standardize the 3D spatial point cloud through bounding box calibration to obtain a standardized input point set. S4: Construct a multi-layer spatial traversal calculation mechanism, and calculate any three points in the standardized input point set as a detection combination. This includes: selecting any reference point and target point to calculate the spatial distance and comparing it with a preset threshold, retaining point pairs that meet the conditions, and then introducing a third point for adjacency determination. The point group consisting of three points that are determined to have adjacency characteristics is used as the preliminary topology connection calculation model. S5: Use the standardized input point set to perform geometric feature matching on the point group in the preliminary topology connection calculation model, and combine the vector cross product operation to verify whether the three points are collinear. Output the valid triangular facet topology data that has passed the verification as a standard polygon file format to complete the 3D model reconstruction.
3. The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation according to claim 1 or 2, characterized in that, S1 specifically includes the following steps: S1-1: Read the DXF file, obtain all entities in the model space, filter them according to the preset target layer, retain only entities in the target layer, exclude noise data from non-target layers, and obtain the target entity set. S1-2: Traverse the target entity set, and extract two-dimensional coordinate points from the entity at fixed sampling intervals according to the type of each entity using the corresponding equidistant sampling method. S1-3: Summarize all extracted 2D coordinate points to obtain the 2D point set of the target layer.
4. The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation according to claim 3, characterized in that, In S1, the equidistant sampling method of the entity includes at least one of the following: Straight line entity: Equidistant sampling of the line segment between the start and end points; Polyline entity: The polyline is split into straight line segments that are connected end to end. Each straight line segment is sampled using the sampling method of the straight line entity, and then spliced together to obtain a complete set of points. Arc entity: Perform equidistant angular sampling on the arc; Point entities: Directly extract the coordinates of the points and add them to the point set.
5. The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation according to claim 1 or 2, characterized in that, S2 specifically includes the following steps: S2-1: Scan line gap analysis method: Set tolerance parameters, and perform binning statistics on the X and Y coordinates of the two-dimensional point set according to the tolerance parameters to obtain a point density histogram; find blank areas, and calculate the width of areas with adjacent index differences greater than 1; select the blank area with the largest width to calculate the dividing line, including vertical dividing lines and horizontal dividing lines; S2-2: Density clustering algorithm: Set the neighborhood radius and minimum number of samples, use the DBSCAN clustering algorithm to cluster the two-dimensional point set to obtain multiple clusters, calculate the center coordinates of each cluster; according to the orthographic projection layout rules, based on the vertical and horizontal positional relationship of each cluster center relative to the vertical and horizontal dividing lines, determine the clusters as the front view, top view or left view respectively, and remove clusters that do not conform to the layout. S2-3: Output the point set of the front view, the point set of the top view, and the point set of the left view.
6. The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation according to claim 1 or 2, characterized in that, S3 specifically includes the following steps: S3-1: Perform offset normalization based on the minimum coordinates of each view to establish the mapping relationship between the coordinates of different views; S3-2: Based on the orthographic projection law, traverse the point set of one view and perform coordinate matching and verification in the other two views. Restore the verified points to three-dimensional coordinate points, and obtain the three-dimensional spatial point cloud after deduplication. S3-3: The spatial range calibration includes: extracting the minimum extreme points of the three-dimensional spatial point cloud in the X, Y, and Z directions, performing centering offset preprocessing on the original point cloud to center the model and obtain a standardized input point set.
7. The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation according to claim 1 or 2, characterized in that, S4 specifically includes the following steps: S4-1: Select any point in the standardized input point set as the reference point, select another point as the target point, calculate the spatial distance between the two points using the Euclidean distance formula, set the lower and upper thresholds of the effective connection distance as the threshold interval, and retain the candidate connection between the two points only when the calculated spatial distance is within the threshold interval. S4-2: Introduce a third candidate point and calculate the spatial distance from the candidate point to the reference point and the target point respectively. Only when both distances are less than the upper limit threshold, it is determined that the three points have close adjacency in space and form a potential triangular patch.
8. The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation according to claim 7, characterized in that, S5 specifically includes the following steps: S5-1: For the three vertices of the potential triangular facet, starting from the first vertex, construct a first spatial vector pointing to the second vertex and a second spatial vector pointing to the third vertex; S5-2: Calculate the spatial cross product of the first spatial vector and the second spatial vector, and calculate the magnitude of the spatial cross product; S5-3: Set a collinearity rejection threshold. If the cross product modulus is greater than the threshold, it is determined that the three points are not collinear. The index values of the three vertices are output as valid triangle patches and stored in the topological face set. S5-4: According to the general 3D graphics standard specifications, write the total number of vertices and the total number of faces into the file header, and generate a standard polygon file in PLY format by outputting the vertex spatial coordinate matrix first and then the triangular face index sequence, thus completing the 3D model reconstruction.
9. The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation according to claim 5, characterized in that, In S2, the scan line gap analysis method specifically includes: setting a tolerance parameter t, and performing binning statistics on the X and Y coordinates of the two-dimensional point set according to the tolerance parameter t to obtain a point density histogram; wherein, the binning index in the X direction is... The Y-direction binning index is The vertical dividing line Horizontal dividing line ; In the formula, This is the floor function; The starting bin index for the widest blank area along the X-axis; The end bin index of the widest blank area along the X-axis; The starting bin index for the widest blank area along the Y-axis; This is the end bin index for the widest blank area along the Y-axis.
10. The DXF 3D reconstruction method based on scan-line clustering and multi-layer topology calculation according to claim 9, characterized in that, In S2, the density clustering algorithm specifically includes: setting the neighborhood radius. With minimum sample size For a two-dimensional point set Perform clustering to obtain clusters. ; Calculate the center coordinates of each cluster: , ,in Number of points within a cluster; allocate views according to the orthographic projection layout rules: Main view: Cluster center satisfies and ; Top view: Cluster center satisfies and ; Left view: Cluster center satisfies and ; The remaining clusters were removed.