目录
一、OCC 拉伸操作
二、例子
1、使BRepBuilderAPI_MakeFace
2、使用BRepPrimAPI_MakeRevol
3、垂直路径扫掠
一、OCC 拉伸操作
BRepPrimAPI_MakeSweep Class Reference - Open CASCADE Technology Documentation
OCC提供几种图形的构建是由基本图形的旋转,拉伸等方式形成的。进行拉伸操作的 时候,最场景这三个派生类。
还有另外一个比较少见。
二、例子
1、使BRepBuilderAPI_MakeFace
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
int main() {
// 定义路径的点,形成一个带有拐角的路径
gp_Pnt p1(0, 0, 0);
gp_Pnt p2(100, 0, 0);
gp_Pnt p3(100, 100, 0);
gp_Pnt p4(200, 100, 0);
// 创建路径的边
TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(p1, p2);
TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge(p2, p3);
TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge(p3, p4);
// 创建路径的线框
TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edge1, edge2, edge3);
// 创建矩形的四个顶点
gp_Pnt q1(-5, -5, 0);
gp_Pnt q2(5, -5, 0);
gp_Pnt q3(5, 0, 5);
gp_Pnt q4(-5, 0, 5);
// 创建矩形的边
TopoDS_Edge rectEdge1 = BRepBuilderAPI_MakeEdge(q1, q2);
TopoDS_Edge rectEdge2 = BRepBuilderAPI_MakeEdge(q2, q3);
TopoDS_Edge rectEdge3 = BRepBuilderAPI_MakeEdge(q3, q4);
TopoDS_Edge rectEdge4 = BRepBuilderAPI_MakeEdge(q4, q1);
// 创建矩形的线框
TopoDS_Wire rectWire = BRepBuilderAPI_MakeWire(rectEdge1, rectEdge2, rectEdge3, rectEdge4);
// 创建矩形面
TopoDS_Face rectFace = BRepBuilderAPI_MakeFace(rectWire);
// 创建管道,沿着路径拉伸矩形截面
BRepOffsetAPI_MakePipe pipe(wire, rectFace);
// 构建最终形状
TopoDS_Shape pipeShape = pipe.Shape();
VTKRenderWindow(pipeShape);
return 0;
}
备注:利用面拉伸时候,在拐角处会出现面与路径平行的情况,因此扫掠出来的不是一个体,还是一个面。
2、使用BRepPrimAPI_MakeRevol
// 定义路径的点,形成一个带有拐角的路径
gp_Pnt p1(0, 0, 0);
gp_Pnt p2(100, 0, 0);
gp_Pnt p3(100, 100, 0);
gp_Pnt p4(200, 100, 0);
// 创建路径的边
TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(p1, p2);
TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge(p2, p3);
TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge(p3, p4);
// 创建路径的线框
TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edge1, edge2, edge3);
// 创建矩形的四个顶点
gp_Pnt q1(-5, -5, 0);
gp_Pnt q2(5, -5, 0);
gp_Pnt q3(5, -5, 5);
gp_Pnt q4(-5, -5, 5);
// 创建矩形的边
TopoDS_Edge rectEdge1 = BRepBuilderAPI_MakeEdge(q1, q2);
TopoDS_Edge rectEdge2 = BRepBuilderAPI_MakeEdge(q2, q3);
TopoDS_Edge rectEdge3 = BRepBuilderAPI_MakeEdge(q3, q4);
TopoDS_Edge rectEdge4 = BRepBuilderAPI_MakeEdge(q4, q1);
// 创建矩形的线框
TopoDS_Wire rectWire = BRepBuilderAPI_MakeWire(rectEdge1, rectEdge2, rectEdge3, rectEdge4);
// 创建矩形面
TopoDS_Face rectFace = BRepBuilderAPI_MakeFace(rectWire);
gp_Ax1 anAxis;
anAxis.SetLocation(gp_Pnt(30.0, 70.0, 0.0));
anAxis.SetDirection(gp::DZ());
TopoDS_Shape aRevolEllipse = BRepPrimAPI_MakeRevol(rectFace, anAxis, M_PI_4);
可见,扫掠的时候,不是沿着路径垂直方向进行扫掠的。如果要实现沿着垂直路径的方向进行扫掠,还需要经过计算。
3、垂直路径扫掠
实现步骤:
1、在拐角地方定义拐角半径,利用圆进行插值
2、在每个插值位置重新进行扫掠面坐标
3、把每个单独扫掠的对象进行合并
// 创建几个形状
TopoDS_Shape box = BRepPrimAPI_MakeBox(10, 10, 10).Shape();
TopoDS_Shape sphere = BRepPrimAPI_MakeSphere(15).Shape();
// 创建一个复合体
TopoDS_Compound compound;
BRep_Builder builder;
builder.MakeCompound(compound);
// 将形状添加到复合体中
builder.Add(compound, box);
builder.Add(compound, sphere);
有更好实现的小伙伴 分享一下知识 ~~