0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / HLRTopoBRep / HLRTopoBRep_OutLiner.cxx
CommitLineData
7fd59977 1// File: HLRTopoBRep_OutLiner.cxx
2// Created: Thu Aug 4 09:53:26 1994
3// Author: Christophe MARION
4// <cma@ecolox>
5
6#include <HLRTopoBRep_OutLiner.ixx>
7#include <HLRTopoBRep_DSFiller.hxx>
8#include <Contap_Contour.hxx>
9#include <BRep_Builder.hxx>
10#include <TopoDS.hxx>
11#include <TopoDS_Edge.hxx>
12#include <TopoDS_Wire.hxx>
13#include <TopoDS_Shell.hxx>
14#include <TopExp_Explorer.hxx>
15#include <TopTools_ListIteratorOfListOfShape.hxx>
16#include <gp_Pnt.hxx>
17#include <gp_Dir.hxx>
18#include <gp_Vec.hxx>
19#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
20#include <TopExp.hxx>
21#include <BRepAdaptor_Curve.hxx>
22#include <Extrema_ExtPC.hxx>
23
24//=======================================================================
25//function : OutLiner
26//purpose :
27//=======================================================================
28
29HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner ()
30{}
31
32//=======================================================================
33//function : OutLiner
34//purpose :
35//=======================================================================
36
37HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner(const TopoDS_Shape& OriS) :
38 myOriginalShape(OriS)
39{}
40
41//=======================================================================
42//function : OutLiner
43//purpose :
44//=======================================================================
45
46HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner(const TopoDS_Shape& OriS,
47 const TopoDS_Shape& OutS) :
48 myOriginalShape(OriS),
49 myOutLinedShape(OutS)
50{}
51
52//=======================================================================
53//function : Fill
54//purpose :
55//=======================================================================
56
57void HLRTopoBRep_OutLiner::Fill(const HLRAlgo_Projector& P,
58 BRepTopAdaptor_MapOfShapeTool& MST,
59 const Standard_Integer nbIso)
60{
61 if (!myOriginalShape.IsNull()) {
62 if (myOutLinedShape.IsNull()) {
63 gp_Vec Vecz (0., 0., 1.);
64 gp_Trsf Tr (P.Transformation ());
65 Tr.Invert ();
66 Vecz.Transform (Tr);
67 Contap_Contour FO;
68 if (P.Perspective ()) {
69 gp_Pnt Eye;
70 Eye.SetXYZ (P.Focus ()*Vecz.XYZ ());
71 FO.Init(Eye);
72 }
73 else {
74 gp_Dir DirZ(Vecz);
75 FO.Init(DirZ);
76 }
77 HLRTopoBRep_DSFiller::Insert(myOriginalShape,FO,myDS,MST,nbIso);
78 BuildShape(MST);
79 }
80 }
81}
82
83//=======================================================================
84// Function : ProcessFace
85// Purpose : Build a Face using myDS and add the new face to a shell
86//=======================================================================
87
88void HLRTopoBRep_OutLiner::ProcessFace(const TopoDS_Face& F,
89 TopoDS_Shape& S,
90 BRepTopAdaptor_MapOfShapeTool& MST)
91{
92 BRep_Builder B;
93 TopExp_Explorer exE, exW;
6e6cd5d9 94 //Standard_Boolean splitted = Standard_False;
7fd59977 95
96 TopTools_IndexedDataMapOfShapeListOfShape aVEMap;
97 TopExp::MapShapesAndAncestors(F, TopAbs_VERTEX, TopAbs_EDGE, aVEMap);
98
99 TopoDS_Shape NF;// = F;
100 //NF.Free(Standard_True);
101
102 //for (exE.Init(F,TopAbs_EDGE); exE.More(); exE.Next()) {
103 //if (myDS.EdgeHasSplE(TopoDS::Edge(exE.Current()))) {
104 //splitted = Standard_True;
105 //break;
106 //}
107 //}
108
109 //if (splitted) { // the face contains a splitted edge :
110 // Make a copy with the new Edges
111 NF = F.EmptyCopied ();
112
113
114 for (exW.Init(F,TopAbs_WIRE); exW.More(); exW.Next()) {
115 TopoDS_Wire W;
116 B.MakeWire(W);
117
118 for (exE.Init(exW.Current(),TopAbs_EDGE); exE.More(); exE.Next()) {
119 TopoDS_Edge E = TopoDS::Edge(exE.Current());
120 if (myDS.EdgeHasSplE(E)) {
121
122 TopTools_ListIteratorOfListOfShape itS;
123 for (itS.Initialize(myDS.EdgeSplE(E));
124 itS.More();
125 itS.Next()) {
126 TopoDS_Edge newE = TopoDS::Edge(itS.Value());
127 newE.Orientation(E.Orientation());
128 myDS.AddOldS(newE,E);
129 B.Add(W,newE);
130 }
131 }
132 else {
133 B.Add(W,E);
134 }
135 }
136 B.Add(NF,W); // add the new wire in the new face.
137 }
138 //}
139
140
141 TopTools_ListOfShape& IntL = myDS.AddIntL(F);
142 TopTools_ListOfShape& OutL = myDS.AddOutL(F);
143
144 if (myDS.FaceHasIntL(F)) { // get the InternalOutLines on face F
145 TopoDS_Wire W;
146
147 TopTools_ListIteratorOfListOfShape itE;
148 for(itE.Initialize(myDS.FaceIntL(F));
149 itE.More();
150 itE.Next()) {
151 TopoDS_Edge E = TopoDS::Edge(itE.Value());
152 E.Orientation(TopAbs_INTERNAL);
153 //Check, if outline edge coincides real edge
154
155 BRepAdaptor_Curve C(E);
156 Standard_Real par = 0.34*C.FirstParameter() + 0.66*C.LastParameter();
157 gp_Pnt P = C.Value(par);
158 TopoDS_Vertex V1, V2, aV1, aV2;
159 TopExp::Vertices(E, V1, V2);
160
161 Standard_Boolean SameEdge = Standard_False;
162 if(!V1.IsNull() && aVEMap.Contains(V1)) {
163 const TopTools_ListOfShape& aEList = aVEMap.FindFromKey(V1);
164 TopTools_ListIteratorOfListOfShape it(aEList);
165 for(; it.More(); it.Next()) {
166 const TopoDS_Edge& aE = TopoDS::Edge(it.Value());
167 TopExp::Vertices(aE, aV1, aV2);
168
169 if((V1.IsSame(aV1) && V2.IsSame(aV2)) || (V1.IsSame(aV2) && V2.IsSame(aV1))) {
170 BRepAdaptor_Curve aC(aE);
171 if((C.GetType() == GeomAbs_Line) &&
172 (aC.GetType() == GeomAbs_Line)) {
173 SameEdge = Standard_True;
174 break;
175 }
176 else {
177 //Try to project one point
178 Extrema_ExtPC anExt(P, aC);
179 if(anExt.IsDone()) {
180 Standard_Integer aNe = anExt.NbExt();
181 if(aNe > 0) {
182 Standard_Real dist = RealLast();
183 Standard_Integer ec;
184 for(ec = 1; ec <= aNe; ++ec) {
185// dist = Min(dist, anExt.Value(ec));
186 dist = Min(dist, anExt.SquareDistance(ec));
187 }
188
189// if(dist <= 1.e-7) {
190 if(dist <= 1.e-14) {
191 SameEdge = Standard_True;
192 break;
193 }
194 }
195 }
196 }
197 }
198 }
199 }
200
201 if(SameEdge) {
202 OutL.Append(E);
203 continue;
204 }
205
206 if (myDS.EdgeHasSplE(E)) {
207
208 TopTools_ListIteratorOfListOfShape itS;
209 for (itS.Initialize(myDS.EdgeSplE(E));
210 itS.More();
211 itS.Next()) {
212 TopoDS_Shape newE = itS.Value();
213 newE.Orientation(TopAbs_INTERNAL);
214 if (W.IsNull()) B.MakeWire(W);
215 myDS.AddOldS(newE,F);
216 B.Add(W,newE);
217 }
218 }
219 else {
220 if (W.IsNull()) B.MakeWire(W);
221 myDS.AddOldS(E,F);
222 B.Add(W,E);
223 }
224 }
225 if (!W.IsNull()) B.Add(NF,W); // add the new wire in the new face.
226 }
227
228 if (myDS.FaceHasIsoL(F)) { // get the IsoLines on face F
229 TopoDS_Wire W;
230
231 TopTools_ListIteratorOfListOfShape itE;
232 for(itE.Initialize(myDS.FaceIsoL(F));
233 itE.More();
234 itE.Next()) {
235 TopoDS_Edge E = TopoDS::Edge(itE.Value());
236 E.Orientation(TopAbs_INTERNAL);
237 if (myDS.EdgeHasSplE(E)) { // normaly IsoLines are never splitted.
238
239 TopTools_ListIteratorOfListOfShape itS;
240 for (itS.Initialize(myDS.EdgeSplE(E));
241 itS.More();
242 itS.Next()) {
243 TopoDS_Shape newE = itS.Value();
244 newE.Orientation(TopAbs_INTERNAL);
245 if (W.IsNull()) B.MakeWire(W);
246 myDS.AddOldS(newE,F);
247 B.Add(W,newE);
248 }
249 }
250 else {
251 if (W.IsNull()) B.MakeWire(W);
252 myDS.AddOldS(E,F);
253 B.Add(W,E);
254 }
255 }
256 if (!W.IsNull()) B.Add(NF,W); // add the new wire in the new face.
257 }
258 myDS.AddOldS(NF,F);
259 MST.Bind(NF, MST.ChangeFind(F));
260 //
261 B.Add(S,NF); // add the face in the shell.
262}
263
264//=======================================================================
265//function : BuildShape
266//purpose : Build the OutLinedShape
267//=======================================================================
268
269void HLRTopoBRep_OutLiner::BuildShape (BRepTopAdaptor_MapOfShapeTool& MST)
270{
271 TopExp_Explorer exshell, exface, exedge;
272 BRep_Builder B;
273 B.MakeCompound(TopoDS::Compound(myOutLinedShape));
274 TopTools_MapOfShape ShapeMap;
275
276 for (exshell.Init (myOriginalShape, TopAbs_SHELL);
277 exshell.More ();
278 exshell.Next ()) { // faces in a shell (open or close)
279 TopoDS_Shell theShell;
280 B.MakeShell(theShell);
281 theShell.Closed(exshell.Current().Closed ());
282
283 for (exface.Init(exshell.Current(), TopAbs_FACE);
284 exface.More();
285 exface.Next()) {
286 if (ShapeMap.Add(exface.Current()))
287 ProcessFace(TopoDS::Face(exface.Current()),theShell,MST);
288 }
289 B.Add(myOutLinedShape,theShell);
290 }
291
292 for (exface.Init(myOriginalShape, TopAbs_FACE, TopAbs_SHELL);
293 exface.More();
294 exface.Next()) { // faces not in a shell
295 if (ShapeMap.Add(exface.Current()))
296 ProcessFace (TopoDS::Face(exface.Current()),myOutLinedShape,MST);
297 }
298
299 for (exedge.Init(myOriginalShape, TopAbs_EDGE, TopAbs_FACE);
300 exedge.More();
301 exedge.Next()) // edges not in a face
302 B.Add(myOutLinedShape,exedge.Current());
303}
304