Problem ith tessellation(no smoothing surface)

Hello

I want to tessellate a shape loaded from a step file. My problem that I found many faces NULL which can't be tessellated. I reduce the value of deflection but also i have some faces null. The code used as below :

qDebug()<<"begin tesselation"<<endl;

Standard_Real aDeflection = 1e-6;

Standard_Real angularDeflection=1e-6;

Standard_Integer aNumOfFace = 1;

Standard_Integer aNumOfEdge = 2;

 

 

//==========================================================================

 

BRepTools::Clean(aShape);

BRepMesh_IncrementalMesh(aShape,aDeflection,angularDeflection);

 

BRep_Builder aBuilder,aBuild1,aBuild2;

TopoDS_Compound aCompound,aComp1,aComp2;

aBuilder.MakeCompound(aCompound);

aBuild1.MakeCompound(aComp1);

aBuild2.MakeCompound(aComp2);

 

TopTools_SequenceOfShape aVertices;

Standard_Integer aCount = 0;

Standard_Integer aNumOfNodes = 0;

Standard_Integer aNumOfTriangles = 0;

 

 

TopExp_Explorer aExpFace,aExpEdge;

 

for(aExpFace.Init(aShape,TopAbs_FACE);aExpFace.More();aExpFace.Next())

{

aCount++;

 

TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());

TopLoc_Location aLocation;

 

Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);

 

if(!aTr.IsNull())

