Mesh the infinite face

Hi,

The Sample.stp I read from SolidWorks look like Figure_1, but when I read the file using STEPCAFControl_Reader and mesh the TopoShape using BRepMesh_IncrementalMesh, I found that a face at the top disappeared, as shown in Figure_2.

It is possible that this face is infinite, so when I execute BRep_Tool::Triangulation on this face, I get an invalid Handle(Poly_Triangulation).

However, when I perform BRepMesh_IncrementalMesh on this TopoShape for the second time, the previously disappeared face unexpectedly reappears! As shown in Figure_3

This is because BRep_Tool::Triangulation returns an valid Handle(Poly_Triangulation).

(I set the parameters theLinDeflection and theAngDeflection to 0.0213333 and 0.3490658 respectively, otherwise performing the second BRepMesh_IncrementalMesh still get the invalid Handle(Poly_Triangulation))

But I don't think this is a good approach because sometimes, when performing the second BRepMesh_IncrementalMesh on a particular TopoShape, the program gets stuck here.

I referenced FreeCAD's handling of infinite faces:

Handle (Poly_Triangulation) Part::Tools::triangulationOfFace(const TopoDS_Face& face)
{
    TopLoc_Location loc;
    Handle (Poly_Triangulation) mesh = BRep_Tool::Triangulation(face, loc);
    if (!mesh.IsNull())
        return mesh;

    // If no triangulation exists then the shape is probably infinite
    double u1{}, u2{}, v1{}, v2{};
    try {
        BRepAdaptor_Surface adapt(face);
        u1 = adapt.FirstUParameter();
        u2 = adapt.LastUParameter();
        v1 = adapt.FirstVParameter();
        v2 = adapt.LastVParameter();
    }
    catch (const Standard_Failure&) {
        return nullptr;
    }

    auto selectRange = [](double& p1, double& p2) {
        if (Precision::IsInfinite(p1) && Precision::IsInfinite(p2)) {
            p1 = -50.0;
            p2 =  50.0;
        }
        else if (Precision::IsInfinite(p1)) {
            p1 = p2 - 100.0;
        }
        else if (Precision::IsInfinite(p2)) {
            p2 = p1 + 100.0;
        }
    };

    // recreate a face with a clear boundary in case it's infinite
    selectRange(u1, u2);
    selectRange(v1, v2);

    Handle(Geom_Surface) surface = BRep_Tool::Surface(face);
    if ( surface.IsNull() ) {
        FC_THROWM(Base::CADKernelError, "Cannot create surface from face");
    }
    BRepBuilderAPI_MakeFace mkBuilder(surface, u1, u2, v1, v2, Precision::Confusion() );
    TopoDS_Shape shape = mkBuilder.Shape();
    shape.Location(loc);

    BRepMesh_IncrementalMesh(shape, 0.005, false, 0.1, true);
    return BRep_Tool::Triangulation(TopoDS::Face(shape), loc);
}

I obtained the result shown in Figure_4, which is clearly not as expected.

Is there any way to mesh an infinite face correctly?

Dmitrii Pasukhin's picture

Hello, at the moment, there are not special parameters for bounds unbound surface.

You can use bounds by bounding box before processing.

As for our general approach, I recommend to determine the unbound shapes and keep them separate from a model (for example as Supplemental geometry). It will be possible to change bounds base on special parameters any time. That can of functionality will be introduced in XCAF in 7.9

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

As I know it is not recommended to keep unbound geometry in STEP file as free geometry. Usually it kept as Supplemental.

Best regards, Dmitrii.