Real-Time Rendering——16.3 Consolidation合并

Once a model has passed through any tessellation algorithms needed, we are left with a set of polygons representing the model. There are a few operations that may be useful for displaying these data. The simplest is checking whether the polygon itself is properly formed, that it has at least three unique vertex locations, and that they are not collinear. For example, if two vertices in a triangle match, then it has no area and can be discarded. Note that in this section we are truly referring to polygons, not just triangles. Depending on your goals, it can be more efficient to store each polygon, instead of immediately converting it to triangles for display. Triangulating creates more edges, which in turn creates more work for the operations that follow.

一旦一个模型通过了任何需要的细分算法,我们就剩下了一组代表这个模型的多边形。有一些操作可能对显示这些数据有用。最简单的是检查多边形本身是否正确形成,它是否至少有三个唯一的顶点位置,以及它们是否不在同一直线上。例如,如果三角形中的两个顶点匹配,那么它就没有面积,可以丢弃。请注意,在本节中,我们真正指的是多边形,而不仅仅是三角形。根据您的目标,存储每个多边形可能更有效,而不是立即将其转换为三角形进行显示。三角剖分创建了更多的边,这反过来又为后面的操作创建了更多的工作。

One procedure commonly applied to polygons is merging, which finds shared vertices among faces. Another operation is called orientation, where all polygons forming a surface are made to face the same direction. Orienting a mesh is important for several different algorithms, such as backface culling, crease edge detection, and correct collision detection and response. Related to orientation is vertex normal generation,where surfaces are made to look smooth. We call all these types of techniques consolidation algorithms.

通常应用于多边形的一个过程是合并,它在面之间寻找共享顶点。另一种操作称为定向,其中形成表面的所有多边形都面向同一方向。为网格定向对于几种不同的算法都很重要,例如背面剔除、折痕边缘检测以及正确的碰撞检测和响应。与方向相关的是顶点法线生成,其中表面看起来很平滑。我们称所有这些类型的技术为合并算法。

16.3.1 Merging

Some data comes in the form of disconnected polygons, often termed a polygon soup or triangle soup. Storing separate polygons wastes memory, and displaying separate polygons is extremely inefficient. For these reasons and others, individual polygons are usually merged into a polygon mesh. At its simplest, a mesh consists of a list of vertices and a set of outlines. Each vertex contains a position and other optional data, such as the shading normal, texture coordinates, tangent vectors, and color.Each polygon outline has a list of integer indices. Each index is a number from 0 to n − 1, where n is the number of vertices and so points to a vertex in the list. In this way, each vertex can be stored just once and shared by any number of polygons. A triangle mesh is a polygon mesh that contains only triangles. Section 16.4.5 discusses mesh storage schemes in depth.

一些数据以不连续多边形的形式出现,通常称为多边形汤或三角形汤。存储单独的多边形浪费内存,显示单独的多边形效率极低。由于这些原因和其他原因,单个多边形通常会合并到一个多边形网格中。最简单的情况是,一个网格由一系列顶点和一组轮廓组成。每个顶点包含一个位置和其他可选数据,如着色法线、纹理坐标、切线向量和颜色。每个多边形轮廓都有一个整数索引列表。每个索引是一个从0到n − 1的数字,其中n是顶点的数量,因此指向列表中的一个顶点。这样,每个顶点可以只存储一次,并由任意数量的多边形共享。三角形网格是只包含三角形的多边形网格。第16.4.5节深入讨论了网格存储方案。

Model data sometimes comes in with separate polygons’ vertices being extremely close, but not identical. The process of merging such vertices is called welding. Efficiently welding vertices can be done by using sorting along with a looser equality function for the position [1135].

模型数据有时会出现单独多边形的顶点非常接近,但不完全相同的情况。合并这些顶点的过程称为焊接。有效地焊接顶点可以通过使用排序以及位置的更宽松的等式函数来完成[1135]。

16.3.2 Orientation方向

One quality-related problem with model data is face orientation. Some model data come in oriented properly, with surface normals either explicitly or implicitly pointing in the correct directions. For example, in CAD work, the standard is that the vertices in the polygon outline proceed in a counterclockwise direction when the frontface is viewed. This is called the winding direction and the triangles use the right-hand rule. Think of the fingers of your right hand wrapping around the polygon’s vertices in counterclockwise order. Your thumb then points in the direction of the polygon’s normal. This orientation is independent of the left-handed or right-handed view-space or world-coordinate orientation used, as it relies purely on the ordering of the vertices in the world, when looking at the front of the triangle. That said, if a reflection matrix is applied to an oriented mesh, each triangle’s normal will be reversed compared to its winding direction.

