目录
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;
}