{

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

aNumOfNodes += aTr->NbNodes();

//Standard_Integer aLower = aNodes.Lower();

//Standard_Integer anUpper = aNodes.Upper();

const Poly_Array1OfTriangle& triangles = aTr->Triangles();

aNumOfTriangles += aTr->NbTriangles();

 

if(aCount == aNumOfFace)

{

Standard_Integer aNbOfNodesOfFace = aTr->NbNodes();

Standard_Integer aNbOfTrianglesOfFace = aTr->NbTriangles();

aExpEdge.Init(aFace,TopAbs_EDGE);

 

TopoDS_Edge aEdge;

 

for( Standard_Integer i = 0; aExpEdge.More() && i < aNumOfEdge ; aExpEdge.Next(), i++)

aEdge = TopoDS::Edge(aExpEdge.Current());

 

if(!aEdge.IsNull())

{

Handle_Poly_PolygonOnTriangulation aPol =

BRep_Tool::PolygonOnTriangulation(aEdge,aTr,aEdge.Location());

 

if(!aPol.IsNull())

{

const TColStd_Array1OfInteger& aNodesOfPol = aPol->Nodes();

Standard_Integer aNbOfNodesOfEdge = aPol->NbNodes();

 

Standard_Integer aLower = aNodesOfPol.Lower(), anUpper = aNodesOfPol.Upper();

for( int i = aLower; i < anUpper ; i++)

{

gp_Pnt aPnt1 = aNodes(aNodesOfPol(i)).Transformed(aLocation);

gp_Pnt aPnt2 = aNodes(aNodesOfPol(i+1)).Transformed(aLocation);

TopoDS_Vertex aVertex1 = BRepBuilderAPI_MakeVertex (aPnt1);

TopoDS_Vertex aVertex2 = BRepBuilderAPI_MakeVertex (aPnt2);

 

if(!aVertex1.IsNull() && !aVertex2.IsNull() && // if vertices are "alive"

!BRep_Tool::Pnt(aVertex1).IsEqual(

BRep_Tool::Pnt(aVertex2),Precision::Confusion())) // if they are different

{

aEdge = BRepBuilderAPI_MakeEdge (aVertex1,aVertex2);

aBuild2.Add(aComp2,aVertex1);

if(!aEdge.IsNull())

aBuild2.Add(aComp2,aEdge);

if(i == anUpper-1)

aBuild2.Add(aComp2,aVertex2);

}

}

}

}

}

 

 

TopTools_DataMapOfIntegerShape aEdges;

TopTools_SequenceOfShape aVertices;

 

for( Standard_Integer i = 1; i < aNodes.Length()+1; i++)

{

gp_Pnt aPnt = aNodes(i).Transformed(aLocation);

TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(aPnt);

 

if(!aVertex.IsNull())

{

aBuilder.Add(aCompound,aVertex);

if(aCount == aNumOfFace )

aBuild1.Add(aComp1,aVertex);

aVertices.Append(aVertex);

}

}

 

Standard_Integer nnn = aTr->NbTriangles();

//aNodes=aTr->Nodes();

Standard_Integer nt,n1,n2,n3;

 

for( nt = 1 ; nt < nnn+1 ; nt++)

{

triangles(nt).Get(n1,n2,n3);

gp_Pnt v1 = aNodes(n1);

gp_Pnt v2 = aNodes(n2);

gp_Pnt v3 = aNodes(n3);

mesh->addFace(QVector3D(v1.X(),v1.Y(),v1.Z()),QVector3D(v2.X(),v2.Y(),v2.Z()),QVector3D(v3.X(),v3.Y(),v3.Z()));

 

 

Standard_Integer key[3];

 

TopoDS_Vertex aV1,aV2;

key[0] = _key(n1, n2);

if(!aEdges.IsBound(key[0]))

{

aV1 = TopoDS::Vertex(aVertices(n1));

aV2 = TopoDS::Vertex(aVertices(n2));

if(!aV1.IsNull() && !aV2.IsNull() &&

!BRep_Tool::Pnt(aV1).IsEqual(BRep_Tool::Pnt(aV2),Precision::Confusion()))

{

TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge (aV1,aV2);

if(!aEdge.IsNull())

{

aEdges.Bind(key[0], aEdge);

aBuilder.Add(aCompound,aEdges(key[0]));

if(aCount == aNumOfFace)

aBuild1.Add(aComp1,aEdges(key[0]));

}

}

}

 

key[1] = _key(n2,n3);

if(!aEdges.IsBound(key[1]))

{

aV1 = TopoDS::Vertex(aVertices(n2));

aV2 = TopoDS::Vertex(aVertices(n3));

if(!aV1.IsNull() && !aV2.IsNull() &&

!BRep_Tool::Pnt(aV1).IsEqual(BRep_Tool::Pnt(aV2),Precision::Confusion()))

{

TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge (aV1,aV2);

if(!aEdge.IsNull())

{

aEdges.Bind(key[1],aEdge);

aBuilder.Add(aCompound,aEdges(key[1]));

if(aCount == aNumOfFace)

aBuild1.Add(aComp1,aEdges(key[1]));

}

}

}

 

key[2] = _key(n3,n1);

if(!aEdges.IsBound(key[2]))

{

aV1 = TopoDS::Vertex(aVertices(n3));

aV2 = TopoDS::Vertex(aVertices(n1));

if(!aV1.IsNull() && !aV2.IsNull() &&

!BRep_Tool::Pnt(aV1).IsEqual(BRep_Tool::Pnt(aV2),Precision::Confusion()))

{

TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge (aV1,aV2);

if(!aEdge.IsNull())

{

aEdges.Bind(key[2],aEdge);

aBuilder.Add(aCompound,aEdges(key[2]));

if(aCount == aNumOfFace)

aBuild1.Add(aComp1,aEdges(key[2]));

}

}

}

}

 

if(aCount == aNumOfFace)

{

qDebug()<<"aCount == aNumOfFace"<<endl;

}

}

else

{

qDebug()<<"face NULL"<<endl;

}

}

Thank you very much for your help 

dphil's picture

Have you tried increasing the deflection and angle? You are using extremely small values. I am not certain, but this could be trying to make mesh triangles that are too small and thus unable to properly create them. You could try something like 0.001 for deflection and 0.1 for angle. Those are probably more reasonable values for many situations.

EDIT: Oh, I just saw your other recent post where you had already tried 0.1 for deflection and angle. Are you sure the Null triangulations you are finding are actually a problem? I occasionally get that in my tessellations as well, but it has never made any noticeable impact on the quality of the output. I believe these are just faces that could not produce proper triangles for whatever reason, such as extremely tiny or collinear features which can be ignored for the sake of a mesh. But it might also be possible that you are dealing with shapes that have some problematic features, in which case perhaps some shape fixing/healing tool could help.

ATTIA's picture

Thank you very much for your reply. I have increased the deflection and angle deflection but the number of null faces are increased also. (with od value, i have 2 null faces but with new values I have 14 null faces) . I think that the probem is in storage function. In fact, I save the mesh of each face. but if I have a method that save the mesh directly I think that the problem will be ignored.