模型数据的一个质量相关问题是面向。有些模型数据的方向是正确的,表面法线或明或暗地指向正确的方向。例如,在CAD工作中,标准是当正面被观看时,多边形轮廓中的顶点以逆时针方向前进。这称为缠绕方向,三角形使用右手法则。想象你右手的手指以逆时针方向环绕多边形的顶点。然后你的拇指指向多边形的法线方向。这个方向独立于所使用的左手或右手视图空间或世界坐标方向,因为当看三角形的前面时,它纯粹依赖于世界中顶点的顺序。也就是说,如果将反射矩阵应用于定向网格,每个三角形的法线将与其缠绕方向相反。

Given a reasonable model, here is one approach to orient a polygonal mesh:
1. Form edge-face structures for all polygons.
2. Sort or hash the edges to find which edges match.
3. Find groups of polygons that touch each other.
4. For each group, flip faces as needed to obtain consistency.

给定一个合理的模型,下面是一种定向多边形网格的方法:

1.为所有多边形形成边面结构。

2.对边进行排序或散列,以找到匹配的边。

3.寻找相互接触的多边形组。

4.对于每个组,根据需要翻转面以获得一致性。

The first step is to create a set of half-edge objects. A half-edge is an edge of a polygon, with a pointer to its associated face (polygon). Since an edge is normally shared by two polygons, this data structure is called a half-edge. Create each halfedge with its first vertex stored before the second vertex, using sorting order. One vertex comes before another in sorting order if its x-coordinate value is smaller. If the x-coordinates are equal, then the y-value is used; if these match, then z is used. For example, vertex (−3, 5, 2) comes before vertex (−3, 6,−8); the −3s match, but 5 < 6.

第一步是创建一组半边对象。半边是一个多边形的边,有一个指针指向它的相关面(多边形)。因为一条边通常由两个多边形共享,所以这种数据结构被称为半边。使用排序顺序创建每个半边,其第一个顶点存储在第二个顶点之前。如果一个顶点的x坐标值较小,则该顶点在排序顺序中位于另一个顶点之前。如果x坐标相等,则使用y值;如果这些匹配,则使用z。例如,顶点 (−3, 5, 2)在顶点(−3, 6,−8)之前;−3s匹配,但5 < 6。

The goal is to find which edges are identical. Since each edge is stored so that the first vertex is less than the second, comparing edges is a matter of comparing first to first and second to second vertices. No permutations such as comparing one edge’s first vertex to another’s second vertex are needed. A hash table can be used to find matching edges [19, 542]. If all vertices have previously been merged, so that half-edges use the same vertex indices, then each half-edge can be matched by putting it on a temporary list associated with its first vertex index. A vertex has an average of 6 edges attached to it, making edge matching extremely rapid once grouped [1487].

目标是找出哪些边是相同的。由于存储每条边时,第一个顶点小于第二个顶点,因此比较边就是比较第一个顶点和第一个顶点以及第二个顶点和第二个顶点。不需要置换,例如将一条边的第一个顶点与另一条边的第二个顶点进行比较。哈希表可用于查找匹配边[19,542]。如果先前已经合并了所有顶点,使得半边使用相同的顶点索引,则可以通过将每个半边放在与其第一个顶点索引相关联的临时列表中来匹配该半边。一个顶点平均有6条边与之相连,一旦分组,边的匹配会非常迅速[1487]。

Once the edges are matched, connections among neighboring polygons are known,forming an adjacency graph. For a triangle mesh, this can be represented as a list for each triangle of its (up to) three neighboring triangle faces. Any edge that does not have two neighboring polygons is a boundary edge. The set of polygons that are connected by edges forms a continuous group. For example, a teapot model has two groups, the pot and the lid.

一旦边匹配,相邻多边形之间的连接是已知的,形成一个邻接图。对于三角形网格,这可以表示为其(最多)三个相邻三角形面的每个三角形的列表。没有两个相邻多边形的任何边都是边界边。由边连接的多边形集合形成一个连续的组。例如,茶壶模型有两组,壶和壶盖。

