BRepFeat_SplitShape problem

Hi,

I use a plane to split a TopoDS_Face in my project. Most of the time following code works fine except few faces. I've exported one such face in STEP file and attached here. I'm using OCC 6.5.3 version for this sample code.

The error comes in source file "locope_splitshape.cxx". "AddOpenWire" function call fails and error is caught in catch block of this function. Could anyone tell me if there is any problem in attached code? Please find the sample code used for splitting.

Greatly appreciate any help.

TIA,
Ashish

TopoDS_Shape l_tdShape = aSeqOfShape->Value(i);//this is imported from STEP file
TopExp_Explorer l_tdExp;
for(l_tdExp.Init(l_tdShape, TopAbs_FACE); l_tdExp.More(); l_tdExp.Next())
{
TopoDS_Shape l_tdFace = l_tdExp.Current();
//make plane face
gp_Pln l_gpCutPln(gp_Pnt(9.0,-9.0,139.511),gp_Dir(0.,0.,-1.0));
double l_dSize = 50.0;
double l_dHalfSize = l_dSize/2;
gp_Pnt l_gpCent = l_gpCutPln.Location();
gp_Dir l_gpXDir = l_gpCutPln.XAxis().Direction();
gp_Dir l_gpYDir = l_gpCutPln.YAxis().Direction();
gp_Dir l_gpZDir = l_gpCutPln.Axis().Direction();
//go half length in x direction
gp_Pnt l_gpNext(l_gpCent.X()+(l_gpXDir.X()*l_dHalfSize),
l_gpCent.Y()+(l_gpXDir.Y()*l_dHalfSize),
l_gpCent.Z()+(l_gpXDir.Z()*l_dHalfSize));
//get first segment points by going along Ydir two times in opposite dir
gp_Pnt l_gpPnt1(l_gpNext.X()+(l_gpYDir.X()*l_dHalfSize),
l_gpNext.Y()+(l_gpYDir.Y()*l_dHalfSize),
l_gpNext.Z()+(l_gpYDir.Z()*l_dHalfSize));
gp_Pnt l_gpPnt2(l_gpNext.X()-(l_gpYDir.X()*l_dHalfSize),
l_gpNext.Y()-(l_gpYDir.Y()*l_dHalfSize),
l_gpNext.Z()-(l_gpYDir.Z()*l_dHalfSize));
gp_Pnt l_gpPnt3(l_gpPnt2.X()-(l_gpXDir.X()*l_dSize),
l_gpPnt2.Y()-(l_gpXDir.Y()*l_dSize),
l_gpPnt2.Z()-(l_gpXDir.Z()*l_dSize));
gp_Pnt l_gpPnt4(l_gpPnt3.X()+(l_gpYDir.X()*l_dSize),
l_gpPnt3.Y()+(l_gpYDir.Y()*l_dSize),
l_gpPnt3.Z()+(l_gpYDir.Z()*l_dSize));

GC_MakeSegment l_gcSeg1(l_gpPnt1, l_gpPnt2);
Handle(Geom_TrimmedCurve) l_hSeg1 = l_gcSeg1.Value();
//get other segments
GC_MakeSegment l_gcSeg2(l_gpPnt2, l_gpPnt3);
Handle(Geom_TrimmedCurve) l_hSeg2 = l_gcSeg2.Value();
GC_MakeSegment l_gcSeg3(l_gpPnt3, l_gpPnt4);
Handle(Geom_TrimmedCurve) l_hSeg3 = l_gcSeg3.Value();
GC_MakeSegment l_gcSeg4(l_gpPnt4, l_gpPnt1);
Handle(Geom_TrimmedCurve) l_hSeg4 = l_gcSeg4.Value();

TopoDS_Edge l_tdE1 = BRepBuilderAPI_MakeEdge(l_hSeg1);
TopoDS_Edge l_tdE2 = BRepBuilderAPI_MakeEdge(l_hSeg2);
TopoDS_Edge l_tdE3 = BRepBuilderAPI_MakeEdge(l_hSeg3);
TopoDS_Edge l_tdE4 = BRepBuilderAPI_MakeEdge(l_hSeg4);

TopoDS_Wire l_tdW = BRepBuilderAPI_MakeWire(l_tdE1,l_tdE2,l_tdE3,l_tdE4);
TopoDS_Face l_tdF = BRepBuilderAPI_MakeFace(l_gpCutPln,l_tdW);

//display plane
myAISContext->Display(new AIS_Shape(l_tdF));

try
{
//cut shape by cut plane
BRepAlgoAPI_Section l_brepSec(l_tdFace,l_tdF,Standard_False);
l_brepSec.ComputePCurveOn1(Standard_True);
l_brepSec.Approximation(Standard_True);
l_brepSec.Build();
if (l_brepSec.IsDone() && !l_brepSec.Shape().IsNull() && BRepAlgo::IsValid(l_brepSec.Shape()))
{
TopoDS_Shape l_tdSec = l_brepSec.Shape();
//use splitter
BRepFeat_SplitShape l_brepSplit(l_tdFace);
bool l_bVoid = true;
//get cut shapes
TopTools_SequenceOfShape l_seqCutEdgeTemp;
for(TopExp_Explorer l_tpExp(l_tdSec,TopAbs_EDGE); l_tpExp.More(); l_tpExp.Next())
{
TopoDS_Shape l_tdNewEd = l_tpExp.Current();
TopoDS_Shape l_tdFace1;
if(l_brepSec.HasAncestorFaceOn1(l_tdNewEd,l_tdFace1))
{
TopoDS_Edge l_tdE = TopoDS::Edge(l_tdNewEd);
TopoDS_Face l_tdF = TopoDS::Face(l_tdFace1);
//add section curves and its face in splitter
l_brepSplit.Add(l_tdE,l_tdF);
l_bVoid = false;

//add this edge in collection to return
l_seqCutEdgeTemp.Append(l_tdE);
}
}
if(!l_bVoid)
{
//get split shape
TopoDS_Shape l_tdSplitShape = l_brepSplit.Shape();
//get faces after split of this face
Handle(TopoDS_TShape) l_htdTFace = l_tdFace.TShape();

//remove old face
}
}
}
catch(Standard_ConstructionError)
{
//some faces may be cut half
int i=0;
}
catch(Standard_Failure)
{
//some faces may be cut half
int i=0;
}
}

Attachments: 
Game Milky's picture

Dear Ashish,

Have you solved this problem?

Looking Forward to hear from you,

With Regards

Game

Ashish's picture

No, I couldn't solve this. I try to neglect such patches which fail to split

Regards,
Ashish

Ashish's picture

Using BRepAlgo_Section instead of BRepAlgoAPI_Section solved my problem