原文: Open Cascade造型算法——倒圆与倒角
eryar@163.com
使用类BRepFilletAPI_MakeFillet来为形状添加倒圆。倒圆是用光滑面来代替角边。使用方法如下:
l 首先,给定一个需要倒圆的形状;
l 然后,通过Add方法来添加描述倒圆的参数,倒圆所需的参数包括一个边edge和半径radius。当然,边edge必须由两个面face所共有。倒圆会将原来的边替换成光滑的圆面过渡。
l 最后,通过询问结果来执行倒圆操作。
注:添加一个倒圆两次并不会出错,因为只保留了最后一次添的倒圆。
Figure 1. Filleting two edges using radius r1 and r2
下面给出一个将创建一个倒圆的长方体,其尺寸分别为a,b,c,倒圆半径r。
Figure 2. Filleting a box
代码如下所示,创建上图所示的倒圆的长方体的参数分别为:
a = 100,b = 60,c = 80,r = 10:
#include
#include
#include
#include
#include
#include
TopoDS_Shape FilletedBox(const Standard_Real a,
const Standard_Real b,
const Standard_Real c,
const Standard_Real r)
{
TopoDS_Solid Box = BRepPrimAPI_MakeBox(a,b,c);
BRepFilletAPI_MakeFillet MF(Box);
// add all the edges to fillet
TopExp_Explorer ex(Box,TopAbs_EDGE);
while (ex.More())
{
MF.Add(r,TopoDS::Edge(ex.Current()));
ex.Next();
}
return MF.Shape();
}
如下图所示为创建一个半径变化的倒圆操作:
Figure 3. Evolutive radius fillet
Figure 4. Evolutive radius fillet a box
程序代码如下所示:
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200, 200, 200);
BRepFilletAPI_MakeFillet Rake(theBox);
ChFi3d_FilletShape FSH = ChFi3d_Rational;
Rake.SetFilletShape(FSH);
TColgp_Array1OfPnt2d parAndRad(1, 6);
parAndRad.SetValue(1, gp_Pnt2d(0, 10));
parAndRad.SetValue(2, gp_Pnt2d(50, 20));
parAndRad.SetValue(3, gp_Pnt2d(70, 20));
parAndRad.SetValue(4, gp_Pnt2d(130, 60));
parAndRad.SetValue(5, gp_Pnt2d(160, 30));
parAndRad.SetValue(6, gp_Pnt2d(200, 20));
TopExp_Explorer ex(theBox, TopAbs_EDGE);
Rake.Add(parAndRad, TopoDS::Edge(ex.Current()));
TopoDS_Shape evolvedBox = Rake.Shape();
BRepFilletAPI_MakeFillet2d is used to construct fillets and chamfers on planar faces.
我按照示例代码运行了一下程序,结果程序总是崩溃,其操作的效果不得而知,所以也得不到真实的效果图。将其程序代码列出如下所示:
PS:我想应该是TopExp_Explorer的问题吧,顶点构成边时共享使用了多次,改用TopExp::MapShapes(srcFace,TopAbs_VERTEX,mapVertex);即可。
#include “BRepPrimAPI_MakeBox.hxx”
#include “TopoDS_Shape.hxx”
#include “TopExp_Explorer.hxx”
#include “BRepFilletAPI_MakeFillet2d.hxx”
#include “TopoDS.hxx”
#include “TopoDS_Solid.hxx”
TopoDS_Shape FilletFace(const Standard_Real a,
const Standard_Real b,
const Standard_Real c,
const Standard_Real r)
{
TopoDS_Solid Box = BRepPrimAPI_MakeBox (a,b,c);
TopExp_Explorer ex1(Box,TopAbs_FACE);
const TopoDS_Face& F = TopoDS::Face(ex1.Current());
BRepFilletAPI_MakeFillet2d MF(F);
TopExp_Explorer ex2(F, TopAbs_VERTEX);
while (ex2.More())
{
MF.AddFillet(TopoDS::Vertex(ex2.Current()),r);
ex2.Next();
}
// while...
return MF.Shape();
}
类BREpFilletAPI_MakeChamfer的使用方法与BRepFilletAPI_MakeFillet大致类似,但稍有不同:
a) The surfaces created are ruled and not smooth;
b) The Add syntax for selecting edges requires one or two distances, one edge and one face(contiguous to the edge);
Add(dist, E, F);
Add(d1, d2, E, F); with d1 on the face F.
Figure 5. Creating a chamfer
Figure 6. The box with chamfers
程序代码如下所示:
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(130,200,170);
BRepFilletAPI_MakeChamfer MC(theBox);
TopTools_IndexedDataMapOfShapeListOfShape M;
TopExp::MapShapesAndAncestors(theBox,TopAbs_EDGE,TopAbs_FACE,M);
for (Standar1d_Integer i;i