The next step is to give the mesh orientation consistency, e.g., we usually want all polygons to have counterclockwise outlines. For each continuous group of polygons,choose an arbitrary starting polygon. Check each of its neighboring polygons and determine whether the orientation is consistent. If the direction of traversal for the edge is the same for both polygons, then the neighboring polygon must be flipped. See Figure 16.10. Recursively check the neighbors of these neighbors, until all polygons in a continuous group are tested once.

下一步是给网格方向一致性,例如,我们通常希望所有的多边形都有逆时针的轮廓。对于每个连续的多边形组,选择一个任意的起始多边形。检查它的每个相邻多边形,并确定方向是否一致。如果两个多边形的边的遍历方向相同,则相邻的多边形必须翻转。参见图16.10。递归检查这些邻居的邻居,直到一个连续组中的所有多边形都被测试一次。

Figure 16.10. A starting polygon S is chosen and its neighbors are checked. Because the vertices in the edge shared by S and B are traversed in the same order (from x to y), the outline for B needs to be reversed to make it follow the right-hand rule. 

图16.10。选择起始多边形S并检查其邻居。因为S和B共享的边中的顶点以相同的顺序遍历(从x到y),所以B的轮廓需要反转以使其遵循右手法则。

Although all the faces are properly oriented at this point, they could all be oriented inward. In most cases we want them facing outward. One quick test for whether all faces should be flipped is to compute the signed volume of the group and check the sign.If it is negative, reverse all the loops and normals. Compute this volume by calculating the signed volume scalar triple product for each triangle and summing these. Look for the volume calculation in our online linear algebra appendix at realtimerendering.com.

尽管此时所有的面都正确定向,但是它们都可以向内定向。在大多数情况下,我们希望它们朝外。是否所有面都应该翻转的一个快速测试是计算该组的有符号体积并检查符号。如果是负数,反转所有的循环和法线。通过计算每个三角形的带符号体积标量三重积并求和来计算该体积。在realtimerendering.com在线线性代数附录中寻找体积计算。

This method works well for solid objects but is not foolproof. For example, if the object is a box forming a room, the user wants its normals to face inward toward the camera. If the object is not a solid, but rather a surface description, the problem of orienting each surface can become tricky to perform automatically. If, say, two cubes touch along an edge and are a part of the same mesh, that edge would be shared by four polygons, making orientation more difficult. One-sided objects such as M¨obius strips can never be fully oriented, since there is no separation of inside and outside. Even for well-behaved surface meshes it can be difficult to determine which side should face outward. Takayama et al. [1736] discuss previous work and present their own solution,casting random rays from each facet and determining which orientation is more visible from the outside.

这种方法适用于固体物体,但不是绝对安全的。例如,如果对象是一个形成房间的盒子,用户希望它的法线向内朝向相机。如果对象不是一个实体,而是一个曲面描述,那么自动定位每个曲面的问题会变得很棘手。比方说,如果两个立方体沿着一条边接触,并且是同一个网格的一部分,那么这条边将被四个多边形共享,这使得定向更加困难。像M obius带这样的单面物体永远不可能完全定向,因为没有内外分离。即使对于表现良好的曲面网格,也很难确定哪一侧应该面向外。Takayama等人[1736]讨论了以前的工作,并提出了他们自己的解决方案,从每个面投射随机光线,并确定从外面看哪个方向更明显。

16.3.3 Solidity坚固性

Informally, a mesh forms a solid if it is oriented and all the polygons visible from the outside have the same orientation. In other words, only one side of the mesh is visible.Such polygonal meshes are called closed or watertight.

非正式地说,如果一个网格被定向,并且从外部可见的所有多边形都具有相同的方向,那么它就形成了一个实体。换句话说,只有网格的一侧是可见的。这种多边形网格被称为封闭的或不透水的。

Knowing an object is solid means backface culling can be used to improve display efficiency, as discussed in Section 19.2. Solidity is also a critical property for objects casting shadow volumes (Section 7.3) and for several other algorithms. For example,a 3D printer requires that the mesh it prints be solid.

知道一个物体是实心的意味着背面剔除可以用来提高显示效率,如19.2节所讨论的。对于投射阴影体的物体(7.3节)和其他一些算法来说,坚固性也是一个重要的属性。例如,3D打印机要求它打印的网格是实心的。

