How to check plane surfaces in TopoDS_Shape imported from IGES file

Hello,
I import some models from iges file with this code:

IGESControl_Reader reader;
reader.ReadFile((Standard_CString)filename);
reader.TransferRoots();
for (int i=1;i Handle_ShapeFix_Shape sfs = new ShapeFix_Shape(reader.Shape(i));
sfs->Perform();
shapes.Append(sfs->Shape());

SoSeparator *newSolid = new SoSeparator;
occShape2FaceSets(sfs->Shape(), newSolid);
parentNode->addChild(newSolid);
}

the function occShape2FaceSets must check for every face that compose the shape if is a plane surface. I make it with this:

TopExp_Explorer ex;
for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) {
const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
BRepAdaptor_Surface aFaceElementAdaptor(aFace, true);
GeomAbs_SurfaceType surfaceType= aFaceElementAdaptor.GetType();
if(surfaceType==GeomAbs_Plane){...}
}

this algorithm works if I create the shape with open cascade (for example with BRepPrimAPI_MakePrism or BRepPrimAPI_MakeRevol), or also if I save the occ created shape in IGES format using BRep mode (IGESControl_Writer igsWriter("MM", 1) //2nd parameter defines the write mode and may be 0=Faces (default) or 1=BRep).

But importing a general igs file I can't check for every face is a plane surface or not.
Perhaps IGESControl_Reader create the shapes with general surface and BRepAdaptor_Surface can't recognize the surface type. So I have to use an algorithm that analyze geometrically the face, but I dont'know how.

Massimo.

Marco Matt's picture

I had the same problem; it seems there is some issues using TopExp_Explorer to find faces loaded from an IGES file.

Try:

void ExploreFace(const TopoDS_Shape& shape)
{
for (TopoDS_Iterator ext(shape); ext.More(); ext.Next())
{
if ( ext.Value().ShapeType()==TopAbs_FACE )
{
// bdo something...
}
ExploreFace(ext.Value());
}
}

Call the above function with the highest level shape (or iterate if you have more than one root shape in your IGES)

Marco

Marco Balen's picture

Hello massimo,

I have the same problem. When I import an IGES file I cannot recognize the plane surface with :

TopoDS_Face aFace = TopoDS::Face(aSubShape);
Handle(Geom_Surface) Surface = BRep_Tool::Surface(aFace);
if (Surface->IsKind(STANDARD_TYPE(Geom_Plane)) ) .....

Have you find any solution to this question ?

Thanks

Evgeny Lodyzhehsky's picture

Dear Giglietti Antonio.

There are several types of basic surfaces (see GeomAbs.cdl):

enumeration SurfaceType
is Plane, Cylinder, Cone ,Sphere ,Torus, BezierSurface,
BSplineSurface, SurfaceOfRevolution , SurfaceOfExtrusion,
OffsetSurface,OtherSurface end;

There are surfaces that are not basic but have basic surface as underlying information. For e.g. Geom_RectangularTrimmedSurface,Geom_OffsetSurface have basis surface

The method
BasisSurface (me) returns Surface from Geom;

could help you with the analyse you need.

Regards.