Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a method for rapidly drawing a curve by using a triangular mesh, so as to overcome the defects of large required calculation amount and long consumed time when the curve is drawn by using the existing 3D software.
The technical purpose of the invention is realized by the following technical scheme: a method for quickly drawing a curve by a triangular mesh comprises the following steps:
s1, constructing a triangular mesh model, and preprocessing the triangular mesh model, wherein the preprocessing comprises the following steps: respectively calculating each triangular patch on the triangular mesh model to generate a corresponding bounding box;
s2, determining a plurality of initial points on the triangular mesh model, connecting the initial points according to a preset track, and correspondingly generating at least one line segment;
s3, according to a preset resolution, setting a plurality of equal sampling points on the line segment, determining the grid vertex of the triangular grid model closest to each equal sampling point, and calculating a first distance between each equal sampling point and the corresponding closest grid vertex;
s4, respectively calculating the distance between each equal sampling point and all bounding boxes to obtain a distance set corresponding to each equal sampling point; comparing a first distance corresponding to each equal sampling point with all distances in a distance set corresponding to the equal sampling points one by one, determining a plurality of second distances smaller than the first distance in the distance set, and marking a plurality of triangular patches corresponding to bounding boxes corresponding to the plurality of second distances as a triangular patch set;
s5, respectively calculating a first coordinate point set between each equally-divided sampling point and each triangular surface patch in the corresponding triangular surface patch set, screening out a first coordinate point which is closest to the equally-divided sampling point in the first coordinate point set, and marking as a second coordinate point;
and S6, correspondingly and sequentially connecting the second coordinate points according to the sequence of the equal sampling points on the line segment to generate a curve with a corresponding preset resolution.
Optionally, the preprocessing the triangular mesh model further includes: and traversing all vertexes on the triangular mesh model, acquiring three-dimensional coordinates corresponding to all vertexes, and establishing a three-dimensional KD tree by taking all three-dimensional coordinates as nodes.
Optionally, the determining a mesh vertex of the triangular mesh model closest to each equally-divided sampling point includes: and traversing all the equant sampling points, acquiring three-dimensional coordinates corresponding to all the equant sampling points, and respectively performing KD tree retrieval on each equant sampling point to determine a grid vertex closest to each equant sampling point.
Optionally, the determining a plurality of initial points on the triangular mesh model includes:
s21, determining an observation point;
s22, determining a mouse picking point according to a preset curve track;
s23, connecting the observation point and the mouse picking point, and correspondingly generating rays;
and S24, recording the intersection point between the ray and the triangular mesh model, and marking as an initial point.
Optionally, the preprocessing the triangular mesh model further includes:
establishing a hierarchical bounding box tree for all bounding boxes;
the calculating the distance between each equally divided sampling point and all the bounding boxes respectively comprises the following steps:
and respectively screening each equal sampling point by using the hierarchical bounding box tree, and calculating the distance between each equal sampling point and a bounding box on the hierarchical bounding box tree.
Optionally, the calculating the distances between each aliquot sampling point and all bounding boxes respectively includes:
s41, acquiring coordinates (Xmin, ymin, zmin, xmax, ymax, zmax) corresponding to any bounding box, and acquiring coordinates (X, Y, Z) of any equal sampling point;
s42, obtaining a distance dx in the X-axis direction, wherein dx = Xmin-X under the condition that X is smaller than Xmin; dx =0 in the case where X is greater than Xmin and X is less than Xmax; in the case where X is greater than Xmax, dx = X-Xmax;
s43, obtaining a distance dy in the Y-axis direction, wherein dy = Ymin-Y under the condition that Y is smaller than Ymin; in the case where Y is greater than Ymin and Y is less than Ymax, dy =0; in the case where Y is greater than Ymax, dy = Y-Ymax;
s44, obtaining a Z-axis direction distance dz, wherein dz = Zmin-Z under the condition that Z is smaller than Zmin; dz =0 in case Z is greater than Zmin and Z is less than Zmax; in the case that Z is greater than Zmax, dz = Z-Zmax;
s45, calculating the distance between any bounding box and any equal sampling point according to the X-axis direction distance dx, the Y-axis direction distance dy and the Z-axis direction distance dz
And S46, obtaining a distance set corresponding to all the equally divided sampling points according to the distances between the equally divided sampling points and all the bounding boxes.
Optionally, the calculating a first set of coordinate points between each equally-divided sampling point and each triangular patch in the corresponding triangular patch set respectively includes:
s51, determining a plane where each triangular patch is located;
s52, acquiring projection points of each equal sampling point on each corresponding plane;
s53, judging whether the projection points on each plane are positioned in the triangular patch on the plane or not, and if so, taking the projection points as corresponding first coordinate points; and if not, taking the point on the triangular patch closest to the equally divided sampling points as a first coordinate point.
A triangular mesh rapid profiling system, comprising:
the triangular mesh model generating module is used for generating a triangular mesh model;
the KD tree generation module is used for correspondingly generating a KD book tree model according to the vertex coordinates on the triangular mesh model;
a bounding box generation module: correspondingly generating a bounding box according to a triangular patch on the triangular mesh model;
the hierarchical bounding box tree generation module: and generating a hierarchical bounding box tree according to the bounding boxes of the triangular patches on the triangular mesh model.
A computer device comprising a memory storing a computer program and a processor implementing the steps of the method described above when executing the computer program.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned method.
In conclusion, the invention has the following beneficial effects:
1. the bounding box is calculated for the triangular patch on the triangular mesh model, and the distance between the equal sampling point and the triangular patch can be calculated instead of calculating the distance between the equal sampling point and the triangular patch, so that the calculation amount is effectively reduced, and the curve generation speed is improved;
2. the KD tree is correspondingly established by traversing the vertex coordinates of the triangular mesh, when the nearest mesh vertex corresponding to the equal sampling point needs to be calculated, the position of each equal sampling point on the KD tree can be determined by KD tree retrieval, and the mesh vertex on the corresponding KD tree branch can be calculated, so that the calculation amount required for searching the nearest mesh vertex corresponding to each equal sampling point can be effectively reduced compared with the traversal algorithm;
3. by establishing the hierarchical bounding box tree, when the distance between the equally-divided sampling point and the bounding box is calculated, whether the distance between the equally-divided sampling point and each bounding box is larger than the first distance or not can be judged through branches on the hierarchical bounding box tree, and the calculation amount of equipment is effectively reduced.
Detailed Description
In order to make the objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail below. Several embodiments of the invention are presented in the drawings. This invention may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein.
In the present invention, unless otherwise expressly specified or limited, the terms "mounted," "connected," "secured," and the like are to be construed broadly and can, for example, be fixedly connected, detachably connected, or integrally connected; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meanings of the above terms in the present invention can be understood according to specific situations by those of ordinary skill in the art. The terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating 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 present invention, unless otherwise expressly stated or limited, "above" or "below" a first feature means that the first and second features are in direct contact, or that the first and second features are not in direct contact but are in contact with each other via another feature therebetween. Also, the first feature being "on," "above" and "over" the second feature includes the first feature being directly on and obliquely above the second feature, or merely indicating that the first feature is at a higher level than the second feature. A first feature being "under," "below," and "beneath" a second feature includes the first feature being directly under and obliquely below the second feature, or simply meaning that the first feature is at a lesser elevation than the second feature. The terms "vertical," "horizontal," "left," "right," "up," "down," and the like are used for descriptive purposes only and are not intended to indicate or imply that the referenced devices or elements must be in a particular orientation, configuration, and operation, and therefore should not be construed as limiting the present invention.
The invention is described in detail below with reference to the figures and examples.
The invention provides a method for rapidly drawing a curve by a triangular mesh, which comprises the following steps of:
s1, constructing a triangular mesh model, and preprocessing the triangular mesh model, wherein the preprocessing comprises the following steps: calculating each triangular patch on the triangular mesh model respectively to generate a corresponding bounding box;
s2, determining a plurality of initial points on the triangular mesh model, connecting the initial points according to a preset track, and correspondingly generating at least one line segment;
s3, according to a preset resolution, setting a plurality of equal sampling points on the line segment, determining a grid vertex of a triangular grid model closest to each equal sampling point, and calculating a first distance between each equal sampling point and the corresponding closest grid vertex;
s4, respectively calculating the distance between each equal sampling point and all bounding boxes to obtain a distance set corresponding to each equal sampling point; comparing a first distance corresponding to each equal sampling point with all distances in a distance set corresponding to the equal sampling points one by one, determining a plurality of second distances smaller than the first distances in the distance set, and recording a plurality of triangular patches corresponding to bounding boxes corresponding to the plurality of second distances as a triangular patch set;
s5, respectively calculating a first coordinate point set between each equal sampling point and each triangular patch in the corresponding triangular patch set, screening out a first coordinate point which is closest to the equal sampling point in the first coordinate point set and recording as a second coordinate point;
and S6, correspondingly and sequentially connecting the second coordinate points according to the sequence of the equal sampling points on the line segment to generate a curve with a corresponding preset resolution.
Specifically, a corresponding bounding box is respectively generated for each triangular patch on the triangular mesh model; in practical applications, bounding boxes are algorithms for solving the optimal bounding space of discrete point sets, and the basic idea is to approximately replace complex geometric objects with slightly larger and simple-featured geometries (called bounding boxes). The simplicity refers to the amount of calculation needed when intersection tests are performed between bounding boxes, which not only requires that the geometric shapes are simple and easy to calculate, but also requires that the intersection test algorithm is simple and quick; the compactness requires that the bounding box is as close to the enclosed object as possible, the attribute is directly related to the number of bounding boxes needing intersection tests, and the better the compactness, the fewer the number of bounding boxes participating in the intersection tests. Through corresponding generation of the bounding boxes, the collision between the subsequent rays and the triangular surface patch can be quickly calculated, the calculation amount is reduced, and the calculation speed is increased. In this embodiment, the bounding box employs an AABB bounding box, which is the earliest bounding box to be applied. It is defined as the smallest hexahedron containing the object with the sides parallel to the coordinate axes. So describing one AABB bounding box, only six scalars are needed. The AABB bounding box is simple in structure, small in storage space and small in corresponding calculation amount, for the triangular patch in the modeling process, the requirement for reducing the calculation amount can be met by using the AABB bounding box, and excessive negative defects cannot exist.
Then, as shown in fig. 7, a plurality of initial points are determined on the triangular mesh model, and according to a predetermined track, the plurality of initial points are connected to correspondingly generate at least one line segment; specifically, the initial point is used to correspond to the generated trajectory, i.e., two points determine a line segment, and for a curve, the curve can be approximated by multiple segments.
Then, as shown in fig. 8, according to a preset resolution, setting a plurality of equal sampling points on the line segment, determining a mesh vertex of the triangular mesh model closest to each equal sampling point, and calculating a distance between each equal sampling point and the corresponding closest mesh vertex, and recording as a first distance; specifically, the distances between the equal sampling points are fixed, that is, the number of the equal sampling points on each line segment is different according to the length of the line segment, each equal sampling point has a corresponding grid vertex with the nearest distance due to the difference of the positions, the grid vertex with the nearest distance to the equal sampling point is found, and the corresponding first distance is calculated, that is, each equal sampling point has a corresponding first distance.
Then, respectively calculating second distances between each equal sampling point and all bounding boxes to obtain a distance set corresponding to each equal sampling point; comparing a first distance corresponding to each equally divided sampling point with a plurality of second distances contained in a distance set corresponding to the equally divided sampling points one by one, screening a plurality of second distances smaller than the first distance, and marking a plurality of triangular patches contained in a bounding box corresponding to the screened plurality of second distances as a triangular patch set; specifically, the distance between the aliquot sampling point and the bounding box is calculated, since the number of bounding boxes is constant, for example, there are 100 bounding boxes, each aliquot sampling point has 100 corresponding second distances, that is, there are 100 second distances in each distance set, and likewise, there is a fixed first distance in each aliquot sampling point, the 100 second distances are compared with the first distances one by one, the second distances greater than the first distances are removed, the second distances smaller than the first distances are retained, for example, 12 second distances smaller than the first distances exist in the 100 second distances in the distance set, then the 12 second distances are retained, and triangular patches in the bounding boxes corresponding to the 12 second distances are labeled, so that the 12 triangles are labeled as triangular patch sets, and similarly, the triangular patch sets also correspond to the aliquot sampling points one by one, that it can be understood that the number of triangles included in different aliquot sampling points may be different.
Then, respectively calculating a first coordinate point set between each equally-divided sampling point and each triangular patch contained in the corresponding triangular patch set, screening out a first coordinate point which is closest to the equally-divided sampling point in the first coordinate point set, and marking as a second coordinate point; specifically, since the set of triangular patches includes a plurality of triangular patches, the set of first coordinate points corresponding to the equally divided sampling points includes a plurality of corresponding first coordinate points; for example, a triangular patch set corresponding to a certain aliquot sampling point includes 12 triangular patches, and correspondingly, the number of first coordinate points included in a first coordinate point set corresponding to the aliquot sampling point is also 12. The specific determination method of the first coordinate points refers to the subsequent steps, the positions of the first coordinate points are all located on the triangular face, and the 12 first coordinate points cannot be used for describing the trend and the position of the curve, so that one first coordinate point closest to the equal sampling point is selected from the 12 first coordinate points, and the other 11 equal sampling points are discarded. That is, by this step, each of the divided sampling points corresponds to a second coordinate point on the triangular patch.
Then, correspondingly connecting a plurality of second coordinate points in sequence according to the sequence of a plurality of equally divided sampling points on the line segment to generate a corresponding curve with a preset resolution; specifically, the second coordinate points are sequentially connected to generate a curve with a predetermined resolution, the number of the second coordinate points is the same as the number of the equal sampling points, and the number of the equal sampling points is determined according to the predetermined resolution, so that the number of the second coordinate points also meets the requirement of the resolution, and the second coordinate points are sequentially connected to form a multi-segment line, which can be approximately fitted into a smooth curve meeting the requirement, as shown in fig. 9, the curve is generated on the human body model, wherein S1 is a corresponding segment, that is, a segment correspondingly generated by connecting the initial points, and P1 is a high-resolution multi-segment line correspondingly generated by the equal sampling points on the segment, that is, a curve meeting the requirement of the resolution, and specifically, the multi-segment line is still not a line closely attached to the triangular mesh model, but meets the requirement of convenient division, so that the multi-segment line can be approximately attached to the triangular mesh under the condition of visual observation.
The method comprises the steps of drawing corresponding high-resolution multi-segment lines on the surface of a preset low-resolution three-dimensional model according to a preset line segment track to approximately fit the multi-segment lines into a smooth curve. S1, reducing the calculated amount of collision between a triangular patch and a line segment by setting a bounding box; s2 is used for determining the direction of a curve to be drawn, S3 is used for subdividing a line segment into a plurality of segments connected end to end through equal sampling points, and S4 and S5 are used for correspondingly mapping the equal sampling points to a 3D model and correspondingly determining the positions of the equal sampling points; and S6, connecting corresponding points on the triangular mesh model to form a multi-segment line, wherein the multi-segment line is more attached to the surface shape of the triangular mesh model than a line segment where the equal-division sampling points are located, and meets the requirement of curve drawing.
In practical application, a curve is drawn through 3D software, a basic triangular mesh model is generally required to be introduced into the 3D software, each triangular patch is decomposed into three smaller patches based on the triangular mesh model, and the shape of a triangle therein is adjusted, so that part of vertexes of the generated triangle meet the requirement of the curve, and when enough vertexes of the triangle meet the requirement, a plurality of vertexes can be connected in sequence to form a corresponding curve. And the more points provided, the higher the resolution of the curve and the smoother the curve. However, this curve drawing method requires a large amount of computation, and for an entire 3D model, all the triangular patches generally need to be decomposed into smaller triangular patches to achieve resolution enhancement, which results in an exponential increase in the amount of computation.
In summary, according to the high-resolution curve drawing method based on the triangular mesh provided by the present invention, firstly, the corresponding triangular mesh model needs to be imported into software, and the bounding box is calculated for the triangular patch on the triangular mesh model, and the distance between the equal sampling point and the triangular patch can be calculated instead of calculating the distance between the equal sampling point and the triangular patch, so that the calculation amount is effectively reduced, and the curve generation speed is increased.
Further, the preprocessing the triangular mesh model further includes: and traversing all the vertexes on the triangular mesh model, acquiring three-dimensional coordinates corresponding to all the vertexes, and establishing a three-dimensional KD tree by taking all the three-dimensional coordinates as nodes.
The determining of the mesh vertex of the triangular mesh model closest to each of the equally divided sampling points includes: and traversing all the equant sampling points, acquiring three-dimensional coordinates corresponding to all the equant sampling points, and respectively performing KD tree retrieval on each equant sampling point to determine a grid vertex closest to each equant sampling point.
Specifically, the concept of kd (k-dimensional) tree was proposed since 1975 to solve the problem of creating an index for a dataset in k-dimensional space, in the actual use process, a segment of line is actually cut out for the final segmentation result of a one-dimensional space, similarly, in a two-dimensional space, the space of the final segmentation result for a plurality of point sets should be a set of sub-planes, and in a three-dimensional space, the space of the final segmentation result for a plurality of point sets should be a set of sub-spaces. Here, the final goal of the kd tree is to construct a tree, and a final subspace set obtained by segmenting a three-dimensional space can be constructed; and establishing a three-dimensional coordinate system in the three-dimensional space, labeling the vertex of the triangular mesh model in the three-dimensional coordinate system, and dividing the three-dimensional coordinate system into a plurality of subspaces by using a plane parallel to the plane of the coordinate system and the corresponding vertex. The three-dimensional KD tree is built as follows: marking the vertexes in a three-dimensional space according to coordinates, firstly dividing the space by using a plane parallel to XY axes, selecting the heights of the vertexes corresponding to the Z-axis coordinates positioned in the middle (wherein if the number of the fixed points is an even number, and the number of the points positioned in the middle is two, any one of the two points is optional), and dividing the three-dimensional space into an upper space and a lower space by using a first plane, wherein the Z-axis coordinates corresponding to the upper space are all larger than the Z-axis coordinates of the plane, and the corresponding Z-axis coordinates of all the points positioned in the lower space are all smaller than the Z-axis coordinates of the plane; then, the upper space and the lower space are divided by planes parallel to the YZ axis respectively, and similarly, points with X-axis coordinates located at the middlemost are selected from the upper space and the lower space respectively to serve as demarcation points, so that the upper space and the lower space are divided into two spaces, namely four spaces are correspondingly generated. And finally, respectively selecting corresponding points in the four spaces, dividing the points by a plane parallel to the XZ, and performing space division, and also selecting a middle point of a Y-axis coordinate to perform space division. The above steps are then repeated for each vertex in each subspace until all vertices lie on the plane.
According to the division, a certain rule exists, 1, in the subspace divided by the parent plane, the child plane used for further division cannot pass through the parent plane, that is, when the child plane divides the space, the child plane can only extend to the parent plane. 2. When the vertex of the triangular mesh model does not exist in the subspace, the space cannot be divided. 3. The planes used for the division into spaces need to be in order, for example, a plane parallel to the XY plane is used first, then a plane parallel to the YZ plane is used, finally a plane parallel to the XZ plane is used, and the following further division into sub-spaces needs to be divided by using the parallel planes in this order.
Therefore, when the corresponding nearest vertex of a certain equally-divided sampling point is searched, the lowest subspace where the equally-divided sampling point is located can be correspondingly determined according to the coordinates of the equally-divided sampling point, and then the vertex of the triangular mesh model closest to the equally-divided sampling point can be determined after the vertex near the lowest subspace is queried. A large number of irrelevant points can be arranged through kd tree retrieval, the calculation amount is effectively reduced, and the curve generation speed is improved.
Further, the determining a plurality of initial points on the triangular mesh model includes:
s21, determining an observation point;
s22, determining a mouse picking point according to a preset curve track;
s23, connecting the observation point and the mouse picking point, and correspondingly generating a ray;
and S24, recording the intersection point between the ray and the triangular mesh model, and marking as an initial point.
Specifically, as shown in fig. 6, the observation point is a shooting point of a camera in the existing three-dimensional software, and is used for observing the model in the three-dimensional software; in three-dimensional software, the picked-up point of the mouse does not necessarily fall on the three-dimensional model, and due to the viewing angle, the picked-up point of the mouse usually passes through the three-dimensional model and falls behind the three-dimensional model or falls in front of the three-dimensional model. Therefore, by establishing the observation point and determining the mouse picking point, a ray taking the observation point as a starting point can be established, and the ray infinitely extends to the bottom far plane of the 3d software, so that whether the ray and the triangular mesh model have intersection points or not can be determined; if there is no intersection, the ray is discarded, if there is one intersection, the intersection is taken as an initial point, and if there are two or more intersections, the first intersection of the ray and the triangular mesh model is taken as the initial point.
Further, the preprocessing the triangular mesh model further includes:
establishing a hierarchical bounding box tree for all bounding boxes;
the calculating the distance between each equally divided sampling point and all the bounding boxes respectively comprises the following steps:
and respectively screening each equal sampling point by using the hierarchical bounding box tree, and calculating the distance between each equal sampling point and a bounding box on the hierarchical bounding box tree.
In particular, hierarchical bounding box trees, in physics engines, most shapes are dynamically updated due to physics simulations, e.g., displacement/rotation changes shape. Thus, there is another hierarchical bounding box tree supporting dynamic update, called dynamic hierarchical bounding box tree. Its algorithm core can be summarized as: the displacement/rotation/scaling of the shape updates the corresponding leaf nodes, and then the nodes above are updated one level at a time, so that their bounding volumes surround child nodes. By establishing the hierarchical bounding box tree, the bounding boxes of the triangular patch can be divided through bounding boxes with different sizes, the corresponding sub-bounding boxes inside the bounding boxes can be quickly eliminated by calculating with the parent bounding box, the calculation amount is effectively reduced, and the calculation speed is improved.
Further, the distance between each equally divided sampling point and all the bounding boxes is respectively calculated, and the method comprises the following steps:
s41, acquiring coordinates (Xmin, ymin, zmin, xmax, ymax, zmax) corresponding to any bounding box, and acquiring coordinates (X, Y, Z) of any equal sampling point;
s42, obtaining a distance dx in the X-axis direction, wherein when X is smaller than Xmin, dx = Xmin-X; dx =0 in the case where X is greater than Xmin and X is less than Xmax; in the case where X is greater than Xmax, dx = X-Xmax;
s43, obtaining a distance dy in the Y-axis direction, wherein dy = Ymin-Y under the condition that Y is smaller than Ymin; in the case where Y is greater than Ymin and Y is less than Ymax, dy =0; in the case where Y is greater than Ymax, dy = Y-Ymax;
s44, obtaining a Z-axis direction distance dz, wherein dz = Zmin-Z under the condition that Z is smaller than Zmin; dz =0 in case Z is greater than Zmin and Z is less than Zmax; in the case that Z is greater than Zmax, dz = Z-Zmax;
s45, calculating the distance between any bounding box and any equal sampling point according to the X-axis direction distance dx, the Y-axis direction distance dy and the Z-axis direction distance dz
And S46, obtaining a distance set corresponding to all the equally divided sampling points according to the distances between the equally divided sampling points and all the bounding boxes.
Specifically, the distances between each equally divided sampling point and all bounding boxes are calculated, for example, five equally divided sampling points are provided on one line segment, twenty triangular patches are provided on the triangular mesh model, and then the distance between one equally divided sampling point and one bounding box needs to be calculated repeatedly by 5 × 20=100 times, and steps S42 to S45 are to calculate the distance between one equally divided sampling point and one bounding box, and all combinations between the equally divided sampling points and the bounding boxes need to be calculated respectively according to permutation and combination, so as to obtain 5 distance sets corresponding to the 5 equally divided sampling points. In this embodiment, the bounding box is an AABB bounding box, and six faces of the AABB bounding box are all parallel to the base plane, so that the position of the corresponding bounding box can be determined by coordinates of two opposite points, that is, coordinates (Xmin, ymin, zmin, xmax, ymax, zmax), and the distance between a certain equally-divided sampling point and the bounding box is calculated. The bounding box tree is characterized in that a larger parent bounding box is used for bounding a plurality of child bounding boxes with smaller volume, so that the distance between the equally divided sampling point and the parent bounding box can be calculated firstly during calculation, and if the distance is larger than a first distance, the distance between the equally divided sampling point and the child bounding box in the parent bounding box is larger than the first distance, namely all the child bounding boxes in the parent bounding box can be excluded. Therefore, the calculation amount in the distance calculation process can be effectively reduced, and the calculation speed is improved.
Further, the calculating a first coordinate point set between each equally-divided sampling point and each triangular patch in the corresponding triangular patch set respectively includes:
s51, determining a plane where each triangular patch is located;
s52, acquiring projection points of each equal sampling point on each corresponding plane;
s53, judging whether the projection points on each plane are positioned in the triangular patch on the plane, and if so, taking the projection points as corresponding first coordinate points; if not, taking the point on the triangular patch closest to the equally divided sampling points as a first coordinate point.
Specifically, each equal sampling point corresponds to one triangular patch set, but the number of triangular patches included in the triangular patch sets corresponding to different equal sampling points is different, for example, the number of triangular patches in a triangular patch set corresponding to a certain equal sampling point is 5, then the number of planes corresponding to the triangular patches is 5, correspondingly, the number of projection points corresponding to the equal sampling points on each plane is 5, and by determining the positions of the projection points and the triangular patches on the corresponding planes, 5 first coordinate points can be obtained correspondingly, that is, the 5 corresponding first coordinate points are recorded as a first coordinate point set. When the first coordinate point is determined, whether the projection point is located inside the triangular surface patch or not can be judged through the distance between the gravity center of the triangular surface patch and the projection point, and if the projection point is located inside the triangular surface patch, the projection point is used as the first coordinate point; if the projection point is not in the triangular patch, calculating and selecting a point on the triangular patch closest to the equal division sampling point as a first coordinate point, specifically, the point closest to the equal division sampling point is located at the edge of the triangular patch; then, the distances between the three line segment sides of the triangular patch and the sampling point are respectively calculated, and one side closest to the equal sampling point can be selected by comparing the distances between the projection point and the three sides. Then, by calculating the closest point of the equally divided sampling point to the edge (i.e. the closest point of a point determined on a certain line segment), the following calculation method can be used: recording a line segment AB, wherein the starting point is A, the end point is B, the equal division sampling point is P, establishing vectors AB and AP, multiplying AB vector points by AP to obtain a, the square of the length of the vector AB is B, dividing a by B to obtain a ratio, and if ratio < =0, the closest point is A; if ratio > =1, the closest point is B; if 0< -ratio < -1 >, the closest point is A (1-ratio) + B ratio. Wherein, ratio is the proportion point of the nearest point on the line segment AB, and the size of ratio is determined, namely the position of the point on the line segment is determined.
As shown in fig. 5, the present invention further provides a system for rapidly drawing a curve by using a triangular mesh, including:
the triangular mesh model generating module is used for generating a triangular mesh model;
the KD tree generation module is used for correspondingly generating a KD book tree model according to the vertex coordinates on the triangular mesh model;
the bounding box generation module: correspondingly generating a bounding box according to a triangular patch on the triangular mesh model;
the hierarchical bounding box tree generation module: and generating a hierarchical bounding box tree according to the bounding boxes of the triangular patches on the triangular mesh model.
For the specific definition of a triangle mesh rapid curve-drawing system, refer to the above definition of a triangle mesh rapid curve-drawing system, which is not described herein again. All modules in the triangular mesh rapid curve drawing system can be completely or partially realized by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as shown in fig. 10. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The computer program is executed by a processor to implement a method for rapid curve-drawing of a triangular mesh.
It will be appreciated by those skilled in the art that the configuration shown in fig. 10 is a block diagram of only a portion of the configuration associated with the present application, and is not intended to limit the computing device to which the present application may be applied, and that a particular computing device may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, a computer device is provided, comprising a memory having a computer program stored therein and a processor that when executing the computer program performs the steps of: the method comprises the following steps:
the method comprises the following steps:
s1, constructing a triangular mesh model, and preprocessing the triangular mesh model, wherein the preprocessing comprises the following steps: calculating each triangular patch on the triangular mesh model respectively to generate a corresponding bounding box;
s2, determining a plurality of initial points on the triangular mesh model, connecting the initial points according to a preset track, and correspondingly generating at least one line segment;
s3, according to a preset resolution, setting a plurality of equal sampling points on the line segment, determining the grid vertex of the triangular grid model closest to each equal sampling point, and calculating a first distance between each equal sampling point and the corresponding closest grid vertex;
s4, respectively calculating the distance between each equal sampling point and all bounding boxes to obtain a distance set corresponding to each equal sampling point; comparing a first distance corresponding to each equal sampling point with all distances in a distance set corresponding to the equal sampling points one by one, determining a plurality of second distances smaller than the first distances in the distance set, and recording a plurality of triangular patches corresponding to bounding boxes corresponding to the plurality of second distances as a triangular patch set;
s5, respectively calculating a first coordinate point set between each equally-divided sampling point and each triangular surface patch in the corresponding triangular surface patch set, screening out a first coordinate point which is closest to the equally-divided sampling point in the first coordinate point set, and marking as a second coordinate point;
and S6, correspondingly and sequentially connecting the second coordinate points according to the sequence of the equal sampling points on the line segment to generate a curve with a corresponding preset resolution.
In one embodiment, the preprocessing the triangular mesh model further includes: and traversing all the vertexes on the triangular mesh model, acquiring three-dimensional coordinates corresponding to all the vertexes, and establishing a three-dimensional KD tree by taking all the three-dimensional coordinates as nodes.
In one embodiment, the determining the mesh vertices of the triangular mesh model closest to the respective equally sampled points comprises: traversing all the equally divided sampling points, acquiring three-dimensional coordinates corresponding to all the equally divided sampling points, and performing KD tree retrieval on each equally divided sampling point to determine a grid vertex closest to each equally divided sampling point.
In one embodiment, said determining a number of initial points on said triangular mesh model comprises:
s21, determining an observation point;
s22, determining a mouse picking point according to a preset curve track;
s23, connecting the observation point and the mouse picking point, and correspondingly generating rays;
and S24, recording an intersection point between the ray and the triangular mesh model, and marking as an initial point.
In one embodiment, the preprocessing the triangular mesh model further includes:
establishing a hierarchical bounding box tree for all bounding boxes;
the calculating the distance between each equally divided sampling point and all the bounding boxes respectively comprises the following steps:
and respectively screening each equally divided sampling point by using the hierarchical bounding box tree, and calculating the distance between the equally divided sampling point and a bounding box on the hierarchical bounding box tree.
In one embodiment, calculating the distance between each aliquot sampling point and all bounding boxes separately comprises:
s41, acquiring coordinates (Xmin, ymin, zmin, xmax, ymax, zmax) corresponding to any bounding box, and acquiring coordinates (X, Y, Z) of any equal sampling point;
s42, obtaining a distance dx in the X-axis direction, wherein dx = Xmin-X under the condition that X is smaller than Xmin; dx =0 in the case where X is greater than Xmin and X is less than Xmax; in the case where X is greater than Xmax, dx = X-Xmax;
s43, obtaining a distance dy in the Y-axis direction, wherein dy = Ymin-Y under the condition that Y is smaller than Ymin; in the case where Y is greater than Ymin and Y is less than Ymax, dy =0; in the case where Y is greater than Ymax, dy = Y-Ymax;
s44, obtaining a Z-axis direction distance dz, wherein dz = Zmin-Z under the condition that Z is smaller than Zmin; dz =0 in case Z is greater than Zmin and Z is less than Zmax; in the case that Z is greater than Zmax, dz = Z-Zmax;
s45, calculating the distance between any bounding box and any equal sampling point according to the X-axis direction distance dx, the Y-axis direction distance dy and the Z-axis direction distance dz
And S46, obtaining a distance set corresponding to all the equally divided sampling points according to the distances between the equally divided sampling points and all the bounding boxes.
Further, the calculating a first set of coordinate points between each equally-divided sampling point and each triangular patch in the corresponding triangular patch set respectively includes:
s51, determining a plane where each triangular patch is located;
s52, acquiring projection points of each equal sampling point on each corresponding plane;
s53, judging whether the projection points on each plane are positioned in the triangular patch on the plane or not, and if so, taking the projection points as corresponding first coordinate points; and if not, taking the point on the triangular patch closest to the equally divided sampling points as a first coordinate point.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above may be implemented by hardware instructions of a computer program, which may be stored in a non-volatile computer-readable storage medium, and when executed, may include the processes of the embodiments of the methods described above. Any reference to memory, storage, database or other medium used in the embodiments provided herein can include non-volatile and/or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), rambus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
All possible combinations of the technical features in the above embodiments may not be described for the sake of brevity, but should be considered as being within the scope of the present disclosure as long as there is no contradiction between the combinations of the technical features.
The above description is only a preferred embodiment of the present invention, and the scope of the present invention is not limited to the above embodiments, and all technical solutions that belong to the idea of the present invention belong to the scope of the present invention. It should be noted that modifications and embellishments within the scope of the invention may occur to those skilled in the art without departing from the principle of the invention, and are considered to be within the scope of the invention.