7bd071ed |
1 | // Created on: 2016-04-07 |
2 | // Copyright (c) 2016 OPEN CASCADE SAS |
3 | // Created by: Oleg AGASHIN |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <IMeshTools_ShapeExplorer.hxx> |
17 | #include <TopExp.hxx> |
18 | #include <TopExp_Explorer.hxx> |
19 | #include <TopoDS.hxx> |
20 | #include <TopoDS_Face.hxx> |
21 | #include <TopoDS_Edge.hxx> |
22 | #include <TopTools_ListOfShape.hxx> |
23 | #include <BRepLib.hxx> |
24 | #include <BRep_Tool.hxx> |
25 | #include <TopTools_MapOfShape.hxx> |
26 | #include <Geom_Surface.hxx> |
27 | |
28 | //======================================================================= |
29 | // Function: Constructor |
30 | // Purpose : |
31 | //======================================================================= |
32 | IMeshTools_ShapeExplorer::IMeshTools_ShapeExplorer ( |
33 | const TopoDS_Shape& theShape) |
34 | : IMeshData_Shape (theShape) |
35 | { |
36 | } |
37 | |
38 | //======================================================================= |
39 | // Function: Destructor |
40 | // Purpose : |
41 | //======================================================================= |
42 | IMeshTools_ShapeExplorer::~IMeshTools_ShapeExplorer () |
43 | { |
44 | } |
45 | |
46 | //======================================================================= |
47 | // Function: Accept |
48 | // Purpose : |
49 | //======================================================================= |
50 | void IMeshTools_ShapeExplorer::Accept ( |
51 | const Handle (IMeshTools_ShapeVisitor)& theVisitor) |
52 | { |
53 | // Explore all edges in shape - either free or related to some face. |
54 | TopTools_IndexedMapOfShape aEdges; |
55 | TopExp::MapShapes (GetShape (), TopAbs_EDGE, aEdges); |
56 | |
57 | TopTools_IndexedMapOfShape::Iterator aEdgeIt (aEdges); |
58 | for (; aEdgeIt.More (); aEdgeIt.Next ()) |
59 | { |
60 | const TopoDS_Edge& aEdge = TopoDS::Edge (aEdgeIt.Value ()); |
61 | if (!BRep_Tool::IsGeometric(aEdge)) |
62 | { |
63 | continue; |
64 | } |
65 | |
66 | theVisitor->Visit (aEdge); |
67 | } |
68 | |
69 | // Explore faces |
70 | TopTools_ListOfShape aFaceList; |
71 | BRepLib::ReverseSortFaces (GetShape (), aFaceList); |
72 | TopTools_MapOfShape aFaceMap; |
73 | |
74 | // make array of faces suitable for processing (excluding faces without surface) |
75 | TopLoc_Location aDummyLoc; |
76 | const TopLoc_Location aEmptyLoc; |
77 | TopTools_ListIteratorOfListOfShape aFaceIter (aFaceList); |
78 | for (; aFaceIter.More (); aFaceIter.Next ()) |
79 | { |
80 | TopoDS_Shape aFaceNoLoc = aFaceIter.Value (); |
81 | aFaceNoLoc.Location (aEmptyLoc); |
82 | if (!aFaceMap.Add(aFaceNoLoc)) |
83 | { |
84 | continue; // already processed |
85 | } |
86 | |
87 | TopoDS_Face aFace = TopoDS::Face (aFaceIter.Value ()); |
88 | const Handle (Geom_Surface)& aSurf = BRep_Tool::Surface (aFace, aDummyLoc); |
89 | if (aSurf.IsNull()) |
90 | { |
91 | continue; |
92 | } |
93 | |
94 | // Store only forward faces in order to prevent inverse issue. |
95 | theVisitor->Visit (TopoDS::Face (aFace.Oriented (TopAbs_FORWARD))); |
96 | } |
97 | } |