Something wrong when use BRepBuilderAPI_MakeFace to build a face through a face and wire.

jianbaoxia

CAD master
Hi Bros, I'm JianBaoxia.
After I finally the wire build with you help yestoday, I keep try to use it to build a TopoDS_Face,
however, there seems get something wrong without error raise.

I get a TopoDS_Face from file "cylFaceForCut.step"(Fig 1), and get TopoDS_Wire from file "wire.step"(Fig 2), their relationship is show in file "face_wire.step"(Fig 3).
I try to build a face through the TopoDS_Face and TopoDS_Wire get from file.
After use "BRepBuilderAPI_MakeFace", it seems success, however,when try to output the face as .step or .brep, it failed.
I think may be failed in BRepBuilderAPI_MakeFace, but the code seems normal.

There are Fig 1~3 below:

1667584223504.png1667584262387.png1667584304075.png
There is my demo:
Code:
TopoDS_Shape ReadStepFile(const std::string& filepath)
{
    STEPControl_Reader reader;
    reader.ReadFile(filepath.c_str());
    reader.TransferRoots();
    TopoDS_Shape shape = reader.OneShape();
    return shape;
}

bool WriteStepFile(const TopoDS_Shape& shape, const std::string filepath)
{
    bool output_flag = true;
    STEPControl_Writer writer;
    Interface_Static::SetCVal("write.step.schema", "AP203");
    IFSelect_ReturnStatus status = writer.Transfer(shape, STEPControl_AsIs);
    if (status != IFSelect_RetDone) output_flag = false;
    status = writer.Write(filepath.c_str());
    if (status != IFSelect_RetDone) output_flag = false;

    return output_flag;
}

int main()
{
    std::string filePath = "C:/Users/14656/Desktop/Program/Open Cascade/Demo/";
    TopoDS_Shape cylShape = ReadStepFile(filePath + "cylFaceForCut.step");
    TopoDS_Shape wireShape = ReadStepFile(filePath + "wire.step");

    TopoDS_Face cyl;                                            // the face for cut
    for (TopExp_Explorer exp(cylShape, TopAbs_FACE); exp.More(); exp.Next())
        cyl = TopoDS::Face(exp.Current());
   
    BRepBuilderAPI_MakeWire mkWire;
    for (TopExp_Explorer exp(wireShape, TopAbs_EDGE); exp.More(); exp.Next())
        mkWire.Add(TopoDS::Edge(exp.Current()));
    TopoDS_Wire wire = mkWire.Wire();                            // the wire to cut a face


    TopoDS_Face aFace = BRepBuilderAPI_MakeFace(cyl, wire);        // build face

    //! I try to output the face I build for check, and failed
    // WriteStepFile(aFace, filePath + "aFace.step");

    std::filebuf aFileBuf;
    std::ostream aStream(&aFileBuf);
    if (aFileBuf.open(filePath + "aFace.brep", ios::out))
    {
        BRepTools::Write(aFace, aStream);
    }
    aFileBuf.close();


    return 0;
}

Hope for youe suggestion.
 

Attachments

  • cylFaceForCut.step
    6.3 KB · Views: 1
  • wire.step
    6.5 KB · Views: 1
  • face_wire.step
    14.7 KB · Views: 1

jianbaoxia

CAD master
Bros, I fix this problem, I use "BRepBuilderAPI_MakeFace (const gp_Cylinder &C, const TopoDS_Wire &W, const Standard_Boolean Inside=Standard_True)" instead ”BRepBuilderAPI_MakeFace (const TopoDS_Face &F, const TopoDS_Wire &W)“,and then use "ShapeFix_Face".

Although I build the face finally, I still confuse about why the ”BRepBuilderAPI_MakeFace (const TopoDS_Face &F, const TopoDS_Wire &W)“ failed, I usually meet this type problem when using OCCT, sometimes work sometimes not work, both make me confuse. o_O

At lase, there is my demo:

Code:
int main()
{
    std::string filePath = "C:/Users/14656/Desktop/Program/Open Cascade/Demo/";
    TopoDS_Shape cylShape = ReadStepFile(filePath + "cylFaceForCut.step");
    TopoDS_Shape wireShape = ReadStepFile(filePath + "wire.step");

    TopoDS_Face cyl;                                            // the face for cut
    for (TopExp_Explorer exp(cylShape, TopAbs_FACE); exp.More(); exp.Next())
        cyl = TopoDS::Face(exp.Current());
    BRepAdaptor_Surface brepAdaptorSur(cyl);
    const GeomAdaptor_Surface& geomAdaptorSur = brepAdaptorSur.Surface();
    gp_Cylinder gpCyl = geomAdaptorSur.Cylinder();
    
    BRepBuilderAPI_MakeWire mkWire;
    for (TopExp_Explorer exp(wireShape, TopAbs_EDGE); exp.More(); exp.Next())
        mkWire.Add(TopoDS::Edge(exp.Current()));
    TopoDS_Wire wire = mkWire.Wire();                            // the wire to cut a face

    BRepBuilderAPI_MakeFace faceMaker(gpCyl, wire);                // build face

    ShapeFix_Face fix(faceMaker.Face());                        // fix the face
    fix.Perform();

    TopoDS_Face aFace = faceMaker.Face();

    //! I try to output the face I build for check, and failed
    WriteStepFile(aFace, filePath + "aFace.step");

    std::filebuf aFileBuf;
    std::ostream aStream(&aFileBuf);
    if (aFileBuf.open(filePath + "aFace.brep", ios::out))
    {
        BRepTools::Write(aFace, aStream);
    }
    aFileBuf.close();


    return 0;
}
 

blobfish

CAD community veteran
Although I build the face finally, I still confuse about why the ”BRepBuilderAPI_MakeFace (const TopoDS_Face &F, const TopoDS_Wire &W)“ failed, I usually meet this type problem when using OCCT, sometimes work sometimes not work, both make me confuse. o_O
Welcome to opencascade. ;) It is probably because the wire is crossing the periodic boundary of your surface. If you rotate the surface 180 degrees around it's axis, it will probably work.
periodicBoundary.png
 
Top