Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present invention without any creative effort belong to the protection scope of the embodiments of the present invention.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the embodiments of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the embodiments of the invention. As used in the description of embodiments of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in the description of embodiments of the present invention and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
Referring to fig. 1, fig. 1 is a schematic flowchart of a vector shape rendering method based on a mesh structure according to an embodiment of the present invention.
As shown in fig. 1, the method includes steps S101 to S104.
S101, initializing the access states of all connection points and connection edges of the vector grid structure.
In this embodiment, the vector grid structure is a data structure of vector drawing, and is composed of connection points, connection edges, and regions, where the connection points describe position coordinates and some other attributes of the points, the connection edge structure describes which two connection points the connection edge connects, and which connection edges are mathematically used as two access control points of a bezier curve, and the regions specify which connection edges connect to form a closed link; each connection point may be connected to other points by any number of connecting edges to form a unidirectional network.
Initializing access states of all connection points and connection edges in the vector grid structure, wherein the access states comprise an accessed state and an inaccessible state, and initializing all the connection points and the connection edges to be in the inaccessible state so as to conveniently mark drawn positions in the process of drawing a link.
S102, constructing a connection edge index of each connection point; so as to arrange all the connecting edges, and facilitate subsequent selection and drawing.
Specifically, step S102 includes:
and aiming at each connection point, acquiring a connection edge connected with each connection point, collecting all connection edges connected with all connection points, and constructing a connection edge index.
In this embodiment, the number of the connection edges connected to each connection point may be one or more, and the two connection points may connect the same connection edge, so that after all the connection edges connected to all the connection points are collected, the repeated connection edges are screened out, only one connection edge is retained, and then a connection edge index is constructed for all the screened connection edges.
S103, traversing all the connection edges in the connection edge indexes and obtaining drawing link indexes; so as to draw according to the drawing link.
Specifically, as shown in fig. 2, step S103 includes:
s201, selecting a current connecting edge, and accessing a connecting point and the connecting edge along the directions of two ends of the current connecting edge until the construction of a drawing link in the directions of two ends of the current connecting edge is completed;
s202, combining the drawing links in the directions of the two ends of the current connecting edge, and finishing the drawing link of the current connecting edge;
s203, continuously selecting the next connecting edge, constructing the drawing link of the next connecting edge until the drawing links of all the connecting edges are completed, and obtaining the drawing link index according to the drawing links of all the connecting edges.
In the process of drawing a graph, firstly, in the index of the connecting edge, a connecting edge is randomly selected as the current connecting edge, then drawing is started along the directions of two ends of the current connecting edge, and the process of drawing continuously advances to other connecting points and connecting edges until the construction of drawing links in the directions of two ends of the current connecting edge is completed; then combining the drawing links in the directions of the two ends to form a complete and coherent drawing link; and then, randomly selecting a connecting edge with an access state being an unaccessed state from the connecting edge index as a next connecting edge, and starting to draw along the directions of two ends of the next connecting edge according to the same drawing mode until a next complete and coherent drawing link is obtained. And continuously selecting and drawing the remaining drawing links of all the connecting sides in the same mode until the drawing links of all the connecting sides in the connecting side index are finished, and finally obtaining the drawing link index according to the drawing links of all the connecting sides.
In one embodiment, as shown in fig. 3, step S201 includes:
s301, selecting a current connecting edge, and constructing a drawing link based on the current connecting edge;
s302, accessing the connection points at the two ends along the directions of the two ends of the current connection edge, and if the connection point at any end is in an accessed state or the number of the connection edges connected with the connection point at any end is 1, ending the drawing link in the current direction.
In this embodiment, a connecting edge is randomly selected from the connecting edge index as a current connecting edge, a drawing link is constructed based on the current connecting edge, and then the drawing link is continuously drawn.
Specifically, drawing is performed from two end directions of a current connection edge, for any one end direction, a connection point is visited first during drawing, the visiting state of the connection point and the number of connection edges connected with the connection point need to be judged, if the connection point is in the visited state, it is indicated that the connection point has been drawn by other drawing links, and then drawing is performed to generate an overlapping effect; if the number of the connecting sides connected by the connecting point is 1, it indicates that the connecting point is only connected with one side of the current connecting side, which is the end of the drawing, and the drawing in the current direction can be finished when any one of the two conditions is met.
In an embodiment, as shown in fig. 4, step S201 further includes:
s401, accessing connection points at two ends along the directions of the two ends of the current connection edge, and if the connection point at any end is in an unaccessed state and the number of the connection edges connected with the connection point at any end is 2, marking the connection point as an accessed state and advancing to a non-current connection edge connected with the connection point;
s402, judging the access state of the non-current connecting edge, if the non-current connecting edge is in the accessed state, ending the drawing link in the current direction, if the non-current connecting edge is in the unaccessed state, marking the non-current connecting edge as the accessed state, adding the non-current connecting edge into the drawing link, and continuing to move forward to the next connecting point until the drawing link in the current direction is ended.
In this embodiment, a connecting edge is randomly selected from the connecting edge index as a current connecting edge, a drawing link is constructed based on the current connecting edge, and then the drawing link is continuously drawn.
Specifically, drawing is performed from two end directions of a current connection side respectively, for any one end direction, a connection point is visited first during drawing, the visiting state of the connection point and the number of connection sides connected with the connection point need to be judged, if the connection point is in a non-visiting state, it is indicated that the connection point is not drawn, the connection point can be moved forward, and the connection point is marked as a visited state to prevent repetition during subsequent drawing; secondly, if the number of the connecting edges connected by the connecting point is 2 (that is, one edge is the current connecting edge, and the other edge is the non-current connecting edge), the process can be continued to the non-current connecting edge.
Then judging the access state of the non-current connection edge, if the access state is the accessed state, indicating that the drawing link is drawn by other drawing links, and finishing the construction of the drawing link in the current direction; if the current drawing link is in the non-access state, the non-current connection edge is marked as the access state, the non-current connection edge is added into the currently drawn drawing link, and the process of proceeding to the next connection point is continued until the construction of the drawing link in the current direction is finished.
In one embodiment, as shown in fig. 5, step S201 further includes:
s501, accessing connection points at two ends along the directions of the two ends of the current connection edge, and if the connection point at any end is in an unaccessed state and the number of the connection edges connected with the connection points is more than 2, acquiring two connection edges with the largest included angle among the connection edges connected with the connection points;
s502, judging whether one of the two connecting edges is the current connecting edge, and if not, ending the drawing link in the current direction; if so, advancing to the non-current connecting side of the two connecting sides;
s503, judging the access state of the non-current connecting edge, if the non-current connecting edge is in the accessed state, ending the drawing link in the current direction, if the non-current connecting edge is in the unaccessed state, marking the non-current connecting edge as the accessed state, adding the non-current connecting edge into the drawing link, and continuing to move forward to the next connecting point until the drawing link in the current direction is ended.
In this embodiment, a connecting edge is randomly selected from the connecting edge index as a current connecting edge, a drawing link is constructed based on the current connecting edge, and then the drawing link is continuously drawn.
Specifically, drawing is performed from two end directions of a current connection side respectively, for any one end direction, a connection point is visited first during drawing, the visiting state of the connection point and the number of connection sides connected with the connection point need to be judged, if the connection point is in an unaccessed state, it is indicated that the connection point is not drawn, the connection point can be moved forward, and the connection point is marked as an accessed state to prevent repetition during subsequent drawing; secondly, if the number of the connecting edges connected with the connecting point is more than 2, two connecting edges with the largest included angle (less than or equal to 180 degrees) among the connecting edges connected with the connecting point can be obtained; then comparing the indexes of the two connecting edges with the index of the current connecting edge, if the indexes of the two connecting edges are not the same as the index of the current connecting edge, the two connecting edges do not have the current connecting edge, and the construction of the drawing link in the current direction can be finished; if the index of one of the two connected edges is the same as the index of the current connected edge, one of the two connected edges is the current connected edge, and the connected point may be marked as visited and may proceed to a non-current connected edge of the two connected edges.
Judging the access state of the non-current connection edge, if the access state is the accessed state, indicating that the drawing link is drawn by other drawing links, and finishing the construction of the drawing link in the current direction; if the current drawing link is in the non-access state, the non-current connection edge is marked as the access state, the non-current connection edge is added into the currently drawn drawing link, and the process of proceeding to the next connection point is continued until the construction of the drawing link in the current direction is finished.
Further, as shown in fig. 6 and 7, the key point of this embodiment lies in ensuring the line drawing effect at the connection point, and for a single connection point, a path drawing sequence passing through the connection point needs to be found, for example, if there are three connection edges a, b, and c passing through the same line width of the single connection point, two connection edges with the largest included angle among the connection edges connected to the connection point need to be obtained, and then it is continuously determined whether one of the connection edges is the current connection edge, and if one of the connection edges is the current connection edge, the connection edge is advanced to a non-current connection edge, so the line drawing effect at the connection point is better, and the principle is as follows:
the maximum included angle between a and b is only set as follows:
in the first case: a. the included angle between b is an acute angle, the line width is the same, the circle in the figure shows that the line c rotates around the connecting point, the track circle formed by the outline vertex is tangent to the outline of a and b, and the line outline vertex of c at the connecting position cannot exceed the outline range of a and b because the included angle between a and b is the maximum.
In the first case: a. the included angle between b is obtuse angle, the line width is the same, the circle in the figure shows that the line c rotates around the connecting point, the track circle formed by the outline vertex is tangent with the outline of a and b, the line outline vertex of c at the connecting position does not exceed the outline range of a and b because the included angle between a and b is the maximum, and the intersection point of the outline of a and b is always in the outline range of c.
By selecting two connecting edges with the largest included angle to form a continuous drawing sequence, the drawing effect at the connecting point can be ensured.
Further, referring to the comparison between the effects of fig. 8 and fig. 9, the drawing order of fig. 8 is { a- > c }, { b }; the drawing order of fig. 9 is { a- > c }, { b }; therefore, two connecting edges with the largest included angle are selected to form a continuous drawing sequence, and the line drawing effect at the connecting point can be guaranteed.
And S104, performing path drawing according to the drawing link index to obtain a vector graph.
Specifically, step S104 includes:
and performing path drawing on each drawing link in the drawing link index to form a plurality of vector lines, and constructing a vector graph according to all the vector lines.
In this embodiment, after traversing all the connecting edges and obtaining the drawing link indexes, path drawing is performed on each drawing link to obtain a corresponding vector line, and a vector graph can be constructed by combining all the vector lines of all the drawing links.
The embodiment of the invention also provides a vector shape drawing device based on the grid structure, which is used for executing any embodiment of the vector graphic drawing method based on the grid structure. Specifically, referring to fig. 10, fig. 10 is a schematic block diagram of a vector shape drawing apparatus based on a mesh structure according to an embodiment of the present invention.
As shown in fig. 10, the vector shape drawing apparatus 1000 based on a mesh structure includes: an initialization unit 1001, a construction unit 1002, an acquisition unit 1003, and a rendering unit 1004.
An initialization unit 1001 configured to initialize access states of all connection points and connection edges of the vector mesh structure;
a constructing unit 1002, configured to construct a connection edge index of each connection point;
an obtaining unit 1003, configured to traverse all connection edges in the connection edge index and obtain a drawing link index;
and a drawing unit 1004 for performing path drawing according to the drawing link index to obtain a vector graph.
In an embodiment, the building unit 1002 includes:
and the connection edge index construction unit is used for acquiring the connection edge connected with each connection point aiming at each connection point, gathering all the connection edges connected with all the connection points and constructing a connection edge index.
In an embodiment, the obtaining unit 1003 includes:
the first selection unit is used for selecting the current connection edge, accessing the connection point and the connection edge along the directions of the two ends of the current connection edge until the construction of the drawing link in the directions of the two ends of the current connection edge is completed;
a merging unit, configured to merge drawing links in directions of two ends of a current connection edge, and end the drawing link of the current connection edge;
and the second selection unit is used for continuously selecting the next connecting edge and constructing the drawing link of the next connecting edge until the drawing links of all the connecting edges are completed, and obtaining the drawing link index according to the drawing links of all the connecting edges.
In one embodiment, the first selecting unit includes:
the current construction unit is used for selecting a current connecting edge and constructing a drawing link based on the current connecting edge;
and the current drawing unit is used for accessing the connection points at the two ends along the directions of the two ends of the current connection edge, and ending the drawing link in the current direction if the connection point at any end is in an accessed state or the number of the connection edges connected with the connection point at any end is 1.
In an embodiment, the first selecting unit further includes:
a first forwarding unit, configured to access connection points at two ends along directions of two ends of a current connection edge, and if a connection point at any one end is in an unaccessed state and the number of connection edges connected to the connection point at any one end is 2, mark the connection point as an accessed state and forward the connection point to a non-current connection edge connected to the connection point;
and the first judgment unit is used for judging the access state of the non-current connecting edge, ending the drawing link in the current direction if the non-current connecting edge is in the accessed state, marking the non-current connecting edge as the accessed state and adding the non-current connecting edge into the drawing link if the non-current connecting edge is in the unaccessed state, and continuing to move forward to the next connecting point until the drawing link in the current direction is ended.
In an embodiment, the first selecting unit further includes:
a second judging unit, configured to access connection points at two ends along directions of two ends of a current connection edge, and if a connection point at any one end is in an unaccessed state and the number of connection edges connected to the connection point is greater than 2, obtain two connection edges with the largest included angle among the connection edges connected to the connection point;
a third judging unit, configured to judge whether one of the two connecting edges is a current connecting edge, and if not, end the drawing link in the current direction; if so, advancing to the non-current connecting side of the two connecting sides;
and the fourth judging unit is used for judging the access state of the non-current connecting edge, ending the drawing link in the current direction if the non-current connecting edge is in the accessed state, marking the non-current connecting edge as the accessed state and adding the non-current connecting edge into the drawing link if the non-current connecting edge is in the unaccessed state, and continuing to move forward to the next connecting point until the drawing link in the current direction is ended.
In an embodiment, the rendering unit 1004 further includes:
and the path drawing unit is used for drawing paths of each drawing link in the drawing link index to form a plurality of vector lines and constructing a vector graph according to all the vector lines.
The embodiment of the invention also provides computer equipment which comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein the vector graphics drawing method based on the grid structure is realized when the processor executes the computer program.
The embodiment of the invention also provides a computer readable storage medium, wherein a computer program is stored on the computer readable storage medium, and when being executed by a processor, the computer program realizes the vector graphics drawing method based on the grid structure.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses, devices and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
While the embodiments of the present invention have been described with reference to the accompanying drawings, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the embodiments of the present invention. Therefore, the protection scope of the embodiments of the present invention shall be subject to the protection scope of the claims.