Open CASCADE学习|BrepOffsetAPI_ThruSections无法放样成Solid

目录

1、边界线(TopoDS_Wire)不在一个平面上时,无法生成Solid

2、边界线(TopoDS_Wire)在一个平面上时,可以生成Solid

3、边界线(TopoDS_Wire)不在一个平面上时,添加TopoDS_Vertex后生成Solid


在Open CASCADE Technology (OCCT) 中,BRepOffsetAPI_ThruSections 类是用来通过放样生成一个实体或者一个面壳(Shell)。当使用这个类时,isSolid 参数决定了生成的是实体(TopoDS_Solid)还是面壳(TopoDS_Shell)。如果isSolid为true,则尝试生成实体;如果为false,则生成面壳。

然而,当两个边界线(TopoDS_Wire)不在一个平面上时,使用BRepOffsetAPI_ThruSections 可能会遇到问题,因为放样过程通常需要在一个连续的平面或者空间曲线上进行。

1、边界线(TopoDS_Wire)不在一个平面上时,无法生成Solid

cpp 复制代码
#include <gp_Ax2.hxx>
#include <gp_Circ.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
​
#include"Viewer.h"
​
int main(int argc, char* argv[])
{
    gp_Dir  Z(0.0, 0.0, 1.0);
    gp_Pnt center(0, 0, 0.0);
    gp_Pnt xr(0.5, 0, 0.0);
    gp_Pnt yr(0.0, 1.0, 0.0);
    gp_Pnt zr(0.0, 0.0, 7.0);
    gp_Ax2  wb(center, Z);
    gp_Circ  wbcircle(wb, 0.125 / 2);
    TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);
    TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);
    TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);
    TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
​
    // test
    TopoDS_Edge L1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.5));
    TopoDS_Edge L2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.5), gp_Pnt(1.0, 1.0, 0.0));
    TopoDS_Edge L3 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 1.0, 0.5));
    TopoDS_Edge L4 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 0.5), gp_Pnt(0.0, 0.0, 0.0));
    BRepBuilderAPI_MakeWire mkWire_L;
    mkWire_L.Add(L1);
    mkWire_L.Add(L2);
    mkWire_L.Add(L3);
    mkWire_L.Add(L4);
    TopoDS_Wire Wire_L = mkWire_L.Wire();
​
    TopoDS_Edge L11 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 1.0), gp_Pnt(1.0, 0.0, 1.0));
    TopoDS_Edge L12 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 1.0), gp_Pnt(1.0, 1.0, 1.0));
    TopoDS_Edge L13 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 1.0), gp_Pnt(0.0, 1.0, 1.0));
    TopoDS_Edge L14 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 1.0), gp_Pnt(0.0, 0.0, 1.0));
    BRepBuilderAPI_MakeWire mkWire_U;
    mkWire_U.Add(L11);
    mkWire_U.Add(L12);
    mkWire_U.Add(L13);
    mkWire_U.Add(L14);
    TopoDS_Wire Wire_U = mkWire_U.Wire();
​
    BRepOffsetAPI_ThruSections mk_solid(Standard_True);
    mk_solid.AddWire(Wire_L);
    mk_solid.AddWire(Wire_U);
    TopoDS_Shape Solid_Test = mk_solid.Shape();
​
​
    Viewer vout(50, 50, 500, 500);
    vout << wbe;
    vout << xline;
    vout << yline;
    vout << zline;
    vout << Solid_Test;
    vout.StartMessageLoop();
    return 0;
}
​

2、边界线(TopoDS_Wire)在一个平面上时,可以生成Solid

cpp 复制代码
#include <gp_Ax2.hxx>
#include <gp_Circ.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
​
#include"Viewer.h"
​
int main(int argc, char* argv[])
{
    gp_Dir  Z(0.0, 0.0, 1.0);
    gp_Pnt center(0, 0, 0.0);
    gp_Pnt xr(0.5, 0, 0.0);
    gp_Pnt yr(0.0, 1.0, 0.0);
    gp_Pnt zr(0.0, 0.0, 7.0);
    gp_Ax2  wb(center, Z);
    gp_Circ  wbcircle(wb, 0.125 / 2);
    TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);
    TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);
    TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);
    TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
​
    // test
    TopoDS_Edge L1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0));
    TopoDS_Edge L2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0));
    TopoDS_Edge L3 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 1.0, 0.0));
    TopoDS_Edge L4 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0));
    BRepBuilderAPI_MakeWire mkWire_L;
    mkWire_L.Add(L1);
    mkWire_L.Add(L2);
    mkWire_L.Add(L3);
    mkWire_L.Add(L4);
    TopoDS_Wire Wire_L = mkWire_L.Wire();
