A method and system for arranging annotation hierarchical avoidance for two-dimensional drawings
By constructing scatter plots and mirror partitions, combined with hierarchical avoidance strategies and bidirectional offset algorithms, the annotation layout in two-dimensional drawings is automatically processed, solving the problems of annotation overlap and confusion, improving the readability and aesthetics of the drawings, and increasing processing efficiency.
Patent Information
- Application Number
- CN202510689150.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-27
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2045-05-27
AI Technical Summary
Existing CAD software lacks effective avoidance processing when arranging annotations in two-dimensional drawings, which leads to overlapping and confusion of annotations, requires a lot of manual intervention, and is inefficient.
A hierarchical avoidance layout method for annotations in two-dimensional drawings is adopted. By constructing a scatter plot, mirror partitioning and hierarchical avoidance strategy, the layout of annotations is automatically processed, including uniform distribution and avoidance within the drawing frame, and the bidirectional offset algorithm and the nearest avoidance algorithm are used to optimize the annotation position.
It significantly improves the automation and efficiency of annotation arrangement, solves the problem of annotation overlap, improves the readability and aesthetics of drawings, reduces calculation complexity, and increases the processing speed of large-scale drawings.
Smart Images

Figure CN120197250B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of engineering digitalization technology, and in particular to a method and system for arranging annotation hierarchical avoidance for two-dimensional drawings. Background Art
[0002] With the increasing complexity of modern engineering, the workload and difficulty of engineering drawing have increased significantly, placing higher demands on drawing efficiency and drawing quality. Computer-aided design (CAD) technology, with its parametric modeling and geometric operation engine, has enabled digital editing of graphics, coordinate transformation, and massive data management, effectively improving the reusability and design standardization of drawings. However, in two-dimensional drawings, annotations are an important part of the drawings. However, due to the fixed position of components in the drawings, annotations often need to be flexibly moved to avoid components and other annotations to ensure the readability and aesthetics of the drawings.
[0003] While existing CAD software like AutoCAD can export annotation characters, they lack effective avoidance in annotation placement, leading to overlapping and chaotic annotations. While some avoidance methods exist that simply adjust annotation positions by sliding, these methods are inefficient and still require significant manual intervention.
[0004] In response to the above problems, the present disclosure proposes a method for automatic arrangement of annotations with hierarchical avoidance for two-dimensional drawings. This method can realize automatic avoidance and reasonable arrangement of annotations in the design of two-dimensional drawings with dense annotations, without the need for designers to manually adjust a large number of annotations one by one, thereby significantly reducing the drawing workload, shortening the drawing cycle, and improving drawing efficiency. Summary of the Invention
[0005] The present disclosure provides a method and system for hierarchical avoidance arrangement of annotations for two-dimensional drawings, which can realize automatic avoidance and reasonable arrangement of annotations in the design of two-dimensional drawings with dense annotations, effectively solve the problem of overlapping annotations in complex layouts, and realize uniform distribution of annotations within the drawing frame, significantly improving the overall readability and aesthetics of the drawings, while greatly improving the degree of automation and efficiency of annotation arrangement.
[0006] In a first aspect, the present disclosure provides a method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings, comprising:
[0007] Step S1: Obtaining the two-dimensional CAD drawing data to be processed;
[0008] Step S2: construct a scatter plot, fit a cutting path according to the scatter plot, and execute cutting to generate a frame;
[0009] Step S3: performing mirror partitioning within the frame according to the center of gravity of the pipeline object;
[0010] Step S4: Arrange the labels in an offset avoidance manner based on a hierarchical avoidance arrangement strategy.
[0011] In some embodiments, the two-dimensional drawing data includes at least pipeline objects and annotations.
[0012] In some embodiments, step S2 includes: constructing a scatter plot, calculating a cutting path according to the scatter plot, and cutting continuously along the cutting path according to cutting units to obtain at least one rectangular frame.
[0013] In some embodiments, step S3 includes:
[0014] Step S31: Calculate the center of gravity: within the frame, calculate the center of gravity of all pipeline objects in the frame by averaging the coordinates of the midpoints of all pipe segment objects;
[0015] Step S32: Mirror partitioning: Using the axis of the center of gravity as the dividing line, the drawing frame is divided into the upper half and the lower half. Each pipe segment object is divided into the corresponding area according to the coordinates of the midpoint of the pipe segment object. The axis of the center of gravity is a straight line passing through the center of gravity and parallel to the horizontal border of the drawing frame.
[0016] In some embodiments, step S4 includes:
[0017] Step S41: selecting a target total width of annotation, wherein the target total width of annotation includes the annotation width and the annotation interval width;
[0018] Step S42: using a bidirectional offset arrangement algorithm to arrange the annotations within the pipe segment object;
[0019] Step S43: After completing the offset avoidance arrangement within the pipe segment object, the nearest avoidance algorithm within the layout space is used to perform labeling arrangement between the pipe segment objects.
[0020] In some embodiments, the bidirectional offset arrangement algorithm includes:
[0021] 1) Sort the annotations within the pipe segment object according to the left-right order of the annotation leader start points and determine the first sort number;
[0022] 2) With the baseline as the central axis, the offset of each annotation within the pipe segment object is calculated based on the uniform distribution principle of arithmetic progression, and automated offset avoidance arrangement is performed.
[0023] In some embodiments, the nearest avoidance algorithm in the layout space may include:
[0024] 1) For the half area of the frame, first sort the annotation set of each pipe segment object according to the left-right order of the midpoint coordinates of each pipe segment object, and determine the second sorting number;
[0025] 2) Calculate the layout space of the annotation set block corresponding to the current pipe segment object;
[0026] The layout space of the second sorted set of marked blocks numbered j ( ) is calculated as follows:
[0027] ;
[0028] Where, , x represents the total width of the target annotation, Indicates the width of the annotation, m indicates the width of the interval between annotations, Indicates the width of the frame, represents the number of annotations in the jth annotation set block, It represents the total number of annotations of all the annotation set blocks that are in the same half area as the j-th annotation set block and on the right side of the j-th annotation set block, that is, , Indicates the offset of the j-1th annotation set block. hour, , ; j represents the second sorting number of the marked set block, j is an integer, and ;
[0029] 3) Determine the nearest offset of the annotation set block corresponding to the current pipe segment object , and perform automatic offset avoidance arrangement, wherein the nearest offset is the offset of the closest parallel distance between the central axis of the current annotation set block and the baseline of the current pipe segment object midpoint within the layout space of the annotation set block corresponding to the current pipe segment object ;
[0030] 4) Repeat steps 2) to 3) above to determine the offset of each annotation set in the half area ;
[0031] 5) Repeat steps 1) to 4) for the other half of the frame.
[0032] In some embodiments, step S41 includes:
[0033] 1) The maximum value of the total width of the annotation is calculated based on the drawing frame width and the number of first annotations, and the maximum value of the annotation width is determined in combination with the minimum value of the annotation interval width;
[0034] 2) determining whether the maximum value of the annotation width that can be set is not less than the minimum value of the first preset range; if so, proceeding to step 3); if not, prompting the user to select a larger frame or reduce the number of annotations;
[0035] 3) determining a second preset range based on the first preset range and the maximum value that can be set for the annotation width, and displaying the second preset range to the user; determining a value range of the annotation interval width in response to the annotation width selected by the user, and calculating the target annotation total width based on the annotation interval width selected by the user.
[0036] In some embodiments, step S2 includes:
[0037] 1) Construct a scatter plot and calculate the width of the scatter distribution band;
[0038] 2) Select the frame size and scale the scatter distribution strip area;
[0039] 3) Fit the cutting path based on the scatter plot and determine the cutting unit. The cutting unit is the frame width minus the reserved redundancy.
[0040] 4) Perform step-by-step cutting along the cutting path with the cutting unit as the step length to generate the frame.
[0041] In a second aspect, the present disclosure provides a system for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings, which is used to execute the method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings. The system includes:
[0042] Drawing acquisition module, used to obtain the two-dimensional CAD drawing data to be processed;
[0043] The frame generation module is used to construct a scatter plot, fit a cutting path according to the scatter plot, and execute cutting to generate a frame;
[0044] Mirror partition module, used to perform mirror partitioning according to the center of gravity of pipeline objects within the frame range;
[0045] The automatic layout module is used to offset and avoid the layout of annotations based on a hierarchical avoidance layout strategy.
[0046] The beneficial effects of the present disclosure are that, compared with the prior art, the present disclosure has the following advantages:
[0047] 1) This disclosed implementation is suitable for intelligent annotation layout optimization in CAD drawings of various pipeline networks (such as urban groundwater networks, power lines, and gas pipelines). By optimizing annotation layout hierarchically, it first performs local optimization within pipe segment objects, ensuring uniform and non-overlapping distribution of annotations within each segment. It then performs global optimization across segments, precisely calculating the offsets of each annotation set block to avoid interference between annotations on different segments. This approach splits the problem of global annotation layout optimization into a linearly complex first-level avoidance (within a segment) and a polynomially complex second-level avoidance (between segments). This hierarchical layout strategy reduces the algorithm's time complexity from O(n²) to O(n log n), significantly improving the processing speed of large-scale pipeline network drawings. Furthermore, this approach not only effectively addresses the issue of overlapping annotations in complex layouts but also ensures uniform distribution of annotations within the drawing frame, significantly improving the overall readability and aesthetics of the drawing while significantly increasing the automation and efficiency of annotation layout.
[0048] 2) When verifying the capacity of the drawing frame, the disclosed embodiment uses the first preset range as the parameter range of the annotation width based on actual engineering application requirements to ensure that the font display is clear and easy to identify. Whether the maximum value that can be set according to the annotation width meets the minimum value requirement of the first preset range can accurately determine whether the drawing frame has the capacity to accommodate all annotations. If it is found that the drawing frame does not have the capacity to accommodate all annotations, the user is promptly prompted to select a larger frame or reduce the number of annotations to avoid overlapping annotations or unclear display due to font reduction due to insufficient space. In addition, on the basis of meeting the capacity, the user is allowed to flexibly select the annotation width according to actual needs within the second preset range. This free setting mechanism meets the personalized requirements of different projects for the aesthetics and clarity of annotations while ensuring the reasonable layout of the annotations in the drawing frame.
[0049] 3) By combining a concave hull polygon algorithm, appropriate scaling strategies, cropping redundancy settings, and overlay checking and correction, this disclosed implementation significantly improves the accuracy and efficiency of the cropping process, ensuring the precision of subsequent automated annotation placement. This approach optimizes the cropping process, reduces manual intervention, and increases the speed and automation of processing large datasets. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0051] Figure 1 A schematic flow chart of a method for arranging annotations in a hierarchical, avoidance manner for two-dimensional drawings provided by an embodiment of the present disclosure;
[0052] Figure 2 An example of annotation for a two-dimensional drawing provided in an embodiment of the present disclosure;
[0053] Figure 3 A schematic diagram of a mirror partition provided in an embodiment of the present disclosure;
[0054] Figure 4 A flowchart of a method for offset avoidance arrangement of annotations based on a hierarchical avoidance arrangement strategy provided in an embodiment of the present disclosure;
[0055] Figure 5 A schematic diagram of the arrangement of frame annotations provided in an embodiment of the present disclosure;
[0056] Figure 6 A schematic diagram illustrating the arrangement of markings within a pipe section according to an embodiment of the present disclosure;
[0057] Figure 7 A schematic diagram of the bidirectional offset arrangement algorithm flow provided in an embodiment of the present disclosure;
[0058] Figure 8 A schematic diagram of the arrangement of pipe segment markings provided in an embodiment of the present disclosure;
[0059] Figure 9 A schematic diagram of the flow of a nearby avoidance algorithm within a configurable space provided by an embodiment of the present disclosure;
[0060] Figure 10 A schematic diagram of the structure of a hierarchical avoidance arrangement system for annotations on two-dimensional drawings provided in an embodiment of the present disclosure.
[0061] The above drawings illustrate specific embodiments of the present disclosure, which will be described in more detail below. These drawings and textual descriptions are not intended to limit the scope of the present disclosure in any way, but rather to illustrate the concepts of the present disclosure to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION
[0062] The present disclosure is further described below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solutions of the present disclosure and are not intended to limit the scope of protection of the present disclosure.
[0063] It should be noted that the order of the steps in the present disclosure is only for illustrative purposes. During actual implementation, the order can be adjusted as needed, or some steps can be executed in parallel. Unless the execution of a certain step is clearly dependent on the result of the previous step, the order between the steps does not constitute a limitation on the present disclosure.
[0064] The method and system for the hierarchical avoidance layout of annotations for two-dimensional drawings provided by the present invention are secondary developed based on CAD graphics-aided design platforms (such as AutoCAD, MicroStation, etc.). They can be used as independent plug-ins or integrated into CAD platforms. They are mainly used for intelligent annotation layout optimization of CAD drawings of various pipeline networks (such as urban underground water pipeline networks, power line networks, gas pipelines, etc.).
[0065] like Figure 1 As shown, this embodiment provides a method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings, which is applied to a CAD platform and includes the following steps:
[0066] Step S1: Obtaining the two-dimensional CAD drawing data to be processed;
[0067] Specifically, 2D drawing data can be obtained through electronic file import (e.g., DWG or DXF format), database query, or manual input, and stored in a structured format for subsequent processing. This embodiment uses a database query method to obtain drawing data. The database can be deployed on a local computing device or in the cloud. The data in the database is checked and entered on-site by construction personnel. The data is obtained through a database query interface in JSON format and used to draw the drawings.
[0068] In this embodiment, the drawing data includes a two-dimensional pipeline model drawn using polyline or line entities (it will be understood that the "pipeline object" and "pipe segment object" mentioned in the following embodiment method steps refer to entity objects in model space), annotations used to describe defect point information, and leader lines used to point the annotations to the defect point locations. The pipeline entity attributes include layer information, geometric position coordinate data, defect point location information, length parameters, and the pipeline number in extended attributes. The defect point annotations are stored in a separate annotation layer, associated with the defect point in the corresponding pipeline entity via leader annotations, and include extended attribute data such as defect descriptions and repair measures.
[0069] The system analyzes the data structure of the CAD drawing, extracts the geometric data and attribute information of the above-mentioned entity objects, and provides a data basis for subsequent processing.
[0070] Among them, the defect description and repair measures are the annotations to be processed, which will eventually be drawn in the form of lead annotations on the two-dimensional drawing. Figure 2As shown, it includes the defect description "53YS0041-53YS0038 2.7-meter-high rupture level 2" and the repair measures "mechanical spiral winding lining method + segment lining method (3S module method)"; "53YS0041-53YS0038" is the pipe section number, and a 2-level rupture defect occurs at 2.7 meters in this pipe section, requiring both "mechanical spiral winding lining method" and "segment lining method (3S module method)" to repair this defect.
[0071] Step S2: construct a scatter plot, fit a cutting path according to the scatter plot, and execute cutting to generate a frame;
[0072] In this embodiment, the annotated objects in the two-dimensional drawing are pipelines (e.g., urban groundwater pipelines). The descriptions of the defects to be addressed and the repair measures are annotated with leaders at the defect points on the pipelines. Therefore, the endpoints and midpoints of all pipeline segments in the pipeline network object can be used as sampling points. A scatter plot is constructed by extracting the coordinates of the segment endpoints and midpoints. Because pipelines (e.g., urban groundwater pipelines) are primarily distributed along roads, the scatter plot also appears to be distributed roughly in a strip along the roads.
[0073] It should be noted that the method of dividing the pipe sections on the pipeline can adopt, for example, the length spacing method, the turning point / node method, etc., and this disclosure does not make specific limitations on this.
[0074] When constructing a scatter plot, a sampling method is generally used to select representative sampling points so that they can accurately reflect the distribution of the target elements.
[0075] Then, a cutting path is calculated according to the scatter plot, and the cutting is performed continuously along the cutting path according to the cutting units to obtain at least one rectangular frame.
[0076] The clipping path is a curved path calculated based on the distribution fit of the scatter plot. The algorithm used in this embodiment to calculate the clipping path based on the distribution fit of the scatter plot can employ existing techniques, such as the least squares method or B-spline curves, and is not specifically limited in this disclosure. The clipping path calculated in this embodiment approximates the central axis of the road.
[0077] Optionally, the clipping unit may be a preset frame width, or the clipping unit may be set to be slightly smaller than the frame width.
[0078] In this embodiment, the drawing frame can be selected from standard A0, A1, A2, or A3 drawings. Optionally, the preset drawing frame width uses the standard A3 drawing frame width. A standard A3 drawing is 420mm wide and 297mm high, with a drawing area width of 385mm and a height of 277mm. The 385mm*277mm drawing area is the drawing frame size for cutting. Specifically, during the cutting process, when the drawing frame width is selected as the cutting unit, the specific operation is as follows: Starting from the starting point of the curved path, the drawing is continuously cut in a standard 385mm cutting unit to generate multiple rectangular frames.
[0079] The subsequent steps are the calculations performed separately in each frame.
[0080] Step S3: performing mirror partitioning within the frame according to the center of gravity of the pipeline object;
[0081] In this embodiment, considering that various pipelines (such as urban underground water pipelines, etc.) are mainly distributed in strips along both sides of the road, each pipe segment object of the pipeline object is firstly partitioned into upper and lower mirror images.
[0082] In an optional implementation, step S3 specifically includes:
[0083] Step S31: Calculate the center of gravity: within the frame, calculate the center of gravity of all pipeline objects in the frame by averaging the coordinates of the midpoints of all pipe segment objects.
[0084] Step S32: Mirror Partitioning: Using the axis of the center of gravity as the dividing line, divide the frame into the upper half and the lower half. Based on the coordinates of the midpoint of the pipe segment object, divide each pipe segment object into the corresponding area. In this embodiment, the axis of the center of gravity refers to the straight line passing through the center of gravity and parallel to the horizontal border of the frame. Figure 3 As shown, the pipe segment object with its midpoint in the upper half belongs to the upper half, and its included annotations are arranged in the upper half; the pipe segment object with its midpoint in the lower half belongs to the lower half, and its included annotations are arranged in the lower half.
[0085] It can be seen that mirror partitioning utilizes the strip-like characteristics of pipelines (such as urban groundwater pipelines) distributed along roads. By calculating the center of gravity of pipeline objects, a mirror dividing line is constructed, dividing the drawing frame into two independent upper and lower layout areas. The originally concentrated annotations are divided into regional affiliations according to the spatial position of the pipe segment objects, thereby splitting the global annotation avoidance layout into local layout optimization calculations, effectively reducing the calculation complexity and thereby improving the processing speed of large-scale pipeline network drawings.
[0086] Step S4: Arrange the labels in an offset avoidance manner based on a hierarchical avoidance arrangement strategy.
[0087] Typically, each drawing frame includes several pipe segment objects, each pipe segment object includes several annotations, and the pipe segment objects are in a parallel relationship. Therefore, when arranging annotations, we must consider not only how the annotations within the pipe segment object are arranged, but also how the annotations between different pipe segment objects are arranged. Figure 5 As shown, the outer rectangle is a drawing frame, which contains six pipe segment objects, and each pipe segment object contains several annotations.
[0088] Therefore, this hierarchical avoidance arrangement strategy can be divided into two levels: avoidance within a pipe segment object and avoidance between pipe segments. Within a pipe segment object is the first level of avoidance, while between pipe segments is the second level of avoidance. Therefore, to arrange all annotations based on this hierarchical avoidance arrangement strategy, it is necessary to first arrange the annotations locally within the pipe segment object. Then, for the annotations between different pipe segments, avoidance arrangement between pipe segments (i.e., pipe segments within the drawing frame) is performed, ultimately achieving global annotation arrangement optimization.
[0089] In an optional embodiment, as Figure 4 As shown, the step S4: performing offset avoidance arrangement on the annotations based on the hierarchical avoidance arrangement strategy specifically includes:
[0090] Step S41: selecting a target total width of annotation, wherein the target total width of annotation includes the annotation width and the annotation interval width;
[0091] In actual projects, to ensure clear label fonts, it's often necessary to set parameter ranges for the label width and label interval width. Within this parameter range, the user selects a target total label width, including both the label width and the label interval width, to determine the final total label width. It's understood that the label length can be pre-set based on actual project requirements. Since label layout optimization primarily considers avoidance layout along the width direction, the label length setting is not limited here.
[0092] Step S42: using a bidirectional offset arrangement algorithm to arrange the annotations within the pipe segment object;
[0093] In this embodiment, the axis passing through the midpoint of the pipe segment object and perpendicular to the mirror partition boundary direction is defined as the reference line, such as Figure 6 As shown in the figure, the dashed line represents the baseline of the pipe segment object. The offset d of a dimension is defined as the parallel distance of the dimension's center axis relative to the baseline. That is, when the dimension's center axis is on the baseline, offset d = 0; when it is to the right of the baseline, offset d > 0; and when it is to the left of the baseline, offset d < 0. The rectangular box represents the actual area occupied by the dimension. Dimensions are typically presented as rectangular boxes in engineering drawings.
[0094] The annotation center axis refers to a straight line passing through the center point of the annotation box and parallel to the long side of the annotation box. The annotation box is a rectangular box used to replace the annotation form.
[0095] In an alternative embodiment, referring to Figure 7 , the bidirectional offset arrangement algorithm specifically includes:
[0096] 1) Sort the annotations within the pipe segment object according to the left-right order of the annotation leader start points and determine the first sort number;
[0097] Specifically, before calculating the offset of each annotation, the annotations within the pipe segment object must be sorted. Since the starting point of the annotation's leader is the defect point on the pipe segment object, the position of the defect point is fixed, so the annotations can be sorted according to the left-right order of the leader's starting point. Figure 6 As shown, the pipe segment object has a total of n annotations, and the first sorting numbers of the annotations from left to right are 0 to n-1.
[0098] 2) With the baseline as the central axis, the offset of each annotation within the pipe segment object is calculated based on the uniform distribution principle of arithmetic progression, and automated offset avoidance arrangement is performed;
[0099] By processing the offset based on the principle of uniform distribution of arithmetic progression, the annotations within the pipe segment object can be evenly arranged at equal intervals.
[0100] The first sort number is The label offset The calculation formula is as follows:
[0101]
[0102] It can be seen from this that The tolerance is An arithmetic progression, where , x represents the total width of the target annotation, Indicates the width of the label. Indicates the width of the interval between annotations, n is the number of annotations in the pipe section, Indicates the first sorting number of the annotation, is an integer, and .
[0103] Finally, the annotations within the pipe segment object are automatically offset and arranged based on each annotation's offset and baseline position, ensuring no overlap. This ensures that the annotations within the pipe segment object are evenly distributed near the object's center, achieving optimal placement within the object.
[0104] Step S43: After completing the offset avoidance arrangement within the pipe segment object, the nearest avoidance algorithm within the layout space is used to perform label arrangement between the pipe segment objects;
[0105] It is understandable that after the avoidance process is completed within the pipe segment object, the annotations within each pipe segment object form a annotation set block. The central axis of the annotation set block is defined as the axis that is collinear with the baseline in step S42 before the avoidance process between pipe segment objects. The width of each annotation set block is , where x represents the total width of the target annotation, Indicates the number of annotations in the jth annotation set block.
[0106] like Figure 8 As shown in the figure, the dotted rectangle is the annotation set block of the pipe segment object, which will be used as a whole for the avoidance calculation between pipe segment objects. In this embodiment, the parallel distance between the central axis of each annotation set block (i.e. the central axis of the dotted rectangle) and the left edge of the frame is defined. is the offset of the marked set block. The key to avoidance between pipe segments is to calculate the offset corresponding to the marked set block of each pipe segment object.
[0107] Based on the idea of first clarifying the constraints and then finding the extreme values under the constraints in operations research, a nearest avoidance algorithm in a layout space is obtained. After completing the offset avoidance arrangement within the pipe segment object, the nearest avoidance algorithm in the layout space is used to perform the offset avoidance arrangement between pipe segment objects.
[0108] It should be noted that the frame has been divided into two halves, the upper and lower halves. The two halves should be sorted and subsequently calculated independently without interfering with each other; however, the processing methods for the two halves are exactly the same.
[0109] Reference Figure 9 The specific implementation steps of the nearest avoidance algorithm in the layout space are as follows:
[0110] 1) For the half area of the frame, first sort the annotation set blocks of each pipe segment object according to the left-right order of the midpoint coordinates of each pipe segment object, and determine the second sorting number;
[0111] Specifically, the annotation set blocks of the pipe segment objects are sorted according to the left and right order of the midpoint coordinates of each pipe segment object, such as Figure 8 As shown, there are N labeled set blocks in the half-area of the frame, which are numbered from left to right, thereby determining the second sorting number range to be 0 to N-1.
[0112] 2) Calculate the layout space of the annotation set block corresponding to the current pipe segment object ( );
[0113] The layout space of the second sorted set of marked blocks numbered j ( ) is calculated as follows:
[0114] ;
[0115] Where, , x represents the total width of the target annotation, Indicates the width of the annotation, m indicates the width of the interval between annotations, Indicates the width of the frame, represents the number of annotations in the jth annotation set block, It represents the total number of annotations of all the annotation set blocks that are in the same half (upper or lower half) as the jth annotation set block and to the right of the jth annotation set block, that is, , Indicates the offset of the j-1th annotation set block. hour, , ; j represents the second sorting number of the marked set block, j is an integer, and .
[0116] "Layoutable space" refers to the frame area where the current pipe segment object annotation set block does not overlap with other pipe segment object annotation set blocks, where: The minimum offset value indicating that the second sorted tag set block numbered j does not overlap with the adjacent tag set block, The maximum offset value indicating that the second sorted tag set block numbered j does not overlap with the adjacent tag set block, and The two constitute the constraint interval of the current pipe segment object annotation set block layout, that is, the layout space;
[0117] 3) Determine the nearest offset of the annotation set block corresponding to the current pipe segment object , and perform automatic offset avoidance arrangement, wherein the nearest offset is the layout space of the annotation set block corresponding to the current pipe segment object ( ), the closest offset between the center axis of the current annotation set block and the baseline of the current pipe segment object midpoint .
[0118] Layout space ( ) can achieve that the annotation set block of the current pipe segment object does not overlap with the annotation set blocks of other pipe segment objects, but the center axis of the current annotation set block (the center axis of the dotted rectangle) and the baseline where the midpoint of the current pipe segment object is located (i.e. Figure 6The distance between the dotted line and the center line is the shortest, so that the annotation leader line is the shortest and the layout is the most beautiful. ) to obtain the nearest offset .
[0119] 4) Repeat steps 2) to 3) above to determine the offset of each labeled set block in the half area , and automatically offset and arrange each annotation set block between pipe segment objects according to the offset of each annotation set block, ensuring that there is no overlap between the arrangements of annotation set blocks of different pipe segment objects.
[0120] As an example scenario, assume the following parameters: , , , frame width , the number of markings in the upper half , , , ; According to the calculation, we can get: , , ; According to the nearest avoidance algorithm in the layout space, we can get: The layout space is (6mm, 352mm). It is the closest offset between the center axis of the annotation set block and the baseline of the current pipe segment object midpoint within the layout space (6mm, 352mm). and , the processing method is the same as above.
[0121] 5) Repeat steps 1) to 4) for the other half of the frame, i.e., use the same method to arrange the annotations between the pipe objects in the two halves.
[0122] This ensures that there is no overlap between the annotation set blocks of different pipe segment objects and that they are distributed as evenly as possible around the center area of each pipe segment object, thereby achieving an optimized arrangement of all annotations within the drawing range.
[0123] In this embodiment, the layout of annotations is optimized hierarchically. First, the annotations are locally optimized within the pipe segment object to ensure that the annotations within each pipe segment object are evenly distributed and overlap-free. Then, a global optimization is performed between the pipe segment objects, and the offset of each annotation set block is accurately calculated to avoid mutual interference between the annotations of different pipe segment objects. On the one hand, this method splits the problem of global annotation layout optimization into a first-level avoidance (within the pipe segment object) with linear complexity and a second-level avoidance (between pipe segment objects) with polynomial complexity, greatly reducing the computational complexity and significantly improving the processing speed of large-scale pipe network drawings. On the other hand, this method not only effectively solves the problem of annotation overlap in complex layouts, but also achieves a uniform distribution of annotations within the drawing frame, improving the readability, overall aesthetics, and automation efficiency of the drawing.
[0124] In an optional embodiment, the step S41: selecting the target total width of the annotation, wherein the target total width of the annotation includes the annotation width and the annotation interval width, is specifically performed as follows:
[0125] 1) The maximum value of the dimension width can be set. The maximum value of the total dimension width can be calculated based on the drawing frame width and the number of first dimensions, and is determined in combination with the minimum dimension interval width.
[0126] To ensure that all annotations can be accommodated in the drawing frame, you need to first determine the maximum settable value of the annotation width.
[0127] In actual engineering, in order to ensure that the annotation font is displayed clearly, it is usually necessary to set a parameter range for the annotation interval width. For example, the minimum value of the annotation interval width can be set to a fixed value (such as 0.5mm), or determined in proportion to the annotation width (such as ).
[0128] Specifically, the step of calculating the maximum value of the total annotation width according to the drawing frame width and the first annotation quantity, and determining the maximum value of the annotation width according to the minimum value of the annotation interval width includes:
[0129] Get the number of annotations of the half area with more annotations in the upper and lower half areas as the first annotation number, recorded as , get the frame width L. The calculation formula for the maximum value of the total width of the annotation can be set is: .
[0130] Finally, the maximum value of the dimension width can be set by calculating the dimension width based on the minimum value of the dimension interval width.
[0131] 2) Verify the frame capacity. Determine whether the maximum value of the annotation width that can be set is not less than the minimum value of the first preset range. If so, proceed to step 3). If not, prompt the user to select a larger frame size or reduce the number of annotations.
[0132] In actual projects, to ensure that the annotation font is clearly displayed, it is usually necessary to set parameter ranges for the annotation width and annotation interval width. For example, the preset parameter range for the annotation width is usually 2.5mm to 10mm.
[0133] In this step, the first preset value range of the marking width is a preset parameter range of the marking width. For example, in actual engineering, the first preset range of the marking width is usually 2.5 mm to 10 mm.
[0134] When verifying the capacity of the drawing frame, the following situations are specifically included: if the maximum value that can be set for the annotation width is not less than the minimum value of the first preset range, it means that the drawing frame can accommodate all annotations, and go to step 3); if the maximum value that can be set for the annotation width is less than the minimum value of the first preset range, it means that the drawing frame cannot accommodate all annotations. At this time, the user should be prompted to select a larger frame size or reduce the number of annotations.
[0135] Specifically, the minimum value of the first preset value range is , For example, the total width is marked Assuming that the half area with the largest number of annotations in the drawing frame has a total of 128 annotations, the maximum value of the total annotation width in the A3 standard drawing frame is , which can just fit all annotations. However, in extreme cases, such as when the number of annotations in a half-area with more annotations exceeds 128 within a frame, the maximum annotation width setting will be less than 2.5mm, failing to meet the minimum requirement of the first preset range, indicating that the frame cannot accommodate all annotations. In this case, the user should be prompted to select a larger frame size or reduce the number of annotations to ensure that all annotations can be accommodated.
[0136] 3) Setting the target total width of the annotation. A second preset range is determined based on the first preset range and the maximum value that can be set for the annotation width, and the second preset range is displayed to the user. In response to the user-selected annotation width, the range of values for the annotation interval width is determined, and the target total width of the annotation is calculated based on the user-selected annotation interval width.
[0137] Specifically, this embodiment displays the second preset range to the user through the user interface. The second preset range is determined by the first preset range and the maximum value that can be set for the marking width. For example, if the maximum value of the total marking width can be set to 4mm and the minimum width of the marking interval is , then the maximum value of the marking width can be set to 3.5mm. At this time, the second preset range is determined to be (2.5mm-3.5mm). For another example, if the total marking width is obtained, the maximum value can be set to 12mm, and the minimum marking interval width is , the maximum value of the marking width can be set to 11.5mm. At this time, the second preset range is determined to be (2.5mm-10mm).
[0138] That is to say, within the second preset range, users can select the annotation width according to actual needs, and ensure that the drawing frame can accommodate all annotations.
[0139] After the user selects a label width within the second preset range, the maximum label width is calculated in step 1 and subtracted from the selected width to determine the maximum label interval width. This determines the label interval width range. For example, if the maximum label width is 4mm, and the user selects a width of 3mm within the second preset range (2.5mm-3.5mm), the maximum label interval width is 1mm. Therefore, the label interval width range is (0.5mm-1mm). Finally, the target total label width is determined based on the selected label interval width.
[0140] Further optionally, the method further includes: in response to the user selecting a larger-sized frame, returning to step S2 to re-crop the image.
[0141] This embodiment verifies the frame's capacity based on actual engineering application requirements, using a first preset range (e.g., 2.5mm to 10mm) as the parameter range for the annotation width to ensure clear and legible fonts. Whether the maximum value of the annotation width meets the minimum value of the first preset range can accurately determine whether the frame can accommodate all annotations. If the frame is found to be unable to accommodate all annotations, the user is promptly prompted to select a larger frame or reduce the number of annotations, avoiding overlapping annotations or unclear fonts due to insufficient space.
[0142] Furthermore, on the basis of meeting the accommodation capacity, a second preset range (for example, 2.5mm to 3.5mm) is introduced to allow users to flexibly select the annotation width according to actual needs. This free setting mechanism not only ensures the reasonable layout of the annotations in the frame, but also meets the personalized requirements of different projects for the aesthetics and clarity of the annotations. By intuitively displaying the value range of the second preset range and the annotation interval width to the user, it is convenient for the user to quickly select the parameters within a reasonable range, reducing the complexity of parameter setting. In addition, in extreme cases, if the frame cannot accommodate all the annotations, the system will actively prompt the user to select a larger frame or reduce the number of annotations, avoiding the inconvenience caused by the user repeatedly adjusting the parameters.
[0143] In an optional embodiment, the step S2: constructing a scatter plot, fitting a cutting path according to the scatter plot, and executing cutting to generate a frame, includes the following steps:
[0144] 1) Construct a scatter plot and calculate the width of the scatter distribution band.
[0145] In this embodiment, the scatter plot is fitted by the concave hull polygon algorithm to generate the concave hull polygon of the scatter plot. Subsequently, sampling calculation is performed on the concave hull polygon to obtain the width of the strip area. For example, the average or maximum value of the width of all sampling points can be taken as the width of the strip area. It should be noted that this solution may also adopt other boundary fitting algorithms, which are not specifically limited in this application.
[0146] 2) Select the frame size and scale the scatter distribution strip area.
[0147] To ensure that the selected crop frame covers the scattered point distribution area, if If it is too large or too small compared to the clipping frame height, the scattered point distribution strip area needs to be appropriately scaled.
[0148] The specific operations are as follows: select the cutting frame size and obtain the frame height h; judge The relationship between the size of h is If it is too large or too small, the strip area will be scaled appropriately.
[0149] In this embodiment, set Less than the frame height h and greater than 0.5h, that is The following conditions are met: < h, and >0.5×h. Preferably, The display effect is best when
[0150] 3) Fit the cutting path according to the scatter plot and determine the cutting unit. The cutting unit is the frame width minus the reserved redundancy.
[0151] In this embodiment, the method for fitting the cutting path is described in step S2, and the specific process is not repeated here. During the cutting process, the cutting unit is set to be slightly smaller than the frame width, that is, the cutting unit is the frame width minus the reserved redundancy. Although this method may cause a certain degree of overlap between adjacent frames, it can effectively prevent the scattered points at the junction of the frames from overflowing the frame. Specifically, the ratio between the reserved redundancy and the frame width is usually set to 3%-10%; preferably, the reserved redundancy accounts for 5% of the frame width.
[0152] For example, when using an A3 drawing frame, the reserved margin is 385 × 0.05 = 19.25mm, and the actual cutting unit is set to 385 × 0.95 = 365.75mm.
[0153] 4) Perform step-by-step cutting along the cutting path with the cutting unit as the step length to generate the frame.
[0154] During the cutting process, the target curve is divided into sections along the cutting path curve at intervals of one cutting unit. A frame is placed on each target curve section, with the center of each frame centered at the midpoint of the target curve. Cutting is performed continuously in a stepwise manner, and the horizontal orientation of the frame is set according to the tangent direction of the target curve midpoint, generating multiple rectangular frames. In other words, the length of the target curve is one cutting unit.
[0155] It should be noted that, in this embodiment, the clipping unit is set to be slightly smaller than the frame width in order to ensure that even if the clipping path contains straight line segments, there is still a certain degree of overlap between adjacent frames. By subtracting the reserved redundancy from the frame width to set the clipping unit, a continuous overlapping relationship can be ensured between frames under various path forms (including straight line segments and curved segments), thereby avoiding the situation where scattered points at the junction of frames overflow the frames.
[0156] Further optionally, after step 4), the method further includes:
[0157] 5) Coverage inspection and correction after cutting.
[0158] After the cutting is completed, it is necessary to check and correct the coverage. The specific steps are as follows:
[0159] Check whether there is any scatter point overflowing the frame. If there is no overflow, the cropping is considered successful. If there is overflow, the frame position is slightly adjusted (for example, the frame is moved up or down) according to the coordinates of the overflowing scatter points.
[0160] After correction, recheck the coverage of the frame over the scattered points, that is, the proportion of scattered points within the frame to all scattered points. If the coverage of the frame over the scattered points is higher than the preset threshold, the cropping is determined to be successful. Otherwise, adjust the zoom ratio of the scattered point distribution band or the cropping unit length and re-execute the cropping. Preferably, the preset coverage threshold is set to 90%.
[0161] This embodiment significantly improves the accuracy and efficiency of the cutting process by combining the concave hull polygon algorithm, appropriate scaling strategy, cutting redundancy setting, and coverage check and correction, thereby ensuring the accuracy of subsequent automatic labeling arrangement. Specifically, first, a strip area is fitted by a scatter plot, and scaled in combination with the frame size to ensure that the cutting can fully cover the scattered point distribution area. The setting of cutting redundancy effectively avoids the overflow of scattered points between adjacent frames, thereby ensuring the integrity of the scattered points at the frame boundary. In addition, after cutting, the frame position can be further accurately adjusted through the coverage check and correction steps to avoid the omission of scattered points and ensure a high coverage rate of scattered points by the frame. This method optimizes the cutting process, reduces manual intervention, and improves the processing speed and automation level of large-scale data sets.
[0162] On the other hand, Figure 10 As shown, this embodiment provides a system 100 for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings, which is used to execute the method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings as described in the above embodiments. The system includes:
[0163] Drawing acquisition module 101, used to acquire two-dimensional CAD drawing data to be processed;
[0164] The frame generation module 102 is used to construct a scatter plot, fit a cutting path according to the scatter plot, and execute cutting to generate a frame;
[0165] A mirror partitioning module 103 is used to perform mirror partitioning according to the center of gravity of the pipeline object within the frame range;
[0166] The automatic arrangement module 104 is used to perform offset avoidance arrangement on the annotations based on a hierarchical avoidance arrangement strategy.
[0167] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0168] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.
[0169] It should be understood that the above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present disclosure.
Claims
1. A method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings, characterized in that: include: Step S1: Obtaining the two-dimensional CAD drawing data to be processed; Step S2: construct a scatter plot, fit a cutting path according to the scatter plot, and execute cutting to generate a frame; Step S3: performing mirror partitioning within the frame according to the center of gravity of the pipeline object; Step S4: performing offset avoidance arrangement on the annotations based on the hierarchical avoidance arrangement strategy; The bidirectional offset arrangement algorithm includes: 1) Sort the annotations within the pipe segment object according to the left-right order of the annotation leader start points and determine the first sort number; 2) With the baseline as the central axis, the offset of each annotation within the pipe segment object is calculated based on the uniform distribution principle of arithmetic progression, and automated offset avoidance arrangement is performed; The nearest avoidance algorithms within the layout space include: 1) For the half area of the frame, first sort the annotation set of each pipe segment object according to the left-right order of the midpoint coordinates of each pipe segment object, and determine the second sorting number; 2) Calculate the layout space of the annotation set block corresponding to the current pipe segment object; The layout space of the second sorted set of marked blocks numbered j ( , ) is calculated as follows: Where, , x represents the total width of the target annotation, Indicates the width of the annotation, m indicates the width of the interval between annotations, Indicates the width of the frame. represents the number of annotations in the jth annotation set block, It represents the total number of annotations of all the annotation set blocks that are in the same half area as the j-th annotation set block and on the right side of the j-th annotation set block, that is, , Indicates the offset of the j-1th annotation set block; set hour, , ; j represents the second sorting number of the marked set block, j is an integer, and ; 3) Determine the nearest offset of the annotation set block corresponding to the current pipe segment object , and perform automatic offset avoidance arrangement, wherein the nearest offset is the offset of the closest parallel distance between the central axis of the current annotation set block and the baseline of the current pipe segment object midpoint within the layout space of the annotation set block corresponding to the current pipe segment object ; 4) Repeat steps 2) to 3) above to determine the offset of each annotation set in the half area ; 5) Repeat steps 1) to 4) for the other half of the frame.
2. The method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings according to claim 1, characterized in that: The two-dimensional CAD drawing data at least includes pipeline objects and annotations.
3. The method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings according to claim 1, characterized in that: The step S2 includes: constructing a scatter plot, calculating a cutting path according to the scatter plot, and cutting the image in sequence according to cutting units along the cutting path to obtain at least one rectangular frame.
4. The method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings according to claim 1, characterized in that: The step S3 comprises: Step S31: Calculate the center of gravity: within the frame, calculate the center of gravity of all pipeline objects in the frame by averaging the coordinates of the midpoints of all pipe segment objects; Step S32: Mirror partitioning: Using the axis of the center of gravity as the dividing line, the drawing frame is divided into the upper half and the lower half. Each pipe segment object is divided into the corresponding area according to the coordinates of the midpoint of the pipe segment object. The axis of the center of gravity is a straight line passing through the center of gravity and parallel to the horizontal border of the drawing frame.
5. The method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings according to claim 1, characterized in that: The step S4 comprises: Step S41: selecting a target total width of annotation, wherein the target total width of annotation includes the annotation width and the annotation interval width; Step S42: using a bidirectional offset arrangement algorithm to arrange the annotations within the pipe segment object; Step S43: After completing the offset avoidance arrangement within the pipe segment object, the nearest avoidance algorithm within the layout space is used to perform labeling arrangement between the pipe segment objects.
6. The method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings according to claim 5, characterized in that: The step S41 includes: 1) The maximum value of the total width of the annotation is calculated based on the drawing frame width and the number of first annotations, and the maximum value of the annotation width is determined in combination with the minimum value of the annotation interval width; 2) determining whether the maximum value of the annotation width that can be set is not less than the minimum value of the first preset range; if so, proceeding to step 3); if not, prompting the user to select a larger frame or reduce the number of annotations; 3) determining a second preset range based on the first preset range and the maximum value that can be set for the annotation width, and displaying the second preset range to the user; determining a value range of the annotation interval width in response to the annotation width selected by the user, and calculating the target annotation total width based on the annotation interval width selected by the user.
7. The method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings according to any one of claims 1 to 6, characterized in that: The step S2 comprises: 1) Construct a scatter plot and calculate the width of the scatter distribution band; 2) Select the frame size and scale the scatter distribution strip area; 3) Fit the cutting path based on the scatter plot and determine the cutting unit. The cutting unit is the frame width minus the reserved redundancy. 4) Perform step-by-step cutting along the cutting path with the cutting unit as the step length to generate the frame.
8. A system for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings, for executing the method for arranging annotations in a hierarchical avoidance manner for two-dimensional drawings according to any one of claims 1 to 7, characterized in that: The system comprises: Drawing acquisition module, used to obtain the two-dimensional CAD drawing data to be processed; The frame generation module is used to construct a scatter plot, fit a cutting path according to the scatter plot, and execute cutting to generate a frame; Mirror partition module, used to perform mirror partitioning according to the center of gravity of pipeline objects within the frame range; The automatic layout module is used to offset and avoid the layout of annotations based on a hierarchical avoidance layout strategy.
Citation Information
Patent Citations
Drawing marking method and system
CN109325214A
Method for realizing avoidance arrangement of annotation characters in design drawing
CN114781013A