Method and apparatus for dividing a polygon by a broken line
By splitting polylines and polygons into line segments, sorting events and processing the event chain, and determining valid line segments, the problem of low computational efficiency in complex polygon segmentation is solved, and efficient polygon segmentation is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA MOBILE SHANGHAI ICT CO LTD
- Filing Date
- 2022-02-25
- Publication Date
- 2026-05-26
AI Technical Summary
Existing polygon segmentation methods suffer from significantly increased computational costs and reduced computational efficiency when dealing with complex polylines and self-intersection relationships.
The method of segmenting polygons using polylines involves splitting polylines and polygons into multiple line segments, sorting the line segment events, and using a polygon segmentation algorithm to process the event list, determine the valid line segments, and construct the segmented polygons.
By completing the intersection, overlap, and status marking of line segments in a single scan, computational efficiency is improved, especially in cases of complex polygons and multiple intersections.
Smart Images

Figure CN116703936B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a method and apparatus for dividing polygons using polylines. Background Technology
[0002] With the development of the geographic information and computer industries, geographic information related to our daily lives, such as maps, locations, and spatial information, can be expressed more concretely within computers, thus giving rise to more spatial computing-related needs and applications. Polyline segmentation of polygons is frequently used in many spatial computing applications.
[0003] If the polygon is complex, there are many polylines that divide the polygon, and these polylines have complex self-intersection relationships, the existing segmentation methods will significantly increase the computational cost by constructing the minimum cycle, thereby reducing computational efficiency. Summary of the Invention
[0004] In view of this, the present invention provides a method and apparatus for segmenting polygons using polylines, which solves the problem that current polygon segmentation methods significantly increase the amount of computation and thus reduce computational efficiency.
[0005] To address the aforementioned technical problems, in a first aspect, the present invention provides a method for dividing a polygon using a polyline, wherein the polyline divides the polygon into at least two parts, the method comprising:
[0006] Based on the inflection points of the polyline and the polygon, the polyline and the polygon are respectively divided into multiple line segments;
[0007] The events corresponding to the line segments are sorted to obtain an event list, and the events in the event list are processed iteratively using a polygon segmentation algorithm to obtain candidate line segments and the identifiers on both sides of each candidate line segment. The events corresponding to the line segments include: scan start event and scan end event. The scan start event corresponds to the start point of the line segment, and the scan end event corresponds to the end point of the line segment. The structure of the event includes whether the event corresponds to the start point of the line segment to which it belongs, the point coordinates of the event, the structural information of the line segment to which the event belongs, and another event corresponding to the line segment to which the event belongs. The structural information of the line segment includes the start point, end point, and the identifiers on both sides of the line segment. The identifiers are used to characterize the relative positional relationship between the line segment and the polygon and the polyline.
[0008] The valid line segments are determined based on the markings on both sides of the candidate line segments;
[0009] Based on the valid line segments, construct the segmented polygons.
[0010] Optionally, the step of sorting the events corresponding to the line segment to obtain an event linked list, and using a polygon segmentation algorithm to iteratively process the events in the event linked list to obtain the candidate line segments and the identifiers on both sides of each candidate line segment includes:
[0011] The events corresponding to the line segments obtained by the polyline are sorted to obtain a polyline event list, and the events corresponding to the line segments obtained by the polygon are sorted to obtain a polygon event list.
[0012] The first candidate line segment is obtained by iteratively processing the events in the polyline event chain using a polygon segmentation algorithm, and the second candidate line segment is obtained by iteratively processing the events in the polygon event chain. The first candidate line segment is marked with an identifier relative to the polyline on both sides, and the second candidate line segment is marked with an identifier relative to the polygon on both sides.
[0013] A combined event list is obtained by comprehensively sorting the events corresponding to the first candidate line segment and the second candidate line segment;
[0014] The events in the combined event list are processed cyclically using a polygon segmentation algorithm to obtain a third candidate line segment. The third candidate line segment is marked with an identifier relative to the polyline and an identifier relative to the polygon on both sides.
[0015] Optionally, sorting the events corresponding to the line segment to obtain an event linked list includes:
[0016] Set the scanning direction when scanning the polyline and the polygon using scan lines;
[0017] Based on the scanning direction, determine the order in which the scanning line passes through the endpoints of each line segment;
[0018] Based on the given sequence, the events corresponding to the line segments are sorted to obtain an event linked list.
[0019] Optionally, the markings on both sides of the line segment include a first marking on both sides of the line segment when the line segment is relative to the polyline and a second marking on both sides of the line segment when the line segment is relative to the polygon;
[0020] When the line segment obtained by splitting the polyline is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. When the line segment obtained by splitting the polyline is relative to the polygon, if the line segment obtained by splitting the polyline is inside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. If the line segment obtained by splitting the polyline is outside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as unfilled identifiers.
[0021] When the line segment obtained by splitting the polygon is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polygon are marked as fill identifiers. When the line segment obtained by splitting the polygon is relative to the polygon, the second identifier of the side of the line segment obtained by splitting the polygon located inside the polygon is marked as fill identifier, and the second identifier of the side of the line segment obtained by splitting the polygon located outside the polygon is marked as no fill identifier.
[0022] Optionally, determining the valid line segment based on the markings on both sides of the candidate line segment includes:
[0023] If the markings on both sides of the candidate line segment satisfy any one of the following conditions, then the candidate line segment is determined as a valid line segment:
[0024] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is unfilled, and the second mark below it is filled.
[0025] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is filled marks, and the second mark below it is unfilled marks;
[0026] When the candidate line segment is relative to the polyline, the first identifiers on both sides are fill identifiers, and when it is relative to the polygon, the second identifiers on both sides of the candidate line segment are fill identifiers.
[0027] Optionally, the step of using a polygon segmentation algorithm to iteratively process the events in the event chain to obtain the candidate line segments and the identifiers on both sides of each candidate line segment includes:
[0028] Create a state list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the first line segment, add the node corresponding to the first line segment to the state list.
[0029] If the first line segment and the second line segment intersect, the scan start event of the first line segment is split into the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment, according to the intersection point. The node corresponding to the second line segment in the state chain is adjacent to the node corresponding to the first line segment.
[0030] Insert the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment into the event chain list.
[0031] Optionally, the step of using a polygon segmentation algorithm to iteratively process the events in the event chain to obtain the candidate line segments and the identifiers on both sides of each candidate line segment includes:
[0032] Create a state list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, add the node corresponding to the third line segment to the state list.
[0033] If there are no other nodes after the node corresponding to the third line segment in the state chain, then the identifier above the third line segment is marked as a fill identifier, and the identifier below the third line segment is marked as a non-fill identifier;
[0034] If there is an adjacent node after the node corresponding to the third line segment in the state chain, then the identifier above the third line segment is marked as the same as the identifier above the line segment corresponding to the adjacent node, and the identifier below the third line segment is marked as the opposite of the identifier above the third line segment, wherein the filling identifier and the non-filling identifier are opposite to each other.
[0035] Optionally, the step of creating the state linked list, if the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, after adding the node corresponding to the third line segment to the state linked list, further includes:
[0036] If the polygon segmentation algorithm is currently processing the scan end event corresponding to the third line segment, delete the node corresponding to the third line segment from the state list;
[0037] If the first node and the second node in the state chain are adjacent after the node corresponding to the third line segment is deleted, then the identifiers on both sides of the fourth line segment are updated according to the identifiers on both sides of the fifth line segment.
[0038] Wherein, the first node is the node corresponding to the fourth line segment, the second node is the node corresponding to the fifth line segment, the first node is adjacent to the node corresponding to the third line segment and located before the node corresponding to the third line segment is deleted, and the second node is adjacent to the node corresponding to the third line segment and located after the node corresponding to the third line segment is deleted.
[0039] Optionally, constructing the segmented polygon based on the valid line segments includes:
[0040] Create an open linked list, wherein the open linked list includes at least one open chain;
[0041] Determine whether the valid line segment can be added to the end of any open chain in the open linked list. If the valid line segment cannot be added to the end of any open chain in the open linked list, then create a new open chain using the valid line segment. If the valid line segment can be added to the end of two open chains in the open linked list, then merge the two open chains into one open chain.
[0042] In a second aspect, the present invention also provides an apparatus for dividing a polygon using a polyline, wherein the polyline divides the polygon into at least two parts, the apparatus comprising:
[0043] The splitting module is used to split the polyline and the polygon into multiple line segments based on the inflection points of the polyline and the polygon, respectively.
[0044] The processing module is used to sort the events corresponding to the line segments to obtain an event chain list, and to use a polygon segmentation algorithm to iteratively process the events in the event chain list to obtain candidate line segments and the identifiers on both sides of each candidate line segment. The events corresponding to the line segments include: a scan start event and a scan end event. The scan start event corresponds to the start point of the line segment, and the scan end event corresponds to the end point of the line segment. The structure of the event includes whether the event corresponds to the start point of the line segment to which it belongs, the point coordinates of the event, the structural information of the line segment to which the event belongs, and another event corresponding to the line segment to which the event belongs. The structural information of the line segment includes the start point, the end point, and the identifiers on both sides of the line segment. The identifiers are used to characterize the relative positional relationship between the line segment and the polygon and the polyline.
[0045] The determination module is used to determine the valid line segments based on the markings on both sides of the candidate line segments;
[0046] A construction module is used to construct the segmented polygons based on the valid line segments.
[0047] Optionally, the processing module includes:
[0048] The first sorting unit is used to sort the events corresponding to the line segments obtained by the polyline decomposition to obtain a polyline event list, and to sort the events corresponding to the line segments obtained by the polygon decomposition to obtain a polygon event list.
[0049] The first processing unit is used to iteratively process the events in the polyline event chain list using a polygon segmentation algorithm to obtain a first candidate line segment and iteratively process the events in the polygon event chain list to obtain a second candidate line segment. The first candidate line segment is marked with an identifier relative to the polyline on both sides, and the second candidate line segment is marked with an identifier relative to the polygon on both sides.
[0050] The second sorting unit is used to perform a comprehensive sorting of the events corresponding to the first candidate line segment and the events corresponding to the second candidate line segment to obtain a combined event linked list;
[0051] The second processing unit is used to process the events in the combined event list in a loop using a polygon segmentation algorithm to obtain a third candidate line segment. The third candidate line segment is marked with an identifier relative to the polyline and an identifier relative to the polygon on both sides.
[0052] Optionally, the processing module includes:
[0053] The setting unit is used to set the scanning direction when scanning the polyline and the polygon using scan lines;
[0054] The sequence determination unit is used to determine the order in which the scan line passes through the endpoints of each line segment according to the scan direction;
[0055] The line segment sorting unit is used to sort the events corresponding to the line segments according to the order to obtain an event linked list.
[0056] Optionally, the markings on both sides of the line segment include a first marking on both sides of the line segment when the line segment is relative to the polyline and a second marking on both sides of the line segment when the line segment is relative to the polygon;
[0057] When the line segment obtained by splitting the polyline is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. When the line segment obtained by splitting the polyline is relative to the polygon, if the line segment obtained by splitting the polyline is inside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. If the line segment obtained by splitting the polyline is outside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as unfilled identifiers.
[0058] When the line segment obtained by splitting the polygon is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polygon are marked as fill identifiers. When the line segment obtained by splitting the polygon is relative to the polygon, the second identifier of the side of the line segment obtained by splitting the polygon located inside the polygon is marked as fill identifier, and the second identifier of the side of the line segment obtained by splitting the polygon located outside the polygon is marked as no fill identifier.
[0059] Optionally, the determining module includes:
[0060] The first determining unit is configured to determine the candidate line segment as a valid line segment if the identifiers on both sides of the candidate line segment satisfy any one of the following:
[0061] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is unfilled, and the second mark below it is filled.
[0062] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is filled marks, and the second mark below it is unfilled marks;
[0063] When the candidate line segment is relative to the polyline, the first identifiers on both sides are fill identifiers, and when it is relative to the polygon, the second identifiers on both sides of the candidate line segment are fill identifiers.
[0064] Optionally, the processing module includes:
[0065] The first adding unit is used to create a state linked list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the first line segment, the node corresponding to the first line segment is added to the state linked list.
[0066] The intersection splitting unit is used to split the scan start event of the first line segment into the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment, according to the intersection point, if the first line segment and the second line segment have an intersection point, wherein the node corresponding to the second line segment in the state chain is adjacent to the node corresponding to the first line segment;
[0067] An insertion unit is used to insert the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment into the event chain list.
[0068] Optionally, the processing module includes:
[0069] The second adding unit is used to create a state linked list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, the node corresponding to the third line segment is added to the state linked list.
[0070] The first marking unit is used to mark the identifier above the third line segment as a filling identifier and the identifier below the third line segment as a non-filling identifier if there are no other nodes after the node corresponding to the third line segment in the state chain list.
[0071] The second marking unit is used to mark the identifier above the third line segment as the same as the identifier above the line segment corresponding to the adjacent node if there is an adjacent node after the node corresponding to the third line segment in the state chain, and to mark the identifier below the third line segment as the opposite of the identifier above the third line segment, wherein the filling identifier and the non-filling identifier are opposite to each other.
[0072] Optionally, the device further includes:
[0073] The deletion module is used to delete the node corresponding to the third line segment in the state list if the polygon segmentation algorithm is currently processing the scan end event corresponding to the third line segment.
[0074] The update module is used to update the identifiers on both sides of the fourth line segment according to the identifiers on both sides of the fifth line segment if the first node and the second node in the state chain are adjacent after the node corresponding to the third line segment is deleted.
[0075] Wherein, the first node is the node corresponding to the fourth line segment, the second node is the node corresponding to the fifth line segment, the first node is adjacent to the node corresponding to the third line segment and located before the node corresponding to the third line segment is deleted, and the second node is adjacent to the node corresponding to the third line segment and located after the node corresponding to the third line segment is deleted.
[0076] Optionally, the building module includes:
[0077] A creation unit is used to create an open linked list, wherein the open linked list includes at least one open chain;
[0078] The judgment processing unit is used to determine whether the valid line segment can be added to the end of any open chain in the open linked list. If the valid line segment cannot be added to the end of any open chain in the open linked list, a new open chain is created using the valid line segment. If the valid line segment can be added to the end of two open chains in the open linked list, the two open chains are merged into one open chain.
[0079] Thirdly, the present invention also provides a terminal, including a memory, a processor, and a computer program stored in the memory and executable on the processor; when the processor executes the computer program, it implements any of the above-described methods for dividing polygons using polylines.
[0080] Fourthly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in any of the methods described above for dividing polygons using polylines.
[0081] The beneficial effects of the above-described technical solution of the present invention are as follows:
[0082] In this embodiment of the invention, polygons are segmented using polylines. A polygon segmentation algorithm is used to detect the position between line segments and simultaneously mark the state on both sides of the line segments. The intersection, overlap, and state marking of line segments are completed in one scan. Then, the valid line segments can be determined based on the markings on both sides of the candidate line segments. Finally, the segmented polygons are constructed based on the valid line segments. Thus, the method of the present invention greatly improves the computational efficiency. Moreover, the more complex the segmented polygons and the more intersections there are, the more significant the efficiency of the method of the present invention will be. Attached Figure Description
[0083] Figure 1 This is a flowchart illustrating a method for dividing polygons using polylines, as provided in Embodiment 1 of the present invention.
[0084] Figure 2 A schematic diagram of the markings on both sides of a polygonal line segment provided in an embodiment of the present invention;
[0085] Figure 3 A schematic diagram of the markings on both sides of a broken line segment provided in an embodiment of the present invention;
[0086] Figure 4 A schematic diagram showing the markings on both sides of a line segment formed by combining polygons and polylines;
[0087] Figure 5 A schematic diagram of the scan lines provided in an embodiment of the present invention;
[0088] Figure 6 A schematic diagram of events involving a line segment provided in an embodiment of the present invention;
[0089] Figure 7 This is a schematic diagram of the intersection of two line segments provided in an embodiment of the present invention;
[0090] Figure 8 A schematic diagram illustrating the overlap of two line segments provided in an embodiment of the present invention;
[0091] Figure 9 This is an index table for marking both sides of a line segment provided in an embodiment of the present invention;
[0092] Figure 10 This is a schematic diagram of a device for dividing polygons using polylines, provided in Embodiment 2 of the present invention.
[0093] Figure 11 This is a schematic diagram of the structure of a terminal provided in Embodiment 3 of the present invention. Detailed Implementation
[0094] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the described embodiments of the present invention are within the scope of protection of the present invention.
[0095] Please see Figure 1 , Figure 1 This is a flowchart illustrating a method for dividing a polygon using polylines according to Embodiment 1 of the present invention. The polylines divide the polygon into at least two parts. The method includes the following steps:
[0096] Step 11: Based on the inflection points of the polyline and the polygon, divide the polyline and the polygon into multiple line segments respectively;
[0097] In this embodiment of the invention, a polygon is divided by a polyline. The polyline divides the polygon into at least two parts. The polyline has at least one inflection point, and the polygon has multiple inflection points. The inflection point is the intersection of two adjacent line segments of the polyline or polygon when they are not collinear. When splitting the polyline and the polygon, the splitting can be performed from the inflection point position, thereby obtaining multiple line segments.
[0098] Step 12: Sort the events corresponding to the line segments to obtain an event list, and use a polygon segmentation algorithm to iteratively process the events in the event list to obtain candidate line segments and the identifiers on both sides of each candidate line segment. The events corresponding to the line segments include: scan start event and scan end event. The scan start event corresponds to the start point of the line segment, and the scan end event corresponds to the end point of the line segment. The structure of the event includes whether the event corresponds to the start point of the line segment to which it belongs, the point coordinates of the event, the structural information of the line segment to which the event belongs, and another event corresponding to the line segment to which the event belongs. The structural information of the line segment includes the start point, end point, and the identifiers on both sides of the line segment. The identifiers are used to characterize the relative positional relationship between the line segment and the polygon and the polyline.
[0099] In the above steps, the structure of the line segment, the events corresponding to the line segment, and the structure of the events can be defined first. Specifically, the structure of the line segment includes: the starting point of the line segment, the ending point of the line segment, and the markers on both sides of the line segment. The markers on both sides of the line segment are used to represent the relative positional relationship of the line segment with respect to the polygon and the polyline. The events corresponding to the line segment include: scan start event and scan end event. The scan start event corresponds to the starting point of the line segment, and the scan end event corresponds to the ending point of the line segment. The structure of the event includes: whether the event corresponds to the starting point of the line segment to which it belongs (i.e., whether the event is the scan start event of the corresponding line segment), the point coordinates of the event, the structural information of the line segment to which the event belongs, and another event corresponding to the line segment to which the event belongs (if the event is the scan start event, then the other event corresponding to the line segment to which the event belongs is the scan end event, and vice versa).
[0100] After defining the above content, the events corresponding to the line segments can be sorted to obtain the corresponding event list; then, the events in the event list can be processed in a loop using a polygon segmentation algorithm to obtain the candidate line segments and the identifiers on both sides of each candidate line segment.
[0101] In this embodiment of the invention, optionally, the polygon segmentation algorithm is the Bentley-Ottmann algorithm, which can find the intersection points of multiple line segments and has high computational efficiency.
[0102] Step 13: Determine the valid line segments based on the markings on both sides of the candidate line segments;
[0103] Since the markings on both sides of the candidate line segment indicate the relative positional relationship between the candidate line segment and the polygon and the polyline, the final valid line segment can be selected based on the markings on both sides of each candidate line segment.
[0104] Step 14: Construct the segmented polygon based on the effective line segments.
[0105] After obtaining the final valid line segments, these valid line segments can be used to construct the segmented polygons.
[0106] Therefore, the method for segmenting polygons using polylines provided in this embodiment of the invention uses polylines to segment polygons, utilizes a polygon segmentation algorithm to detect the positional relationship between line segments, and simultaneously marks the state on both sides of the line segments. A single scan completes the intersection, overlap, and state marking of line segments. Then, valid line segments can be determined based on the markings on both sides of the candidate line segments, and finally, the segmented polygons are constructed based on the valid line segments. Thus, the method of this invention greatly improves computational efficiency, and the more complex the segmented polygons and the more intersection points they have, the more significant the efficiency of the method will be.
[0107] The following example illustrates the method of dividing polygons using polylines.
[0108] In some embodiments of the present invention, the markings on both sides of the line segment include a first marking on both sides of the line segment when the line segment is relative to the polyline and a second marking on both sides of the line segment when the line segment is relative to the polygon;
[0109] When the line segment obtained by splitting the polyline is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. When the line segment obtained by splitting the polyline is relative to the polygon, if the line segment obtained by splitting the polyline is inside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. If the line segment obtained by splitting the polyline is outside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as unfilled identifiers.
[0110] When the line segment obtained by splitting the polygon is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polygon are marked as fill identifiers. When the line segment obtained by splitting the polygon is relative to the polygon, the second identifier of the side of the line segment obtained by splitting the polygon located inside the polygon is marked as fill identifier, and the second identifier of the side of the line segment obtained by splitting the polygon located outside the polygon is marked as no fill identifier.
[0111] Please refer to Figures 2 to 4 , Figure 2 This is a schematic diagram of the markings on both sides of a polygonal line segment provided in an embodiment of the present invention. Figure 3 This is a schematic diagram of the markings on both sides of a polyline segment provided in an embodiment of the present invention. Figure 4 This is a schematic diagram showing the markings on both sides of a line segment formed by combining a polygon and a polyline. In this embodiment, Figure 2 In the context of considering only the polygon itself, the rules for marking the sides of the polygon's line segments are as follows: the second identifier 202 located inside the polygon is marked as a filled identifier, and the second identifier 202 of the line segments obtained by splitting the polygon located outside the polygon is marked as an unfilled identifier. Figure 3 In the case of polyline itself, the marking rule for both sides of the polyline segment is as follows: the first identifier 201 on both sides of the segment is marked as the fill identifier. Figure 4In the above, when a line segment of a polyline is relative to the polyline itself, the first identifier 201 on both sides of the line segment is marked as a filled identifier. When a line segment of a polyline is relative to a polygon, if the line segment of the polyline is inside the polygon, the second identifier 202 on both sides of the line segment obtained by splitting the polyline is marked as a filled identifier. If the line segment obtained by splitting the polyline is outside the polygon, the second identifier 202 on both sides of the line segment obtained by splitting the polyline is marked as a non-filled identifier. When a line segment obtained by splitting a polygon is relative to the polyline, the first identifier 201 on both sides of the line segment obtained by splitting the polygon is marked as a filled identifier. When a line segment obtained by splitting a polygon is relative to the polygon, the second identifier 202 on the side of the line segment obtained by splitting the polygon that is inside the polygon is marked as a filled identifier, and the second identifier 202 on the side of the line segment obtained by splitting the polygon that is outside the polygon is marked as a non-filled identifier.
[0112] In some embodiments of the present invention, sorting the events corresponding to the line segment to obtain an event linked list includes:
[0113] Set the scanning direction when scanning the polyline and the polygon using scan lines;
[0114] Based on the scanning direction, determine the order in which the scanning line passes through the endpoints of each line segment;
[0115] Based on the given sequence, the events corresponding to the line segments are sorted to obtain an event linked list.
[0116] In other words, the scanning direction when scanning lines and polygons can be set, for example, from left to right or from bottom to top. Then, the order in which the scan line passes through the endpoints of each line segment can be determined based on this scanning direction. That is, it determines which of the two endpoints of a line segment is the start point and which is the end point. Specifically, the endpoint scanned first is the start point, and the endpoint scanned later is the end point. For example, in a Cartesian coordinate system, when scanning a line segment, the X-coordinates of the two endpoints can be compared. The endpoint with the smaller X-coordinate is the start point. If the X-coordinates are the same, the Y-coordinates are compared. The endpoint with the smaller Y-coordinate is the start point, and the endpoint with the larger Y-coordinate is the end point. During the scanning process, it is known that the scan line only causes logical changes when it passes through specific points. These specific points are the inflection points of polygons and lines, and the intersection points of the corresponding line segments.
[0117] Therefore, based on the order in which the scan line passes through the endpoints of each line segment, the events corresponding to each line segment can be sorted, resulting in a corresponding event list. This sorting method can be applied to sorting events corresponding to line segments obtained from polyline decomposition, sorting events corresponding to line segments obtained from polygon decomposition, and combining the sorting of events corresponding to the first candidate line segment and the second candidate line segment.
[0118] Please refer to Figure 5 , Figure 5 This is a schematic diagram of the scan lines provided in an embodiment of the present invention. Figure 5 As shown in the embodiment of the present invention, optionally, the scanning line 501 can be set to vertical, and the scanning direction when scanning the fold line and the polygon is from left to right.
[0119] Please refer to Figure 6 , Figure 6 This is a schematic diagram illustrating events related to a line segment provided in an embodiment of the present invention. For example... Figure 6 As shown, when scan line 501 scans line segments from left to right, the event corresponding to the endpoint of the first scanned line segment is the scan start event, and the event corresponding to the endpoint of the last scanned line segment is the scan end event.
[0120] In some optional embodiments of the present invention, the step of sorting the events corresponding to the line segment to obtain an event linked list, and using a polygon segmentation algorithm to iteratively process the events in the event linked list to obtain the candidate line segments and the identifiers on both sides of each candidate line segment includes:
[0121] The events corresponding to the line segments obtained by the polyline are sorted to obtain a polyline event list, and the events corresponding to the line segments obtained by the polygon are sorted to obtain a polygon event list.
[0122] The first candidate line segment is obtained by iteratively processing the events in the polyline event chain using a polygon segmentation algorithm, and the second candidate line segment is obtained by iteratively processing the events in the polygon event chain. The first candidate line segment is marked with an identifier relative to the polyline on both sides, and the second candidate line segment is marked with an identifier relative to the polygon on both sides.
[0123] A combined event list is obtained by comprehensively sorting the events corresponding to the first candidate line segment and the second candidate line segment;
[0124] The events in the combined event list are processed cyclically using a polygon segmentation algorithm to obtain a third candidate line segment. The third candidate line segment is marked with an identifier relative to the polyline and an identifier relative to the polygon on both sides.
[0125] In this embodiment, firstly, the events corresponding to the line segments obtained from the polyline decomposition are sorted to obtain a polyline event list, and the events corresponding to the line segments obtained from the polygon decomposition are sorted to obtain a polygon event list. Then, the Bentley-Ottmann algorithm is used to iteratively process the events in the polyline event list to obtain a first candidate line segment. At this time, the two sides of the first candidate line segment can obtain a mark relative to the polyline itself. Similarly, the Bentley-Ottmann algorithm is used to iteratively process the events in the polygon event list to obtain a second candidate line segment. At this time, the two sides of the second candidate line segment can obtain a mark relative to the polygon itself. Afterwards, the events corresponding to the first candidate line segment and the events corresponding to the second candidate line segment are comprehensively sorted to obtain a combined event list. That is, the events corresponding to the first candidate line segment and the events corresponding to the second candidate line segment are sorted together. The Bentley-Ottmann algorithm is used again to iteratively process the events in the combined event list to finally obtain a third candidate line segment. At this time, the two sides of the third candidate line segment have both the mark relative to the polyline and the mark relative to the polygon.
[0126] In some embodiments of the present invention, the step of using a polygon segmentation algorithm to iteratively process the events in the event chain to obtain candidate line segments and the identifiers on both sides of each candidate line segment includes:
[0127] Create a state list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the first line segment, add the node corresponding to the first line segment to the state list.
[0128] If the first line segment and the second line segment intersect, the scan start event of the first line segment is split into the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment, according to the intersection point. The node corresponding to the second line segment in the state chain is adjacent to the node corresponding to the first line segment.
[0129] Insert the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment into the event chain list.
[0130] Specifically, when using the Bentley-Ottmann algorithm to iteratively process events in an event list, such as when processing events in a combined event list, a temporary state list can be created. This state list stores the nodes corresponding to line segments that have just started scanning but have not yet reached their end points. If the event currently being processed by the Bentley-Ottmann algorithm is the scan start event corresponding to the first line segment, then the node corresponding to the first line segment is added to the state list. If the first line segment and the second line segment intersect, then based on this intersection point, the scan start event of the first line segment is split into the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment. The resulting scan end events of the leftmost segment of the first line segment, the scan end events of the leftmost segment of the second line segment, the scan start events of the rightmost segment of the first line segment, and the scan start events of the rightmost segment of the second line segment are then inserted into the event list, thereby completing the event splitting processing at the line segment intersection position. In this context, the node corresponding to the second line segment in the state linked list is adjacent to the node corresponding to the first line segment.
[0131] In this embodiment of the invention, the first line segment and the second line segment can be line segments obtained by splitting polylines and polygons, or they can be the aforementioned first candidate line segment, second candidate line segment, etc. Specifically, it can be determined whether the event chain being processed is a polyline event chain, a polygon event chain, or a combined event chain.
[0132] Please refer to Figure 7 , Figure 7 This is a schematic diagram illustrating the intersection of two line segments provided in an embodiment of the present invention. Figure 7 As shown, when the line segments of the polygon and the line segments of the polyline intersect, there is an intersection point 701. When the Bentley-Ottmann algorithm is used to process the events in the event chain in a loop, the above processing is equivalent to splitting the two intersecting line segments into four line segments, that is, splitting the line segment of the polyline intersecting the polygon into two line segments, and splitting the line segment of the polygon intersecting the polyline into two line segments.
[0133] Please refer to Figure 8 , Figure 8 This is a schematic diagram illustrating the overlap of two line segments provided in an embodiment of the present invention. Figure 8 As shown, in some embodiments of the present invention, when two line segments directly overlap each other, there exists Figure 8The six cases shown include, for example, case 1 where the two line segments completely overlap. If one line segment is a polygon and the other is a polyline, then when using the Bentley-Ottmann algorithm to iteratively process events in the event chain, the polygonal line segment and its two side markers are retained, while the polyline line segment is discarded. For cases 2-6, they can be treated as a combination of partially overlapping line segments and intersecting line segments; that is, the corresponding processing steps for case 1 and the processing steps for line segment intersection can be executed.
[0134] In other embodiments of the present invention, the step of using a polygon segmentation algorithm to iteratively process the events in the event chain to obtain candidate line segments and the identifiers on both sides of each candidate line segment includes:
[0135] Create a state list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, add the node corresponding to the third line segment to the state list.
[0136] If there are no other nodes after the node corresponding to the third line segment in the state chain, then the identifier above the third line segment is marked as a fill identifier, and the identifier below the third line segment is marked as a non-fill identifier;
[0137] If there is an adjacent node after the node corresponding to the third line segment in the state chain, then the identifier above the third line segment is marked as the same as the identifier above the line segment corresponding to the adjacent node, and the identifier below the third line segment is marked as the opposite of the identifier above the third line segment, wherein the filling identifier and the non-filling identifier are opposite to each other.
[0138] Specifically, when using the Bentley-Ottmann algorithm to iteratively process events in an event list, such as when processing events in a combined event list, a temporary state list can be created. This state list stores nodes corresponding to line segments that have just started scanning but have not yet reached their end point. If the Bentley-Ottmann algorithm is currently processing the scan start event corresponding to the third line segment, then the node corresponding to the third line segment is added to the state list. If there are no other nodes after the node corresponding to the third line segment in the state list at this time, then the marker above the third line segment is marked as a fill marker, and the marker below the third line segment is marked as a no-fill marker. If there are adjacent nodes after the node corresponding to the third line segment in the state list at this time, then the marker above the third line segment is marked as the same as the marker above the line segment corresponding to the adjacent node, and the marker below the third line segment is marked as the opposite of the marker above the third line segment. The fill marker and the no-fill marker are opposites of each other. Of course, the fill marker and the no-fill marker are only used to represent the positional relationship of the line segment relative to the polyline or polygon; therefore, other types of markers can also be used to represent this positional relationship.
[0139] In this embodiment of the invention, the third line segment can be a line segment obtained by splitting a polyline and a polygon, or it can be the aforementioned first candidate line segment, second candidate line segment, third candidate line segment, etc. Specifically, it can be determined according to whether the event chain currently being processed is a polyline event chain, a polygon event chain, or a combined event chain.
[0140] In other embodiments of the present invention, the step of creating a state linked list, if the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, after adding the node corresponding to the third line segment to the state linked list, further includes:
[0141] If the polygon segmentation algorithm is currently processing the scan end event corresponding to the third line segment, delete the node corresponding to the third line segment from the state list;
[0142] If the first node and the second node in the state chain are adjacent after the node corresponding to the third line segment is deleted, then the identifiers on both sides of the fourth line segment are updated according to the identifiers on both sides of the fifth line segment.
[0143] Wherein, the first node is the node corresponding to the fourth line segment, the second node is the node corresponding to the fifth line segment, the first node is adjacent to the node corresponding to the third line segment and located before the node corresponding to the third line segment is deleted, and the second node is adjacent to the node corresponding to the third line segment and located after the node corresponding to the third line segment is deleted.
[0144] In other words, when using the Bentley-Ottmann algorithm to iteratively process events in the event chain, after adding the node corresponding to the third line segment to the state chain, if the Bentley-Ottmann algorithm starts processing the end-of-scan event of the third line segment, it means that the scan of the third line segment is finished. Then, the node corresponding to the third line segment is deleted from the state chain. After deletion, if the first node and the second node in the state chain become adjacent, that is, if a new adjacent situation appears in the state chain, then the identifiers on both sides of the fourth line segment are updated according to the identifiers on both sides of the fifth line segment. Here, the first node and the second node are the preceding and following nodes of the node corresponding to the third line segment, the first node is the node corresponding to the fourth line segment, and the second node is the node corresponding to the fifth line segment.
[0145] In this embodiment of the invention, the third, fourth, and fifth line segments can be line segments obtained by splitting polylines and polygons, or they can be the aforementioned first, second, and third candidate line segments, etc. Specifically, it can be determined whether the event chain being processed is a polyline event chain, a polygon event chain, or a combined event chain.
[0146] In other embodiments of the present invention, determining the valid line segment based on the markings on both sides of the candidate line segment includes:
[0147] If the markings on both sides of the candidate line segment satisfy any one of the following conditions, then the candidate line segment is determined as a valid line segment:
[0148] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is unfilled, and the second mark below it is filled.
[0149] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is filled marks, and the second mark below it is unfilled marks;
[0150] When the candidate line segment is relative to the polyline, the first identifiers on both sides are fill identifiers, and when it is relative to the polygon, the second identifiers on both sides of the candidate line segment are fill identifiers.
[0151] In the above steps, since the markings on both sides of the candidate line segments have been determined, and these markings represent the position and other characteristics of the corresponding candidate line segments, the final valid line segments can be selected based on the markings on both sides of the candidate line segments. The candidate line segments referred to here are the aforementioned third candidate line segments.
[0152] Please refer to Figure 9 , Figure 9This is an index table for marking both sides of a line segment, provided in an embodiment of the present invention. For example... Figure 9 As shown, there are 16 possible filling states for the first and second identifiers on both sides of the line segment. Among them, the states corresponding to indices 7, 11, and 15 satisfy the above requirements and are thus retained as valid line segments. Optionally, an encoding table can be defined to compile the 16 states into an array containing 16 elements. Define 0 to indicate that the line segment is not retained, 1 to indicate that it is retained and filled at the top, 2 to indicate that it is retained and filled at the bottom, and 3 to indicate that it is retained and filled on both sides. The array would then be [0,0,0,0,0,0,0,2,0,0,0,1,0,0,0,3]. The identifiers can then be interpreted as bits to determine the corresponding index in the array. For example, "No, Yes, Yes, Yes" can be represented by "0111", corresponding to index 7. The number in the array corresponding to this index is 2, meaning it is retained. Therefore, the final valid line segment can be selected based on the identifiers on both sides of the line segment.
[0153] In other embodiments of the present invention, constructing the segmented polygon based on the effective line segments includes:
[0154] Create an open linked list, wherein the open linked list includes at least one open chain;
[0155] Determine whether the valid line segment can be added to the end of any open chain in the open linked list. If the valid line segment cannot be added to the end of any open chain in the open linked list, then create a new open chain using the valid line segment. If the valid line segment can be added to the end of two open chains in the open linked list, then merge the two open chains into one open chain.
[0156] In this embodiment, after selecting valid line segments, an open linked list can be created, which includes at least one open chain. Since each valid line segment contains a start point and an end point, it can be checked one by one whether each valid line segment can be added to the end of any open chain in the open linked list. If it cannot be added to the end of an open chain, a new open chain is created using the valid line segment. If a valid line segment can be added to the end of two open chains in the open linked list, the two open chains are merged into one open chain.
[0157] In some embodiments of the present invention, optionally, if the starting point of a valid line segment to be added to the open linked list is the intersection of a polygon and a polyline, and is a line segment obtained by splitting a polygon, then a new open linked list needs to be created based on the valid line segment.
[0158] In some other embodiments of the present invention, optionally, the line segments obtained by the polyline split can be added to the open linked list twice, and if the valid line segments obtained by the polyline split can be added to two open chains, then it is not necessary to merge the two open chains.
[0159] In some embodiments of the present invention, optionally, if a valid line segment is added to a single open chain, it is necessary to check whether adding the valid line segment will cause the open chain to close. If it will cause the open chain to close, then the open chain is closed and the valid line segment is added to the final completed polygon list.
[0160] In summary, in this embodiment of the invention, by employing polyline segmentation of polygons and utilizing a polygon segmentation algorithm to detect the positional relationship between line segments, while simultaneously marking the state on both sides of the line segments, the intersection, overlap, and state marking of line segments are completed in a single scan. Subsequently, valid line segments can be determined based on the markings on both sides of the candidate line segments, and finally, the segmented polygons are constructed based on the valid line segments. Thus, the method of the present invention greatly improves computational efficiency, and the more complex the segmented polygons and the more intersections they have, the more significant the efficiency of the method of the present invention will be.
[0161] Please see Figure 10 , Figure 10 This is a schematic diagram of a device for dividing polygons using polylines, provided in Embodiment 2 of the present invention. Figure 10 As shown, Embodiment 2 of the present invention also provides a device for dividing a polygon using a polyline, wherein the polyline divides the polygon into at least two parts, and the device 1000 includes:
[0162] The splitting module 1001 is used to split the polyline and the polygon into multiple line segments according to the inflection points of the polyline and the polygon, respectively.
[0163] The processing module 1002 is used to sort the events corresponding to the line segment to obtain an event chain list, and to use a polygon segmentation algorithm to iteratively process the events in the event chain list to obtain candidate line segments and the identifiers on both sides of each candidate line segment. The events corresponding to the line segment include: a scan start event and a scan end event. The scan start event corresponds to the start point of the line segment, and the scan end event corresponds to the end point of the line segment. The structure of the event includes whether the event corresponds to the start point of the line segment to which it belongs, the point coordinates of the event, the structural information of the line segment to which the event belongs, and another event corresponding to the line segment to which the event belongs. The structural information of the line segment includes the start point, the end point, and the identifiers on both sides of the line segment. The identifiers are used to characterize the relative positional relationship between the line segment and the polygon and the polyline.
[0164] The determining module 1003 is used to determine the valid line segment based on the markings on both sides of the candidate line segment;
[0165] The construction module 1004 is used to construct the segmented polygon based on the effective line segments.
[0166] Optionally, the processing module includes:
[0167] The first sorting unit is used to sort the events corresponding to the line segments obtained by the polyline decomposition to obtain a polyline event list, and to sort the events corresponding to the line segments obtained by the polygon decomposition to obtain a polygon event list.
[0168] The first processing unit is used to iteratively process the events in the polyline event chain list using a polygon segmentation algorithm to obtain a first candidate line segment and iteratively process the events in the polygon event chain list to obtain a second candidate line segment. The first candidate line segment is marked with an identifier relative to the polyline on both sides, and the second candidate line segment is marked with an identifier relative to the polygon on both sides.
[0169] The second sorting unit is used to perform a comprehensive sorting of the events corresponding to the first candidate line segment and the events corresponding to the second candidate line segment to obtain a combined event linked list;
[0170] The second processing unit is used to process the events in the combined event list in a loop using a polygon segmentation algorithm to obtain a third candidate line segment. The third candidate line segment is marked with an identifier relative to the polyline and an identifier relative to the polygon on both sides.
[0171] Optionally, the processing module includes:
[0172] The setting unit is used to set the scanning direction when scanning the polyline and the polygon using scan lines;
[0173] The sequence determination unit is used to determine the order in which the scan line passes through the endpoints of each line segment according to the scan direction;
[0174] The line segment sorting unit is used to sort the events corresponding to the line segments according to the order to obtain an event linked list.
[0175] Optionally, the markings on both sides of the line segment include a first marking on both sides of the line segment when the line segment is relative to the polyline and a second marking on both sides of the line segment when the line segment is relative to the polygon;
[0176] When the line segment obtained by splitting the polyline is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. When the line segment obtained by splitting the polyline is relative to the polygon, if the line segment obtained by splitting the polyline is inside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. If the line segment obtained by splitting the polyline is outside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as unfilled identifiers.
[0177] When the line segment obtained by splitting the polygon is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polygon are marked as fill identifiers. When the line segment obtained by splitting the polygon is relative to the polygon, the second identifier of the side of the line segment obtained by splitting the polygon located inside the polygon is marked as fill identifier, and the second identifier of the side of the line segment obtained by splitting the polygon located outside the polygon is marked as no fill identifier.
[0178] Optionally, the determining module includes:
[0179] The first determining unit is configured to determine the candidate line segment as a valid line segment if the identifiers on both sides of the candidate line segment satisfy any one of the following:
[0180] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is unfilled, and the second mark below it is filled.
[0181] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is filled marks, and the second mark below it is unfilled marks;
[0182] When the candidate line segment is relative to the polyline, the first identifiers on both sides are fill identifiers, and when it is relative to the polygon, the second identifiers on both sides of the candidate line segment are fill identifiers.
[0183] Optionally, the processing module includes:
[0184] The first adding unit is used to create a state linked list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the first line segment, the node corresponding to the first line segment is added to the state linked list.
[0185] The intersection splitting unit is used to split the scan start event of the first line segment into the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment, according to the intersection point, if the first line segment and the second line segment have an intersection point, wherein the node corresponding to the second line segment in the state chain is adjacent to the node corresponding to the first line segment;
[0186] An insertion unit is used to insert the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment into the event chain list.
[0187] Optionally, the processing module includes:
[0188] The second adding unit is used to create a state linked list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, the node corresponding to the third line segment is added to the state linked list.
[0189] The first marking unit is used to mark the identifier above the third line segment as a filling identifier and the identifier below the third line segment as a non-filling identifier if there are no other nodes after the node corresponding to the third line segment in the state chain list.
[0190] The second marking unit is used to mark the identifier above the third line segment as the same as the identifier above the line segment corresponding to the adjacent node if there is an adjacent node after the node corresponding to the third line segment in the state chain, and to mark the identifier below the third line segment as the opposite of the identifier above the third line segment, wherein the filling identifier and the non-filling identifier are opposite to each other.
[0191] Optionally, the device further includes:
[0192] The deletion module is used to delete the node corresponding to the third line segment in the state list if the polygon segmentation algorithm is currently processing the scan end event corresponding to the third line segment.
[0193] The update module is used to update the identifiers on both sides of the fourth line segment according to the identifiers on both sides of the fifth line segment if the first node and the second node in the state chain are adjacent after the node corresponding to the third line segment is deleted.
[0194] Wherein, the first node is the node corresponding to the fourth line segment, the second node is the node corresponding to the fifth line segment, the first node is adjacent to the node corresponding to the third line segment and located before the node corresponding to the third line segment is deleted, and the second node is adjacent to the node corresponding to the third line segment and located after the node corresponding to the third line segment is deleted.
[0195] Optionally, the building module includes:
[0196] A creation unit is used to create an open linked list, wherein the open linked list includes at least one open chain;
[0197] The judgment processing unit is used to determine whether the valid line segment can be added to the end of any open chain in the open linked list. If the valid line segment cannot be added to the end of any open chain in the open linked list, a new open chain is created using the valid line segment. If the valid line segment can be added to the end of two open chains in the open linked list, the two open chains are merged into one open chain.
[0198] The embodiments of the present invention are product embodiments corresponding to the method embodiment one described above, and therefore will not be repeated here. For details, please refer to the embodiment one described above.
[0199] Please see Figure 11 , Figure 11 This is a schematic diagram of the structure of a terminal provided in Embodiment 3 of the present invention. The terminal 1100 includes a processor 1101, a memory 1102, and a computer program stored in the memory 1102 and executable on the processor 1101. When the processor 1101 executes the computer program, it performs the following steps:
[0200] Based on the inflection points of the polyline and the polygon, the polyline and the polygon are respectively divided into multiple line segments;
[0201] The events corresponding to the line segments are sorted to obtain an event list, and the events in the event list are processed iteratively using a polygon segmentation algorithm to obtain candidate line segments and the identifiers on both sides of each candidate line segment. The events corresponding to the line segments include: scan start event and scan end event. The scan start event corresponds to the start point of the line segment, and the scan end event corresponds to the end point of the line segment. The structure of the event includes whether the event corresponds to the start point of the line segment to which it belongs, the point coordinates of the event, the structural information of the line segment to which the event belongs, and another event corresponding to the line segment to which the event belongs. The structural information of the line segment includes the start point, end point, and the identifiers on both sides of the line segment. The identifiers are used to characterize the relative positional relationship between the line segment and the polygon and the polyline.
[0202] The valid line segments are determined based on the markings on both sides of the candidate line segments;
[0203] Based on the valid line segments, construct the segmented polygons.
[0204] In this embodiment of the invention, optionally, when the processor 1101 executes the computer program, it may also perform the following steps:
[0205] The process of sorting the events corresponding to the line segments to obtain an event linked list, and then using a polygon segmentation algorithm to iteratively process the events in the event linked list to obtain candidate line segments and the identifiers on both sides of each candidate line segment includes:
[0206] The events corresponding to the line segments obtained by the polyline are sorted to obtain a polyline event list, and the events corresponding to the line segments obtained by the polygon are sorted to obtain a polygon event list.
[0207] The first candidate line segment is obtained by iteratively processing the events in the polyline event chain using a polygon segmentation algorithm, and the second candidate line segment is obtained by iteratively processing the events in the polygon event chain. The first candidate line segment is marked with an identifier relative to the polyline on both sides, and the second candidate line segment is marked with an identifier relative to the polygon on both sides.
[0208] A combined event list is obtained by comprehensively sorting the events corresponding to the first candidate line segment and the second candidate line segment;
[0209] The events in the combined event list are processed cyclically using a polygon segmentation algorithm to obtain a third candidate line segment. The third candidate line segment is marked with an identifier relative to the polyline and an identifier relative to the polygon on both sides.
[0210] In this embodiment of the invention, optionally, when the processor 1101 executes the computer program, it may also perform the following steps:
[0211] The step of sorting the events corresponding to the line segment to obtain the event linked list includes:
[0212] Set the scanning direction when scanning the polyline and the polygon using scan lines;
[0213] Based on the scanning direction, determine the order in which the scanning line passes through the endpoints of each line segment;
[0214] Based on the given sequence, the events corresponding to the line segments are sorted to obtain an event linked list.
[0215] Optionally, the markings on both sides of the line segment include a first marking on both sides of the line segment when the line segment is relative to the polyline and a second marking on both sides of the line segment when the line segment is relative to the polygon;
[0216] When the line segment obtained by splitting the polyline is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. When the line segment obtained by splitting the polyline is relative to the polygon, if the line segment obtained by splitting the polyline is inside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. If the line segment obtained by splitting the polyline is outside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as unfilled identifiers.
[0217] When the line segment obtained by splitting the polygon is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polygon are marked as fill identifiers. When the line segment obtained by splitting the polygon is relative to the polygon, the second identifier of the side of the line segment obtained by splitting the polygon located inside the polygon is marked as fill identifier, and the second identifier of the side of the line segment obtained by splitting the polygon located outside the polygon is marked as no fill identifier.
[0218] In this embodiment of the invention, optionally, when the processor 1101 executes the computer program, it may also perform the following steps:
[0219] The step of determining the valid line segment based on the markings on both sides of the candidate line segment includes:
[0220] If the markings on both sides of the candidate line segment satisfy any one of the following conditions, then the candidate line segment is determined as a valid line segment:
[0221] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is unfilled, and the second mark below it is filled.
[0222] When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is filled marks, and the second mark below it is unfilled marks;
[0223] When the candidate line segment is relative to the polyline, the first identifiers on both sides are fill identifiers, and when it is relative to the polygon, the second identifiers on both sides of the candidate line segment are fill identifiers.
[0224] Optionally, the step of using a polygon segmentation algorithm to iteratively process the events in the event chain to obtain the candidate line segments and the identifiers on both sides of each candidate line segment includes:
[0225] Create a state list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the first line segment, add the node corresponding to the first line segment to the state list.
[0226] If the first line segment and the second line segment intersect, the scan start event of the first line segment is split into the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment, according to the intersection point. The node corresponding to the second line segment in the state chain is adjacent to the node corresponding to the first line segment.
[0227] Insert the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment into the event chain list.
[0228] In this embodiment of the invention, optionally, when the processor 1101 executes the computer program, it may also perform the following steps:
[0229] The process of iteratively processing the events in the event chain using a polygon segmentation algorithm to obtain candidate line segments and the identifiers on both sides of each candidate line segment includes:
[0230] Create a state list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, add the node corresponding to the third line segment to the state list.
[0231] If there are no other nodes after the node corresponding to the third line segment in the state chain, then the identifier above the third line segment is marked as a fill identifier, and the identifier below the third line segment is marked as a non-fill identifier;
[0232] If there is an adjacent node after the node corresponding to the third line segment in the state chain, then the identifier above the third line segment is marked as the same as the identifier above the line segment corresponding to the adjacent node, and the identifier below the third line segment is marked as the opposite of the identifier above the third line segment, wherein the filling identifier and the non-filling identifier are opposite to each other.
[0233] In this embodiment of the invention, optionally, when the processor 1101 executes the computer program, it may also perform the following steps:
[0234] The process of creating a state linked list, if the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, after adding the node corresponding to the third line segment to the state linked list, further includes:
[0235] If the polygon segmentation algorithm is currently processing the scan end event corresponding to the third line segment, delete the node corresponding to the third line segment from the state list;
[0236] If the first node and the second node in the state chain are adjacent after the node corresponding to the third line segment is deleted, then the identifiers on both sides of the fourth line segment are updated according to the identifiers on both sides of the fifth line segment.
[0237] Wherein, the first node is the node corresponding to the fourth line segment, the second node is the node corresponding to the fifth line segment, the first node is adjacent to the node corresponding to the third line segment and located before the node corresponding to the third line segment is deleted, and the second node is adjacent to the node corresponding to the third line segment and located after the node corresponding to the third line segment is deleted.
[0238] In this embodiment of the invention, optionally, when the processor 1101 executes the computer program, it may also perform the following steps:
[0239] The step of constructing the segmented polygon based on the effective line segments includes:
[0240] Create an open linked list, wherein the open linked list includes at least one open chain;
[0241] Determine whether the valid line segment can be added to the end of any open chain in the open linked list. If the valid line segment cannot be added to the end of any open chain in the open linked list, then create a new open chain using the valid line segment. If the valid line segment can be added to the end of two open chains in the open linked list, then merge the two open chains into one open chain.
[0242] The specific working process of this invention embodiment is the same as that in the method embodiment one above, so it will not be repeated here. For details, please refer to the description of the method steps in the method embodiment one above.
[0243] Embodiment 4 of the present invention provides a computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the steps of any of the methods for dividing polygons using polylines in Embodiment 1 above. For details, please refer to the descriptions of the method steps in the corresponding embodiments above.
[0244] The aforementioned computer-readable storage media include both permanent and non-permanent, removable and non-removable media, which can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.
[0245] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for dividing a polygon using a polyline, wherein the polyline divides the polygon into at least two parts, characterized in that, The method includes: Based on the inflection points of the polyline and the polygon, the polyline and the polygon are respectively divided into multiple line segments; The events corresponding to the line segments are sorted to obtain an event list, and the events in the event list are processed iteratively using a polygon segmentation algorithm to obtain candidate line segments and the identifiers on both sides of each candidate line segment. The events corresponding to the line segments include: scan start event and scan end event. The scan start event corresponds to the start point of the line segment, and the scan end event corresponds to the end point of the line segment. The structure of the event includes whether the event corresponds to the start point of the line segment to which it belongs, the point coordinates of the event, the structural information of the line segment to which the event belongs, and another event corresponding to the line segment to which the event belongs. The structural information of the line segment includes the start point, end point, and the identifiers on both sides of the line segment. The identifiers are used to characterize the relative positional relationship between the line segment and the polygon and the polyline. The valid line segments are determined based on the markings on both sides of the candidate line segments; Based on the effective line segments, construct the segmented polygons; The process of sorting the events corresponding to the line segments to obtain an event linked list, and then using a polygon segmentation algorithm to iteratively process the events in the event linked list to obtain candidate line segments and the identifiers on both sides of each candidate line segment includes: The events corresponding to the line segments obtained by the polyline are sorted to obtain a polyline event list, and the events corresponding to the line segments obtained by the polygon are sorted to obtain a polygon event list. The first candidate line segment is obtained by iteratively processing the events in the polyline event chain using a polygon segmentation algorithm, and the second candidate line segment is obtained by iteratively processing the events in the polygon event chain. The first candidate line segment is marked with an identifier relative to the polyline on both sides, and the second candidate line segment is marked with an identifier relative to the polygon on both sides. A combined event list is obtained by comprehensively sorting the events corresponding to the first candidate line segment and the second candidate line segment; The events in the combined event list are processed cyclically using a polygon segmentation algorithm to obtain a third candidate line segment. The third candidate line segment is marked with an identifier relative to the polyline and an identifier relative to the polygon on both sides. The step of sorting the events corresponding to the line segment to obtain the event linked list includes: Set the scanning direction when scanning the polyline and the polygon using scan lines; Based on the scanning direction, determine the order in which the scanning line passes through the endpoints of each line segment; Based on the given sequence, the events corresponding to the line segments are sorted to obtain an event linked list.
2. The method according to claim 1, characterized in that, The markings on both sides of the line segment include a first marking on both sides of the line segment when the line segment is relative to the polyline and a second marking on both sides of the line segment when the line segment is relative to the polygon. When the line segment obtained by splitting the polyline is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. When the line segment obtained by splitting the polyline is relative to the polygon, if the line segment obtained by splitting the polyline is inside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as filled identifiers. If the line segment obtained by splitting the polyline is outside the polygon, the second identifiers on both sides of the line segment obtained by splitting the polyline are marked as unfilled identifiers. When the line segment obtained by splitting the polygon is relative to the polyline, the first identifiers on both sides of the line segment obtained by splitting the polygon are marked as fill identifiers. When the line segment obtained by splitting the polygon is relative to the polygon, the second identifier of the side of the line segment obtained by splitting the polygon located inside the polygon is marked as fill identifier, and the second identifier of the side of the line segment obtained by splitting the polygon located outside the polygon is marked as no fill identifier.
3. The method according to claim 2, characterized in that, The step of determining the valid line segment based on the markings on both sides of the candidate line segment includes: If the markings on both sides of the candidate line segment satisfy any one of the following conditions, then the candidate line segment is determined as a valid line segment: When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is unfilled, and the second mark below it is filled. When the line segment to be selected is relative to the polyline, the first marks on both sides are filled marks, and when it is relative to the polygon, the second mark above the line segment to be selected is filled marks, and the second mark below it is unfilled marks; When the candidate line segment is relative to the polyline, the first identifiers on both sides are fill identifiers, and when it is relative to the polygon, the second identifiers on both sides of the candidate line segment are fill identifiers.
4. The method according to claim 1, characterized in that, The process of iteratively processing the events in the event chain using a polygon segmentation algorithm to obtain candidate line segments and the identifiers on both sides of each candidate line segment includes: Create a state list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the first line segment, add the node corresponding to the first line segment to the state list. If the first line segment and the second line segment intersect, the scan start event of the first line segment is split into the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment, according to the intersection point. The node corresponding to the second line segment in the state chain is adjacent to the node corresponding to the first line segment. Insert the scan end event of the leftmost segment of the first line segment, the scan end event of the leftmost segment of the second line segment, the scan start event of the rightmost segment of the first line segment, and the scan start event of the rightmost segment of the second line segment into the event chain list.
5. The method according to claim 1, characterized in that, The process of iteratively processing the events in the event chain using a polygon segmentation algorithm to obtain candidate line segments and the identifiers on both sides of each candidate line segment includes: Create a state list. If the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, add the node corresponding to the third line segment to the state list. If there are no other nodes after the node corresponding to the third line segment in the state chain, then the identifier above the third line segment is marked as a fill identifier, and the identifier below the third line segment is marked as a non-fill identifier; If there is an adjacent node after the node corresponding to the third line segment in the state chain, then the identifier above the third line segment is marked as the same as the identifier above the line segment corresponding to the adjacent node, and the identifier below the third line segment is marked as the opposite of the identifier above the third line segment, wherein the filling identifier and the non-filling identifier are opposite to each other.
6. The method according to claim 5, characterized in that, The process of creating a state linked list, if the polygon segmentation algorithm is currently processing the scan start event corresponding to the third line segment, after adding the node corresponding to the third line segment to the state linked list, further includes: If the polygon segmentation algorithm is currently processing the scan end event corresponding to the third line segment, delete the node corresponding to the third line segment from the state list; If the first node and the second node in the state chain are adjacent after the node corresponding to the third line segment is deleted, then the identifiers on both sides of the fourth line segment are updated according to the identifiers on both sides of the fifth line segment. Wherein, the first node is the node corresponding to the fourth line segment, the second node is the node corresponding to the fifth line segment, the first node is adjacent to the node corresponding to the third line segment and located before the node corresponding to the third line segment is deleted, and the second node is adjacent to the node corresponding to the third line segment and located after the node corresponding to the third line segment is deleted.
7. The method according to claim 1, characterized in that, The step of constructing the segmented polygon based on the effective line segments includes: Create an open linked list, wherein the open linked list includes at least one open chain; Determine whether the valid line segment can be added to the end of any open chain in the open linked list. If the valid line segment cannot be added to the end of any open chain in the open linked list, then create a new open chain using the valid line segment. If the valid line segment can be added to the end of two open chains in the open linked list, then merge the two open chains into one open chain.
8. An apparatus for dividing a polygon using a polyline, wherein the polyline divides the polygon into at least two parts, characterized in that, The device includes: The splitting module is used to split the polyline and the polygon into multiple line segments based on the inflection points of the polyline and the polygon, respectively. The processing module is used to sort the events corresponding to the line segments to obtain an event chain list, and to use a polygon segmentation algorithm to iteratively process the events in the event chain list to obtain candidate line segments and the identifiers on both sides of each candidate line segment. The events corresponding to the line segments include: a scan start event and a scan end event. The scan start event corresponds to the start point of the line segment, and the scan end event corresponds to the end point of the line segment. The structure of the event includes whether the event corresponds to the start point of the line segment to which it belongs, the point coordinates of the event, the structural information of the line segment to which the event belongs, and another event corresponding to the line segment to which the event belongs. The structural information of the line segment includes the start point, the end point, and the identifiers on both sides of the line segment. The identifiers are used to characterize the relative positional relationship between the line segment and the polygon and the polyline. The determination module is used to determine the valid line segments based on the markings on both sides of the candidate line segments; A construction module is used to construct the segmented polygons based on the valid line segments; The process of sorting the events corresponding to the line segments to obtain an event linked list, and then using a polygon segmentation algorithm to iteratively process the events in the event linked list to obtain candidate line segments and the identifiers on both sides of each candidate line segment includes: The events corresponding to the line segments obtained by the polyline are sorted to obtain a polyline event list, and the events corresponding to the line segments obtained by the polygon are sorted to obtain a polygon event list. The first candidate line segment is obtained by iteratively processing the events in the polyline event chain using a polygon segmentation algorithm, and the second candidate line segment is obtained by iteratively processing the events in the polygon event chain. The first candidate line segment is marked with an identifier relative to the polyline on both sides, and the second candidate line segment is marked with an identifier relative to the polygon on both sides. A combined event list is obtained by comprehensively sorting the events corresponding to the first candidate line segment and the second candidate line segment; The events in the combined event list are processed cyclically using a polygon segmentation algorithm to obtain a third candidate line segment. The third candidate line segment is marked with an identifier relative to the polyline and an identifier relative to the polygon on both sides. The step of sorting the events corresponding to the line segment to obtain the event linked list includes: Set the scanning direction when scanning the polyline and the polygon using scan lines; Based on the scanning direction, determine the order in which the scanning line passes through the endpoints of each line segment; Based on the given sequence, the events corresponding to the line segments are sorted to obtain an event linked list.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the method for dividing polygons using polylines as described in any one of claims 1 to 7.