Sewing
缝合
Introduction
简介
Sewing allows creation of connected topology (shells and wires) from a set of separate topological elements (faces and edges). For example, Sewing can be used to create a shell from a compound of separate faces.
缝合可从一组独立的拓扑元素(面和边)创建连通的拓扑结构(壳和线框)。例如,缝合可用于从独立面的组合中创建壳。
Shapes with partially shared edges
具有部分共享边的形状
It is important to distinguish between sewing and other procedures, which modify the geometry, such as filling holes or gaps, gluing, bending curves and surfaces, etc.
区分缝合与其他修改几何形状的过程(如填充孔洞或间隙、粘合、弯曲曲线和曲面等)非常重要。
Sewing does not change the geometrical representation of the shapes. Sewing applies to topological elements (faces, edges) which are not connected but can be connected because they are geometrically coincident: it adds the information about topological connectivity. Already connected elements are left untouched in case of manifold sewing.
缝合不会改变形状的几何表示。缝合适用于未连通但因几何重合而可以连通的拓扑元素(面、边):它添加拓扑连通性信息。在流形缝合的情况下,已连通的元素保持不变。
Let us define several terms:
定义几个术语:
- Floating edges: do not belong to any face;
浮动边:不属于任何面; - Free boundaries: belong to one face only;
自由边界:仅属于一个面; - Shared edges: belong to several faces (i.e. two faces in a manifold topology).
共享边:属于多个面(如流形拓扑中的两个面)。
Sewn faces should have edges shared with each other.
缝合面应具有相互共享的边。
Sewn edges should have vertices shared with each other.
缝合边应具有相互共享的顶点。
Sewing Algorithm
缝合算法
The sewing algorithm is one of the basic algorithms used for shape processing, therefore its quality is very important.
缝合算法是用于形状处理的基础算法之一,因此其质量至关重要。
Implementation
实现
Sewing algorithm is implemented in the class BRepBuilder_Sewing. This class provides the following methods:
缝合算法在 BRepBuilder_Sewing 类中实现,该类提供以下方法:
- loading initial data for global or local sewing;
加载全局或局部缝合的初始数据; - setting customization parameters, such as special operation modes, tolerances and output results;
设置自定义参数,如特殊操作模式、公差和输出结果; - applying analysis methods that can be used to obtain connectivity data required by external algorithms;
应用分析方法以获取外部算法所需的连通性数据; - sewing of the loaded shapes.
对已加载的形状执行缝合。
Sewing supports working mode with big value tolerance. It is not necessary to repeat sewing step by step while smoothly increasing tolerance.
缝合支持大公差工作模式,无需在逐步增大公差时重复缝合步骤。
Stages of the Algorithm
算法阶段
The Sewing algorithm can be subdivided into several independent stages, some of which can be turned on or off using Boolean or other flags.
缝合算法可分为多个独立阶段,其中部分阶段可通过布尔值或其他标志启用或禁用。
In brief, the algorithm should find a set of merge candidates for each free boundary, filter them according to certain criteria, and finally merge the found candidates and build the resulting sewn shape.
简而言之,算法需为每个自由边界找到一组合并候选,根据特定标准过滤,最终合并找到的候选并构建缝合后的形状。
Key Parameters
关键参数
Each stage of the algorithm or the whole algorithm can be adjusted with the following parameters:
算法的每个阶段或整个算法可通过以下参数调整:
- Working tolerance: Defines the maximal distance between topological elements which can be sewn. It is not ultimate that such elements will be actually sewn as many other criteria are applied to make the final decision.
工作公差:定义可缝合的拓扑元素间的最大距离。由于需结合其他标准决策,满足该公差的元素未必一定会被缝合。 - Minimal tolerance: Defines the size of the smallest element (edge) in the resulting shape. No edges with size less than this value are created after sewing.
最小公差:定义结果形状中最小元素(边)的尺寸。缝合后不会生成小于该值的边。 - Non-manifold mode: Enables sewing of non-manifold topology.
非流形模式:启用非流形拓扑的缝合。
Example
示例
To connect a set of n contiguous but independent faces:
连接n个相邻但独立的面:
BRepBuilderAPI_Sewing Sew;
Sew.Add(Face1);
Sew.Add(Face2);
...
Sew.Add(Facen);
Sew.Perform();
TopoDS_Shape result = Sew.SewedShape();
If all faces have been sewn correctly, the result is a shell. Otherwise, it is a compound. After a successful sewing operation, all faces have a coherent orientation.
若所有面正确缝合,结果为壳;否则为组合体。成功缝合后,所有面具有一致的方向。
Tolerance Management
公差管理
Recommendations for tuning the sewing process:
缝合过程的调优建议:
- Use small working tolerance: Reduces sewing time and minimizes incorrectly sewn edges for shells with free boundaries.
使用小工作公差:减少缝合时间,并降低自由边界壳的错误缝合边数量。 - Use large minimal tolerance: Reduces small geometry in the shape (both original and generated after cutting).
使用大最小公差:减少形状中的微小几何(包括原始和切割后生成的)。 - For shells with holes: Set working tolerance ≤ the smallest element size of free boundaries to avoid partial sewing.
带孔壳场景:设置工作公差≤自由边界的最小元素尺寸,避免部分缝合。
Manifold and Non-manifold Sewing
流形与非流形缝合
- Manifold sewing: Merges only two nearest edges (from different faces or one closed face). Produces only manifold shells.
流形缝合:仅合并两条最近的边(来自不同面或一个闭合面),仅生成流形壳。 - Non-manifold sewing: Merges all edges within the specified tolerance. Used for non-manifold shells.
非流形缝合:合并指定公差内的所有边,用于非流形壳。
Best practice: Apply manifold sewing first, then non-manifold sewing with minimal tolerance for complex topologies.
最佳实践:复杂拓扑先使用流形缝合,再用最小公差进行非流形缝合。
Local Sewing
局部缝合
Local sewing is used to stitch remaining non-sewn elements with a larger tolerance, especially for open shells. It preserves existing connections of the whole shape.
局部缝合用于以更大公差缝合剩余未缝合元素,尤其适用于开放壳,且保留整体形状的现有连接。
Example workflow:
示例流程:
// 初始缝合形状
TopoDS_Shape aS1, aS2; // 预期为已正确缝合的壳
TopoDS_Shape aComp;
BRep_Builder aB;
aB.MakeCompound(aComp);
aB.Add(aComp, aS1);
aB.Add(aComp, aS2);
BRepBuilderAPI_Sewing aSewing;
aSewing.Load(aComp); // 加载组合体
// 添加需要局部缝合的子形状
aSewing.Add(aF1);
aSewing.Add(aF2);
// 执行缝合
aSewing.Perform();
TopoDS_Shape aRes = aSewing.SewedShape(); // 获取结果形状
Local sewing is faster than global sewing and allows selective stitching of specific regions.
局部缝合比全局缝合更快,且支持对特定区域的选择性缝合。