]>
Commit | Line | Data |
---|---|---|
973c2be1 | 1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 2 | // |
973c2be1 | 3 | // This file is part of Open CASCADE Technology software library. |
b311480e | 4 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 10 | // |
973c2be1 | 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. | |
b311480e | 13 | |
42cf5bc1 | 14 | |
7fd59977 | 15 | #include <BRep_Builder.hxx> |
7fd59977 | 16 | #include <BRepBuilderAPI_MakeFace.hxx> |
42cf5bc1 | 17 | #include <BRepBuilderAPI_MakePolygon.hxx> |
18 | #include <BRepBuilderAPI_MakeVertex.hxx> | |
7fd59977 | 19 | #include <BRepBuilderAPI_Sewing.hxx> |
20 | #include <gp_Pnt.hxx> | |
42cf5bc1 | 21 | #include <OSD_Path.hxx> |
22 | #include <RWStl.hxx> | |
23 | #include <StlAPI_Reader.hxx> | |
24 | #include <StlMesh_Mesh.hxx> | |
25 | #include <StlMesh_MeshExplorer.hxx> | |
7fd59977 | 26 | #include <TopoDS_Compound.hxx> |
7fd59977 | 27 | #include <TopoDS_Edge.hxx> |
7fd59977 | 28 | #include <TopoDS_Face.hxx> |
42cf5bc1 | 29 | #include <TopoDS_Shape.hxx> |
7fd59977 | 30 | #include <TopoDS_Shell.hxx> |
42cf5bc1 | 31 | #include <TopoDS_Vertex.hxx> |
32 | #include <TopoDS_Wire.hxx> | |
7fd59977 | 33 | |
34 | StlAPI_Reader::StlAPI_Reader() {} | |
35 | ||
36 | void StlAPI_Reader::Read(TopoDS_Shape& aShape, const Standard_CString aFileName) | |
37 | { | |
38 | OSD_Path aFile(aFileName); | |
39 | ||
40 | Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile(aFile); | |
41 | Standard_Integer NumberDomains = aSTLMesh->NbDomains(); | |
42 | Standard_Integer iND; | |
43 | gp_XYZ p1, p2, p3; | |
44 | TopoDS_Vertex Vertex1, Vertex2, Vertex3; | |
45 | TopoDS_Face AktFace; | |
46 | TopoDS_Wire AktWire; | |
47 | BRepBuilderAPI_Sewing aSewingTool; | |
48 | Standard_Real x1, y1, z1; | |
49 | Standard_Real x2, y2, z2; | |
50 | Standard_Real x3, y3, z3; | |
51 | ||
52 | aSewingTool.Init(1.0e-06,Standard_True); | |
53 | ||
54 | TopoDS_Compound aComp; | |
55 | BRep_Builder BuildTool; | |
56 | BuildTool.MakeCompound( aComp ); | |
57 | ||
58 | StlMesh_MeshExplorer aMExp (aSTLMesh); | |
59 | ||
60 | for (iND=1;iND<=NumberDomains;iND++) | |
61 | { | |
62 | for (aMExp.InitTriangle (iND); aMExp.MoreTriangle (); aMExp.NextTriangle ()) | |
63 | { | |
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); | |
68 | ||
69 | if ((!(p1.IsEqual(p2,0.0))) && (!(p1.IsEqual(p3,0.0)))) | |
70 | { | |
71 | Vertex1 = BRepBuilderAPI_MakeVertex(p1); | |
72 | Vertex2 = BRepBuilderAPI_MakeVertex(p2); | |
73 | Vertex3 = BRepBuilderAPI_MakeVertex(p3); | |
74 | ||
75 | AktWire = BRepBuilderAPI_MakePolygon( Vertex1, Vertex2, Vertex3, Standard_True); | |
76 | ||
77 | if( !AktWire.IsNull()) | |
78 | { | |
79 | AktFace = BRepBuilderAPI_MakeFace( AktWire); | |
80 | if(!AktFace.IsNull()) | |
81 | BuildTool.Add( aComp, AktFace ); | |
82 | } | |
83 | } | |
84 | } | |
85 | } | |
86 | aSTLMesh->Clear(); | |
87 | ||
88 | aSewingTool.Load( aComp ); | |
89 | aSewingTool.Perform(); | |
90 | aShape = aSewingTool.SewedShape(); | |
91 | if ( aShape.IsNull() ) | |
92 | aShape = aComp; | |
93 | } | |
94 |