opencascade

Classifying TopoDS_Face face


I have a TopoDS_Face object which comes from a translation of an IGES file. If I parse the IGES file using my own algorithm (written in C) which search for the faces then the loop(s) pointed to by the face and finally the edges in the loop, I can determine whether the face is planar or non-planar(semi-cylindrical in bends). This is done by checking if the edge is a line or an arc based on the form number in the underlying NURBS(entity 126). A line has form 1 and an arc has form 2.

What methods/functions or other mechanism can be used in Open Cascade to determine whether a TopoDS_Face is planar or semi-cylindrical(bends)?


Solution

  • You can use BRepAdaptor_Surface class to get the type of TopoDS_Face surface:

    BRepAdaptor_Surface surface = BRepAdaptor_Surface(face);
    if (surface.GetType() == GeomAbs_Plane)
    {
      // Surface is a plane
    }
    else
    {
      // Surface is not a plane
    }
    

    Update:

    The alternate way to define planar surface or not is using a curvature value. For planar surfaces a mean curvature should be equal to 0.

    BRepAdaptor_Surface surface = BRepAdaptor_Surface(face);
    
    double u = (surface.FirstUParameter() + surface.LastUParameter()) / 2.0;
    double v = (surface.FirstVParameter() + surface.LastVParameter()) / 2.0;
    
    BRepLProp_SLProps surfaceProps(surface, u, v, 2, gp::Resolution());
    if (surfaceProps.MeanCurvature() == 0.0)
    {
      // Surface is a plane
    }
    else
    {
      // Surface is not a plane
    }