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;
}
相关推荐
唐诺3 小时前
几种广泛使用的 C++ 编译器
c++·编译器
南宫生4 小时前
力扣-图论-17【算法学习day.67】
java·学习·算法·leetcode·图论
sanguine__4 小时前
Web APIs学习 (操作DOM BOM)
学习
冷眼看人间恩怨4 小时前
【Qt笔记】QDockWidget控件详解
c++·笔记·qt·qdockwidget
红龙创客4 小时前
某狐畅游24校招-C++开发岗笔试(单选题)
开发语言·c++
Lenyiin4 小时前
第146场双周赛:统计符合条件长度为3的子数组数目、统计异或值为给定值的路径数目、判断网格图能否被切割成块、唯一中间众数子序列 Ⅰ
c++·算法·leetcode·周赛·lenyiin
yuanbenshidiaos6 小时前
c++---------数据类型
java·jvm·c++
数据的世界016 小时前
.NET开发人员学习书籍推荐
学习·.net
四口鲸鱼爱吃盐6 小时前
CVPR2024 | 通过集成渐近正态分布学习实现强可迁移对抗攻击
学习
十年一梦实验室6 小时前
【C++】sophus : sim_details.hpp 实现了矩阵函数 W、其导数,以及其逆 (十七)
开发语言·c++·线性代数·矩阵