0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / HLRBRep / HLRBRep_PolyAlgo.cxx
1 // File:      HLRBRep_PolyAlgo.cxx
2 // Created:   Fri May  5 15:58:19 1995
3 // Author:    Christophe MARION
4 // Copyright: OPEN CASCADE 2000
5
6 // Modified by cma, Tue Apr  1 11:39:48 1997
7 // Modified by cma, Tue Apr  1 11:40:30 1997
8
9 #include <Standard_Stream.hxx>
10 #include <HLRBRep_PolyAlgo.ixx>
11 #include <Standard_ErrorHandler.hxx>
12 #include <TColStd_HArray1OfTransient.hxx>
13 #include <TColStd_HArray1OfInteger.hxx>
14 #include <CSLib.hxx>
15 #include <CSLib_DerivativeStatus.hxx>
16 #include <CSLib_NormalStatus.hxx>
17 #include <Geom_Surface.hxx>
18 #include <Geom_RectangularTrimmedSurface.hxx>
19 #include <HLRAlgo_ListIteratorOfListOfBPoint.hxx>
20 #include <HLRAlgo_PolyShellData.hxx>
21 #include <HLRAlgo_PolyData.hxx>
22 #include <HLRAlgo_BiPoint.hxx>
23 #include <TopoDS.hxx>
24 #include <TopExp.hxx>
25 #include <TopExp_Explorer.hxx>
26 #include <TopTools_Array1OfShape.hxx>
27 #include <TopTools_ListIteratorOfListOfShape.hxx>
28 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
29 #include <Poly_Triangulation.hxx>
30 #include <Poly_Polygon3D.hxx>
31 #include <Poly_PolygonOnTriangulation.hxx>
32 #include <BRep_Builder.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRepLib_MakeEdge.hxx>
35 #include <Precision.hxx>
36 #include <gp.hxx>
37
38 #define EMskOutLin1  ((Standard_Boolean)   1)
39 #define EMskOutLin2  ((Standard_Boolean)   2)
40 #define EMskOutLin3  ((Standard_Boolean)   4)
41 #define EMskGrALin1  ((Standard_Boolean)   8)
42 #define EMskGrALin2  ((Standard_Boolean)  16)
43 #define EMskGrALin3  ((Standard_Boolean)  32)
44 #define FMskBack     ((Standard_Boolean)  64)
45 #define FMskSide     ((Standard_Boolean) 128)
46 #define FMskHiding   ((Standard_Boolean) 256)
47 #define FMskFlat     ((Standard_Boolean) 512)
48 #define FMskOnOutL   ((Standard_Boolean)1024)
49 #define FMskOrBack   ((Standard_Boolean)2048)
50 #define FMskFrBack   ((Standard_Boolean)4096)
51
52 #define NMskVert ((Standard_Boolean) 1)
53 #define NMskOutL ((Standard_Boolean) 2)
54 #define NMskNorm ((Standard_Boolean) 4)
55 #define NMskFuck ((Standard_Boolean) 8)
56 #define NMskEdge ((Standard_Boolean)16)
57 #define NMskMove ((Standard_Boolean)32)
58
59 #define PntXTI1 ((Standard_Real*)Coordinates)[ 0]
60 #define PntYTI1 ((Standard_Real*)Coordinates)[ 1]
61 #define PntZTI1 ((Standard_Real*)Coordinates)[ 2]
62 #define PntXTI2 ((Standard_Real*)Coordinates)[ 3]
63 #define PntYTI2 ((Standard_Real*)Coordinates)[ 4]
64 #define PntZTI2 ((Standard_Real*)Coordinates)[ 5]
65 #define PntX1   ((Standard_Real*)Coordinates)[ 6]
66 #define PntY1   ((Standard_Real*)Coordinates)[ 7]
67 #define PntZ1   ((Standard_Real*)Coordinates)[ 8]
68 #define PntX2   ((Standard_Real*)Coordinates)[ 9]
69 #define PntY2   ((Standard_Real*)Coordinates)[10]
70 #define PntZ2   ((Standard_Real*)Coordinates)[11]
71
72 #define Pn2XTI1 ((Standard_Real*)Coordinate2)[ 0]
73 #define Pn2YTI1 ((Standard_Real*)Coordinate2)[ 1]
74 #define Pn2ZTI1 ((Standard_Real*)Coordinate2)[ 2]
75 #define Pn2XTI2 ((Standard_Real*)Coordinate2)[ 3]
76 #define Pn2YTI2 ((Standard_Real*)Coordinate2)[ 4]
77 #define Pn2ZTI2 ((Standard_Real*)Coordinate2)[ 5]
78 #define Pn2X1   ((Standard_Real*)Coordinate2)[ 6]
79 #define Pn2Y1   ((Standard_Real*)Coordinate2)[ 7]
80 #define Pn2Z1   ((Standard_Real*)Coordinate2)[ 8]
81 #define Pn2X2   ((Standard_Real*)Coordinate2)[ 9]
82 #define Pn2Y2   ((Standard_Real*)Coordinate2)[10]
83 #define Pn2Z2   ((Standard_Real*)Coordinate2)[11]
84
85 #define Tri1Node1 ((Standard_Integer*)Tri1Indices)[0]
86 #define Tri1Node2 ((Standard_Integer*)Tri1Indices)[1]
87 #define Tri1Node3 ((Standard_Integer*)Tri1Indices)[2]
88 #define Tri1Flags ((Standard_Boolean*)Tri1Indices)[3]
89
90 #define Tri2Node1 ((Standard_Integer*)Tri2Indices)[0]
91 #define Tri2Node2 ((Standard_Integer*)Tri2Indices)[1]
92 #define Tri2Node3 ((Standard_Integer*)Tri2Indices)[2]
93 #define Tri2Flags ((Standard_Boolean*)Tri2Indices)[3]
94
95 #define Tri3Node1 ((Standard_Integer*)Tri3Indices)[0]
96 #define Tri3Node2 ((Standard_Integer*)Tri3Indices)[1]
97 #define Tri3Node3 ((Standard_Integer*)Tri3Indices)[2]
98 #define Tri3Flags ((Standard_Boolean*)Tri3Indices)[3]
99
100 #define Seg1LstSg1 ((Standard_Integer*)Seg1Indices)[0]
101 #define Seg1LstSg2 ((Standard_Integer*)Seg1Indices)[1]
102 #define Seg1NxtSg1 ((Standard_Integer*)Seg1Indices)[2]
103 #define Seg1NxtSg2 ((Standard_Integer*)Seg1Indices)[3]
104 #define Seg1Conex1 ((Standard_Integer*)Seg1Indices)[4]
105 #define Seg1Conex2 ((Standard_Integer*)Seg1Indices)[5]
106
107 #define Seg2LstSg1 ((Standard_Integer*)Seg2Indices)[0]
108 #define Seg2LstSg2 ((Standard_Integer*)Seg2Indices)[1]
109 #define Seg2NxtSg1 ((Standard_Integer*)Seg2Indices)[2]
110 #define Seg2NxtSg2 ((Standard_Integer*)Seg2Indices)[3]
111 #define Seg2Conex1 ((Standard_Integer*)Seg2Indices)[4]
112 #define Seg2Conex2 ((Standard_Integer*)Seg2Indices)[5]
113
114 #define Nod1NdSg ((Standard_Integer*)Nod1Indices)[0]
115 #define Nod1Flag ((Standard_Boolean*)Nod1Indices)[1]
116 #define Nod1Edg1 ((Standard_Boolean*)Nod1Indices)[2]
117 #define Nod1Edg2 ((Standard_Boolean*)Nod1Indices)[3]
118
119 #define Nod1PntX ((Standard_Real*)Nod1RValues)[ 0]
120 #define Nod1PntY ((Standard_Real*)Nod1RValues)[ 1]
121 #define Nod1PntZ ((Standard_Real*)Nod1RValues)[ 2]
122 #define Nod1PntU ((Standard_Real*)Nod1RValues)[ 3]
123 #define Nod1PntV ((Standard_Real*)Nod1RValues)[ 4]
124 #define Nod1NrmX ((Standard_Real*)Nod1RValues)[ 5]
125 #define Nod1NrmY ((Standard_Real*)Nod1RValues)[ 6]
126 #define Nod1NrmZ ((Standard_Real*)Nod1RValues)[ 7]
127 #define Nod1PCu1 ((Standard_Real*)Nod1RValues)[ 8]
128 #define Nod1PCu2 ((Standard_Real*)Nod1RValues)[ 9]
129 #define Nod1Scal ((Standard_Real*)Nod1RValues)[10]
130
131 #define NodANdSg ((Standard_Integer*)NodAIndices)[0]
132 #define NodAFlag ((Standard_Boolean*)NodAIndices)[1]
133 #define NodAEdg1 ((Standard_Boolean*)NodAIndices)[2]
134 #define NodAEdg2 ((Standard_Boolean*)NodAIndices)[3]
135
136 #define NodAPntX ((Standard_Real*)NodARValues)[ 0]
137 #define NodAPntY ((Standard_Real*)NodARValues)[ 1]
138 #define NodAPntZ ((Standard_Real*)NodARValues)[ 2]
139 #define NodAPntU ((Standard_Real*)NodARValues)[ 3]
140 #define NodAPntV ((Standard_Real*)NodARValues)[ 4]
141 #define NodANrmX ((Standard_Real*)NodARValues)[ 5]
142 #define NodANrmY ((Standard_Real*)NodARValues)[ 6]
143 #define NodANrmZ ((Standard_Real*)NodARValues)[ 7]
144 #define NodAPCu1 ((Standard_Real*)NodARValues)[ 8]
145 #define NodAPCu2 ((Standard_Real*)NodARValues)[ 9]
146 #define NodAScal ((Standard_Real*)NodARValues)[10]
147
148 #define NodBNdSg ((Standard_Integer*)NodBIndices)[0]
149 #define NodBFlag ((Standard_Boolean*)NodBIndices)[1]
150 #define NodBEdg1 ((Standard_Boolean*)NodBIndices)[2]
151 #define NodBEdg2 ((Standard_Boolean*)NodBIndices)[3]
152
153 #define NodBPntX ((Standard_Real*)NodBRValues)[ 0]
154 #define NodBPntY ((Standard_Real*)NodBRValues)[ 1]
155 #define NodBPntZ ((Standard_Real*)NodBRValues)[ 2]
156 #define NodBPntU ((Standard_Real*)NodBRValues)[ 3]
157 #define NodBPntV ((Standard_Real*)NodBRValues)[ 4]
158 #define NodBNrmX ((Standard_Real*)NodBRValues)[ 5]
159 #define NodBNrmY ((Standard_Real*)NodBRValues)[ 6]
160 #define NodBNrmZ ((Standard_Real*)NodBRValues)[ 7]
161 #define NodBPCu1 ((Standard_Real*)NodBRValues)[ 8]
162 #define NodBPCu2 ((Standard_Real*)NodBRValues)[ 9]
163 #define NodBScal ((Standard_Real*)NodBRValues)[10]
164
165 #define Nod2NdSg ((Standard_Integer*)Nod2Indices)[0]
166 #define Nod2Flag ((Standard_Boolean*)Nod2Indices)[1]
167 #define Nod2Edg1 ((Standard_Boolean*)Nod2Indices)[2]
168 #define Nod2Edg2 ((Standard_Boolean*)Nod2Indices)[3]
169
170 #define Nod2PntX ((Standard_Real*)Nod2RValues)[ 0]
171 #define Nod2PntY ((Standard_Real*)Nod2RValues)[ 1]
172 #define Nod2PntZ ((Standard_Real*)Nod2RValues)[ 2]
173 #define Nod2PntU ((Standard_Real*)Nod2RValues)[ 3]
174 #define Nod2PntV ((Standard_Real*)Nod2RValues)[ 4]
175 #define Nod2NrmX ((Standard_Real*)Nod2RValues)[ 5]
176 #define Nod2NrmY ((Standard_Real*)Nod2RValues)[ 6]
177 #define Nod2NrmZ ((Standard_Real*)Nod2RValues)[ 7]
178 #define Nod2PCu1 ((Standard_Real*)Nod2RValues)[ 8]
179 #define Nod2PCu2 ((Standard_Real*)Nod2RValues)[ 9]
180 #define Nod2Scal ((Standard_Real*)Nod2RValues)[10]
181
182 #define Nod3NdSg ((Standard_Integer*)Nod3Indices)[0]
183 #define Nod3Flag ((Standard_Boolean*)Nod3Indices)[1]
184 #define Nod3Edg1 ((Standard_Boolean*)Nod3Indices)[2]
185 #define Nod3Edg2 ((Standard_Boolean*)Nod3Indices)[3]
186
187 #define Nod3PntX ((Standard_Real*)Nod3RValues)[ 0]
188 #define Nod3PntY ((Standard_Real*)Nod3RValues)[ 1]
189 #define Nod3PntZ ((Standard_Real*)Nod3RValues)[ 2]
190 #define Nod3PntU ((Standard_Real*)Nod3RValues)[ 3]
191 #define Nod3PntV ((Standard_Real*)Nod3RValues)[ 4]
192 #define Nod3NrmX ((Standard_Real*)Nod3RValues)[ 5]
193 #define Nod3NrmY ((Standard_Real*)Nod3RValues)[ 6]
194 #define Nod3NrmZ ((Standard_Real*)Nod3RValues)[ 7]
195 #define Nod3PCu1 ((Standard_Real*)Nod3RValues)[ 8]
196 #define Nod3PCu2 ((Standard_Real*)Nod3RValues)[ 9]
197 #define Nod3Scal ((Standard_Real*)Nod3RValues)[10]
198
199 #define Nod4NdSg ((Standard_Integer*)Nod4Indices)[0]
200 #define Nod4Flag ((Standard_Boolean*)Nod4Indices)[1]
201 #define Nod4Edg1 ((Standard_Boolean*)Nod4Indices)[2]
202 #define Nod4Edg2 ((Standard_Boolean*)Nod4Indices)[3]
203
204 #define Nod4PntX ((Standard_Real*)Nod4RValues)[ 0]
205 #define Nod4PntY ((Standard_Real*)Nod4RValues)[ 1]
206 #define Nod4PntZ ((Standard_Real*)Nod4RValues)[ 2]
207 #define Nod4PntU ((Standard_Real*)Nod4RValues)[ 3]
208 #define Nod4PntV ((Standard_Real*)Nod4RValues)[ 4]
209 #define Nod4NrmX ((Standard_Real*)Nod4RValues)[ 5]
210 #define Nod4NrmY ((Standard_Real*)Nod4RValues)[ 6]
211 #define Nod4NrmZ ((Standard_Real*)Nod4RValues)[ 7]
212 #define Nod4PCu1 ((Standard_Real*)Nod4RValues)[ 8]
213 #define Nod4PCu2 ((Standard_Real*)Nod4RValues)[ 9]
214 #define Nod4Scal ((Standard_Real*)Nod4RValues)[10]
215
216 #define Nod11NdSg ((Standard_Integer*)Nod11Indices)[0]
217 #define Nod11Flag ((Standard_Boolean*)Nod11Indices)[1]
218 #define Nod11Edg1 ((Standard_Boolean*)Nod11Indices)[2]
219 #define Nod11Edg2 ((Standard_Boolean*)Nod11Indices)[3]
220
221 #define Nod11PntX ((Standard_Real*)Nod11RValues)[ 0]
222 #define Nod11PntY ((Standard_Real*)Nod11RValues)[ 1]
223 #define Nod11PntZ ((Standard_Real*)Nod11RValues)[ 2]
224 #define Nod11PntU ((Standard_Real*)Nod11RValues)[ 3]
225 #define Nod11PntV ((Standard_Real*)Nod11RValues)[ 4]
226 #define Nod11NrmX ((Standard_Real*)Nod11RValues)[ 5]
227 #define Nod11NrmY ((Standard_Real*)Nod11RValues)[ 6]
228 #define Nod11NrmZ ((Standard_Real*)Nod11RValues)[ 7]
229 #define Nod11PCu1 ((Standard_Real*)Nod11RValues)[ 8]
230 #define Nod11PCu2 ((Standard_Real*)Nod11RValues)[ 9]
231 #define Nod11Scal ((Standard_Real*)Nod11RValues)[10]
232
233 #define Nod1ANdSg ((Standard_Integer*)Nod1AIndices)[0]
234 #define Nod1AFlag ((Standard_Boolean*)Nod1AIndices)[1]
235 #define Nod1AEdg1 ((Standard_Boolean*)Nod1AIndices)[2]
236 #define Nod1AEdg2 ((Standard_Boolean*)Nod1AIndices)[3]
237
238 #define Nod1APntX ((Standard_Real*)Nod1ARValues)[ 0]
239 #define Nod1APntY ((Standard_Real*)Nod1ARValues)[ 1]
240 #define Nod1APntZ ((Standard_Real*)Nod1ARValues)[ 2]
241 #define Nod1APntU ((Standard_Real*)Nod1ARValues)[ 3]
242 #define Nod1APntV ((Standard_Real*)Nod1ARValues)[ 4]
243 #define Nod1ANrmX ((Standard_Real*)Nod1ARValues)[ 5]
244 #define Nod1ANrmY ((Standard_Real*)Nod1ARValues)[ 6]
245 #define Nod1ANrmZ ((Standard_Real*)Nod1ARValues)[ 7]
246 #define Nod1APCu1 ((Standard_Real*)Nod1ARValues)[ 8]
247 #define Nod1APCu2 ((Standard_Real*)Nod1ARValues)[ 9]
248 #define Nod1AScal ((Standard_Real*)Nod1ARValues)[10]
249
250 #define Nod1BNdSg ((Standard_Integer*)Nod1BIndices)[0]
251 #define Nod1BFlag ((Standard_Boolean*)Nod1BIndices)[1]
252 #define Nod1BEdg1 ((Standard_Boolean*)Nod1BIndices)[2]
253 #define Nod1BEdg2 ((Standard_Boolean*)Nod1BIndices)[3]
254
255 #define Nod1BPntX ((Standard_Real*)Nod1BRValues)[ 0]
256 #define Nod1BPntY ((Standard_Real*)Nod1BRValues)[ 1]
257 #define Nod1BPntZ ((Standard_Real*)Nod1BRValues)[ 2]
258 #define Nod1BPntU ((Standard_Real*)Nod1BRValues)[ 3]
259 #define Nod1BPntV ((Standard_Real*)Nod1BRValues)[ 4]
260 #define Nod1BNrmX ((Standard_Real*)Nod1BRValues)[ 5]
261 #define Nod1BNrmY ((Standard_Real*)Nod1BRValues)[ 6]
262 #define Nod1BNrmZ ((Standard_Real*)Nod1BRValues)[ 7]
263 #define Nod1BPCu1 ((Standard_Real*)Nod1BRValues)[ 8]
264 #define Nod1BPCu2 ((Standard_Real*)Nod1BRValues)[ 9]
265 #define Nod1BScal ((Standard_Real*)Nod1BRValues)[10]
266
267 #define Nod12NdSg ((Standard_Integer*)Nod12Indices)[0]
268 #define Nod12Flag ((Standard_Boolean*)Nod12Indices)[1]
269 #define Nod12Edg1 ((Standard_Boolean*)Nod12Indices)[2]
270 #define Nod12Edg2 ((Standard_Boolean*)Nod12Indices)[3]
271
272 #define Nod12PntX ((Standard_Real*)Nod12RValues)[ 0]
273 #define Nod12PntY ((Standard_Real*)Nod12RValues)[ 1]
274 #define Nod12PntZ ((Standard_Real*)Nod12RValues)[ 2]
275 #define Nod12PntU ((Standard_Real*)Nod12RValues)[ 3]
276 #define Nod12PntV ((Standard_Real*)Nod12RValues)[ 4]
277 #define Nod12NrmX ((Standard_Real*)Nod12RValues)[ 5]
278 #define Nod12NrmY ((Standard_Real*)Nod12RValues)[ 6]
279 #define Nod12NrmZ ((Standard_Real*)Nod12RValues)[ 7]
280 #define Nod12PCu1 ((Standard_Real*)Nod12RValues)[ 8]
281 #define Nod12PCu2 ((Standard_Real*)Nod12RValues)[ 9]
282 #define Nod12Scal ((Standard_Real*)Nod12RValues)[10]
283
284 #define Nod13NdSg ((Standard_Integer*)Nod13Indices)[0]
285 #define Nod13Flag ((Standard_Boolean*)Nod13Indices)[1]
286 #define Nod13Edg1 ((Standard_Boolean*)Nod13Indices)[2]
287 #define Nod13Edg2 ((Standard_Boolean*)Nod13Indices)[3]
288
289 #define Nod13PntX ((Standard_Real*)Nod13RValues)[ 0]
290 #define Nod13PntY ((Standard_Real*)Nod13RValues)[ 1]
291 #define Nod13PntZ ((Standard_Real*)Nod13RValues)[ 2]
292 #define Nod13PntU ((Standard_Real*)Nod13RValues)[ 3]
293 #define Nod13PntV ((Standard_Real*)Nod13RValues)[ 4]
294 #define Nod13NrmX ((Standard_Real*)Nod13RValues)[ 5]
295 #define Nod13NrmY ((Standard_Real*)Nod13RValues)[ 6]
296 #define Nod13NrmZ ((Standard_Real*)Nod13RValues)[ 7]
297 #define Nod13PCu1 ((Standard_Real*)Nod13RValues)[ 8]
298 #define Nod13PCu2 ((Standard_Real*)Nod13RValues)[ 9]
299 #define Nod13Scal ((Standard_Real*)Nod13RValues)[10]
300
301 #define Nod14NdSg ((Standard_Integer*)Nod14Indices)[0]
302 #define Nod14Flag ((Standard_Boolean*)Nod14Indices)[1]
303 #define Nod14Edg1 ((Standard_Boolean*)Nod14Indices)[2]
304 #define Nod14Edg2 ((Standard_Boolean*)Nod14Indices)[3]
305
306 #define Nod14PntX ((Standard_Real*)Nod14RValues)[ 0]
307 #define Nod14PntY ((Standard_Real*)Nod14RValues)[ 1]
308 #define Nod14PntZ ((Standard_Real*)Nod14RValues)[ 2]
309 #define Nod14PntU ((Standard_Real*)Nod14RValues)[ 3]
310 #define Nod14PntV ((Standard_Real*)Nod14RValues)[ 4]
311 #define Nod14NrmX ((Standard_Real*)Nod14RValues)[ 5]
312 #define Nod14NrmY ((Standard_Real*)Nod14RValues)[ 6]
313 #define Nod14NrmZ ((Standard_Real*)Nod14RValues)[ 7]
314 #define Nod14PCu1 ((Standard_Real*)Nod14RValues)[ 8]
315 #define Nod14PCu2 ((Standard_Real*)Nod14RValues)[ 9]
316 #define Nod14Scal ((Standard_Real*)Nod14RValues)[10]
317
318 #define Nod21NdSg ((Standard_Integer*)Nod21Indices)[0]
319 #define Nod21Flag ((Standard_Boolean*)Nod21Indices)[1]
320 #define Nod21Edg1 ((Standard_Boolean*)Nod21Indices)[2]
321 #define Nod21Edg2 ((Standard_Boolean*)Nod21Indices)[3]
322
323 #define Nod21PntX ((Standard_Real*)Nod21RValues)[ 0]
324 #define Nod21PntY ((Standard_Real*)Nod21RValues)[ 1]
325 #define Nod21PntZ ((Standard_Real*)Nod21RValues)[ 2]
326 #define Nod21PntU ((Standard_Real*)Nod21RValues)[ 3]
327 #define Nod21PntV ((Standard_Real*)Nod21RValues)[ 4]
328 #define Nod21NrmX ((Standard_Real*)Nod21RValues)[ 5]
329 #define Nod21NrmY ((Standard_Real*)Nod21RValues)[ 6]
330 #define Nod21NrmZ ((Standard_Real*)Nod21RValues)[ 7]
331 #define Nod21PCu1 ((Standard_Real*)Nod21RValues)[ 8]
332 #define Nod21PCu2 ((Standard_Real*)Nod21RValues)[ 9]
333 #define Nod21Scal ((Standard_Real*)Nod21RValues)[10]
334
335 #define Nod2ANdSg ((Standard_Integer*)Nod2AIndices)[0]
336 #define Nod2AFlag ((Standard_Boolean*)Nod2AIndices)[1]
337 #define Nod2AEdg1 ((Standard_Boolean*)Nod2AIndices)[2]
338 #define Nod2AEdg2 ((Standard_Boolean*)Nod2AIndices)[3]
339
340 #define Nod2APntX ((Standard_Real*)Nod2ARValues)[ 0]
341 #define Nod2APntY ((Standard_Real*)Nod2ARValues)[ 1]
342 #define Nod2APntZ ((Standard_Real*)Nod2ARValues)[ 2]
343 #define Nod2APntU ((Standard_Real*)Nod2ARValues)[ 3]
344 #define Nod2APntV ((Standard_Real*)Nod2ARValues)[ 4]
345 #define Nod2ANrmX ((Standard_Real*)Nod2ARValues)[ 5]
346 #define Nod2ANrmY ((Standard_Real*)Nod2ARValues)[ 6]
347 #define Nod2ANrmZ ((Standard_Real*)Nod2ARValues)[ 7]
348 #define Nod2APCu1 ((Standard_Real*)Nod2ARValues)[ 8]
349 #define Nod2APCu2 ((Standard_Real*)Nod2ARValues)[ 9]
350 #define Nod2AScal ((Standard_Real*)Nod2ARValues)[10]
351
352 #define Nod2BNdSg ((Standard_Integer*)Nod2BIndices)[0]
353 #define Nod2BFlag ((Standard_Boolean*)Nod2BIndices)[1]
354 #define Nod2BEdg1 ((Standard_Boolean*)Nod2BIndices)[2]
355 #define Nod2BEdg2 ((Standard_Boolean*)Nod2BIndices)[3]
356
357 #define Nod2BPntX ((Standard_Real*)Nod2BRValues)[ 0]
358 #define Nod2BPntY ((Standard_Real*)Nod2BRValues)[ 1]
359 #define Nod2BPntZ ((Standard_Real*)Nod2BRValues)[ 2]
360 #define Nod2BPntU ((Standard_Real*)Nod2BRValues)[ 3]
361 #define Nod2BPntV ((Standard_Real*)Nod2BRValues)[ 4]
362 #define Nod2BNrmX ((Standard_Real*)Nod2BRValues)[ 5]
363 #define Nod2BNrmY ((Standard_Real*)Nod2BRValues)[ 6]
364 #define Nod2BNrmZ ((Standard_Real*)Nod2BRValues)[ 7]
365 #define Nod2BPCu1 ((Standard_Real*)Nod2BRValues)[ 8]
366 #define Nod2BPCu2 ((Standard_Real*)Nod2BRValues)[ 9]
367 #define Nod2BScal ((Standard_Real*)Nod2BRValues)[10]
368
369 #define Nod22NdSg ((Standard_Integer*)Nod22Indices)[0]
370 #define Nod22Flag ((Standard_Boolean*)Nod22Indices)[1]
371 #define Nod22Edg1 ((Standard_Boolean*)Nod22Indices)[2]
372 #define Nod22Edg2 ((Standard_Boolean*)Nod22Indices)[3]
373
374 #define Nod22PntX ((Standard_Real*)Nod22RValues)[ 0]
375 #define Nod22PntY ((Standard_Real*)Nod22RValues)[ 1]
376 #define Nod22PntZ ((Standard_Real*)Nod22RValues)[ 2]
377 #define Nod22PntU ((Standard_Real*)Nod22RValues)[ 3]
378 #define Nod22PntV ((Standard_Real*)Nod22RValues)[ 4]
379 #define Nod22NrmX ((Standard_Real*)Nod22RValues)[ 5]
380 #define Nod22NrmY ((Standard_Real*)Nod22RValues)[ 6]
381 #define Nod22NrmZ ((Standard_Real*)Nod22RValues)[ 7]
382 #define Nod22PCu1 ((Standard_Real*)Nod22RValues)[ 8]
383 #define Nod22PCu2 ((Standard_Real*)Nod22RValues)[ 9]
384 #define Nod22Scal ((Standard_Real*)Nod22RValues)[10]
385
386 #define Nod23NdSg ((Standard_Integer*)Nod23Indices)[0]
387 #define Nod23Flag ((Standard_Boolean*)Nod23Indices)[1]
388 #define Nod23Edg1 ((Standard_Boolean*)Nod23Indices)[2]
389 #define Nod23Edg2 ((Standard_Boolean*)Nod23Indices)[3]
390
391 #define Nod23PntX ((Standard_Real*)Nod23RValues)[ 0]
392 #define Nod23PntY ((Standard_Real*)Nod23RValues)[ 1]
393 #define Nod23PntZ ((Standard_Real*)Nod23RValues)[ 2]
394 #define Nod23PntU ((Standard_Real*)Nod23RValues)[ 3]
395 #define Nod23PntV ((Standard_Real*)Nod23RValues)[ 4]
396 #define Nod23NrmX ((Standard_Real*)Nod23RValues)[ 5]
397 #define Nod23NrmY ((Standard_Real*)Nod23RValues)[ 6]
398 #define Nod23NrmZ ((Standard_Real*)Nod23RValues)[ 7]
399 #define Nod23PCu1 ((Standard_Real*)Nod23RValues)[ 8]
400 #define Nod23PCu2 ((Standard_Real*)Nod23RValues)[ 9]
401 #define Nod23Scal ((Standard_Real*)Nod23RValues)[10]
402
403 #define Nod24NdSg ((Standard_Integer*)Nod24Indices)[0]
404 #define Nod24Flag ((Standard_Boolean*)Nod24Indices)[1]
405 #define Nod24Edg1 ((Standard_Boolean*)Nod24Indices)[2]
406 #define Nod24Edg2 ((Standard_Boolean*)Nod24Indices)[3]
407
408 #define Nod24PntX ((Standard_Real*)Nod24RValues)[ 0]
409 #define Nod24PntY ((Standard_Real*)Nod24RValues)[ 1]
410 #define Nod24PntZ ((Standard_Real*)Nod24RValues)[ 2]
411 #define Nod24PntU ((Standard_Real*)Nod24RValues)[ 3]
412 #define Nod24PntV ((Standard_Real*)Nod24RValues)[ 4]
413 #define Nod24NrmX ((Standard_Real*)Nod24RValues)[ 5]
414 #define Nod24NrmY ((Standard_Real*)Nod24RValues)[ 6]
415 #define Nod24NrmZ ((Standard_Real*)Nod24RValues)[ 7]
416 #define Nod24PCu1 ((Standard_Real*)Nod24RValues)[ 8]
417 #define Nod24PCu2 ((Standard_Real*)Nod24RValues)[ 9]
418 #define Nod24Scal ((Standard_Real*)Nod24RValues)[10]
419
420 #define ShapeIndex ((Standard_Integer*)IndexPtr)[0]
421 #define F1Index    ((Standard_Integer*)IndexPtr)[1]
422 #define F1Pt1Index ((Standard_Integer*)IndexPtr)[2]
423 #define F1Pt2Index ((Standard_Integer*)IndexPtr)[3]
424 #define F2Index    ((Standard_Integer*)IndexPtr)[4]
425 #define F2Pt1Index ((Standard_Integer*)IndexPtr)[5]
426 #define F2Pt2Index ((Standard_Integer*)IndexPtr)[6]
427 #define MinSeg     ((Standard_Integer*)IndexPtr)[7]
428 #define MaxSeg     ((Standard_Integer*)IndexPtr)[8]
429 #define SegFlags   ((Standard_Integer*)IndexPtr)[9]
430 #ifdef DEB
431 static Standard_Integer DoTrace = Standard_False; 
432 static Standard_Integer DoError = Standard_False; 
433 static Standard_Integer IndexPlusOnePerCentThree [] = { 1 , 2 , 0 };
434 #endif
435 //=======================================================================
436 //function : HLRBRep_PolyAlgo
437 //purpose  : 
438 //=======================================================================
439
440 HLRBRep_PolyAlgo::HLRBRep_PolyAlgo () :
441 myDebug     (Standard_False),
442 myAngle     (5 * M_PI / 180.),
443 myTolSta    (0.1),
444 myTolEnd    (0.9),
445 myTolAngular(0.001)
446 {
447   myAlgo = new HLRAlgo_PolyAlgo();
448 }
449
450 //=======================================================================
451 //function : HLRBRep_PolyAlgo
452 //purpose  : 
453 //=======================================================================
454
455 HLRBRep_PolyAlgo::HLRBRep_PolyAlgo (const Handle(HLRBRep_PolyAlgo)& A)
456 {
457   myDebug      = A->Debug();
458   myAngle      = A->Angle();
459   myTolAngular = A->TolAngular();
460   myTolSta     = A->TolCoef();
461   myTolEnd     = 1 - myTolSta;
462   myAlgo       = A->Algo();
463   myProj       = A->Projector();
464
465   Standard_Integer n = A->NbShapes();
466
467   for (Standard_Integer i = 1; i <= n; i++)
468     Load(A->Shape(i));
469 }
470
471 //=======================================================================
472 //function : HLRBRep_PolyAlgo
473 //purpose  : 
474 //=======================================================================
475
476 HLRBRep_PolyAlgo::HLRBRep_PolyAlgo (const TopoDS_Shape& S) :
477 myDebug     (Standard_False),
478 myAngle     (5 * M_PI / 180.),
479 myTolSta    (0.1),
480 myTolEnd    (0.9),
481 myTolAngular(0.001)
482 {
483   myShapes.Append(S);
484   myAlgo = new HLRAlgo_PolyAlgo();
485 }
486
487 //=======================================================================
488 //function : Shape
489 //purpose  : 
490 //=======================================================================
491
492 TopoDS_Shape & HLRBRep_PolyAlgo::Shape (const Standard_Integer I)
493 {
494   Standard_OutOfRange_Raise_if (I == 0 || I > myShapes.Length(),
495                                "HLRBRep_PolyAlgo::Shape : unknown Shape");
496   return myShapes(I);
497 }
498
499 //=======================================================================
500 //function : Remove
501 //purpose  : 
502 //=======================================================================
503
504 void HLRBRep_PolyAlgo::Remove (const Standard_Integer I)
505 {
506   Standard_OutOfRange_Raise_if (I == 0 || I > myShapes.Length(),
507                                 "HLRBRep_PolyAlgo::Remove : unknown Shape");
508   myShapes.Remove(I);
509   myAlgo->Clear();
510   myEMap.Clear();
511   myFMap.Clear();
512 }
513
514 //=======================================================================
515 //function : Index
516 //purpose  : 
517 //=======================================================================
518
519 Standard_Integer HLRBRep_PolyAlgo::Index (const TopoDS_Shape& S) const
520 {
521   Standard_Integer n = myShapes.Length();
522
523   for (Standard_Integer i = 1; i <= n; i++)
524     if (myShapes(i) == S) return i;
525
526   return 0;
527 }
528
529 //=======================================================================
530 //function : Algo
531 //purpose  : 
532 //=======================================================================
533
534 Handle(HLRAlgo_PolyAlgo) HLRBRep_PolyAlgo::Algo () const
535 {
536   return myAlgo;
537 }
538
539 //=======================================================================
540 //function : Update
541 //purpose  : 
542 //=======================================================================
543
544 void HLRBRep_PolyAlgo::Update ()
545 {
546   myAlgo->Clear();
547   myEMap.Clear();
548   myFMap.Clear();
549   TopoDS_Shape Shape = MakeShape();
550
551   if (!Shape.IsNull()) {
552     TopExp_Explorer exshell;
553     Standard_Boolean IsoledF,IsoledE;//,closed;
554     TopLoc_Location L;
555     TopTools_MapOfShape ShapeMap1,ShapeMap2;
556     TopExp::MapShapes(Shape,TopAbs_EDGE,myEMap);
557     TopExp::MapShapes(Shape,TopAbs_FACE,myFMap);
558     Standard_Integer nbEdge = myEMap.Extent();
559     Standard_Integer nbFace = myFMap.Extent();
560     TColStd_Array1OfInteger   ES (0,nbEdge); // index of the Shell
561     TColStd_Array1OfTransient PD (0,nbFace); // HLRAlgo_PolyData
562     TColStd_Array1OfTransient PID(0,nbFace); // PolyInternalData
563     Standard_Integer nbShell = InitShape(Shape,IsoledF,IsoledE);
564     if (nbShell > 0) {
565       TColStd_Array1OfTransient& Shell = myAlgo->PolyShell();
566       Standard_Integer iShell = 0;
567       
568       for (exshell.Init(Shape, TopAbs_SHELL);
569            exshell.More(); 
570            exshell.Next())
571         StoreShell(exshell.Current(),iShell,Shell,
572                    Standard_False,Standard_False,
573                    ES,PD,PID,ShapeMap1,ShapeMap2);
574       if (IsoledF)
575         StoreShell(Shape,iShell,Shell,IsoledF,Standard_False,
576                    ES,PD,PID,ShapeMap1,ShapeMap2);
577       if (IsoledE)
578         StoreShell(Shape,iShell,Shell,Standard_False,IsoledE,
579                    ES,PD,PID,ShapeMap1,ShapeMap2);
580       myAlgo->Update();
581     }
582   }
583 }
584
585 //=======================================================================
586 //function : MakeShape
587 //purpose  : 
588 //=======================================================================
589
590 TopoDS_Shape HLRBRep_PolyAlgo::MakeShape () const
591 {
592   Standard_Integer n = myShapes.Length();
593   Standard_Boolean FirstTime = Standard_True;
594   BRep_Builder B;
595   TopoDS_Shape Shape;
596   
597   for (Standard_Integer i = 1; i <= n; i++) {
598     if (FirstTime) {
599       FirstTime = Standard_False;
600       B.MakeCompound(TopoDS::Compound(Shape));
601     }
602     B.Add(Shape,myShapes(i));
603   }
604   return Shape;
605 }
606   
607 //=======================================================================
608 //function : InitShape
609 //purpose  : 
610 //=======================================================================
611
612 Standard_Integer
613 HLRBRep_PolyAlgo::InitShape (const TopoDS_Shape& Shape,
614                              Standard_Boolean& IsoledF,
615                              Standard_Boolean& IsoledE)
616 {
617   TopTools_MapOfShape ShapeMap0;
618   Standard_Integer nbShell = 0;
619   IsoledF = Standard_False;
620   IsoledE = Standard_False;
621   TopExp_Explorer exshell,exface,exedge;
622   TopLoc_Location L;
623   
624   for (exshell.Init(Shape, TopAbs_SHELL);
625        exshell.More(); 
626        exshell.Next()) {
627     Standard_Boolean withTrian = Standard_False;
628     
629     for (exface.Init(exshell.Current(), TopAbs_FACE);
630          exface.More(); 
631          exface.Next()) {
632       const TopoDS_Face& F = TopoDS::Face(exface.Current());
633       if (!BRep_Tool::Triangulation(F,L).IsNull()) {
634         if (ShapeMap0.Add(F))
635           withTrian = Standard_True;
636       }
637     }
638     if (withTrian) nbShell++;
639   }
640   
641   for (exface.Init(Shape, TopAbs_FACE, TopAbs_SHELL);
642        exface.More() && !IsoledF; 
643        exface.Next()) {
644     const TopoDS_Face& F = TopoDS::Face(exface.Current());
645     if (!BRep_Tool::Triangulation(F,L).IsNull()) {
646       if (ShapeMap0.Add(F))
647         IsoledF = Standard_True;
648     }
649   }
650   if (IsoledF) nbShell++;
651   
652   for (exedge.Init(Shape, TopAbs_EDGE, TopAbs_FACE);
653        exedge.More() && !IsoledE; 
654        exedge.Next())
655     IsoledE = Standard_True;
656   if (IsoledE) nbShell++;
657   if (nbShell > 0)
658     myAlgo->Init(new TColStd_HArray1OfTransient(1,nbShell));
659   return nbShell;
660 }
661
662 //=======================================================================
663 //function : StoreShell
664 //purpose  : 
665 //=======================================================================
666
667 void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape,
668                                    Standard_Integer& iShell,
669                                    TColStd_Array1OfTransient& Shell,
670                                    const Standard_Boolean IsoledF,
671                                    const Standard_Boolean IsoledE,
672                                    TColStd_Array1OfInteger& ES,
673                                    TColStd_Array1OfTransient& PD,
674                                    TColStd_Array1OfTransient& PID,
675                                    TopTools_MapOfShape& ShapeMap1,
676                                    TopTools_MapOfShape& ShapeMap2)
677 {
678   TopLoc_Location L;
679   TopExp_Explorer exface,exedge;
680   Standard_Integer f,i,j;
681   Standard_Integer nbFaceShell = 0;
682   Standard_Boolean reversed;
683   Standard_Boolean closed    = Standard_False;
684   const gp_Trsf& T  = myProj.Transformation();
685   const gp_Trsf& TI = myProj.InvertedTransformation();
686   const gp_XYZ& tloc = T.TranslationPart();
687   TLoc[0] = tloc.X();
688   TLoc[1] = tloc.Y();
689   TLoc[2] = tloc.Z();
690   const gp_Mat& tmat = T.VectorialPart();
691   TMat[0][0] = tmat.Value(1,1);
692   TMat[0][1] = tmat.Value(1,2);
693   TMat[0][2] = tmat.Value(1,3);
694   TMat[1][0] = tmat.Value(2,1);
695   TMat[1][1] = tmat.Value(2,2);
696   TMat[1][2] = tmat.Value(2,3);
697   TMat[2][0] = tmat.Value(3,1);
698   TMat[2][1] = tmat.Value(3,2);
699   TMat[2][2] = tmat.Value(3,3);
700   const gp_XYZ& tilo = TI.TranslationPart();
701   TILo[0] = tilo.X();
702   TILo[1] = tilo.Y();
703   TILo[2] = tilo.Z();
704   const gp_Mat& tima = TI.VectorialPart();
705   TIMa[0][0] = tima.Value(1,1);
706   TIMa[0][1] = tima.Value(1,2);
707   TIMa[0][2] = tima.Value(1,3);
708   TIMa[1][0] = tima.Value(2,1);
709   TIMa[1][1] = tima.Value(2,2);
710   TIMa[1][2] = tima.Value(2,3);
711   TIMa[2][0] = tima.Value(3,1);
712   TIMa[2][1] = tima.Value(3,2);
713   TIMa[2][2] = tima.Value(3,3);
714   if (!IsoledE) {
715     if (!IsoledF) {
716       closed = Shape.Closed();
717       if (!closed) {
718         TopTools_IndexedMapOfShape EM;
719         TopExp::MapShapes(Shape,TopAbs_EDGE,EM);
720         Standard_Integer ie;
721         Standard_Integer nbEdge = EM.Extent ();
722         Standard_Integer *flag = new Standard_Integer[nbEdge + 1];
723
724         for (ie = 1; ie <= nbEdge; ie++)
725           flag[ie] = 0;
726         
727         for (exedge.Init(Shape, TopAbs_EDGE);
728              exedge.More(); 
729              exedge.Next()) {
730           const TopoDS_Edge& E = TopoDS::Edge(exedge.Current());
731           ie = EM.FindIndex(E);
732           TopAbs_Orientation orient = E.Orientation();
733           if (!BRep_Tool::Degenerated(E)) {
734             if      (orient == TopAbs_FORWARD ) flag[ie] += 1;
735             else if (orient == TopAbs_REVERSED) flag[ie] -= 1;
736           }
737         }
738         closed = Standard_True;
739         
740         for (ie = 1; ie <= nbEdge && closed; ie++)
741           closed = (flag[ie] == 0); 
742         delete [] flag;
743         flag = NULL;
744       }
745       
746       exface.Init(Shape, TopAbs_FACE);
747     }
748     else
749       exface.Init(Shape, TopAbs_FACE, TopAbs_SHELL);
750     
751     for (; exface.More(); exface.Next()) {
752       const TopoDS_Face& F = TopoDS::Face(exface.Current());
753       if (!BRep_Tool::Triangulation(F,L).IsNull()) {
754         if (ShapeMap1.Add(F))
755           nbFaceShell++;
756       }
757     }
758   }
759   if (nbFaceShell > 0 || IsoledE) {
760     iShell++;
761     Shell(iShell) = new HLRAlgo_PolyShellData(nbFaceShell);
762   }
763   if (nbFaceShell > 0) {
764     const Handle(HLRAlgo_PolyShellData)& psd =
765       *(Handle(HLRAlgo_PolyShellData)*)&(Shell(iShell));
766     Standard_Integer iFace = 0;
767     if (!IsoledF) exface.Init(Shape, TopAbs_FACE);
768     else          exface.Init(Shape, TopAbs_FACE, TopAbs_SHELL);
769     TopTools_MapOfShape ShapeMapBis;
770     
771     for (; exface.More(); exface.Next()) {
772       const TopoDS_Face& F = TopoDS::Face(exface.Current());  
773       const Handle(Poly_Triangulation)& Tr = BRep_Tool::Triangulation(F,L);
774       if (!Tr.IsNull()) {
775         if (ShapeMap2.Add(F)) {
776           iFace++;
777           f = myFMap.FindIndex(F);
778           reversed = F.Orientation() == TopAbs_REVERSED;
779           gp_Trsf TT = L.Transformation();
780           TT.PreMultiply(T);
781           const gp_XYZ& ttlo = TT.TranslationPart();
782           TTLo[0] = ttlo.X();
783           TTLo[1] = ttlo.Y();
784           TTLo[2] = ttlo.Z();
785           const gp_Mat& ttma = TT.VectorialPart();
786           TTMa[0][0] = ttma.Value(1,1);
787           TTMa[0][1] = ttma.Value(1,2);
788           TTMa[0][2] = ttma.Value(1,3);
789           TTMa[1][0] = ttma.Value(2,1);
790           TTMa[1][1] = ttma.Value(2,2);
791           TTMa[1][2] = ttma.Value(2,3);
792           TTMa[2][0] = ttma.Value(3,1);
793           TTMa[2][1] = ttma.Value(3,2);
794           TTMa[2][2] = ttma.Value(3,3);
795           Poly_Array1OfTriangle & Tri = Tr->ChangeTriangles();
796           TColgp_Array1OfPnt    & Nod = Tr->ChangeNodes();
797           Standard_Integer nbN = Nod.Upper();
798           Standard_Integer nbT = Tri.Upper();
799           PD (f) = new HLRAlgo_PolyData();
800           psd->PolyData().ChangeValue(iFace) = PD(f);
801           PID(f) = new HLRAlgo_PolyInternalData(nbN,nbT);
802           Handle(HLRAlgo_PolyInternalData)& pid = 
803             *(Handle(HLRAlgo_PolyInternalData)*)&(PID(f));
804           Handle(Geom_Surface) S = BRep_Tool::Surface(F);
805           if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
806             S = Handle(Geom_RectangularTrimmedSurface)::DownCast(S)->BasisSurface();
807           GeomAdaptor_Surface AS(S);
808           pid->Planar(AS.GetType() == GeomAbs_Plane);
809           Standard_Address TData = &pid->TData();
810           Standard_Address PISeg = &pid->PISeg();
811           Standard_Address PINod = &pid->PINod();
812           Poly_Triangle       * OT = &(Tri.ChangeValue(1));
813           HLRAlgo_TriangleData* NT =
814             &(((HLRAlgo_Array1OfTData*)TData)->ChangeValue(1));
815
816           for (i = 1; i <= nbT; i++) {
817             Standard_Address Tri2Indices = NT->Indices();
818             OT->Get(Tri2Node1,Tri2Node2,Tri2Node3);
819             Tri2Flags = 0;
820             if (reversed) {
821               j         = Tri2Node1;
822               Tri2Node1 = Tri2Node3;
823               Tri2Node3 = j;
824             }
825             OT++;
826             NT++;
827           }
828
829           gp_Pnt                          * ON = &(Nod.ChangeValue(1));
830           Handle(HLRAlgo_PolyInternalNode)* NN = 
831             &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(1));
832
833           for (i = 1; i <= nbN; i++) {
834             const Standard_Address Nod1RValues = (*NN)->RValues();
835             const Standard_Address Nod1Indices = (*NN)->Indices();
836             Nod1NdSg = 0;
837             Nod1Flag = 0;
838             Nod1PntX = ON->X();
839             Nod1PntY = ON->Y();
840             Nod1PntZ = ON->Z();
841             TTMultiply(Nod1PntX,Nod1PntY,Nod1PntZ);
842             ON++;
843             NN++;
844           }
845           pid->UpdateLinks(TData,PISeg,PINod);
846           if (Tr->HasUVNodes()) {
847             myBSurf.Initialize(F,Standard_False);
848             TColgp_Array1OfPnt2d & UVN = Tr->ChangeUVNodes();
849             gp_Pnt2d* OUVN = &(UVN.ChangeValue(1));
850             NN             = &(((HLRAlgo_Array1OfPINod*)PINod)->
851                                ChangeValue(1));
852             
853             for (i = 1; i <= nbN; i++) {
854               const Standard_Address Nod1Indices = (*NN)->Indices();
855               const Standard_Address Nod1RValues = (*NN)->RValues();
856               Nod1PntU = OUVN->X();
857               Nod1PntV = OUVN->Y();
858               if (Normal(i,Nod1Indices,Nod1RValues,
859                          TData,PISeg,PINod,Standard_False))
860                 Nod1Flag |=  NMskNorm;
861               else {
862                 Nod1Flag &= ~NMskNorm;
863                 Nod1Scal = 0;
864               }
865               OUVN++;
866               NN++;
867             }
868           }
869 #ifdef DEB
870           else if (DoError) {
871             cout << " HLRBRep_PolyAlgo::StoreShell : Face ";
872             cout << f << " non triangulated" << endl;
873           }
874 #endif
875           NT = &(((HLRAlgo_Array1OfTData*)TData)->ChangeValue(1));
876
877           for (i = 1; i <= nbT; i++) {
878             const Standard_Address Tri1Indices = NT->Indices();
879             const Handle(HLRAlgo_PolyInternalNode)* PN1 = 
880               &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri1Node1));
881             const Handle(HLRAlgo_PolyInternalNode)* PN2 = 
882               &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri1Node2));
883             const Handle(HLRAlgo_PolyInternalNode)* PN3 = 
884               &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri1Node3));
885             const Standard_Address Nod1Indices = (*PN1)->Indices();
886             const Standard_Address Nod2Indices = (*PN2)->Indices();
887             const Standard_Address Nod3Indices = (*PN3)->Indices();
888             const Standard_Address Nod1RValues = (*PN1)->RValues();
889             const Standard_Address Nod2RValues = (*PN2)->RValues();
890             const Standard_Address Nod3RValues = (*PN3)->RValues();
891             OrientTriangle(i,Tri1Indices,
892                            Nod1Indices,Nod1RValues,
893                            Nod2Indices,Nod2RValues,
894                            Nod3Indices,Nod3RValues);
895             NT++;
896           }
897         }
898       }
899 #ifdef DEB
900       else if (DoError) {
901         cout << "HLRBRep_PolyAlgo::StoreShell : Face ";
902         cout << f << " deja stockee" << endl;
903       }
904 #endif
905     }
906     Standard_Integer nbFace = myFMap.Extent();
907     HLRAlgo_ListOfBPoint& List = psd->Edges();
908     TopTools_IndexedDataMapOfShapeListOfShape EF;
909     TopExp::MapShapesAndAncestors(Shape,TopAbs_EDGE,TopAbs_FACE,EF);
910     Handle(HLRAlgo_PolyInternalData)* pid = 
911         (Handle(HLRAlgo_PolyInternalData)*)&(PID.ChangeValue(1));
912     
913     for (f = 1; f <= nbFace; f++) {
914       if (!(*pid).IsNull()) {
915
916         for (exedge.Init(myFMap(f),TopAbs_EDGE);
917              exedge.More(); 
918              exedge.Next()) {
919           TopoDS_Edge E = TopoDS::Edge(exedge.Current());
920           if (ShapeMap1.Add(E)) {
921             Standard_Integer e = myEMap.FindIndex(E);
922             ES(e) = iShell;
923             Standard_Integer i = EF.FindIndex(E);
924             if (i > 0) {
925               TopTools_ListOfShape& LS = EF(i);
926               InitBiPointsWithConnexity(e,E,List,PID,LS,Standard_True);
927             }
928             else {
929               TopTools_ListOfShape LS;
930               InitBiPointsWithConnexity(e,E,List,PID,LS,Standard_False);
931             }
932           }
933         }
934       }
935       pid++;
936     }
937     InsertOnOutLine(PID);
938     CheckFrBackTriangles(List,PID);
939     UpdateOutLines(List,PID);
940     UpdateEdgesBiPoints(List,PID,closed);
941     UpdatePolyData(PD,PID,closed);
942     pid = (Handle(HLRAlgo_PolyInternalData)*)&(PID.ChangeValue(1));
943     
944     for (f = 1; f <= nbFace; f++) {
945       (*pid).Nullify();  
946       pid++;
947     }
948   }
949   else if (IsoledE) {
950     const Handle(HLRAlgo_PolyShellData)& psd =
951       *(Handle(HLRAlgo_PolyShellData)*)&(Shell(iShell));
952     HLRAlgo_ListOfBPoint& List = psd->Edges();
953     
954     for (exedge.Init(Shape, TopAbs_EDGE, TopAbs_FACE);
955          exedge.More(); 
956          exedge.Next()) {
957       TopoDS_Edge E = TopoDS::Edge(exedge.Current());
958       if (ShapeMap1.Add(E)) {
959         Standard_Integer e = myEMap.FindIndex(E);
960         ES(e) = iShell;
961         TopTools_ListOfShape LS;
962         InitBiPointsWithConnexity(e,E,List,PID,LS,Standard_False);
963       }
964     }
965   }
966 }
967
968 //=======================================================================
969 //function : Normal
970 //purpose  : 
971 //=======================================================================
972
973 Standard_Boolean HLRBRep_PolyAlgo::
974 Normal (const Standard_Integer iNode,
975         const Standard_Address Nod1Indices,
976         const Standard_Address Nod1RValues,
977         Standard_Address& TData,
978         Standard_Address& PISeg,
979         Standard_Address& PINod,
980         const Standard_Boolean orient) const
981 {
982   gp_Vec D1U,D1V,D2U,D2V,D2UV;
983   gp_Pnt P;
984   gp_Dir Norma;
985   Standard_Boolean OK;
986   CSLib_DerivativeStatus Status;
987   CSLib_NormalStatus NStat;
988   myBSurf.D1(Nod1PntU,Nod1PntV,P,D1U,D1V);
989   CSLib::Normal(D1U,D1V,Standard_Real(Precision::Angular()),
990                 Status,Norma);
991   if (Status != CSLib_Done) {
992     myBSurf.D2(Nod1PntU,Nod1PntV,P,D1U,D1V,D2U,D2V,D2UV);
993     CSLib::Normal(D1U,D1V,D2U,D2V,D2UV,
994                   Precision::Angular(),OK,NStat,Norma);
995     if (!OK)
996       return Standard_False;
997   }
998   Standard_Real EyeX =  0;
999   Standard_Real EyeY =  0;
1000   Standard_Real EyeZ = -1;
1001   if (myProj.Perspective()) {
1002     EyeX = Nod1PntX;
1003     EyeY = Nod1PntY;
1004     EyeZ = Nod1PntZ - myProj.Focus();
1005     Standard_Real d = sqrt(EyeX * EyeX + EyeY * EyeY + EyeZ * EyeZ);
1006     if (d > 0) {
1007       EyeX /= d;
1008       EyeY /= d;
1009       EyeZ /= d;
1010     }
1011   }
1012   Nod1NrmX = Norma.X();
1013   Nod1NrmY = Norma.Y();
1014   Nod1NrmZ = Norma.Z();
1015 //  TMultiply(Nod1NrmX,Nod1NrmY,Nod1NrmZ);
1016   TMultiply(Nod1NrmX,Nod1NrmY,Nod1NrmZ,myProj.Perspective()); //OCC349
1017   Standard_Real NormX,NormY,NormZ;
1018   
1019   if (AverageNormal(iNode,Nod1Indices,TData,PISeg,PINod,
1020                     NormX,NormY,NormZ)) {
1021     if (Nod1NrmX * NormX +
1022         Nod1NrmY * NormY +
1023         Nod1NrmZ * NormZ < 0) {
1024       Nod1NrmX = -Nod1NrmX;
1025       Nod1NrmY = -Nod1NrmY;
1026       Nod1NrmZ = -Nod1NrmZ;
1027     }
1028     Nod1Scal = (Nod1NrmX * EyeX +
1029                 Nod1NrmY * EyeY +
1030                 Nod1NrmZ * EyeZ);
1031   }
1032   else {
1033     Nod1Scal = 0;
1034     Nod1NrmX = 1;
1035     Nod1NrmY = 0;
1036     Nod1NrmZ = 0;
1037 #ifdef DEB
1038     if (DoError) {
1039       cout << "HLRBRep_PolyAlgo::Normal : AverageNormal error";
1040       cout << endl;
1041     }
1042 #endif
1043   }
1044   if (Nod1Scal > 0) {
1045     if ( Nod1Scal < myTolAngular) {
1046       Nod1Scal  = 0;
1047       Nod1Flag |= NMskOutL;
1048     }
1049   }
1050   else {
1051     if (-Nod1Scal < myTolAngular) {
1052       Nod1Scal  = 0;
1053       Nod1Flag |= NMskOutL;
1054     }
1055   }
1056   if (orient) UpdateAroundNode(iNode,Nod1Indices,
1057                                TData,PISeg,PINod);
1058   return Standard_True;
1059 }
1060
1061 //=======================================================================
1062 //function : AverageNormal
1063 //purpose  : 
1064 //=======================================================================
1065
1066 Standard_Boolean
1067 HLRBRep_PolyAlgo::AverageNormal(const Standard_Integer iNode,
1068                                 const Standard_Address Nod1Indices,
1069                                 Standard_Address& TData,
1070                                 Standard_Address& PISeg,
1071                                 Standard_Address& PINod,
1072                                 Standard_Real& X,
1073                                 Standard_Real& Y,
1074                                 Standard_Real& Z) const
1075 {
1076   Standard_Boolean OK = Standard_False;
1077   Standard_Integer jNode = 0,kNode,iiii,iTri1,iTri2;
1078   X = 0;
1079   Y = 0;
1080   Z = 0;
1081   iiii = Nod1NdSg;
1082
1083   while (iiii != 0 && !OK) {
1084     const Standard_Address Seg2Indices = 
1085       ((HLRAlgo_Array1OfPISeg*)PISeg)->ChangeValue(iiii).Indices();
1086     iTri1 = Seg2Conex1;
1087     iTri2 = Seg2Conex2;
1088     if ( iTri1 != 0) AddNormalOnTriangle
1089       (iTri1,iNode,jNode,TData,PINod,X,Y,Z,OK);
1090     if ( iTri2 != 0) AddNormalOnTriangle
1091       (iTri2,iNode,jNode,TData,PINod,X,Y,Z,OK);
1092     if (Seg2LstSg1 == iNode) iiii = Seg2NxtSg1;
1093     else                     iiii = Seg2NxtSg2;
1094   }
1095
1096   if (jNode != 0) {
1097     const Standard_Address Nod2Indices =
1098       ((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(jNode)->Indices();
1099     iiii = Nod2NdSg;
1100     
1101     while (iiii != 0 && !OK) {
1102       const Standard_Address Seg2Indices = 
1103         ((HLRAlgo_Array1OfPISeg*)PISeg)->ChangeValue(iiii).Indices();
1104       iTri1 = Seg2Conex1;
1105       iTri2 = Seg2Conex2;
1106       if ( iTri1 != 0) AddNormalOnTriangle
1107         (iTri1,jNode,kNode,TData,PINod,X,Y,Z,OK);
1108       if ( iTri2 != 0) AddNormalOnTriangle
1109         (iTri2,jNode,kNode,TData,PINod,X,Y,Z,OK);
1110       if (Seg2LstSg1 == jNode) iiii = Seg2NxtSg1;
1111       else                     iiii = Seg2NxtSg2;
1112     }
1113   }
1114   Standard_Real d = sqrt (X * X + Y * Y + Z * Z);
1115   if (OK && d < 1.e-10) {
1116     OK = Standard_False;
1117 #ifdef DEB
1118     if (DoError) {
1119       cout << "HLRAlgo_PolyInternalData:: inverted normals on ";
1120       cout << "node " << iNode << endl;
1121     }
1122 #endif
1123   }
1124   return OK;
1125 }
1126
1127 //=======================================================================
1128 //function : AddNormalOnTriangle
1129 //purpose  : 
1130 //=======================================================================
1131
1132 void
1133 HLRBRep_PolyAlgo::
1134 AddNormalOnTriangle(const Standard_Integer iTri,
1135                     const Standard_Integer iNode,
1136                     Standard_Integer& jNode,
1137                     Standard_Address& TData,
1138                     Standard_Address& PINod,
1139                     Standard_Real& X,
1140                     Standard_Real& Y,
1141                     Standard_Real& Z,
1142                     Standard_Boolean& OK) const
1143 {
1144   Standard_Real dn,dnx,dny,dnz;
1145   Standard_Real d1,dx1,dy1,dz1;
1146   Standard_Real d2,dx2,dy2,dz2;
1147   Standard_Real d3,dx3,dy3,dz3;
1148   const Standard_Address Tri2Indices =
1149     ((HLRAlgo_Array1OfTData*)TData)->ChangeValue(iTri).Indices();
1150   const Standard_Address Nod1RValues =
1151     ((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri2Node1)->RValues();
1152   const Standard_Address Nod2RValues =
1153     ((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri2Node2)->RValues();
1154   const Standard_Address Nod3RValues =
1155     ((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri2Node3)->RValues();
1156   dx1 = Nod2PntX - Nod1PntX;
1157   dy1 = Nod2PntY - Nod1PntY;
1158   dz1 = Nod2PntZ - Nod1PntZ;
1159   d1 = sqrt(dx1 * dx1 + dy1 * dy1 + dz1 * dz1);
1160   if (d1 < 1.e-10) {
1161     if      (Tri2Node1 == iNode) jNode = Tri2Node2;
1162     else if (Tri2Node2 == iNode) jNode = Tri2Node1;
1163   }
1164   else {
1165     dx2 = Nod3PntX - Nod2PntX;
1166     dy2 = Nod3PntY - Nod2PntY;
1167     dz2 = Nod3PntZ - Nod2PntZ;
1168     d2 = sqrt(dx2 * dx2 + dy2 * dy2 + dz2 * dz2);
1169     if (d2 < 1.e-10) {
1170       if      (Tri2Node2 == iNode) jNode = Tri2Node3;
1171       else if (Tri2Node3 == iNode) jNode = Tri2Node2;
1172     }
1173     else {
1174       dx3 = Nod1PntX - Nod3PntX;
1175       dy3 = Nod1PntY - Nod3PntY;
1176       dz3 = Nod1PntZ - Nod3PntZ;
1177       d3 = sqrt(dx3 * dx3 + dy3 * dy3 + dz3 * dz3);
1178       if (d3 < 1.e-10) {
1179         if      (Tri2Node3 == iNode) jNode = Tri2Node1;
1180         else if (Tri2Node1 == iNode) jNode = Tri2Node3;
1181       }
1182       else {
1183         dn = 1 / (d1 * d2);
1184         dnx = (dy1 * dz2 - dy2 * dz1) * dn;
1185         dny = (dz1 * dx2 - dz2 * dx1) * dn;
1186         dnz = (dx1 * dy2 - dx2 * dy1) * dn;
1187         dn = sqrt(dnx * dnx + dny * dny + dnz * dnz);
1188         if (dn > 1.e-10) {
1189           OK = Standard_True;
1190           X += dnx;
1191           Y += dny;
1192           Z += dnz;
1193         }
1194       }
1195     }
1196   }
1197 }
1198
1199 //=======================================================================
1200 //function : InitBiPointsWithConnexity
1201 //purpose  : 
1202 //=======================================================================
1203
1204 void HLRBRep_PolyAlgo::
1205 InitBiPointsWithConnexity (const Standard_Integer e,
1206                            TopoDS_Edge& E,
1207                            HLRAlgo_ListOfBPoint& List,
1208                            TColStd_Array1OfTransient& PID,
1209                            TopTools_ListOfShape& LS,
1210                            const Standard_Boolean connex)
1211 {
1212   Standard_Integer iPol,nbPol,i1,i1p1,i1p2,i2,i2p1,i2p2;
1213   Standard_Real X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ;
1214   Standard_Real XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2;
1215   Standard_Real U1,U2;
1216   Handle(Poly_PolygonOnTriangulation) HPol[2];
1217   TopLoc_Location L;
1218   myBCurv.Initialize(E);
1219   if (connex) {
1220     Standard_Integer nbConnex = LS.Extent();
1221     if      (nbConnex == 1) {
1222       TopTools_ListIteratorOfListOfShape itn(LS);
1223       const TopoDS_Face& F1 = TopoDS::Face(itn.Value());
1224       i1      = myFMap.FindIndex(F1);
1225       const Handle(Poly_Triangulation)& Tr1 = BRep_Tool::Triangulation(F1,L);
1226       HPol[0] = BRep_Tool::PolygonOnTriangulation(E,Tr1,L);
1227       const Handle(HLRAlgo_PolyInternalData)& pid1 = 
1228         *(Handle(HLRAlgo_PolyInternalData)*)&(PID(i1));
1229       if (!HPol[0].IsNull()) {
1230         myPC.Initialize(E,F1);
1231         const Handle(TColStd_HArray1OfReal)& par = HPol[0]->Parameters();
1232         const TColStd_Array1OfInteger&      Pol1 = HPol[0]->Nodes();
1233         nbPol = Pol1.Upper();
1234         Standard_Address TData1 = &pid1->TData();
1235         Standard_Address PISeg1 = &pid1->PISeg();
1236         Standard_Address PINod1 = &pid1->PINod();
1237         Standard_Address Nod11Indices,Nod12Indices;
1238         Standard_Address Nod11RValues,Nod12RValues;
1239         const Handle(HLRAlgo_PolyInternalNode)* pi1p1 =
1240           &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(Pol1(1    )));
1241         Nod11Indices = (*pi1p1)->Indices();
1242         Nod11RValues = (*pi1p1)->RValues();
1243         const Handle(HLRAlgo_PolyInternalNode)* pi1p2 =
1244           &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(Pol1(nbPol)));
1245         Nod12Indices = (*pi1p2)->Indices();
1246         Nod12RValues = (*pi1p2)->RValues();
1247         Nod11Flag |=  NMskVert;
1248         Nod12Flag |=  NMskVert;
1249         
1250         for (iPol = 1; iPol <= nbPol; iPol++) {
1251           const Handle(HLRAlgo_PolyInternalNode)* pi1pA =
1252             &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(Pol1(iPol)));
1253           Standard_Address Nod1AIndices = (*pi1pA)->Indices();
1254           Standard_Address Nod1ARValues = (*pi1pA)->RValues();
1255           if (Nod1AEdg1 == 0 || Nod1AEdg1 == (Standard_Boolean) e) {
1256             Nod1AEdg1 = e;
1257             Nod1APCu1 = par->Value(iPol);
1258           }
1259           else {
1260             Nod1AEdg2 = e;
1261             Nod1APCu2 = par->Value(iPol);
1262           }
1263         }
1264         
1265         i1p2 = Pol1(1);
1266         Nod12Indices = Nod11Indices;
1267         Nod12RValues = Nod11RValues;
1268         XTI2 = X2 = Nod12PntX;
1269         YTI2 = Y2 = Nod12PntY;
1270         ZTI2 = Z2 = Nod12PntZ;
1271         if      (Nod12Edg1 ==  (Standard_Boolean) e) U2 = Nod12PCu1;
1272         else if (Nod12Edg2 ==  (Standard_Boolean) e) U2 = Nod12PCu2;
1273 #ifdef DEB
1274         else {
1275           cout << " HLRBRep_PolyAlgo::InitBiPointsWithConnexity : ";
1276           cout << "Parameter error on Node " << i1p2 << endl;
1277         }
1278 #endif
1279         Nod12Flag |= NMskEdge;
1280         TIMultiply(XTI2,YTI2,ZTI2);
1281         if (Pol1(1) == Pol1(nbPol) && myPC.IsPeriodic())
1282           U2 = U2 - myPC.Period();
1283         
1284         if (nbPol == 2 && BRep_Tool::Degenerated(E)) {
1285           CheckDegeneratedSegment(Nod11Indices,Nod11RValues,
1286                                   Nod12Indices,Nod12RValues);
1287           UpdateAroundNode(Pol1(1    ),Nod11Indices,TData1,PISeg1,PINod1);
1288           UpdateAroundNode(Pol1(nbPol),Nod12Indices,TData1,PISeg1,PINod1);
1289         }
1290         else {
1291
1292           for (iPol = 2; iPol <= nbPol; iPol++) {
1293             i1p1 = i1p2;
1294             Nod11Indices = Nod12Indices;
1295             Nod11RValues = Nod12RValues;
1296             i1p2 = Pol1(iPol);
1297             const Handle(HLRAlgo_PolyInternalNode)* pi1p2 =
1298               &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(Pol1(iPol)));
1299             Nod12Indices = (*pi1p2)->Indices();
1300             Nod12RValues = (*pi1p2)->RValues();
1301 #ifdef DEB
1302             if (DoError) {
1303               if (Nod11NrmX*Nod12NrmX +
1304                   Nod11NrmY*Nod12NrmY +
1305                   Nod11NrmZ*Nod12NrmZ < 0) {
1306                 cout << " HLRBRep_PolyAlgo::InitBiPointsWithConnexity : ";
1307                 cout << "Too big angle between " << i1p1 << setw(6);
1308                 cout << " and " << i1p2 << setw(6);
1309                 cout << " in face " << i1 << endl;
1310               }
1311             }
1312 #endif
1313             X1   = X2;
1314             Y1   = Y2;
1315             Z1   = Z2;
1316             XTI1 = XTI2;
1317             YTI1 = YTI2;
1318             ZTI1 = ZTI2;
1319             U1   = U2;
1320             XTI2 = X2 = Nod12PntX;
1321             YTI2 = Y2 = Nod12PntY;
1322             ZTI2 = Z2 = Nod12PntZ;
1323             if      (Nod12Edg1 ==  (Standard_Boolean) e) U2 = Nod12PCu1;
1324             else if (Nod12Edg2 ==  (Standard_Boolean) e) U2 = Nod12PCu2;
1325 #ifdef DEB
1326             else {
1327               cout << " HLRBRep_PolyAlgo::InitBiPointsWithConnexity : ";
1328               cout << "Parameter error on Node " << i1p2 << endl;
1329             }
1330 #endif
1331             Nod12Flag |= NMskEdge;
1332             TIMultiply(XTI2,YTI2,ZTI2);
1333             Interpolation(List,
1334                           X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
1335                           XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1336                           e,U1,U2,
1337                           Nod11Indices,Nod11RValues,
1338                           Nod12Indices,Nod12RValues,
1339                           i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1);
1340           }
1341         }
1342       }
1343 #ifdef DEB
1344       else if (DoError) {
1345         cout << "HLRBRep_PolyAlgo::InitBiPointsWithConnexity : Edge ";
1346         cout << e << " connex 1 sans PolygonOnTriangulation" << endl;
1347       }
1348 #endif
1349     }
1350     else if (nbConnex == 2) {
1351       TopTools_ListIteratorOfListOfShape itn(LS);
1352       const TopoDS_Face& F1 = TopoDS::Face(itn.Value());
1353       i1      = myFMap.FindIndex(F1);
1354       const Handle(Poly_Triangulation)& Tr1 = BRep_Tool::Triangulation(F1,L);
1355       HPol[0] = BRep_Tool::PolygonOnTriangulation(E,Tr1,L);
1356       itn.Next();
1357       const TopoDS_Face& F2 = TopoDS::Face(itn.Value());
1358       i2      = myFMap.FindIndex(F2);
1359       if (i1 == i2) E.Reverse();
1360       const Handle(Poly_Triangulation)& Tr2 = BRep_Tool::Triangulation(F2,L);
1361       HPol[1] = BRep_Tool::PolygonOnTriangulation(E,Tr2,L);
1362       GeomAbs_Shape rg = BRep_Tool::Continuity(E,F1,F2);
1363       const Handle(HLRAlgo_PolyInternalData)& pid1 = 
1364         *(Handle(HLRAlgo_PolyInternalData)*)&(PID(i1));
1365       const Handle(HLRAlgo_PolyInternalData)& pid2 = 
1366         *(Handle(HLRAlgo_PolyInternalData)*)&(PID(i2));
1367       if (!HPol[0].IsNull() && !HPol[1].IsNull()) {
1368         myPC.Initialize(E,F1);
1369         const TColStd_Array1OfInteger&      Pol1 = HPol[0]->Nodes();
1370         const TColStd_Array1OfInteger&      Pol2 = HPol[1]->Nodes();
1371         const Handle(TColStd_HArray1OfReal)& par = HPol[0]->Parameters();
1372         Standard_Integer nbPol = Pol1.Upper();
1373         Standard_Address TData1 = &pid1->TData();
1374         Standard_Address PISeg1 = &pid1->PISeg();
1375         Standard_Address PINod1 = &pid1->PINod();
1376         Standard_Address TData2 = &pid2->TData();
1377         Standard_Address PISeg2 = &pid2->PISeg();
1378         Standard_Address PINod2 = &pid2->PINod();
1379         Standard_Address Nod11Indices,Nod11RValues;
1380         Standard_Address Nod12Indices,Nod12RValues;
1381         Standard_Address Nod21Indices,Nod21RValues;
1382         Standard_Address Nod22Indices,Nod22RValues;
1383         const Handle(HLRAlgo_PolyInternalNode)* pi1p1 =
1384           &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(Pol1(1    )));
1385         Nod11Indices = (*pi1p1)->Indices();
1386         Nod11RValues = (*pi1p1)->RValues();
1387         const Handle(HLRAlgo_PolyInternalNode)* pi1p2 =
1388           &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(Pol1(nbPol)));
1389         Nod12Indices = (*pi1p2)->Indices();
1390         Nod12RValues = (*pi1p2)->RValues();
1391         const Handle(HLRAlgo_PolyInternalNode)* pi2p1 =
1392           &(((HLRAlgo_Array1OfPINod*)PINod2)->ChangeValue(Pol2(1    )));
1393         Nod21Indices = (*pi2p1)->Indices();
1394         Nod21RValues = (*pi2p1)->RValues();
1395         const Handle(HLRAlgo_PolyInternalNode)* pi2p2 =
1396           &(((HLRAlgo_Array1OfPINod*)PINod2)->ChangeValue(Pol2(nbPol)));
1397         Nod22Indices = (*pi2p2)->Indices();
1398         Nod22RValues = (*pi2p2)->RValues();
1399         Nod11Flag |=  NMskVert;
1400         Nod12Flag |=  NMskVert;
1401         Nod21Flag |=  NMskVert;
1402         Nod22Flag |=  NMskVert;
1403         
1404         for (iPol = 1; iPol <= nbPol; iPol++) {
1405           const Handle(HLRAlgo_PolyInternalNode)* pi1pA =
1406             &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(Pol1(iPol)));
1407           Standard_Address Nod1AIndices = (*pi1pA)->Indices();
1408           Standard_Address Nod1ARValues = (*pi1pA)->RValues();
1409           const Handle(HLRAlgo_PolyInternalNode)* pi2pA =
1410             &(((HLRAlgo_Array1OfPINod*)PINod2)->ChangeValue(Pol2(iPol)));
1411           Standard_Address Nod2AIndices = (*pi2pA)->Indices();
1412           Standard_Address Nod2ARValues = (*pi2pA)->RValues();
1413           Standard_Real PCu = par->Value(iPol);
1414           if (Nod1AEdg1 == 0 || Nod1AEdg1 ==  (Standard_Boolean) e) {
1415             Nod1AEdg1 = e;
1416             Nod1APCu1 = PCu;
1417           }
1418           else {
1419             Nod1AEdg2 = e;
1420             Nod1APCu2 = PCu;
1421           }
1422           if (Nod2AEdg1 == 0 || Nod2AEdg1 == (Standard_Boolean) e) {
1423             Nod2AEdg1 = e;
1424             Nod2APCu1 = PCu;
1425           }
1426           else {
1427             Nod2AEdg2 = e;
1428             Nod2APCu2 = PCu;
1429           }
1430         }
1431
1432         i1p2 = Pol1(1);
1433         Nod12Indices = Nod11Indices;
1434         Nod12RValues = Nod11RValues;
1435         i2p2 = Pol2(1);
1436         Nod22Indices = Nod21Indices;
1437         Nod22RValues = Nod21RValues;
1438         XTI2 = X2 = Nod12PntX;
1439         YTI2 = Y2 = Nod12PntY;
1440         ZTI2 = Z2 = Nod12PntZ;
1441         if      (Nod12Edg1 == (Standard_Boolean) e) U2 = Nod12PCu1;
1442         else if (Nod12Edg2 == (Standard_Boolean) e) U2 = Nod12PCu2;
1443 #ifdef DEB
1444         else {
1445           cout << " HLRBRep_PolyAlgo::InitBiPointsWithConnexity : ";
1446           cout << "Parameter error on Node " << i1p2 << endl;
1447         }
1448 #endif
1449         Nod12Flag |= NMskEdge;
1450         Nod22Flag |= NMskEdge;
1451         TIMultiply(XTI2,YTI2,ZTI2);
1452         if (Pol1(1) == Pol1(nbPol) && myPC.IsPeriodic())
1453           U2 = U2 - myPC.Period();
1454         
1455         if (nbPol == 2 && BRep_Tool::Degenerated(E)) {
1456           CheckDegeneratedSegment(Nod11Indices,Nod11RValues,
1457                                   Nod12Indices,Nod12RValues);
1458           CheckDegeneratedSegment(Nod21Indices,Nod21RValues,
1459                                   Nod22Indices,Nod22RValues);
1460           UpdateAroundNode(Pol1(1    ),Nod11Indices,TData1,PISeg1,PINod1);
1461           UpdateAroundNode(Pol1(nbPol),Nod12Indices,TData1,PISeg1,PINod1);
1462           UpdateAroundNode(Pol2(1    ),Nod21Indices,TData2,PISeg2,PINod2);
1463           UpdateAroundNode(Pol2(nbPol),Nod22Indices,TData2,PISeg2,PINod2);
1464         }
1465         else {
1466
1467           for (iPol = 2; iPol <= nbPol; iPol++) {
1468             i1p1 = i1p2;
1469             Nod11Indices = Nod12Indices;
1470             Nod11RValues = Nod12RValues;
1471             i2p1 = i2p2;
1472             Nod21Indices = Nod22Indices;
1473             Nod21RValues = Nod22RValues;
1474             i1p2 = Pol1(iPol);
1475             const Handle(HLRAlgo_PolyInternalNode)* pi1p2 =
1476               &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(Pol1(iPol)));
1477             Nod12Indices = (*pi1p2)->Indices();
1478             Nod12RValues = (*pi1p2)->RValues();
1479             i2p2 = Pol2(iPol);
1480             const Handle(HLRAlgo_PolyInternalNode)* pi2p2 =
1481               &(((HLRAlgo_Array1OfPINod*)PINod2)->ChangeValue(Pol2(iPol)));
1482             Nod22Indices = (*pi2p2)->Indices();
1483             Nod22RValues = (*pi2p2)->RValues();
1484 #ifdef DEB
1485             if (DoError) {
1486               if (Nod11NrmX*Nod12NrmX +
1487                   Nod11NrmY*Nod12NrmY +
1488                   Nod11NrmZ*Nod12NrmZ < 0) {
1489                 cout << " HLRBRep_PolyAlgo::InitBiPointsWithConnexity : ";
1490                 cout << "To big angle between " << i1p1 << setw(6);
1491                 cout << " and " << i1p2 << setw(6);
1492                 cout << " in face " << i1 << endl;
1493               }
1494               if (Nod21NrmX*Nod22NrmX +
1495                   Nod21NrmY*Nod22NrmY +
1496                   Nod21NrmZ*Nod22NrmZ < 0) {
1497                 cout << " HLRBRep_PolyAlgo::InitBiPointsWithConnexity : ";
1498                 cout << "To big angle between " << i2p1 << setw(6);
1499                 cout << " and " << i2p2 << setw(6);
1500                 cout<< " in face " << i2 << endl;
1501               }
1502             }
1503 #endif
1504             X1   = X2;
1505             Y1   = Y2;
1506             Z1   = Z2;
1507             XTI1 = XTI2;
1508             YTI1 = YTI2;
1509             ZTI1 = ZTI2;
1510             U1   = U2;
1511             XTI2 = X2 = Nod12PntX;
1512             YTI2 = Y2 = Nod12PntY;
1513             ZTI2 = Z2 = Nod12PntZ;
1514             if      (Nod12Edg1 == (Standard_Boolean) e) U2 = Nod12PCu1;
1515             else if (Nod12Edg2 == (Standard_Boolean) e) U2 = Nod12PCu2;
1516 #ifdef DEB
1517             else {
1518               cout << " HLRBRep_PolyAlgo::InitBiPointsWithConnexity : ";
1519               cout << "Parameter error on Node " << i1p2 << endl;
1520             }
1521 #endif
1522             Nod12Flag |= NMskEdge;
1523             Nod22Flag |= NMskEdge;
1524             TIMultiply(XTI2,YTI2,ZTI2);
1525             Interpolation(List,
1526                           X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
1527                           XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1528                           e,U1,U2,rg,
1529                           Nod11Indices,Nod11RValues,
1530                           Nod12Indices,Nod12RValues,
1531                           i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1,
1532                           Nod21Indices,Nod21RValues,
1533                           Nod22Indices,Nod22RValues,
1534                           i2p1,i2p2,i2,pid2,TData2,PISeg2,PINod2);
1535           }
1536         }
1537       }
1538 #ifdef DEB
1539       else if (DoError) {
1540         cout << "HLRBRep_PolyAlgo::InitBiPointsWithConnexity : Edge ";
1541         cout << e << " connect 2 without PolygonOnTriangulation" << endl;
1542       }
1543 #endif
1544     }
1545   }
1546   else {  // no connexity
1547     const Handle(Poly_Polygon3D)& Polyg = BRep_Tool::Polygon3D(E,L);
1548     if (!Polyg.IsNull()) {
1549       const TColgp_Array1OfPnt& Pol = Polyg->Nodes();
1550       gp_Trsf TT       = L.Transformation();
1551       const gp_Trsf& T = myProj.Transformation();
1552       TT.PreMultiply(T);
1553       const gp_XYZ& ttlo = TT.TranslationPart();
1554       TTLo[0] = ttlo.X();
1555       TTLo[1] = ttlo.Y();
1556       TTLo[2] = ttlo.Z();
1557       const gp_Mat& ttma = TT.VectorialPart();
1558       TTMa[0][0] = ttma.Value(1,1);
1559       TTMa[0][1] = ttma.Value(1,2);
1560       TTMa[0][2] = ttma.Value(1,3);
1561       TTMa[1][0] = ttma.Value(2,1);
1562       TTMa[1][1] = ttma.Value(2,2);
1563       TTMa[1][2] = ttma.Value(2,3);
1564       TTMa[2][0] = ttma.Value(3,1);
1565       TTMa[2][1] = ttma.Value(3,2);
1566       TTMa[2][2] = ttma.Value(3,3);
1567       Standard_Integer nbPol = Pol.Upper();
1568       const gp_XYZ& P1 = Pol(1).XYZ();
1569       X2 = P1.X();
1570       Y2 = P1.Y();
1571       Z2 = P1.Z();
1572       TTMultiply(X2,Y2,Z2);
1573       XTI2 = X2;
1574       YTI2 = Y2;
1575       ZTI2 = Z2;
1576       TIMultiply(XTI2,YTI2,ZTI2);
1577       
1578       for (Standard_Integer iPol = 2; iPol <= nbPol; iPol++) {
1579         X1   = X2;
1580         Y1   = Y2;
1581         Z1   = Z2;
1582         XTI1 = XTI2;
1583         YTI1 = YTI2;
1584         ZTI1 = ZTI2;
1585         const gp_XYZ& P2 = Pol(iPol).XYZ();
1586         X2 = P2.X();
1587         Y2 = P2.Y();
1588         Z2 = P2.Z();
1589         TTMultiply(X2,Y2,Z2);
1590         XTI2 = X2;
1591         YTI2 = Y2;
1592         ZTI2 = Z2;
1593         TIMultiply(XTI2,YTI2,ZTI2);
1594         List.Prepend(HLRAlgo_BiPoint
1595                      (XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1596                       X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,   e,
1597                       0));
1598       }
1599     }
1600 #ifdef DEB
1601     else if (DoError) {
1602       cout << "HLRBRep_PolyAlgo::InitBiPointsWithConnexity : Edge ";
1603       cout << e << " Isolated, without Polygone 3D" << endl;
1604     }
1605 #endif
1606   }
1607 }
1608
1609 //=======================================================================
1610 //function : Interpolation
1611 //purpose  : 
1612 //=======================================================================
1613
1614 void
1615 HLRBRep_PolyAlgo::
1616 Interpolation (HLRAlgo_ListOfBPoint& List,
1617                Standard_Real& X1,
1618                Standard_Real& Y1,
1619                Standard_Real& Z1,
1620                Standard_Real& X2,
1621                Standard_Real& Y2,
1622                Standard_Real& Z2,
1623                Standard_Real& XTI1,
1624                Standard_Real& YTI1,
1625                Standard_Real& ZTI1,
1626                Standard_Real& XTI2,
1627                Standard_Real& YTI2,
1628                Standard_Real& ZTI2,
1629                const Standard_Integer e,
1630                Standard_Real& U1,
1631                Standard_Real& U2,
1632                Standard_Address& Nod11Indices,
1633                Standard_Address& Nod11RValues,
1634                Standard_Address& Nod12Indices,
1635                Standard_Address& Nod12RValues,
1636                const Standard_Integer i1p1,
1637                const Standard_Integer i1p2,
1638                const Standard_Integer i1,
1639                const Handle(HLRAlgo_PolyInternalData)& pid1,
1640                Standard_Address& TData1,
1641                Standard_Address& PISeg1,
1642                Standard_Address& PINod1) const
1643 {
1644   Standard_Boolean insP3,mP3P1;
1645   Standard_Real X3,Y3,Z3,XTI3,YTI3,ZTI3,coef3,U3;
1646 //  gp_Pnt P3,PT3;
1647   insP3 = Interpolation(U1,U2,Nod11RValues,Nod12RValues,
1648                         X3,Y3,Z3,XTI3,YTI3,ZTI3,coef3,U3,mP3P1);
1649   MoveOrInsertPoint(List,
1650                     X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
1651                     XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1652                     e,U1,U2,
1653                     Nod11Indices,Nod11RValues,
1654                     Nod12Indices,Nod12RValues,
1655                     i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1,
1656                     X3,Y3,Z3,XTI3,YTI3,ZTI3,coef3,U3,insP3,mP3P1,0);
1657 }
1658
1659 //=======================================================================
1660 //function : Interpolation
1661 //purpose  : 
1662 //=======================================================================
1663
1664 void
1665 HLRBRep_PolyAlgo::
1666 Interpolation (HLRAlgo_ListOfBPoint& List,
1667                Standard_Real& X1,
1668                Standard_Real& Y1,
1669                Standard_Real& Z1,
1670                Standard_Real& X2,
1671                Standard_Real& Y2,
1672                Standard_Real& Z2,
1673                Standard_Real& XTI1,
1674                Standard_Real& YTI1,
1675                Standard_Real& ZTI1,
1676                Standard_Real& XTI2,
1677                Standard_Real& YTI2,
1678                Standard_Real& ZTI2,
1679                const Standard_Integer e,
1680                Standard_Real& U1,
1681                Standard_Real& U2,
1682                const GeomAbs_Shape rg,
1683                Standard_Address& Nod11Indices,
1684                Standard_Address& Nod11RValues,
1685                Standard_Address& Nod12Indices,
1686                Standard_Address& Nod12RValues,
1687                const Standard_Integer i1p1,
1688                const Standard_Integer i1p2,
1689                const Standard_Integer i1,
1690                const Handle(HLRAlgo_PolyInternalData)& pid1,
1691                Standard_Address& TData1,
1692                Standard_Address& PISeg1,
1693                Standard_Address& PINod1,
1694                Standard_Address& Nod21Indices,
1695                Standard_Address& Nod21RValues,
1696                Standard_Address& Nod22Indices,
1697                Standard_Address& Nod22RValues,
1698                const Standard_Integer i2p1,
1699                const Standard_Integer i2p2,
1700                const Standard_Integer i2,
1701                const Handle(HLRAlgo_PolyInternalData)& pid2,
1702                Standard_Address& TData2,
1703                Standard_Address& PISeg2,
1704                Standard_Address& PINod2) const
1705 {
1706   Standard_Boolean insP3,mP3P1,insP4,mP4P1;
1707   Standard_Real X3,Y3,Z3,XTI3,YTI3,ZTI3,coef3,U3;
1708   Standard_Real X4,Y4,Z4,XTI4,YTI4,ZTI4,coef4,U4;
1709 //  gp_Pnt P3,PT3,P4,PT4;
1710   Standard_Boolean flag = 0;
1711   if (rg >= GeomAbs_G1) flag += 1;
1712   if (rg >= GeomAbs_G2) flag += 2;
1713   insP3 = Interpolation(U1,U2,Nod11RValues,Nod12RValues,
1714                         X3,Y3,Z3,XTI3,YTI3,ZTI3,coef3,U3,mP3P1);
1715   insP4 = Interpolation(U1,U2,Nod21RValues,Nod22RValues,
1716                         X4,Y4,Z4,XTI4,YTI4,ZTI4,coef4,U4,mP4P1);
1717   Standard_Boolean OK = insP3 || insP4;
1718   if (OK) {
1719     if      (!insP4)                               // p1 i1p3 p2
1720       MoveOrInsertPoint(List,
1721                         X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
1722                         XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1723                         e,U1,U2,
1724                         Nod11Indices,Nod11RValues,
1725                         Nod12Indices,Nod12RValues,
1726                         i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1,
1727                         Nod21Indices,Nod21RValues,
1728                         Nod22Indices,Nod22RValues,
1729                         i2p1,i2p2,i2,pid2,TData2,PISeg2,PINod2,
1730                         X3,Y3,Z3,XTI3,YTI3,ZTI3,coef3,U3,insP3,mP3P1,flag);
1731     else if (!insP3)                               // p1 i2p4 p2
1732       MoveOrInsertPoint(List,
1733                         X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
1734                         XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1735                         e,U1,U2,
1736                         Nod21Indices,Nod21RValues,
1737                         Nod22Indices,Nod22RValues,
1738                         i2p1,i2p2,i2,pid2,TData2,PISeg2,PINod2,
1739                         Nod11Indices,Nod11RValues,
1740                         Nod12Indices,Nod12RValues,
1741                         i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1,
1742                         X4,Y4,Z4,XTI4,YTI4,ZTI4,coef4,U4,insP4,mP4P1,flag);
1743     else if (Abs(coef4 - coef3) < myTolSta)       // p1 i1p3-i2p4 p2
1744       MoveOrInsertPoint(List,
1745                         X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
1746                         XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1747                         e,U1,U2,
1748                         Nod21Indices,Nod21RValues,
1749                         Nod22Indices,Nod22RValues,
1750                         i2p1,i2p2,i2,pid2,TData2,PISeg2,PINod2,
1751                         Nod11Indices,Nod11RValues,
1752                         Nod12Indices,Nod12RValues,
1753                         i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1,
1754                         X4,Y4,Z4,XTI4,YTI4,ZTI4,coef4,U4,insP4,mP4P1,flag);
1755     else if (coef4 < coef3)                        // p1 i2p4 i1p3 p2
1756       MoveOrInsertPoint(List,
1757                         X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
1758                         XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1759                         e,U1,U2,
1760                         Nod21Indices,Nod21RValues,
1761                         Nod22Indices,Nod22RValues,
1762                         i2p1,i2p2,i2,pid2,TData2,PISeg2,PINod2,
1763                         Nod11Indices,Nod11RValues,
1764                         Nod12Indices,Nod12RValues,
1765                         i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1,
1766                         X4,Y4,Z4,XTI4,YTI4,ZTI4,coef4,U4,insP4,mP4P1,
1767                         X3,Y3,Z3,XTI3,YTI3,ZTI3,coef3,U3,insP3,mP3P1,flag);
1768     else                                           // p1 i1p3 i2p4 p2
1769       MoveOrInsertPoint(List,
1770                         X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
1771                         XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1772                         e,U1,U2,
1773                         Nod11Indices,Nod11RValues,
1774                         Nod12Indices,Nod12RValues,
1775                         i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1,
1776                         Nod21Indices,Nod21RValues,
1777                         Nod22Indices,Nod22RValues,
1778                         i2p1,i2p2,i2,pid2,TData2,PISeg2,PINod2,
1779                         X3,Y3,Z3,XTI3,YTI3,ZTI3,coef3,U3,insP3,mP3P1,
1780                         X4,Y4,Z4,XTI4,YTI4,ZTI4,coef4,U4,insP4,mP4P1,flag);
1781   }
1782   else                                             // p1 p2
1783     List.Prepend(HLRAlgo_BiPoint
1784                  (XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1785                   X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,   e,
1786                   i1  ,i1p1,i1p2,i2  ,i2p1,i2p2,flag));
1787 }
1788
1789 //=======================================================================
1790 //function : Interpolation
1791 //purpose  : 
1792 //=======================================================================
1793
1794 Standard_Boolean
1795 HLRBRep_PolyAlgo::
1796 Interpolation (const Standard_Real U1,
1797                const Standard_Real U2,
1798                const Standard_Address Nod1RValues,
1799                const Standard_Address Nod2RValues,
1800                Standard_Real& X3,
1801                Standard_Real& Y3,
1802                Standard_Real& Z3,
1803                Standard_Real& XTI3,
1804                Standard_Real& YTI3,
1805                Standard_Real& ZTI3,
1806                Standard_Real& coef3,
1807                Standard_Real& U3,
1808                Standard_Boolean& mP3P1) const
1809 {
1810   if (NewNode(Nod1RValues,Nod2RValues,coef3,mP3P1)) {
1811     U3 = U1 + (U2 - U1) * coef3;
1812     const gp_Pnt& P3 = myBCurv.Value(U3);
1813     XTI3 = X3 = P3.X();
1814     YTI3 = Y3 = P3.Y();
1815     ZTI3 = Z3 = P3.Z();
1816     TMultiply(X3,Y3,Z3);
1817     return Standard_True;
1818   }
1819   return Standard_False;
1820 }
1821
1822 //=======================================================================
1823 //function : MoveOrInsertPoint
1824 //purpose  : 
1825 //=======================================================================
1826
1827 void
1828 HLRBRep_PolyAlgo::
1829 MoveOrInsertPoint (HLRAlgo_ListOfBPoint& List,
1830                    Standard_Real& X1,
1831                    Standard_Real& Y1,
1832                    Standard_Real& Z1,
1833                    Standard_Real& X2,
1834                    Standard_Real& Y2,
1835                    Standard_Real& Z2,
1836                    Standard_Real& XTI1,
1837                    Standard_Real& YTI1,
1838                    Standard_Real& ZTI1,
1839                    Standard_Real& XTI2,
1840                    Standard_Real& YTI2,
1841                    Standard_Real& ZTI2,
1842                    const Standard_Integer e,
1843                    Standard_Real& U1,
1844                    Standard_Real& U2,
1845                    Standard_Address& Nod11Indices,
1846                    Standard_Address& Nod11RValues,
1847                    Standard_Address& Nod12Indices,
1848                    Standard_Address& Nod12RValues,
1849                    const Standard_Integer i1p1,
1850                    const Standard_Integer i1p2,
1851                    const Standard_Integer i1,
1852                    const Handle(HLRAlgo_PolyInternalData)& pid1,
1853                    Standard_Address& TData1,
1854                    Standard_Address& PISeg1,
1855                    Standard_Address& PINod1,
1856                    const Standard_Real X3,
1857                    const Standard_Real Y3,
1858                    const Standard_Real Z3,
1859                    const Standard_Real XTI3,
1860                    const Standard_Real YTI3,
1861                    const Standard_Real ZTI3,
1862                    const Standard_Real coef3,
1863                    const Standard_Real U3,
1864                    const Standard_Boolean insP3,
1865                    const Standard_Boolean mP3P1,
1866                    const Standard_Boolean flag) const
1867 {
1868   Standard_Address TData2 = 0;
1869   Standard_Address PISeg2 = 0;
1870   Standard_Address PINod2 = 0;
1871   Standard_Boolean ins3 = insP3;
1872   if (ins3 && mP3P1) {                             // P1 ---> P3
1873     if (!(Nod11Flag & NMskVert) && coef3 < myTolSta) {
1874       ins3 = Standard_False;
1875       ChangeNode(i1p1,i1p2,
1876                  Nod11Indices,Nod11RValues,
1877                  Nod12Indices,Nod12RValues,
1878                  coef3,X3,Y3,Z3,Standard_True,
1879                  TData1,PISeg1,PINod1);
1880       X1   = X3;
1881       Y1   = Y3;
1882       Z1   = Z3;
1883       XTI1 = XTI3;
1884       YTI1 = YTI3;
1885       ZTI1 = ZTI3;
1886       U1   = U3;
1887       Nod11PntX = X3;
1888       Nod11PntY = Y3;
1889       Nod11PntZ = Z3;
1890       if      (Nod11Edg1 == (Standard_Boolean) e) Nod11PCu1 = U3;
1891       else if (Nod11Edg2 == (Standard_Boolean) e) Nod11PCu2 = U3;
1892 #ifdef DEB
1893       else {
1894         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
1895         cout << "Parameter error on Node " << i1p1 << endl;
1896       }
1897 #endif
1898       Nod11Scal  = 0;
1899       Nod11Flag |= NMskOutL;
1900       UpdateAroundNode(i1p1,Nod11Indices,TData1,PISeg1,PINod1);
1901       Standard_Address Coordinates = List.First().Coordinates();
1902       PntX2   = X3;
1903       PntY2   = Y3;
1904       PntZ2   = Z3;
1905       PntXTI2 = XTI3;
1906       PntYTI2 = YTI3;
1907       PntZTI2 = ZTI3;
1908     }
1909   }
1910   if (ins3 && !mP3P1) {                            // P2 ---> P3
1911     if (!(Nod12Flag & NMskVert) && coef3 > myTolEnd) {
1912       ins3 = Standard_False;
1913       ChangeNode(i1p1,i1p2,
1914                  Nod11Indices,Nod11RValues,
1915                  Nod12Indices,Nod12RValues,
1916                  coef3,X3,Y3,Z3,Standard_False,
1917                  TData1,PISeg1,PINod1);
1918       X2   = X3;
1919       Y2   = Y3;
1920       Z2   = Z3;
1921       XTI2 = XTI3;
1922       YTI2 = YTI3;
1923       ZTI2 = ZTI3;
1924       U2   = U3;
1925       Nod12PntX = X3;
1926       Nod12PntY = Y3;
1927       Nod12PntZ = Z3;
1928       if      (Nod12Edg1 == (Standard_Boolean) e) Nod12PCu1 = U3;
1929       else if (Nod12Edg2 == (Standard_Boolean) e) Nod12PCu2 = U3;
1930 #ifdef DEB
1931       else {
1932         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
1933         cout << "Parameter error on Node " << i1p2 << endl;
1934       }
1935 #endif
1936       Nod12Scal  = 0;
1937       Nod12Flag |= NMskOutL;
1938       UpdateAroundNode(i1p2,Nod12Indices,TData1,PISeg1,PINod1);
1939     }
1940   }
1941   if (ins3) {                                      // p1 i1p3 p2
1942     Standard_Integer i1p3 = pid1->AddNode
1943       (Nod11RValues,Nod12RValues,PINod1,PINod2,coef3,X3,Y3,Z3);
1944     const Handle(HLRAlgo_PolyInternalNode)* pi1p3 =
1945       &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(i1p3));
1946     const Standard_Address Nod13Indices = (*pi1p3)->Indices();
1947     const Standard_Address Nod13RValues = (*pi1p3)->RValues();
1948     Nod13Edg1  = e;
1949     Nod13PCu1  = U3;
1950     Nod13Scal  = 0;
1951     Nod13Flag |= NMskOutL;
1952     Nod13Flag |= NMskEdge;
1953     pid1->UpdateLinks(i1p1,i1p2,i1p3,
1954                       TData1,TData2,PISeg1,PISeg2,PINod1,PINod2);
1955     UpdateAroundNode(i1p3,Nod13Indices,TData1,PISeg1,PINod1);
1956     List.Prepend(HLRAlgo_BiPoint
1957                  (XTI1,YTI1,ZTI1,XTI3,YTI3,ZTI3,
1958                   X1  ,Y1  ,Z1  ,X3  ,Y3  ,Z3  ,   e,
1959                   i1  ,i1p1,i1p3,flag));
1960     List.Prepend(HLRAlgo_BiPoint
1961                  (XTI3,YTI3,ZTI3,XTI2,YTI2,ZTI2,
1962                   X3  ,Y3  ,Z3  ,X2  ,Y2  ,Z2  ,   e,
1963                   i1  ,i1p3,i1p2,flag));
1964   }
1965   else                                             // p1 p2
1966     List.Prepend(HLRAlgo_BiPoint
1967                  (XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
1968                   X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,   e,
1969                   i1  ,i1p1,i1p2,flag));
1970 }
1971
1972 //=======================================================================
1973 //function : MoveOrInsertPoint
1974 //purpose  : 
1975 //=======================================================================
1976
1977 void
1978 HLRBRep_PolyAlgo::
1979 MoveOrInsertPoint (HLRAlgo_ListOfBPoint& List,
1980                    Standard_Real& X1,
1981                    Standard_Real& Y1,
1982                    Standard_Real& Z1,
1983                    Standard_Real& X2,
1984                    Standard_Real& Y2,
1985                    Standard_Real& Z2,
1986                    Standard_Real& XTI1,
1987                    Standard_Real& YTI1,
1988                    Standard_Real& ZTI1,
1989                    Standard_Real& XTI2,
1990                    Standard_Real& YTI2,
1991                    Standard_Real& ZTI2,
1992                    const Standard_Integer e,
1993                    Standard_Real& U1,
1994                    Standard_Real& U2,
1995                    Standard_Address& Nod11Indices,
1996                    Standard_Address& Nod11RValues,
1997                    Standard_Address& Nod12Indices,
1998                    Standard_Address& Nod12RValues,
1999                    const Standard_Integer i1p1,
2000                    const Standard_Integer i1p2,
2001                    const Standard_Integer i1,
2002                    const Handle(HLRAlgo_PolyInternalData)& pid1,
2003                    Standard_Address& TData1,
2004                    Standard_Address& PISeg1,
2005                    Standard_Address& PINod1,
2006                    Standard_Address& Nod21Indices,
2007                    Standard_Address& Nod21RValues,
2008                    Standard_Address& Nod22Indices,
2009                    Standard_Address& Nod22RValues,
2010                    const Standard_Integer i2p1,
2011                    const Standard_Integer i2p2,
2012                    const Standard_Integer i2,
2013                    const Handle(HLRAlgo_PolyInternalData)& pid2,
2014                    Standard_Address& TData2,
2015                    Standard_Address& PISeg2,
2016                    Standard_Address& PINod2,
2017                    const Standard_Real X3,
2018                    const Standard_Real Y3,
2019                    const Standard_Real Z3,
2020                    const Standard_Real XTI3,
2021                    const Standard_Real YTI3,
2022                    const Standard_Real ZTI3,
2023                    const Standard_Real coef3,
2024                    const Standard_Real U3,
2025                    const Standard_Boolean insP3,
2026                    const Standard_Boolean mP3P1,
2027                    const Standard_Boolean flag) const
2028 {
2029   Standard_Boolean ins3 = insP3;
2030   if (ins3 && mP3P1) {                             // P1 ---> P3
2031     if (!(Nod11Flag & NMskVert) && coef3 < myTolSta) {
2032       ins3 = Standard_False;
2033       ChangeNode(i1p1,i1p2,
2034                  Nod11Indices,Nod11RValues,
2035                  Nod12Indices,Nod12RValues,
2036                  coef3,X3,Y3,Z3,Standard_True,
2037                  TData1,PISeg1,PINod1);
2038       ChangeNode(i2p1,i2p2,
2039                  Nod21Indices,Nod21RValues,
2040                  Nod22Indices,Nod22RValues,
2041                  coef3,X3,Y3,Z3,Standard_True,
2042                  TData2,PISeg2,PINod2);
2043       X1   = X3;
2044       Y1   = Y3;
2045       Z1   = Z3;
2046       XTI1 = XTI3;
2047       YTI1 = YTI3;
2048       ZTI1 = ZTI3;
2049       U1   = U3;
2050       Nod11PntX = X3;
2051       Nod11PntY = Y3;
2052       Nod11PntZ = Z3;
2053       if      (Nod11Edg1 == (Standard_Boolean) e) Nod11PCu1 = U3;
2054       else if (Nod11Edg2 == (Standard_Boolean) e) Nod11PCu2 = U3;
2055 #ifdef DEB
2056       else {
2057         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
2058         cout << "Parameter error on Node " << i1p1 << endl;
2059       }
2060 #endif
2061       Nod11Scal  = 0;
2062       Nod11Flag |= NMskOutL;
2063       UpdateAroundNode(i1p1,Nod11Indices,TData1,PISeg1,PINod1);
2064       Nod21PntX  = X3;
2065       Nod21PntY  = Y3;
2066       Nod21PntZ  = Z3;
2067       if      (Nod21Edg1 == (Standard_Boolean) e) Nod21PCu1 = U3;
2068       else if (Nod21Edg2 == (Standard_Boolean) e) Nod21PCu2 = U3;
2069 #ifdef DEB
2070       else {
2071         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
2072         cout << "Parameter error on Node " << i2p1 << endl;
2073       }
2074 #endif
2075       Nod21Scal  = 0;
2076       Nod21Flag |= NMskOutL;
2077       UpdateAroundNode(i2p1,Nod21Indices,TData2,PISeg2,PINod2);
2078       Standard_Address Coordinates = List.First().Coordinates();
2079       PntX2   = X3;
2080       PntY2   = Y3;
2081       PntZ2   = Z3;
2082       PntXTI2 = XTI3;
2083       PntYTI2 = YTI3;
2084       PntZTI2 = ZTI3;
2085     }
2086   }
2087   if (ins3 && !mP3P1) {                            // P2 ---> P3
2088     if (!(Nod12Flag & NMskVert) && coef3 > myTolEnd) {
2089       ins3 = Standard_False;
2090       ChangeNode(i1p1,i1p2,
2091                  Nod11Indices,Nod11RValues,
2092                  Nod12Indices,Nod12RValues,
2093                  coef3,X3,Y3,Z3,Standard_False,
2094                  TData1,PISeg1,PINod1);
2095       ChangeNode(i2p1,i2p2,
2096                  Nod21Indices,Nod21RValues,
2097                  Nod22Indices,Nod22RValues,
2098                  coef3,X3,Y3,Z3,Standard_False,
2099                  TData2,PISeg2,PINod2);
2100       X2   = X3;
2101       Y2   = Y3;
2102       Z2   = Z3;
2103       XTI2 = XTI3;
2104       YTI2 = YTI3;
2105       ZTI2 = ZTI3;
2106       U2   = U3;
2107       Nod12PntX = X3;
2108       Nod12PntY = Y3;
2109       Nod12PntZ = Z3;
2110       if      (Nod12Edg1 == (Standard_Boolean) e) Nod12PCu1 = U3;
2111       else if (Nod12Edg2 == (Standard_Boolean) e) Nod12PCu2 = U3;
2112 #ifdef DEB
2113       else {
2114         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
2115         cout << "Parameter error on Node " << i1p2 << endl;
2116       }
2117 #endif
2118       Nod12Scal  = 0;
2119       Nod12Flag |= NMskOutL;
2120       UpdateAroundNode(i1p2,Nod12Indices,TData1,PISeg1,PINod1);
2121       Nod22PntX  = X3;
2122       Nod22PntY  = Y3;
2123       Nod22PntZ  = Z3;
2124       if      (Nod22Edg1 == (Standard_Boolean) e) Nod22PCu1 = U3;
2125       else if (Nod22Edg2 == (Standard_Boolean) e) Nod22PCu2 = U3;
2126 #ifdef DEB
2127       else {
2128         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
2129         cout << "Parameter error on Node " << i2p2 << endl;
2130       }
2131 #endif
2132       Nod22Scal = 0;
2133       Nod22Flag |=  NMskOutL;
2134       UpdateAroundNode(i2p2,Nod22Indices,TData2,PISeg2,PINod2);
2135     }
2136   }
2137   if (ins3) {                                      // p1 i1p3 p2
2138     Standard_Integer i1p3 = pid1->AddNode
2139       (Nod11RValues,Nod12RValues,PINod1,PINod2,coef3,X3,Y3,Z3);
2140     Standard_Integer i2p3 = pid2->AddNode
2141       (Nod21RValues,Nod22RValues,PINod2,PINod1,coef3,X3,Y3,Z3); 
2142     const Handle(HLRAlgo_PolyInternalNode)* pi1p3 =
2143       &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(i1p3));
2144     const Standard_Address Nod13Indices = (*pi1p3)->Indices();
2145     const Standard_Address Nod13RValues = (*pi1p3)->RValues();
2146     const Handle(HLRAlgo_PolyInternalNode)* pi2p3 =
2147       &(((HLRAlgo_Array1OfPINod*)PINod2)->ChangeValue(i2p3));
2148     const Standard_Address Nod23Indices = (*pi2p3)->Indices();
2149     const Standard_Address Nod23RValues = (*pi2p3)->RValues();
2150     Nod13Edg1  = e;
2151     Nod13PCu1  = U3;
2152     Nod13Scal  = 0;
2153     Nod13Flag |= NMskOutL;
2154     Nod13Flag |= NMskEdge;
2155     Nod23Edg1  = e;
2156     Nod23PCu1  = U3;
2157     Nod23Scal  = 0;
2158     Nod23Flag |= NMskOutL;
2159     Nod23Flag |= NMskEdge;
2160     pid1->UpdateLinks(i1p1,i1p2,i1p3,
2161                       TData1,TData2,PISeg1,PISeg2,PINod1,PINod2);
2162     pid2->UpdateLinks(i2p1,i2p2,i2p3,
2163                       TData2,TData1,PISeg2,PISeg1,PINod2,PINod1);
2164     UpdateAroundNode(i1p3,Nod13Indices,TData1,PISeg1,PINod1);
2165     UpdateAroundNode(i2p3,Nod23Indices,TData2,PISeg2,PINod2);
2166     List.Prepend(HLRAlgo_BiPoint
2167                  (XTI1,YTI1,ZTI1,XTI3,YTI3,ZTI3,
2168                   X1  ,Y1  ,Z1  ,X3  ,Y3  ,Z3  ,   e,
2169                   i1  ,i1p1,i1p3,i2  ,i2p1,i2p3,flag));
2170     List.Prepend(HLRAlgo_BiPoint
2171                  (XTI3,YTI3,ZTI3,XTI2,YTI2,ZTI2,
2172                   X3  ,Y3  ,Z3  ,X2  ,Y2  ,Z2  ,   e,
2173                   i1  ,i1p3,i1p2,i2  ,i2p3,i2p2,flag));
2174   }
2175   else                                             // p1 p2
2176     List.Prepend(HLRAlgo_BiPoint
2177                  (XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
2178                   X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,   e,
2179                   i1  ,i1p1,i1p2,i2  ,i2p1,i2p2,flag));
2180 }
2181
2182 //=======================================================================
2183 //function : MoveOrInsertPoint
2184 //purpose  : 
2185 //=======================================================================
2186
2187 void
2188 HLRBRep_PolyAlgo::
2189 MoveOrInsertPoint (HLRAlgo_ListOfBPoint& List,
2190                    Standard_Real& X1,
2191                    Standard_Real& Y1,
2192                    Standard_Real& Z1,
2193                    Standard_Real& X2,
2194                    Standard_Real& Y2,
2195                    Standard_Real& Z2,
2196                    Standard_Real& XTI1,
2197                    Standard_Real& YTI1,
2198                    Standard_Real& ZTI1,
2199                    Standard_Real& XTI2,
2200                    Standard_Real& YTI2,
2201                    Standard_Real& ZTI2,
2202                    const Standard_Integer e,
2203                    Standard_Real& U1,
2204                    Standard_Real& U2,
2205                    Standard_Address& Nod11Indices,
2206                    Standard_Address& Nod11RValues,
2207                    Standard_Address& Nod12Indices,
2208                    Standard_Address& Nod12RValues,
2209                    const Standard_Integer i1p1,
2210                    const Standard_Integer i1p2,
2211                    const Standard_Integer i1,
2212                    const Handle(HLRAlgo_PolyInternalData)& pid1,
2213                    Standard_Address& TData1,
2214                    Standard_Address& PISeg1,
2215                    Standard_Address& PINod1,
2216                    Standard_Address& Nod21Indices,
2217                    Standard_Address& Nod21RValues,
2218                    Standard_Address& Nod22Indices,
2219                    Standard_Address& Nod22RValues,
2220                    const Standard_Integer i2p1,
2221                    const Standard_Integer i2p2,
2222                    const Standard_Integer i2,
2223                    const Handle(HLRAlgo_PolyInternalData)& pid2,
2224                    Standard_Address& TData2,
2225                    Standard_Address& PISeg2,
2226                    Standard_Address& PINod2,
2227                    const Standard_Real X3,
2228                    const Standard_Real Y3,
2229                    const Standard_Real Z3,
2230                    const Standard_Real XTI3,
2231                    const Standard_Real YTI3,
2232                    const Standard_Real ZTI3,
2233                    const Standard_Real coef3,
2234                    const Standard_Real U3,
2235                    const Standard_Boolean insP3,
2236                    const Standard_Boolean mP3P1,
2237                    const Standard_Real X4,
2238                    const Standard_Real Y4,
2239                    const Standard_Real Z4,
2240                    const Standard_Real XTI4,
2241                    const Standard_Real YTI4,
2242                    const Standard_Real ZTI4,
2243                    const Standard_Real coef4,
2244                    const Standard_Real U4,
2245                    const Standard_Boolean insP4,
2246                    const Standard_Boolean mP4P1,
2247                    const Standard_Boolean flag) const
2248 {
2249   Standard_Boolean ins3 = insP3;
2250   Standard_Boolean ins4 = insP4;
2251   if (ins3 && mP3P1) {                             // P1 ---> P3
2252     if (!(Nod11Flag & NMskVert) && coef3 < myTolSta) {
2253       ins3 = Standard_False;
2254       ChangeNode(i1p1,i1p2,
2255                  Nod11Indices,Nod11RValues,
2256                  Nod12Indices,Nod12RValues,
2257                  coef3,X3,Y3,Z3,Standard_True,
2258                  TData1,PISeg1,PINod1);
2259       ChangeNode(i2p1,i2p2,
2260                  Nod21Indices,Nod21RValues,
2261                  Nod22Indices,Nod22RValues,
2262                  coef3,X3,Y3,Z3,Standard_True,
2263                  TData2,PISeg2,PINod2);
2264       X1   = X3;
2265       Y1   = Y3;
2266       Z1   = Z3;
2267       XTI1 = XTI3;
2268       YTI1 = YTI3;
2269       ZTI1 = ZTI3;
2270       U1   = U3;
2271       Nod11PntX = X3;
2272       Nod11PntY = Y3;
2273       Nod11PntZ = Z3;
2274       if      (Nod11Edg1 == (Standard_Boolean) e) Nod11PCu1 = U3;
2275       else if (Nod11Edg2 == (Standard_Boolean) e) Nod11PCu2 = U3;
2276 #ifdef DEB
2277       else {
2278         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
2279         cout << "Parameter error on Node " << i1p1 << endl;
2280       }
2281 #endif
2282       Nod11Scal  = 0;
2283       Nod11Flag |= NMskOutL;
2284       UpdateAroundNode(i1p1,Nod11Indices,TData1,PISeg1,PINod1);
2285       Nod21PntX  = X3;
2286       Nod21PntY  = Y3;
2287       Nod21PntZ  = Z3;
2288       if      (Nod21Edg1 == (Standard_Boolean) e) Nod21PCu1 = U3;
2289       else if (Nod21Edg2 == (Standard_Boolean) e) Nod21PCu2 = U3;
2290 #ifdef DEB
2291       else {
2292         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
2293         cout << "Parameter error on Node " << i2p1 << endl;
2294       }
2295 #endif
2296       Nod21Scal  = 0;
2297       Nod21Flag |= NMskOutL;
2298       UpdateAroundNode(i2p1,Nod21Indices,TData2,PISeg2,PINod2);
2299       Standard_Address Coordinates = List.First().Coordinates();
2300       PntX2   = X3;
2301       PntY2   = Y3;
2302       PntZ2   = Z3;
2303       PntXTI2 = XTI3;
2304       PntYTI2 = YTI3;
2305       PntZTI2 = ZTI3;
2306     }
2307   }
2308   if (ins4 && !mP4P1) {                            // P2 ---> P4
2309     if (!(Nod12Flag & NMskVert) && coef4 > myTolEnd) {
2310       ins4 = Standard_False;
2311       ChangeNode(i2p1,i2p2,
2312                  Nod21Indices,Nod21RValues,
2313                  Nod22Indices,Nod22RValues,
2314                  coef4,X4,Y4,Z4,Standard_False,
2315                  TData2,PISeg2,PINod2);
2316       ChangeNode(i1p1,i1p2,
2317                  Nod11Indices,Nod11RValues,
2318                  Nod12Indices,Nod12RValues,
2319                  coef4,X4,Y4,Z4,Standard_False,
2320                  TData1,PISeg1,PINod1);
2321       X2   = X4;
2322       Y2   = Y4;
2323       Z2   = Z4;
2324       XTI2 = XTI4;
2325       YTI2 = YTI4;
2326       ZTI2 = ZTI4;
2327       U2   = U4;
2328       Nod12PntX = X4;
2329       Nod12PntY = Y4;
2330       Nod12PntZ = Z4;
2331       if      (Nod12Edg1 == (Standard_Boolean) e) Nod12PCu1 = U4;
2332       else if (Nod12Edg2 == (Standard_Boolean) e) Nod12PCu2 = U4;
2333 #ifdef DEB
2334       else {
2335         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
2336         cout << "Parameter error on Node " << i1p2 << endl;
2337       }
2338 #endif
2339       Nod12Scal  = 0;
2340       Nod12Flag |= NMskOutL;
2341       UpdateAroundNode(i1p2,Nod12Indices,TData1,PISeg1,PINod1);
2342       Nod22PntX  = X4;
2343       Nod22PntY  = Y4;
2344       Nod22PntZ  = Z4;
2345       if      (Nod22Edg1 == (Standard_Boolean) e) Nod22PCu1 = U4;
2346       else if (Nod22Edg2 == (Standard_Boolean) e) Nod22PCu2 = U4;
2347 #ifdef DEB
2348       else {
2349         cout << " HLRBRep_PolyAlgo::MoveOrInsertPoint : ";
2350         cout << "Parameter error on Node " << i2p2 << endl;
2351       }
2352 #endif
2353       Nod22Scal  = 0;
2354       Nod22Flag |= NMskOutL;
2355       UpdateAroundNode(i2p2,Nod22Indices,TData2,PISeg2,PINod2);
2356     }
2357   }
2358   if (ins3 || ins4) {
2359     if      (!ins4)                                // p1 i1p3 p2
2360       MoveOrInsertPoint(List,
2361                         X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
2362                         XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
2363                         e,U1,U2,
2364                         Nod11Indices,Nod11RValues,
2365                         Nod12Indices,Nod12RValues,
2366                         i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1,
2367                         Nod21Indices,Nod21RValues,
2368                         Nod22Indices,Nod22RValues,
2369                         i2p1,i2p2,i2,pid2,TData2,PISeg2,PINod2,
2370                         X3,Y3,Z3,XTI3,YTI3,ZTI3,coef3,U3,insP3,mP3P1,flag);
2371     else if (!ins3)                                // p1 i2p4 p2
2372       MoveOrInsertPoint(List,
2373                         X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
2374                         XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
2375                         e,U1,U2,
2376                         Nod21Indices,Nod21RValues,
2377                         Nod22Indices,Nod22RValues,
2378                         i2p1,i2p2,i2,pid2,TData2,PISeg2,PINod2,
2379                         Nod11Indices,Nod11RValues,
2380                         Nod12Indices,Nod12RValues,
2381                         i1p1,i1p2,i1,pid1,TData1,PISeg1,PINod1,
2382                         X4,Y4,Z4,XTI4,YTI4,ZTI4,coef4,U4,insP4,mP4P1,flag);
2383     else {                                         // p1 i1p3 i2p4 p2
2384       Standard_Integer i1p3 = pid1->AddNode
2385         (Nod11RValues,Nod12RValues,PINod1,PINod2,coef3,X3,Y3,Z3);
2386       Standard_Integer i2p3 = pid2->AddNode
2387         (Nod21RValues,Nod22RValues,PINod2,PINod1,coef3,X3,Y3,Z3);
2388       Standard_Integer i1p4 = pid1->AddNode
2389         (Nod11RValues,Nod12RValues,PINod1,PINod2,coef4,X4,Y4,Z4);
2390       Standard_Integer i2p4 = pid2->AddNode
2391         (Nod21RValues,Nod22RValues,PINod2,PINod1,coef4,X4,Y4,Z4);
2392       const Handle(HLRAlgo_PolyInternalNode)* pi1p3 =
2393         &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(i1p3));
2394       const Standard_Address Nod13Indices = (*pi1p3)->Indices();
2395       const Standard_Address Nod13RValues = (*pi1p3)->RValues();
2396       const Handle(HLRAlgo_PolyInternalNode)* pi1p4 =
2397         &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(i1p4));
2398       const Standard_Address Nod14Indices = (*pi1p4)->Indices();
2399       const Standard_Address Nod14RValues = (*pi1p4)->RValues();
2400       const Handle(HLRAlgo_PolyInternalNode)* pi2p3 =
2401         &(((HLRAlgo_Array1OfPINod*)PINod2)->ChangeValue(i2p3));
2402       const Standard_Address Nod23Indices = (*pi2p3)->Indices();
2403       const Standard_Address Nod23RValues = (*pi2p3)->RValues();
2404       const Handle(HLRAlgo_PolyInternalNode)* pi2p4 = 
2405         &(((HLRAlgo_Array1OfPINod*)PINod2)->ChangeValue(i2p4));
2406       const Standard_Address Nod24Indices = (*pi2p4)->Indices();
2407       const Standard_Address Nod24RValues = (*pi2p4)->RValues();
2408       Nod13Edg1  = e;
2409       Nod13PCu1  = U3;
2410       Nod13Scal  = 0;
2411       Nod13Flag |= NMskOutL;
2412       Nod13Flag |= NMskEdge;
2413       Nod23Edg1  = e;
2414       Nod23PCu1  = U3;
2415       Nod23Scal  = 0;
2416       Nod23Flag |= NMskOutL;
2417       Nod23Flag |= NMskEdge;
2418       Nod14Edg1  = e;
2419       Nod14PCu1  = U4;
2420       Nod14Scal  = 0;
2421       Nod14Flag |= NMskOutL;
2422       Nod14Flag |= NMskEdge;
2423       Nod24Edg1  = e;
2424       Nod24PCu1  = U4;
2425       Nod24Scal  = 0;
2426       Nod24Flag |= NMskOutL;
2427       Nod24Flag |= NMskEdge;
2428       pid1->UpdateLinks(i1p1,i1p2,i1p3,
2429                         TData1,TData2,PISeg1,PISeg2,PINod1,PINod2);
2430       pid2->UpdateLinks(i2p1,i2p2,i2p3,
2431                         TData2,TData1,PISeg2,PISeg1,PINod2,PINod1);
2432       pid2->UpdateLinks(i2p3,i2p2,i2p4,
2433                         TData2,TData1,PISeg2,PISeg1,PINod2,PINod1);
2434       pid1->UpdateLinks(i1p3,i1p2,i1p4,
2435                         TData1,TData2,PISeg1,PISeg2,PINod1,PINod2);
2436       UpdateAroundNode(i1p3,Nod13Indices,TData1,PISeg1,PINod1);
2437       UpdateAroundNode(i2p3,Nod23Indices,TData2,PISeg2,PINod2);
2438       UpdateAroundNode(i1p4,Nod14Indices,TData1,PISeg1,PINod1);
2439       UpdateAroundNode(i2p4,Nod24Indices,TData2,PISeg2,PINod2);
2440       List.Prepend(HLRAlgo_BiPoint
2441                    (XTI1,YTI1,ZTI1,XTI3,YTI3,ZTI3,
2442                     X1  ,Y1  ,Z1  ,X3  ,Y3  ,Z3  ,   e,
2443                     i1  ,i1p1,i1p3,i2  ,i2p1,i2p3,flag));
2444       List.Prepend(HLRAlgo_BiPoint
2445                    (XTI3,YTI3,ZTI3,XTI4,YTI4,ZTI4,
2446                     X3  ,Y3  ,Z3  ,X4  ,Y4  ,Z4  ,   e,
2447                     i1  ,i1p3,i1p4,i2  ,i2p3,i2p4,flag));
2448       List.Prepend(HLRAlgo_BiPoint
2449                    (XTI4,YTI4,ZTI4,XTI2,YTI2,ZTI2,
2450                     X4  ,Y4  ,Z4  ,X2  ,Y2  ,Z2  ,   e,
2451                     i1  ,i1p4,i1p2,i2  ,i2p4,i2p2,flag));
2452     }
2453   }
2454   else                                             // p1 p2
2455     List.Prepend(HLRAlgo_BiPoint
2456                  (XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
2457                   X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,   e,
2458                   i1  ,i1p1,i1p2,i2  ,i2p1,i2p2,flag));
2459 }
2460
2461 //=======================================================================
2462 //function : InsertOnOutLine
2463 //purpose  : 
2464 //=======================================================================
2465
2466 void
2467 HLRBRep_PolyAlgo::InsertOnOutLine (TColStd_Array1OfTransient& PID)
2468 {
2469   Standard_Address TData2 = 0;
2470   Standard_Address PISeg2 = 0;
2471   Standard_Address PINod2 = 0;
2472   Standard_Address Seg1Indices;
2473   Standard_Address Nod1Indices,Nod1RValues;
2474   Standard_Address Nod2Indices,Nod2RValues;
2475   Handle(HLRAlgo_PolyInternalData)* pid = 
2476     (Handle(HLRAlgo_PolyInternalData)*) (&(PID.ChangeValue(1)));
2477
2478   TopLoc_Location L;
2479   Standard_Boolean insP3,mP3P1,IntOutL;
2480   Standard_Integer f,ip1,ip2,ip3;//, i;
2481   Standard_Real U3,V3,coef3,X3,Y3,Z3;
2482
2483   const gp_Trsf& T  = myProj.Transformation();
2484   
2485   Standard_Integer nbFace = myFMap.Extent();
2486   for (f = 1; f <= nbFace; f++) {
2487
2488     if (!((*pid).IsNull())) {
2489       IntOutL = Standard_False;
2490       Standard_Address TData1= &((*pid)->TData());
2491       Standard_Address PISeg1= &((*pid)->PISeg());
2492       Standard_Address PINod1= &((*pid)->PINod());
2493       TopoDS_Shape LocalShape = myFMap(f);
2494       const TopoDS_Face& F = TopoDS::Face(LocalShape);
2495       myBSurf.Initialize(F,Standard_False);
2496       myGSurf = BRep_Tool::Surface(F,L);
2497       gp_Trsf TT = L.Transformation();
2498       TT.PreMultiply(T);
2499       const gp_XYZ& ttlo = TT.TranslationPart();
2500       TTLo[0] = ttlo.X();
2501       TTLo[1] = ttlo.Y();
2502       TTLo[2] = ttlo.Z();
2503       const gp_Mat& ttma = TT.VectorialPart();
2504       TTMa[0][0] = ttma.Value(1,1);
2505       TTMa[0][1] = ttma.Value(1,2);
2506       TTMa[0][2] = ttma.Value(1,3);
2507       TTMa[1][0] = ttma.Value(2,1);
2508       TTMa[1][1] = ttma.Value(2,2);
2509       TTMa[1][2] = ttma.Value(2,3);
2510       TTMa[2][0] = ttma.Value(3,1);
2511       TTMa[2][1] = ttma.Value(3,2);
2512       TTMa[2][2] = ttma.Value(3,3);
2513       Standard_Integer iseg,nbT,nbS,nbN;
2514
2515       nbT = (*pid)->NbTData();
2516       nbN = (*pid)->NbPINod();
2517       nbS = (*pid)->NbPISeg();
2518
2519 #ifdef DEB
2520       if (DoTrace) {
2521         cout << " InsertOnOutLine : NbTData " << nbT << endl;
2522         cout << " InsertOnOutLine : NbPISeg " << nbS << endl;
2523         cout << " InsertOnOutLine : NbPINod " << nbN << endl;
2524       }
2525 #endif
2526
2527       for (iseg = 1; iseg <= nbS; iseg++) {
2528         Seg1Indices =
2529           ((HLRAlgo_Array1OfPISeg*)PISeg1)->ChangeValue(iseg).Indices();
2530 //      Standard_Boolean Cutted = Standard_False;
2531         if (Seg1Conex1 != 0 && Seg1Conex2 != 0) {
2532           ip1 = Seg1LstSg1;
2533           ip2 = Seg1LstSg2;
2534           const Handle(HLRAlgo_PolyInternalNode)* pip1 =
2535             &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(ip1));
2536           Nod1Indices = (*pip1)->Indices();
2537           Nod1RValues = (*pip1)->RValues();
2538           const Handle(HLRAlgo_PolyInternalNode)* pip2 =
2539             &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(ip2));
2540           Nod2Indices = (*pip2)->Indices();
2541           Nod2RValues = (*pip2)->RValues();
2542           if (Nod1Flag & NMskOutL && Nod2Flag & NMskOutL)
2543             IntOutL = Standard_True;
2544           else if ((Nod1Scal >=  myTolAngular &&
2545                     Nod2Scal <= -myTolAngular) ||
2546                    (Nod2Scal >=  myTolAngular &&
2547                     Nod1Scal <= -myTolAngular)) {
2548             IntOutL = Standard_True;
2549             insP3 = NewNode(Nod1RValues,Nod2RValues,coef3,mP3P1);
2550             if (insP3) {
2551               UVNode(Nod1RValues,Nod2RValues,coef3,U3,V3);
2552               const gp_Pnt& PT3 = myGSurf->Value(U3,V3);
2553               X3 = PT3.X();
2554               Y3 = PT3.Y();
2555               Z3 = PT3.Z();
2556               TTMultiply(X3,Y3,Z3);
2557             }
2558             
2559             if (insP3 && mP3P1) {                        // P1 ---> P3
2560               if ((Nod1Flag & NMskEdge) == 0 && coef3 < myTolSta) {
2561                 insP3 = Standard_False;
2562                 ChangeNode(ip1,ip2,
2563                            Nod1Indices,Nod1RValues,
2564                            Nod2Indices,Nod2RValues,
2565                            coef3,X3,Y3,Z3,Standard_True,
2566                            TData1,PISeg1,PINod1);
2567                 Nod1Scal  = 0;
2568                 Nod1Flag |= NMskOutL;
2569               }
2570             }
2571             if (insP3 && !mP3P1) {                       // P2 ---> P3
2572               if ((Nod2Flag & NMskEdge) == 0 && coef3 > myTolEnd) {
2573                 insP3 = Standard_False;
2574                 ChangeNode(ip1,ip2,
2575                            Nod1Indices,Nod1RValues,
2576                            Nod2Indices,Nod2RValues,
2577                            coef3,X3,Y3,Z3,Standard_False,
2578                            TData1,PISeg1,PINod1);
2579                 Nod2Scal  = 0;
2580                 Nod2Flag |= NMskOutL;
2581               }
2582             }
2583             if (insP3) {                                 // p1 ip3 p2
2584               ip3 = (*pid)->AddNode(Nod1RValues,Nod2RValues,PINod1,PINod2,
2585                                     coef3,X3,Y3,Z3);
2586               const Handle(HLRAlgo_PolyInternalNode)* pip3 =
2587                 (&((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(ip3));
2588               const Standard_Address Nod3Indices = (*pip3)->Indices();
2589               const Standard_Address Nod3RValues = (*pip3)->RValues();
2590               (*pid)->UpdateLinks(ip1,ip2,ip3,
2591                                   TData1,TData2,PISeg1,PISeg2,PINod1,PINod2);
2592               UpdateAroundNode(ip3,Nod3Indices,TData1,PISeg1,PINod1);
2593               Nod3Scal  = 0;
2594               Nod3Flag |= NMskOutL;
2595             }
2596           }
2597         }
2598       }
2599       if (IntOutL)
2600         (*pid)->IntOutL(Standard_True);
2601
2602       nbT = (*pid)->NbTData();
2603       nbN = (*pid)->NbPINod();
2604       nbS = (*pid)->NbPISeg();
2605
2606 #ifdef DEB
2607       if (DoTrace) {
2608         cout << " InsertOnOutLine : NbTData " << nbT << endl;
2609         cout << " InsertOnOutLine : NbPISeg " << nbS << endl;
2610         cout << " InsertOnOutLine : NbPINod " << nbN << endl;
2611       }
2612 #endif
2613     }
2614     pid++;
2615   }
2616 }
2617
2618 //=======================================================================
2619 //function : CheckFrBackTriangles
2620 //purpose  : 
2621 //=======================================================================
2622
2623 void
2624 HLRBRep_PolyAlgo::CheckFrBackTriangles (HLRAlgo_ListOfBPoint& List,
2625                                         TColStd_Array1OfTransient& PID)
2626 {
2627   Standard_Integer f,i,nbN,nbT,nbFace;
2628   Standard_Real X1 =0.,Y1 =0.,X2 =0.,Y2 =0.,X3 =0.,Y3 =0.;
2629   Standard_Real D1,D2,D3;
2630   Standard_Real dd,dX,dY,nX,nY;
2631   Standard_Boolean FrBackInList;
2632   Standard_Address TData ,PISeg ,PINod ;
2633 /*  Standard_Address IndexPtr = NULL; 
2634   const Handle(HLRAlgo_PolyInternalData)& pid1 =
2635     *(Handle(HLRAlgo_PolyInternalData)*)&(PID(F1Index));
2636   Standard_Address TData1 = &pid1->TData(),
2637   PISeg1 = &pid1->PISeg(),
2638   PINod1 = &pid1->PINod();
2639
2640   const Handle(HLRAlgo_PolyInternalData)& pid2 =
2641     *(Handle(HLRAlgo_PolyInternalData)*)&(PID(F2Index));
2642   Standard_Address TData2 = &pid2->TData(),
2643   PISeg2 = &pid2->PISeg(),
2644   PINod2 = &pid2->PISeg();*/
2645   Standard_Address TData1 = NULL,PISeg1 = NULL,PINod1 = NULL;
2646   Standard_Address TData2 = NULL,PISeg2 = NULL,PINod2 = NULL;
2647   Standard_Address Nod11Indices,Nod12Indices,Nod13Indices;
2648   Standard_Address Nod11RValues,Nod12RValues,Nod13RValues;
2649   Standard_Address Tri1Indices;
2650
2651   Handle(HLRAlgo_PolyInternalData)* pid;
2652
2653   nbFace = myFMap.Extent();
2654   Standard_Boolean Modif = Standard_True;
2655   Standard_Integer iLoop = 0;
2656   
2657   while (Modif && iLoop < 4) {
2658     iLoop++;
2659     Modif        = Standard_False;
2660     FrBackInList = Standard_False;
2661     pid = (Handle(HLRAlgo_PolyInternalData)*)&(PID.ChangeValue(1));
2662     
2663     for (f = 1; f <= nbFace; f++) {
2664       if (!(*pid).IsNull()) {
2665         nbT   =  (*pid)->NbTData();
2666         TData = &(*pid)->TData();
2667         PISeg = &(*pid)->PISeg();
2668         PINod = &(*pid)->PINod();
2669         HLRAlgo_TriangleData* tdata =
2670           &(((HLRAlgo_Array1OfTData*)TData)->ChangeValue(1));
2671         
2672         for (i = 1; i <= nbT; i++) {
2673           Tri1Indices = tdata->Indices();
2674           if ((Tri1Flags & FMskSide) == 0 &&
2675               (Tri1Flags & FMskFrBack)) {
2676 #ifdef DEB
2677             if (DoTrace)
2678               cout << " face : " << f << " , triangle " << i << endl;
2679 #endif
2680             Modif        = Standard_True;
2681             const Handle(HLRAlgo_PolyInternalNode)* pi1p1 =
2682               &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri1Node1));
2683             Nod11Indices = (*pi1p1)->Indices();
2684             Nod11RValues = (*pi1p1)->RValues();
2685             const Handle(HLRAlgo_PolyInternalNode)* pi1p2 =
2686               &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri1Node2));
2687             Nod12Indices = (*pi1p2)->Indices();
2688             Nod12RValues = (*pi1p2)->RValues();
2689             const Handle(HLRAlgo_PolyInternalNode)* pi1p3 =
2690               &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri1Node3));
2691             Nod13Indices = (*pi1p3)->Indices();
2692             Nod13RValues = (*pi1p3)->RValues();
2693             D1 = 0.; D2 = 0.; D3 = 0.;
2694             if (((Nod11Flag & NMskEdge) == 0 || iLoop > 1) &&
2695                 ((Nod11Flag & NMskOutL) == 0 || iLoop > 1) &&
2696                 ((Nod11Flag & NMskVert) == 0)) {
2697               dX = Nod13PntX - Nod12PntX; dY = Nod13PntY - Nod12PntY;
2698               D1 = dX * dX + dY * dY;
2699               D1 = sqrt(D1);
2700               nX = - dY / D1; nY =   dX / D1;
2701               dX = Nod11PntX - Nod12PntX; dY = Nod11PntY - Nod12PntY;
2702               dd = - (dX * nX + dY * nY);
2703               if (dd < 0) dd -= D1 * 0.01;
2704               else        dd += D1 * 0.01;
2705               X1 = nX * dd; Y1 = nY * dd;
2706             }
2707             if (((Nod12Flag & NMskEdge) == 0 || iLoop > 1) &&
2708                 ((Nod12Flag & NMskOutL) == 0 || iLoop > 1) &&
2709                 ((Nod12Flag & NMskVert) == 0)) {
2710               dX = Nod11PntX - Nod13PntX; dY = Nod11PntY - Nod13PntY;
2711               D2 = dX * dX + dY * dY;
2712               D2 = sqrt(D2);
2713               nX = - dY / D2; nY =   dX / D2;
2714               dX = Nod12PntX - Nod13PntX; dY = Nod12PntY - Nod13PntY;
2715               dd = - (dX * nX + dY * nY);
2716               if (dd < 0) dd -= D2 * 0.01;
2717               else        dd += D2 * 0.01;
2718               X2 = nX * dd; Y2 = nY * dd;
2719             }
2720             if (((Nod13Flag & NMskEdge) == 0 || iLoop > 1) &&
2721                 ((Nod13Flag & NMskOutL) == 0 || iLoop > 1) &&
2722                 ((Nod13Flag & NMskVert) == 0)) {
2723               dX = Nod12PntX - Nod11PntX; dY = Nod12PntY - Nod11PntY;
2724               D3 = dX * dX + dY * dY;
2725               D3 = sqrt(D3);
2726               nX = - dY / D3; nY =   dX / D3;
2727               dX = Nod13PntX - Nod11PntX; dY = Nod13PntY - Nod11PntY;
2728               dd = - (dX * nX + dY * nY);
2729               if (dd < 0) dd -= D3 * 0.01;
2730               else        dd += D3 * 0.01;
2731               X3 = nX * dd; Y3 = nY * dd;
2732             }
2733             if      (D1 > D2 && D1 > D3) {
2734               Nod11PntX += X1; Nod11PntY += Y1;
2735               Nod11Flag |= NMskMove;
2736               UpdateAroundNode(Tri1Node1,Nod11Indices,TData,PISeg,PINod);
2737               FrBackInList = Standard_True;
2738 #ifdef DEB
2739               if (DoTrace) {
2740                 cout << Tri1Node1 << " modifies  : DX,DY ";
2741                 cout << X1 << " , " << Y1 << endl;
2742               }
2743 #endif
2744             }
2745             else if (D2 > D3 && D2 > D1) {
2746               Nod12PntX += X2; Nod12PntY += Y2;
2747               Nod12Flag |= NMskMove;
2748               UpdateAroundNode(Tri1Node2,Nod12Indices,TData,PISeg,PINod);
2749               FrBackInList = Standard_True;
2750 #ifdef DEB
2751               if (DoTrace) {
2752                 cout << Tri1Node2 << " modifies  : DX,DY ";
2753                 cout << X2 << " , " << Y2 << endl;
2754               }
2755 #endif
2756             }
2757             else if (D3 > D1 && D3 > D2) {
2758               Nod13PntX += X3; Nod13PntY += Y3;
2759               Nod13Flag |= NMskMove;
2760               UpdateAroundNode(Tri1Node3,Nod13Indices,TData,PISeg,PINod);
2761               FrBackInList = Standard_True;
2762 #ifdef DEB
2763               if (DoTrace) {
2764                 cout << Tri1Node3 << " modifies  : DX,DY ";
2765                 cout << X3 << " , " << Y3 << endl;
2766               }
2767 #endif
2768             }
2769 #ifdef DEB
2770             else if (DoTrace)
2771               cout << "modification error" << endl;
2772 #endif
2773           }
2774           tdata++;
2775         }
2776       }
2777       pid++;
2778     }
2779     if (FrBackInList) {
2780       Standard_Address IndexPtr,Coordinates;
2781       HLRAlgo_ListIteratorOfListOfBPoint it;
2782       
2783       for (it.Initialize(List); it.More(); it.Next()) {      
2784         HLRAlgo_BiPoint& BP = it.Value();
2785         IndexPtr = BP.Indices();
2786         if (F1Index != 0) {
2787           const Handle(HLRAlgo_PolyInternalData)& pid1 =
2788             *(Handle(HLRAlgo_PolyInternalData)*)&(PID(F1Index));
2789           TData1 = &pid1->TData();
2790           PISeg1 = &pid1->PISeg();
2791           PINod1 = &pid1->PINod();
2792         }
2793         if (F2Index != 0) {
2794           if (F1Index == F2Index) {
2795             TData2 = TData1;
2796             PISeg2 = PISeg1;
2797             PINod2 = PINod1;
2798           }
2799           else {
2800             const Handle(HLRAlgo_PolyInternalData)& pid2 =
2801               *(Handle(HLRAlgo_PolyInternalData)*)&(PID(F2Index));
2802             TData2 = &pid2->TData();
2803             PISeg2 = &pid2->PISeg();
2804             PINod2 = &pid2->PINod();
2805           }
2806         }
2807         if (F1Index != 0) {
2808           Nod11Indices = (((HLRAlgo_Array1OfPINod*)PINod1)->
2809                           ChangeValue(F1Pt1Index))->Indices();
2810           if (Nod11Flag & NMskMove) {
2811 #ifdef DEB
2812             if (DoTrace)
2813               cout << F1Pt1Index << " modifies 11" << endl;
2814 #endif
2815             Nod11RValues = (((HLRAlgo_Array1OfPINod*)PINod1)->
2816                             ChangeValue(F1Pt1Index))->RValues();
2817             Coordinates = BP.Coordinates();
2818             PntXTI1 = PntX1 = Nod11PntX;
2819             PntYTI1 = PntY1 = Nod11PntY;
2820             PntZTI1 = PntZ1 = Nod11PntZ;
2821             TIMultiply(PntXTI1,PntYTI1,PntZTI1);
2822             if (F2Index != 0) {
2823               Nod12Indices = (((HLRAlgo_Array1OfPINod*)PINod2)->
2824                               ChangeValue(F2Pt1Index))->Indices();
2825               Nod12RValues = (((HLRAlgo_Array1OfPINod*)PINod2)->
2826                               ChangeValue(F2Pt1Index))->RValues();
2827               Nod12PntX    = Nod11PntX;
2828               Nod12PntY    = Nod11PntY;
2829               UpdateAroundNode(F2Pt1Index,Nod12Indices,
2830                                TData2,PISeg2,PINod2);
2831             }
2832           }
2833           Nod11Indices = (((HLRAlgo_Array1OfPINod*)PINod1)->
2834                           ChangeValue(F1Pt2Index))->Indices();
2835           if (Nod11Flag & NMskMove) {
2836 #ifdef DEB
2837             if (DoTrace)
2838               cout << F1Pt2Index << " modifies 12" << endl;
2839 #endif
2840             Nod11RValues = (((HLRAlgo_Array1OfPINod*)PINod1)->
2841                             ChangeValue(F1Pt2Index))->RValues();
2842             Coordinates = BP.Coordinates();
2843             PntXTI2 = PntX2 = Nod11PntX;
2844             PntYTI2 = PntY2 = Nod11PntY;
2845             PntZTI2 = PntZ2 = Nod11PntZ;
2846             TIMultiply(PntXTI2,PntYTI2,PntZTI2);
2847             if (F2Index != 0) {
2848               Nod12Indices = (((HLRAlgo_Array1OfPINod*)PINod2)->
2849                               ChangeValue(F2Pt2Index))->Indices();
2850               Nod12RValues = (((HLRAlgo_Array1OfPINod*)PINod2)->
2851                               ChangeValue(F2Pt2Index))->RValues();
2852               Nod12PntX    = Nod11PntX;
2853               Nod12PntY    = Nod11PntY;
2854               UpdateAroundNode(F2Pt2Index,Nod12Indices,
2855                                TData2,PISeg2,PINod2);
2856             }
2857           }
2858         }
2859         if (F2Index != 0) {
2860           const Handle(HLRAlgo_PolyInternalData)& pid2 =
2861             *(Handle(HLRAlgo_PolyInternalData)*)&(PID(F2Index));
2862           PINod2 = &pid2->PINod();
2863           Nod11Indices = (((HLRAlgo_Array1OfPINod*)PINod2)->
2864                           ChangeValue(F2Pt1Index))->Indices();
2865           if (Nod11Flag & NMskMove) {
2866 #ifdef DEB
2867             if (DoTrace)
2868               cout << F2Pt1Index << " modifies 21" << endl;
2869 #endif
2870             Nod11RValues = (((HLRAlgo_Array1OfPINod*)PINod2)->
2871                             ChangeValue(F2Pt1Index))->RValues();
2872             Coordinates = BP.Coordinates();
2873             PntXTI1 = PntX1 = Nod11PntX;
2874             PntYTI1 = PntY1 = Nod11PntY;
2875             PntZTI1 = PntZ1 = Nod11PntZ;
2876             TIMultiply(PntXTI1,PntYTI1,PntZTI1);
2877             if (F1Index != 0) {
2878               Nod12Indices = (((HLRAlgo_Array1OfPINod*)PINod1)->
2879                               ChangeValue(F1Pt1Index))->Indices();
2880               Nod12RValues = (((HLRAlgo_Array1OfPINod*)PINod1)->
2881                               ChangeValue(F1Pt1Index))->RValues();
2882               Nod12PntX    = Nod11PntX;
2883               Nod12PntY    = Nod11PntY;
2884               UpdateAroundNode(F1Pt1Index,Nod12Indices,
2885                                TData1,PISeg1,PINod1);
2886             }
2887           }
2888           Nod11Indices = (((HLRAlgo_Array1OfPINod*)PINod2)->
2889                           ChangeValue(F2Pt2Index))->Indices();
2890           if (Nod11Flag & NMskMove) {
2891 #ifdef DEB
2892             if (DoTrace)
2893               cout << F2Pt2Index << " modifies 22" << endl;
2894 #endif
2895             Nod11RValues = (((HLRAlgo_Array1OfPINod*)PINod2)->
2896                             ChangeValue(F2Pt2Index))->RValues();
2897             Coordinates = BP.Coordinates();
2898             PntXTI2 = PntX2 = Nod11PntX;
2899             PntYTI2 = PntY2 = Nod11PntY;
2900             PntZTI2 = PntZ2 = Nod11PntZ;
2901             TIMultiply(PntXTI2,PntYTI2,PntZTI2);
2902             if (F1Index != 0) {
2903               Nod12Indices = (((HLRAlgo_Array1OfPINod*)PINod1)->
2904                               ChangeValue(F1Pt2Index))->Indices();
2905               Nod12RValues = (((HLRAlgo_Array1OfPINod*)PINod1)->
2906                               ChangeValue(F1Pt2Index))->RValues();
2907               Nod12PntX    = Nod11PntX;
2908               Nod12PntY    = Nod11PntY;
2909               UpdateAroundNode(F1Pt2Index,Nod12Indices,
2910                                TData1,PISeg1,PINod1);
2911             }
2912           }
2913         }
2914       }
2915       pid = (Handle(HLRAlgo_PolyInternalData)*)&(PID.ChangeValue(1));
2916       
2917       for (f = 1; f <= nbFace; f++) {
2918         if (!(*pid).IsNull()) {
2919           nbN   =  (*pid)->NbPINod();
2920           PINod = &(*pid)->PINod();
2921           Handle(HLRAlgo_PolyInternalNode)* NN = 
2922             &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(1));
2923
2924           for (i = 1; i <= nbN; i++) {
2925             Nod11Indices = (*NN)->Indices();
2926             Nod11Flag   &= ~NMskMove;
2927             NN++;
2928           }
2929         }
2930         pid++;
2931       }
2932     }
2933   }
2934 }
2935
2936 //=======================================================================
2937 //function : FindEdgeOnTriangle
2938 //purpose  : 
2939 //=======================================================================
2940
2941 void
2942 HLRBRep_PolyAlgo::
2943 FindEdgeOnTriangle (const Standard_Address Tri1Indices,
2944                     const Standard_Integer ip1,
2945                     const Standard_Integer ip2,
2946                     Standard_Integer& jtrouv,
2947                     Standard_Boolean& isDirect) const
2948 {
2949   Standard_Integer n1 = Tri1Node1;
2950   Standard_Integer n2 = Tri1Node2;
2951   Standard_Integer n3 = Tri1Node3;
2952   if      (ip1 == n1 && ip2 == n2) {
2953     jtrouv = 0;
2954     isDirect = Standard_True;
2955     return;
2956   }
2957   else if (ip2 == n1 && ip1 == n2) {
2958     jtrouv = 0;
2959     isDirect = Standard_False;
2960     return;
2961   }
2962   else if (ip1 == n2 && ip2 == n3) {
2963     jtrouv = 1;
2964     isDirect = Standard_True;
2965     return;
2966   }
2967   else if (ip2 == n2 && ip1 == n3) {
2968     jtrouv = 1;
2969     isDirect = Standard_False;
2970     return;
2971   }
2972   else if (ip1 == n3 && ip2 == n1) {
2973     jtrouv = 2;
2974     isDirect = Standard_True;
2975     return;
2976   }
2977   else if (ip2 == n3 && ip1 == n1) {
2978     jtrouv = 2;
2979     isDirect = Standard_False;
2980     return;
2981   }
2982 }
2983
2984 //=======================================================================
2985 //function : ChangeNode
2986 //purpose  : 
2987 //=======================================================================
2988
2989 void HLRBRep_PolyAlgo::ChangeNode (const Standard_Integer ip1,
2990                                    const Standard_Integer ip2,
2991                                    const Standard_Address Nod1Indices,
2992                                    const Standard_Address Nod1RValues,
2993                                    const Standard_Address Nod2Indices,
2994                                    const Standard_Address Nod2RValues,
2995                                    const Standard_Real coef1,
2996                                    const Standard_Real X3,
2997                                    const Standard_Real Y3,
2998                                    const Standard_Real Z3,
2999                                    const Standard_Boolean first,
3000                                    Standard_Address& TData,
3001                                    Standard_Address& PISeg,
3002                                    Standard_Address& PINod) const
3003 {
3004   Standard_Real coef2 = 1 - coef1;
3005   if (first) {
3006     Nod1PntX = X3;
3007     Nod1PntY = Y3;
3008     Nod1PntZ = Z3;
3009     Nod1PntU = Nod1PntU * coef2 + Nod2PntU * coef1;
3010     Nod1PntV = Nod1PntV * coef2 + Nod2PntV * coef1; 
3011     Nod1Scal = Nod1Scal * coef2 + Nod2Scal * coef1;
3012     Standard_Real x = Nod1NrmX * coef2 + Nod2NrmX * coef1;
3013     Standard_Real y = Nod1NrmY * coef2 + Nod2NrmY * coef1;
3014     Standard_Real z = Nod1NrmZ * coef2 + Nod2NrmZ * coef1;
3015     Standard_Real D = sqrt (x * x + y * y + z * z);
3016     if (D > 0) {
3017       Nod1NrmX = x / D;
3018       Nod1NrmY = y / D;
3019       Nod1NrmZ = z / D;
3020     }
3021     else {
3022       Nod1NrmX = 1;
3023       Nod1NrmY = 0;
3024       Nod1NrmZ = 0;
3025 #ifdef DEB
3026       if (DoError) {
3027         cout << "HLRBRep_PolyAlgo::ChangeNode between " << ip1;
3028         cout << " and " << ip2 << endl;
3029       }
3030 #endif
3031     }
3032     UpdateAroundNode(ip1,Nod1Indices,TData,PISeg,PINod);
3033   }
3034   else {
3035     Nod2PntX = X3;
3036     Nod2PntY = Y3;
3037     Nod2PntZ = Z3;
3038     Nod2PntU = Nod1PntU * coef2 + Nod2PntU * coef1;
3039     Nod2PntV = Nod1PntV * coef2 + Nod2PntV * coef1; 
3040     Nod2Scal = Nod1Scal * coef2 + Nod2Scal * coef1;
3041     Standard_Real x = Nod1NrmX * coef2 + Nod2NrmX * coef1;
3042     Standard_Real y = Nod1NrmY * coef2 + Nod2NrmY * coef1;
3043     Standard_Real z = Nod1NrmZ * coef2 + Nod2NrmZ * coef1;
3044     Standard_Real D = sqrt (x * x + y * y + z * z);
3045     if (D > 0) {
3046       D = 1 / D;
3047       Nod2NrmX = x * D;
3048       Nod2NrmY = y * D;
3049       Nod2NrmZ = z * D;
3050     }
3051     else {
3052       Nod2NrmX = 1;
3053       Nod2NrmY = 0;
3054       Nod2NrmZ = 0;
3055 #ifdef DEB
3056       if (DoError) {
3057         cout << "HLRBRep_PolyAlgo::ChangeNode between " << ip2;
3058         cout << " and " << ip1 << endl;
3059       }
3060 #endif
3061     }
3062     UpdateAroundNode(ip2,Nod2Indices,TData,PISeg,PINod);
3063   }
3064 }
3065
3066 //=======================================================================
3067 //function : UpdateAroundNode
3068 //purpose  : 
3069 //=======================================================================
3070
3071 void HLRBRep_PolyAlgo::
3072 UpdateAroundNode (const Standard_Integer iNode,
3073                   const Standard_Address Nod1Indices,
3074                   const Standard_Address TData,
3075                   const Standard_Address PISeg,
3076                   const Standard_Address PINod) const
3077 {
3078   Standard_Integer iiii,iTri1,iTri2;
3079   iiii = Nod1NdSg;
3080   
3081   while (iiii != 0) {
3082     const Standard_Address Seg1Indices =
3083       ((HLRAlgo_Array1OfPISeg*)PISeg)->ChangeValue(iiii).Indices();
3084     iTri1 = Seg1Conex1;
3085     iTri2 = Seg1Conex2;
3086     if ( iTri1 != 0) {
3087       const Standard_Address Tri1Indices =
3088         ((HLRAlgo_Array1OfTData*)TData)->ChangeValue(iTri1).Indices();
3089       const Handle(HLRAlgo_PolyInternalNode)* PN1 = 
3090         &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri1Node1));
3091       const Handle(HLRAlgo_PolyInternalNode)* PN2 = 
3092         &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri1Node2));
3093       const Handle(HLRAlgo_PolyInternalNode)* PN3 = 
3094         &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri1Node3));
3095       const Standard_Address Nod1Indices = (*PN1)->Indices();
3096       const Standard_Address Nod2Indices = (*PN2)->Indices();
3097       const Standard_Address Nod3Indices = (*PN3)->Indices();
3098       const Standard_Address Nod1RValues = (*PN1)->RValues();
3099       const Standard_Address Nod2RValues = (*PN2)->RValues();
3100       const Standard_Address Nod3RValues = (*PN3)->RValues();
3101       OrientTriangle(iTri1,Tri1Indices,
3102                      Nod1Indices,Nod1RValues,
3103                      Nod2Indices,Nod2RValues,
3104                      Nod3Indices,Nod3RValues);
3105     }
3106     if ( iTri2 != 0) {
3107       const Standard_Address Tri2Indices =
3108         ((HLRAlgo_Array1OfTData*)TData)->ChangeValue(iTri2).Indices();
3109       const Handle(HLRAlgo_PolyInternalNode)* PN1 = 
3110         &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri2Node1));
3111       const Handle(HLRAlgo_PolyInternalNode)* PN2 = 
3112         &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri2Node2));
3113       const Handle(HLRAlgo_PolyInternalNode)* PN3 = 
3114         &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(Tri2Node3));
3115       const Standard_Address Nod1Indices = (*PN1)->Indices();
3116       const Standard_Address Nod2Indices = (*PN2)->Indices();
3117       const Standard_Address Nod3Indices = (*PN3)->Indices();
3118       const Standard_Address Nod1RValues = (*PN1)->RValues();
3119       const Standard_Address Nod2RValues = (*PN2)->RValues();
3120       const Standard_Address Nod3RValues = (*PN3)->RValues();
3121       OrientTriangle(iTri2,Tri2Indices,
3122                      Nod1Indices,Nod1RValues,
3123                      Nod2Indices,Nod2RValues,
3124                      Nod3Indices,Nod3RValues);
3125     }
3126     if (Seg1LstSg1 == iNode) iiii = Seg1NxtSg1;
3127     else                     iiii = Seg1NxtSg2;
3128   }
3129 }
3130
3131 //=======================================================================
3132 //function : OrientTriangle
3133 //purpose  : 
3134 //=======================================================================
3135
3136 void 
3137 HLRBRep_PolyAlgo::OrientTriangle(const Standard_Integer iTri,
3138                                  const Standard_Address Tri1Indices,
3139                                  const Standard_Address Nod1Indices,
3140                                  const Standard_Address Nod1RValues,
3141                                  const Standard_Address Nod2Indices,
3142                                  const Standard_Address Nod2RValues,
3143                                  const Standard_Address Nod3Indices,
3144                                  const Standard_Address Nod3RValues) const
3145 {
3146   Standard_Boolean o1 = Nod1Flag & NMskOutL;
3147   Standard_Boolean o2 = Nod2Flag & NMskOutL;
3148   Standard_Boolean o3 = Nod3Flag & NMskOutL;
3149   Tri1Flags &= ~FMskFlat;
3150   Tri1Flags &= ~FMskOnOutL;
3151   if (o1 && o2 && o3) {
3152     Tri1Flags |=  FMskSide;
3153     Tri1Flags &= ~FMskBack;
3154     Tri1Flags |=  FMskOnOutL;
3155 #ifdef DEB
3156     if (DoTrace) {
3157       cout << "HLRBRep_PolyAlgo::OrientTriangle : OnOutL";
3158       cout << " triangle " << iTri << endl;
3159     }
3160 #endif
3161   }
3162   else {
3163     Standard_Real s1 = Nod1Scal;
3164     Standard_Real s2 = Nod2Scal;
3165     Standard_Real s3 = Nod3Scal;
3166     Standard_Real as1 = s1;
3167     Standard_Real as2 = s2;
3168     Standard_Real as3 = s3;
3169     if (s1 < 0) as1 = -s1;
3170     if (s2 < 0) as2 = -s2;
3171     if (s3 < 0) as3 = -s3;
3172     Standard_Real  s = 0;
3173     Standard_Real as = 0;
3174     if (!o1            ) {s = s1; as = as1;}
3175     if (!o2 && as < as2) {s = s2; as = as2;}
3176     if (!o3 && as < as3) {s = s3; as = as3;}
3177     if (s > 0) {
3178       Tri1Flags &= ~FMskSide;
3179       Tri1Flags |=  FMskBack;
3180     }
3181     else {
3182       Tri1Flags &= ~FMskSide;
3183       Tri1Flags &= ~FMskBack;
3184     }
3185     Standard_Real dx12 = Nod2PntX - Nod1PntX;
3186     Standard_Real dy12 = Nod2PntY - Nod1PntY;
3187     Standard_Real dz12 = Nod2PntZ - Nod1PntZ;
3188     Standard_Real  d12 = sqrt(dx12 * dx12 + dy12 * dy12 + dz12 * dz12);
3189     if (d12 <= 1.e-10) {
3190 #ifdef DEB
3191       if (DoTrace) {
3192         cout << "HLRBRep_PolyAlgo::OrientTriangle : Flat";
3193         cout << " triangle " << iTri << endl;
3194       }
3195 #endif
3196       Tri1Flags |=  FMskFlat;
3197       Tri1Flags |=  FMskSide;
3198       Tri1Flags &= ~FMskBack;
3199     }
3200     else {
3201       Standard_Real dx23 = Nod3PntX - Nod2PntX;
3202       Standard_Real dy23 = Nod3PntY - Nod2PntY;
3203       Standard_Real dz23 = Nod3PntZ - Nod2PntZ;
3204       Standard_Real  d23 = sqrt(dx23 * dx23 + dy23 * dy23 + dz23 * dz23);
3205       if (d23 < 1.e-10) {
3206 #ifdef DEB
3207         if (DoTrace) {
3208           cout << "HLRBRep_PolyAlgo::OrientTriangle : Flat";
3209           cout << " triangle " << iTri << endl;
3210         }
3211 #endif
3212         Tri1Flags |=  FMskFlat;
3213         Tri1Flags |=  FMskSide;
3214         Tri1Flags &= ~FMskBack;
3215       }
3216       else {
3217         Standard_Real  dx31  = Nod1PntX - Nod3PntX;
3218         Standard_Real  dy31  = Nod1PntY - Nod3PntY;
3219         Standard_Real  dz31  = Nod1PntZ - Nod3PntZ;
3220         Standard_Real   d31  = sqrt(dx31 * dx31 + dy31 * dy31 + dz31 * dz31);
3221         if (d31 < 1.e-10) {
3222 #ifdef DEB
3223           if (DoTrace) {
3224             cout << "HLRBRep_PolyAlgo::OrientTriangle : Flat";
3225             cout << " triangle " << iTri << endl;
3226           }
3227 #endif
3228           Tri1Flags |=  FMskFlat;
3229           Tri1Flags |=  FMskSide;
3230           Tri1Flags &= ~FMskBack;
3231         }
3232         else {
3233           dx12 /= d12;
3234           dy12 /= d12;
3235           dz12 /= d12;
3236           dx23 /= d23;
3237           dy23 /= d23;
3238           dz23 /= d23;
3239           Standard_Real  dx = dy12 * dz23 - dz12 * dy23;
3240           Standard_Real  dy = dz12 * dx23 - dx12 * dz23;
3241           Standard_Real  dz = dx12 * dy23 - dy12 * dx23;
3242           Standard_Real  d  = sqrt(dx * dx + dy * dy + dz * dz);
3243           if (d < 1.e-5) {
3244 #ifdef DEB
3245             if (DoTrace) {
3246               cout << "HLRBRep_PolyAlgo::OrientTriangle : Flat";
3247               cout << " triangle " << iTri << endl;
3248             }
3249 #endif
3250             Tri1Flags |=  FMskFlat;
3251             Tri1Flags |=  FMskSide;
3252             Tri1Flags &= ~FMskBack;
3253           }
3254           else {
3255             Standard_Real o;
3256             if (myProj.Perspective()) {
3257               dx /= d;
3258               dy /= d;
3259               dz /= d;
3260               o = (  dz * myProj.Focus()
3261                    - dx * Nod1PntX
3262                    - dy * Nod1PntY
3263                    - dz * Nod1PntZ);
3264             }
3265             else
3266               o = dz / d;
3267             if (o < 0) {
3268               Tri1Flags |=  FMskOrBack;
3269               o = -o;
3270             }
3271             else
3272               Tri1Flags &= ~FMskOrBack;
3273             if (o < 1.e-10) {
3274               Tri1Flags |=  FMskSide;
3275               Tri1Flags &= ~FMskBack;
3276             }
3277           }
3278         }
3279       }
3280     }
3281   }
3282   if ((!(Tri1Flags & FMskBack) &&  (Tri1Flags & FMskOrBack)) ||
3283       ( (Tri1Flags & FMskBack) && !(Tri1Flags & FMskOrBack)))
3284     Tri1Flags |=  FMskFrBack;
3285   else 
3286     Tri1Flags &= ~FMskFrBack;
3287 }
3288
3289 //=======================================================================
3290 //function : Triangles
3291 //purpose  : 
3292 //=======================================================================
3293
3294 Standard_Boolean
3295 HLRBRep_PolyAlgo::Triangles(const Standard_Integer ip1,
3296                             const Standard_Integer ip2,
3297                             const Standard_Address Nod1Indices,
3298                             Standard_Address& PISeg,
3299                             Standard_Integer& iTri1,
3300                             Standard_Integer& iTri2) const
3301 {
3302   Standard_Address Seg1Indices;
3303   Standard_Integer iiii = Nod1NdSg;
3304   
3305   while (iiii != 0) {
3306     Seg1Indices =
3307       ((HLRAlgo_Array1OfPISeg*)PISeg)->ChangeValue(iiii).Indices();
3308     if (Seg1LstSg1 == ip1) {
3309       if (Seg1LstSg2 == ip2) {
3310         iTri1 = Seg1Conex1;
3311         iTri2 = Seg1Conex2;
3312         return Standard_True;
3313       }
3314       else iiii = Seg1NxtSg1;
3315     }
3316     else {
3317       if (Seg1LstSg1 == ip2) {
3318         iTri1 = Seg1Conex1;
3319         iTri2 = Seg1Conex2;
3320         return Standard_True;
3321       }
3322       else iiii = Seg1NxtSg2;
3323     }
3324   }
3325   iTri1 = 0;
3326   iTri2 = 0;
3327 #ifdef DEB
3328   if (DoError) {
3329     cout << "HLRBRep_PolyAlgo::Triangles : error";
3330     cout << " between " << ip1 << " and " << ip2 << endl;
3331   }
3332 #endif
3333   return Standard_False;
3334 }
3335
3336 //=======================================================================
3337 //function : NewNode
3338 //purpose  : 
3339 //=======================================================================
3340
3341 Standard_Boolean
3342 HLRBRep_PolyAlgo::
3343 NewNode (const Standard_Address Nod1RValues,
3344          const Standard_Address Nod2RValues,
3345          Standard_Real& coef1,
3346          Standard_Boolean& moveP1) const
3347 {
3348   Standard_Real TolAng = myTolAngular * 0.5;
3349   if ((Nod1Scal >= TolAng && Nod2Scal <= -TolAng) ||
3350       (Nod2Scal >= TolAng && Nod1Scal <= -TolAng)) {
3351     coef1 = Nod1Scal / ( Nod2Scal - Nod1Scal );
3352     if (coef1 < 0) coef1 = - coef1;
3353     moveP1 = coef1 < 0.5;
3354     return Standard_True;
3355   }
3356   return Standard_False;
3357 }
3358
3359 //=======================================================================
3360 //function : UVNode
3361 //purpose  : 
3362 //=======================================================================
3363
3364 void
3365 HLRBRep_PolyAlgo::UVNode (const Standard_Address Nod1RValues,
3366                           const Standard_Address Nod2RValues,
3367                           const Standard_Real coef1,
3368                           Standard_Real& U3,
3369                           Standard_Real& V3) const
3370 {
3371   Standard_Real coef2 = 1 - coef1;
3372   U3 = Nod1PntU * coef2 + Nod2PntU * coef1;
3373   V3 = Nod1PntV * coef2 + Nod2PntV * coef1;
3374 }
3375
3376 //=======================================================================
3377 //function : CheckDegeneratedSegment
3378 //purpose  : 
3379 //=======================================================================
3380
3381 void
3382 HLRBRep_PolyAlgo::
3383 CheckDegeneratedSegment(const Standard_Address Nod1Indices,
3384                         const Standard_Address Nod1RValues,
3385                         const Standard_Address Nod2Indices,
3386                         const Standard_Address Nod2RValues) const
3387 {
3388   Nod1Flag |=  NMskFuck;
3389   Nod2Flag |=  NMskFuck;
3390   if ((Nod1Scal >= myTolAngular && Nod2Scal <= -myTolAngular) ||
3391       (Nod2Scal >= myTolAngular && Nod1Scal <= -myTolAngular)) {
3392     Nod1Scal  = 0.;
3393     Nod1Flag |= NMskOutL;
3394     Nod2Scal  = 0.;
3395     Nod2Flag |= NMskOutL;
3396   }
3397 }
3398
3399 //=======================================================================
3400 //function : UpdateOutLines
3401 //purpose  : 
3402 //=======================================================================
3403
3404 void
3405 HLRBRep_PolyAlgo::UpdateOutLines (HLRAlgo_ListOfBPoint& List,
3406                                   TColStd_Array1OfTransient& PID)
3407 {
3408   Standard_Integer f;
3409   Standard_Integer nbFace = myFMap.Extent();
3410   Standard_Real X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ;
3411   Standard_Real XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2;
3412     
3413   Handle(HLRAlgo_PolyInternalData)* pid = 
3414     (Handle(HLRAlgo_PolyInternalData)*)&(PID.ChangeValue(1));
3415
3416   for (f = 1; f <= nbFace; f++) { 
3417     if (!(*pid).IsNull()) {
3418       if ((*pid)->IntOutL()) {
3419         Standard_Address TData = &((*pid)->TData());
3420         Standard_Address PISeg = &((*pid)->PISeg());
3421         Standard_Address PINod = &((*pid)->PINod());
3422         Standard_Integer i,j,it1,it2,tn1,tn2,tn3,pd,pf;
3423         Standard_Address Seg2Indices,Tri1Indices,Tri2Indices;
3424         Standard_Boolean outl;
3425         Standard_Integer nbS = (*pid)->NbPISeg();
3426         HLRAlgo_PolyInternalSegment* psg =
3427           &(((HLRAlgo_Array1OfPISeg*)PISeg)->ChangeValue(1));
3428         
3429         for (i = 1; i <= nbS; i++) {
3430           Seg2Indices = psg->Indices();
3431           it1 = Seg2Conex1;
3432           it2 = Seg2Conex2;
3433           if (it1 != 0 && it2 != 0 && it1 != it2) {  // debile but sure !
3434             Tri1Indices = ((HLRAlgo_Array1OfTData*)TData)->
3435               ChangeValue(it1).Indices();
3436             Tri2Indices = ((HLRAlgo_Array1OfTData*)TData)->
3437               ChangeValue(it2).Indices();
3438             if      (!(Tri1Flags & FMskSide) && !(Tri2Flags & FMskSide))
3439               outl =  (Tri1Flags & FMskBack) !=  (Tri2Flags & FMskBack);
3440             else if ( (Tri1Flags & FMskSide) &&  (Tri2Flags & FMskSide))
3441               outl = Standard_False;
3442             else if (  Tri1Flags & FMskSide)
3443               outl = !(Tri1Flags & FMskFlat) && !(Tri2Flags & FMskBack);
3444             else
3445               outl = !(Tri2Flags & FMskFlat) && !(Tri1Flags & FMskBack);
3446             
3447             if (outl) {
3448               pd = Seg2LstSg1;
3449               pf = Seg2LstSg2;
3450               tn1 = Tri1Node1;
3451               tn2 = Tri1Node2;
3452               tn3 = Tri1Node3;
3453               if (!(Tri1Flags & FMskSide) && (Tri1Flags & FMskOrBack)) {
3454                 j   = tn1;
3455                 tn1 = tn3;
3456                 tn3 = j;
3457               }
3458               if      ((tn1 == pd && tn2 == pf) || (tn1 == pf && tn2 == pd))
3459                 Tri1Flags |=  EMskOutLin1;
3460               else if ((tn2 == pd && tn3 == pf) || (tn2 == pf && tn3 == pd))
3461                 Tri1Flags |=  EMskOutLin2;
3462               else if ((tn3 == pd && tn1 == pf) || (tn3 == pf && tn1 == pd))
3463                 Tri1Flags |=  EMskOutLin3;
3464 #ifdef DEB
3465               else if (DoError) {
3466                 cout << "HLRAlgo_PolyInternalData::UpdateOutLines";
3467                 cout << " : segment not found" << endl;
3468               }
3469 #endif
3470               tn1 = Tri2Node1;
3471               tn2 = Tri2Node2;
3472               tn3 = Tri2Node3;
3473               if (!(Tri2Flags & FMskSide) && (Tri2Flags & FMskOrBack)) {
3474                 j   = tn1;
3475                 tn1 = tn3;
3476                 tn3 = j;
3477               }
3478               if      ((tn1 == pd && tn2 == pf) || (tn1 == pf && tn2 == pd))
3479                 Tri2Flags |=  EMskOutLin1;
3480               else if ((tn2 == pd && tn3 == pf) || (tn2 == pf && tn3 == pd))
3481                 Tri2Flags |=  EMskOutLin2;
3482               else if ((tn3 == pd && tn1 == pf) || (tn3 == pf && tn1 == pd))
3483                 Tri2Flags |=  EMskOutLin3;
3484 #ifdef DEB
3485               else if (DoError) {
3486                 cout << "HLRAlgo_PolyInternalData::UpdateOutLines";
3487                 cout << " : segment not found" << endl;
3488               }
3489 #endif
3490               Standard_Address Nod1RValues =
3491                 ((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(pd)->RValues();
3492               Standard_Address Nod2RValues =
3493                 ((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(pf)->RValues();
3494               XTI1 = X1 = Nod1PntX;
3495               YTI1 = Y1 = Nod1PntY;
3496               ZTI1 = Z1 = Nod1PntZ;
3497               XTI2 = X2 = Nod2PntX;
3498               YTI2 = Y2 = Nod2PntY;
3499               ZTI2 = Z2 = Nod2PntZ;
3500               TIMultiply(XTI1,YTI1,ZTI1);
3501               TIMultiply(XTI2,YTI2,ZTI2);
3502               List.Append(HLRAlgo_BiPoint(XTI1,YTI1,ZTI1,XTI2,YTI2,ZTI2,
3503                                           X1  ,Y1  ,Z1  ,X2  ,Y2  ,Z2  ,
3504                                           f,f,pd,pf,f,pd,pf,12));
3505             }
3506           }
3507           psg++;
3508         }
3509       }
3510     }
3511     pid++;
3512   }
3513 }
3514
3515 //=======================================================================
3516 //function : UpdateEdgesBiPoints
3517 //purpose  : 
3518 //=======================================================================
3519
3520 void HLRBRep_PolyAlgo::
3521 UpdateEdgesBiPoints (HLRAlgo_ListOfBPoint& List,
3522                      const TColStd_Array1OfTransient& PID,
3523                      const Standard_Boolean closed)
3524 {
3525   Standard_Integer itri1,itri2,tbid;
3526   Standard_Boolean OK;
3527   HLRAlgo_ListIteratorOfListOfBPoint it;
3528   
3529   for (it.Initialize(List); it.More(); it.Next()) {      
3530     HLRAlgo_BiPoint& BP = it.Value();
3531 //    Standard_Integer i[5];
3532     Standard_Address IndexPtr = BP.Indices();
3533     if (F1Index != 0 && F2Index != 0) {
3534       const Handle(HLRAlgo_PolyInternalData)& pid1 =
3535         *(Handle(HLRAlgo_PolyInternalData)*)&(PID(F1Index));
3536       const Handle(HLRAlgo_PolyInternalData)& pid2 =
3537         *(Handle(HLRAlgo_PolyInternalData)*)&(PID(F2Index));
3538       Standard_Address PISeg1 = &pid1->PISeg();
3539       Standard_Address PISeg2 = &pid2->PISeg();
3540       Standard_Address Nod11Indices = 
3541         pid1->PINod().ChangeValue(F1Pt1Index)->Indices();
3542       Standard_Address Nod21Indices = 
3543         pid2->PINod().ChangeValue(F2Pt1Index)->Indices();
3544       OK = Triangles(F1Pt1Index,F1Pt2Index,Nod11Indices,PISeg1,itri1,tbid);
3545       OK = Triangles(F2Pt1Index,F2Pt2Index,Nod21Indices,PISeg2,itri2,tbid);
3546
3547       if (itri1 != 0 && itri2 != 0) {
3548         if (F1Index != F2Index || itri1 != itri2) {
3549           Standard_Address TData1 = &pid1->TData();
3550           Standard_Address TData2 = &pid2->TData();
3551           Standard_Address Tri1Indices =
3552             ((HLRAlgo_Array1OfTData*)TData1)->ChangeValue(itri1).Indices();
3553           Standard_Address Tri2Indices =
3554             ((HLRAlgo_Array1OfTData*)TData2)->ChangeValue(itri2).Indices();
3555           if (closed) {
3556             if (((Tri1Flags & FMskBack) && (Tri2Flags & FMskBack)) ||
3557                 ((Tri1Flags & FMskSide) && (Tri2Flags & FMskSide)) ||
3558                 ((Tri1Flags & FMskBack) && (Tri2Flags & FMskSide)) ||
3559                 ((Tri1Flags & FMskSide) && (Tri2Flags & FMskBack)))
3560               BP.Hidden(Standard_True);
3561           }
3562           Standard_Boolean outl;
3563           if      (!(Tri1Flags & FMskSide) && !(Tri2Flags & FMskSide))
3564             outl =  (Tri1Flags & FMskBack) !=  (Tri2Flags & FMskBack);
3565           else if ( (Tri1Flags & FMskSide) &&  (Tri2Flags & FMskSide))
3566             outl = Standard_False;
3567           else if ( (Tri1Flags & FMskSide))
3568             outl = !(Tri1Flags & FMskFlat) && !(Tri2Flags & FMskBack);
3569           else
3570             outl = !(Tri2Flags & FMskFlat) && !(Tri1Flags & FMskBack);
3571           BP.OutLine(outl);
3572         }
3573       }
3574 #ifdef DEB
3575       else if (DoError) {
3576         cout << "HLRBRep_PolyAlgo::UpdateEdgesBiPoints : error ";
3577         cout << " between " << F1Index << setw(6);
3578         cout << " and " << F2Index << endl;
3579       }
3580 #endif
3581     }
3582   }
3583 }
3584
3585 //=======================================================================
3586 //function : UpdatePolyData
3587 //purpose  : 
3588 //=======================================================================
3589
3590 void
3591 HLRBRep_PolyAlgo::UpdatePolyData (TColStd_Array1OfTransient& PD,
3592                                   TColStd_Array1OfTransient& PID,
3593                                   const Standard_Boolean closed)
3594 {
3595   Standard_Integer f,i;//,n[3];
3596   Handle(TColgp_HArray1OfXYZ)    HNodes;
3597   Handle(HLRAlgo_HArray1OfTData) HTData;
3598   Handle(HLRAlgo_HArray1OfPHDat) HPHDat;
3599   Standard_Integer nbFace = myFMap.Extent();
3600   Handle(HLRAlgo_PolyInternalData)* pid = 
3601     (Handle(HLRAlgo_PolyInternalData)*)&(PID.ChangeValue(1));
3602   Handle(HLRAlgo_PolyData)* pd =
3603     (Handle(HLRAlgo_PolyData)*)&(PD.ChangeValue(1));
3604
3605   for (f = 1; f <= nbFace; f++) {
3606     if (!(*pid).IsNull()) {
3607       Standard_Integer nbN = (*pid)->NbPINod();
3608       Standard_Integer nbT = (*pid)->NbTData();
3609       HNodes = new TColgp_HArray1OfXYZ   (1,nbN);
3610       HTData = new HLRAlgo_HArray1OfTData(1,nbT);
3611       TColgp_Array1OfXYZ&    Nodes = HNodes->ChangeArray1();
3612       HLRAlgo_Array1OfTData& Trian = HTData->ChangeArray1();
3613       Standard_Address TData = &(*pid)->TData();
3614       Standard_Address PINod = &(*pid)->PINod();
3615       Standard_Integer nbHide = 0;
3616       Handle(HLRAlgo_PolyInternalNode)* ON = 
3617         &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(1));
3618       gp_XYZ                          * NN = &(Nodes.ChangeValue(1));
3619       
3620       for (i = 1; i <= nbN; i++) {
3621         const Standard_Address Nod1RValues = (*ON)->RValues();
3622         NN->SetCoord(Nod1PntX,Nod1PntY,Nod1PntZ);
3623         ON++;
3624         NN++;
3625       }
3626       
3627       HLRAlgo_TriangleData* OT =
3628         &(((HLRAlgo_Array1OfTData*)TData)->ChangeValue(1));
3629       HLRAlgo_TriangleData* NT = &(Trian.ChangeValue(1));
3630       Standard_Address Tri1Indices,Tri2Indices;
3631       
3632       for (i = 1; i <= nbT; i++) {
3633         Tri1Indices = OT->Indices();
3634         Tri2Indices = NT->Indices();
3635         if (!(Tri1Flags & FMskSide)) {
3636 #ifdef DEB
3637           if ((Tri1Flags & FMskFrBack) && DoTrace) {
3638             cout << "HLRBRep_PolyAlgo::ReverseBackTriangle :";
3639             cout << " face " << f << setw(6);
3640             cout << " triangle " << i << endl;
3641           }
3642 #endif
3643           if (Tri1Flags & FMskOrBack) {
3644             Standard_Integer j = Tri1Node1;
3645             Tri1Node1          = Tri1Node3;
3646             Tri1Node3          = j;
3647             Tri1Flags |=  FMskBack;
3648           }
3649           else
3650             Tri1Flags &= ~FMskBack;
3651             //Tri1Flags |= FMskBack;//OCC349
3652         }
3653         Tri2Node1 = Tri1Node1;
3654         Tri2Node2 = Tri1Node2;
3655         Tri2Node3 = Tri1Node3;
3656         Tri2Flags = Tri1Flags;
3657         if (!(Tri2Flags & FMskSide) &&
3658             (!(Tri2Flags & FMskBack) || !closed)) {
3659           Tri2Flags |=  FMskHiding;
3660           nbHide++;
3661         }
3662         else
3663           Tri2Flags &= ~FMskHiding;
3664         OT++;
3665         NT++;
3666       }
3667       if (nbHide > 0) HPHDat = new HLRAlgo_HArray1OfPHDat(1,nbHide);
3668       else            HPHDat.Nullify();
3669       (*pd)->HNodes(HNodes);
3670       (*pd)->HTData(HTData);
3671       (*pd)->HPHDat(HPHDat);
3672       (*pd)->FaceIndex(f);
3673     }
3674     pid++;
3675     pd++;
3676   }
3677 }
3678
3679 //=======================================================================
3680 //function : TMultiply
3681 //purpose  : 
3682 //=======================================================================
3683
3684 void
3685 HLRBRep_PolyAlgo::TMultiply (Standard_Real& X,
3686                              Standard_Real& Y,
3687                              Standard_Real& Z,
3688                              const Standard_Boolean VPO) const
3689 {
3690   Standard_Real Xt = TMat[0][0]*X + TMat[0][1]*Y + TMat[0][2]*Z + (VPO ? 0 : TLoc[0]);//OCC349
3691   Standard_Real Yt = TMat[1][0]*X + TMat[1][1]*Y + TMat[1][2]*Z + (VPO ? 0 : TLoc[1]);//OCC349
3692   Z                = TMat[2][0]*X + TMat[2][1]*Y + TMat[2][2]*Z + (VPO ? 0 : TLoc[2]);//OCC349
3693   X                = Xt;
3694   Y                = Yt;
3695 }
3696
3697 //=======================================================================
3698 //function : TTMultiply
3699 //purpose  : 
3700 //=======================================================================
3701
3702 void
3703 HLRBRep_PolyAlgo::TTMultiply (Standard_Real& X,
3704                               Standard_Real& Y,
3705                               Standard_Real& Z,
3706                               const Standard_Boolean VPO) const
3707 {
3708   Standard_Real Xt = TTMa[0][0]*X + TTMa[0][1]*Y + TTMa[0][2]*Z + (VPO ? 0 : TTLo[0]);//OCC349
3709   Standard_Real Yt = TTMa[1][0]*X + TTMa[1][1]*Y + TTMa[1][2]*Z + (VPO ? 0 : TTLo[1]);//OCC349
3710   Z                = TTMa[2][0]*X + TTMa[2][1]*Y + TTMa[2][2]*Z + (VPO ? 0 : TTLo[2]);//OCC349
3711   X                = Xt;
3712   Y                = Yt;
3713 }
3714
3715 //=======================================================================
3716 //function : TIMultiply
3717 //purpose  : 
3718 //=======================================================================
3719
3720 void
3721 HLRBRep_PolyAlgo::TIMultiply (Standard_Real& X,
3722                               Standard_Real& Y,
3723                               Standard_Real& Z,
3724                               const Standard_Boolean VPO) const
3725 {
3726   Standard_Real Xt = TIMa[0][0]*X + TIMa[0][1]*Y + TIMa[0][2]*Z + (VPO ? 0 : TILo[0]);//OCC349
3727   Standard_Real Yt = TIMa[1][0]*X + TIMa[1][1]*Y + TIMa[1][2]*Z + (VPO ? 0 : TILo[1]);//OCC349
3728   Z                = TIMa[2][0]*X + TIMa[2][1]*Y + TIMa[2][2]*Z + (VPO ? 0 : TILo[2]);//OCC349
3729   X                = Xt;
3730   Y                = Yt;
3731 }
3732
3733 //=======================================================================
3734 //function : Hide
3735 //purpose  : 
3736 //=======================================================================
3737
3738 void HLRBRep_PolyAlgo::Hide (Standard_Address& Coordinates,
3739                              HLRAlgo_EdgeStatus& status,
3740                              TopoDS_Shape& S,
3741                              Standard_Boolean& reg1,
3742                              Standard_Boolean& regn,
3743                              Standard_Boolean& outl,
3744                              Standard_Boolean& intl)
3745 {
3746   Standard_Integer index;
3747   myAlgo->Hide(Coordinates,status,index,reg1,regn,outl,intl);
3748   if (intl) S = myFMap(index);
3749   else      S = myEMap(index);
3750 }
3751
3752 //=======================================================================
3753 //function : Show
3754 //purpose  : 
3755 //=======================================================================
3756
3757 void HLRBRep_PolyAlgo::Show (Standard_Address& Coordinates,
3758                              TopoDS_Shape& S,
3759                              Standard_Boolean& reg1,
3760                              Standard_Boolean& regn,
3761                              Standard_Boolean& outl,
3762                              Standard_Boolean& intl)
3763 {
3764   Standard_Integer index;
3765   myAlgo->Show(Coordinates,index,reg1,regn,outl,intl);
3766   if (intl) S = myFMap(index);
3767   else      S = myEMap(index);
3768 }
3769
3770 //=======================================================================
3771 //function : OutLinedShape
3772 //purpose  : 
3773 //=======================================================================
3774
3775 TopoDS_Shape
3776 HLRBRep_PolyAlgo::OutLinedShape (const TopoDS_Shape& S) const
3777 {
3778   TopoDS_Shape Result;
3779
3780   if (!S.IsNull()) {
3781     BRep_Builder B;
3782     B.MakeCompound(TopoDS::Compound(Result));
3783     B.Add(Result,S);
3784
3785     TopTools_MapOfShape Map;
3786     TopExp_Explorer ex;
3787     for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next())
3788       Map.Add(ex.Current());
3789     for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next())
3790       Map.Add(ex.Current());
3791
3792     Standard_Integer nbFace = myFMap.Extent();
3793     if (nbFace > 0) {
3794       TopTools_Array1OfShape NewF(1,nbFace);
3795       TColStd_Array1OfTransient& Shell = myAlgo->PolyShell();
3796       Standard_Integer nbShell = Shell.Upper();
3797       HLRAlgo_ListIteratorOfListOfBPoint it;
3798       
3799       for (Standard_Integer iShell = 1; iShell <= nbShell; iShell++) {
3800         HLRAlgo_ListOfBPoint& List =
3801           (*(Handle(HLRAlgo_PolyShellData)*)&(Shell(iShell)))->Edges();
3802         
3803         for (it.Initialize(List); it.More(); it.Next()) {
3804           HLRAlgo_BiPoint& BP = it.Value();
3805           if (BP.IntLine()) {
3806             Standard_Address IndexPtr = BP.Indices();
3807             if (Map.Contains(myFMap(ShapeIndex))) {
3808               Standard_Address Coordinates = BP.Coordinates();
3809               B.Add(Result,BRepLib_MakeEdge
3810                     (gp_Pnt(PntXTI1,PntYTI1,PntZTI1),
3811                      gp_Pnt(PntXTI2,PntYTI2,PntZTI2)));
3812             }
3813           }
3814         }
3815       }
3816     }    
3817   }
3818   return Result;
3819 }
3820