A method, device and electronic device for extracting DXF drawings

By automatically identifying and processing closed contours in DXF drawings, the problem of excessive dependence on layer annotation in the prior art is solved, and the accuracy and efficiency of analysis are improved.

CN119004706BActive Publication Date: 2025-06-24JIAXING YUNCUT SUPPLY CHAIN MANAGEMENT CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411183337.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-27
Publication Date
2025-06-24
Estimated Expiration
2044-08-27

AI Technical Summary

Technical Problem

The existing DXF drawing automatic parsing technology over-rely relies on layer annotation, resulting in inaccurate parsing and inefficient efficiency.

Method used

By automatically identifying and processing closed contours in DXF drawings, a preset contour algorithm is used to identify the number, layout and relative position of closed contours, thereby extracting effective closed contours.

Benefits of technology

It improves the accuracy and efficiency of DXF drawing analysis, avoids problems caused by layer name errors, and realizes automatic identification and extraction of multiple elements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119004706B_ABST
    Figure CN119004706B_ABST
Patent Text Reader

Abstract

A method, device, and electronic device for extracting DXF drawings, which relate to the CAD field. In this method, the primitives included in the DXF drawing are read, and the primitives include line segments and arcs; the primitives are preprocessed to determine the key attributes of the primitives, and the key attributes include the starting coordinates and the ending coordinates; according to the key attributes, the closed contours in the DXF drawing are determined; a preset contour algorithm is used to identify the closed contours to obtain the number, layout, and relative positions of the closed contours; the valid closed contours are determined from multiple closed contours according to the number, layout, and relative positions; and the valid closed contours are output in the standard DXF format. Implementing the technical solution provided by this application solves the problem of over-reliance on layer annotation in the related art by automatically identifying and processing closed contours, and improves the accuracy of DXF drawing parsing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of CAD, and specifically relates to a method, device, and electronic device for extracting DXF drawings. Background Art

[0002] The DXF file format is a CAD data exchange file format. It is designed to ensure the exchange of drawing data between different drawing software. Due to its open nature and ease of parsing, DXF files have become one of the most widely used drawing exchange formats in engineering design, architecture, and manufacturing. It supports various primitive types such as line segments, arcs, and polygons, and can save information such as layers, colors, and dimensions, making the transfer of design data more efficient and accurate. With the development of computer technology, the automatic parsing technology of DXF drawings has received increasing attention. This technology enables users to automatically extract key data from drawings, thereby realizing automatic quotation, computer-aided design, and automated operations in the production process. For example, on a custom processing website, by automatically parsing DXF files, the cost of required materials and processing time can be calculated immediately, greatly improving work efficiency and customer response speed. In addition, the automatic parsing technology also supports quickly importing and modifying drawings in computer-aided design software, as well as directly reading and applying drawing data on the production line.

[0003] Currently, the main defect of the existing DXF drawing automatic parsing technology lies in its excessive dependence on layer annotations. Due to differences in layer annotation habits and specifications among different users, and the inevitable human errors, the existing technology often can only automatically parse a small part of the drawings that meet specific requirements, and there will be problems of inaccurate extraction due to incorrect layer name annotations.

[0004] Therefore, there is an urgent need for a method, device, and electronic device for extracting DXF drawings. Summary of the Invention

[0005] This application provides a method, device, and electronic device for extracting DXF drawings, which solves the problem of excessive dependence on layer annotations in related technologies by automatically identifying and processing closed contours, and improves the accuracy of DXF drawing parsing.

[0006] In the first aspect of the present application, a method for extracting DXF drawings is provided. The method includes: reading the primitives included in the DXF drawing, where the primitives include line segments and arcs; preprocessing the primitives to determine the key attributes of the primitives, where the key attributes include start coordinates and end coordinates; determining the closed contours in the DXF drawing according to the key attributes; using a preset contour algorithm to identify the closed contours to obtain the number, layout, and relative positions of the closed contours; determining valid closed contours from multiple closed contours according to the number, the layout, and the relative positions; and outputting the valid closed contours in the standard DXF format.

[0007] By adopting the above technical solution, by reading the primitives included in the DXF drawing and preprocessing the primitives to determine the key attributes of the primitives, including start coordinates and end coordinates, then determining the closed contours in the DXF drawing according to the key attributes. Next, using a preset contour algorithm to identify the closed contours to obtain the number, layout, and relative positions of the closed contours, and determining valid closed contours from multiple closed contours according to this information. Finally, outputting the valid closed contours in the standard DXF format. This method can automatically identify and extract the valid closed contours in the DXF drawing, does not depend on the layer name, avoids problems caused by incorrect layer name annotation, and improves the accuracy and reliability of contour extraction.

[0008] Optionally, the preprocessing the primitives to determine the key attributes of the primitives specifically includes: obtaining a preset geometric data structure, where the preset geometric data structure represents each primitive in the form of a polyline; when reading each primitive of the DXF drawing, generating a polyline corresponding to each primitive according to the preset geometric data structure, and approximating the polyline to the corresponding primitive to generate an approximated polyline; establishing a correspondence between the approximated polyline and the primitive, and determining the key attributes of the primitive according to the correspondence.

[0009] By adopting the above technical solution, when preprocessing the graphic elements and determining the key attributes, a preset geometric data structure is introduced to represent each graphic element in the form of a polyline. When reading each graphic element of the DXF drawing, according to the preset geometric data structure, a polyline corresponding to each graphic element is generated, and the polyline is approximated to the corresponding graphic element to generate an approximated polyline. Then, the corresponding relationship between the approximated polyline and the graphic element is established, and the key attributes of the graphic element are determined according to the corresponding relationship. This method uses a polyline to approximate and represent the graphic element, simplifies the data structure and processing flow of the graphic element, and improves the efficiency and accuracy of key attribute extraction. By establishing the corresponding relationship between the approximated polyline and the graphic element, the starting point coordinates and end point coordinates of the graphic element, which are key attributes, can be conveniently obtained, providing an accurate data basis for subsequent closed contour recognition and analysis. At the same time, by using the method of polyline approximation, it can adapt to different types and shapes of graphic elements and has better versatility.

