A method and system for extracting geometric contours from CAD drawings
By combining the Douglas-Peucker algorithm with the least squares method, the problem of extracting geometric contour information from CAD drawings is solved, and efficient and accurate geometric model generation is achieved, which is suitable for reverse engineering.
Patent Information
- Application Number
- CN202311396463.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-25
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2043-10-25
AI Technical Summary
Existing technologies cannot directly extract the geometric contour information of components from CAD drawings, which limits the application of reverse engineering.
The Douglas-Peucker algorithm and the least squares method are combined to extract the whole circle contour, segment the contour points, fit the circle and the line, determine the contour type, and generate the geometric model.
It realizes the accurate extraction of geometric contour models from CAD drawings, has strong noise resistance and high robustness, and solves the shortcomings of existing technologies.
Smart Images

Figure CN117275032B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a method and system for extracting geometric contours from CAD drawings. Background Art
[0002] With the continuous development of computer technology, CAD technology has gradually improved and its application scope has continued to expand, covering a variety of fields such as architecture, machinery, electronics, and aviation. In these fields, reverse engineering is often used to disassemble and measure physical components to understand their design, operating principles, and manufacturing methods. Currently, when CAD technology is applied to reverse engineering, because the drawings sometimes do not store geometric information, it is impossible to directly extract component data, which cannot meet the application requirements of the project.
[0003] Therefore, it is necessary to propose a method that can extract geometric contour information from CAD drawings.
[0004] The above information is presented as background information only to assist with an understanding of the present disclosure and is not a determination or admission that any of the above may be applicable as prior art with respect to the present disclosure. Summary of the Invention
[0005] The present invention provides a method and system for extracting geometric contours of CAD drawings, so as to solve the deficiencies in the prior art.
[0006] To achieve the above object, the present invention provides the following technical solutions:
[0007] In a first aspect, the present invention provides a method for extracting geometric contours from a CAD drawing, the method comprising:
[0008] S10, inputting the contour points of the CAD drawing, performing full circle contour extraction, and obtaining the full circle contour and remaining contour points;
[0009] S20, simplifying the remaining contour points using the Douglas-Peucker algorithm, and segmenting the contour points using the simplified point set to obtain a segmented contour array;
[0010] S30. In the contour array, calculate the scores of two adjacent contour fitting circles whose distance between the first and last points meets the requirement, and determine whether they are fused into one contour; after fusion, fit a circle and a straight line to each contour point, and calculate the residual. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than an empirical threshold, the contour is an arc; otherwise, the contour is a line segment.
[0011] S40: For a contour of line segment type, set the first and last points to fit the line segment model; for a contour of arc type, use the distance and angle to determine the arc angle to fit the arc model.
[0012] Furthermore, in the geometric contour extraction method of the CAD drawing, step S10 includes:
[0013] S11, input the contour points of the CAD drawing;
[0014] S12, using connectivity segmentation and distance threshold to preliminarily divide the contour points into several disconnected contour sets;
[0015] S13, connecting the contours whose first and last points are very close to each other, and calculating the mean smoothed contour point within a certain range for each point;
[0016] S14. Fit the smoothed point set to a circle using the least squares method, and determine whether the distance from each point to the center of the circle is close to the radius, thereby calculating the proportion of the point on the circle; if the proportion is greater than a preset proportion threshold, the shape of the contour is determined to be a circle, the contour is extracted, and fitted into a circle model to obtain the entire circle contour and the remaining contour points.
[0017] Furthermore, in the geometric contour extraction method of the CAD drawing, the least squares fitting circle formula is:
[0018] ;
[0019] in, is the variance, is the number of points of the current contour, so When it is minimum, calculate the center of the circle and radius .
[0020] Furthermore, in the geometric contour extraction method of the CAD drawing, step S20 includes:
[0021] S21. For the remaining contour points, assume that points, find the first point P1 and the last point P2 to form a straight line, and calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P3;
[0022] S22. Determine the maximum distance and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P3 is retained;
[0023] S23. Based on the retained farthest point P3, connect the first point P1 and the farthest point P3 as the new starting and ending points to form a straight line, and calculate the distance between each point and the straight line. , and determine the one with the greatest distance The farthest point P4, and the farthest point P3 and the tail point P2 as the new starting and ending points to connect into a straight line, calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P5; respectively determine the farthest point P4 and the farthest point P5 and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P4 and the farthest point P5 are retained, and the above steps of taking the retained farthest points as the new first and last points are repeated until no points that meet the requirements are found, and the simplified point set is obtained;
[0024] S24, using the simplified point set as the boundary, divide the contour points into multiple small segments to obtain the contour array .
[0025] Furthermore, in the geometric contour extraction method of the CAD drawing, step S30 includes:
[0026] S31. Assume contour array Total Segment, calculate and judge the contours of two adjacent segments and The distance between the first and last points, If it is less than the second preset distance threshold, the points of the two contours are fitted into a circle and the score is calculated. If the score is higher than or equal to the preset score threshold, the two contours are merged into one contour, which is defined as , clear , thus and Calculation and judgment of the distance between the first and last points; if the score is lower than the preset score threshold, and Calculate and judge the distance between the first and last points until the traversal is completed and a new contour array is obtained ;
[0027] S32, for the new contour array For each contour point in , a circle and a straight line are fitted respectively and the residual is calculated. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than the empirical threshold, the contour is an arc, otherwise the contour is a line segment.
[0028] Furthermore, in the geometric contour extraction method of the CAD drawing, the empirical threshold is 0.1.
[0029] Furthermore, in the geometric contour extraction method of the CAD drawing, step S40 includes:
[0030] S41. For a contour of line segment type, set the first and last points to fit the line segment model;
[0031] S42. For an arc-shaped contour, calculate the vector between the starting point of the arc contour and the center of the fitted circle. and the vector between the contour end point and the circle center , if the vector and vector If the angle between them is greater than the preset angle threshold, the cross product is used to determine whether the midpoint of the arc is on the left or right of the vector composed of the first and last points to calculate different angle fitting models. If the angle is not greater than the preset angle threshold, the sum of the distances of the contour points in the two opening directions is calculated respectively. The opening angle that is closer to the sum of the original contour point distances is the correct angle, thereby fitting the arc model.
[0032] In a second aspect, the present invention provides a system for extracting geometric contours from CAD drawings, the system comprising:
[0033] The full circle contour extraction module is used to input the contour points of the CAD drawing, perform full circle contour extraction, and obtain the full circle contour and the remaining contour points;
[0034] The contour point segmentation module is used to simplify the remaining contour points using the Douglas-Peucker algorithm and segment the contour points using the simplified point set to obtain a segmented contour array;
[0035] The contour type judgment module is used to calculate the score of two adjacent contour fitting circles in the contour array whose starting and ending points meet the requirements, and determine whether they are fused into a single contour. After fusion, a circle and a straight line are fitted to each contour point and the residual is calculated. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than the empirical threshold, the contour is an arc; otherwise, the contour is a line segment.
[0036] The geometric model generation module is used to set the first and last points of the line segment model for the contour of the line segment type, and to fit the arc model for the contour of the arc type by using the distance and angle to judge the arc angle.
[0037] Furthermore, in the geometric contour extraction system of the CAD drawing, the full circle contour extraction module is specifically used to:
[0038] S11, input the contour points of the CAD drawing;
[0039] S12, using connectivity segmentation and distance threshold to preliminarily divide the contour points into several disconnected contour sets;
[0040] S13, connecting the contours whose first and last points are very close to each other, and calculating the mean smoothed contour point within a certain range for each point;
[0041] S14. Fit the smoothed point set to a circle using the least squares method, and determine whether the distance from each point to the center of the circle is close to the radius, thereby calculating the proportion of the point on the circle; if the proportion is greater than a preset proportion threshold, the shape of the contour is determined to be a circle, the contour is extracted, and fitted into a circle model to obtain the entire circle contour and the remaining contour points.
[0042] Furthermore, in the geometric contour extraction system of the CAD drawing, the least squares fitting circle formula is:
[0043] ;
[0044] in, is the variance, is the number of points of the current contour, so When it is minimum, calculate the center of the circle and radius .
[0045] Furthermore, in the geometric contour extraction system of the CAD drawing, the contour point segmentation module is specifically used to:
[0046] S21. For the remaining wheel contour points, assume that points, find the first point P1 and the last point P2 to form a straight line, and calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P3;
[0047] S22. Determine the maximum distance and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P3 is retained;
[0048] S23. Based on the retained farthest point P3, connect the first point P1 and the farthest point P3 as the new starting and ending points to form a straight line, and calculate the distance between each point and the straight line. , and determine the one with the greatest distance The farthest point P4, and the farthest point P3 and the tail point P2 as the new starting and ending points to connect into a straight line, calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P5; respectively determine the farthest point P4 and the farthest point P5 and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P4 and the farthest point P5 are retained, and the above steps of taking the retained farthest points as the new first and last points are repeated until no points that meet the requirements are found, and the simplified point set is obtained;
[0049] S24, using the simplified point set as the boundary, divide the contour points into multiple small segments to obtain the contour array .
[0050] Furthermore, in the geometric contour extraction system of the CAD drawing, the contour type judgment module is specifically used to:
[0051] S31. Assume contour array Total Segment, calculate and judge the contours of two adjacent segments and The distance between the first and last points, If it is less than the second preset distance threshold, the points of the two contours are fitted into a circle and the score is calculated. If the score is higher than or equal to the preset score threshold, the two contours are merged into one contour, which is defined as , clear , thus and Calculation and judgment of the distance between the first and last points; if the score is lower than the preset score threshold, and Calculate and judge the distance between the first and last points until the traversal is completed and a new contour array is obtained ;
[0052] S32, for the new contour array For each contour point in , a circle and a straight line are fitted respectively and the residual is calculated. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than the empirical threshold, the contour is an arc, otherwise the contour is a line segment.
[0053] Furthermore, in the geometric contour extraction system of the CAD drawing, the empirical threshold is 0.1.
[0054] Furthermore, in the geometric contour extraction system of the CAD drawing, the geometric model generation module is specifically used to:
[0055] S41. For a contour of line segment type, set the first and last points to fit the line segment model;
[0056] S42. For an arc-shaped contour, calculate the vector between the starting point of the arc contour and the center of the fitted circle. and the vector between the contour end point and the circle center , if the vector and vector If the angle between them is greater than the preset angle threshold, the cross product is used to determine whether the midpoint of the arc is on the left or right of the vector composed of the first and last points to calculate different angle fitting models. If the angle is not greater than the preset angle threshold, the sum of the distances of the contour points in the two opening directions is calculated respectively. The opening angle that is closer to the sum of the original contour point distances is the correct angle, thereby fitting the arc model.
[0057] In a third aspect, the present invention provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method for extracting the geometric contour of a CAD drawing as described in the first aspect above is implemented.
[0058] In a fourth aspect, the present invention provides a storage medium comprising computer-executable instructions, wherein the computer-executable instructions are executed by a computer processor to implement the method for extracting geometric contours from CAD drawings as described in the first aspect above.
[0059] Compared with the prior art, the present invention has the following beneficial effects:
[0060] The present invention provides a method and system for extracting the geometric contour of a CAD drawing, which can reversely extract the CAD geometric contour model from the CAD drawing, solving the technical problem that the existing technology cannot accurately obtain the geometric information of the CAD drawing. The method and system are not only simple and easy to implement, but also have strong noise resistance and robustness.
[0061] The present invention has other features and advantages that will be apparent from or will be described in detail in the accompanying drawings and the following detailed description incorporated herein, which together serve to explain certain principles of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0063] Figure 1 This is a flow chart of a method for extracting geometric contours from a CAD drawing provided in Example 1 of the present invention;
[0064] Figure 2 is the original contour map to be processed in the first embodiment of the present invention;
[0065] Figure 3 This is the contour image after full circle extraction in the first embodiment of the present invention;
[0066] Figure 4 is the contour image after segmentation in the first embodiment of the present invention;
[0067] Figure 5 is the extracted contour geometric model diagram in the first embodiment of the present invention;
[0068] Figure 6 yes Figure 5 Detailed picture of
[0069] Figure 7 This is a schematic diagram of the functional modules of a geometric contour extraction system for CAD drawings provided in a second embodiment of the present invention;
[0070] Figure 8 This is a structural diagram of a computer device provided in Example 3 of the present invention. DETAILED DESCRIPTION
[0071] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application. In addition, it is known to those of ordinary skill in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0072] In the description of this application, it should be understood that, unless otherwise defined, all technical and scientific terms used in this application have the same meaning as commonly understood by those skilled in the art to which this application belongs. In addition, any terminology used is only for the purpose of describing specific embodiments and is not intended to limit this application.
[0073] In addition, numerous specific details are provided in the detailed description below to better illustrate the present application. Those skilled in the art will appreciate that the present application can be practiced without certain specific details. In some instances, methods, means, components, and circuits well known to those skilled in the art are not described in detail in order to highlight the main purpose of the present application.
[0074] The technical solution of the present invention will be further described below with reference to the accompanying drawings and through specific implementation methods.
[0075] Example 1
[0076] Please refer to Figure 1 , Figure 1This is a flow chart of a method for extracting geometric contours from CAD drawings, provided in Example 1 of the present invention. The method is performed by a system for extracting geometric contours from CAD drawings, which can be implemented by software and / or hardware. The method specifically includes the following steps:
[0077] S10, inputting the contour points of the CAD drawing, performing full circle contour extraction, and obtaining the full circle contour and remaining contour points.
[0078] In this embodiment, step S10 can be further refined to include the following steps:
[0079] S11, inputting contour points of a CAD drawing; S12, using connectivity segmentation and distance threshold to preliminarily divide the contour points into several disconnected contour sets;
[0080] S13, connecting the contours whose first and last points are very close to each other, and calculating the mean smoothed contour point within a certain range for each point;
[0081] S14. Fit the smoothed point set to a circle using the least squares method, and determine whether the distance from each point to the center of the circle is close to the radius, thereby calculating the proportion of the point on the circle; if the proportion is greater than a preset proportion threshold, the shape of the contour is determined to be a circle, the contour is extracted, and fitted into a circle model to obtain the entire circle contour and the remaining contour points.
[0082] The preset ratio threshold value can be arbitrarily set by technical personnel based on experience and actual application scenarios. This embodiment does not make any specific limitation here, but for example, it can be 95%.
[0083] In this embodiment, the least squares fitting circle formula is:
[0084] ;
[0085] in, is the variance, is the number of points of the current contour, so When it is minimum, calculate the center of the circle and radius .
[0086] After entering the outline points of the CAD drawing Figure 2 As shown, the result after full circle contour extraction is as follows Figure 3 shown.
[0087] S20. Simplify the remaining contour points using the Douglas-Peucker algorithm, and segment the contour points using the simplified point set to obtain a segmented contour array.
[0088] In this embodiment, step S20 can be further refined to include the following steps:
[0089] S21. For the remaining contour points, assume that points, find the first point P1 and the last point P2 to form a straight line, and calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P3;
[0090] S22. Determine the maximum distance and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P3 is retained;
[0091] S23. Based on the retained farthest point P3, connect the first point P1 and the farthest point P3 as the new starting and ending points to form a straight line, and calculate the distance between each point and the straight line. , and determine the one with the greatest distance The farthest point P4, and the farthest point P3 and the tail point P2 as the new starting and ending points to connect into a straight line, calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P5; respectively determine the farthest point P4 and the farthest point P5 and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P4 and the farthest point P5 are retained, and the above steps of taking the retained farthest points as the new first and last points are repeated until no points that meet the requirements are found, and the simplified point set is obtained;
[0092] S24, using the simplified point set as the boundary, divide the contour points into multiple small segments to obtain the contour array .
[0093] The result after segmentation is as follows Figure 4 shown.
[0094] S30. In the contour array, calculate the scores of the two adjacent contour fitting circles whose distance between the first and last points meets the requirements, and determine whether they are fused into one contour; after fusion, fit a circle and a straight line to each contour point respectively, and calculate the residual. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than the empirical threshold, then the contour is an arc; otherwise, the contour is a line segment.
[0095] In this embodiment, step S30 can be further refined to include the following steps:
[0096] S31. Assume contour array Total Segment, calculate and judge the contours of two adjacent segments and The distance between the first and last points, If it is less than the second preset distance threshold, the points of the two contours are fitted into a circle and the score is calculated. If the score is higher than or equal to the preset score threshold, the two contours are merged into one contour, which is defined as , clear , thus and Calculation and judgment of the distance between the first and last points; if the score is lower than the preset score threshold, and Calculate and judge the distance between the first and last points until the traversal is completed and a new contour array is obtained ;
[0097] S32, for the new contour array For each contour point in , a circle and a straight line are fitted respectively and the residual is calculated. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than the empirical threshold, the contour is an arc, otherwise the contour is a line segment.
[0098] The empirical threshold value can be arbitrarily set by technicians based on experience and actual application scenarios. This embodiment does not make any specific limitation here, but for example, it can be 0.1.
[0099] S40: For a contour of line segment type, set the first and last points to fit the line segment model; for a contour of arc type, use the distance and angle to determine the arc angle to fit the arc model.
[0100] In this embodiment, step S40 can be further refined to include the following steps:
[0101] S41. For a contour of line segment type, set the first and last points to fit the line segment model;
[0102] S42. For an arc-shaped contour, calculate the vector between the starting point of the arc contour and the center of the fitted circle. and the vector between the contour end point and the circle center , if the vector and vector If the angle between them is greater than the preset angle threshold (close to a straight angle), the cross product is used to determine whether the midpoint of the arc is on the left or right of the vector composed of the first and last points to calculate different angle fitting models. If the angle is not greater than the preset angle threshold (not close to a straight angle), the sum of the distances of the contour points in the two opening directions is calculated respectively. The opening angle that is closer to the sum of the distances of the original contour points is the correct angle, thereby fitting the arc model.
[0103] The geometric model obtained by fitting the final input contour is as follows Figure 5 As shown, Figure 6 for Figure 5 Detail picture.
[0104] Although the terms such as contour, threshold, segmentation, and fitting are frequently used in this application, the possibility of using other terms is not excluded. These terms are used only to more conveniently describe and explain the essence of the present invention; interpreting them as any additional limitations is contrary to the spirit of the present invention.
[0105] The present invention provides a method for extracting the geometric contour of a CAD drawing, which can reversely extract the CAD geometric contour model from the CAD drawing, solving the technical problem that the existing technology cannot accurately obtain the geometric information of the CAD drawing. The method is not only simple and easy to implement, but also has strong noise resistance and robustness.
[0106] Example 2
[0107] Please refer to Figure 7 , is a functional module diagram of a system for extracting geometric contours from CAD drawings provided in an embodiment of the present invention. The system is suitable for executing the method for extracting geometric contours from CAD drawings provided in an embodiment of the present invention. The system specifically includes the following modules:
[0108] The full circle contour extraction module 201 is used to input the contour points of the CAD drawing, perform full circle contour extraction, and obtain the full circle contour and the remaining contour points;
[0109] A contour point segmentation module 202 is configured to simplify the remaining contour points using the Douglas-Peucker algorithm and segment the contour points using the simplified point set to obtain a segmented contour array;
[0110] The contour type determination module 203 is used to calculate the scores of two adjacent contour fitting circles in the contour array whose distance between the first and last points meets the requirements, and determine whether they are fused into a single contour. After fusion, a circle and a straight line are fitted to each contour point segment and the residual is calculated. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than the empirical threshold, the contour is an arc; otherwise, the contour is a line segment.
[0111] The geometric model generation module 204 is used to set the first and last points of the contour to fit the line segment model for the contour of the line segment type, and to fit the arc model for the contour of the arc type by using the distance and angle to determine the arc angle.
[0112] Preferably, the full circle contour extraction module 201 is specifically used for:
[0113] S11, input the contour points of the CAD drawing;
[0114] S12, using connectivity segmentation and distance threshold to preliminarily divide the contour points into several disconnected contour sets;
[0115] S13, connecting the contours whose first and last points are very close to each other, and calculating the mean smoothed contour point within a certain range for each point;
[0116] S14. Fit the smoothed point set to a circle using the least squares method, and determine whether the distance from each point to the center of the circle is close to the radius, thereby calculating the proportion of the point on the circle; if the proportion is greater than a preset proportion threshold, the shape of the contour is determined to be a circle, the contour is extracted, and fitted into a circle model to obtain the entire circle contour and the remaining contour points.
[0117] Preferably, the least squares fitting circle formula is:
[0118] ;
[0119] in, is the variance, is the number of points of the current contour, so When it is minimum, calculate the center of the circle and radius .
[0120] Preferably, the contour point segmentation module 202 is specifically used for:
[0121] S21. For the remaining wheel contour points, assume that points, find the first point P1 and the last point P2 to form a straight line, and calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P3;
[0122] S22. Determine the maximum distance and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P3 is retained;
[0123] S23. Based on the retained farthest point P3, connect the first point P1 and the farthest point P3 as the new starting and ending points to form a straight line, and calculate the distance between each point and the straight line. , and determine the one with the greatest distance The farthest point P4, and the farthest point P3 and the tail point P2 as the new starting and ending points to connect into a straight line, calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P5; respectively determine the farthest point P4 and the farthest point P5 and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P4 and the farthest point P5 are retained, and the above steps of taking the retained farthest points as the new first and last points are repeated until no points that meet the requirements are found, and the simplified point set is obtained;
[0124] S24, using the simplified point set as the boundary, divide the contour points into multiple small segments to obtain the contour array .
[0125] Preferably, the contour type determination module 203 is specifically configured to:
[0126] S31. Assume contour array Total Segment, calculate and judge the contours of two adjacent segments and The distance between the first and last points, If it is less than the second preset distance threshold, the points of the two contours are fitted into a circle and the score is calculated. If the score is higher than or equal to the preset score threshold, the two contours are merged into one contour, which is defined as , clear , thus and Calculation and judgment of the distance between the first and last points; if the score is lower than the preset score threshold, and Calculate and judge the distance between the first and last points until the traversal is completed and a new contour array is obtained ;
[0127] S32, for the new contour array For each contour point in , a circle and a straight line are fitted respectively and the residual is calculated. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than the empirical threshold, the contour is an arc, otherwise the contour is a line segment.
[0128] Preferably, the empirical threshold is 0.1.
[0129] Preferably, the geometric model generation module 204 is specifically used to:
[0130] S41. For a contour of line segment type, set the first and last points to fit the line segment model;
[0131] S42. For an arc-shaped contour, calculate the vector between the starting point of the arc contour and the center of the fitted circle. and the vector between the contour end point and the circle center , if the vector and vector If the angle between them is greater than the preset angle threshold, the cross product is used to determine whether the midpoint of the arc is on the left or right of the vector composed of the first and last points to calculate different angle fitting models. If the angle is not greater than the preset angle threshold, the sum of the distances of the contour points in the two opening directions is calculated respectively. The opening angle that is closer to the sum of the original contour point distances is the correct angle, thereby fitting the arc model.
[0132] The present invention provides a geometric contour extraction system for CAD drawings, which can reversely extract CAD geometric contour models from CAD drawings, solving the technical problem that the existing technology cannot accurately obtain the geometric information of CAD drawings. It is not only simple and easy to use, but also has strong noise resistance and robustness.
[0133] The above system can execute the method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0134] Example 3
[0135] Figure 8 A schematic diagram of the structure of a computer device provided in Example 3 of the present invention. Figure 8 A block diagram of an exemplary computer device 12 suitable for use in implementing embodiments of the present invention is shown. Figure 8 The computer device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0136] like Figure 8 As shown, computer device 12 is implemented as a general-purpose computing device. Components of computer device 12 may include, but are not limited to, one or more processors or processing units 16, system memory 28, and a bus 18 that connects various system components (including system memory 28 and processing unit 16).
[0137] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. Examples of these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0138] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0139] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be configured to read and write non-removable, non-volatile magnetic media ( Figure 8 Not shown, usually called a "hard drive"). Although Figure 8Although not shown, a magnetic disk drive for reading and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), as well as an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of various embodiments of the present invention.
[0140] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may include an implementation of a network environment. Program modules 42 generally implement the functions and / or methodologies of the embodiments described herein.
[0141] The computer device 12 may also communicate with one or more external devices 14 (e.g., a keyboard, a pointing device, a display 24, etc.), one or more devices that enable a user to interact with the computer device 12, and / or any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication may be performed via an input / output (I / O) interface 22. Furthermore, the computer device 12 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 20. As shown, the network adapter 20 communicates with the other modules of the computer device 12 via the bus 18. It should be understood that although Figure 8 Not shown, other hardware and / or software modules may be used in conjunction with computer device 12, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0142] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing the geometric contour extraction method of a CAD drawing provided in an embodiment of the present invention.
[0143] Example 4
[0144] A fourth embodiment of the present invention provides a computer-readable storage medium having computer-executable instructions stored thereon. When the instructions are executed by a processor, the method for extracting the geometric contour of a CAD drawing provided in all the embodiments of the invention of this application is implemented.
[0145] Any combination of one or more computer-readable media may be employed. A computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0146] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0147] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0148] Computer program code for performing the operations of the present invention may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0149] In summary, after reading this detailed disclosure, those skilled in the art will appreciate that the foregoing detailed disclosure may be presented by way of example only and may not be limiting. Although not explicitly stated herein, those skilled in the art will understand that this application is intended to encompass various reasonable changes, improvements, and modifications to the embodiments. Such changes, improvements, and modifications are intended to be proposed by this application and are within the spirit and scope of the exemplary embodiments of this application.
[0150] In addition, certain terms in this application have been used to describe embodiments of the present application. For example, "one embodiment," "an embodiment," and / or "some embodiments" mean that a particular feature, structure, or characteristic described in conjunction with that embodiment may be included in at least one embodiment of the present application. Therefore, it is emphasized and should be understood that two or more references to "an embodiment," "one embodiment," or "an alternative embodiment" in various parts of this specification do not necessarily refer to the same embodiment. Furthermore, particular features, structures, or characteristics may be appropriately combined in one or more embodiments of the present application.
[0151] It should be understood that in the foregoing description of the embodiments of this application, in order to facilitate understanding of a feature and to simplify this application, this application combines various features into a single embodiment, figure, or description thereof. However, this does not mean that the combination of these features is required. When reading this application, it is entirely possible for those skilled in the art to extract some of the features and understand them as separate embodiments. In other words, the embodiments of this application can also be understood as the integration of multiple secondary embodiments. This also applies when the content of each secondary embodiment is less than all the features of a single aforementioned disclosed embodiment.
[0152] Finally, it should be understood that the embodiments of the application disclosed herein are illustrations of the principles of the embodiments of the present application. Other modified embodiments are also within the scope of the present application. Therefore, the embodiments disclosed in the present application are merely examples and not limitations. Those skilled in the art can adopt alternative configurations based on the embodiments in the present application to implement the applications in the present application. Therefore, the embodiments of the present application are not limited to the embodiments precisely described in the application.
Claims
1. A method for extracting geometric contours from CAD drawings, characterized in that: The method comprises: S10, inputting the contour points of the CAD drawing, performing full circle contour extraction, and obtaining the full circle contour and remaining contour points; S20, simplifying the remaining contour points using the Douglas-Peucker algorithm, and segmenting the contour points using the simplified point set to obtain a segmented contour array; S30. In the contour array, calculate the scores of two adjacent contour fitting circles whose distance between the first and last points meets the requirement, and determine whether they are fused into one contour; after fusion, fit a circle and a straight line to each contour point, and calculate the residual. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than an empirical threshold, the contour is an arc; otherwise, the contour is a line segment. S40: For a contour of line segment type, set the first and last points to fit the line segment model; for a contour of arc type, use the distance and angle to determine the arc angle to fit the arc model.
2. The method for extracting geometric contours from CAD drawings according to claim 1, wherein: Step S10 includes: S11, input the contour points of the CAD drawing; S12, using connectivity segmentation and distance threshold to preliminarily divide the contour points into several disconnected contour sets; S13, connecting the contours whose first and last points are very close to each other, and calculating the mean smoothed contour point within a certain range for each point; S14. Fit the smoothed point set to a circle using the least squares method, and determine whether the distance from each point to the center of the circle is close to the radius, thereby calculating the proportion of the point on the circle; if the proportion is greater than a preset proportion threshold, the shape of the contour is determined to be a circle, the contour is extracted, and fitted into a circle model to obtain the entire circle contour and the remaining contour points.
3. The method for extracting geometric contours from CAD drawings according to claim 2, wherein: The least squares fitting circle formula is: ; in, is the variance, is the number of points of the current contour, so When it is minimum, calculate the center of the circle and radius .
4. The method for extracting geometric contours from CAD drawings according to claim 1, wherein: Step S20 includes: S21. For the remaining contour points, assume that points, find the first point P1 and the last point P2 to form a straight line, and calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P3; S22. Determine the maximum distance and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P3 is retained; S23. Based on the retained farthest point P3, connect the first point P1 and the farthest point P3 as the new starting and ending points to form a straight line, and calculate the distance between each point and the straight line. , and determine the one with the greatest distance The farthest point P4, and the farthest point P3 and the tail point P2 as the new starting and ending points to connect into a straight line, calculate the distance between each point and the straight line , and determine the one with the greatest distance The farthest point P5; respectively determine the farthest point P4 and the farthest point P5 and the first preset distance threshold If it is greater than the first preset distance threshold , then the farthest point P4 and the farthest point P5 are retained, and the above steps of taking the retained farthest points as the new first and last points are repeated until no points that meet the requirements are found, and the simplified point set is obtained; S24, using the simplified point set as the boundary, divide the contour points into multiple small segments to obtain the contour array .
5. The method for extracting geometric contours from CAD drawings according to claim 1, wherein: Step S30 includes: S31. Assume contour array Total Segment, calculate and judge the contours of two adjacent segments and The distance between the first and last points, If it is less than the second preset distance threshold, the points of the two contours are fitted into a circle and the score is calculated. If the score is higher than or equal to the preset score threshold, the two contours are merged into one contour, which is defined as , clear , thus and Calculation and judgment of the distance between the first and last points; if the score is lower than the preset score threshold, and Calculate and judge the distance between the first and last points until the traversal is completed and a new contour array is obtained ; S32, for the new contour array For each contour point in , a circle and a straight line are fitted respectively and the residual is calculated. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than the empirical threshold, the contour is an arc, otherwise the contour is a line segment.
6. The method for extracting geometric contours from CAD drawings according to claim 1, wherein: The empirical threshold is 0.
1.
7. The method for extracting geometric contours from CAD drawings according to claim 1, wherein: Step S40 includes: S41. For a contour of line segment type, set the first and last points to fit the line segment model; S42. For an arc-shaped contour, calculate the vector between the starting point of the arc contour and the center of the fitted circle. and the vector between the end point of the contour and the center of the circle , if the vector and vector If the angle between them is greater than the preset angle threshold, the cross product is used to determine whether the midpoint of the arc is on the left or right of the vector composed of the first and last points to calculate different angle fitting models. If the angle is not greater than the preset angle threshold, the sum of the distances of the contour points in the two opening directions is calculated respectively. The opening angle that is closer to the sum of the original contour point distances is the correct angle, thereby fitting the arc model.
8. A geometric contour extraction system for CAD drawings, characterized in that: The system comprises: The full circle contour extraction module is used to input the contour points of the CAD drawing, perform full circle contour extraction, and obtain the full circle contour and the remaining contour points; The contour point segmentation module is used to simplify the remaining contour points using the Douglas-Peucker algorithm and segment the contour points using the simplified point set to obtain a segmented contour array; The contour type judgment module is used to calculate the score of two adjacent contour fitting circles in the contour array whose starting and ending points meet the requirements, and determine whether they are fused into a single contour. After fusion, a circle and a straight line are fitted to each contour point and the residual is calculated. If the residual of the circle is smaller and the difference between the straight line and the circle is greater than the empirical threshold, the contour is an arc; otherwise, the contour is a line segment. The geometric model generation module is used to set the first and last points of the line segment model for the contour of the line segment type, and to fit the arc model for the contour of the arc type by using the distance and angle to judge the arc angle.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the method for extracting the geometric outline of a CAD drawing according to any one of claims 1 to 7 is implemented.
10. A storage medium containing computer-executable instructions, characterized in that: The computer executable instructions are executed by a computer processor to implement the method for extracting the geometric contour of a CAD drawing according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and system for shape point optimization based on curvature
CN108469263A
Entity profile curve extraction method based on digital model
CN114626157A