//方法1
gp_Pnt pt1(0,0,0);//gp_Pnt类定义点包含double的xyz。
gp_Pnt pt2(1,1,1);
TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(pt1,pt2);
//方法2
//TColgp_Array1OfPnt类定义点的数组。NCollection_Array1类定义了一个Array
TColgp_Array1OfPnt array(1, num);
for (int i = 1; i <= num; ++i)
{
array.SetValue(i, list[i - 1]);
}
GeomAPI_PointsToBSpline Approx(array);//GeomAPI_PointsToBSpline类用一组点近似得到BSpline曲线。***展开相关类
Handle_Geom_BSplineCurve K = Approx.Curve();//Geom_BSplineCurve类是B_spline 曲线的定义
TopoDS_Edge shape = BRepBuilderAPI_MakeEdge(K);//提供构建edge的方法。
TopoDS_Edge edge1,edge2,edge3,edge4;
TopoDS_Wire wireSrc = BRepBuilderAPI_MakeWire(edge4);
TopoDS_Wire four_wire = BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4);
TopoDS_Face four_face = BRepBuilderAPI_MakeFace(four_wire);
TopoDS_Edge edge1,edge2,edge3,edge4;
BRepBuilderAPI_MakeWire wire;//导线,由边组成。
wire.Add(edge1);
wire.Add(edge2);
wire.Add(edge3);
wire.Add(edge4);
if (!wire.IsDone())
return false;
wireRect = wire.Wire();
TopoDS_Face face1 = BRepBuilderAPI_MakeFace(wire1);
BRepBuilderAPI_MakeFace mf;
mf.Init(face);
mf.Add(holeWire);
if (!mf.IsDone())
return false;
TopoDS_Face face2 = mf.Face();
BRepBuilderAPI_MakeFace builder(gp_Pln(gp_Pnt(0,0,0), gp_Dir(0,0,1)));
if (!builder.IsDone())
return;
TopoDS_Shape shape = builder.Shape();
TopoDS_Face face = BRepFill::Face(TopoDS::Edge(shape1), TopoDS::Edge(shape2));
TopoDS_Shell shell = BRepFill::Shell(TopoDS::Wire(shape1), TopoDS::Wire(shape2));
//构建 复合模型
BRep_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
BRepBuilderAPI_MakeSolid solid(*shell1);
if (!solid.IsDone())
return false;
TopoDS_Shape coverSolid = solid.Solid();
gp_Ax2 ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 30));
TopoDS_Shape cylinder = BRepPrimAPI_MakeCylinder(ax2, radius, height).Shape();
TopoDS_Shape box = BRepPrimAPI_MakeBox(x, y, z);
TopoDS::Face 相关。 TopoDS包 是用于定义拓扑信息。
//类型转换都类似,这里只是列举2个
TopoDS_Wire wire = TopoDS::Wire(shape);//类型转换
TopoDS_Face face = TopoDS::Face(mk.Shape());
注意: 扫描,拉伸,回转拉伸本质相同
拉伸命令
BRepPrimAPI_MakePrism类 。拓扑信息实体化,支持最简单的方体,锥形,圆柱,球体,还有基础形状的扫略拉伸。
另外:dir给负数可以挖洞。
//height的正负是拉伸的方向。
TopoDS_Shape shapeRes = BRepPrimAPI_MakePrism(wireSrc, gp_Vec(0, -height, 0));
BRepPrimAPI_MakePrism PrismMaker(from, Ltotal*gp_Vec(dir), 0, 1); // finite prism
TopoDS_Shape shapeRes;
if (PrismMaker.IsDone())
shapeRes = PrismMaker.Shape();
旋转扫描命令
BRepPrimAPI_MakeRevol类 生成生成旋转扫描拓扑。
TopoDS_Shape shape= BRepPrimAPI_MakeRevol(wire, gp::OZ());
BRepPrimAPI_MakeRevol mkRevol(mkFace.Face(), gp_Ax1(gp_Pnt(0,0,0), gp_Dir(0,0,1)),
Base::toRadians<double>(angle3), Standard_True);
TopoDS_Shape shape = mkRevol.Shape();
BRepFilletAPI_MakeFillet 描述在壳或实体的断裂边上构建圆角的函数
//edges为需要倒圆角的所有边;
//shapeSrc为需要倒圆角的源模型;
BRepFilletAPI_MakeFillet fillet(shapeSrc);
auto iter = edges.begin();
while (iter != edges.end())
{
TopoDS_Edge& e = *iter;
fillet.Add(radus, e);
iter++;
}
TopoDS_Shape shapeRes = fillet.Shape();
if (shapeRes.IsNull())
return false;
return true;
BRepFilletAPI_MakeChamfer 类 倒直角命令
BRepOffsetAPI_MakeThickSolid 用于构建空心实体的函数。
//构建空心实体(有厚度)
BRepOffsetAPI_MakeThickSolid BodyMaker;
TopoDS_Shape solidSrc;
TopoDS_Shape shapeRes;
try
{//solidSrc是实体;facesToRemove是被删除的面集;Thickness定义墙的厚度;
//1.e-6定义了生成形状中重合的公差标准;
BodyMaker.MakeThickSolidByJoin(solidSrc, facesToRemove, -3, 1.e-6);//,
//BRepOffset_Skin, Standard_False, Standard_False, GeomAbs_Intersection);
shapeRes= BodyMaker.Shape();
}
catch (Standard_Failure)
{
return false;
}
BRepBuilderAPI_Sewing 类 组装不同shape、face。离心机的离线装配中用到了。
BRepBuilderAPI_Sewing sew;
sew.Add(shape1);
sew.Add(shape2);
sew.Add(shape3);
sew.Add(shape4);
sew.Perform();
TopoDS_Shape shapeRes = sew.SewedShape();
拔模: 铸造件更好的脱离磨具,添加的角度。
BRepOffsetAPI_DraftAngle类 拔模命令,太高一个角度。
BRepAlgoAPI_Fuse 类为并集Fuse。
BRepAlgoAPI_Fuse mkFuse;
TopTools_ListOfShape shapeArguments,shapeTools;
const TopoDS_Shape& shape = s.front();
if (shape.IsNull())
throw Base::RuntimeError("Input shape is null");
shapeArguments.Append(shape);
for (std::vector<TopoDS_Shape>::iterator it = s.begin()+1; it != s.end(); ++it) {
if (it->IsNull())
throw Base::RuntimeError("Input shape is null");
shapeTools.Append(*it);
}
mkFuse.SetArguments(shapeArguments);
mkFuse.SetTools(shapeTools);
mkFuse.Build();
if (!mkFuse.IsDone())
throw Base::RuntimeError("MultiFusion failed");
TopoDS_Shape resShape = mkFuse.Shape();
BRepAlgoAPI_Common类为交集comm,
BRepAlgoAPI_Cut类为差集Cut。 从一个体中裁剪去另一个体。剪切命令
BRepBuilderAPI_Transform 平移旋转缩放命令。gp_Ax1类、gp_Trsf类实现绕轴旋转矩阵。
gp_Trsf 配合上面命令的平移旋转缩放矩阵,gp_Ax1 类是定义任意轴;
STEPControl_Writer 类和 STEPControl_Reader 类。
IGESControl_Writer 类和 IGESControl_Reader 类。
TopExp_Explorer 函数可以用来探索该实体的edge,返回的结果为子形状(sub-shape);同时该函数的经常会使用其子函数More,Current,Next 放进循环中
//遍历
for (TopExp_Explorer exp(shapSrc, TopAbs_FACE); exp.More(); exp.Next())
{
TopoDS_Face face = TopoDS::Face(exp.Current());
Handle(Geom_Surface) geomSurface = BRep_Tool::Surface(face);//BRep_Tool类用于获取相关shape的几何信息。
...
}
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(s, type, anIndices);
// 用于探索拓扑数据结构的工具。在地图中存储的所有子形状,类型。