[0010] Optionally, after generating a polyline corresponding to each graphic element of the DXF drawing according to the preset geometric data structure and approximating the polyline to the corresponding graphic element to generate an approximated polyline, the method further includes: if it is determined that the graphic element is an arc, determining whether the arc is a part of the outer contour of the part or a part of the inner contour of the part; if it is determined that the arc is a part of the outer contour of the part, the polyline corresponding to the arc is a polyline that is tangent to the outside of the arc; if it is determined that the arc is a part of the inner contour of the part, the polyline corresponding to the arc is a polyline that is tangent to the inside of the arc.

[0011] By adopting the above technical solution, during the process of generating a polyline corresponding to a graphic element and approximating the graphic element, special processing is performed on graphic elements of the arc type. First, it is determined whether the arc is a part of the outer contour of the part or a part of the inner contour of the part, and then different approximated polylines are generated according to the determination result. If the arc is a part of the outer contour of the part, a polyline that is tangent to the outside of the arc is generated; if the arc is a part of the inner contour of the part, a polyline that is tangent to the inside of the arc is generated. This method takes into account the different roles and positions of the arc in the part contour, and more accurately represents the topological relationship and geometric constraints between the arc and adjacent graphic elements by generating a circumscribed or inscribed polyline. The circumscribed polyline can closely adhere to the outer boundary of the arc, representing the connection relationship between the arc and external graphic elements; the inscribed polyline can fit the inner boundary of the arc, representing the inclusion relationship between the arc and internal graphic elements. This can better retain the shape characteristics of the arc, avoid errors and distortions caused by polyline approximation, and improve the accuracy and reliability of closed contour recognition.

[0012] Optionally, determining the closed contours in the DXF drawing according to the key attributes specifically includes: constructing the topological relationship of the graphic elements according to the starting point coordinates and the ending point coordinates; identifying target graphic elements according to the topological relationship, where the target graphic elements are the mutually connected graphic elements in the graphic elements; determining whether the target graphic elements form a closed path; if it is determined that the target graphic elements form a closed path, determining that the target graphic elements form a closed contour.

[0013] By adopting the above technical solution, when determining the closed contours in the DXF drawing, first construct the topological relationship of the graphic elements according to the starting point coordinates and the ending point coordinates of the graphic elements, and then identify the mutually connected target graphic elements according to the topological relationship. Then determine whether the target graphic elements form a closed path. If a closed path is formed, determine that the target graphic elements form a closed contour. This method uses the starting point coordinates and ending point coordinates information of the graphic elements to establish the topological relationship between the graphic elements, and can accurately judge the mutual connectivity between the graphic elements. By identifying the mutually connected target graphic elements, the potential candidate areas of the closed contours can be quickly found, reducing the complexity of searching and calculation. At the same time, by determining whether the target graphic elements form a closed path, the true closed contours can be effectively identified, excluding incomplete or open contour segments. This method based on topological relationship and closedness judgment improves the efficiency and accuracy of closed contour recognition, and avoids the occurrence of missed detection or misjudgment.

[0014] Optionally, determining the effective closed contours from multiple closed contours according to the quantity, the layout, and the relative position specifically includes: calculating the geometric center of each closed contour according to the quantity, the layout, and the relative position; calculating the distance matrix between each closed contour according to the geometric center; according to the distance matrix, classifying the closed contours with a relative distance less than a preset first distance threshold into one group to form multiple closed contour groups; analyzing the inclusion relationship of each closed contour group, marking and identifying the outer contour and the inner contour; identifying the effective closed contour representing the main shape of the part according to the outer contour and the inner contour.

[0015] By adopting the above technical solution, when determining the effective closed contours from multiple closed contours, first calculate the geometric centers of each closed contour according to the number, layout, and relative positions of the closed contours, and then calculate the distance matrix between the closed contours based on the geometric centers. Next, according to the distance matrix, group the closed contours with a relative distance less than a preset first distance threshold into one group to form multiple groups of closed contours. Then analyze the inclusion relationships of each group of closed contours, mark and identify the outer contour and the inner contour. Finally, based on the outer contour and the inner contour, identify the effective closed contour representing the main shape of the part. This method comprehensively considers multiple factors such as the number, layout, and relative positions of the closed contours. By calculating the geometric centers and the distance matrix, it can quantitatively evaluate the spatial relationship and distribution characteristics between the closed contours. Grouping the closed contours with a relatively close distance into one group to form groups of closed contours can initially divide different contour regions. By analyzing the inclusion relationships of the groups of closed contours, the outer contour and the inner contour can be further identified to determine the hierarchical structure and nesting relationship of the contours. Finally, based on the information of the outer contour and the inner contour, the effective closed contour representing the main shape of the part can be accurately identified, excluding interfering contours and irrelevant details. This multi-level and multi-angle analysis method improves the intelligent level and recognition accuracy of effective closed contour recognition and can meet the contour extraction requirements of complex parts.

[0016] Optionally, before determining the effective closed contours from multiple closed contours according to the number, layout, and relative positions, the method further includes: determining whether there is a situation where the first endpoint and the second endpoint of the DXF drawing do not intersect precisely, where the first endpoint is the endpoint of the first line segment, the second endpoint is the endpoint of the second line segment, the distance between the first endpoint and the second endpoint is less than a preset second distance threshold, the first line segment is any one line segment in the primitive, and the second line segment is any one line segment in the primitive other than the first line segment; if it is determined that there is a situation where the first endpoint and the second endpoint of the DXF drawing do not intersect precisely, then adjust the first endpoint so that the first endpoint intersects with the second endpoint.

[0017] By adopting the above technical solution, before determining the effective closed contour, steps for judging and processing inaccurate intersection situations are introduced. First, it is judged whether there is an inaccurate intersection situation between the first endpoint and the second endpoint in the DXF drawing, that is, the distance between the endpoints of the first line segment and the endpoints of the second line segment is less than a preset second distance threshold. If such a situation exists, the first endpoint is adjusted so that the first endpoint intersects with the second endpoint. This method solves the problem of inaccurate intersection caused by precision errors between the endpoints of the graphic elements. By judging whether the distance between the endpoints is less than the threshold, potential intersection points can be identified. Then, by adjusting the positions of the endpoints to make them intersect precisely, tiny gaps or overlaps are eliminated, ensuring the correct connection relationship between the graphic elements. This can improve the accuracy of closed contour recognition and avoid contour breakage or misjudgment caused by endpoint errors.

