1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <BRep_Builder.hxx>
16 #include <BRepBuilderAPI_MakeFace.hxx>
17 #include <BRepBuilderAPI_MakePolygon.hxx>
18 #include <BRepBuilderAPI_MakeVertex.hxx>
19 #include <BRepBuilderAPI_Sewing.hxx>
21 #include <OSD_Path.hxx>
23 #include <StlAPI_Reader.hxx>
24 #include <StlMesh_Mesh.hxx>
25 #include <StlMesh_MeshExplorer.hxx>
26 #include <TopoDS_Compound.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Face.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Shell.hxx>
31 #include <TopoDS_Vertex.hxx>
32 #include <TopoDS_Wire.hxx>
34 StlAPI_Reader::StlAPI_Reader() {}
36 void StlAPI_Reader::Read(TopoDS_Shape& aShape, const Standard_CString aFileName)
38 OSD_Path aFile(aFileName);
40 Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile(aFile);
41 Standard_Integer NumberDomains = aSTLMesh->NbDomains();
44 TopoDS_Vertex Vertex1, Vertex2, Vertex3;
47 BRepBuilderAPI_Sewing aSewingTool;
48 Standard_Real x1, y1, z1;
49 Standard_Real x2, y2, z2;
50 Standard_Real x3, y3, z3;
52 aSewingTool.Init(1.0e-06,Standard_True);
54 TopoDS_Compound aComp;
55 BRep_Builder BuildTool;
56 BuildTool.MakeCompound( aComp );
58 StlMesh_MeshExplorer aMExp (aSTLMesh);
60 for (iND=1;iND<=NumberDomains;iND++)
62 for (aMExp.InitTriangle (iND); aMExp.MoreTriangle (); aMExp.NextTriangle ())
64 aMExp.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3);
65 p1.SetCoord(x1,y1,z1);
66 p2.SetCoord(x2,y2,z2);
67 p3.SetCoord(x3,y3,z3);
69 if ((!(p1.IsEqual(p2,0.0))) && (!(p1.IsEqual(p3,0.0))))
71 Vertex1 = BRepBuilderAPI_MakeVertex(p1);
72 Vertex2 = BRepBuilderAPI_MakeVertex(p2);
73 Vertex3 = BRepBuilderAPI_MakeVertex(p3);
75 AktWire = BRepBuilderAPI_MakePolygon( Vertex1, Vertex2, Vertex3, Standard_True);
77 if( !AktWire.IsNull())
79 AktFace = BRepBuilderAPI_MakeFace( AktWire);
81 BuildTool.Add( aComp, AktFace );
88 aSewingTool.Load( aComp );
89 aSewingTool.Perform();
90 aShape = aSewingTool.SewedShape();
91 if ( aShape.IsNull() )