7fd59977 |
1 | // File: HLRBRep_ShapeToHLR.cxx |
2 | // Created: Thu Aug 27 12:33:14 1992 |
3 | // Author: Christophe MARION |
4 | // <cma@sdsun2> |
5 | #ifndef No_Exception |
6 | // #define No_Exception |
7 | #endif |
8 | #include <HLRBRep_ShapeToHLR.ixx> |
9 | |
10 | #include <TopAbs.hxx> |
11 | #include <TopExp.hxx> |
12 | #include <TopExp_Explorer.hxx> |
13 | #include <TopoDS.hxx> |
14 | #include <TopoDS_Vertex.hxx> |
15 | #include <TopoDS_Edge.hxx> |
16 | #include <TopoDS_Face.hxx> |
17 | #include <TopoDS_Iterator.hxx> |
18 | #include <TopTools_ListOfShape.hxx> |
19 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
20 | #include <TopTools_MapOfShape.hxx> |
21 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
22 | #include <BRepTools.hxx> |
23 | #include <BRep_Tool.hxx> |
24 | #include <HLRBRep.hxx> |
25 | #include <BRepTopAdaptor_MapOfShapeTool.hxx> |
26 | |
27 | //======================================================================= |
28 | // Function : Load |
29 | // Purpose : |
30 | //======================================================================= |
31 | |
32 | Handle(HLRBRep_Data) |
33 | HLRBRep_ShapeToHLR::Load(const Handle(HLRTopoBRep_OutLiner)& S, |
34 | const HLRAlgo_Projector& P, |
35 | BRepTopAdaptor_MapOfShapeTool& MST, |
36 | const Standard_Integer nbIso) |
37 | { |
38 | S->Fill(P,MST,nbIso); |
39 | |
40 | HLRTopoBRep_Data& TopDS = S->DataStructure(); |
41 | TopTools_IndexedMapOfShape FM; |
42 | TopTools_IndexedMapOfShape EM; |
43 | TopTools_IndexedDataMapOfShapeListOfShape VerticesToEdges; |
44 | TopTools_IndexedDataMapOfShapeListOfShape EdgesToFaces; |
45 | |
46 | TopExp_Explorer exshell,exface; |
47 | |
48 | for (exshell.Init(S->OutLinedShape(), TopAbs_SHELL); |
49 | exshell.More(); |
50 | exshell.Next()) { // faces in a shell |
51 | |
52 | for (exface.Init(exshell.Current(), TopAbs_FACE); |
53 | exface.More(); |
54 | exface.Next()) { |
55 | if (!FM.Contains(exface.Current())) |
56 | FM.Add(exface.Current()); |
57 | } |
58 | } |
59 | |
60 | for (exface.Init(S->OutLinedShape(), TopAbs_FACE, TopAbs_SHELL); |
61 | exface.More(); |
62 | exface.Next()) { // faces not in a shell |
63 | if (!FM.Contains(exface.Current())) |
64 | FM.Add(exface.Current()); |
65 | } |
66 | |
67 | TopExp::MapShapes(S->OutLinedShape(),TopAbs_EDGE,EM); |
68 | |
69 | Standard_Integer i; |
70 | Standard_Integer nbEdge = EM.Extent (); |
71 | |
72 | for (i = 1; i <= nbEdge; i++) // vertices back to edges |
73 | TopExp::MapShapesAndAncestors |
74 | (EM(i), TopAbs_VERTEX, TopAbs_EDGE, VerticesToEdges); |
75 | |
76 | Standard_Integer nbVert = VerticesToEdges.Extent(); |
77 | Standard_Integer nbFace = FM.Extent(); |
78 | |
79 | TopoDS_Vertex VF, VL; |
80 | TopTools_ListIteratorOfListOfShape itn; |
81 | Standard_Integer i1, i2; |
82 | Standard_Boolean o1, o2; |
83 | Standard_Boolean c1, c2; |
84 | Standard_Real pf, pl; |
85 | Standard_ShortReal tf, tl; |
86 | |
87 | // Create the data structure |
88 | Handle(HLRBRep_Data) DS = new HLRBRep_Data (nbVert, nbEdge, nbFace); |
89 | #ifdef DEB |
90 | HLRBRep_Array1OfEData& ED = |
91 | #endif |
92 | DS->EDataArray (); |
93 | HLRBRep_EdgeData* ed; |
94 | if(nbEdge != 0) ed = &(DS->EDataArray().ChangeValue(1)); |
95 | // ed++; |
96 | |
97 | for (i = 1; i <= nbFace; i++) { // test of Double edges |
98 | TopExp::MapShapesAndAncestors |
99 | (FM(i),TopAbs_EDGE, TopAbs_FACE, EdgesToFaces); |
100 | } |
101 | |
102 | for (i = 1; i <= nbEdge; i++) { // load the Edges |
103 | const TopoDS_Edge& Edg = TopoDS::Edge (EM(i)); |
104 | TopExp::Vertices (Edg, VF, VL); |
105 | BRep_Tool::Range (Edg, pf, pl); |
106 | Standard_Boolean reg1 = Standard_False; |
107 | Standard_Boolean regn = Standard_False; |
108 | Standard_Integer inde = EdgesToFaces.FindIndex(Edg); |
109 | if (inde > 0) { |
110 | if (EdgesToFaces(inde).Extent() == 2) { |
111 | itn = EdgesToFaces(inde); |
112 | const TopoDS_Face& F1 = TopoDS::Face(itn.Value()); |
113 | itn.Next(); |
114 | const TopoDS_Face& F2 = TopoDS::Face(itn.Value()); |
115 | GeomAbs_Shape rg = BRep_Tool::Continuity(Edg,F1,F2); |
116 | reg1 = rg >= GeomAbs_G1; |
117 | regn = rg >= GeomAbs_G2; |
118 | } |
119 | } |
120 | |
121 | if (VF.IsNull()) { |
122 | i1 = 0; |
123 | o1 = Standard_False; |
124 | c1 = Standard_False; |
125 | pf = RealFirst(); |
126 | tf = (Standard_ShortReal) Epsilon(pf); |
127 | } |
128 | else { |
129 | i1 = VerticesToEdges.FindIndex(VF); |
130 | o1 = TopDS.IsOutV(VF); |
131 | c1 = TopDS.IsIntV(VF); |
132 | tf = (Standard_ShortReal) BRep_Tool::Tolerance(VF); |
133 | } |
134 | |
135 | if (VL.IsNull()) { |
136 | i2 = 0; |
137 | o2 = Standard_False; |
138 | c2 = Standard_False; |
139 | pl = RealLast(); |
140 | tl = (Standard_ShortReal) Epsilon (pl); |
141 | } |
142 | else { |
143 | i2 = VerticesToEdges.FindIndex(VL); |
144 | o2 = TopDS.IsOutV(VL); |
145 | c2 = TopDS.IsIntV(VL); |
146 | tl = (Standard_ShortReal) BRep_Tool::Tolerance(VL); |
147 | } |
148 | |
149 | ed->Set (reg1,regn, Edg, i1, i2, o1, o2, c1, c2, pf, tf, pl, tl); |
150 | DS->EdgeMap().Add(Edg); |
151 | ed++; |
152 | } |
153 | |
154 | ExploreShape(S,DS,FM,EM); |
155 | return DS; |
156 | } |
157 | |
158 | //======================================================================= |
159 | // Function : ExploreFace |
160 | // Purpose : |
161 | //======================================================================= |
162 | |
163 | void |
164 | HLRBRep_ShapeToHLR::ExploreFace(const Handle(HLRTopoBRep_OutLiner)& S, |
165 | const Handle(HLRBRep_Data)& DS, |
166 | const TopTools_IndexedMapOfShape& FM, |
167 | const TopTools_IndexedMapOfShape& EM, |
168 | Standard_Integer& i, |
169 | const TopoDS_Face& F, |
170 | const Standard_Boolean closed) |
171 | { |
172 | i++; |
173 | TopExp_Explorer Ex1,Ex2; |
174 | HLRTopoBRep_Data& TopDS = S->DataStructure(); |
175 | TopAbs_Orientation orient = FM(i).Orientation(); |
176 | TopoDS_Face theFace = TopoDS::Face(FM(i)); |
177 | theFace.Orientation (TopAbs_FORWARD); |
178 | HLRBRep_FaceData& fd = DS->FDataArray().ChangeValue(i); |
179 | |
180 | Standard_Integer nw = 0; |
181 | |
182 | for (Ex1.Init(theFace, TopAbs_WIRE); Ex1.More(); Ex1.Next()) |
183 | nw++; |
184 | |
185 | fd.Set (theFace, orient, closed, nw); |
186 | nw = 0; |
187 | |
188 | for (Ex1.Init(theFace, TopAbs_WIRE); Ex1.More(); Ex1.Next()) { |
189 | nw++; |
190 | Standard_Integer ne = 0; |
191 | |
192 | for (Ex2.Init(Ex1.Current(), TopAbs_EDGE); Ex2.More(); Ex2.Next()) |
193 | ne++; |
194 | |
195 | fd.SetWire (nw, ne); |
196 | ne = 0; |
197 | |
198 | for (Ex2.Init(Ex1.Current(), TopAbs_EDGE); |
199 | Ex2.More(); |
200 | Ex2.Next()) { |
201 | ne++; |
202 | const TopoDS_Edge& E = TopoDS::Edge(Ex2.Current()); |
203 | Standard_Integer ie = EM.FindIndex(E); |
204 | TopAbs_Orientation orient = E.Orientation(); |
205 | Standard_Boolean Int = TopDS.IsIntLFaceEdge(F,E); |
206 | Standard_Boolean Iso = TopDS.IsIsoLFaceEdge(F,E); |
207 | Standard_Boolean Out = TopDS.IsOutLFaceEdge(F,E); |
208 | Standard_Boolean Dbl = BRepTools::IsReallyClosed(TopoDS::Edge(E),theFace); |
209 | fd.SetWEdge(nw, ne, ie, orient, Out, Int, Dbl, Iso); |
210 | } |
211 | } |
212 | DS->FaceMap().Add(theFace); |
213 | } |
214 | |
215 | //======================================================================= |
216 | //function : ExploreShape |
217 | //purpose : |
218 | //======================================================================= |
219 | |
220 | void |
221 | HLRBRep_ShapeToHLR::ExploreShape (const Handle(HLRTopoBRep_OutLiner)& S, |
222 | const Handle(HLRBRep_Data)& DS, |
223 | const TopTools_IndexedMapOfShape& FM, |
224 | const TopTools_IndexedMapOfShape& EM) |
225 | { |
226 | TopTools_MapOfShape ShapeMap; |
227 | TopExp_Explorer exshell, exface, exedge; |
228 | Standard_Integer i = 0; |
229 | |
230 | for (exshell.Init (S->OriginalShape(), TopAbs_SHELL); |
231 | exshell.More (); |
232 | exshell.Next ()) { // faces in a shell (open or close) |
233 | |
234 | Standard_Boolean closed = exshell.Current().Closed(); |
235 | |
236 | if (!closed) { |
237 | Standard_Integer ie; |
238 | Standard_Integer nbEdge = EM.Extent (); |
239 | Standard_Integer *flag = new Standard_Integer[nbEdge + 1]; |
240 | |
241 | for(ie = 1; ie<=nbEdge; ie++) |
242 | flag[ie] = 0; |
243 | |
244 | for (exedge.Init(exshell.Current(), TopAbs_EDGE); |
245 | exedge.More(); |
246 | exedge.Next()) { |
247 | const TopoDS_Edge& E = TopoDS::Edge(exedge.Current()); |
248 | ie = EM.FindIndex(E); |
249 | TopAbs_Orientation orient = E.Orientation(); |
250 | if (!BRep_Tool::Degenerated(E)) { |
251 | if (orient == TopAbs_FORWARD ) flag[ie] += 1; |
252 | else if (orient == TopAbs_REVERSED) flag[ie] -= 1; |
253 | } |
254 | } |
255 | closed = Standard_True; |
256 | |
257 | for (ie = 1; ie <= nbEdge && closed; ie++) |
258 | closed = (flag[ie] == 0); |
259 | delete [] flag; |
260 | flag = NULL; |
261 | } |
262 | |
263 | for (exface.Init(exshell.Current(), TopAbs_FACE); |
264 | exface.More(); |
265 | exface.Next()) { |
266 | if (ShapeMap.Add(exface.Current())) { |
267 | ExploreFace(S,DS,FM,EM,i, |
268 | TopoDS::Face(exface.Current()), |
269 | closed); |
270 | } |
271 | } |
272 | } |
273 | |
274 | for (exface.Init(S->OriginalShape(), TopAbs_FACE, TopAbs_SHELL); |
275 | exface.More(); |
276 | exface.Next()) { // faces not in a shell |
277 | if (ShapeMap.Add(exface.Current())) { |
278 | ExploreFace(S,DS,FM,EM,i, |
279 | TopoDS::Face(exface.Current()), |
280 | Standard_False); |
281 | } |
282 | } |
283 | } |
284 | |