A Visualized Adaptive Text Removal Method Based on Spatial Indexing and Data Weighting
By adopting an adaptive elimination method based on spatial indexing and data weights, the problems of display priority, judgment accuracy and running efficiency of massive text tags in visualization technology are solved. It realizes the priority display of high-value tags and efficient collision detection, and is suitable for dynamic interactive scenarios.
Patent Information
- Application Number
- CN202611362759.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-03
- Publication Date
- 2026-11-17
AI Technical Summary
Existing visualization technologies struggle to balance display priority, judgment accuracy, and operational efficiency in scenarios with massive amounts of text tags, failing to meet the needs of dynamic interactive scenarios. In particular, high-value tags are easily obscured, collision detection efficiency is low, and the index structure is simplistic and has poor adaptability.
An adaptive culling method based on spatial index and data weight is adopted. A global processing queue is constructed by sorting by comprehensive weight. Wide phase filtering and true overlap determination are performed by combining axis-aligned bounding boxes and spatial index. Quadtree or R-tree index is established for fast retrieval. The inter-frame reuse and local update mechanism are optimized.
It effectively ensures the priority display of highly interactive and valuable tags, reduces collision detection computation overhead, improves operating performance, adapts to rotating tag scenarios, and solves the problem of tag overlap and occlusion in dynamic visualization scenarios.
Smart Images