The simplest test for solidity is to check if every polygon edge in the mesh is shared by exactly two polygons. This test is sufficient for most data sets. Such a surface is loosely referred to as being manifold, specifically, two-manifold. Technically,a manifold surface is one without any topological inconsistencies, such as having three or more polygons sharing an edge or two or more corners touching each other. A continuous surface forming a solid is a manifold without boundaries.

最简单的可靠性测试是检查网格中的每个多边形边是否正好被两个多边形共享。这个测试对大多数数据集来说是足够的。这种表面不严格地称为流形,具体地说,是二维流形。从技术上讲,流形曲面是没有任何拓扑不一致的曲面,例如有三个或三个以上的多边形共享一条边,或者两个或两个以上的角彼此接触。形成立体的连续曲面是没有边界的流形。

16.3.4 Normal Smoothing and Crease Edges正常平滑和折痕边缘

Some polygon meshes form curved surfaces, but the polygon vertices do not have normal vectors, so they cannot be rendered with the illusion of curvature. See Figure16.11.

一些多边形网格形成曲面,但是多边形顶点没有法向量,所以不能用曲率的错觉来渲染。参见图16.11

Figure 16.11. The object on the left does not have normals per vertex; the one on the right does. 

图16.11。左边的对象没有每顶点法线;右边的有。

Many model formats do not provide surface edge information. See Section 15.2 for the various types of edges. These edges are important for several reasons. They can highlight an area of the model made of a set of polygons or can help in nonphotorealistic rendering. Because they provide important visual cues, such edges are often favored to avoid being simplified by progressive mesh algorithms (Section 16.5).

许多模型格式不提供曲面边信息。各种类型的边缘见第15.2节。这些边缘很重要,原因有几个。它们可以高亮显示由一组多边形组成的模型区域,或者有助于非真实感渲染。因为它们提供了重要的视觉线索,这样的边经常被用来避免被渐进网格算法简化(第16.5节)。

Reasonable crease edges and vertex normals can usually be derived with some success from an oriented mesh. Once the orientation is consistent and the adjacency graph is derived, vertex normals can be generated by smoothing techniques. The model’s format may provide help by specifying smoothing groups for the polygon mesh.Smoothing group values are used to explicitly define which polygons in a group belong together to make up a curved surface. Edges between different smoothing groups are considered sharp.

合理的折痕边和顶点法线通常可以从定向网格中成功导出。一旦方向一致并且邻接图被导出,顶点法线可以通过平滑技术生成。模型的格式可以通过为多边形网格指定平滑组来提供帮助。平滑组值用于明确定义组中哪些多边形属于一个曲面。不同平滑组之间的边缘被认为是清晰的。

Another way to smooth a polygon mesh is to specify a crease angle. This value is compared to the dihedral angle, which is the angle between the plane normals of two polygons. Values typically range from 20 to 50 degrees. If the dihedral angle between two neighboring polygons is found to be lower than the specified crease angle, then these two polygons are considered to be in the same smoothing group. This technique is sometimes called edge preservation.

平滑多边形网格的另一种方法是指定折痕角度。该值与二面角进行比较,二面角是两个多边形的平面法线之间的角度。值通常在20到50度之间。如果发现两个相邻多边形之间的二面角小于指定的折痕角,则这两个多边形被视为在同一个平滑组中。这种技术有时被称为边缘保持。

Using a crease angle can sometimes give an improper amount of smoothing, rounding edges that should be creased, or vice versa. Often experimentation is needed, and no single angle may work perfectly for a mesh. Even smoothing groups have limitations.One example is when you pinch a sheet of paper in the middle. The sheet could be thought of as a single smoothing group, yet it has creases within it, which a smoothing group would smooth away. The modeler then needs multiple overlapping smoothing groups, or direct crease edge definition on the mesh. Another example is a cone made from triangles. Smoothing the cone’s whole surface gives the peculiar result that the tip has one normal pointing directly out along the cone’s axis. The cone tip is a singularity. For perfect representation of the interpolated normal, each triangle would need to be more like a quadrilateral, with two normals at this tip location [647].