[0018] Optionally, after judging whether there is an inaccurate intersection situation between the first endpoint and the second endpoint in the DXF drawing, the method further includes: judging whether there is a situation where the first line segment and the second line segment completely overlap; if it is determined that the first line segment and the second line segment completely overlap, the first line segment is deleted.

[0019] By adopting the above technical solution, after judging the inaccurate intersection situation, steps for judging and processing completely overlapping line segments are further introduced. First, it is judged whether there is a situation where the first line segment and the second line segment completely overlap. If there is a complete overlap, the first line segment is deleted. This method solves the redundant situation of complete overlap between the graphic elements. By judging whether the first line segment and the second line segment completely coincide, redundant line segments can be identified. Then, by deleting one of the overlapping line segments, the redundant representation of the graphic elements is eliminated, the graphic structure is simplified, and the complexity of subsequent processing is reduced. This can improve the efficiency and accuracy of closed contour recognition and avoid contour confusion or misjudgment caused by overlapping line segments.

[0020] In the second aspect of the present application, an extraction device for DXF drawings is provided. The device includes: an acquisition module and a processing module, where: the acquisition module is used to read the graphic elements included in the DXF drawing, and the graphic elements include line segments and arcs; the processing module is used to preprocess the graphic elements to determine the key attributes of the graphic elements, and the key attributes include start coordinates and end coordinates; the processing module is further used to determine the closed contour in the DXF drawing according to the key attributes; the processing module is further used to identify the closed contour by using a preset contour algorithm to obtain the quantity, layout, and relative position of the closed contour; the processing module is further used to determine the effective closed contour from multiple closed contours according to the quantity, the layout, and the relative position; the processing module is further used to output the effective closed contour in the standard DXF format.

[0021] In the third aspect of the present application, an electronic device is provided, including a processor, a memory, a user interface, and a network interface. The memory is used to store instructions. Both the user interface and the network interface are used to communicate with other devices. The processor is used to execute the instructions stored in the memory so that the electronic device executes the method described in any one of the above.

[0022] In the fourth aspect of the present application, a computer-readable storage medium is provided. The computer-readable storage medium stores instructions that, when executed, execute the method described in any one of the above.

[0023] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:

[0024] 1. By reading the primitives included in the DXF drawing and preprocessing the primitives to determine the key attributes of the primitives, including the start coordinates and end coordinates, and then determining the closed contours in the DXF drawing according to the key attributes. Then, a preset contour algorithm is used to identify the closed contours to obtain the number, layout, and relative positions of the closed contours, and the effective closed contours are determined from the multiple closed contours according to this information. Finally, the effective closed contours are output in the standard DXF format. This method can automatically identify and extract the effective closed contours in the DXF drawing, does not depend on the layer name, avoids problems caused by incorrect layer name annotation, and improves the accuracy and reliability of contour extraction.

[0025] 2. When preprocessing the primitives and determining the key attributes, a preset geometric data structure is introduced to represent each primitive in the form of a polyline. When reading each primitive in the DXF drawing, according to the preset geometric data structure, a polyline corresponding to each primitive is generated, and the polyline is approximated to the corresponding primitive to generate an approximated polyline. Then, the correspondence between the approximated polyline and the primitive is established, and the key attributes of the primitive are determined according to the correspondence. This method uses a polyline to approximate and represent the primitive, simplifies the data structure and processing flow of the primitive, and improves the efficiency and accuracy of key attribute extraction. By establishing the correspondence between the approximated polyline and the primitive, the start coordinates, end coordinates, and other key attributes of the primitive can be conveniently obtained, providing an accurate data basis for subsequent closed contour recognition and analysis. At the same time, the method of using polyline approximation can adapt to different types and shapes of primitives and has better versatility.

[0026] 3. During the process of generating the polyline corresponding to the graphic element and approximating the graphic element, special processing is performed on the graphic elements of the arc type. First, it is determined whether the arc is a component of the outer contour of the part or a component of the inner contour of the part, and then different approximating polylines are generated according to the determination result. If the arc is a component of the outer contour of the part, a polyline tangent to the outside of the arc is generated; if the arc is a component of the inner contour of the part, a polyline tangent to the inside of the arc is generated. This method takes into account the different roles and positions of the arc in the part contour, and more accurately represents the topological relationship and geometric constraints between the arc and adjacent graphic elements by generating the tangent or inscribed polyline. The circumscribed polyline can closely adhere to the outer boundary of the arc, representing the connection relationship between the arc and the external graphic elements; the inscribed polyline can fit the inner boundary of the arc, representing the inclusion relationship between the arc and the internal graphic elements. In this way, the shape characteristics of the arc can be better retained, avoiding errors and distortions caused by polyline approximation, and improving the accuracy and reliability of closed contour recognition. Description of the Drawings

[0027] Figure 1 is a schematic flowchart of a method for extracting a DXF drawing disclosed in an embodiment of the present application;

[0028] Figure 2 is a schematic block diagram of a device for extracting a DXF drawing disclosed in an embodiment of the present application;

[0029] Figure 3 is a schematic structural diagram of an electronic device disclosed in an embodiment of the present application.

[0030] Description of the Reference Numerals: 201, acquisition module; 202, processing module; 300, electronic device; 301, processor; 302, communication bus; 303, user interface; 304, network interface; 305, memory. Detailed Embodiments

[0031] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings in the embodiments of this specification. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments.

[0032] In the description of the embodiments of the present application, words such as "for example" or "for instance" are used to represent examples, illustrations, or explanations. Any embodiment or design solution described as "for example" or "for instance" in the embodiments of the present application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Exactly speaking, the use of words such as "for example" or "for instance" is intended to present relevant concepts in a specific manner.

[0033] In the description of the embodiments of the present application, the term "plural" means two or more. For example, plural systems refer to two or more systems, and plural screen terminals refer to two or more screen terminals. In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. The terms "comprise", "include", "have" and their variants all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0034] The present application provides a method for extracting DXF drawings. Refer to Figure 1 , Figure 1 which is a schematic flowchart of a method for extracting DXF drawings provided by an embodiment of the present application. This method is applied to a server and includes steps S101 to S106. The above steps are as follows:

