Error with triangulation OCC

Hello Supervisors!

I have a error message trying to explore and triangulate a shape! I found the following sample example from forum, and i couldn't solve the error!
It just stacked, hope to read from you!
Here is below the code! of the meshing part!

// ===============================================================================================
//meshing part here//////

Standard_Real aDeflection=0.3;
// aDeflection = ... ;

// removes all the triangulations of the faces ,
//and all the polygons on the triangulations of the edges:
// BRepTools::Clean(aCyl);

// adds a triangulation of the shape aShape with the deflection aDeflection:
BRepMesh::Mesh(shape,aDeflection);
BRep_Builder builder;
TopoDS_Compound Comp;
builder.MakeCompound(Comp);
TopExp_Explorer aExpFace,aExpEdge;
for(aExpFace.Init(shape,TopAbs_FACE);aExpFace.More();aExpFace.Next())
{
TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());
TopLoc_Location aLocation;

// takes the triangulation of the face aFace:
// Standard_Integer nbNodes, nbTriangles;
// Standard_Boolean UVNodes;
gp_Pnt2d uv; gp_Pnt vertex; gp_Vec faceNormale;
Handle(Poly_Triangulation) aTr = BRep_Tool::Triangulation(aFace,aLocation);

if(!aTr.IsNull()) // if this triangulation is not NULL
{

// takes the array of nodes for this triangulation:

const TColgp_Array1OfPnt& aNodes = aTr->NbNodes();

// takes the array of triangles for this triangulation:
const Poly_Array1OfTriangle& triangles = aTr->NbTriangles();

// create array of node points in absolute coordinate system
TColgp_Array1OfPnt aPoints(1, aNodes.Length());
for( Standard_Integer i = 1; i aPoints(i) = aNodes(i).Transformed(aLocation);

// Takes the node points of each triangle of this triangulation.
// takes a number of triangles:
Standard_Integer nnn = aTr->NbTriangles();
Standard_Integer nt,n1,n2,n3;
for( nt = 1 ; nt {
// takes the node indices of each triangle in n1,n2,n3:
triangles(nt).Get(n1,n2,n3);
// takes the node points:
gp_Pnt aPnt1 = aPoints(n1);
gp_Pnt aPnt2 = aPoints(n2);
gp_Pnt aPnt3 = aPoints(n3);

Handle(Geom_TrimmedCurve) meshSegment1 = GC_MakeSegment(aPnt1 , aPnt2);

Handle(Geom_TrimmedCurve) meshSegment2 = GC_MakeSegment(aPnt1 , aPnt3);

Handle(Geom_TrimmedCurve) meshSegment3 = GC_MakeSegment(aPnt2 , aPnt3);

TopoDS_Edge meshEdge1 = BRepBuilderAPI_MakeEdge(meshSegment1);

TopoDS_Edge meshEdge2 = BRepBuilderAPI_MakeEdge(meshSegment2);

TopoDS_Edge meshEdge3 = BRepBuilderAPI_MakeEdge(meshSegment3);

BRepBuilderAPI_MakeWire meshWire(meshEdge1 , meshEdge3 , meshEdge2);

Handle(AIS_Shape) anAISShape = new AIS_Shape(meshWire.Shape());

// context->Display( anAISShape, false );

// Takes the polygon associated to an edge.
aExpEdge.Init(aFace,TopAbs_EDGE);
TopoDS_Edge aEdge;
// for example,working with the first edge:
if(aExpEdge.More())
aEdge = TopoDS::Edge(aExpEdge.Current());

if(!aEdge.IsNull()) // if this edge is not NULL
{
// takes the polygon associated to the edge aEdge:
Handle_Poly_PolygonOnTriangulation aPol =
BRep_Tool::PolygonOnTriangulation(aEdge,aTr,aEdge.Location());

if(!aPol.IsNull()) // if this polygon is not NULL
// takes the array of nodes for this polygon
// (indexes in the array of nodes for triangulation of theFace):
const TColStd_Array1OfInteger& aNodesOfPol = aPol->Nodes();
}
}

context->Display( anAISShape, false );
}
}

ERROR MESSAGE.......................................

main.cpp:193:54: error: invalid initialization of reference of type ‘const TColgp_Array1OfPnt&’ from expression of type ‘Standard_Integer {aka int}’
main.cpp:196:64: error: invalid initialization of reference of type ‘const Poly_Array1OfTriangle&’ from expression of type ‘Standard_Integer {aka int}’
main.cpp:230:73: error: invalid use of incomplete type ‘struct AIS_Shape’
/usr/local/opecascade-6.5.2/inc/Handle_AIS_Shape.hxx:23:7: error: forward declaration of ‘struct AIS_Shape’
main.cpp:252:55: error: invalid use of incomplete type ‘struct Poly_PolygonOnTriangulation’
/usr/local/opecascade-6.5.2/inc/Handle_Poly_PolygonOnTriangulation.hxx:23:7: error: forward declaration of ‘struct Poly_PolygonOnTriangulation’
main.cpp:256:6: error: ‘context’ was not declared in this scope
main.cpp:256:24: error: ‘anAISShape’ was not declared in this scope

I work with OCC652 and Qt for information!

Regards

Game

Alexander Schneller's picture

Hi Game,

I am not familiar with meshing but,

1) change "const TColgp_Array1OfPnt& aNodes = aTr->NbNodes();"
to "const TColgp_Array1OfPnt& aNodes = aTr->Nodes();"

2)"const Poly_Array1OfTriangle& triangles = aTr->NbTriangles();"
to "const Poly_Array1OfTriangle& triangles = aTr->Triangles();"

3) "Handle(AIS_Shape) anAISShape = new AIS_Shape(meshWire.Shape());"
is declared locally in the for loop, but used outside from it.

hope that helps.

Regards
Alex

Game Milky's picture

Thank you very much Alex,
Your information much solved my problem, I corrected all according to your correction!Most of the error solved!
But I still have an error at: const TColStd_Array1OfInteger& aNodesOfPol = aPol->Nodes(); and context->Display(anAISShape, false );

Here is the error
main.cpp:255:55: error: invalid use of incomplete type ‘struct Poly_PolygonOnTriangulation’
/usr/local/opecascade-6.5.2/inc/Handle_Poly_PolygonOnTriangulation.hxx:23:7: error: forward declaration of ‘struct Poly_PolygonOnTriangulation’
main.cpp:255:37: warning: unused variable ‘aNodesOfPol’ [-Wunused-variable]
main.cpp:257:4: error: ‘context’ was not declared in this scope

Thank you for your help in advance!

With best Regards

Game

Alexander Schneller's picture

1) "main.cpp:255:55: error: invalid use of incomplete type ‘struct Poly_PolygonOnTriangulation’"
try to include "#include "

2) "main.cpp:257:4: error: ‘context’ was not declared in this scope"
You need to declare an AIS_InteractiveContext (visu.pdf, page 24, 3. 1. 1 Interactive Context/Local Context)
if you use Draw to display objects, you can use:
-------------------------------
#include
Handle (AIS_InteractiveContext) theContext = ViewerTest::GetAISContext();
-------------------------------
to get an AIS_InteractiveContext. It depends on the structure of your program.

You may take a look at the examples of OCC, to find another way for you to get an AIS_InteractiveContext.

Regards and a nice weekend
Alex