使用折痕角度有时会产生不适当的平滑量,使应该有折痕的边变圆,反之亦然。通常需要实验,没有一个单一的角度可以完美地适用于一个网格。即使是平滑组也有局限性。一个例子是当你从中间捏一张纸。可以将纸张视为单个平滑组,但它内部有折痕,平滑组会将折痕平滑掉。然后,建模者需要多个重叠的平滑组,或者在网格上直接定义折痕边。另一个例子是由三角形组成的圆锥体。平滑圆锥体的整个表面会产生特殊的结果,即尖端有一个法线直接指向圆锥体的轴。锥尖是一个奇点。为了插值法线的完美表现,每个三角形需要更像一个四边形,在这个尖端位置有两条法线[647]。

Fortunately, such problematic cases are usually rare. Once a smoothing group is found, vertex normals can be computed for vertices shared within the group. The standard textbook solution for finding the vertex normal is to average the surface normals of the polygons sharing the vertex [541, 542]. However, this method can lead to inconsistent and poorly weighted results. Th¨urmer and W¨uthrich [1770] present an alternate method, in which each polygon normal’s contribution is weighted by the angle it forms at the vertex. This method has the desirable property of giving the same result whether a polygon sharing a vertex is triangulated or not. If the tessellated polygon turned into, say, two triangles sharing the vertex, the average normal method would incorrectly exert twice the influence from the two triangles as it would for the original polygon. See Figure 16.12.

幸运的是,这种有问题的案例通常很少。一旦找到平滑组,就可以为组内共享的顶点计算顶点法线。寻找顶点法线的标准教科书解决方案是平均共享顶点的多边形的表面法线[541,542]。然而,这种方法可能导致不一致和加权结果不佳。Th urmer和W uthrich [1770]提出了另一种方法,其中每个多边形法线的贡献由它在顶点形成的角度加权。这种方法有一个令人满意的特性,即无论一个共享一个顶点的多边形是否被三角化,都给出相同的结果。如果细分的多边形变成了两个共享顶点的三角形,平均法线方法将错误地施加两个三角形的两倍于原始多边形的影响。参见图16.12。

Figure 16.12. On the left, the surface normals of a quadrilateral and two triangles are averaged to give a vertex normal. In the middle, the quadrilateral has been triangulated. This results in the average normal shifting, since each polygon’s normal is weighted equally. On the right, Th¨urmer and W¨uthrich’s method weights each normal’s contribution by its angle between the pair of edges forming it, so triangulation does not shift the normal. 

图16.12。在左边,一个四边形和两个三角形的表面法线被平均以给出顶点法线。在中间,四边形已经被三角化。这导致平均法线偏移,因为每个多边形的法线权重相等。在右边,Th urmer和W uthrich的方法通过形成法线的一对边之间的角度对每个法线的贡献进行加权,因此三角剖分不会移动法线。

Max [1146] gives a different weighting method, based on the assumption that long edges form polygons that should affect the normal less. This type of smoothing may be superior when using simplification techniques, as larger polygons that are formed will be less likely to follow the surface’s curvature.

Max [1146]给出了一种不同的加权方法,该方法基于长边形成的多边形对法线的影响较小的假设。当使用简化技术时,这种类型的平滑可能更好,因为形成的较大多边形不太可能遵循表面的曲率。

Jin et al. [837] provide a comprehensive survey of these and other methods, concluding that weighting by angle is either the best or among the best under various conditions. Cignoni [268] implements a few methods in Meshlab and notes about the same. He also warns against weighting the contribution of each normal by the area of its associated triangle.

Jin等人[837]对这些方法和其他方法进行了全面的调查,得出的结论是,在各种条件下,按角度加权要么是最好的,要么是最好的。Cignoni [268]在Meshlab中实现了一些方法,并对此做了说明。他还警告说,不要用相关三角形的面积来衡量每条法线的贡献。

For heightfields, Shankel [1614] shows how taking the difference in heights of the neighbors along each axis can be used to rapidly approximate smoothing using the angle-weighted method. For a given point p and four neighboring points, px−1 and px+1 on the x axis of the heightfield and py−1 and py+1 on the y-axis, a close approximation of the (unnormalized) normal at p is

对于高度场,Shankel [1614]展示了如何通过角度加权法,利用沿各轴相邻高度的差异来快速近似平滑。对于给定点p和四个相邻点,即高度场x轴上的px−1和px+1以及y轴上的py−1和py+1,p处(未归一化)法线的近似表达式为

猜你喜欢

转载自blog.csdn.net/m0_37609239/article/details/126985924
今日推荐