[0035] Step S101: Read the primitives included in the DXF drawing. The primitives include line segments and arcs.

[0036] In step S101, the server reads the primitive information included in the DXF drawing. DXF is a CAD drawing format used to exchange graphic data between different CAD software. The DXF file stores graphic information in ASCII text format and contains the definitions and attributes of various primitives in the drawing. The server extracts the primitive data by parsing the content of the DXF file. The primitive types include line segments, arcs, polylines, circles, text, etc. Each primitive has a corresponding data block in the DXF file, which describes the type, geometric parameters, and style attribute information of the primitive.

[0037] Taking a line segment as an example, in the DXF file, the line segment data block contains the following content: primitive type identifier, start point coordinates, end point coordinates, and layer information; among them, the primitive type indicates that the primitive is a line segment, represented by the code "LINE", the start point coordinates are the X, Y, and Z coordinate values of the start point of the line segment, the end point coordinates are the X, Y, and Z coordinate values of the end point of the line segment, and the layer information is the layer name to which the line segment belongs.

[0038] Taking an arc as an example, in the DXF file, the arc data block contains the following content: primitive type identifier, center coordinates, radius, start angle, end angle, and layer information; among them, the primitive type identifier indicates that the primitive is an arc, represented by the code "ARC", the center coordinates are the X, Y, and Z coordinate values of the center of the circle where the arc is located, the radius is the radius value of the circle where the arc is located, the start angle is the start angle of the arc, represented in radians, and the end angle is the end angle of the arc, represented in radians. The layer information is the layer name to which the arc belongs.

[0039] In addition to line segments and arcs, the server can also read other primitive types in the DXF file, such as polylines, circles, text, etc. Each primitive has its specific data block structure and attribute definition. The server correctly parses and extracts the data of various primitives according to the format specification of the DXF file.

[0040] Step S102: Preprocess the primitive to determine the key attributes of the primitive. The key attributes include the starting coordinate and the ending coordinate.

[0041] In step S102, obtain the preset geometric data structure. The preset geometric data structure represents each primitive in the form of a polyline. When reading each primitive of the DXF drawing, according to the preset geometric data structure, generate the polyline corresponding to each primitive, and approximate the polyline to the corresponding primitive to generate an approximated polyline. Establish the correspondence between the approximated polyline and the primitive, and determine the key attributes of the primitive according to the correspondence.

[0042] Specifically, the server needs to define and obtain the preset geometric data structure. The preset geometric data structure uses a series of connected line segments (i.e., a polyline) to represent the shape of the primitive. The polyline consists of a series of ordered vertices, and each vertex contains its coordinate information. By adjusting the number and position of the vertices of the polyline, various curve primitives, such as arcs, can be approximated.

[0043] When reading each primitive of the DXF drawing, the server converts each primitive into a corresponding polyline representation according to the preset geometric data structure. This process is called polyline approximation. Specifically, the server generates a series of polyline vertices according to the type and geometric parameters of the primitive, so that the polyline can approximate the shape of the original primitive as much as possible.

[0044] Taking an arc as an example, the server calculates the starting and ending coordinates of the arc according to the center coordinate, radius, starting angle, and ending angle of the arc. According to the angular range of the arc and the preset angular step, the server divides the arc into multiple small segments. For each small segment, calculate the coordinates of the corresponding points on the circumference as the vertices of the polyline. The server connects all the polyline vertices in sequence to form a polyline that approximates the arc.

[0045] For a simple primitive like a line segment, the polyline approximation is relatively simple. A straight line segment can be directly represented by the starting and ending coordinates and does not require additional discretization processing.

[0046] During the process of generating the approximated polyline, the server also needs to establish the correspondence between the polyline and the original primitive. This correspondence records which primitive each polyline vertex belongs to, as well as the position or parameter information of the vertex in the primitive. Through this correspondence, the server can conveniently map and convert between the polyline and the original primitive.

[0047] After establishing the correspondence between the polyline and the graphic element, the server can determine the key attributes of the graphic element based on the vertex information of the polyline. For a straight line segment, the key attributes are the starting coordinate and the ending coordinate, which can be directly obtained from the first and the last vertices of the polyline. For an arc, the key attributes include the center coordinate, the radius, the starting angle, and the ending angle, and these information can be calculated by analyzing the distribution of the polyline vertices and the correspondence of the arc.

[0048] In a possible implementation manner, when reading each graphic element of the DXF drawing, according to the preset geometric data structure, a polyline corresponding to each graphic element is generated, and the polyline is approximated to the corresponding graphic element. After generating the approximated polyline, the method further includes: if it is determined that the graphic element is an arc, determining whether the arc is a component of the outer contour of the part or a component of the inner contour of the part; if it is determined that the arc is a component of the outer contour of the part, the polyline corresponding to the arc is a polyline that is tangent to the outside of the arc; if it is determined that the arc is a component of the inner contour of the part, the polyline corresponding to the arc is a polyline that is tangent to the inside of the arc.

[0049] Specifically, the server first determines whether each arc graphic element belongs to the outer contour of the part or the inner contour of the part. The server achieves this by analyzing the spatial position and the context relationship of the graphic element in the drawing. For example, the server can check the connection relationship between the arc and other graphic elements (such as straight line segments) to determine whether the arc forms a closed contour. If the arc is a part of a closed contour and the closed contour contains other graphic elements, then the arc can be regarded as the outer contour of the part. On the contrary, if the arc is a part of a closed contour, but the closed contour is completely located inside another larger closed contour, then the arc can be regarded as the inner contour of the part. After determining the contour type to which the arc belongs, the server adjusts the polyline corresponding to the arc to ensure that the polyline can correctly approximate the inner and outer contours of the part.

