Wed, 04/28/2021 - 11:52
hello everyone,
i have a problem when i use the BRepAlgoAPI_Cut to get a hole in a wall. my two shapes are two prism. they intersect with each other obviously. but the hole can't be generated. then i use BRepAlgoAPI_Section to gernerate the section line. also, there is nothing generated. i don't know why. as i think my two shapes are really simple. i don't understand the code inside so i have no idea to investigate. can you help me find what the problem is?
the asseccesary is my two shapes.
here is my code.
TopoDS_Edge E212 = BRepBuilderAPI_MakeEdge(gp_Pnt(-5110,-1546,1000), gp_Pnt(-5110,-346,1000));
TopoDS_Edge E222 = BRepBuilderAPI_MakeEdge(gp_Pnt(-5110,-346,1000), gp_Pnt(-5110,-346,2100));
TopoDS_Edge E232 = BRepBuilderAPI_MakeEdge(gp_Pnt(-5110,-346,2100), gp_Pnt(-5110,-1546,2100));
TopoDS_Edge E242 = BRepBuilderAPI_MakeEdge(gp_Pnt(-5110,-1546,2100), gp_Pnt(-5110,-1546,1000));
TopoDS_Wire W22 = BRepBuilderAPI_MakeWire(E212,E222, E232, E242);
TopoDS_Face F22 = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0), gp_Vec(1,0,0)),W22);
TopoDS_Shape S22 = BRepPrimAPI_MakePrism(F22,gp_Vec(10000.,0.,0));
TopoDS_Edge E211 = BRepBuilderAPI_MakeEdge(gp_Pnt(-2000,0,-4000), gp_Pnt(-2000,2700,-4000));
TopoDS_Edge E221 = BRepBuilderAPI_MakeEdge(gp_Pnt(-2000,2700,-4000), gp_Pnt(2000,2700,-4000));
TopoDS_Edge E231 = BRepBuilderAPI_MakeEdge(gp_Pnt(2000,2700,-4000), gp_Pnt(2000,0,-4000));
TopoDS_Edge E241 = BRepBuilderAPI_MakeEdge(gp_Pnt(2000,0,-4000), gp_Pnt(-2000,0,-4000));
TopoDS_Wire W21 = BRepBuilderAPI_MakeWire(E211,E221, E231, E241);
TopoDS_Face F21 = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0), gp_Vec(0,0,1)),W21);
TopoDS_Shape S21 = BRepPrimAPI_MakePrism(F21,gp_Vec(0,0,500));
gp_Trsf theTransformation;
gp_Ax1 axe = gp_Ax1(gp_Pnt(0,1350,0),gp_Dir(1.,0.,0.));
Handle(Geom_Axis1Placement) Gax1 = new Geom_Axis1Placement(axe);
Handle (AIS_Axis) ax1 = new AIS_Axis(Gax1);
theTransformation.SetRotation(axe,90*M_PI/180);
gp_Trsf theTransformation1;
gp_Ax1 axe1 = gp_Ax1(gp_Pnt(0,0,1350),gp_Dir(0.,1.,0.));
theTransformation1.SetRotation(axe1,90*M_PI/180);
theTransformation.Multiply(theTransformation1);
gp_Pnt pt(-2000,0,-4000);
pt.Transform(theTransformation);
gp_Trsf theTransformation2;
theTransformation2.SetTranslation(pt, gp_Pnt(gp_Pnt(-4000,-2000,0)));
theTransformation.Multiply(theTransformation2);
theTransformation.Invert();
gp_Trsf theTransformation3;
theTransformation3.SetTranslation(gp_Pnt(gp_Pnt(-2000,-1000,0)), gp_Pnt(gp_Pnt(-8000,0,-2000)));
theTransformation.Multiply(theTransformation3);
BRepBuilderAPI_Transform myBRepTransformation(S22,theTransformation);
TopoDS_Shape S222 = myBRepTransformation.Shape();
BRepAlgoAPI_Cut& fuse = BRepAlgoAPI_Cut(S21,S222);
fuse.Build();
bError = fuse.HasErrors();
TopoDS_Shape shapeCUt1 = fuse.Shape();
Standard_Integer iErr;
TopTools_ListOfShape aLS;
BOPAlgo_PaveFiller aPF;
//
aLS.Append(S21);
aLS.Append(S222);
aPF.SetArguments(aLS);
//
aPF.Perform();
iErr = aPF.HasErrors();
if (iErr) {
//cout << "Intersection failed with error status: " << iErr << "\n";
//return 1;
int a = 1;
}
ShapeFix_ShapeTolerance tol;
tol.SetTolerance(S21, 0.0001);
tol.SetTolerance(S222, 0.0001);
Standard_Boolean PerformNow=Standard_True;
BRepAlgoAPI_Section section(S21,S222, aPF,PerformNow);
section.ComputePCurveOn1(Standard_True);
section.Approximation(TopOpeBRepTool_APPROX);
section.ComputePCurveOn1(Standard_True);
section.ComputePCurveOn2(Standard_True);
// Use Oriented Bounding Boxes inside Booleans to speed up calculation of the section
section.SetUseOBB(Standard_True);
section.Build();
bError = section.HasErrors();
Handle(Message_Report) s = section.GetReport();
TopoDS_Shape asection=section.Shape();