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;
}
相关推荐
秃头佛爷2 小时前
Python学习大纲总结及注意事项
开发语言·python·学习
dayouziei4 小时前
java的类加载机制的学习
java·学习
捕鲸叉5 小时前
创建线程时传递参数给线程
开发语言·c++·算法
A charmer5 小时前
【C++】vector 类深度解析:探索动态数组的奥秘
开发语言·c++·算法
Peter_chq5 小时前
【操作系统】基于环形队列的生产消费模型
linux·c语言·开发语言·c++·后端
青花瓷7 小时前
C++__XCode工程中Debug版本库向Release版本库的切换
c++·xcode
dsywws7 小时前
Linux学习笔记之vim入门
linux·笔记·学习
晨曦_子画8 小时前
3种最难学习和最容易学习的 3 种编程语言
学习
幺零九零零8 小时前
【C++】socket套接字编程
linux·服务器·网络·c++
城南vision8 小时前
Docker学习—Docker核心概念总结
java·学习·docker