[0050] For an arc that belongs to the outer contour of the part, the server will generate a polyline that is tangent to the outside of the arc. An outer tangent polyline means that all vertices of the polyline are located outside the arc and are tangent to the arc. The steps to generate the outer tangent polyline are as follows: According to the center coordinate, the radius, the starting angle, and the ending angle of the arc, calculate the coordinates of a series of points on the arc as the initial polyline vertices. For each polyline vertex, offset a certain distance along the normal direction of the arc to generate new vertex coordinates. The offset distance can be determined according to the approximation accuracy and the drawing scale. Connect all the offset vertices in the direction of the arc to form the outer tangent polyline. By generating the outer tangent polyline, the server can ensure that the polyline completely contains the arc and maintains a certain distance from the boundary of the arc, avoiding the intersection or overlap of the polyline and the arc. In this way, the external contour of the part can be represented more accurately.

[0051] For the arcs belonging to the inner contour of the part, the server will generate a polyline inscribed in the arc. An inscribed polyline means that all vertices of the polyline are located inside the arc and are tangent to the arc. The steps for generating the inscribed polyline are similar to those for the circumscribed polyline, except that during the vertex offset process, the vertices are offset inward by a certain distance along the normal direction of the arc.

[0052] Step S103: Determine the closed contour in the DXF drawing according to the key attributes.

[0053] In step S103, construct the topological relationship of the primitive according to the starting point coordinates and the ending point coordinates; identify the target primitive according to the topological relationship, where the target primitive is the interconnected primitive in the primitive; determine whether the target primitive forms a closed path; if it is determined that the target primitive forms a closed path, then determine that the target primitive forms a closed contour.

[0054] Specifically, the server constructs the topological relationship between graphic elements based on the starting coordinates and ending coordinates of each graphic element. The topological relationship reflects the connectivity and adjacency between graphic elements. The steps to construct the topological relationship are as follows: The server creates an empty topological relationship graph to store the connection information between graphic elements. The server traverses all graphic elements. For each graphic element, its starting coordinates and ending coordinates are added as nodes to the topological relationship graph. Traverse all graphic elements again. For each graphic element, a directed edge is added in the topological relationship graph to connect the starting node and the ending node of this graphic element. For each node in the topological relationship graph, check the connected edges. If there are multiple graphic elements sharing the same starting point or ending point, additional edges are added between these graphic elements to represent their connectivity. By constructing the topological relationship graph, the server can clearly represent the connection relationship between graphic elements. Next, the server identifies the target graphic elements that are interconnected based on the topological relationship graph. Target graphic elements refer to a set of graphic elements that can reach each other through a series of continuous edges in the topological relationship graph. The steps to identify target graphic elements are as follows: The server selects any node in the topological relationship graph as the starting node and creates an empty set of target graphic elements. Starting from the starting node, through depth-first search, the server traverses all nodes and edges connected to the starting node and adds all graphic elements passed during the traversal to the set of target graphic elements. The server repeats the above steps until all nodes in the topological relationship graph have been visited. By identifying target graphic elements, the server can divide the interconnected graphic elements (target graphic elements) in the drawing into the same set of target graphic elements, and each set of target graphic elements represents an independent geometric feature or contour. The server determines whether each set of target graphic elements forms a closed path to determine whether it is a closed contour. The steps to judge the closed path are as follows: For each set of target graphic elements, select any graphic element as the starting graphic element. Starting from the starting graphic element, in accordance with the direction of the edges in the topological relationship graph, traverse all graphic elements in the set of target graphic elements in sequence. During the traversal, the server records the visited graphic elements and nodes and checks whether there is a path back to the starting graphic element. If, after traversing all graphic elements, there is a path back to the starting graphic element and this path passes through all nodes in the set of target graphic elements, it is considered that this set of target graphic elements forms a closed path, that is, a closed contour. If there is no path back to the starting graphic element, or there are unvisited nodes, it is considered that this set of target graphic elements does not form a closed contour.

[0055] Step S104: Use a preset contour algorithm to identify the closed contours, and obtain the number, layout, and relative positions of the closed contours.

[0056] In step S104, the server needs to select an appropriate preset contour algorithm to process the closed contour. In the embodiment of the present application, the server adopts a boundary tracking algorithm to process the closed contour, and this algorithm extracts the geometric information of the contour by tracing the boundary of the closed contour. The specific steps are as follows: For each closed contour, select any starting point as the starting point for tracking. Starting from the starting point, move counterclockwise along the boundary of the closed contour and visit each node on the contour in turn. During the tracking process, record the coordinates of the visited nodes, and calculate the distance and direction between adjacent nodes. When returning to the starting point, the tracking of a closed contour is completed, and the recorded node coordinates are stored as the geometric information of the contour. The server repeats the above steps until all closed contours are tracked. Through the boundary tracking algorithm, the server can accurately extract the geometric information of each closed contour, including the shape, size, and position of the contour. Next, the server needs to count the number of closed contours to understand the number of independent geometric features contained in the drawing. The server achieves this by simply counting the number of identified closed contours. After obtaining the number of closed contours, the server also needs to analyze the layout and relative positions of the closed contours to understand the spatial relationship and structure of the geometric features in the drawing. The steps for the server to analyze the layout and relative positions are as follows:

[0057] The server establishes a coordinate system, taking the lower left corner of the drawing as the origin, the right side as the positive direction of the X-axis, and the upper side as the positive direction of the Y-axis. For each closed contour, calculate the position and size of its circumscribed rectangle. The circumscribed rectangle refers to the smallest rectangle that can completely contain the closed contour. According to the position and size of the circumscribed rectangle, determine the relative position of each closed contour in the coordinate system and the space range it occupies. Analyze the relative position relationships between different closed contours, such as adjacent, inclusion, and overlap. Through the above steps, the server can obtain the number, layout, and relative positions of the closed contours.

[0058] Step S105: Determine valid closed contours from multiple closed contours according to the number, layout, and relative positions.

[0059] In step S105, calculate the geometric center of each closed contour according to the number, layout, and relative positions; calculate the distance matrix between each closed contour according to the geometric center; according to the distance matrix, group the closed contours with a relative distance less than a preset first distance threshold into one group to form multiple closed contour groups; analyze the inclusion relationships of each closed contour group, mark and identify the outer contour and the inner contour; according to the outer contour and the inner contour, identify the valid closed contour representing the main shape of the part.

[0060] Specifically, the server calculates the geometric center of each closed contour based on the number, layout, and relative positions of the closed contours. For each closed contour, the server averages all the node coordinates on its boundary to obtain the center point coordinates (x, y) of the contour. Next, the server calculates the distance matrix between them based on the geometric centers of the respective closed contours. The distance matrix is a symmetric matrix used to store the distance values between any two closed contours. The steps for calculating the distance matrix are as follows:

