1 // Created on: 1992-08-27
2 // Created by: Christophe MARION
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 // #define No_Exception
22 #include <BRep_Tool.hxx>
23 #include <BRepTools.hxx>
24 #include <BRepTopAdaptor_MapOfShapeTool.hxx>
25 #include <HLRAlgo_Projector.hxx>
26 #include <HLRBRep.hxx>
27 #include <HLRBRep_Data.hxx>
28 #include <HLRBRep_ShapeToHLR.hxx>
29 #include <HLRTopoBRep_OutLiner.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Iterator.hxx>
37 #include <TopoDS_Vertex.hxx>
38 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 #include <TopTools_ListOfShape.hxx>
41 #include <TopTools_MapOfShape.hxx>
43 //=======================================================================
46 //=======================================================================
48 HLRBRep_ShapeToHLR::Load(const Handle(HLRTopoBRep_OutLiner)& S,
49 const HLRAlgo_Projector& P,
50 BRepTopAdaptor_MapOfShapeTool& MST,
51 const Standard_Integer nbIso)
55 HLRTopoBRep_Data& TopDS = S->DataStructure();
56 TopTools_IndexedMapOfShape FM;
57 TopTools_IndexedMapOfShape EM;
58 TopTools_IndexedDataMapOfShapeListOfShape VerticesToEdges;
59 TopTools_IndexedDataMapOfShapeListOfShape EdgesToFaces;
61 TopExp_Explorer exshell,exface;
63 for (exshell.Init(S->OutLinedShape(), TopAbs_SHELL);
65 exshell.Next()) { // faces in a shell
67 for (exface.Init(exshell.Current(), TopAbs_FACE);
70 if (!FM.Contains(exface.Current()))
71 FM.Add(exface.Current());
75 for (exface.Init(S->OutLinedShape(), TopAbs_FACE, TopAbs_SHELL);
77 exface.Next()) { // faces not in a shell
78 if (!FM.Contains(exface.Current()))
79 FM.Add(exface.Current());
82 TopExp::MapShapes(S->OutLinedShape(),TopAbs_EDGE,EM);
85 Standard_Integer nbEdge = EM.Extent ();
87 for (i = 1; i <= nbEdge; i++) // vertices back to edges
88 TopExp::MapShapesAndAncestors
89 (EM(i), TopAbs_VERTEX, TopAbs_EDGE, VerticesToEdges);
91 Standard_Integer nbVert = VerticesToEdges.Extent();
92 Standard_Integer nbFace = FM.Extent();
95 TopTools_ListIteratorOfListOfShape itn;
96 Standard_Integer i1, i2;
97 Standard_Boolean o1, o2;
98 Standard_Boolean c1, c2;
100 Standard_ShortReal tf, tl;
102 // Create the data structure
103 Handle(HLRBRep_Data) DS = new HLRBRep_Data (nbVert, nbEdge, nbFace);
104 HLRBRep_EdgeData* ed = NULL;
105 if(nbEdge != 0) ed = &(DS->EDataArray().ChangeValue(1));
108 for (i = 1; i <= nbFace; i++) { // test of Double edges
109 TopExp::MapShapesAndAncestors
110 (FM(i),TopAbs_EDGE, TopAbs_FACE, EdgesToFaces);
113 for (i = 1; i <= nbEdge; i++) { // load the Edges
114 const TopoDS_Edge& Edg = TopoDS::Edge (EM(i));
115 TopExp::Vertices (Edg, VF, VL);
116 BRep_Tool::Range (Edg, pf, pl);
117 Standard_Boolean reg1 = Standard_False;
118 Standard_Boolean regn = Standard_False;
119 Standard_Integer inde = EdgesToFaces.FindIndex(Edg);
121 if (EdgesToFaces(inde).Extent() == 2) {
122 itn = EdgesToFaces(inde);
123 const TopoDS_Face& F1 = TopoDS::Face(itn.Value());
125 const TopoDS_Face& F2 = TopoDS::Face(itn.Value());
126 GeomAbs_Shape rg = BRep_Tool::Continuity(Edg,F1,F2);
127 reg1 = rg >= GeomAbs_G1;
128 regn = rg >= GeomAbs_G2;
137 tf = (Standard_ShortReal) Epsilon(pf);
140 i1 = VerticesToEdges.FindIndex(VF);
141 o1 = TopDS.IsOutV(VF);
142 c1 = TopDS.IsIntV(VF);
143 tf = (Standard_ShortReal) BRep_Tool::Tolerance(VF);
151 tl = (Standard_ShortReal) Epsilon (pl);
154 i2 = VerticesToEdges.FindIndex(VL);
155 o2 = TopDS.IsOutV(VL);
156 c2 = TopDS.IsIntV(VL);
157 tl = (Standard_ShortReal) BRep_Tool::Tolerance(VL);
160 ed->Set (reg1,regn, Edg, i1, i2, o1, o2, c1, c2, pf, tf, pl, tl);
161 DS->EdgeMap().Add(Edg);
165 ExploreShape(S,DS,FM,EM);
169 //=======================================================================
170 // Function : ExploreFace
172 //=======================================================================
175 HLRBRep_ShapeToHLR::ExploreFace(const Handle(HLRTopoBRep_OutLiner)& S,
176 const Handle(HLRBRep_Data)& DS,
177 const TopTools_IndexedMapOfShape& FM,
178 const TopTools_IndexedMapOfShape& EM,
180 const TopoDS_Face& F,
181 const Standard_Boolean closed)
184 TopExp_Explorer Ex1,Ex2;
185 HLRTopoBRep_Data& TopDS = S->DataStructure();
186 TopAbs_Orientation orient = FM(i).Orientation();
187 TopoDS_Face theFace = TopoDS::Face(FM(i));
188 theFace.Orientation (TopAbs_FORWARD);
189 HLRBRep_FaceData& fd = DS->FDataArray().ChangeValue(i);
191 Standard_Integer nw = 0;
193 for (Ex1.Init(theFace, TopAbs_WIRE); Ex1.More(); Ex1.Next())
196 fd.Set (theFace, orient, closed, nw);
199 for (Ex1.Init(theFace, TopAbs_WIRE); Ex1.More(); Ex1.Next()) {
201 Standard_Integer ne = 0;
203 for (Ex2.Init(Ex1.Current(), TopAbs_EDGE); Ex2.More(); Ex2.Next())
205 const TopoDS_Edge& anEdge = TopoDS::Edge(Ex2.Current());
206 if (!BRep_Tool::Degenerated(anEdge))
213 for (Ex2.Init(Ex1.Current(), TopAbs_EDGE);
216 const TopoDS_Edge& E = TopoDS::Edge(Ex2.Current());
217 if (BRep_Tool::Degenerated(E))
220 Standard_Integer ie = EM.FindIndex(E);
221 TopAbs_Orientation anOrientE = E.Orientation();
222 Standard_Boolean Int = TopDS.IsIntLFaceEdge(F,E);
223 Standard_Boolean Iso = TopDS.IsIsoLFaceEdge(F,E);
224 Standard_Boolean Out = TopDS.IsOutLFaceEdge(F,E);
225 Standard_Boolean Dbl = BRepTools::IsReallyClosed(TopoDS::Edge(E),theFace);
226 fd.SetWEdge(nw, ne, ie, anOrientE, Out, Int, Dbl, Iso);
229 DS->FaceMap().Add(theFace);
232 //=======================================================================
233 //function : ExploreShape
235 //=======================================================================
238 HLRBRep_ShapeToHLR::ExploreShape (const Handle(HLRTopoBRep_OutLiner)& S,
239 const Handle(HLRBRep_Data)& DS,
240 const TopTools_IndexedMapOfShape& FM,
241 const TopTools_IndexedMapOfShape& EM)
243 TopTools_MapOfShape ShapeMap;
244 TopExp_Explorer exshell, exface, exedge;
245 Standard_Integer i = 0;
247 for (exshell.Init (S->OriginalShape(), TopAbs_SHELL);
249 exshell.Next ()) { // faces in a shell (open or close)
251 Standard_Boolean closed = exshell.Current().Closed();
255 Standard_Integer nbEdge = EM.Extent ();
256 Standard_Integer *flag = new Standard_Integer[nbEdge + 1];
258 for(ie = 1; ie<=nbEdge; ie++)
261 for (exedge.Init(exshell.Current(), TopAbs_EDGE);
264 const TopoDS_Edge& E = TopoDS::Edge(exedge.Current());
265 ie = EM.FindIndex(E);
266 TopAbs_Orientation orient = E.Orientation();
267 if (!BRep_Tool::Degenerated(E)) {
268 if (orient == TopAbs_FORWARD ) flag[ie] += 1;
269 else if (orient == TopAbs_REVERSED) flag[ie] -= 1;
272 closed = Standard_True;
274 for (ie = 1; ie <= nbEdge && closed; ie++)
275 closed = (flag[ie] == 0);
280 for (exface.Init(exshell.Current(), TopAbs_FACE);
283 if (ShapeMap.Add(exface.Current())) {
284 ExploreFace(S,DS,FM,EM,i,
285 TopoDS::Face(exface.Current()),
291 for (exface.Init(S->OriginalShape(), TopAbs_FACE, TopAbs_SHELL);
293 exface.Next()) { // faces not in a shell
294 if (ShapeMap.Add(exface.Current())) {
295 ExploreFace(S,DS,FM,EM,i,
296 TopoDS::Face(exface.Current()),