1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
void StlReadIn::STL_Import()
{
std::string FileName;
std::cout<<"\nEnter the file name\n";
std::cin>>FileName;
OSD_Path aFile(FileName.c_str());
Standard_Boolean ReturnValue = Standard_True;
Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile(aFile);
TopoDS_Compound ResultShape;
BRep_Builder CompoundBuilder;
CompoundBuilder.MakeCompound(ResultShape);
Standard_Integer NumberDomains = aSTLMesh->NbDomains(); // The error shows here
Standard_Integer iND;
gp_XYZ p1, p2, p3;
TopoDS_Vertex Vertex1, Vertex2, Vertex3;
TopoDS_Face AktFace;
TopoDS_Wire AktWire;
BRep_Builder B;
Standard_Real x1, y1, z1;
Standard_Real x2, y2, z2;
Standard_Real x3, y3, z3;
StlMesh_MeshExplorer aMExp (aSTLMesh);
// BRepBuilderAPI_MakeWire WireCollector;
for (iND=1;iND<=NumberDomains;iND++)
{
for (aMExp.InitTriangle (iND); aMExp.MoreTriangle (); aMExp.NextTriangle ())
{
aMExp.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3);
p1.SetCoord(x1,y1,z1);
p2.SetCoord(x2,y2,z2);
p3.SetCoord(x3,y3,z3);
if ((!(p1.IsEqual(p2,0.0))) && (!(p1.IsEqual(p3,0.0))))
{
Vertex1 = BRepBuilderAPI_MakeVertex(p1);
Vertex2 = BRepBuilderAPI_MakeVertex(p2);
Vertex3 = BRepBuilderAPI_MakeVertex(p3);
AktWire = BRepBuilderAPI_MakePolygon( Vertex1, Vertex2, Vertex3, Standard_True);
if( !AktWire.IsNull())
{
AktFace = BRepBuilderAPI_MakeFace( AktWire);
if(!AktFace.IsNull())
CompoundBuilder.Add(ResultShape,AktFace);
}
}
}
}
TopoDS_Shape aShape = ResultShape;
}
|