[0061] The server creates an N×N distance matrix D, where N is the number of closed contours. For each element D[i][j] in matrix D, it calculates the Euclidean distance between the geometric centers of the i-th and j-th closed contours and stores the distance value in D[i][j]. Since the distance matrix is symmetric, only the elements in the upper triangular or lower triangular part need to be calculated, and then the elements in the other part are set to the same value. Through the distance matrix, the server can quantify the spatial relationship between the closed contours, providing a basis for subsequent contour grouping. The server groups the closed contours with a relative distance less than a preset first distance threshold into one group, forming multiple closed contour groups. The server internally sets a preset first distance threshold for determining whether two closed contours belong to the same group. The selection of the preset first distance threshold is determined in advance according to the scale of the drawing and the size of the geometric features, and this application does not limit it. The server traverses the distance matrix. For each element D[i][j], if its value is less than or equal to the preset first distance threshold, it groups the i-th and j-th closed contours into the same group. The server uses the union-find algorithm to merge the closed contours belonging to the same group, forming multiple independent closed contour groups. For each closed contour group, the server calculates the number of closed contours it contains and the position of the geometric center. The server analyzes the inclusion relationship within each closed contour group, marks, and identifies the outer contour and the inner contour. The outer contour is the outermost contour that contains other contours, representing the overall shape of the part; the inner contour is the contour contained within the outer contour, representing the internal features of the part, such as holes, slots, etc. The steps for identifying the outer contour and the inner contour are as follows:

[0062] For each contour group, the server analyzes the inclusion relationship between the closed contours it contains. The server determines the inclusion relationship by comparing the positions of the circumscribed rectangles or geometric centers of the contours. If a closed contour is not contained by any other contour, it is marked as an outer contour. There may be multiple outer contours in a contour group. For each outer contour, traverse the other closed contours inside it and mark them as inner contours. The inner contours can be further classified into different types such as holes, slots, etc. If there is only one closed contour in a contour group, it is directly marked as an outer contour and there are no inner contours. The server determines the valid closed contours representing the shape of the part body based on the identified outer and inner contours. Usually, the main shape of the part is determined by one or more outer contours on the outermost layer, while the inner contours inside represent additional features of the part. Therefore, the server can select the outer contour with the largest area or containing the most other contours as the valid closed contour to represent the main shape of the part.

[0063] In a possible implementation manner, before step S105, the method further includes: determining whether there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing, where the first endpoint is the endpoint of the first line segment, the second endpoint is the endpoint of the second line segment, the distance between the first endpoint and the second endpoint is less than a preset second distance threshold, the first line segment is any one line segment in the primitive, and the second line segment is any one line segment in the primitive other than the first line segment; if it is determined that there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing, then adjust the first endpoint so that the first endpoint intersects with the second endpoint.

[0064] Specifically, the server determines whether there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing. The first endpoint refers to the endpoint of the first line segment, and the second endpoint refers to the endpoint of the second line segment, where the first line segment and the second line segment are any two different line segments in the drawing. The server judges whether the two endpoints do not intersect precisely by calculating the distance between the first endpoint and the second endpoint and comparing it with a preset second distance threshold. The judgment steps are as follows: A preset second distance threshold is set inside the server to judge whether the two endpoints do not intersect precisely. The selection of the preset second distance threshold needs to be determined according to the scale and drawing accuracy of the drawing. Usually, it can be set to one ten-thousandth of the unit length of the drawing or less, and this application does not make any limitations in this regard. For each line segment in the drawing, extract its starting coordinate and ending coordinate, and use them as the first endpoint and the second endpoint respectively. For each first endpoint, traverse all the line segments in the drawing except the line segment where it is located, and extract their starting coordinates and ending coordinates as the second endpoints. The server uses the Euclidean distance formula to calculate the distance between the first endpoint and each second endpoint, and compares this distance value with the second distance threshold. If there exists any pair of the first endpoint and the second endpoint whose distance is less than the second distance threshold but they do not completely coincide, it is considered that there is a situation where the endpoints in the drawing do not intersect precisely. If the server determines that there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing, the position of the first endpoint needs to be adjusted so that it intersects precisely with the second endpoint. For each pair of the first endpoint and the second endpoint that do not intersect precisely, the server updates the coordinates of the first endpoint to the coordinates of the second endpoint to maintain the integrity of the line segment. For all pairs of endpoints that do not intersect precisely, the server repeats the above steps until there is no longer a situation where the endpoints in the drawing do not intersect precisely.

[0065] In a possible implementation manner, after determining whether there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing, the method further includes: judging whether the first line segment and the second line segment are completely overlapped; if it is determined that the first line segment and the second line segment are completely overlapped, then delete the first line segment.

[0066] Specifically, for each pair of the first line segment and the second line segment, their starting coordinates and ending coordinates are extracted. The server compares the starting coordinates of the first line segment with those of the second line segment to determine whether they are exactly the same. The server compares the ending coordinates of the first line segment with those of the second line segment to determine whether they are exactly the same. If the starting coordinates and the ending coordinates of the first line segment and the second line segment are all exactly the same, the server determines that there is a complete overlap between the two line segments. If the server determines that there is a complete overlap between the first line segment and the second line segment, one of the line segments needs to be deleted to eliminate redundant primitives in the drawing. The deletion steps are as follows: The server selects any one of the first line segment and the second line segment as the object to be deleted. The server finds the line segment data block of the deleted line segment in the drawing data and removes it from the data structure. For all pairs of line segments with complete overlap, the server repeats the above steps until there are no longer any line segments with complete overlap in the drawing.

[0067] Step S106: Output the valid closed contour in the standard DXF format.

[0068] In step S106, the server traverses each valid closed contour, converts it into primitive data in the standard DXF format, and outputs it for subsequent use.

