Tue, 01/10/2017 - 14:45
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 aRadius = 10;
//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);
}
inline void ReadIGES(const char* filename)
{
//! IGES FILE READER BASED ON OCC BACKEND
//! THIS FUNCTION CAN BE EXPANDED FURTHER TO TAKE CURVE/SURFACE CONSISTENY INTO ACCOUNT
//! http://www.opencascade.org/doc/occt-6.7.0/overview/html/user_guides__ige...
IGESControl_Reader reader;
reader.ReadFile(filename);
// CHECK FOR IMPORT STATUS
reader.PrintCheckLoad(Standard_True,IFSelect_GeneralInfo);
reader.PrintCheckTransfer(Standard_True,IFSelect_ItemsByEntity);
// READ IGES FILE AS-IS
Interface_Static::SetIVal("read.iges.bspline.continuity",0);
Standard_Integer ic = Interface_Static::IVal("read.iges.bspline.continuity");
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)
//Interface_Static::SetIVal("xstep.cascade.unit",0);
//Interface_Static::SetIVal("read.scale.unit",0);
// IF ALL OKAY, THEN TRANSFER ROOTS
reader.TransferRoots();
TopoDS_Shape imported_shape = reader.OneShape();
Standard_Integer no_of_shapes = reader.NbShapes();
std::cout<<no_of_shapes<<"\n";
getMesh(imported_shape);
}
Tue, 01/10/2017 - 15:24
Hello,
Try to use sewing (BRepBuilderAPI_Sewing) after reading. It seems that your model doesn't have shared edges.
Qa Qa
Tue, 01/10/2017 - 16:03
Thanks a lot for your answer. It is possible to make shared edge in this case? Can you give simple Example of code?
Tue, 01/10/2017 - 16:12
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);
Sewer.Load(shape);
// Perform sewing
Sewer.Perform();
shape = Sewer.SewedShape();
return true;
}
This will recover sharing for your edges and the mesh will become conformed.
Tue, 01/10/2017 - 16:32
Thank you. Result is very good
Tue, 01/10/2017 - 16:10
Sorry, I check another iges files. And mesh generated good. Problem was with my file. Model doesn't have shared edges.
Fri, 01/13/2017 - 14:26
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?