A pipeline loop-aware linearization decomposition method for Cocos engine
By generating directed graphs through DFS with cycle detection and directional pre-constraints, and combining excess degree and greedy strategy to select the starting point, the problem of directional conflicts in rendering complex topological graphs in the Cocos engine is solved, achieving efficient and accurate linear decomposition.
Patent Information
- Application Number
- CN202511881918.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-15
- Publication Date
- 2026-03-06
- Estimated Expiration
- 2045-12-15
AI Technical Summary
Existing technologies cannot effectively handle the ring structure in complex topology graphs, resulting in direction conflicts and data redundancy during rendering in the Cocos engine, and failing to generate a single continuous path that meets the engine's requirements.
A directed graph is generated by loop detection and directional pre-constraint, and depth-first search (DFS). The starting point is selected by combining excess degree and greedy strategy to construct a linear chain, ensuring that each edge has a unique direction.
It achieves lossless conversion of complex topological graphs into a linear drawing instruction sequence acceptable to the Cocos engine, ensuring 100% correctness of the decomposition results and optimizing rendering performance.
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer graphics processing and industrial software technology, specifically, a pipeline loop-aware linearization decomposition method for the Cocos engine. Background Technology
[0002] In the digitalization process of industrial design, architectural engineering, and energy pipeline networks, it is often necessary to visualize and render topological graphs reflecting physical connections using graphics engines such as Cocos. The Graphics components of these engines (such as Cocos Creator) mandate the use of strict unidirectional linear sequences of commands like moveTo and lineTo to describe graphical paths. However, topological graphs are essentially mesh structures describing the connections between points, and often contain closed loop paths. This inherently conflicts with the linear instruction chains required by the engines, specifically manifested as follows:
[0003] 1. Conflict between circular structures and linear instructions:
[0004] A topological loop is essentially a closed-loop mesh structure, where any node can serve as a starting point. However, the moveTo instruction must specify a unique absolute starting point, and the linear instruction chain requires a strict unidirectional order. The endpoint cannot jump backward to close the path, causing the loop structure to be unable to be correctly described by a single graphical element.
[0005] 2. Conflict between relation descriptions and entity elements:
[0006] The essence of a topology graph is to describe connectivity (such as "point A connects to point B"), but engines like Cocos force each connectivity to be converted into an independent entity line segment element. This "block-style" architecture leads to data redundancy and makes it difficult to maintain a complete topological semantics.
[0007] 3. The complexity of global sorting:
[0008] For a given undirected topological graph, there is no obvious method to directly generate a global linear sequence that satisfies the strict order requirement of a single-line graph. The algorithm faces extremely high computational complexity and uncertainty.
[0009] 4. The fundamental limitations of existing decomposition methods in handling ring structures:
[0010] Traditional graph traversal algorithms such as Depth-First Search (DFS) inherently exhibit randomness in their traversal direction when dealing with undirected graphs. When encountering cycles, this randomness leads to conflicts and ambiguities in path selection, especially when handling complex cycles with multiple nesting or intersections. This almost inevitably results in decomposition failures or the generation of incorrect paths, failing to produce a single, continuous, closed path that meets the requirements of a graphics engine.
[0011] Currently, existing technical solutions have fundamental limitations and defects in addressing the specific problem of converting AI-identified pipeline topology diagrams in industrial scenarios into linear instruction chains that can be rendered by graphics engines such as Cocos. These limitations mainly include the following aspects:
[0012] 1. Structural mismatch in general graph traversal algorithms:
[0013] The industry typically uses general graph theory algorithms, such as depth-first search (DFS) or breadth-first search (BFS), to traverse graphs and generate paths. However, these general algorithms were not originally designed to solve the specific constraint of "generating a linear, branchless chain of instructions".
[0014] Defect 1: Randomness of Direction and Instruction Conflicts: When DFS / BFS traverses a cycle structure in an undirected graph, the choice of the starting point and direction is random. This leads to inconsistent path directions. When multiple cycles are nested or connected, it is very easy to generate direction conflicts that cannot be closed. The resulting instruction chain cannot be correctly drawn into a closed cycle structure in the graphics engine.
[0015] Defect 2: Inability to handle the coexistence of branches and loops: General algorithms struggle to properly handle both branch points and loop structures within a linear instruction chain. The algorithms typically generate numerous broken, isolated line segments or redundant instructions containing repetitive points, failing to meet the efficient rendering requirements of a "single continuous path."
[0016] 2. Limitations of traditional CAD or graphics software conversion methods:
[0017] Some traditional computer-aided design (CAD) software or graphics tools have the ability to export graphics as vector data (such as SVG), but their conversion logic is different from the requirements of the Cocos engine.
[0018] Defect 3: Information Loss and Semantic Gap: The conversion purpose of such tools is mostly for visual presentation. Their export path is usually a canvas path based on Bézier curves, rather than a semantic instruction chain built from the original topological points and line relationships. The conversion process loses key topological information such as nodes and connection relationships, making it impossible to associate and interact with the backend business logic (such as pipe segment attributes and node types).
[0019] Defect 4: Format incompatibility: Its output format (such as Path in SVG) is not directly compatible with the explicit moveTo and lineTo instruction sequences required by the Cocos Graphics module, requiring secondary parsing and conversion, which increases the complexity of the process and the probability of errors.
[0020] 3. Lack of dedicated solutions for industrial-grade complexity:
[0021] Existing sporadic research or methods mostly focus on simple graph structures, lacking consideration for the high-complexity, large-scale topology graphs commonly found in pipeline systems.
[0022] Defect 5: High computational complexity and prominent performance bottleneck: When faced with complex pipeline topologies containing a large number of nodes and nested loops, unoptimized algorithms (such as pure backtracking algorithms) will suffer from combinatorial explosion, and the computational time complexity will deteriorate to O(n²) or even higher, which cannot meet the application requirements of real-time or near real-time applications.
[0023] Defect 6: Lack of deterministic processing capability for complex structures and poor robustness: Existing general methods cannot guarantee 100% successful transformation of arbitrary topologies when dealing with common industrial structures such as complex cross loops and high-density branch nodes due to their inherent randomness and path selection ambiguity. The algorithms are prone to getting stuck in infinite loops or failing to decompose due to directional conflicts, lacking the robustness required for industrial applications. Summary of the Invention
[0024] The purpose of this invention is to provide a pipeline loop-aware linearization decomposition method for the Cocos engine, aiming to solve the problem of complex topological graphs containing high-density nested loops that cannot be effectively handled by existing technologies. The goal is to completely and accurately decompose such structures into a sequence of linear drawing instructions acceptable to the Cocos engine, ensuring lossless transformation of the original topological information.
[0025] This invention is achieved through the following technical solution: a pipeline loop-aware linearization decomposition method for the Cocos engine, comprising the following specific steps:
[0026] 1) Ring detection and analysis: After inputting undirected topology graph data, the ring detection algorithm is called to identify and record all independent ring structures in the undirected topology graph and the nodes and edges contained in the independent ring structure;
[0027] 2) Cycle Existence Detection: Determine if at least one cycle was detected in step 1). If a cycle exists, proceed to step 3. If no cycle exists (i.e., the input is an acyclic graph, such as a tree structure), skip step 3 and proceed directly to step 4.
[0028] 3) Loop direction pre-constraint: For each detected loop, a definite traversal direction is specified based on the pre-defined loop direction rule; this direction rule will serve as the highest priority basis for processing the edges of these loops in subsequent steps.
[0029] 4) Perform direction-aware depth-first search (DFS): Start from any node and perform a depth-first search traversal of the undirected topology graph data; during the traversal, assign a direction to each edge of the undirected topology graph data;
[0030] 5) Generate the final directed graph: Integrate the traversal results from step 4) to generate a complete directed graph model in which all edges are assigned a unique and conflict-free direction;
[0031] 6) Calculate the excess out-degree of nodes and establish a candidate set of starting points: Traverse all nodes in the directed graph model, calculate the "excess out-degree" of each node, and add all nodes with an excess out-degree greater than 0, as well as all nodes with a degree of 1 (i.e., endpoints) in the directed graph model into a set to generate a candidate set of starting points.
[0032] 7) Selecting the optimal starting point based on a greedy strategy: Using a greedy strategy, select the node with the maximum current "excess degree" from the candidate starting point set as the new chain starting point;
[0033] 8) Constructing chains and dynamically updating the graph: Starting from the starting point selected in step 7), strictly traverse along the edge directions in the directed graph model, adding the visited nodes and edges to a new chain in turn to form a linear chain; and each time an edge is traversed, remove the linear chain from the directed graph model (or mark it as "processed"), and synchronously update the out-degree and in-degree of the nodes involved in the directed graph model.
[0034] 9) Loop and Termination: Check if there are any unprocessed edges in the directed graph model. If so, return to step 7). In the updated directed graph model, continue to select the node with the next maximum "excess degree" as the starting point of the new chain, construct the next linear chain, until the entire directed graph model is traversed, and form a set of all removed linear chains.
[0035] 10) Formatted output: Converts the set of linear chains to the specified format and outputs it.
[0036] To further improve the implementation of the pipeline loop-aware linearization decomposition method for the Cocos engine described in this invention, the following configuration is adopted: the undirected topology graph data is a topology graph describing the nodes and connection relationships of the pipeline.
[0037] To further improve the implementation of the pipeline loop-aware linearization decomposition method for the Cocos engine described in this invention, the following configuration is adopted: the loop detection algorithm is based on depth-first search or disjoint-set data structure.
[0038] To further improve the implementation of the pipeline loop-aware linearization decomposition method for the Cocos engine described in this invention, the following settings are specifically adopted: the loop direction rules include specifying that the outermost loop is traversed in a counterclockwise direction and the inner loop is traversed in a clockwise direction, or specifying that the outermost loop is traversed in a clockwise direction and the inner loop is traversed in a counterclockwise direction, or all loops are traversed in a clockwise direction, or all loops are traversed in a counterclockwise direction.
[0039] To further improve the implementation of the pipeline loop-aware linearization decomposition method for the Cocos engine described in this invention, the following settings are specifically adopted: During the traversal process, each edge of the undirected topology graph data is assigned a direction, specifically as follows:
[0040] For edges on a cycle: if the edge being traversed belongs to a cycle that has been constrained in step 3), then the edge direction is forced to be assigned according to the traversal direction preset for that cycle, ignoring the traversal order of the depth-first search (DFS) itself.
[0041] For non-cyclic edges: If the edge being traversed does not belong to any cycle, then it is assigned a direction according to the actual traversal order of the current depth-first search (DFS) traversal.
[0042] To further improve the implementation of the pipeline loop-aware linearization decomposition method for the Cocos engine described in this invention, the following setting is adopted: the "excess out-degree" is the out-degree minus the in-degree of the node.
[0043] To further improve the implementation of the pipeline loop-aware linearization decomposition method for the Cocos engine described in this invention, the following setting is adopted: In step 7), when selecting the node with the current maximum "excess out-degree" as the new chain starting point, if there are multiple nodes with the same maximum "excess out-degree", then any one of them can be selected.
[0044] To further improve the implementation of the pipeline loop-aware linearization decomposition method for the Cocos engine described in this invention, the following setting is adopted: the specified format is a JSON instruction set that meets the requirements of the Cocos engine Graphics component.
[0045] The ring-aware linear decomposition method described in this invention successfully solves the industry problem of losslessly converting complex topological graphs containing arbitrary ring and network structures into linear rendering instructions through a series of closely linked steps, including "ring direction pre-constraint, direction-aware DFS, determining the starting point of excess out-degree, and building long chains with a greedy strategy".
[0046] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0047] This invention provides a dedicated decomposition method that can deeply understand the rendering characteristics of the Cocos engine and effectively solve the direction conflict problem of complex ring structures through a deterministic mechanism, thereby achieving efficient and reliable conversion.
[0048] This invention fundamentally eliminates the randomness and directional conflicts in loop processing by using "loop direction pre-constraints," ensuring 100% accuracy of the decomposition results.
[0049] This invention scientifically selects the starting point through "excess output" and "greedy strategy," significantly reducing chain fragmentation and optimizing the final rendering performance.
[0050] This invention does not rely on a specific graph layout and can provide deterministic and reproducible decomposition results for arbitrarily complex topologies, demonstrating strong industrial application value and exhibiting robustness and versatility.
[0051] This invention fundamentally solves the problem of decomposing complex ring structures, ensuring the absolute correctness of the results. Addressing the inevitable direction conflicts that arise in existing technologies when dealing with ring structures, it proposes a core "ring direction pre-constraint" mechanism. By detecting and unifying the traversal directions of all rings before decomposition, uncertain undirected rings are transformed into definite directed paths. This eliminates the risk of path conflicts and self-intersections at the source, ensuring that for any complex ring or network topology, the decomposition result is unique, correct, and conflict-free.
[0052] This invention significantly optimizes the decomposition results and improves engine rendering performance: by combining "calculating excess out-degree" and "greedy strategy for selecting the starting point," the optimal starting point for chain decomposition is scientifically determined. This strategy prioritizes building long chains starting from the node with the strongest "outflow demand," effectively avoiding the large number of short chain fragments generated by the blind selection of the starting point in traditional methods. The final output instruction set chain has fewer chains and a longer average length, directly corresponding to fewer draw calls in the graphics engine, thereby significantly reducing CPU overhead and improving the rendering frame rate and smoothness of large-scale pipeline scenes.
[0053] This invention achieves deterministic processing of arbitrary topologies with strong system robustness: It provides a complete deterministic processing flow from input to output. Since each step (loop detection, direction constraint, starting point selection, path construction) follows explicit rules rather than random traversal, this method does not depend on a specific graph layout or node order. Regardless of the irregularity or high density of the complex topology, this invention guarantees stable and reproducible correct results, demonstrating the strong robustness necessary for industrial applications.
[0054] This invention, through its innovative "ring-aware decomposition method," particularly the key steps of "ring direction pre-constraint" and "greedy starting point selection based on excess out-degree," successfully overcomes the fundamental defects of existing technologies in handling complex ring topologies, providing a correct, efficient, and reliable pipeline linearization solution and offering crucial underlying technical support for industrial visualization applications based on the Cocos engine. Detailed Implementation
[0055] The present invention will be further described in detail below with reference to embodiments, but the implementation of the present invention is not limited thereto.
[0056] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. Therefore, the following detailed description of the embodiments of the present invention is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0057] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0058] Example 1:
[0059] This invention designs a pipeline loop-aware linearization decomposition method for the Cocos engine, aiming to solve the problem of complex topological graphs containing high-density nested loops that existing technologies cannot effectively handle. The goal is to completely and accurately decompose such structures into a sequence of linear drawing instructions acceptable to the Cocos engine, ensuring lossless transformation of the original topological information, including the following specific steps:
[0060] 1) Ring detection and analysis: After inputting undirected topology graph data, the ring detection algorithm is called to identify and record all independent ring structures in the undirected topology graph and the nodes and edges contained in the independent ring structure. This step is the foundation of the "ring sensing" method. By systematically identifying all ring structures in the graph, it provides a clear processing object for the subsequent directional pre-constraint steps.
[0061] 2) Cycle Existence Detection: Determine whether at least one cycle was detected in step 1). If a cycle exists, continue to step 3. If no cycle exists (i.e., the input is an acyclic graph, such as a tree structure), skip step 3 and proceed directly to step 4. This determination step ensures the universality of the algorithm (cycle-aware linearization decomposition method). For acyclic graphs, unnecessary cycle processing can be skipped, and the subsequent graph traversal can proceed directly, improving processing efficiency.
[0062] 3) Loop Direction Pre-Constraint: For each detected loop, a definite traversal direction is assigned based on pre-defined loop direction rules; this direction rule will serve as the highest priority criterion for processing the edges of these loops in subsequent steps. This step is the core innovation in solving the problem of decomposing complex loop structures. By unifying the direction of all loop paths before decomposition, uncertain undirected loops are transformed into definite directed paths, fundamentally eliminating potential direction conflicts and self-intersection errors that may occur during subsequent path construction.
[0063] 4) Perform direction-aware depth-first search (DFS): Start from any node and perform a depth-first search traversal of the undirected topology graph data; during the traversal, assign a direction to each edge of the undirected topology graph data;
[0064] This step transforms the undirected topological graph into a "hybrid directed graph" through a unified traversal process. The direction of edges on cycles is rigidly determined by predefined rules, while the direction of edges on non-cycles is dynamically determined by the Depth-First Search (DFS) traversal, laying the foundation for the next step of generating a complete, conflict-free directed graph model.
[0065] 5) Generate the final directed graph: Integrate the traversal results of step 4) to generate a complete directed graph model in which all edges are assigned a unique and conflict-free direction; this step marks the completion of the transformation from undirected topological relations to a deterministic flow model (directed graph model), and all subsequent decomposition operations will be based on this directed graph.
[0066] 6) Calculate the excess out-degree of nodes and establish a candidate set of starting points: Traverse all nodes in the directed graph model, calculate the "excess out-degree" of each node, and add all nodes with an excess out-degree greater than 0, along with all nodes with a degree of 1 (i.e., endpoints) in the directed graph model, to a set to generate a candidate set of starting points. This step scientifically identifies all nodes that can logically serve as the starting point of a chain using graph theory principles. Nodes with an excess out-degree greater than 0 are the source of the "flow," while endpoints are natural starting points of paths. This method is more reasonable and efficient than simply selecting arbitrary nodes as starting points.
[0067] 7) Selecting the optimal starting point based on a greedy strategy: A greedy strategy is adopted to select the node with the maximum current "excess out-degree" from the candidate starting point set as the new chain starting point; this step is a key optimization to improve the decomposition quality. By greedily selecting the node that "most needs to flow out" as the starting point, the main path and long path can be constructed and decomposed first, thereby effectively reducing the number of chain fragments generated in the end and optimizing rendering performance.
[0068] 8) Constructing Chains and Dynamically Updating the Graph: Starting from the selected starting point in step 7), strictly traverse along the edge directions in the directed graph model, adding the visited nodes and edges to a new chain in turn, forming a linear chain; and after each edge is traversed, remove the linear chain from the directed graph model (or mark it as "processed"), and synchronously update the out-degree and in-degree of the nodes involved in the directed graph model; this step is the actual chain generation process. By dynamically updating the state of the graph (directed graph model) during the construction process (removing edges, updating degrees), it is ensured that the subsequent starting point selection (step 7) and loop termination judgment (step 9) are always based on the latest graph state, guaranteeing the correctness of the algorithm (loop-aware linearization decomposition method).
[0069] 9) Loop and Termination: Check if there are any unprocessed edges in the directed graph model. If so, return to step 7). In the updated directed graph model, continue to select the node with the next maximum "excess degree" as the starting point of the new chain, construct the next linear chain, until the entire directed graph model has been traversed, and form a set of all removed linear chains. This step is the main loop control logic of the algorithm (loop-aware linearization decomposition method). It ensures that every edge in the graph (directed graph model) is assigned to one and only one chain, thereby guaranteeing the integrity and completeness of the topological decomposition.
[0070] 10) Formatted Output: Converts the set of linear chains into the specified format and outputs it. This step is the final delivery stage of the algorithm (ring-aware linearization decomposition method), and its output can be directly used by downstream graphics rendering engines.
[0071] The ring-aware linear decomposition method described in this invention successfully solves the industry challenge of losslessly converting complex topologies containing arbitrary rings and networks into linear rendering instructions through a series of steps, including "ring direction pre-constraint, DFS generation of directed graphs, determining the starting point based on excess out-degree, and constructing long chains using a greedy strategy." Its advantages lie in its clear direction and correct results: "ring direction pre-constraint" fundamentally eliminates the randomness and directional conflicts in ring processing, ensuring 100% accuracy of the decomposition results. The scientific selection of the starting point through "excess out-degree" and the "greedy strategy" significantly reduces chain fragmentation and optimizes the final rendering performance. It does not rely on a specific graph layout and can provide deterministic and reproducible decomposition results for arbitrarily complex topologies, demonstrating strong industrial application value and exhibiting robustness and versatility.
[0072] Example 2:
[0073] This embodiment is a further optimization based on the above embodiment. The parts that are the same as those in the foregoing technical solutions will not be repeated here. In order to better realize the pipeline loop-aware linearization decomposition method for Cocos engine described in this invention, the following setting is adopted: the undirected topology graph data is a topology graph describing the nodes and connection relationships of the pipeline.
[0074] Example 3:
[0075] This embodiment is a further optimization based on any of the above embodiments. The parts that are the same as those in the foregoing technical solutions will not be repeated here. In order to better realize the pipeline loop-aware linearization decomposition method for Cocos engine described in this invention, the following setting is adopted: the loop detection algorithm is a method based on depth-first search or disjoint-set data structure.
[0076] Example 4:
[0077] This embodiment is a further optimization based on any of the above embodiments. The parts that are the same as those in the aforementioned technical solutions will not be repeated here. In order to better realize the pipeline loop-aware linearization decomposition method for Cocos engine described in this invention, the following settings are specifically adopted: the loop direction rules include specifying that the outermost loop is traversed in a counterclockwise direction and the inner loop is traversed in a clockwise direction, or specifying that the outermost loop is traversed in a clockwise direction and the inner loop is traversed in a counterclockwise direction, or all loops are traversed in a clockwise direction, or all loops are traversed in a counterclockwise direction.
[0078] Example 5:
[0079] This embodiment is a further optimization based on any of the above embodiments. The parts identical to the aforementioned technical solutions will not be repeated here. Furthermore, to better implement the pipeline loop-aware linearization decomposition method for the Cocos engine described in this invention, the following setting is specifically adopted: During the traversal process, each edge of the undirected topology graph data is assigned a direction, specifically as follows:
[0080] For edges on a cycle: if the edge being traversed belongs to a cycle that has been constrained in step 3), then the edge direction is forced to be assigned according to the traversal direction preset for that cycle, ignoring the traversal order of the depth-first search (DFS) itself.
[0081] For non-cyclic edges: If the edge being traversed does not belong to any cycle, then it is assigned a direction according to the actual traversal order of the current depth-first search (DFS) traversal.
[0082] Example 6:
[0083] This embodiment is a further optimization based on any of the above embodiments. The parts that are the same as those in the aforementioned technical solutions will not be repeated here. In order to better realize the pipeline loop-aware linearization decomposition method for Cocos engine described in this invention, the following setting is adopted: the "excess out-degree" is the out-degree of the node minus the in-degree.
[0084] Example 7:
[0085] This embodiment is a further optimization based on any of the above embodiments. The parts that are the same as those in the aforementioned technical solutions will not be repeated here. In order to better realize the pipeline loop-aware linearization decomposition method for Cocos engine described in this invention, the following setting is adopted: In step 7), when selecting the node with the current maximum "excess out-degree" as the new chain starting point, if there are multiple nodes with the same maximum "excess out-degree", then any one of them can be selected.
[0086] Example 8:
[0087] This embodiment is a further optimization based on any of the above embodiments. The parts that are the same as those in the foregoing technical solutions will not be repeated here. In order to better realize the pipeline loop-aware linearization decomposition method for Cocos engine described in this invention, the following setting is adopted: the specified format is a JSON instruction set that meets the requirements of the Cocos engine Graphics component.
[0088] Example 9:
[0089] A pipeline loop-aware linearization decomposition method for the Cocos engine aims to solve complex topological graphs containing high-density nested loops, which cannot be effectively handled by existing technologies. The goal is to completely and accurately decompose such structures into a sequence of linear drawing instructions acceptable to the Cocos engine, ensuring lossless transformation of the original topological information. The method includes the following specific steps:
[0090] 1) Ring Detection and Analysis: After inputting undirected topology graph data (a topology graph describing the nodes and connections of pipelines), a ring detection algorithm (e.g., a method based on depth-first search or disjoint-set data structure) is called to identify and record all independent ring structures in the undirected topology graph and the nodes and edges contained in each independent ring structure. This step is the foundation of the "ring sensing" method. By systematically identifying all ring structures in the graph, it provides a clear processing object for the subsequent directional pre-constraint steps.
[0091] 2) Cycle Existence Detection: Determine whether at least one cycle was detected in step 1). If a cycle exists, continue to step 3. If no cycle exists (i.e., the input is an acyclic graph, such as a tree structure), skip step 3 and proceed directly to step 4. This determination step ensures the universality of the algorithm (cycle-aware linearization decomposition method). For acyclic graphs, unnecessary cycle processing can be skipped, and the subsequent graph traversal can proceed directly, improving processing efficiency.
[0092] 3) Loop Direction Pre-Constraint: For each detected loop, a definite traversal direction is assigned based on pre-defined loop direction rules (e.g., specifying that the outermost loop is traversed counterclockwise and the inner loops clockwise, or specifying that the outermost loop is traversed clockwise and the inner loops counterclockwise, or all loops are traversed clockwise, or all loops are traversed counterclockwise, or different directions are set according to the relationship between inner and outer layers). This direction rule will serve as the highest priority basis for processing the edges of these loops in subsequent steps. This step is the core innovation in solving the problem of decomposing complex loop structures. By unifying the direction of all loop paths before decomposition, uncertain undirected loops are transformed into definite directed paths, fundamentally eliminating possible direction conflicts and self-intersection errors during subsequent path construction.
[0093] 4) Perform direction-aware depth-first search (DFS): Starting from any node, perform a depth-first search traversal of the undirected topological graph data; during the traversal, assign a direction to each edge of the undirected topological graph data:
[0094] For edges on a cycle: if the edge being traversed belongs to a cycle that has been constrained in step 3), then the edge direction is forced to be assigned according to the traversal direction preset for that cycle, ignoring the traversal order of DFS itself;
[0095] For non-cyclic edges: if the edge being traversed does not belong to any cycle, then assign it a direction according to the actual traversal order of this DFS;
[0096] This step transforms the undirected topological graph into a "hybrid directed graph" through a unified traversal process. The direction of edges on cycles is rigidly determined by predefined rules, while the direction of edges on non-cycles is dynamically determined by the Depth-First Search (DFS) traversal, laying the foundation for the next step of generating a complete, conflict-free directed graph model.
[0097] 5) Generate the final directed graph: Integrate the traversal results of step 4) to generate a complete directed graph model in which all edges are assigned a unique and conflict-free direction; this step marks the completion of the transformation from undirected topological relations to a deterministic flow model (directed graph model), and all subsequent decomposition operations will be based on this directed graph.
[0098] 6) Calculate the excess out-degree of nodes and establish a candidate set of starting points: Traverse all nodes in the directed graph model and calculate the "excess out-degree" of each node (defined as: the out-degree of the node minus the in-degree). Add all nodes with an excess out-degree greater than 0, as well as all nodes with a degree of 1 in the directed graph model (i.e., endpoints), to a set to generate a candidate set of starting points. This step scientifically identifies all nodes that can logically serve as the starting point of a chain using graph theory principles. Nodes with an excess out-degree greater than 0 are the source of the "flow," while endpoints are natural starting points of paths. This method is more reasonable and efficient than simply selecting arbitrary nodes as starting points.
[0099] 7) Selecting the optimal starting point using a greedy strategy: A greedy strategy is adopted to select the node with the maximum current "excess out-degree" from the candidate starting point set as the new chain starting point; if multiple nodes with the same maximum "excess out-degree" exist, any one can be selected; this step is a key optimization to improve the decomposition quality. By greedily selecting the node that "most needs to flow out" as the starting point, the main path and long paths can be constructed and decomposed first, thereby effectively reducing the number of chain fragments generated in the end and optimizing rendering performance.
[0100] 8) Constructing Chains and Dynamically Updating the Graph: Starting from the selected starting point in step 7), strictly traverse along the edge directions in the directed graph model, adding the visited nodes and edges to a new chain in turn, forming a linear chain; and after each edge is traversed, remove the linear chain from the directed graph model (or mark it as "processed"), and synchronously update the out-degree and in-degree of the nodes involved in the directed graph model; this step is the actual chain generation process. By dynamically updating the state of the graph (directed graph model) during the construction process (removing edges, updating degrees), it is ensured that the subsequent starting point selection (step 7) and loop termination judgment (step 9) are always based on the latest graph state, guaranteeing the correctness of the algorithm (loop-aware linearization decomposition method).
[0101] 9) Loop and Termination: Check if there are any unprocessed edges in the directed graph model. If so, return to step 7). In the updated directed graph model, continue to select the node with the next maximum "excess degree" as the starting point of the new chain, construct the next linear chain, until the entire directed graph model has been traversed, and form a set of all removed linear chains. This step is the main loop control logic of the algorithm (loop-aware linearization decomposition method). It ensures that every edge in the graph (directed graph model) is assigned to one and only one chain, thereby guaranteeing the integrity and completeness of the topological decomposition.
[0102] 10) Formatted Output: Convert the set of linear chains into a specified format (e.g., a JSON instruction set that meets the requirements of the Cocos Engine Graphics component) and output it. This step is the final delivery stage of the algorithm (ring-aware linearization decomposition method), and its output can be directly used by downstream graphics rendering engines.
[0103] The ring-aware linear decomposition method described in this invention successfully solves the industry challenge of losslessly converting complex topologies containing arbitrary rings and networks into linear rendering instructions through a series of steps, including "ring direction pre-constraint, DFS generation of directed graphs, determining the starting point based on excess out-degree, and constructing long chains using a greedy strategy." Its advantages lie in its clear direction and correct results: "ring direction pre-constraint" fundamentally eliminates the randomness and directional conflicts in ring processing, ensuring 100% accuracy of the decomposition results. The scientific selection of the starting point through "excess out-degree" and the "greedy strategy" significantly reduces chain fragmentation and optimizes the final rendering performance. It does not rely on a specific graph layout and can provide deterministic and reproducible decomposition results for arbitrarily complex topologies, demonstrating strong industrial application value and exhibiting robustness and versatility.
[0104] The key to resolving directional conflicts in this invention is a unified pre-constraint strategy for the cyclic direction.
[0105] Before the formal decomposition, a cycle detection algorithm is used to identify all independent cycle structures in the graph, and a definite traversal direction is predefined for each cycle (such as a uniform clockwise or counterclockwise direction). This "pre-constraint" operation transforms undirected cycles into directed paths, fundamentally eliminating path conflicts and self-intersection problems caused by uncertain directions during subsequent traversal. This is the core prerequisite for ensuring 100% accuracy of the decomposition results.
[0106] The key to optimizing decomposition efficiency and quality in this invention is the greedy starting point selection method based on "excess output degree".
[0107] After generating a preliminary directed graph using Depth-First Search (DFS) and cycle constraints, this invention scientifically quantifies the priority of each node as a starting point by calculating its "excess out-degree" (out-degree minus in-degree). Combined with a greedy strategy, the chain is always constructed starting from the node with the largest current excess out-degree. This method ensures that decomposition prioritizes nodes with the most branches or the strongest outflow demand, thereby maximizing the generation of long chains and reducing chain fragmentation, which is key to improving final rendering performance.
[0108] In the field of industrial design and drafting software: it is applied to the automatic generation and rendering of pipelines (such as pressure pipelines and HVAC systems) and process flow diagrams. The system receives topology diagram information generated by image recognition or CAD software, and efficiently and accurately decomposes it into a sequence of single-line diagram instructions that can be rendered by graphics engines such as Cocos through the method provided by this invention, realizing the visualization, interaction and editing of drawings.
[0109] In the field of Building Information Modeling (BIM): This invention is used to process network structures such as pipelines and electrical wiring in building floor plans. It converts complex building network topologies into standard linear graphical elements, facilitating integrated display and conflict analysis in BIM software.
[0110] In the field of energy and power grid management: This invention is applied to the visualization of pipeline or power grid topology diagrams in industries such as oil, natural gas, and electricity. It can handle complex networks containing numerous ring and branch structures, converting them into graphical data that can be efficiently rendered using the Cocos engine on web or mobile devices, supporting real-time monitoring and scheduling.
[0111] In gaming and simulation: This invention is used to construct complex network structures such as pipes, roads, and lines in game or simulation systems. The method provided by this invention ensures that the visual rendering of these structures fully complies with the engine's graphics component specifications, improving development efficiency and rendering accuracy.
[0112] The present invention aims to resolve the inherent contradiction between the topology graph data structure and the linear rendering instructions of the graphics engine, and to provide a universal, efficient and accurate data conversion bridge for the above-mentioned fields.
[0113] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Any simple modifications or equivalent changes made to the above embodiments based on the technical essence of the present invention shall fall within the protection scope of the present invention.
Claims
1. A pipeline loop-aware linearization decomposition method for Cocos engine, characterized in that: The method comprises the following specific steps: 1) after inputting the undirected topological graph data, calling a loop detection algorithm to identify and record all independent loop structures in the undirected topological graph and the nodes and edges contained in the independent loop structures; 2) judging whether at least one loop is detected in step 1), if a loop exists, continuing to execute step 3), if no loop exists, skipping step 3) and directly executing step 4); 3) for each loop detected, assigning a certain traversal direction according to a pre-existing loop direction rule; 4) starting from an arbitrary node, performing a depth-first search traversal on the undirected topological graph data; in the traversal process, assigning a direction to each edge of the undirected topological graph data, specifically: for the edges on the loop: if the current traversed edge belongs to a loop that has been constrained in step 3), forcibly assigning a direction to the edge according to the preset traversal direction of the loop, ignoring the traversal order of the depth-first search traversal itself; for the edges that are not on the loop: if the current traversed edge does not belong to any loop, assigning a direction to it according to the actual traversal order of the current depth-first search traversal; 5) integrating the traversal results of step 4) to generate a complete directed graph model in which all edges are assigned a unique and non-conflicting direction; 6) traversing all nodes in the directed graph model, calculating the "excess out-degree" of each node, and adding all nodes with "excess out-degree" greater than 0 and all nodes with degree 1 in the directed graph model into a set to generate a starting point candidate set; the "excess out-degree" is the out-degree minus the in-degree of the node; 7) selecting the node with the maximum "excess out-degree" from the starting point candidate set as the new chain starting point using a greedy strategy; 8) constructing a chain and dynamically updating the graph: starting from the starting point selected in step 7), strictly traversing along the edge direction in the directed graph model, sequentially adding the visited nodes and edges to a new chain to form a linear chain; and each time an edge is passed, the linear chain is removed from the directed graph model, and the out-degree and in-degree of the nodes involved in the directed graph model are updated synchronously; 9) loop and termination: checking whether there are still unprocessed edges in the directed graph model, if there are, returning to step 7) to select the node with the maximum "excess out-degree" in the updated directed graph model as the starting point of the new chain, and constructing the next linear chain, until the directed graph model is completely traversed, and all removed linear chains form a linear chain set; 10) formatting output: converting the linear chain set into a specified format and outputting.
2. The Cocos engine-oriented pipeline loop-aware linearization decomposition method according to claim 1, wherein: The undirected topological graph data is a topological graph describing the nodes and connection relationships of a pipeline.
3. The Cocos engine-oriented pipeline loop-aware linearization decomposition method according to claim 1, wherein: The loop detection algorithm is a method based on depth-first search or union-find set.
4. The Cocos engine-oriented pipeline loop-aware linearization decomposition method according to claim 1, wherein: The loop direction rule includes specifying the outermost loop to be traversed in a counterclockwise direction, the inner loop to be traversed in a clockwise direction, or the outermost loop to be traversed in a clockwise direction and the inner loop to be traversed in a counterclockwise direction, or all loops to be traversed in a clockwise direction, or all loops to be traversed in a counterclockwise direction.
5. The Cocos engine-oriented pipeline loop-aware linearization decomposition method according to claim 1, wherein: In step 7), when selecting the node with the maximum "excess out-degree" as the starting point of the new chain, if there are multiple nodes with the same maximum "excess out-degree", one of them is selected.
6. The Cocos engine-oriented pipeline loop-aware linearization decomposition method according to claim 1, wherein: The specified format is a JSON instruction set that meets the requirements of the Cocos Engine Graphics component.
Citation Information
Patent Citations
Method of decomposing loop polygon and drawing device
CN104658018A
Topological graph structure information processing system based on image recognition
CN119741726A