[0069] Refer to Figure 2 , this application also provides an extraction device for DXF drawings. The device is a server, and the server includes an acquisition module 201 and a processing module 202, where: The acquisition module 201 is used to read the primitives included in the DXF drawing, and the primitives include line segments and arcs; The processing module 202 is used to preprocess the primitives to determine the key attributes of the primitives, and the key attributes include starting coordinates and ending coordinates; The processing module 202 is also used to determine the closed contours in the DXF drawing according to the key attributes; The processing module 202 is also used to identify the closed contours by using a preset contour algorithm to obtain the number, layout, and relative positions of the closed contours; The processing module 202 is also used to determine valid closed contours from multiple closed contours according to the number, layout, and relative positions; The processing module 202 is also used to output the valid closed contours in the standard DXF format.

[0070] In a possible implementation manner, the processing module 202 preprocesses the primitives to determine the key attributes of the primitives, specifically including: The acquisition module 201 acquires a preset geometric data structure, and the preset geometric data structure represents each primitive in the form of a polyline; When the processing module 202 reads each primitive of the DXF drawing, according to the preset geometric data structure, it generates a polyline corresponding to each primitive, approximates the polyline to the corresponding primitive, and generates an approximated polyline; The processing module 202 establishes a correspondence between the approximated polyline and the primitive, and determines the key attributes of the primitive according to the correspondence.

[0071] In a possible implementation, when the processing module 202 reads each primitive of the DXF drawing, according to the preset geometric data structure, it generates a polyline corresponding to each primitive and approximates the polyline to the corresponding primitive. After generating the approximated polyline, the method further includes: if the processing module 202 determines that the primitive is an arc, it determines whether the arc is a component of the outer contour of the part or a component of the inner contour of the part; if the processing module 202 determines that the arc is a component of the outer contour of the part, the polyline corresponding to the arc is a polyline externally tangent to the arc; if the processing module 202 determines that the arc is a component of the inner contour of the part, the polyline corresponding to the arc is a polyline internally tangent to the arc.

[0072] In a possible implementation, the processing module 202 determines the closed contours in the DXF drawing according to the key attributes, specifically including: the processing module 202 constructs the topological relationship of the primitive according to the starting point coordinates and the ending point coordinates; the processing module 202 identifies the target primitive according to the topological relationship, and the target primitive is the primitive that is interconnected in the primitive; the processing module 202 determines whether the target primitive forms a closed path; if the processing module 202 determines that the target primitive forms a closed path, it determines that the target primitive forms a closed contour.

[0073] In a possible implementation, before the processing module 202 determines the effective closed contours from multiple closed contours according to the quantity, layout, and relative position, the method further includes: the processing module 202 determines whether there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing, the first endpoint is the endpoint of the first line segment, the second endpoint is the endpoint of the second line segment, the distance between the first endpoint and the second endpoint is less than the preset second distance threshold, the first line segment is any line segment in the primitive, and the second line segment is any line segment in the primitive other than the first line segment; if the processing module 202 determines that there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing, it adjusts the first endpoint so that the first endpoint intersects with the second endpoint.

[0074] In a possible implementation, before the processing module 202 determines the effective closed contours from multiple closed contours according to the quantity, layout, and relative position, the method further includes: the processing module 202 determines whether there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing, the first endpoint is the endpoint of the first line segment, the second endpoint is the endpoint of the second line segment, the distance between the first endpoint and the second endpoint is less than the preset second distance threshold, the first line segment is any line segment in the primitive, and the second line segment is any line segment in the primitive other than the first line segment; if the processing module 202 determines that there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing, it adjusts the first endpoint so that the first endpoint intersects with the second endpoint.

[0075] In a possible implementation, after the processing module 202 determines whether there is a situation where the first endpoint and the second endpoint do not intersect precisely in the DXF drawing, the method further includes: the processing module 202 determines whether there is a situation where the first line segment and the second line segment completely overlap; if the processing module 202 determines that the first line segment and the second line segment completely overlap, the first line segment is deleted.

[0076] It should be noted that: when the device provided in the above embodiment realizes its functions, only the division of the above functional modules is used for illustration. In actual applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process can be seen in the method embodiment, which will not be repeated here.

[0077] This application also provides an electronic device. Refer to Figure 3 , Figure 3 is a schematic structural diagram of an electronic device provided in an embodiment of this application. The electronic device 300 may include: at least one processor 301, at least one network interface 304, a user interface 303, a memory 305, and at least one communication bus 302.

[0078] Among them, the communication bus 302 is used to realize the connection and communication between these components.

[0079] Among them, the user interface 303 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 303 may further include a standard wired interface and a wireless interface.

[0080] Among them, the network interface 304 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).

[0081] Among them, the processor 301 may include one or more processing cores. The processor 301 connects various parts within the entire server through various interfaces and lines, and executes various functions of the server and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 305, and by calling the data stored in the memory 305. Optionally, the processor 301 may be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), or programmable logic array (PLA). The processor 301 may integrate one or a combination of several of a central processing unit (CPU), a graphics processing unit (GPU), and a modem, etc. Among them, the CPU mainly processes the operating system, user interface, application programs, etc.; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communication. It can be understood that the above-mentioned modem may not be integrated into the processor 301 and may be implemented separately by a chip.

[0082] Among them, the memory 305 may include random access memory (RAM) and may also include read-only memory. Optionally, the memory 305 includes a non-transitory computer-readable storage medium. The memory 305 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 305 may include a program storage area and a data storage area. Among them, the program storage area may store instructions for implementing the operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-mentioned method embodiments, etc.; the data storage area may store the data involved in the above-mentioned method embodiments. The memory 305 may optionally also be at least one storage device located far from the aforementioned processor 301. Refer to Figure 3 , in the memory 305 as a computer storage medium, there may be included an operating system, a network communication module, a user interface module, and an application program for a method of extracting a DXF drawing.

[0083] In Figure 3In the electronic device 300 shown, the user interface 303 is mainly used to provide an interface for the user to input and obtain the data input by the user; and the processor 301 can be used to call an application program stored in the memory 305 for a method of extracting a DXF drawing. When executed by one or more processors 301, the electronic device 300 is caused to execute one or more of the methods as described in the above embodiments. It should be noted that for the foregoing method embodiments, for simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present application.

[0084] The present application also provides a computer-readable storage medium storing instructions. When executed by one or more processors 301, the electronic device 300 is caused to execute one or more of the methods as described in the above embodiments.