​
    TopoDS_Edge L11 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 1.0), gp_Pnt(1.0, 0.0, 1.0));
    TopoDS_Edge L12 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 1.0), gp_Pnt(1.0, 1.0, 1.0));
    TopoDS_Edge L13 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 1.0), gp_Pnt(0.0, 1.0, 1.0));
    TopoDS_Edge L14 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 1.0), gp_Pnt(0.0, 0.0, 1.0));
    BRepBuilderAPI_MakeWire mkWire_U;
    mkWire_U.Add(L11);
    mkWire_U.Add(L12);
    mkWire_U.Add(L13);
    mkWire_U.Add(L14);
    TopoDS_Wire Wire_U = mkWire_U.Wire();
​
    BRepOffsetAPI_ThruSections mk_solid(Standard_True);
    mk_solid.AddWire(Wire_L);
    mk_solid.AddWire(Wire_U);
    TopoDS_Shape Solid_Test = mk_solid.Shape();
​
    Viewer vout(50, 50, 500, 500);
    vout << wbe;
    vout << xline;
    vout << yline;
    vout << zline;
    vout << Solid_Test;
    vout.StartMessageLoop();
    return 0;
}
​

3、边界线(TopoDS_Wire)不在一个平面上时,添加TopoDS_Vertex后生成Solid

cpp 复制代码
#include <gp_Ax2.hxx>
#include <gp_Circ.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>

#include"Viewer.h"

int main(int argc, char* argv[])
{
    gp_Dir  Z(0.0, 0.0, 1.0);
    gp_Pnt center(0, 0, 0.0);
    gp_Pnt xr(0.5, 0, 0.0);
    gp_Pnt yr(0.0, 1.0, 0.0);
    gp_Pnt zr(0.0, 0.0, 7.0);
    gp_Ax2  wb(center, Z);
    gp_Circ  wbcircle(wb, 0.125 / 2);
    TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);
    TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);
    TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);
    TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);

    // test
    TopoDS_Edge L1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.5));
    TopoDS_Edge L2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.5), gp_Pnt(1.0, 1.0, 0.0));
    TopoDS_Edge L3 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 1.0, 0.5));
    TopoDS_Edge L4 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 0.5), gp_Pnt(0.0, 0.0, 0.0));
    TopoDS_Vertex vL = BRepBuilderAPI_MakeVertex(gp_Pnt(0.5, 0.5, 0.2));
    BRepBuilderAPI_MakeWire mkWire_L;
    mkWire_L.Add(L1);
    mkWire_L.Add(L2);
    mkWire_L.Add(L3);
    mkWire_L.Add(L4);
    TopoDS_Wire Wire_L = mkWire_L.Wire();

    TopoDS_Edge L11 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 1.0), gp_Pnt(1.0, 0.0, 1.0));
    TopoDS_Edge L12 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 1.0), gp_Pnt(1.0, 1.0, 1.0));
    TopoDS_Edge L13 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 1.0), gp_Pnt(0.0, 1.0, 1.0));
    TopoDS_Edge L14 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 1.0), gp_Pnt(0.0, 0.0, 1.0));
    TopoDS_Vertex vU = BRepBuilderAPI_MakeVertex(gp_Pnt(0.5, 0.5, 1.));
    BRepBuilderAPI_MakeWire mkWire_U;
    mkWire_U.Add(L11);
    mkWire_U.Add(L12);
    mkWire_U.Add(L13);
    mkWire_U.Add(L14);
    TopoDS_Wire Wire_U = mkWire_U.Wire();

    BRepOffsetAPI_ThruSections mk_solid(Standard_True);
    mk_solid.AddVertex(vL);
    mk_solid.AddWire(Wire_L);
    mk_solid.AddWire(Wire_U);
    mk_solid.AddVertex(vU);
    TopoDS_Shape Solid_Test = mk_solid.Shape();

    Viewer vout(50, 50, 500, 500);
    vout << wbe;
    vout << xline;
    vout << yline;
    vout << zline;
    vout << Solid_Test;
    vout.StartMessageLoop();
    return 0;
}
相关推荐
‘’林花谢了春红‘’4 小时前
C++ list (链表)容器
c++·链表·list
机器视觉知识推荐、就业指导6 小时前
C++设计模式:建造者模式(Builder) 房屋建造案例
c++
朝九晚五ฺ6 小时前
【Linux探索学习】第十四弹——进程优先级:深入理解操作系统中的进程优先级
linux·运维·学习
猫爪笔记8 小时前
前端:HTML (学习笔记)【1】
前端·笔记·学习·html
Yang.998 小时前
基于Windows系统用C++做一个点名工具
c++·windows·sql·visual studio code·sqlite3
熬夜学编程的小王8 小时前
【初阶数据结构篇】双向链表的实现(赋源码)
数据结构·c++·链表·双向链表
zz40_8 小时前
C++自己写类 和 运算符重载函数
c++
六月的翅膀8 小时前
C++:实例访问静态成员函数和类访问静态成员函数有什么区别
开发语言·c++
pq113_68 小时前
ftdi_sio应用学习笔记 3 - GPIO
笔记·学习·ftdi_sio