Trying to build a closed face

I am trying to build a closed face using the following code:

gp_Pnt V1(0,0,0), V2(1,0,0), V3(1,0,1), V4(0,0,1);

BRepBuilderAPI_MakePolygon polyBuilder( V1, V2, V3, V4, Standard_True );

BRepBuilderAPI_FindPlane planeBuilder( polyBuilder.Wire(), Precision::Confusion() );

gp_Pln plane( planeBuilder.Plane()->Pln() );

TopoDS_Face face = BRepBuilderAPI_MakeFace( plane, polyBuilder.Wire() ).Face();

TopExp_Explorer ex( face, TopAbs_EDGE );

for ( ; ex.More(); ex.Next() ) {

TopoDS_Edge e = TopoDS::Edge( ex.Current() );

if ( BRep_Tool::IsClosed( e, face ) != Standard_True ) {

throw AMIErr( string( "Unclosed face." ), &V1, &V2, &V3, &V4 );

}

}

The exception always gets thrown saying that my face is not closed. I have also tried explicitly calling the Close() function of the polygon builder as well as adding the first vertex again at the end. Can anyone help me diagnose this?

Thanks,

Shaun Bloom

Jerome DUFAURE's picture

Hello Shaun To build a closed face try this

> gp_Pnt V1(0,0,0), V2(1,0,0), V3(1,0,1),
> V4(0,0,1);

> BRepBuilderAPI_MakePolygon (name of your polygon); yourpolygon.Add(V1); yourpolygon.Add(V2); yourpolygon.Add(V3); yourpolygon.Add(V4); yourpolygon.Close();

TopoDS_Face yourface =BRepBuilderAPI_MakeFace (yourpolygon);

your face is now built through V1,V2,V3,V4 and it is closed.

if you have more points to add use this: for(i=1;i<=NB of points;i++){ polygon.Add(Array_OfPnt.Value(i)); } Wrect.Close();

I hope this will help you

Jerome

Shaun Bloom's picture

I tried the change that you suggested, but to no avail. I have also tried adding the first vertex again at the end of the list of points to try and close it that way, but that didn't work either. Then I tried including a BRepCheck_Analyzer as follows after I built the "closed" face:

...

TopoDS_Face face = BRepBuilderAPI_MakeFace( plane, polyBuilder.Wire() ).Face();

BRepCheck_Analyzer analyzer( face );

if ( ! analyzer.IsValid() ) {

TopExp_Explorer ex( face, TopAbs_EDGE );

for ( ; ex.More(); ex.Next() ) {

TopoDS_Edge e = TopoDS::Edge( ex.Current() );

if ( BRep_Tool::IsClosed( e, face ) != Standard_True ) {

throw AMIErr( string( "Unclosed face." ), &V1, &V2, &V3, &V4 );

}

}

}

The BRepCheck_Analyzer::IsValid() method returns true and the code that checks the closure of the face doesn't get executed. This leads me to believe that one of two things are true: (1) an unclosed face is a valid face, or (2) my code to check the closure of a face doesn't work. I believe that I am constructing a valid closed face since I have followed code examples, the documentation, and now your suggestion as well, but my code to check the closure of a face looks OK to me. Something must be wrong with it. Can you help?

Thanks,

(and thanks for your quick reply to my first message.)

-- Shaun Bloom

Igor Feoktistov's picture

Hello, Shaun

your code for checking is wrong. Method BRep_Tool::IsClosed(e, face) only checks if edge e lies on periodical closed surface just on line of sewing this surface, for example line edge on cylindrical face.

Method BRep_Tool::IsClosed(Shape) checks if Shape is closed in 3d space. For solids, shells and compounds it means that Shape has no free boundaries and has closed volume "inside".

In this sence face is always opened, because it has free boundaries.

Best regards, Igor