[0085] In the above embodiments, the descriptions of the various embodiments each have their own emphases. For parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.

[0086] In several implementation manners provided by the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some service interfaces. The indirect couplings or communication connections of the devices or units can be in electrical or other forms.

[0087] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0088] In addition, in each embodiment of the present application, the functional units can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.

[0089] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in various embodiments of the present application. The aforementioned memory includes various media that can store program codes, such as USB flash drives, mobile hard disks, magnetic disks, or optical discs.

[0090] The above are only exemplary embodiments of the present disclosure, and the scope of the present disclosure cannot be limited thereby. That is, any equivalent changes and modifications made in accordance with the teachings of the present disclosure still fall within the scope covered by the present disclosure. Those skilled in the art will easily think of other implementation manners of the present disclosure after considering the specification and the disclosure of the practical truth.

[0091] The present application aims to cover any variations, uses, or adaptive changes of the present disclosure, which follow the general principles of the present disclosure and include the common general knowledge or conventional technical means in the technical field not recorded in the present disclosure. The specification and the embodiments are only regarded as exemplary, and the scope and spirit of the present disclosure are defined by the claims.

Claims

1. A method for extracting DXF drawings, characterized in that: The method comprises: Reading primitives included in a DXF drawing, wherein the primitives include line segments and arcs; Preprocessing the graphic element to determine key attributes of the graphic element, wherein the key attributes include a starting point coordinate and an end point coordinate; Determining a closed contour in the DXF drawing according to the key attribute; Using a preset contour algorithm to identify the closed contours, and obtaining the number, layout and relative position of the closed contours; determining a valid closed contour from the plurality of closed contours according to the number, the layout, and the relative position; Outputting the valid closed contour as a standard DXF format; Determining a valid closed contour from the plurality of closed contours according to the quantity, the layout, and the relative position specifically includes: Calculating the geometric center of each of the closed contours according to the quantity, the layout, and the relative position; Calculate the distance matrix between each of the closed contours according to the geometric center; According to the distance matrix, closed contours whose relative distance is less than a preset first distance threshold are grouped together to form a plurality of closed contour groups; Analyzing the inclusion relationship of each of the closed contour groups, marking and identifying the outer contour and the inner contour; According to the outer contour and the inner contour, a valid closed contour representing the main shape of the part is identified.

2. The method according to claim 1, characterized in that: The preprocessing of the primitive to determine the key attributes of the primitive specifically includes: Acquire a preset geometric data structure, wherein the preset geometric data structure represents each of the graphic elements in the form of a polyline; When reading each primitive of the DXF drawing, generating a polyline corresponding to each primitive according to the preset geometric data structure, and approximating the polyline to the corresponding primitive to generate an approximated polyline; A correspondence between the approximation polyline and the primitive is established, and a key attribute of the primitive is determined according to the correspondence.

3. The method according to claim 2, characterized in that When reading each primitive of the DXF drawing, generating a polyline corresponding to each primitive according to the preset geometric data structure, and approximating the polyline to the corresponding primitive, after generating the approximated polyline, the method further includes: If it is determined that the graphic element is an arc, then determining whether the arc is a component of the outer contour of the part or a component of the inner contour of the part; If it is determined that the circular arc is a component of the outer contour of the part, then the polyline corresponding to the circular arc is a polyline circumscribed to the circular arc; If it is determined that the circular arc is a component of the inner contour of the part, then the broken line corresponding to the circular arc is a broken line inscribed in the circular arc.

4. The method according to claim 1, characterized in that Determining the closed contour in the DXF drawing according to the key attribute specifically includes: Constructing a topological relationship of the graphic element according to the starting point coordinates and the end point coordinates; According to the topological relationship, identifying a target primitive, wherein the target primitive is a primitive that is interconnected among the primitives; Determining whether the target primitive forms a closed path; If it is determined that the target primitives form a closed path, then it is determined that the target primitives form a closed contour.

5. The method according to claim 1, characterized in that Before determining a valid closed contour from the plurality of closed contours according to the quantity, the layout and the relative position, the method further comprises: Determine whether there is a situation in which a first endpoint and a second endpoint in the DXF drawing do not precisely intersect, the first endpoint is an endpoint of a first line segment, the second endpoint is an endpoint of a second line segment, a distance between the first endpoint and the second endpoint is less than a preset second distance threshold, the first line segment is any line segment in the graphic element, and the second line segment is any line segment in the graphic element except the first line segment; If it is determined that the first endpoint and the second endpoint in the DXF drawing do not intersect accurately, the first endpoint is adjusted so that the first endpoint intersects with the second endpoint.

6. The method according to claim 5, characterized in that After determining whether there is an inaccurate intersection between the first endpoint and the second endpoint in the DXF drawing, the method further includes: Determine whether the first line segment and the second line segment completely overlap; If it is determined that the first line segment and the second line segment completely overlap, the first line segment is deleted.

7. A DXF drawing extraction device, characterized in that: The device is used to execute the method according to any one of claims 1 to 6, and comprises an acquisition module (201) and a processing module (202), wherein: The acquisition module (201) is used to read the graphic elements included in the DXF drawing, wherein the graphic elements include line segments and circular arcs; The processing module (202) is used to pre-process the primitive to determine key attributes of the primitive, wherein the key attributes include a starting point coordinate and an end point coordinate; The processing module (202) is further used to determine a closed contour in the DXF drawing according to the key attribute; The processing module (202) is further used to identify the closed contours using a preset contour algorithm to obtain the number, layout and relative position of the closed contours; The processing module (202) is further used to determine a valid closed contour from the plurality of closed contours according to the number, the layout and the relative position; The processing module (202) is also used to output the valid closed contour in a standard DXF format.

8. An electronic device, characterized in that: The electronic device (300) comprises a processor (301), a memory (305), a user interface (303) and a network interface (304), wherein the memory (305) is used to store instructions, the user interface (303) and the network interface (304) are used to communicate with other devices, and the processor (301) is used to execute the instructions stored in the memory (305) so that the electronic device (300) executes the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed, the method according to any one of claims 1 to 6 is performed.

Citation Information

Patent Citations

  • DXF format-based house type image information extraction and vectorization method and device

    CN114092952A