Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics

BRepFeat_SplitShape problem

BRepFeat_SplitShape problem
Ashish 2012/06/01 16:55

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.


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),
               //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),
               gp_Pnt l_gpPnt2(l_gpNext.X()-(l_gpYDir.X()*l_dHalfSize),
               gp_Pnt l_gpPnt3(l_gpPnt2.X()-(l_gpXDir.X()*l_dSize),
               gp_Pnt l_gpPnt4(l_gpPnt3.X()+(l_gpYDir.X()*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));

                    //cut shape by cut plane
                    BRepAlgoAPI_Section l_brepSec(l_tdFace,l_tdF,Standard_False);
                    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;
                                   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_bVoid = false;

                                   //add this edge in collection to return
                              //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
                    //some faces may be cut half
                    int i=0;
                    //some faces may be cut half
                    int i=0;
You have to be logged in to download the attached file
Game Milky 2012/11/12 17:00
      Dear Ashish,

Have you solved this problem?

Looking Forward to hear from you,

With Regards

Ashish 2013/04/02 16:09
No, I couldn't solve this. I try to neglect such patches which fail to split

Ashish 2013/06/28 10:37
Using BRepAlgo_Section instead of BRepAlgoAPI_Section solved my problem
Latest news
  • Open CASCADE CAD Assistant for iOS platform is available!
  • Open CASCADE Technology 6.9.0 is available for download!
  • JT Assistant for Android

  • © OPEN CASCADE 2000 - 2015  |  Search  |  Contacts   |  Site map