Features
特征
This library contained in BRepFeat package is necessary for creation and manipulation of form and mechanical features that go beyond the classical boundary representation of shapes. In that sense, BRepFeat is an extension of BRepBuilderAPI package.
包含在 BRepFeat 包中的该库,用于创建和操作超出形状经典边界表示的形状特征和机械特征。从这个意义上讲,BRepFeat 是 BRepBuilderAPI 包的扩展。
Form Features
形状特征
The form features are depressions or protrusions including the following types:
形状特征是指凹坑或凸起,包括以下类型:
- Cylinder;
圆柱体; - Draft Prism;
拔模棱柱; - Prism;
棱柱; - Revolved feature;
旋转特征; - Pipe.
管道。
Depending on whether you wish to make a depression or a protrusion, you can choose either to remove matter (Boolean cut: Fuse equal to 0) or to add it (Boolean fusion: Fuse equal to 1).
根据需要创建凹坑或凸起,可选择去除材料(布尔切割:Fuse等于0)或添加材料(布尔融合:Fuse等于1)。
The semantics of form feature creation is based on the construction of shapes:
形状特征创建的语义基于以下形状构造方式:
- for a certain length in a certain direction;
在特定方向上延伸特定长度; - up to the limiting face;
延伸至限制面; - from the limiting face at a height;
从限制面起按高度延伸; - above and/or below a plane.
在平面上方和/或下方。
The shape defining the construction of a feature can be either a supporting edge or a concerned area of a face.
定义特征构造的形状可以是支撑边或面的相关区域。
In case of supporting edge, this contour can be attached to a face of the basis shape by binding. When the contour is bound to this face, the information that the contour will slide on the face becomes available to the relevant class methods. In case of the concerned area of a face, you can, for example, cut it out and move it at a different height, which defines the limiting face of a protrusion or depression.
Topological definition with local operations of this sort makes calculations simpler and faster than a global operation. The latter would entail a second phase of removing unwanted matter to get the same result.
The Form from BRepFeat package is a deferred class used as a root for form features. It inherits MakeShape from BRepBuilderAPI and provides implementation of methods keep track of all sub-shapes.
在支撑边的情况下,该轮廓可通过绑定方式附着到基础形状的某个面上。当此轮廓绑定到该面时,“轮廓将在面上滑动” 的信息便可供相关类方法使用。对于面的相关区域,例如可将其切割出来并在不同高度移动,这定义了凸起或凹陷的限制面。
这种通过局部操作进行的拓扑定义,使得计算相比全局操作更为简单且快速。后者需要通过第二阶段去除多余部分才能获得相同结果。
BRepFeat 包中的 Form 是一个延迟类,用作形状特征的根类。它从 BRepBuilderAPI 继承了 MakeShape,并提供了用于跟踪所有子形状的方法实现。
Prism
The class BRepFeat_MakePrism is used to build a prism interacting with a shape. It is created or initialized from
BRepFeat_MakePrism 类用于构建与形状交互的棱柱体。其创建或初始化基于以下参数:
- a shape (the basic shape),
一个形状(基础形状), - the base of the prism,
棱柱的底面, - a face (the face of sketch on which the base has been defined and used to determine whether the base has been defined on the basic shape or not),
一个面(草图所在的面,底面在此面上定义,用于判断底面是否定义在基础形状上), - a direction,
一个方向, - a Boolean indicating the type of operation (fusion=protrusion or cut=depression) on the basic shape,
一个布尔值,指示对基础形状执行的操作类型(融合=凸起或切割=凹陷), - another Boolean indicating if the self-intersections have to be found (not used in every case).
另一个布尔值,指示是否需要查找自相交(非所有情况均使用)。
There are six Perform methods:
共有六种 Perform 方法:
Method | Description |
---|---|
Perform(Height) | 生成的棱柱具有给定的长度。 |
Perform(Until) | 棱柱定义于底面位置与给定面之间。 |
Perform(From, Until) | 棱柱定义于两个面 From 和 Until 之间。 |
PerformUntilEnd() | 棱柱为半无限延伸,由底面的实际位置限制。 |
PerformFromEnd(Until) | 棱柱为半无限延伸,由面 Until 限制。 |
PerformThruAll() | 棱柱为无限延伸。若为凹陷操作,结果类似用无限棱柱切割;若为凸起操作,结果不保留无限部分。 |
Note that Add method can be used before Perform methods to indicate that a face generated by an edge slides onto a face of the base shape.
注意:可在调用 Perform 方法前使用 Add 方法,用于指示边生成的面在基础形状的面上滑动。
代码示例
以下代码执行凸起操作(即将形状的面转换为棱柱):
TopoDS_Shape Sbase = ...; // 初始形状
TopoDS_Face Fbase = ....; // 棱柱底面 gp_Dir Extrusion (.,.,.); // extrusion 方向 // 传入空面作为草图面
BRepFeat_MakePrism thePrism(Sbase, Fbase, TopoDS_Face(), Extrusion, Standard_True, Standard_True); thePrism.Perform(100.); // 执行高度为100的棱柱操作
if (thePrism.IsDone()) { TopoDS_Shape theResult = thePrism; // 后续处理 ...
}
Fusion with MakePrism
使用 MakePrism 进行融合操作
Creating a prism between two faces with Perform()
通过 Perform() 方法在两个面之间创建棱柱体
Draft Prism
拔模棱柱
The class BRepFeat_MakeDPrism is used to build draft prism topologies interacting with a basis shape. These can be depressions or protrusions. A class object is created or initialized from:
BRepFeat_MakeDPrism 类用于构建与基础形状交互的拔模棱柱拓扑结构,可实现凹陷或凸起特征。类对象通过以下参数创建或初始化:
- a shape (basic shape),
一个形状(基础形状), - the base of the prism,
棱柱的底面, - a face (face of sketch on which the base has been defined and used to determine whether the base has been defined on the basic shape or not),
一个面(草图所在的面,底面在此面上定义,用于判断底面是否定义在基础形状上), - an angle,
一个角度, - a Boolean indicating the type of operation (fusion=protrusion or cut=depression) on the basic shape,
一个布尔值,指示对基础形状执行的操作类型(融合=凸起或切割=凹陷), - another Boolean indicating if self-intersections have to be found (not used in every case).
另一个布尔值,指示是否需要查找自相交(非所有情况均使用)。
Evidently, the input data for MakeDPrism are the same as for MakePrism except for a new parameter Angle
and a missing parameter Direction
: the direction of the prism generation is determined automatically as the normal to the base of the prism. The semantics of draft prism feature creation is based on the construction of shapes:
显然,除新增参数 Angle
和移除参数 Direction
外,MakeDPrism 的输入数据与 MakePrism 一致。棱柱生成方向自动确定为底面的法线方向。拔模棱柱特征的创建语义基于以下形状构造方式:
- along a length
沿指定长度 - up to a limiting face
延伸至限制面 - from a limiting face to a height
从限制面到指定高度
The shape defining construction of the draft prism feature can be either the supporting edge or the concerned area of a face.
拔模棱柱特征的形状定义方式包括支撑边或面的相关区域:
In case of the supporting edge, this contour can be attached to a face of the basis shape by binding. When the contour is bound to this face, the information that the contour will slide on the face becomes available to the relevant class methods.
当使用支撑边时,轮廓可通过绑定附加到基础形状的面上。当轮廓绑定到该面后,相关类方法将获取“轮廓在面上滑动”的信息。
In case of the concerned area of a face, it is possible to cut it out and move it to a different height, which will define the limiting face of a protrusion or depression direction.
当使用面的相关区域时,可将其切割并移动到不同高度,从而定义凸起或凹陷方向的限制面。
The Perform methods are the same as for MakePrism.
Perform 方法与 MakePrism 完全一致。
代码示例:创建 tapered prism(锥形棱柱)
// 初始化基础形状(创建长方体)
TopoDS_Shape S = BRepPrimAPI_MakeBox(400., 250., 300.); // 遍历获取目标面(此处通过Explorer获取第5个面)
TopExp_Explorer Ex;
Ex.Init(S, TopAbs_FACE);
Ex.Next(); Ex.Next(); Ex.Next(); Ex.Next(); Ex.Next();
TopoDS_Face F = TopoDS::Face(Ex.Current()); // 提取面的几何曲面
Handle(Geom_Surface) surf = BRep_Tool::Surface(F); // 定义2D圆轮廓(圆心(200,130),半径50,X轴方向)
gp_Circ2d c(gp_Ax2d(gp_Pnt2d(200., 130.), gp_Dir2d(1., 0.)), 50.); // 构建2D轮廓线(半圆+半圆闭合)
BRepBuilderAPI_MakeWire MW;
Handle(Geom2d_Curve) aline = new Geom2d_Circle(c);
MW.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., PI));
MW.Add(BRepBuilderAPI_MakeEdge(aline, surf, PI, 2.*PI)); // 基于曲面和轮廓构建面
BRepBuilderAPI_MakeFace MKF;
MKF.Init(surf, Standard_False);
MKF.Add(MW.Wire());
TopoDS_Face FP = MKF.Face();
BRepLib::BuildCurves3d(FP); // 创建拔模棱柱操作(参数:基础形状、底面、草图面、角度10°、凸起操作、启用自相交检测)
BRepFeat_MakeDPrism MKDP (S, FP, F, 10*PI/180, Standard_True, Standard_True);
MKDP.Perform(200); // 执行高度为200的拔模操作
TopoDS_Shape res1 = MKDP.Shape(); // 获取结果形状
Revolution
旋转特征
The class BRepFeat_MakeRevol is used to build a revolution interacting with a shape. It is created or initialized from:
BRepFeat_MakeRevol 类用于构建与形状交互的旋转特征。其创建或初始化参数如下:
- a shape (the basic shape,)
一个形状(基础形状), - the base of the revolution,
旋转的底面, - a face (the face of sketch on which the base has been defined and used to determine whether the base has been defined on the basic shape or not),
一个面(草图所在的面,底面在此面上定义,用于判断底面是否定义在基础形状上), - an axis of revolution,
旋转轴, - a boolean indicating the type of operation (fusion=protrusion or cut=depression) on the basic shape,
一个布尔值,指示对基础形状执行的操作类型(融合=凸起或切割=凹陷), - another boolean indicating whether the self-intersections have to be found (not used in every case).
另一个布尔值,指示是否需要查找自相交(非所有情况均使用)。
Perform 方法
There are four Perform methods:
共有四种 Perform 方法:
Method | Description |
---|---|
Perform(Angle) | 生成指定角度大小的旋转特征。 |
Perform(Until) | 旋转范围定义为从底面当前位置到给定面之间。 |
Perform(From, Until) | 旋转范围定义为两个面 From 和 Until 之间。 |
PerformThruAll() | 结果类似于 Perform(2*PI),即完整旋转一周。 |
Note that Add method can be used before Perform methods to indicate that a face generated by an edge slides onto a face of the base shape.
注意:可在调用 Perform 方法前使用 Add 方法,用于指示边生成的面在基础形状的面上滑动。
代码示例:旋转操作(受限面限制)
TopoDS_Shape Sbase = ...; // 初始形状
TopoDS_Face Frevol = ....; // 旋转底面
TopoDS_Face FUntil = ....; // 限制旋转的面 gp_Dir RevolDir (.,.,.); // 旋转方向
gp_Ax1 RevolAx(gp_Pnt(.,.,.), RevolDir); // 旋转轴 // 传入空面作为草图面
BRepFeat_MakeRevol theRevol(Sbase, Frevol, TopoDS_Face(), RevolAx, Standard_True, Standard_True); theRevol.Perform(FUntil); // 执行旋转直到FUntil面
if (theRevol.IsDone()) { TopoDS_Shape theResult = theRevol; // 后续处理 ...
}
Pipe
管道特征
The class BRepFeat_MakePipe constructs compound shapes with pipe features: depressions or protrusions. A class object is created or initialized from:
BRepFeat_MakePipe 类用于构建带有管道特征的复合形状(凹陷或凸起)。其创建或初始化参数如下:
- a shape (basic shape),
一个形状(基础形状), - a base face (profile of the pipe)
一个底面(管道截面轮廓), - a face (face of sketch on which the base has been defined and used to determine whether the base has been defined on the basic shape or not),
一个面(草图所在的面,底面在此面上定义,用于判断底面是否定义在基础形状上), - a spine wire
一条路径线(管道中心线), - a Boolean indicating the type of operation (fusion=protrusion or cut=depression) on the basic shape,
一个布尔值,指示对基础形状执行的操作类型(融合=凸起或切割=凹陷), - another Boolean indicating if self-intersections have to be found (not used in every case).
另一个布尔值,指示是否需要查找自相交(非所有情况均使用)。
Perform 方法
There are three Perform methods:
共有三种 Perform 方法:
Method | Description |
---|---|
Perform() | 管道沿整个路径线(中心线)定义。 |
Perform(Until) | 管道沿路径延伸直到给定面。 |
Perform(From, Until) | 管道定义在两个面 From 和 Until 之间。 |
代码示例:创建管道特征
// 创建基础形状(长方体)
TopoDS_Shape S = BRepPrimAPI_MakeBox(400., 250., 300.); // 遍历获取目标面(第2个面)
TopExp_Explorer Ex;
Ex.Init(S, TopAbs_FACE);
Ex.Next(); Ex.Next();
TopoDS_Face F1 = TopoDS::Face(Ex.Current());
Handle(Geom_Surface) surf = BRep_Tool::Surface(F1); // 构建管道截面轮廓(三角形)
BRepBuilderAPI_MakeWire MW1;
gp_Pnt2d p1, p2; // 第一条边
p1 = gp_Pnt2d(100., 100.);
p2 = gp_Pnt2d(200., 100.);
Handle(Geom2d_Line) aline = GCE2d_MakeLine(p1, p2).Value();
MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))); // 第二条边
p1 = p2;
p2 = gp_Pnt2d(150., 200.);
aline = GCE2d_MakeLine(p1, p2).Value();
MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))); // 第三条边(闭合三角形)
p1 = p2;
p2 = gp_Pnt2d(100., 100.);
aline = GCE2d_MakeLine(p1, p2).Value();
MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))); // 基于曲面和轮廓构建面
BRepBuilderAPI_MakeFace MKF1;
MKF1.Init(surf, Standard_False);
MKF1.Add(MW1.Wire());
TopoDS_Face FP = MKF1.Face();
BRepLib::BuildCurves3d(FP); // 定义管道路径线(贝塞尔曲线)
TColgp_Array1OfPnt CurvePoles(1, 3);
gp_Pnt pt = gp_Pnt(150., 0., 150.);
CurvePoles(1) = pt;
pt = gp_Pnt(200., 100., 150.);
CurvePoles(2) = pt;
pt = gp_Pnt(150., 200., 150.);
CurvePoles(3) = pt; Handle(Geom_BezierCurve) curve = new Geom_BezierCurve(CurvePoles);
TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve);
TopoDS_Wire W = BRepBuilderAPI_MakeWire(E); // 创建管道特征(参数:基础形状、截面轮廓、草图面、路径线、切割操作、启用自相交检测)
BRepFeat_MakePipe MKPipe (S, FP, F1, W, Standard_False, Standard_True);
MKPipe.Perform(); // 执行管道操作
TopoDS_Shape res1 = MKPipe.Shape(); // 获取结果形状
Mechanical Features
机械特征
Mechanical features include ribs, protrusions and grooves (or slots), depressions along planar (linear) surfaces or revolution surfaces.
机械特征包括筋、凸起、凹槽(或槽)以及沿平面(线性)表面或旋转表面的凹陷。
The semantics of mechanical features is built around giving thickness to a contour. This thickness can either be symmetrical – on one side of the contour – or dissymmetrical – on both sides. As in the semantics of form features, the thickness is defined by construction of shapes in specific contexts.
机械特征的语义核心是为轮廓赋予厚度。厚度可以是对称的(位于轮廓一侧)或不对称的(位于两侧)。与形状特征类似,厚度通过在特定上下文中构造形状来定义。
The development contexts differ, however, in the case of mechanical features. Here they include extrusion:
然而,机械特征的构建上下文有所不同,包括以下拉伸方式:
- to a limiting face of the basis shape;
到基础形状的限制面; - to or from a limiting plane;
到或从限制平面; - to a height.
到指定高度。
类初始化参数
A class object is created or initialized from:
类对象通过以下参数创建或初始化:
- a shape (basic shape);
一个形状(基础形状); - a wire (base of rib or groove);
一条线(筋或槽的基础轮廓); - a plane (plane of the wire);
一个平面(轮廓所在的平面); - direction1 (a vector along which thickness will be built up);
方向1(厚度增加的方向向量); - direction2 (vector opposite to the previous one along which thickness will be built up, may be null);
方向2(与方向1相反的方向向量,厚度增加方向,可为空); - a Boolean indicating the type of operation (fusion=rib or cut=groove) on the basic shape;
一个布尔值,指示对基础形状执行的操作类型(融合=筋或切割=槽); - another Boolean indicating if self-intersections have to be found (not used in every case).
另一个布尔值,指示是否需要查找自相交(非所有情况均使用)。
Linear Form
线性形状
Linear form is implemented in MakeLinearForm class, which creates a rib or a groove along a planar surface. There is one Perform() method, which performs a prism from the wire along the direction1 and direction2 interacting with base shape Sbase. The height of the prism is Magnitude(Direction1)+Magnitude(direction2).
线性形状由 MakeLinearForm 类实现,用于沿平面创建筋或槽。该类有一个 Perform() 方法,沿 direction1 和 direction2 方向从轮廓线创建棱柱,并与基础形状 Sbase 交互。棱柱高度为 Direction1 长度与 Direction2 长度之和。
代码示例:创建筋特征
// 构建基础轮廓线(六边形)
BRepBuilderAPI_MakeWire mkw;
gp_Pnt p1 = gp_Pnt(0., 0., 0.);
gp_Pnt p2 = gp_Pnt(200., 0., 0.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1, p2)); p1 = p2;
p2 = gp_Pnt(200., 0., 50.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1, p2)); p1 = p2;
p2 = gp_Pnt(50., 0., 50.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1, p2)); p1 = p2;
p2 = gp_Pnt(50., 0., 200.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1, p2)); p1 = p2;
p2 = gp_Pnt(0., 0., 200.);
mkw.Add(BRepBuilderAPI_MakeEdge(p1, p2)); p1 = p2;
mkw.Add(BRepBuilderAPI_MakeEdge(p2, gp_Pnt(0., 0., 0.))); // 基于轮廓创建基础形状(拉伸为棱柱)
TopoDS_Shape S = BRepBuilderAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()), gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(0., 100., 0.))
); // 定义筋的轮廓线(斜线段)
TopoDS_Wire W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 45., 100.), gp_Pnt(100., 45., 50.))
); // 定义轮廓所在平面
Handle(Geom_Plane) aplane = new Geom_Plane(gp_Pnt(0., 45., 0.), gp_Vec(0., 1., 0.)
); // 创建线性形状特征(参数:基础形状、轮廓线、平面、方向1、方向2、操作类型、自相交检测)
BRepFeat_MakeLinearForm aform(S, W, aplane, gp_Dir(0., 5., 0.), // 正向厚度方向(Y轴正方向)gp_Dir(0., -3., 0.), // 负向厚度方向(Y轴负方向)1, Standard_True // 操作类型:融合(创建筋)
); aform.Perform(); // 执行操作
TopoDS_Shape res = aform.Shape(); // 获取结果形状
Gluer
粘合器
The class BRepFeat_Gluer allows gluing two solids along faces. The contact faces of the glued shape must not have parts outside the contact faces of the basic shape. Upon completion the algorithm gives the glued shape with cut out parts of faces inside the shape.
BRepFeat_Gluer 类用于沿面粘合两个实体。被粘合形状的接触面不得超出基础形状的接触面范围。算法执行完毕后,粘合形状会剪切掉内部的面部分。
The class is created or initialized from two shapes: the “glued” shape and the basic shape (on which the other shape is glued). Two Bind methods are used to bind a face of the glued shape to a face of the basic shape and an edge of the glued shape to an edge of the basic shape.
该类通过两个形状创建或初始化:“被粘合”形状和基础形状(另一个形状粘合到基础形状上)。使用两种 Bind 方法将被粘合形状的面绑定到基础形状的面,以及将被粘合形状的边绑定到基础形状的边。
Note that every face and edge has to be bounded, if two edges of two glued faces are coincident they must be explicitly bounded.
请注意,每个面和边必须是有界的;如果两个粘合面的边重合,必须显式界定。
代码示例:粘合两个形状
TopoDS_Shape Sbase = ...; // 基础形状
TopoDS_Shape Sglued = ...; // 被粘合形状 TopTools_ListOfShape Lfbase;
TopTools_ListOfShape Lfglued;
// 确定粘合面
... BRepFeat_Gluer theGlue(Sglued, Sbase);
TopTools_ListIteratorOfListOfShape itlb(Lfbase);
TopTools_ListIteratorOfListOfShape itlg(Lfglued);
for (; itlb.More(); itlb.Next(), itlg.Next()) { const TopoDS_Face& f1 = TopoDS::Face(itlg.Value()); const TopoDS_Face& f2 = TopoDS::Face(itlb.Value()); theGlue.Bind(f1, f2); // 绑定面// 例如,使用LocOpe中的FindEdges类确定重合边LocOpe_FindEdge fined(f1, f2); for (fined.InitIterator(); fined.More(); fined.Next()) { theGlue.Bind(fined.EdgeFrom(), fined.EdgeTo()); // 绑定边}
}
theGlue.Build(); // 执行粘合
if (theGlue.IsDone()) { TopoDS_Shape theResult = theGlue; ...
}
Split Shape
形状分割
The class BRepFeat_SplitShape is used to split faces of a shape into wires or edges. The shape containing the new entities is rebuilt, sharing the unmodified ones.
BRepFeat_SplitShape 类用于将形状的面分割为线框或边。包含新实体的形状会被重建,并共享未修改的实体。
The class is created or initialized from a shape (the basic shape). Three Add methods are available:
该类通过一个形状(基础形状)创建或初始化,提供三种 Add 方法:
- Add(Wire, Face) – adds a new wire on a face of the basic shape.
Add(线框, 面) – 在基础形状的面上添加新线框。 - Add(Edge, Face) – adds a new edge on a face of the basic shape.
Add(边, 面) – 在基础形状的面上添加新边。 - Add(EdgeNew, EdgeOld) – adds a new edge on an existing one (the old edge must contain the new edge).
Add(新边, 旧边) – 在现有边上添加新边(旧边必须包含新边)。
Note: The added wires and edges must define closed wires on faces or wires located between two existing edges. Existing edges must not be intersected.
注意:添加的线框和边必须在面上定义闭合线框,或位于两个现有边之间的线框。现有边不得相交。
代码示例:分割面
TopoDS_Shape Sbase = ...; // 基础形状
TopoDS_Face Fsplit = ...; // Sbase的面
TopoDS_Wire Wsplit = ...; // 包含在Fsplit中的新线框 BRepFeat_SplitShape Spls(Sbase);
Spls.Add(Wsplit, Fsplit); // 添加线框到面
TopoDS_Shape theResult = Spls;
...