Intersection with STEP model

Hi there,

I'm trying to use the open cascade library to import a STEP file and then to create intersect points with the imported shapes using lines. For testing I created a simple STEP file with a simple cube which is attached to this post. I'm successful in retrieving the shape from the STEP file and drawing it using the import STEP example:

  bool ImportStep(const TCollection_AsciiString& theFileName)
    STEPControl_Reader aReader;
    IFSelect_ReturnStatus aStatus = aReader.ReadFile(theFileName.ToCString());
    if ( aStatus == IFSelect_RetDone )
      bool isFailsonly = false;
      aReader.PrintCheckLoad( isFailsonly, IFSelect_ItemsByEntity );

      int aNbRoot = aReader.NbRootsForTransfer();
      aReader.PrintCheckTransfer( isFailsonly, IFSelect_ItemsByEntity );
      for ( Standard_Integer n = 1; n <= aNbRoot; n++ )
        Standard_Boolean ok = aReader.TransferRoot( n );
        int aNbShap = aReader.NbShapes();
        if ( aNbShap > 0 )
          for ( int i = 1; i <= aNbShap; i++ )
            TopoDS_Shape aShape = aReader.Shape( i );
            AIS_Shape* ais_shape = new AIS_Shape(aShape);
            myAISContext()->Display (ais_shape, Standard_False);
      return false;

    return true;

If I understand correctly, the correct strategy is to read the "STEP shape" to a TopoDS_Shape object. Then obtain the underlying TopoDS_Face objects and convert those to a Geom_Surface objects. The Geom_Surface objects can then be used to intersect with like this:

gp_Pnt P1(5, 5, 20);
gp_Pnt P2(5, 5, -20);
Handle(Geom_Curve) aCurve = GC_MakeSegment(P1, P2).Value();

TopoDS_Face face; // Retrieved from STEP shape.
Handle(Geom_Surface) aSurface = BRep_Tool::Surface(face);

GeomAPI_IntCS intersector(aCurve, aSurface);

gp_Pnt pIntersect = intersector.Point(0);

I tried to obtain the faces from the shape which I read from the STEP file so I can create a Geom_Surface objects out of them with the above snippet. So far I haven't been able to get the faces. I tried following code snippet:

TopoDS_Shape aShape = aReader.Shape(i);

for (TopoDS_Iterator ext(aShape); ext.More(); ext.Next())
    if (ext.Value().ShapeType() == TopAbs_FACE)
    else if (ext.Value().ShapeType() == TopAbs_VERTEX)
    else if(ext.Value().ShapeType() == TopAbs_EDGE)

The iterator doesn't return anything with the shapetype of TopAbs_FACE (or TopAbs_VERTEX or TopAbs_EDGE). I'm stuck in what to try next to get this working.

Kind regards,


Forum supervisor's picture

Hello Willem,

We already developed certain algorithms for efficient ray casting / ray tracing that could be probably adapted to your needs – please, contact us if you are interested.

Best regards,

Forum supervisor