Figure CN123115264A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of computer data visualization, specifically to a method for adaptive text removal in visualization based on spatial indexing and data weighting. Background Technology
[0002] With the rapid development of big data visualization, geographic information systems, and interactive charting technologies, the scale of text labels to be displayed in visualization scenarios continues to grow. As the direct carrier of data information, the display effect of text labels directly determines the readability and information transmission efficiency of the visualization content. How to achieve reasonable arrangement and adaptive removal of massive amounts of text labels within a limited canvas space has become one of the core technical problems in the field of visualization.
[0003] Current mainstream text tag removal schemes have the following shortcomings: First, the priority design for tag removal is unreasonable. Existing schemes mostly perform collision detection and removal according to the default or random order of data, without considering the interactive state of the tags and the stability of the data for weighting. This results in tags in interactive states such as selected or hovered, as well as core data tags that were added to the database earlier and have high stability, being easily obscured by ordinary tags. This fails to guarantee the priority display of high-value tags and makes it difficult to meet the needs of interactive visualization scenarios. Second, the running efficiency of collision detection is low. Traditional schemes often use brute-force pairwise comparisons to determine tag overlap, with a time complexity of O(N). 2 This means that as the number of tags increases, the number of pairwise tag comparisons increases quadratically. When the number of tags reaches tens of thousands or more, the computational overhead increases exponentially, failing to meet the frame rate requirements of real-time interactive scenarios. Some solutions that introduce spatial indexes suffer from a single index structure and poor adaptability. They cannot dynamically select the optimal index structure based on tag distribution characteristics, and in dynamic scenarios such as camera panning and scaling, and tag state changes, frequent full recalculations are required, further exacerbating performance degradation and easily causing interactive stuttering. Thirdly, it is difficult to balance judgment accuracy and performance. Some solutions simplify the collision judgment logic to reduce computational load, performing overlap verification only by aligning bounding boxes with axes. This results in a large error in judging rotated tags, easily leading to misjudgments where bounding boxes intersect but the actual tags do not overlap. If precise geometric judgment is used for all tags, the computational complexity will increase significantly, making it unsuitable for large-scale tag scenarios.
[0004] In summary, existing visual text tag removal technologies struggle to simultaneously balance display priority, judgment accuracy, and operational efficiency, making them unsuitable for dynamic interactive scenarios with a massive number of tags. Summary of the Invention
[0005] This invention provides a visual text adaptive removal method based on spatial indexing and data weighting to solve the aforementioned technical problems, specifically adopting the following technical solution: A visual text adaptive removal method based on spatial indexing and data weighting includes the following steps: The overall weight is calculated based on the interaction status score and stable entry order score of the text labels to be displayed. The text labels to be displayed are sorted in descending order of overall weight, and when the overall weights are the same, they are sorted in sequence according to the preset decision key to obtain the global processing queue. The axis-aligned bounding box of the text label to be displayed in screen space is calculated based on the current camera transformation matrix, and labels completely located outside the canvas are removed according to the preset canvas boundary to obtain the set to be detected. Create a spatial index instance to store the axis-aligned bounding boxes of labels that have been determined to be displayed, and provide a range retrieval interface based on the intersection of axis-aligned bounding boxes; Based on the order of the global processing queue, the current label in the set to be detected is traversed sequentially, and the spatial index instance is retrieved with the axis of the current label aligned with the bounding box to obtain the candidate label set; If the current label has a real overlap with any candidate label in the candidate label set, then mark the current label as hidden; otherwise, mark it as displayed and insert its axis-aligned bounding box into the spatial index instance. After the traversal is complete, the labels marked for display are submitted to the drawing pipeline for rendering.
[0006] Furthermore, the text labels to be displayed are sorted in descending order of their overall weight, and if the overall weights are the same, they are sorted sequentially according to a preset decision key to obtain a global processing queue, including: Use the overall weight as the primary sorting key to sort the text labels to be displayed in descending order; When the overall weights are the same, the relative order is determined sequentially according to the deciding key: The interaction state priority is used as the first deciding key, and the interaction state is determined according to the currently active type of the tag in a preset hierarchical order. Using the stable entry sequence number as the second deciding key, the items are sorted in ascending order according to the value of the stable entry sequence number; Using stable identifiers as the third deciding key, the stable identifiers are sorted in ascending order based on their lexicographical or numerical order.
[0007] Furthermore, the axis-aligned bounding box of the text label to be displayed in screen space is calculated based on the current camera transformation matrix, including: Based on the current camera transformation matrix, the scene coordinates of the text label to be displayed are mapped to the screen space to obtain the anchor point coordinates of the text label to be displayed in the screen space; Based on the width, height, and preset normalized anchor point positions of the text label to be displayed, determine the offset vectors of the four corner points of the text label to be displayed relative to the anchor point coordinates in the unrotated state; According to the rotation angle of the text label to be displayed, apply a rotation transformation to the offset vector to obtain the rotation offset of each corner point relative to the anchor point coordinates; The anchor point coordinates are superimposed with the rotation offset of each corner point to obtain the screen coordinates of the four corner points; The minimum and maximum values of the four screen coordinates in the x-axis direction of the screen space are used as the minX and maxX of the axis-aligned bounding box, respectively. The minimum and maximum values of the four screen coordinates in the y-axis direction are used as the minY and maxY of the axis-aligned bounding box, respectively.
[0008] Furthermore, spatial index instances are implemented using quadtrees or R-trees, both of which are accessed through a unified abstract adapter interface; The abstract adapter interface should at least provide functions for insertion, deletion, range retrieval, clearing, and batch loading.
[0009] Furthermore, the construction and retrieval methods of quadtrees are as follows: Configure the maximum node capacity and maximum recursion depth, using the screen canvas coordinate range as the root node region; When inserting an axis-aligned bounding box, if the current node is not split, it is stored directly; if it is split, the axis-aligned bounding box to be inserted is pushed down to the child node into which it is fully inserted, and the bounding box that crosses the boundary of the child node is retained in the current node. When the number of axis-aligned bounding boxes stored in any node reaches the node capacity limit and the current depth is less than the maximum recursion depth, the node is divided into four child nodes. During retrieval, recursively access the nodes that intersect the axis-aligned bounding box of the current label, and merge the node and the axis-aligned bounding boxes stored in all intersecting subtrees as a set of candidate labels.
[0010] Furthermore, the construction and retrieval methods of R-trees are as follows: Insert axis-aligned bounding boxes into the R tree in the form of minimum bounding rectangles, with each tree node storing the minimum bounding rectangle of all its entries; During insertion, starting from the root node, select the child node that minimizes the expansion of the node's spatial range as the insertion path, and continue until the leaf node, updating the minimum bounding rectangle of each node along the path. During retrieval, the process recursively checks the root node: if the minimum bounding rectangle of the current node does not intersect with the axis-aligned bounding box of the current label, the node and its subtree are skipped; otherwise, its child nodes are recursively visited until a leaf node returns the stored axis-aligned bounding box as a set of candidate labels.
[0011] Furthermore, the determination of true overlap specifically includes: If neither the current label nor the candidate label has been rotated, then the first projection interval of the two labels in the x-axis direction and the second projection interval in the y-axis direction in the screen space are obtained respectively; when the projection intervals of the two labels in the x-axis direction and the y-axis direction have a positive length intersection, it is determined that there is a real overlap. If the current label or candidate label is rotated, its geometric range is represented by its respective directed bounding box, and a determination is made based on the separating axis theorem: obtain the normal vectors of each side direction of the two directed bounding boxes, remove duplicates and merge them to form a candidate separating axis set; for each separating axis in the candidate separating axis set, project all vertices of the two directed bounding boxes onto the axis to obtain two projection intervals; when the two projection intervals on all candidate separating axes have a positive length intersection, it is determined that there is a true overlap.
[0012] Furthermore, after the traversal is complete and the labels marked for display are submitted to the drawing pipeline, an inter-frame multiplexing step is also included: If the current frame does not have any changes in data source, label style, interaction state, camera transformation, or canvas size compared to the previous frame, the display result and spatial index instance of the previous frame are directly reused, and the entire collision detection process is skipped. If the current frame only undergoes a camera transformation relative to the previous frame, the global processing queue is reused to re-execute axis-aligned bounding box calculation, canvas boundary culling, spatial index retrieval, and true overlap determination. If the current frame undergoes an interaction state change or a label size change relative to the previous frame, a local incremental update is performed.
[0013] Furthermore, local incremental updates include: Identify the target label affected by the change, obtain the old axis-aligned bounding box and the new axis-aligned bounding box of the target label, and expand the union of the two to generate the affected region; The currently displayed tags that fall into the affected area are queried through the spatial index instance, and the tags that are hidden due to collision with the target tag are obtained through the pre-stored conflict association table; The target tag, the currently displayed tag, and the hidden tag are combined into an affected set; Delete the old records of the affected set in the spatial index instance, re-sort and determine the true overlap of the affected set, and update the spatial index instance and conflict association table according to the determination results.
[0014] Furthermore, when performing a local incremental update, if the number of tags in the affected set exceeds a preset number threshold, or the ratio of the affected area to the total canvas area exceeds a preset area threshold, or the cumulative time of this local update exceeds a preset time threshold, the process will revert to global recalculation.
[0015] The advantages of this invention lie in its construction of a global processing queue through comprehensive weighted sorting, which ensures that text tags with high interaction attention and high business value are displayed first. Based on this, wide-phase filtering is performed using spatial indexing, compressing the full tag comparison into a local candidate tag comparison, effectively reducing the computational overhead of collision detection and improving performance in scenarios with massive tags. Simultaneously, by combining axis-aligned bounding box wide-phase filtering with true overlap narrow-phase verification, it balances computational efficiency and collision determination accuracy, adapting to rotating tag scenarios and effectively solving the problems of text tag overlap and occlusion, easy occlusion of high-value tags, and low computational efficiency in dynamic visualization scenarios. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a schematic diagram of the visual text adaptive removal method based on spatial indexing and data weighting of the present invention; Detailed Implementation
[0018] Embodiments of the present invention are described in detail below. Examples of these embodiments are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain the present invention, and should not be construed as limiting the present invention.
[0019] like Figure 1 The diagram illustrates the adaptive text removal method based on spatial indexing and data weighting proposed in this application, which includes the following steps: Step 1: Calculate the comprehensive weight based on the interaction status score and stable entry order score of the text tags to be displayed. Sort the text tags to be displayed in descending order of comprehensive weight, and sort them in sequence according to the preset decision key when the comprehensive weights are the same, to obtain the global processing queue. Step 2: Calculate the axis-aligned bounding box of the text label to be displayed in screen space based on the current camera transformation matrix, and remove labels that are completely outside the canvas according to the preset canvas boundary to obtain the set to be detected; Step 3: Create a spatial index instance to store the axis-aligned bounding boxes of the labels that have been determined to be displayed, and provide a range retrieval interface based on the intersection of the axis-aligned bounding boxes; Step 4: According to the order of the global processing queue, traverse the current label in the set to be detected in turn, and retrieve the spatial index instance with the bounding box aligned with the axis of the current label to obtain the candidate label set; Step 5: If the current label has a real overlap with any candidate label in the candidate label set, mark the current label as hidden; otherwise, mark it as displayed and insert its axis-aligned bounding box into the spatial index instance. Step 6: After the traversal is complete, submit the labels marked for display to the drawing pipeline for rendering.
[0020] The adaptive text removal method based on spatial indexing and data weighting provided in this application can be deployed in front-end rendering scenarios such as WebGIS map visualization and massive scatter plot data display. Addressing the technical problems of label stacking and occlusion, high computational cost of brute-force collision detection, and the easy hiding of high-value labels in large-scale label rendering, this application constructs a complete processing chain including priority sorting, viewport coarse screening, wide spatial index phase, narrow geometric rule phase, and inter-frame incremental optimization. It ensures the priority display of highly interactive and high-business-value labels through a comprehensive weighting mechanism, and compresses the objects requiring true overlap determination from all labels to local candidate labels through spatial indexing. In typical scenarios where label distribution does not exhibit extreme degradation, spatial index maintains effective pruning, and the average number of candidates is limited, it can significantly reduce the collision detection cost compared to brute-force pairwise comparison methods. Simultaneously, it is equipped with multi-level inter-frame reuse and local update mechanisms to maintain a smooth rendering frame rate in interactive scenarios with frequent scaling and translation. The specific implementation methods of each step are explained in detail below.
[0021] For step 1, a comprehensive weight is calculated based on the interaction status score and stable entry order score of the text labels to be displayed. The text labels to be displayed are sorted in descending order according to the comprehensive weight, and when the comprehensive weights are the same, they are sorted sequentially according to the preset decision key to obtain the global processing queue. Specifically, the comprehensive weight is used as the main sorting key to sort the text labels to be displayed in descending order. When the comprehensive weights are the same, the relative order is determined sequentially according to the decision key.
[0022] The method for determining the relative order according to the decision key includes: using the interaction state priority as the first decision key, and determining the order according to the preset hierarchical order based on the currently active interaction state type of the tag; using the stable entry sequence number as the second decision key, and arranging them in ascending order based on the numerical value of the stable entry sequence number; and using the stable identifier as the third decision key, and arranging them in ascending order based on the lexicographical or numerical order of the stable identifier.
[0023] This solution establishes a clear retention priority for all text tags to be displayed through a quantitative weight calculation system and multi-level decision-making rules. This ensures that interactive tags that users pay close attention to occupy the display position first, and avoids random jumps between tags with the same weight through stable sorting rules, thus providing an orderly processing benchmark for the subsequent collision detection process.
[0024] As a specific implementation method, the comprehensive weight is obtained by weighting the interaction state score and the stable entry order score. For the i-th text tag to be displayed, its comprehensive weight W is... i The calculation formula is: W i =αS i +(1-α)Q i , Here, α is a weight adjustment coefficient, ranging from [0,1], used to regulate the relative contribution of interaction state and data entry order in priority determination. In a preferred embodiment, α is set to 0.8, meaning that the priority of interaction state is the core guideline, while also taking into account the stability of data entry order. This coefficient can be flexibly adjusted according to the interaction tag retention rate, overall occlusion rate, and single update time requirements of the business scenario. In scenarios that emphasize the inherent business priority of data, α can be appropriately lowered, while in visualization scenarios with strong interaction orientation, α can be appropriately raised, thereby adapting to the priority preferences of different businesses and improving the scenario adaptability of the solution.
[0025] In the above comprehensive weight calculation formula, S i The interaction status score for the i-th tag is used to quantify the degree to which the tag is currently being paid attention to by the user. The calculation formula is as follows: S i =max(β E E i ,β H H i ,β L L i ,β F F i ), Among them, E i H i L i F i This corresponds to whether the current label is in one of the following interactive states: selected, hovered, locked, or focused. A value of 1 indicates the current state is active, while a value of 0 indicates it is not. β E β is the weight coefficient for the selected state. H β is the weighting factor for the mouse hover state. L β is the weighting coefficient for the locked state. FThe weight coefficients for the focus states all range from [0,1], and their hierarchical order can be preset according to the business's attention to different interaction states. Maximum value calculation is used for score synthesis. On the one hand, this avoids the score accumulation exceeding the normalization upper bound when the same tag activates multiple interaction states simultaneously, ensuring the consistency and comparability of the entire tag scoring system. On the other hand, it directly highlights the tag's current highest priority interaction state, ensuring that the tag the user is currently performing receives the highest priority weight, guaranteeing the visibility of interactive objects from the sorting source, and meeting the user's visual attention needs during the interaction process.
[0026] In alternative implementations where the intensity of complex interactions needs to be reflected, the interaction state score can be calculated using a truncated summation method, with the following formula: S i =min(1,Σ k β k X ik ), Where k is the index of the interaction state type, covering all overlayable states such as selected, hovered, locked, and focused, and X ik Let β be the indicator variable for the k-th interaction state of the i-th label, taking a value of 1 when the state is active and a value of 0 when it is inactive. k This represents the weight coefficient corresponding to the k-th interaction state, with a value range of [0,1]. The summation operation can accumulate the weights of multiple simultaneously active interaction states, reflecting the cumulative effect of attention under complex interactions. For example, when a tag is simultaneously selected and locked, its interaction score will be higher than a single selected state, and its priority will be correspondingly increased; the outer layer... The truncation operation ensures that the final score does not exceed the normalized upper bound of 1, avoiding score overflow after multiple states are superimposed and maintaining the dimensional consistency of the full tag weight system. This truncation and summation method is suitable for business scenarios that require fine-grained differentiation of interaction intensity and support for multi-state superposition and hierarchical classification. It can further enrich the priority gradient levels and improve the finesse of the interaction experience.
[0027] Q in the comprehensive weight calculation formula i A stable entry order score is assigned to the i-th label to reflect the order in which the labels were entered into the dataset, ensuring the baseline stability of the sorting results. The stable entry order score is based on stable entry sequence numbers. Assuming there are N labels in the current dataset, a stable entry sequence number r is assigned when the i-th label first enters the dataset in this round. i The serial numbers start from 1 and increment sequentially. During batch loading, they are allocated according to the order of the input array. The serial number remains unchanged while the tags are not deleted. Therefore, the formula for calculating the stable entry order score is: Q i =1-(r i -1) / max(N-1,1), Therefore, Q can be obtained.i The value range is [0,1]. The earlier the tag is added to the database, the higher the corresponding score. This design gives tags loaded into the dataset earlier a higher retention priority when the overall weight is the same, which aligns with the logic of data loading order. At the same time, the long-term stability of the sequence number avoids large fluctuations in the full sorting results when the data set is partially added or deleted, effectively reducing the visual flicker caused by frequent tag display switching and improving the visual experience during continuous rendering. If business importance needs to participate in the sorting, a separate business priority variable should be set, and it should not be mixed with the stable entry sequence number to avoid the stability of the entry order being interfered with by business attributes, and to ensure that the sorting benchmark is clear and controllable.
[0028] Based on the primary sorting key with comprehensive weights, a three-level deciding key is set to handle scenarios with the same weights layer by layer, eliminating sorting ambiguity and ensuring the determinism and reproducibility of the sorting results: The primary decision-making key at the first level is the interaction state priority. This priority is determined according to the currently active interaction state type of the tag, following a preset hierarchical order, with higher-level interaction states appearing earlier in the order. This key can further differentiate tag priorities based on interaction levels when overall weight values are equal. For example, with the same weight, a selected tag takes precedence over a hovered tag, aligning with the user's visual focus logic during interaction and ensuring that core operational objects are always displayed first.
[0029] The second deciding key at the second level is the stable entry sequence number. Tags are sorted in ascending order of their stable entry sequence number, meaning tags with smaller entry sequences and earlier entry times are ranked higher. Since the stable entry sequence number remains fixed throughout the tag's lifecycle, this deciding key provides a stable order benchmark when interaction states are the same. This prevents tags with the same weight and interaction state from experiencing inter-frame position jumps due to random sorting, significantly improving visual stability during continuous rendering. It also facilitates developers in troubleshooting and verifying effects based on a fixed order.
[0030] The third-level deciding key is the stable identifier, which is arranged in ascending order according to lexicographical or numerical order, serving as the final fallback rule. The stable identifier is a unique identifier for each tag, preferentially using the unique business primary key provided by the data source to ensure business consistency. If the data source lacks a unique primary key, a 128-bit hash value can be calculated from the normalized byte sequence of the data source identifier, the original record key, and the initial entry sequence number as a string identifier, with a deterministically increasing suffix appended when a hash collision is detected. If only intra-session stability is required, a monotonically increasing unsigned 64-bit integer can be assigned during the initial entry. The stable identifier remains unchanged while the tag is not deleted. During data refresh, the same business records use the original identifier, thus completely eliminating sorting ambiguity and ensuring that the sorting results are fully reproducible under the same input conditions, providing a stable order benchmark for subsequent collision detection, inter-frame reuse, and incremental updates.
[0031] With the above solution, after the global processing queue is generated, the queue results can be cached and reused without changes to the data source, label style, or interaction state. In scenarios such as camera transformation and canvas size change, there is no need to re-execute weight calculation and sorting. Only the screen geometry information of the labels needs to be updated synchronously. This can effectively reduce the sorting calculation overhead in dynamic interaction scenarios and improve the rendering frame rate.
[0032] In summary, this step constructs a complete sorting system with sovereignty reclassification and a three-tiered final decision. On the one hand, through a configurable weighted synthesis mechanism and optional interactive scoring calculation methods, it adapts to the priority preferences and refined classification needs of different businesses, ensuring that high-value tags that users interact with can enter the display set first. This solves the problem of core information being easily obscured under traditional random elimination or first-in-first-out rules from a rule-based perspective. On the other hand, through a multi-level stable final decision key design, it ensures the determinism and continuity of the sorting results, avoiding visual flickering and experience degradation caused by random jumps of tags with the same weight.
[0033] For step 2, calculate the axis-aligned bounding box of the text label to be displayed in screen space based on the current camera transformation matrix, and remove labels that are completely outside the canvas according to the preset canvas boundary to obtain the set to be detected. The calculation of the axis-aligned bounding box of the text label to be displayed in screen space based on the current camera transformation matrix includes: mapping the scene coordinates of the text label to be displayed to screen space based on the current camera transformation matrix to obtain the anchor point coordinates of the text label in screen space; then determining the offset vectors of the four corner points of the text label relative to the anchor point coordinates in the unrotated state according to the width, height and preset normalized anchor point position of the text label; next, applying a rotation transformation to the offset vectors according to the rotation angle of the text label to obtain the rotation offset of each corner point relative to the anchor point coordinates, where the rotation angle is a rendering attribute of the label, determined by scene style configuration, data mapping rules or interactive operations, and consistent with the rotation parameters of the rendering pipeline; then superimposing the anchor point coordinates with the rotation offset of each corner point to obtain the screen coordinates of the four corner points; using the minimum and maximum values of the four screen coordinates in the x-axis direction of screen space as the minX and maxX of the axis-aligned bounding box, and using the minimum and maximum values of the four screen coordinates in the y-axis direction as the minY and maxY of the axis-aligned bounding box, respectively.
[0034] As a specific implementation plan, during the anchor point coordinate mapping stage, the entire calculation is strictly aligned with the transformation logic of the rendering pipeline to ensure that the geometric benchmark for collision detection is consistent with the actual rendering result at the pixel level. For 2D visualization scenes, the scene coordinates of the labels are represented as homogeneous vectors p. s =[x s ,y s ,1] T , where x s Let y be the horizontal coordinate component of the label in the two-dimensional scene coordinate system. s The vertical coordinate component of the label in the 2D scene coordinate system is the camera transformation matrix M used to complete the spatial mapping of the label's scene coordinates. vs It is composed of four levels of transformations in a fixed order, namely: M vs =T c ·R c ·S c ·T o , Among them, T o To transform the scene origin and camera center to the computation origin using the translation matrix, S c R is the camera scaling matrix. c Let T be the camera rotation matrix. cThis is the viewport translation and canvas origin mapping matrix. By performing matrix multiplication on the homogeneous vectors of the scene coordinates using this composite matrix, we obtain the mapping result of the label anchor points in screen space: p c =M vs ·p s , The result p c This refers to the screen coordinates of the tag anchor point, denoted as A. i =(A x A y If the rendering buffer uses device pixels for calculation, the above transformation can be multiplied by a scaling matrix corresponding to the device pixel ratio to complete the final pixel-level mapping. The matrix multiplication order, coordinate axis direction, and rotation center of this transformation mechanism are consistent with the rendering engine, which can fundamentally avoid collision detection misalignment caused by coordinate system differences and transformation order deviations, ensuring that the detection results perfectly match the visual experience.
[0035] After obtaining the anchor point coordinates, calculate the offset vectors of the four corner points relative to the anchor point in the unrotated state. Let the width of the label be w. i The height is h i Both are determined by the text measurement width, font size, line height, line break rules, stroke width, and preset safety spacing to ensure that the bounding box size is consistent with the actual visual range of the rendered label; the normalized position of the anchor point in the local rectangle of the label is (a x ,a y ), where a x ,a y ∈[0,1], for example, the top left corner anchor point corresponds to (0,0), the center anchor point corresponds to (0.5,0.5), and the bottom right corner anchor point corresponds to (1,1). In the unrotated state, the local coordinates of the k-th corner point are (ξ... k ,η k ), where ξ k ∈{0,w i}、η k ∈{0,h i From this, the offset vector q of the corner point relative to the anchor point coordinates can be calculated. k : q k =(ξ k -a x w i ,η k -a y h i ), The design of normalized anchor points eliminates the need to develop separate logic for the differences in anchor points of different visualization components. It can adapt to the anchoring rules of various annotations, significantly improving the method's ability to adapt to different scenarios.
[0036] Subsequently, a rotation transformation is applied to the offset vector to obtain the rotation offset of each corner point relative to the anchor point coordinates. The rotation angle θ is an inherent rendering attribute of the label, determined by scene style configuration, data mapping rules, or user interaction. Its value and rotation direction are consistent with the rotation parameters of the rendering pipeline. Based on this, and using the geometric principles of a two-dimensional rotation matrix, the offset vector q... k Rotating the anchor point by an angle θ yields the rotation offset components in the x and y directions. This calculation supports arbitrary rotation angles; special scenarios such as the center anchor point are special cases of this general form at a specific normalized position. If the label also undergoes local scaling or skewing transformations, the offset vector can be extended to a homogeneous vector. All local transformations can be uniformly completed through matrix chain operations of translation, rotation, and scaling, demonstrating excellent scalability and covering diverse rendering needs such as skewing labels and scaled text.
[0037] By adding the anchor point coordinates to the corresponding corner point rotation offsets component by component, the final screen coordinates of the four corner points can be obtained, and the screen coordinate of the k-th corner point (x... k ,y k The calculation formula is: x k =A x +(ξ k -a x w i )cosθ-(η k -a y h i sinθ y k =A y +(ξ k -a x w i )sinθ+(η k -a y h i cosθ This formula allows for the sequential calculation of the screen coordinates of all four corner points of the label, providing a complete geometric basis for the subsequent generation of axis-aligned bounding boxes.
[0038] After obtaining the screen coordinates of all four corner points, the final axis-aligned bounding box is generated by extracting the extreme values of the coordinates. The extreme values of the x and y coordinates of each of the four corner points are taken. The minimum value in the x-direction is used as the minX of the axis-aligned bounding box, and the maximum value is used as the maxX. The minimum value in the y-direction is used as the minY, and the maximum value is used as the maxY. This constitutes the complete axis-aligned bounding box, which can be uniformly represented as: B i =(minX,minY,maxX,maxY), For tags whose anchor point is the geometric center and which only undergo rotational transformations, a simplified method can be used to directly calculate the bounding box size, i.e., the width w. A =|w i cosθ|+|h i sinθ|, height h A =|w i sinθ|+|h i The cosθ| form eliminates the need to calculate the coordinates of each of the four corners, resulting in higher computational efficiency. However, it is only applicable to scenarios where the central anchor point does not undergo additional local transformations. Further reductions in geometric computational overhead can be achieved in suitable scenarios. The resulting axis-aligned bounding box serves as the unified geometric unit for subsequent spatial indexing retrieval, providing a standardized data foundation for rapid wide-phase filtering.
[0039] After calculating the axis-aligned bounding boxes for all labels, perform viewport culling of the canvas boundaries. Let the canvas area be C=[0,W]. c ]×[0,H c ], where W c For canvas width, H c The height is the canvas height, when the label satisfies maxX < 0 and minX > W. c maxY < 0 or minY > H c If a label is completely outside the canvas under any of the above conditions, it is directly removed from the processing set. Labels that do not meet the above conditions, i.e., labels that are completely or partially inside the canvas, are retained to form a detection set for subsequent collision detection processes. For labels that are partially inside the canvas, the collision determination stage still uses the complete axis-aligned bounding box range to ensure the integrity of the determination logic. Once a label is determined to be displayed, it is submitted to the rendering pipeline, and during the rasterization stage, the canvas clipping rectangle removes pixels outside the canvas, thus not affecting the final rendering effect. Viewport pre-culling can filter out all completely invisible labels before collision detection. Especially during large-scale scene translation and scaling interactions, it can quickly exclude most objects outside the viewport, compressing the subsequent computation scale to the visible range. This is the first key optimization step in reducing overall computing power.
[0040] The above steps achieve precise mapping of tag geometry from scene space to screen space through a multi-level composite transformation mechanism fully aligned with the rendering pipeline. Simultaneously, normalized anchor points, universal rotation calculations, and optional simplified forms balance scene adaptability and operational efficiency. The accompanying canvas boundary viewport culling mechanism significantly reduces the number of tags processed subsequently without sacrificing detection accuracy. This provides an accurate and consistent geometric foundation for subsequent spatial indexing and collision detection, and also ensures high frame rate operation for the entire method in scenarios with massive tag counts.
[0041] For step 3, a spatial index instance is created to store the axis-aligned bounding boxes of labels that have been determined to be displayed, and a range retrieval interface based on the intersection of the axis-aligned bounding boxes is provided. The spatial index instance is implemented using a quadtree or an R-tree, both of which are accessed through a unified abstract adapter interface. The abstract adapter interface provides at least the functions of insertion, deletion, range retrieval, clearing, and batch loading.
[0042] The quadtree described above is constructed as follows: The root node region is defined by the screen canvas coordinates, with a maximum node capacity and a maximum recursion depth. When inserting an axis-aligned bounding box, if the current node is not split, it is stored directly; if it is split, the bounding box to be inserted is pushed down to the child node where it is fully inserted, while those crossing the child node boundary are retained in the current node. When the number of axis-aligned bounding boxes stored in any node reaches the node capacity limit and the current depth is less than the maximum recursion depth, the node is divided into four equal child nodes. During retrieval, nodes intersecting the axis-aligned bounding box of the current label are recursively accessed, and the node and the axis-aligned bounding boxes stored in all intersecting subtrees are merged into a candidate label set.
[0043] The R-tree is constructed as follows: axis-aligned bounding boxes are inserted into the R-tree in the form of minimum bounding rectangles. Each tree node stores the minimum bounding rectangles of all its entries. During insertion, starting from the root node, the child node that minimizes the expansion of the node's spatial range is selected as the insertion path, up to the leaf node, and the minimum bounding rectangles of each node are updated along the path. During retrieval, starting from the root node, a recursive check is performed: if the minimum bounding rectangle of the current node does not intersect with the axis-aligned bounding box of the current label, the node and its subtree are skipped; otherwise, its child nodes are recursively visited until the leaf node returns the stored axis-aligned bounding boxes as the candidate label set.
[0044] This step is the core of the wide-phase screening in the entire collision detection system. It uses a spatial data structure to quickly filter labels in space, ensuring that subsequent true overlap determination is performed only on local candidate labels returned by the range retrieval. Under normal circumstances where label distribution does not exhibit extreme degradation and the spatial index maintains effective pruning, this significantly reduces the number of label pairs involved in collision determination compared to indiscriminate pairwise comparisons of all labels, drastically compressing the overall computational scale of collision detection. Simultaneously, a unified abstract adaptation layer shields the differences between different index implementations, adapting to different label distributions and update scales, balancing optimal performance and architectural compatibility across various label distribution scenarios. In the entire detection chain, the spatial index instance only stores the axis-aligned bounding boxes of labels already determined to be displayed, and only performs the function of retrieving spatially adjacent candidates. It is neither responsible for camera viewport culling nor directly equates the retrieval results with true collision conclusions. This forms a two-level detection architecture with subsequent true overlap determination, consisting of wide-phase coarse screening and narrow-phase fine judgment, maximizing the compression of precise computation while ensuring judgment accuracy.
[0045] In other words, the two index implementations are integrated into the system through a unified abstract adapter interface, which provides at least five standard functions: insertion, deletion, range retrieval, clearing, and batch loading. This design allows upper-layer modules such as weight sorting, viewport detection, axis alignment bounding box calculation, and true overlap determination to complete all spatial retrieval operations without needing to be aware of the specific implementation of the underlying index, simply through the standard interface. When business scenarios change and require switching index types, only the index adapter and its configuration parameters need to be replaced; the upper-layer business logic remains unchanged, effectively reducing architectural coupling and improving the solution's scenario adaptability and maintainability.
[0046] Within this unified interface framework, the appropriate index implementation can be automatically selected based on the spatial distribution characteristics and update scale of the tags to ensure optimal retrieval performance in different scenarios. To achieve quantitative optimization of index types, the canvas is first sampled in a grid to statistically analyze its distribution characteristics. Specifically: Divide the canvas into G equal-area sampling grids, and let n be the number of label centers in the g-th sampling grid. g Then the average number of labels μ across all sampled cells is: μ = (Σ g n g Based on the dispersion of the number of sampling grid tags, the spatial distribution dispersion coefficient γ is further calculated to measure the uniformity of the tag distribution. The calculation formula is as follows: , Meanwhile, an update ratio is defined to measure the scale of a single update. Let the number of tags involved in a single update be ΔN and the total number of tags be N. Then the update ratio ρ is: ρ = ΔN / max(N, 1).
[0047] In one exemplary decision rule, when the canvas boundary is fixed, γ≤0.5 and ρ≤0.20, the label distribution is uniform and the update range is small, so a quadtree is preferred to leverage its advantage of efficient local updates; otherwise, an R-tree is preferred to adapt to uneven distribution and large-scale update scenarios. The thresholds corresponding to γ and ρ mentioned above are configurable implementation parameters that can be calibrated according to the label size and device performance.
[0048] To avoid frequent back-and-forth switching of indexes between the two implementations due to scenario fluctuations, a delayed switching mechanism was further implemented. The average total time for a single query and update of both indexes was continuously recorded within a statistical window of length L, with the average time for the quadtree index denoted as T. Q The average time taken to index an R-tree is denoted as T. R Let the time taken by the currently used index be T. cur The time taken for the candidate index to be switched is T. alt If the currently active index is a quadtree, then T cur =T Q Talt =T R If the currently active index is an R-tree, then T cur =T R T alt =T Q Only if the time consumption of the candidate index satisfies T alt ≤(1-η)T cur Index switching is only performed when m windows are established consecutively. Here, η can be 0.15, m can be 3, and L for each window can be 30 to 120 operations. By setting a performance gain threshold and continuous verification windows, a switching hysteresis effect is formed, which effectively suppresses the additional overhead caused by frequent switching and ensures the stability of running performance.
[0049] The aforementioned quadtree index is more suitable for 2D scenes with fixed canvas boundaries, uniform label distribution, and frequent local updates. It uses the canvas coordinate range as the root node region, denoted by K for node capacity and D for maximum depth. K can be set between 4 and 16, and D between 6 and 12, with specific values determined comprehensively based on canvas size, number of labels, spatial distribution, and update frequency. To avoid the hierarchical overhead and object migration costs caused by excessive node subdivision, a minimum unit size constraint is introduced to calibrate the effective depth, preventing performance loss during splitting and migration operations due to excessive granularity. Let the width and height of the screen axis-aligned bounding box of label i be w... i h i The safety distance is δ, and the median of the largest side length of the labels in the current candidate label set is . The calculation formula is as follows: , The minimum unit size of the quadtree is determined by combining the median label size, the safety margin, and the lower limit of pixels. The calculation formula is: , in To prevent excessive subdivision of the lower pixel limit, a range of 32 to 128 device pixels can be used. The effective recursion depth D can be deduced from the minimum unit size. eff The preset maximum depth is calibrated using the following formula: , In the formula This is the floor function. It is only valid if the number of objects within a node reaches K and the current depth is less than D. eff And the smaller of the node width and height is greater than Only when the node is divided into four child nodes along the horizontal and vertical midlines is the index subdivided into four equal parts. This controls the granularity of the index and avoids the extra overhead caused by invalid hierarchical splitting.
[0050] When inserting an axis-aligned bounding box, if the current node is not split, it is stored directly; if it is split, the spatial position of the axis-aligned bounding box to be inserted is determined. Only axis-aligned bounding boxes that fall completely within the range of one child node are dropped to that child node, while axis-aligned bounding boxes that cross the boundaries of more than one child node are retained in the current node. This rule ensures that bounding boxes across regions are not forcibly split, maintaining a one-to-one correspondence between index entries and label geometry. During retrieval, nodes intersecting with the axis-aligned bounding box of the current label are recursively accessed, and the axis-aligned bounding boxes stored in the current node and all intersecting subtrees are merged and returned as a set of candidate labels. When data is added, deleted, or the label size changes, insertion, removal, or re-insertion operations can be performed on the affected axis-aligned bounding boxes. When the total number of objects in the four subtrees is lower than the merging threshold, child nodes can be reclaimed and objects promoted to parent nodes, dynamically optimizing the index structure. In actual configuration tuning, D can be appropriately increased in scenarios with larger canvases or more labels, and K can be appropriately increased in scenarios with frequent updates or highly skewed distribution to reduce the overhead of splitting and object migration.
[0051] Compared to quadtrees, R-tree indexes are implemented based on the R-tree spatial data structure, making them more suitable for scenarios with uneven label distribution, dynamically changing bounding boxes, and batch loading requirements. During construction, the axis-aligned bounding box of each displayed label is inserted into the tree as a minimum bounding rectangle of {minX, minY, maxX, maxY}. Each tree node stores the minimum bounding rectangle of all its entries. This design allows for quick determination of whether to delve deeper into subtrees during retrieval based on the node-level bounding rectangle, achieving extensive spatial pruning. Insertion starts from the root node, selecting the child node that minimizes the node's spatial range as the insertion path layer by layer until the leaf node is reached to complete the entry insertion. The minimum bounding rectangle of each level of nodes is then updated in reverse along the insertion path, ensuring the consistency of the entire tree index range. During retrieval, the system recursively checks the bounding box starting from the root node. If the minimum bounding rectangle of the current node does not intersect with the axis-aligned bounding box of the current label, the node and its subtree are skipped, achieving extensive spatial pruning. If they intersect, the recursive access to its child nodes continues until the leaf node returns the stored axis-aligned bounding box as the candidate label set. During batch initialization, the batch loading interface can be used to build the entire index tree at once, which has higher construction efficiency compared to sequential insertion; when there are local changes, insertion, deletion or re-insertion operations are used to balance the performance of full and incremental scenarios.
[0052] Furthermore, both quadtrees and R-trees only perform wide-phase retrieval in the entire collision detection process. For non-rotated labels, the axial overlap determination of axis-aligned bounding boxes can be directly used as an accurate collision conclusion. For rotated labels, the candidate objects returned by wide-phase retrieval still need to enter the subsequent narrow-phase determination stage, where accurate verification is completed through directed bounding boxes and the separating axis theorem. This two-level detection division of labor design not only significantly compresses the scale of objects requiring complex geometric calculations through spatial indexing, but also ensures the detection accuracy in rotating scenarios through targeted accurate determination, achieving a balance between operational performance and determination accuracy.
[0053] The above steps, through a replaceable dual-index architecture and a unified abstract adaptation interface, achieve flexible expansion and scenario adaptation of the index layer while maintaining the stability of the upper-layer detection logic. Based on a quantitative selection mechanism of distribution skewness and update ratio, combined with a hysteresis switching strategy, the optimal indexing scheme can be dynamically matched for different scenarios, avoiding the performance limitations of a single index under different distributions. The quadtree optimizes the granularity and update efficiency through minimum unit size constraints and a dynamic merging mechanism, while the R-tree adapts to non-uniform distribution and full initialization scenarios through spatial pruning and batch loading mechanisms. Together, they constitute a high-performance, wide-phase screening base. The entire spatial indexing mechanism compresses the computational load of collision detection from traditional full pairwise comparisons to local proximity retrieval, representing a breakthrough in O(N) computational complexity. 2 The core component that addresses the bottleneck of computing power and supports real-time rendering of massive amounts of tags.
[0054] For step 4, according to the order of the global processing queue, the current label in the set to be detected is traversed in turn, and the spatial index instance is retrieved with the axis of the current label aligned with the bounding box to obtain the candidate label set.
[0055] This step combines the priority retention rules with the spatial index wide-area filtering. On the one hand, the weight-based traversal order ensures that high-value tags occupy the display positions first. On the other hand, it relies on the spatial index instance built in step 3 to complete the fast retrieval of neighboring candidates, compressing the comparison scale of the subsequent accurate collision determination from the full set of tags to a local neighbor set. It is a key transitional step connecting the sorting step and the accurate determination step.
[0056] Specifically, the traversal process strictly follows the descending order of the overall weight of the global processing queue, meaning that tags with higher overall weights enter the collision detection process earlier. This traversal order is the core execution carrier of the entire high-priority retention rule: since the spatial index instance only stores tags that have been determined to be displayed, high-weight tags processed first, if they pass the collision detection, will be inserted into the index first to occupy display space; when low-weight tags are retrieved later, the index already contains all higher-priority displayed tags, so if a collision occurs, the low-weight tags are directly marked and hidden, naturally ensuring the display priority of high-value tags without additional priority comparison. This design simplifies the logical complexity of collision detection and strictly implements the priority rules of weight sorting in the execution process, fundamentally solving the problem of core tags being easily obscured in traditional unordered removal schemes.
[0057] For each current label, its own axis-aligned bounding box is used as the query condition, and the range retrieval interface of the spatial index instance is called to perform the query. During the traversal and judgment process, all displayed labels are stored in the spatial index instance in the form of axis-aligned bounding boxes; for rotated labels, a directed bounding box consisting of four ordered vertices is cached synchronously for use in subsequent narrow phase judgment. The spatial index does not directly store directed bounding boxes because both R-trees and regular quadtrees perform range queries using axis-aligned rectangles. The insertion and query overhead of axis-aligned bounding boxes is lower. Only a small number of candidates that hit the wide phase need to be subject to precise directed bounding box judgment. This design ensures judgment accuracy while minimizing the operating overhead of the spatial index.
[0058] Since step 3 has shielded the underlying implementation differences between quadtrees and R-trees through a unified abstract adaptation interface, the upper-level traversal logic does not need to be aware of the specific index type. It can complete the query simply through the standard range retrieval interface, and the returned result is the set of candidate labels that are adjacent to the current label space and have the possibility of intersection. If the underlying implementation uses a quadtree, the retrieval process will recursively traverse all nodes that intersect with the query bounding box, merging all bounding boxes within the node and in the intersecting subtrees to form the candidate label set. If the underlying implementation uses an R-tree, it will perform large-scale spatial pruning through the minimum bounding rectangle of the node, only penetrating the intersecting child nodes to the leaf nodes, and returning the matched bounding boxes as the candidate label set. Both implementations use the pruning capability of the spatial structure to quickly filter out labels that are completely non-intersecting in space, retaining only a small number of adjacent candidates for subsequent precise judgment.
[0059] The candidate label set only represents the possibility of spatial proximity and intersection, and is not the final collision determination. Its core function is to compress the O(M) complexity of comparing with all displayed labels one by one into an O(K) complexity of comparing with only a small number of candidates, where K is the number of candidates returned in a single retrieval, which is usually much smaller than the total number of displayed labels M. In typical scenarios where the label distribution does not exhibit extreme degradation, the spatial index maintains effective pruning, and the average number of candidates is limited, combined with the linear progression of the traversal process, the expected time complexity of the entire collision detection can be approximately expressed as O(NlogM + ∑K). i ), where K i Let represent the number of candidate tags returned in the i-th range search. Compared to the traditional brute-force method of comparing all tags pairwise, this significantly reduces the number of tag pairs that need to be determined for true overlap. In scenarios with massive numbers of tags, this can bring orders of magnitude performance improvement and is one of the core optimization methods to ensure rendering frame rate. During the traversal, after the current tag completes the search of the candidate tag set, it will enter the subsequent true overlap determination stage. If it is determined to be collision-free and can be displayed, its axis-aligned bounding box is inserted into the spatial index instance for use in subsequent tag searches. This achieves dynamic incremental construction of the index, ensuring that each search step is based on all currently determined display tags, and the determination logic is rigorous and self-consistent.
[0060] The above steps, through a weighted traversal order, implement the global sorting priority rules into the collision determination execution process, ensuring the priority display of tags with high interaction attention and high business value. Simultaneously, leveraging the wide-phase retrieval capabilities of the spatial index, it achieves rapid screening of collision candidates with extremely low overhead, significantly reducing the computational scale of subsequent precise geometric determination. The index layer adopts a hierarchical design of unified storage of axis-aligned bounding boxes and directed bounding boxes for rotating tag caching, balancing the operational efficiency of wide-phase retrieval with the accuracy requirements of narrow-phase determination. This combination not only implements the value orientation of tag removal but also ensures operational performance in large-scale scenarios, providing crucial support for the entire adaptive removal method to achieve the dual goals of reasonable effect and high performance.
[0061] For step 5, if the current label has a true overlap with any candidate label in the candidate label set, the current label is marked as hidden; otherwise, it is marked as displayed, and its axis-aligned bounding box is inserted into the spatial index instance. The determination of true overlap specifically includes: if neither the current label nor the candidate label has rotated, then the first projection interval of each label in the x-axis direction and the second projection interval in the y-axis direction of the screen space are obtained respectively; when the projection intervals of the two labels in the x-axis and y-axis directions have a positive length intersection, a true overlap is determined; if either the current label or the candidate label has rotated, then their geometric range is represented by their respective directed bounding boxes, and a determination is made based on the separating axis theorem: the normal vectors of each side direction of the two directed bounding boxes are obtained, deduplicated, and merged to form a candidate separating axis set; for each separating axis in the candidate separating axis set, all vertices of the two directed bounding boxes are projected onto that axis to obtain two projection intervals; when the two projection intervals on all candidate separating axes have a positive length intersection, a true overlap is determined.
[0062] This step is the narrow-phase precise determination link in the collision detection system. It takes the candidate label set returned from step 4, adopts differentiated precise geometric determination rules for whether the label is rotated, outputs the final collision conclusion and label visibility status, and updates the spatial index instance at the same time to ensure that the subsequent label determination is always based on the latest display set. It is the core execution link to ensure the accuracy of collision determination and the implementation of priority rules.
[0063] Specifically, in scenarios where neither the current label nor the candidate labels have rotated, their true geometric extents completely overlap with the axis-aligned bounding boxes. Therefore, the axial projection method can be used for accurate determination. During the determination, the first projection interval of the two labels along the x-axis and the second projection interval along the y-axis in screen space are obtained respectively. If the projection intervals of the two labels in both the x-axis and y-axis directions have a positive length intersection, they are determined to have a true overlap. If the projection intervals along either axis have no intersection, or only boundary contact with a zero intersection length, then no true overlap is determined. This determination logic is completely equivalent to conventional axis-aligned bounding box intersection detection. The computational logic is simple and has extremely low overhead, allowing collision verification of a single set of labels to be completed in constant time. It can efficiently handle the large-scale accurate determination requirements in non-rotated scenarios.
[0064] If the current label or candidate labels are rotated, the true geometric extent of the label is a directed bounding box, while the axis-aligned bounding box is only the outer coarse extent. Directly using axial projection for judgment can easily lead to misjudgments where bounding boxes intersect but the actual labels do not overlap. Therefore, a precise verification is performed based on the separating axis theorem. During the judgment, the unit normal vectors of each side direction of the two directed bounding boxes are first obtained. Duplicate direction vectors are deduplicated and merged to form a candidate separating axis set. For a rectangular directed bounding box, the deduplicated candidate separating axes contain a maximum of four, effectively controlling the computational scale. Then, for each separating axis 'a' in the candidate separating axis set, all vertices v of the two directed bounding boxes are... k Projected onto this axis, the projection value is This allows us to obtain the projection ranges of the two labels respectively. The intersection state of the projection intervals is checked axis by axis. If there is no positive-length intersection between the projection intervals on any separation axis, it can be determined that the two labels do not actually overlap. Only when the two projection intervals on all candidate separation axes have positive-length intersections are they determined to actually overlap. This determination mechanism strictly follows the geometric principle of the separation axis theorem, which can guarantee the geometric accuracy of collision determination in rotating scenes. At the same time, since this operation is only performed on a small number of candidate labels selected by spatial index, the overall computational cost is controllable, balancing determination accuracy and running performance.
[0065] After determining the true overlap between the current tag and all candidate tags, tag status marking and spatial index updates are performed. If the current tag has a true overlap with any higher-priority displayed tag in the candidate tag set, the current tag is marked as hidden, and the conflicting tag identifier that caused it to be hidden is recorded, providing a bidirectional correlation basis for subsequent inter-frame incremental updates. If the current tag has no true overlap with any candidate tags, the current tag is marked as displayed, and its axis-aligned bounding box is inserted into the spatial index instance, allowing subsequent traversed tags to perform retrieval and determination based on the updated display set. Since the traversal process strictly follows the descending order of comprehensive weight, high-priority tags will be determined first and occupy display positions in the index. Low-priority tags will automatically avoid existing high-priority tags during subsequent retrievals. The rule of prioritizing the retention of high-value tags is naturally implemented without additional priority comparison, ensuring the simplicity of the determination logic and the consistency of rule execution.
[0066] For extremely dense visualization scenarios, supplementary control strategies can be set, such as minimum safe spacing between labels, maximum number of labels displayed per viewport, or weighted truncation. These strategies always prioritize retaining interactive state labels. Such strategies only reduce the number of ordinary labels displayed, optimize the visual effect in dense areas, and do not change the already executed wide-phase retrieval and narrow-phase collision determination results, thus not affecting the accuracy of the collision detection logic.
[0067] The above steps employ a differentiated dual-scene judgment strategy, using efficient axial projection judgment for non-rotated labels and precise separation axis theorem judgment for rotated labels. This covers the judgment requirements of different label styles and achieves a balance between accuracy and performance. Combined with pre-emptive spatial index wide-phase filtering, the entire collision detection system forms a layered architecture of rapid coarse screening and precise judgment / verification. In complex visualization scenarios with massive amounts of labels and rotated annotations, it maintains a smooth rendering frame rate while ensuring the geometric accuracy of collision judgment, avoiding label overlap, occlusion, or false rejection. The accompanying extreme scene density control strategy further optimizes visual readability in dense scenes, providing reliable judgment support for the final clear and reasonable text label rendering effect.
[0068] For step 6, after the traversal is complete, the labels marked for display are submitted to the rendering pipeline for rendering. After the traversal is complete and the labels marked for display are submitted to the rendering pipeline, an inter-frame reuse step is also included: if the current frame has not changed in terms of data source, label style, interaction state, camera transformation, or canvas size compared to the previous frame, the display result and spatial index instance of the previous frame are directly reused, skipping the entire collision detection process; if the current frame has only changed in terms of camera transformation compared to the previous frame, the global processing queue is reused, and axis-aligned bounding box calculation, canvas boundary culling, spatial index retrieval, and true overlap determination are re-executed; if the current frame has changed in terms of interaction state or label size compared to the previous frame, a local incremental update is performed. Local incremental updates include: identifying the target label affected by the change; obtaining the old axis-aligned bounding box and the new axis-aligned bounding box of the target label; expanding the union of the two to generate the affected area; querying the currently displayed labels that fall within the affected area using the spatial index instance; and obtaining the labels hidden due to collisions with the target label using a pre-stored conflict association table; integrating the target label, the currently displayed label, and the hidden labels into an affected set; deleting the old records of the affected set in the spatial index instance; re-sorting and determining true overlap for the affected set; and updating the spatial index instance and conflict association table based on the determination results. When performing a local incremental update, if the number of labels in the affected set exceeds a preset threshold, or the ratio of the affected area to the total canvas area exceeds a preset area threshold, or the cumulative time of this local update exceeds a preset time threshold, the update will revert to a global recalculation.
[0069] This step undertakes two core functions: final rendering output and dynamic performance optimization. On the one hand, it outputs the final tag rendering set to complete the visualization presentation. On the other hand, through multi-level inter-frame reuse mechanisms, incremental update strategies, and batch adaptation to low-end devices, it matches the corresponding granularity of the calculation link for different types of scene changes, minimizing meaningless full recalculation. This is the key optimization link for the whole method to maintain a high rendering frame rate in dynamic interactive scenarios.
[0070] The algorithm does not unconditionally reorder and rebuild the index frame by frame. Instead, it triggers updates by listening for five types of events: data additions / deletions, changes in label text or size, changes in interaction state, changes in camera matrix version, and changes in canvas size. It also merges multiple events within the same frame using `requestAnimationFrame` (the browser's frame animation scheduling interface) to avoid performance fluctuations caused by frequent recalculations within a short period. All changes are identified using a version number mechanism. Frames with unchanged data, style, and camera matrix versions are considered static and receive the highest level of reuse. When a version change occurs, the update path is matched to the appropriate level based on the type and scope of the change.
[0071] Based on the type of inter-frame change event, the inter-frame multiplexing strategy is divided into three priority levels, corresponding to three types of processing logic: full reuse, camera transform reuse, and local incremental update. The first level is the full reuse level. When the current frame has not undergone any of the five types of changes compared to the previous frame, it is determined to be a static frame. In this case, the label display result and spatial index instance of the previous frame are directly reused, completely skipping the entire process of weight sorting, geometric calculation, and collision detection, and only performing normal rendering output. The computational overhead of the collision detection stage is almost zero in this level, which can significantly reduce the CPU resource consumption in static scenes. It is especially suitable for scenes where the user does not operate and the screen is static, significantly reducing the running power consumption and resource consumption while ensuring that the display effect remains unchanged.
[0072] The second level is the camera transformation reuse level. When only camera transformations such as zooming, translation, and rotation occur in the current frame, while the data source, label style, and interaction state remain unchanged, the overall weight of the labels is determined only by the interaction state and the order in which they are added to the database. Since the sorting result of the global processing queue remains unchanged, the cached global processing queue can be directly reused without re-performing weight calculation and sorting operations. To further reduce the computational load in scenarios with micro-camera displacement, a displacement threshold determination mechanism is introduced. This mechanism quantifies the inter-frame displacement amplitude of the labels to determine whether to reuse existing collision results.
[0073] Let the four canvas corners of label i before and after the camera change be p. ik p' ik Then the maximum corner displacement d of the label i Defined as the maximum value of the Euclidean distance between the four corner points, i.e.: , Where ||*||2 is the L2 norm, used to calculate the Euclidean distance between the same corner point in the canvas space before and after the camera transformation.
[0074] Equivalently, the boundary displacement can also be defined by the boundary difference between the old and new axis-aligned bounding boxes. The displacement amplitude can be quickly estimated without calculating the Euclidean distance of each corner point individually. The calculation formula is as follows: , Among them, B i =(minX,minY,maxX,maxY) represents the axis-aligned bounding box before camera transformation, B' i =(minX',minY',maxX',maxY') is the transformed axis-aligned bounding box.
[0075] Based on this, the maximum displacement d of the current viewport candidate label set max Take the maximum value of all label offsets, that is... Alternatively, a more conservative approach can be adopted: for each label, take the larger value between the corner displacement and the boundary displacement, and then take the maximum value of the entire set. , A conservative approach to selecting values can further avoid missed detections and ensure the accuracy of collision results.
[0076] When d max ≤ε px When the current camera transformation is determined to be a micro-displacement, where ε px This is a pixel tolerance threshold, configurable from 0.5 to 1 device pixel. It considers that the maximum relative displacement between any two tags can reach 2d. max Micro-displacement conditions are not directly equivalent to label collision relationships remaining unchanged. To prevent labels near the collision boundary from changing their collision state due to micro-displacement, boundary checks are performed on label pairs that did not have a conflict in the previous round but whose expanded bounding boxes may intersect, as well as label pairs that already had a blocking relationship in the previous round's conflict association table.
[0077] Specifically, align the axis of the previous label i with the bounding box B. i According to 2d max Expand outward to obtain an expanded bounding box. : (minX-2d) max ,minY-2d max maxX+2d max maxY+2d max ).
[0078] The spatial index, composed of expanded bounding boxes, is retrieved using the new axis-aligned bounding box of the current label. Label pairs whose spatial intersection state may change due to micro-displacements are then filtered. For labels that are not in the candidate set and do not involve existing conflict associations, the previous round of explicit / implicit results is directly reused. For labels that are in the candidate set or have existing conflict associations, the axis-aligned bounding box intersection determination is re-executed. If any label is rotated, the true overlap determination based on the directed bounding box and the separating axis theorem is continued. The label explicit / implicit state, spatial index, and conflict association table are updated according to the verification results.
[0079] When d max >ε px If the number of labels involved in the boundary verification, the area of the affected region, or the cumulative calculation time exceeds the preset backoff threshold, the axis-aligned bounding box calculation, canvas boundary culling, spatial index construction, and true overlap determination are re-executed. Thus, in scenarios with slight camera displacement, the existing results of unaffected labels are reused, while precise verification is performed on local labels that may cross collision boundaries, maintaining the accuracy and consistency of collision determination results while reducing redundant calculations.
[0080] The third level is the local incremental update level. When only a local change in interaction state or label size occurs in the current frame, such as a change in size due to the selection, hover state switching, or text content adjustment of a single label, a full recalculation is not required. Only the local area affected by the change is incrementally updated, while the label state and spatial index of the remaining areas remain unchanged. This level of update relies on a pre-stored conflict association table, which uses a bidirectional mapping structure to record the collision blocking relationships between labels: the forward table uses the hidden label identifier as the key and the set of one or more displayed label identifiers that caused the label to be hidden as the value; the reverse table uses the displayed label identifier as the key and the set of hidden labels blocked by it as the value. When a label is hidden due to collision, the corresponding relationship is added to both tables simultaneously. When a label is redisplayed, deleted, or its collision object changes, the old relationship is removed from both tables simultaneously. During a global recalculation, both tables are completely rebuilt. When implemented using a hash table, the expected complexity of key positioning is O(1), and the complexity of obtaining all associated objects is O(1+r), where r is the number of associated tags returned. The expected complexity of adding or deleting a single relationship is O(1). The bidirectional association design can quickly locate all objects that have collisional associations with the changed tags without having to traverse all tags, which is the core data foundation for implementing local incremental updates.
[0081] The specific execution process of local incremental updates follows a fixed link to ensure complete coverage of the affected area and accurate and consistent judgment results. First, the target label affected by the change is identified. Its old axis-aligned bounding box before the change and its new axis-aligned bounding box after the change are obtained. The union of the two bounding boxes is taken and expanded outwards at a preset safety distance to generate the final affected area. The purpose of this expansion is to cover the adjacent area that may be affected after the label change, avoiding omissions of collision states of surrounding labels due to changes in position or size, and ensuring the accuracy of incremental update judgments. Second, through the range retrieval interface of the spatial index instance, all currently displayed labels falling within the affected area are queried. Simultaneously, through the reverse mapping of the conflict association table, all labels that were previously hidden due to collisions with the target label are queried. This bidirectional query method covers both displayed labels that may collide with the new state label and labels that were blocked in the original state but may be unhidden after the change, ensuring that affected labels are fully included in the calculation scope and avoiding state omissions or errors. Third, the changed target label, displayed labels within the affected area, and associated hidden labels are integrated into an affected set. All tags outside the affected set retain their visibility and spatial index records unchanged, serving as a fixed background and requiring no recalculation, thus minimizing computational complexity. The fourth step involves deleting all old records of tags within the affected set from the spatial index instance, reordering the tags within the affected set according to global sorting rules, and sequentially performing spatial index retrieval and true overlap determination to obtain new visibility status. Subsequently, the records in the spatial index instance are updated based on the determination results, and the bidirectional mapping relationship in the conflict association table is updated synchronously to ensure that the state of the index and association table is consistent with the current display result.
[0082] To prevent local incremental updates from performing worse than global recalculation when the affected scope is too large, a triple rollback threshold is set. If any threshold condition is met, the local update process is immediately terminated, and a global recalculation is initiated. The first threshold is the number threshold: when the number of labels in the affected set satisfies |A|>max(A0,τ) N N v A rollback is triggered when A0 is the lower limit of the absolute number of local incremental update rollback thresholds, and τ is the value of A0. N N represents the threshold coefficient for the proportion of local incremental update rollbacks. v The first is the number of candidate views. The second is the area threshold, which is set when the ratio of the area of the affected region (area(R)) to the total canvas area (area(C)) satisfies area(R) / area(C)>τ. A The rollback is triggered at time, where τ A This is the threshold coefficient for the area proportion of local incremental update rollback. The third is the time consumption threshold; when the cumulative time of this local update exceeds B... ms A rollback is triggered at a certain time. In one exemplary implementation, A0=500, τN =0.20、τ A =0.25、B ms =6ms, and the above values can be configured according to the device and data scale. The three thresholds together constitute the safety boundary for incremental updates, ensuring that the optimal calculation path is always selected and maintaining stable rendering performance.
[0083] For performance-constrained environments such as low-end devices or mini-programs, this solution also provides a batch execution method with the same judgment logic as the above method, avoiding page lag caused by excessive single-frame computation. Let the single-frame computation time budget be B. ms The maximum number of candidate labels in a single batch is B. n Both are configurable parameters. In an exemplary implementation, B ms It can be configured within the range of 2 to 6 ms, B n The number of candidates can be configured within the range of 200 to 1000, with the actual optimal value determined based on the target frame rate, device level, and actual measurement time. Each batch continues processing on the same temporary space index, and the incremental values of the tags already confirmed for display in this batch are inserted into this temporary index, ensuring consistency between subsequent batches and previous batches. The processing order prioritizes interactive status tags and tags that were added to the database earlier; ordinary tags exceeding the budget are scheduled for subsequent frames. During batch calculations, the complete and stable results from the previous round continue to be displayed; after all batches are completed, the new display set and temporary index atomically replace the old results, thus avoiding tags popping up frame by frame or flickering. Interactive status tags can be updated first through a high-priority real-time channel to ensure the responsiveness of core interactions.
[0084] During the final rendering stage, the rendering engine only sends labels marked as visible to the drawing pipeline; hidden labels do not generate text drawing instructions. Labels completely outside the canvas are not submitted for drawing, while labels partially entering the canvas and passing collision detection are submitted with complete geometry, and the canvas clipping rectangle in the rasterization stage trims off pixels outside the canvas. While batch calculations are not yet complete, the rendering engine continues rendering the stable results from the previous round; once the results from the new round are all complete, a unified switch is made to ensure the continuity and stability of the visual experience.
[0085] The above steps construct a robust performance optimization system with complete gradients through a versioned event triggering mechanism, a three-level inter-frame reuse system, bidirectional conflict-related local incremental updates, triple threshold fallback fallback, and batch adaptation for low-end devices. From zero overhead for still frames to direct reuse of camera micro-displacements, to incremental updates for local changes, and finally to global recalculation as a fallback, different change scenarios are matched with corresponding granularity of computation links. Combined with batch execution of degradation adaptation, it can continuously maintain a smooth rendering frame rate and stable visual experience in all scenarios from high-end devices to low-end mini-programs, providing reliable performance assurance for the application of the entire adaptive culling method in various production environments.
[0086] Overall, this invention achieves a dual improvement in both the effectiveness and operational efficiency of visual text tag removal through the coordinated design of multiple technical aspects. In terms of display quality, a comprehensive weighting mechanism based on interaction status scoring and database entry order scoring enables differentiated management of tag display priority, ensuring that core tags with high interaction attention and high business value are always presented first, effectively improving the information delivery efficiency of visual content. In terms of operational performance, the wide-phase filtering capability of spatial indexing significantly reduces the computational load of collision detection, breaking through the performance bottleneck in scenarios with massive tags. The accompanying hierarchical collision judgment mechanism simultaneously considers the judgment accuracy of rotating tags and the overall computational overhead. In terms of dynamic adaptation, multi-level inter-frame reuse and local incremental update mechanisms significantly reduce the cost of repetitive calculations in dynamic interaction scenarios, maintaining a stable rendering frame rate during frequent translation and scaling operations.
[0087] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the above embodiments do not limit the present invention in any way, and all technical solutions obtained by equivalent substitution or equivalent transformation fall within the protection scope of the present invention.
Claims
1. A visual text adaptive removal method based on spatial indexing and data weighting, characterized in that, Includes the following steps: The overall weight is calculated based on the interaction status score and stable entry order score of the text tags to be displayed. The text tags to be displayed are sorted in descending order according to the overall weight, and when the overall weights are the same, they are sorted sequentially according to the preset decision key to obtain the global processing queue. The axis-aligned bounding box of the text label to be displayed in the screen space is calculated based on the current camera transformation matrix, and labels completely located outside the canvas are removed according to the preset canvas boundary to obtain the set to be detected. Create a spatial index instance to store the axis-aligned bounding boxes of labels that have been determined to be displayed, and provide a range retrieval interface based on the intersection of axis-aligned bounding boxes; Based on the order of the global processing queue, the current labels in the set to be detected are traversed sequentially, and the spatial index instances are retrieved with the axis-aligned bounding box of the current label to obtain the candidate label set; If the current label has a real overlap with any candidate label in the candidate label set, then the current label is marked as hidden; otherwise, it is marked as displayed, and its axis-aligned bounding box is inserted into the spatial index instance. After the traversal is complete, the labels marked for display are submitted to the drawing pipeline for rendering.
2. The visual text adaptive removal method based on spatial indexing and data weighting according to claim 1, characterized in that, The process of sorting the text labels to be displayed in descending order according to their comprehensive weights, and then sorting them sequentially according to a preset decision key when the comprehensive weights are the same, to obtain a global processing queue includes: Using the comprehensive weight as the primary sorting key, the text labels to be displayed are sorted in descending order; When the overall weights are the same, the relative order is determined sequentially according to the deciding key, including: The interaction state priority is used as the first deciding key, and the interaction state is determined according to the currently active type of the tag in a preset hierarchical order. Using the stable entry sequence number as the second deciding key, the items are sorted in ascending order according to the value of the stable entry sequence number; Using stable identifiers as the third deciding key, the stable identifiers are sorted in ascending order based on their lexicographical or numerical order.
3. The visual text adaptive removal method based on spatial indexing and data weighting according to claim 1, characterized in that, The step of calculating the axis-aligned bounding box of the text label to be displayed in screen space based on the current camera transformation matrix includes: Based on the current camera transformation matrix, the scene coordinates of the text label to be displayed are mapped to the screen space to obtain the anchor point coordinates of the text label to be displayed in the screen space; Based on the width, height, and preset anchor point normalized position of the text label to be displayed, determine the offset vectors of the four corner points of the text label to be displayed relative to the anchor point coordinates in the unrotated state; According to the rotation angle of the text label to be displayed, apply a rotation transformation to the offset vector to obtain the rotation offset of each corner point relative to the coordinates of the anchor point; The screen coordinates of the four corner points are obtained by superimposing the coordinates of the anchor points with the rotation offset of each corner point. The minimum and maximum values of the four screen coordinates in the x-axis direction of the screen space are respectively used as the minX and maxX of the axis-aligned bounding box, and the minimum and maximum values of the four screen coordinates in the y-axis direction are respectively used as the minY and maxY of the axis-aligned bounding box.
4. The visual text adaptive removal method based on spatial indexing and data weighting according to claim 1, characterized in that, The spatial index instance is implemented using a quadtree or an R-tree, and both the quadtree and the R-tree are accessed through a unified abstract adapter interface. The abstract adapter interface provides at least the functions of insertion, deletion, range retrieval, clearing, and batch loading.
5. The visual text adaptive removal method based on spatial indexing and data weighting according to claim 4, characterized in that, The quadtree is constructed and retrieved in the following way: Configure the maximum node capacity and maximum recursion depth, using the screen canvas coordinate range as the root node region; When inserting the axis-aligned bounding box, if the current node is not split, it is stored directly; if it is split, the axis-aligned bounding box to be inserted is pushed down to the child node into which it is completely inserted, and the bounding box that crosses the boundary of the child node is retained in the current node. When the number of axis-aligned bounding boxes stored in any node reaches the node capacity limit and the current depth is less than the maximum recursion depth, the node is divided into four child nodes. During retrieval, nodes that intersect with the axis-aligned bounding box of the current label are recursively visited, and the node and the axis-aligned bounding boxes stored in all intersecting subtrees are merged into a set of candidate labels.
6. The visual text adaptive removal method based on spatial indexing and data weighting according to claim 4, characterized in that, The R-tree is constructed and retrieved in the following way: The axis-aligned bounding box is inserted into the R-tree in the form of a minimum bounding rectangle, and each tree node stores the minimum bounding rectangle of all its entries; During insertion, starting from the root node, select the child node that minimizes the expansion of the node's spatial range as the insertion path, and continue until the leaf node, updating the minimum bounding rectangle of each node along the path. During retrieval, the process recursively checks the root node: if the minimum bounding rectangle of the current node does not intersect with the axis-aligned bounding box of the current label, the node and its subtree are skipped; otherwise, its child nodes are recursively visited until a leaf node returns the stored axis-aligned bounding box as a set of candidate labels.
7. The visual text adaptive removal method based on spatial indexing and data weighting according to claim 1, characterized in that, The determination of true overlap specifically includes: If neither the current label nor the candidate label has been rotated, then the first projection interval of the two labels in the x-axis direction and the second projection interval in the y-axis direction of the screen space are obtained respectively; when the projection intervals of the two labels in the x-axis direction and the y-axis direction have a positive length intersection, it is determined that there is a real overlap. If the current label or the candidate label is rotated, its geometric range is represented by its respective directed bounding box, and a determination is made based on the separating axis theorem: the normal vectors of each side direction of the two directed bounding boxes are obtained, and after deduplication and merging, a candidate separating axis set is formed; for each separating axis in the candidate separating axis set, all vertices of the two directed bounding boxes are projected onto the axis to obtain two projection intervals; when the two projection intervals on all candidate separating axes have a positive length intersection, it is determined that there is a true overlap.
8. The visual text adaptive removal method based on spatial indexing and data weighting according to claim 1, characterized in that, After the traversal is completed and the labels marked for display are submitted to the drawing pipeline, an inter-frame multiplexing step is also included: If the current frame does not have any changes in data source, label style, interaction state, camera transformation, or canvas size compared to the previous frame, the display result and spatial index instance of the previous frame are directly reused, and the entire collision detection process is skipped. If the current frame only undergoes a camera transformation relative to the previous frame, the global processing queue is reused to re-execute axis-aligned bounding box calculation, canvas boundary culling, spatial index retrieval, and true overlap determination. If the interaction state or label size changes relative to the previous frame, a local incremental update is performed.
9. The visual text adaptive removal method based on spatial indexing and data weighting according to claim 8, characterized in that, The local incremental update includes: Identify the target label affected by the change, obtain the old axis-aligned bounding box and the new axis-aligned bounding box of the target label, and expand the union of the two to generate the affected region; The currently displayed tags that fall into the affected area are queried through the spatial index instance, and the tags that are hidden due to collision with the target tag are obtained through the pre-stored conflict association table; The target label, the currently displayed label, and the hidden label are combined into an affected set; Delete the old records of the affected set in the spatial index instance, re-sort and determine the true overlap of the affected set, and update the spatial index instance and the conflict association table according to the determination result.
10. The visual text adaptive removal method based on spatial indexing and data weighting according to claim 9, characterized in that, When performing the local incremental update, if the number of tags in the affected set exceeds a preset number threshold, or the ratio of the affected area to the total canvas area exceeds a preset area threshold, or the cumulative time of this local update exceeds a preset time threshold, the process will revert to global recalculation.
