# Problem: Algoritm gets mesh with holes (inconsistent mesh)

Hello i am try to create converter from iges to mesh. In the iges file contains Solid body. Algorithm successfully generate mesh, but vertices of the triangles is not aligned.See image below. How to get mesh with aligned vertices?

I Use this Code for mesh generating:

inline void getMesh(TopoDS_Shape aShape){

//const Standard_Real aHeight = 10;
//const Standard_Real aLinearDeflection = 5;
//const Standard_Real anAngularDeflection = 5;
BRepMesh_IncrementalMesh aMesh(aShape, 8);

std::cout<<"triangles:\n";
ofstream myfile;
myfile.open ("example.stl");
myfile <<"solid csg.js\n";

for (TopExp_Explorer ex(aShape, TopAbs_FACE); ex.More(); ex.Next())
{
// Triangulate current face
TopoDS_Face F = TopoDS::Face(ex.Current());
TopLoc_Location L = TopLoc_Location();
Handle(Poly_Triangulation) facing = BRep_Tool::Triangulation(F, L);
int nbtris = facing->NbTriangles();
std::cout<<nbtris;
std::cout<<" \n";
const Poly_Array1OfTriangle & triangles = facing->Triangles();
const TColgp_Array1OfPnt & nodes = facing->Nodes();
for (int i = facing->NbTriangles(); i >= 1; i--)
{

myfile << "facet normal "<<0.0<<" "<<0.0<<" "<<0.0<<"\n";
myfile << "outer loop\n";

Poly_Triangle triangle = triangles(i);

Standard_Integer node1, node2, node3;
triangle.Get(node1, node2, node3);

gp_Pnt v1 = nodes(node1);
gp_Pnt v2 = nodes(node2);
gp_Pnt v3 = nodes(node3);
myfile << "vertex "<<v1.X()<<" "<<v1.Y()<<" "<<v1.Z()<<"\n";
myfile << "vertex "<<v2.X()<<" "<<v2.Y()<<" "<<v2.Z()<<"\n";
myfile << "vertex "<<v3.X()<<" "<<v3.Y()<<" "<<v3.Z()<<"\n";
myfile << "endloop\n";
myfile << "endfacet\n";

}

}
myfile <<"endsolid csg.js\n";
myfile.close();

//Handle_Poly_Triangulation theTriangulation = BRep_Tool::Triangulation(aFace, theLocation);
}

{
//! IGES FILE READER BASED ON OCC BACKEND
//! THIS FUNCTION CAN BE EXPANDED FURTHER TO TAKE CURVE/SURFACE CONSISTENY INTO ACCOUNT

// CHECK FOR IMPORT STATUS
if (ic !=0)
{
std::cerr << "IGES file was not read as-is. The file was not read/transformed correctly\n";
}

// FORCE UNITS (NONE SEEM TO WORK)

// IF ALL OKAY, THEN TRANSFER ROOTS

std::cout<<no_of_shapes<<"\n";
getMesh(imported_shape);
}

Attachments:

Hello,

Try to use sewing (BRepBuilderAPI_Sewing) after reading. It seems that your model doesn't have shared edges.

Qa Qa

Thanks a lot for your answer. It is possible to make shared edge in this case? Can you give simple Example of code?

Here is a sample code:

//! Performs sewing.
//! \param[in,out] shape     shape to sew.
//! \param[in]     tolerance sewing tolerance.
//! \return true in case of success, false -- otherwise.
bool Sew(TopoDS_Shape& shape, const double  tolerance)
{
BRepBuilderAPI_Sewing Sewer(tolerance);

// Perform sewing
Sewer.Perform();
shape = Sewer.SewedShape();
return true;
}

This will recover sharing for your edges and the mesh will become conformed.

Thank you. Result is very good

Sorry, I check another iges files. And mesh generated good. Problem was with my file. Model doesn't have shared edges.

Hello i try convert igs file to mesh (stl). Geometry from file "141A.IGS" looks correct (inputIGS.jpg), but algorithm getMesh() (see post #1)  gets wrong mesh("result.stl","Wrong output mesh.jpg"). What could happen?

Attachments: