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 <BRepMesh_ShapeVisitor.hxx> |
17 | #include <TopoDS.hxx> |
18 | #include <TopoDS_Edge.hxx> |
19 | #include <TopoDS_Face.hxx> |
20 | #include <TopoDS_Wire.hxx> |
21 | #include <TopoDS_Vertex.hxx> |
22 | #include <TopExp.hxx> |
23 | #include <ShapeAnalysis.hxx> |
24 | #include <TopExp_Explorer.hxx> |
25 | #include <IMeshData_Edge.hxx> |
26 | #include <IMeshData_Wire.hxx> |
27 | #include <IMeshData_Face.hxx> |
28 | #include <ShapeAnalysis_Wire.hxx> |
29 | #include <ShapeAnalysis_WireOrder.hxx> |
30 | #include <ShapeExtend_WireData.hxx> |
31 | #include <Precision.hxx> |
32 | #include <IMeshData_Status.hxx> |
33 | #include <IMeshTools_Context.hxx> |
34 | #include <BRepTools.hxx> |
35 | |
36 | //======================================================================= |
37 | // Function: Constructor |
38 | // Purpose : |
39 | //======================================================================= |
40 | BRepMesh_ShapeVisitor::BRepMesh_ShapeVisitor (const Handle (IMeshData_Model)& theModel) |
41 | : myModel (theModel), |
42 | myDEdgeMap(1, new NCollection_IncAllocator(IMeshData::MEMORY_BLOCK_SIZE_HUGE)) |
43 | { |
44 | } |
45 | |
46 | //======================================================================= |
47 | // Function: Destructor |
48 | // Purpose : |
49 | //======================================================================= |
50 | BRepMesh_ShapeVisitor::~BRepMesh_ShapeVisitor () |
51 | { |
52 | } |
53 | |
54 | //======================================================================= |
55 | // Function: Visit (edge) |
56 | // Purpose : |
57 | //======================================================================= |
58 | void BRepMesh_ShapeVisitor::Visit(const TopoDS_Edge& theEdge) |
59 | { |
60 | myModel->AddEdge(theEdge); |
61 | myDEdgeMap.Bind(theEdge, myModel->EdgesNb() - 1); |
62 | } |
63 | |
64 | //======================================================================= |
65 | // Function: Visit (face) |
66 | // Purpose : |
67 | //======================================================================= |
68 | void BRepMesh_ShapeVisitor::Visit (const TopoDS_Face& theFace) |
69 | { |
70 | BRepTools::Update(theFace); |
71 | const IMeshData::IFaceHandle& aDFace = myModel->AddFace (theFace); |
72 | |
73 | // Outer wire should always be the first in the model. |
74 | TopoDS_Wire aOuterWire = ShapeAnalysis::OuterWire (theFace); |
75 | if (!addWire (aOuterWire, aDFace)) |
76 | { |
77 | aDFace->SetStatus (IMeshData_Failure); |
78 | return; |
79 | } |
80 | |
81 | TopExp_Explorer aWireIt (theFace, TopAbs_WIRE); |
82 | for (; aWireIt.More (); aWireIt.Next ()) |
83 | { |
84 | const TopoDS_Wire& aWire = TopoDS::Wire (aWireIt.Current ()); |
85 | if (aWire.IsSame(aOuterWire)) |
86 | { |
87 | continue; |
88 | } |
89 | |
90 | if (!addWire (aWire, aDFace)) |
91 | { |
92 | // If there is a failure on internal wire, just skip it. |
93 | // The most significant is an outer wire. |
94 | aDFace->SetStatus (IMeshData_UnorientedWire); |
95 | } |
96 | } |
97 | } |
98 | |
99 | //======================================================================= |
100 | // Function: addWire |
101 | // Purpose : |
102 | //======================================================================= |
103 | Standard_Boolean BRepMesh_ShapeVisitor::addWire ( |
104 | const TopoDS_Wire& theWire, |
105 | const IMeshData::IFaceHandle& theDFace) |
106 | { |
107 | if (theWire.IsNull()) |
108 | { |
109 | return Standard_False; |
110 | } |
111 | |
112 | Handle(ShapeExtend_WireData) aWireData = new ShapeExtend_WireData(theWire, Standard_True, Standard_False); |
113 | ShapeAnalysis_Wire aWireTool (aWireData, theDFace->GetFace (), Precision::Confusion ()); |
114 | |
115 | ShapeAnalysis_WireOrder aOrderTool; |
116 | aWireTool.CheckOrder (aOrderTool, Standard_True, Standard_False); |
117 | if (aWireTool.LastCheckStatus(ShapeExtend_FAIL)) |
118 | { |
119 | return Standard_False; |
120 | } |
121 | |
122 | if (aWireTool.LastCheckStatus(ShapeExtend_DONE3)) |
123 | { |
124 | theDFace->SetStatus(IMeshData_UnorientedWire); |
125 | } |
126 | |
127 | const Standard_Integer aEdgesNb = aOrderTool.NbEdges (); |
128 | if (aEdgesNb != aWireData->NbEdges()) |
129 | { |
130 | return Standard_False; |
131 | } |
132 | |
133 | const IMeshData::IWireHandle& aDWire = theDFace->AddWire (theWire, aEdgesNb); |
134 | for (Standard_Integer i = 1; i <= aEdgesNb; ++i) |
135 | { |
136 | const Standard_Integer aEdgeIndex = aOrderTool.Ordered (i); |
137 | const TopoDS_Edge& aEdge = aWireData->Edge (aEdgeIndex); |
138 | if (aEdge.Orientation() != TopAbs_EXTERNAL) |
139 | { |
140 | const IMeshData::IEdgeHandle& aDEdge = myModel->GetEdge (myDEdgeMap.Find (aEdge)); |
141 | |
142 | aDEdge->AddPCurve (theDFace.get(), aEdge.Orientation()); |
143 | aDWire->AddEdge (aDEdge.get(), aEdge.Orientation()); |
144 | } |
145 | } |
146 | |
147 | return Standard_True; |
148 | } |