Issues Redrawing Polygon with Handle_Graphic3d_Group


Currently I can draw a polygon using the Handle_Graphics3d_Group->Polygon like so:
Handle_Graphics3d_Group group;
Graphic3d_Array1OfVertex topVertices(0, points.size() - 1);
/* populate vertices from points*/
group->Polygon(topVertices, Graphic3d_TypeOfPolygon::Graphic3d_TOP_UNKNOWN, true);

However, on redrawing I get a read memory access error violation, which I think has to do with the topVertices not being a 'Handle' type. I can draw the polygons as primitives: 

Handle_Graphic3d_ArrayOfPolygons _polygons;
/* Populate Polygons */

But the shading and presentation do not look the same/as good as using the Polygon function. Does any have any ideas on how I can call the Group->Polygon function in a way that avoids the memory access error? I am drawing between 500 - 2000 of these polygons in 3D, and they will be aligned with a 3D plane (i.e. no curvature to the polygon surface). Or, if there is a way to remove shading/lines/create a solid coloured polygon using the second method, that would be great as well.

Any help is appreciated. 

Kirill Gavrilov's picture

Why not just define a triangulation array instead of polygons?

Note that you are referring to a functionality removed from OCCT a long time ago (4 years), but you have not even mentioned which version you are using - which is very important when you are looking for a help.

Lucas Currah's picture

My apologies Kirill. I am using OpenCascade version 6.2, so I think it is quite dated. And could you expand a little more on the triangulation array? Any starting point would be appreciated. My use case is several vertices that form the outside points of a polygon, and I would like to colour the interior of each polygon a different color. 

Kirill Gavrilov's picture

Naturally, Graphic3d_Group::AddPrimitiveArray() should provide the same functionality as Graphic3d_Group::Polygon() if array is properly initialized
(I don't know how array is initialized in your code, but I suppose it is consistent to the polygon - e.g. with the same attributes like normales / no normales, indices / no indices, etc.).

But OCCT 6.2 might have bugs in this functionality, which have been fixed very long time ago.
Thus, it is difficult to propose something without seeing debugging the code.

Lucas Currah's picture

Hi Kirill, 

I have similar results from the Graphic3d_Group::Polygon() method and Graphic3d_Group::AddPrimitiveArray(). However, the output from the Primitive array creates rendering artefacts that I would like to avoid. They are in the attached picture. With Graphic3d_Group::AddPrimitiveArray() I get these and with Graphic3d_Group::Polygon()  they look solid as I would prefer/expect. Here is some code, is there anything that you think would allow me to remove those rendering artefacts and display the polygons as solid colours?

This is the compute function for an object that inherits from AIS_PositionalObject:

// create the group
Handle(Graphic3d_Group) theGroup = Prs3d_Root::NewGroup(aPresentation);
// Create aspect/ fill style
Handle_Prs3d_ShadingAspect shad = new Prs3d_ShadingAspect();
Handle_Graphic3d_AspectFillArea3d fillAspect = new Graphic3d_AspectFillArea3d();
// Set color of polygon 
// Set drawer to use desired aspect
// Create/add primitives to the group
bool preTransform = _labelVisible;
preTransform = false;
gp_Pnt tilePosition = _tile->GetCenterPoint();
gp_Dir tileNormal(_tile->GetNormal());
std::vector<gp_Pnt> perimeterPoints;
polygons = new Graphic3d_ArrayOfPolygons(points.size(), 0, 0, Standard_False, Standard_False, Standard_False, Standard_False);
for (std::vector<gp_Pnt>::iterator it = perimterPoints.begin(); it != perimeterPoints.end(); ++it)
group->AddPrimitiveArray(polygons, true);


Kirill Gavrilov's picture

Sorry, but from this screenshot I don't even understand how polygons are supposed to be displayed - they all look like overlapping mess ;).
Are you sure your polygons satisfy GL_POLYGON criteria to be properly represented by OpenGL (which is supposed when you pass polygons to both Graphic3d_Group methods)?
I think you need to tessellate them into triangles them manually or using BRepMesh.