Poly_Polygon2D::NbNodes error

I use the followng code to get the 2D polygons on a certain Face
1.I get exception when calling Poly_Polygon2D::NbNodes
2. When I try to access points returned by
Poly_Polygon2D::Nodes
I get invalid values.

for (ExFace.Init(aShape, TopAbs_FACE); ExFace.More(); ExFace.Next())
{
// Reading edges
for (ExEdge.Init(ExFace.Current(),TopAbs_EDGE); ExEdge.More(); ExEdge.Next())
{
// Getting polygons of the current face on the current edge
TopoDS_Edge myEdge;
TopoDS_Face myFace;

myEdge = TopoDS::Edge(ExEdge.Current());
myFace = TopoDS::Face(ExFace.Current());
Handle(Poly_Polygon2D) my2DPolygon = BRep_Tool::PolygonOnSurface( myEdge,myFace );
if ( NULL == my2DPolygon )
continue;

Standard_Integer nNodes = my2DPolygon->NbNodes();

TColgp_Array1OfPnt2d arrayOf2DPoints(1,nNodes);

Standard_Integer nXVal = arrayOf2DPoints(1).X();

}// edges loop
}// faces loop

Stephane Routelous's picture

Hi,
You cannot test
if ( NULL == my2DPolygon )

use

if ( my2DPolygon.IsNull())

Because the Handle_* classes are smart pointers.

HTH

Subhi Jamal's picture

Ok thanks Stephane you are right, IsnNull() returned TRUE.

Now I also tried the following, I always get IsNull() equal to TURE, why is that?

for (ExFace.Init(aShape, TopAbs_FACE); ExFace.More(); ExFace.Next())
{

TopoDS_Face F = TopoDS::Face(ExFace.Current());

TopLoc_Location L;

Handle(Poly_Triangulation) myTriangulation = BRep_Tool::Triangulation(F, L);

if ( myTriangulation .IsNull())
continue;

Standard_Integer nNodes = myTriangulation->NbNodes();
}

Jeanmi B's picture

Hello,

BRep_Tool::Triangulation does not build the triangulation, it just retrieve it from the Face.

By default TopoDS_Face have no triangulation. To build the triangulation you can use BRepMesh_IncrementalMesh

Regards.

Subhi Jamal's picture

I took a look at your link Stephane, I believe now that you have a full undersatanding of opencascade ins and outs. I hope you can help me in this:

I am currently developing an application to import IGES files, I already have an SDK for drawing elementary 3D vector objects:
POLYGON,POLYLINE,RECTANGLE,...

When I used "IGESControl_Reader" to read IGES files, I got shapes of type "TopoDS_Face". I didn't know how to deal with them, but some people here instructed me that I should convert them to surfaces.

When I took a look at the surfaces documentaion in OpenCASCADE, I couldn't understand much, and my vector SDK can't deal with surfaces.

My final goal is to be able to
-Convert any objects I get from OpenCASCADE into polylines,polygons,ellipses,..

OR

-Get the object in the form of 3D points to be able to generate them all as polygons

How can I do so?