0030895: Coding Rules - specify std namespace explicitly for std::cout and streams
[occt.git] / src / HLRAlgo / HLRAlgo_PolyInternalData.cxx
1 // Created on: 1995-07-11
2 // Created by: Christophe MARION
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <HLRAlgo_BiPoint.hxx>
19 #include <HLRAlgo_PolyInternalData.hxx>
20 #include <Standard_Stream.hxx>
21 #include <Standard_Type.hxx>
22
23 IMPLEMENT_STANDARD_RTTIEXT(HLRAlgo_PolyInternalData,Standard_Transient)
24
25 #ifdef OCCT_DEBUG
26 static Standard_Integer HLRAlgo_PolyInternalData_TRACE = Standard_False;
27 static Standard_Integer HLRAlgo_PolyInternalData_ERROR = Standard_False;
28 #endif
29 //=======================================================================
30 //function : PolyInternalData
31 //purpose  : 
32 //=======================================================================
33
34 HLRAlgo_PolyInternalData::HLRAlgo_PolyInternalData
35 (const Standard_Integer nbNod,
36  const Standard_Integer nbTri) :
37  myNbTData(nbTri),
38  myNbPISeg(0),
39  myNbPINod(nbNod),
40  myMxTData(nbTri),
41  myMxPINod(nbNod),
42  myIntOutL(Standard_False),
43  myPlanar(Standard_False)
44 {
45   Standard_Integer i;
46   myMxPISeg = 2 + (3 * nbTri + nbNod) / 2;
47   myTData = new HLRAlgo_HArray1OfTData(0,myMxTData);
48   myPISeg = new HLRAlgo_HArray1OfPISeg(0,myMxPISeg);
49   myPINod = new HLRAlgo_HArray1OfPINod(0,myMxPINod);
50   
51   HLRAlgo_Array1OfPINod& PINod = myPINod->ChangeArray1();
52   Handle(HLRAlgo_PolyInternalNode)* NN = &(PINod.ChangeValue(1));
53
54   for (i = 1; i <= myMxPINod; i++) {
55     *NN = new HLRAlgo_PolyInternalNode();
56     NN++;
57   }
58 }
59
60 //=======================================================================
61 //function : UpdateLinks
62 //purpose  : 
63 //=======================================================================
64
65 void HLRAlgo_PolyInternalData::UpdateLinks
66 (HLRAlgo_Array1OfTData*& TData,
67  HLRAlgo_Array1OfPISeg*& PISeg,
68  HLRAlgo_Array1OfPINod*& PINod)
69 {
70   Standard_Integer i,n1,n2;
71   Standard_Integer find,iiii,icsv = 0;
72   HLRAlgo_PolyInternalSegment* aSegIndices = NULL;
73
74   Standard_Boolean newSeg = Standard_False;
75   HLRAlgo_TriangleData* TD =
76     &(((HLRAlgo_Array1OfTData*)TData)->ChangeValue(1));
77   
78   for (i = 1; i <= myNbTData; i++) {
79     HLRAlgo_PolyInternalNode::NodeIndices& A1 =
80       PINod->ChangeValue(TD->Node1)->Indices();
81     HLRAlgo_PolyInternalNode::NodeIndices& A2 =
82       PINod->ChangeValue(TD->Node2)->Indices();
83     HLRAlgo_PolyInternalNode::NodeIndices& A3 =
84       PINod->ChangeValue(TD->Node3)->Indices();
85
86     {
87     n1 = TD->Node1;
88     n2 = TD->Node2;
89     newSeg = Standard_False;
90     if (A1.NdSg == 0 && A2.NdSg == 0) {
91       newSeg = Standard_True;
92       myNbPISeg++;
93       A1.NdSg = myNbPISeg;
94       A2.NdSg = myNbPISeg;
95     }
96     else {
97       iiii = A1.NdSg;
98       if (iiii != 0) {
99         find = 0;
100         
101         while (iiii != 0 && find == 0) {
102           aSegIndices = &PISeg->ChangeValue(iiii);
103           if (aSegIndices->LstSg1 == n1) {
104             if (aSegIndices->LstSg2 == n2) find = iiii;
105             else                  iiii = aSegIndices->NxtSg1;
106             icsv = 1;
107           }
108           else {
109             if (aSegIndices->LstSg1 == n2) find = iiii;
110             else                  iiii = aSegIndices->NxtSg2;
111             icsv = 2;
112           }
113         }
114         if (find == 0) {
115           newSeg = Standard_True;
116           myNbPISeg++;
117           if (icsv == 1) aSegIndices->NxtSg1 = myNbPISeg;
118           else           aSegIndices->NxtSg2 = myNbPISeg;
119         }
120         else aSegIndices->Conex2 = i;
121       }
122       else {
123         newSeg = Standard_True;
124         myNbPISeg++;
125         A1.NdSg = myNbPISeg;
126       }
127       if (newSeg) {
128         iiii = A2.NdSg;
129         if (iiii != 0) {
130           
131           while (iiii != 0) {
132             aSegIndices = &PISeg->ChangeValue(iiii);
133             if (aSegIndices->LstSg1 == n2) { icsv = 1; iiii = aSegIndices->NxtSg1; }
134             else                  { icsv = 2; iiii = aSegIndices->NxtSg2; }
135           }
136           if (icsv == 1) aSegIndices->NxtSg1 = myNbPISeg;
137           else           aSegIndices->NxtSg2 = myNbPISeg;
138         }
139         else A2.NdSg = myNbPISeg;
140       }
141     }
142     if (newSeg) {
143       aSegIndices = &PISeg->ChangeValue(myNbPISeg);
144       aSegIndices->LstSg1 = n1;
145       aSegIndices->LstSg2 = n2;
146       aSegIndices->Conex1 = i;
147       aSegIndices->Conex2 = 0;
148       aSegIndices->NxtSg1 = 0;
149       aSegIndices->NxtSg2 = 0;
150     }
151     }
152
153     {
154     n1 = TD->Node2;
155     n2 = TD->Node3;
156     newSeg = Standard_False;
157     if (A2.NdSg == 0 && A3.NdSg == 0) {
158       newSeg = Standard_True;
159       myNbPISeg++;
160       A2.NdSg = myNbPISeg;
161       A3.NdSg = myNbPISeg;
162     }
163     else {
164       iiii = A2.NdSg;
165       if (iiii != 0) {
166         find = 0;
167         
168         while (iiii != 0 && find == 0) {
169     aSegIndices = &PISeg->ChangeValue(iiii);
170           if (aSegIndices->LstSg1 == n1) {
171             if (aSegIndices->LstSg2 == n2) find = iiii;
172             else                  iiii = aSegIndices->NxtSg1;
173             icsv = 1;
174           }
175           else {
176             if (aSegIndices->LstSg1 == n2) find = iiii;
177             else                  iiii = aSegIndices->NxtSg2;
178             icsv = 2;
179           }
180         }
181         if (find == 0) {
182           newSeg = Standard_True;
183           myNbPISeg++;
184           if (icsv == 1) aSegIndices->NxtSg1 = myNbPISeg;
185           else           aSegIndices->NxtSg2 = myNbPISeg;
186         }
187         else aSegIndices->Conex2 = i;
188       }
189       else {
190         newSeg = Standard_True;
191         myNbPISeg++;
192         A2.NdSg = myNbPISeg;
193       }
194       if (newSeg) {
195         iiii = A3.NdSg;
196         if (iiii != 0) {
197           
198           while (iiii != 0) {
199       aSegIndices = &PISeg->ChangeValue(iiii);
200             if (aSegIndices->LstSg1 == n2) { icsv = 1; iiii = aSegIndices->NxtSg1; }
201             else                  { icsv = 2; iiii = aSegIndices->NxtSg2; }
202           }
203           if (icsv == 1) aSegIndices->NxtSg1 = myNbPISeg;
204           else           aSegIndices->NxtSg2 = myNbPISeg;
205         }
206         else A3.NdSg = myNbPISeg;
207       }
208     }
209     if (newSeg) {
210       aSegIndices = &PISeg->ChangeValue(myNbPISeg);
211       aSegIndices->LstSg1 = n1;
212       aSegIndices->LstSg2 = n2;
213       aSegIndices->Conex1 = i;
214       aSegIndices->Conex2 = 0;
215       aSegIndices->NxtSg1 = 0;
216       aSegIndices->NxtSg2 = 0;
217     }
218     }
219
220     {
221     n1 = TD->Node3;
222     n2 = TD->Node1;
223     newSeg = Standard_False;
224     if (A3.NdSg == 0 && A1.NdSg == 0) {
225       newSeg = Standard_True;
226       myNbPISeg++;
227       A3.NdSg = myNbPISeg;
228       A1.NdSg = myNbPISeg;
229     }
230     else {
231       iiii = A3.NdSg;
232       if (iiii != 0) {
233         find = 0;
234         
235         while (iiii != 0 && find == 0) {
236     aSegIndices = &PISeg->ChangeValue(iiii);
237           if (aSegIndices->LstSg1 == n1) {
238             if (aSegIndices->LstSg2 == n2) find = iiii;
239             else                  iiii = aSegIndices->NxtSg1;
240             icsv = 1;
241           }
242           else {
243             if (aSegIndices->LstSg1 == n2) find = iiii;
244             else                  iiii = aSegIndices->NxtSg2;
245             icsv = 2;
246           }
247         }
248         if (find == 0) {
249           newSeg = Standard_True;
250           myNbPISeg++;
251           if (icsv == 1) aSegIndices->NxtSg1 = myNbPISeg;
252           else           aSegIndices->NxtSg2 = myNbPISeg;
253         }
254         else aSegIndices->Conex2 = i;
255       }
256       else {
257         newSeg = Standard_True;
258         myNbPISeg++;
259         A3.NdSg = myNbPISeg;
260       }
261       if (newSeg) {
262         iiii = A1.NdSg;
263         if (iiii != 0) {
264           
265           while (iiii != 0) {
266       aSegIndices = &PISeg->ChangeValue(iiii);
267             if (aSegIndices->LstSg1 == n2) { icsv = 1; iiii = aSegIndices->NxtSg1; }
268             else                  { icsv = 2; iiii = aSegIndices->NxtSg2; }
269           }
270           if (icsv == 1) aSegIndices->NxtSg1 = myNbPISeg;
271           else           aSegIndices->NxtSg2 = myNbPISeg;
272         }
273         else A1.NdSg = myNbPISeg;
274       }
275     }
276     if (newSeg) {
277       aSegIndices = &PISeg->ChangeValue(myNbPISeg);
278       aSegIndices->LstSg1 = n1;
279       aSegIndices->LstSg2 = n2;
280       aSegIndices->Conex1 = i;
281       aSegIndices->Conex2 = 0;
282       aSegIndices->NxtSg1 = 0;
283       aSegIndices->NxtSg2 = 0;
284     }
285     }
286     TD++;
287   }
288 }
289
290 //=======================================================================
291 //function : AddNode
292 //purpose  : 
293 //=======================================================================
294
295 Standard_Integer
296 HLRAlgo_PolyInternalData::AddNode (
297   HLRAlgo_PolyInternalNode::NodeData& Nod1RValues,
298   HLRAlgo_PolyInternalNode::NodeData& Nod2RValues,
299   HLRAlgo_Array1OfPINod*& PINod1,
300   HLRAlgo_Array1OfPINod*& PINod2,
301   const Standard_Real coef1,
302   const Standard_Real X3,
303   const Standard_Real Y3,
304   const Standard_Real Z3)
305 {
306   Standard_Real coef2 = 1 - coef1;
307   IncPINod(PINod1,PINod2);
308   Standard_Integer ip3 = myNbPINod;
309   Handle(HLRAlgo_PolyInternalNode)* pip3 = 
310     &(((HLRAlgo_Array1OfPINod*)PINod1)->ChangeValue(ip3));
311   *pip3 = new HLRAlgo_PolyInternalNode();
312   HLRAlgo_PolyInternalNode::NodeData& Nod3RValues = (*pip3)->Data();
313   HLRAlgo_PolyInternalNode::NodeIndices& aNodeIndices = (*pip3)->Indices();
314   aNodeIndices.NdSg = 0;
315   aNodeIndices.Flag = 0;
316   Nod3RValues.Point = gp_XYZ(X3, Y3, Z3);
317   Nod3RValues.UV = coef2 * Nod1RValues.UV + coef1 * Nod2RValues.UV;
318   Nod3RValues.Scal = Nod1RValues.Scal * coef2 + Nod2RValues.Scal * coef1;
319   const gp_XYZ aXYZ = coef2 * Nod1RValues.Normal + coef1 * Nod2RValues.Normal;
320   const Standard_Real aNorm = aXYZ.Modulus();
321
322   if (aNorm > 0) {
323     Nod3RValues.Normal = (1 / aNorm) * aXYZ;
324   }
325   else {
326     Nod3RValues.Normal = gp_XYZ(1., 0., 0.);
327 #ifdef OCCT_DEBUG
328     if (HLRAlgo_PolyInternalData_ERROR)
329       std::cout << "HLRAlgo_PolyInternalData::AddNode" << std::endl;
330 #endif
331   }
332   return ip3;
333 }
334
335 //=======================================================================
336 //function : UpdateLinks
337 //purpose  : 
338 //=======================================================================
339
340 void
341 HLRAlgo_PolyInternalData::UpdateLinks (const Standard_Integer ip1,
342                                        const Standard_Integer ip2,
343                                        const Standard_Integer ip3,
344                                        HLRAlgo_Array1OfTData*& TData1,
345                                        HLRAlgo_Array1OfTData*& TData2,
346                                        HLRAlgo_Array1OfPISeg*& PISeg1,
347                                        HLRAlgo_Array1OfPISeg*& PISeg2,
348                                        HLRAlgo_Array1OfPINod*& PINod1,
349                                        HLRAlgo_Array1OfPINod*& )
350 {
351   Standard_Integer find,iiii,iisv,icsv,iip2 =0,cnx1 =0,cnx2 =0;
352   HLRAlgo_PolyInternalSegment* aSegIndices = NULL;
353   HLRAlgo_PolyInternalSegment* aSegIndices2 = NULL;
354   find = 0;
355   iisv = 0;
356   icsv = 0;
357   IncPISeg(PISeg1,PISeg2);
358   IncPISeg(PISeg1,PISeg2);
359   IncPISeg(PISeg1,PISeg2);
360   myNbPISeg--;
361   myNbPISeg--;
362   IncTData(TData1,TData2);
363   IncTData(TData1,TData2);
364   myNbTData--;
365   myNbTData--;
366   HLRAlgo_PolyInternalNode::NodeIndices* aNodIndices1 =
367     &PINod1->ChangeValue(ip1)->Indices();
368   HLRAlgo_PolyInternalNode::NodeIndices& aNodIndices2 =
369     PINod1->ChangeValue(ip2)->Indices();
370   HLRAlgo_PolyInternalNode::NodeIndices& aNodIndices3 =
371     PINod1->ChangeValue(ip3)->Indices();
372   iiii = aNodIndices2.NdSg;
373   
374   while (iiii != 0 && find == 0) {
375     aSegIndices2 = &PISeg1->ChangeValue(iiii);
376     if (aSegIndices2->LstSg1 == ip2) {
377       if (aSegIndices2->LstSg2 == ip1) {
378         find = iiii;
379         cnx1 = aSegIndices2->Conex1;
380         cnx2 = aSegIndices2->Conex2;
381         aSegIndices2->LstSg1 = ip3;
382         iip2 = aSegIndices2->NxtSg1;
383         aSegIndices2->NxtSg1 = myNbPISeg;
384         if      (iisv == 0) aNodIndices2.NdSg   = myNbPISeg;
385         else if (icsv == 1) aSegIndices->NxtSg1 = myNbPISeg;
386         else                aSegIndices->NxtSg2 = myNbPISeg;
387       }
388       else { 
389         iisv = iiii;
390         icsv = 1;
391       }
392       iiii = aSegIndices2->NxtSg1;
393     }
394     else {
395       if (aSegIndices2->LstSg1 == ip1) {
396         find = iiii;
397         cnx1 = aSegIndices2->Conex1;
398         cnx2 = aSegIndices2->Conex2;
399         aSegIndices2->LstSg2 = ip3;
400         iip2 = aSegIndices2->NxtSg2;
401         aSegIndices2->NxtSg2 = myNbPISeg;
402         if      (iisv == 0) aNodIndices2.NdSg   = myNbPISeg;
403         else if (icsv == 1) aSegIndices->NxtSg1 = myNbPISeg;
404         else                aSegIndices->NxtSg2 = myNbPISeg;
405       }
406       else { 
407         iisv = iiii;
408         icsv = 2;
409       }
410       iiii = aSegIndices2->NxtSg2;
411     }
412     aSegIndices = aSegIndices2;
413   }
414   if (find == 0) {
415     myNbPISeg--;
416 #ifdef OCCT_DEBUG
417     if (HLRAlgo_PolyInternalData_ERROR) {
418       std::cout << "HLRAlgo_PolyInternalData::UpdateLinks : segment error";
419       std::cout << std::endl;
420     }
421 #endif
422   }
423   else {
424     aSegIndices2 = &PISeg1->ChangeValue(myNbPISeg);
425     aSegIndices2->NxtSg1 = 0;
426     aSegIndices2->NxtSg2 = iip2;
427     aSegIndices2->LstSg1 = ip3;
428     aSegIndices2->LstSg2 = ip2;
429     aSegIndices2->Conex1 = cnx1;
430     aSegIndices2->Conex2 = cnx2;
431     aNodIndices3.NdSg   = find;
432
433     Standard_Integer iOld,iNew,iTr,skip,ip4,itpk[2];
434     Standard_Integer n1,n2,n3,nOld[3],nNew[3],New[4];
435     New[0] = cnx1;
436     New[2] = myNbTData + 1;
437     if (cnx2 == 0) {
438       New[1] = 0;
439       New[3] = 0;
440     }
441     else {
442       New[1] = cnx2;
443       New[3] = myNbTData + 2;
444     }
445     
446     for (skip = 0; skip <= 1; skip++) {
447       iOld = New[skip];
448       iNew = New[skip + 2];
449       if (iOld != 0) {
450   HLRAlgo_TriangleData& aTriangle = TData1->ChangeValue(iOld);
451   HLRAlgo_TriangleData& aTriangle2 = TData1->ChangeValue(iNew);
452         n1 = aTriangle.Node1;
453         n2 = aTriangle.Node2;
454         n3 = aTriangle.Node3;
455         nOld[0] = n1;
456         nOld[1] = n2;
457         nOld[2] = n3;
458         nNew[0] = n1;
459         nNew[1] = n2;
460         nNew[2] = n3;
461         Standard_Boolean found = Standard_False;
462         if      (n1 == ip1 && n2 == ip2) {
463           found = Standard_True;
464           nOld[1] = ip3;
465           nNew[0] = ip3;
466           itpk[skip] = n3;
467         }
468         else if (n1 == ip2 && n2 == ip1) {
469           found = Standard_True;
470           nOld[0] = ip3;
471           nNew[1] = ip3;
472           itpk[skip] = n3;
473         }
474         else if (n2 == ip1 && n3 == ip2) {
475           found = Standard_True;
476           nOld[2] = ip3;
477           nNew[1] = ip3;
478           itpk[skip] = n1;
479         }
480         else if (n2 == ip2 && n3 == ip1) {
481           found = Standard_True;
482           nOld[1] = ip3;
483           nNew[2] = ip3;
484           itpk[skip] = n1;
485         }
486         else if (n3 == ip1 && n1 == ip2) {
487           found = Standard_True;
488           nOld[0] = ip3;
489           nNew[2] = ip3;
490           itpk[skip] = n2;
491         }
492         else if (n3 == ip2 && n1 == ip1) {
493           found = Standard_True;
494           nOld[2] = ip3;
495           nNew[0] = ip3;
496           itpk[skip] = n2;
497         }
498         if (found) {
499           myNbTData++;
500           ip4 = itpk[skip];
501           HLRAlgo_PolyInternalNode::NodeIndices& aNodIndices4 =
502       PINod1->ChangeValue(ip4)->Indices();
503           aTriangle.Node1 = nOld[0];
504           aTriangle.Node2 = nOld[1];
505           aTriangle.Node3 = nOld[2];
506           aTriangle2.Node1 = nNew[0];
507           aTriangle2.Node2 = nNew[1];
508           aTriangle2.Node3 = nNew[2];
509           aTriangle2.Flags = aTriangle.Flags;
510           myNbPISeg++;
511     aSegIndices2 = &PISeg1->ChangeValue(myNbPISeg);
512           aSegIndices2->LstSg1 = ip3;
513           aSegIndices2->LstSg2 = ip4;
514           aSegIndices2->NxtSg1 = aNodIndices3.NdSg;
515           aSegIndices2->NxtSg2 = aNodIndices4.NdSg;
516           aSegIndices2->Conex1 = iOld;
517           aSegIndices2->Conex2 = iNew;
518           aNodIndices3.NdSg   = myNbPISeg;
519           aNodIndices4.NdSg   = myNbPISeg;
520         }
521 #ifdef OCCT_DEBUG
522         else if (HLRAlgo_PolyInternalData_ERROR) {
523           std::cout << "HLRAlgo_PolyInternalData::UpdateLinks : triangle error ";
524           std::cout << std::endl;
525         }
526 #endif
527       }
528     }
529     
530     for (iTr = 0; iTr <= 3; iTr++) {
531       iNew = New [iTr];
532       if (iTr < 2) skip = iTr;
533       else         skip = iTr - 2;
534       iOld = New [skip];
535       ip4  = itpk[skip];
536       if (iNew != 0) {
537   HLRAlgo_TriangleData& aTriangle2 = TData1->ChangeValue(iNew);
538         n1 = aTriangle2.Node1;
539         n2 = aTriangle2.Node2;
540         n3 = aTriangle2.Node3;
541         
542         if (!((n1 == ip3 && n2 == ip4) ||
543               (n2 == ip3 && n1 == ip4))) {
544           Standard_Boolean found = Standard_False;
545     aNodIndices1 = &PINod1->ChangeValue(n1)->Indices();
546           iiii = aNodIndices1->NdSg;
547           
548           while (iiii != 0 && !found) {
549       aSegIndices2 = &PISeg1->ChangeValue(iiii);
550             if (aSegIndices2->LstSg1 == n1) {
551               if (aSegIndices2->LstSg2 == n2) {
552                 found = Standard_True;
553                 if      (aSegIndices2->Conex1 == iOld) aSegIndices2->Conex1 = iNew;
554                 else if (aSegIndices2->Conex2 == iOld) aSegIndices2->Conex2 = iNew;
555               }
556               else iiii = aSegIndices2->NxtSg1;
557             }
558             else {
559               if (aSegIndices2->LstSg1 == n2) {
560                 found = Standard_True;
561                 if      (aSegIndices2->Conex1 == iOld) aSegIndices2->Conex1 = iNew;
562                 else if (aSegIndices2->Conex2 == iOld) aSegIndices2->Conex2 = iNew;
563               }
564               else iiii = aSegIndices2->NxtSg2;
565             }
566           }
567         }
568         
569         if (!((n2 == ip3 && n3 == ip4) ||
570               (n3 == ip3 && n2 == ip4))) {
571           Standard_Boolean found = Standard_False;
572     aNodIndices1 = &PINod1->ChangeValue(n2)->Indices();
573           iiii = aNodIndices1->NdSg;
574           
575           while (iiii != 0 && !found) {
576       aSegIndices2 = &PISeg1->ChangeValue(iiii);
577             if (aSegIndices2->LstSg1 == n2) {
578               if (aSegIndices2->LstSg2 == n3) {
579                 found = Standard_True;
580                 if      (aSegIndices2->Conex1 == iOld) aSegIndices2->Conex1 = iNew;
581                 else if (aSegIndices2->Conex2 == iOld) aSegIndices2->Conex2 = iNew;
582               }
583               else iiii = aSegIndices2->NxtSg1;
584             }
585             else {
586               if (aSegIndices2->LstSg1 == n3) {
587                 found = Standard_True;
588                 if      (aSegIndices2->Conex1 == iOld) aSegIndices2->Conex1 = iNew;
589                 else if (aSegIndices2->Conex2 == iOld) aSegIndices2->Conex2 = iNew;
590               }
591               else iiii = aSegIndices2->NxtSg2;
592             }
593           }
594         }
595
596         if (!((n3 == ip3 && n1 == ip4) ||
597               (n1 == ip3 && n3 == ip4))) {
598           Standard_Boolean found = Standard_False;
599     aNodIndices1 = &PINod1->ChangeValue(n3)->Indices();
600           iiii = aNodIndices1->NdSg;
601           
602           while (iiii != 0 && !found) {
603       aSegIndices2 = &PISeg1->ChangeValue(iiii);
604             if (aSegIndices2->LstSg1 == n3) {
605               if (aSegIndices2->LstSg2 == n1) {
606                 found = Standard_True;
607                 if      (aSegIndices2->Conex1 == iOld) aSegIndices2->Conex1 = iNew;
608                 else if (aSegIndices2->Conex2 == iOld) aSegIndices2->Conex2 = iNew;
609               }
610               else iiii = aSegIndices2->NxtSg1;
611             }
612             else {
613               if (aSegIndices2->LstSg1 == n1) {
614                 found = Standard_True;
615                 if      (aSegIndices2->Conex1 == iOld) aSegIndices2->Conex1 = iNew;
616                 else if (aSegIndices2->Conex2 == iOld) aSegIndices2->Conex2 = iNew;
617               }
618               else iiii = aSegIndices2->NxtSg2;
619             }
620           }
621         }
622       }
623     }
624   }
625 }
626
627 //=======================================================================
628 //function : Dump
629 //purpose  : 
630 //=======================================================================
631
632 void HLRAlgo_PolyInternalData::Dump () const
633 {
634   Standard_Integer i;//,i1,i2,i3;
635   HLRAlgo_Array1OfTData* TData = &myTData->ChangeArray1();
636   HLRAlgo_Array1OfPISeg* PISeg = &myPISeg->ChangeArray1();
637   HLRAlgo_Array1OfPINod* PINod = &myPINod->ChangeArray1();
638   
639   for (i = 1; i <= myNbPINod; i++) {
640     const Handle(HLRAlgo_PolyInternalNode)* pi = &PINod->ChangeValue(i);
641     HLRAlgo_PolyInternalNode::NodeIndices& aNodIndices1 = (*pi)->Indices();
642     HLRAlgo_PolyInternalNode::NodeData& Nod1RValues = (*pi)->Data();
643     std::cout << "Node " << std::setw(6) << i << " : ";
644     std::cout << std::setw(6) << aNodIndices1.NdSg;
645     std::cout << std::setw(20)<< Nod1RValues.Point.X();
646     std::cout << std::setw(20)<< Nod1RValues.Point.Y();
647     std::cout << std::setw(20)<< Nod1RValues.Point.Z();
648     std::cout << std::endl;
649   }
650
651   for (i = 1; i <= myNbPISeg; i++) {
652     HLRAlgo_PolyInternalSegment* aSegIndices = &PISeg->ChangeValue(i);
653     std::cout << "Segment " << std::setw(6) << i << " : ";
654     std::cout << std::setw(6) << aSegIndices->LstSg1;
655     std::cout << std::setw(6) << aSegIndices->LstSg2;
656     std::cout << std::setw(6) << aSegIndices->NxtSg1;
657     std::cout << std::setw(6) << aSegIndices->NxtSg2;
658     std::cout << std::setw(6) << aSegIndices->Conex1;
659     std::cout << std::setw(6) << aSegIndices->Conex2;
660     std::cout << std::endl;
661   }
662
663   for (i = 1; i <= myNbTData; i++) {
664     HLRAlgo_TriangleData& aTriangle = TData->ChangeValue(i);
665     std::cout << "Triangle " << std::setw(6) << i << " : ";
666     std::cout << std::setw(6) << aTriangle.Node1;
667     std::cout << std::setw(6) << aTriangle.Node2;
668     std::cout << std::setw(6) << aTriangle.Node3;
669     std::cout << std::endl;
670   }
671 }
672
673 //=======================================================================
674 //function : IncTData
675 //purpose  : 
676 //=======================================================================
677
678 void HLRAlgo_PolyInternalData::IncTData(
679   HLRAlgo_Array1OfTData*& TData1, HLRAlgo_Array1OfTData*& TData2)
680 {
681   if (myNbTData >= myMxTData) {
682 #ifdef OCCT_DEBUG
683     if (HLRAlgo_PolyInternalData_TRACE)
684       std::cout << "HLRAlgo_PolyInternalData::IncTData : " << myMxTData << std::endl;
685 #endif
686     Standard_Integer i,j,k;
687     j = myMxTData;
688     k = 2 * j;
689
690     Handle(HLRAlgo_HArray1OfTData) NwTData =
691       new HLRAlgo_HArray1OfTData(0,k);
692     HLRAlgo_Array1OfTData& oTData = myTData->ChangeArray1();
693     HLRAlgo_Array1OfTData& nTData = NwTData->ChangeArray1();
694
695     for (i = 1; i <= j; i++)
696     {
697       nTData.ChangeValue(i) = oTData.Value(i);
698     }
699     myMxTData = k;
700     myTData  = NwTData;
701     if (TData1 == TData2) {
702       TData1 = &nTData;
703       TData2 = TData1;
704     }
705     else {
706       TData1 = &nTData;
707     }
708   }
709   myNbTData++;
710 }
711
712 //=======================================================================
713 //function : IncPISeg
714 //purpose  : 
715 //=======================================================================
716
717 void HLRAlgo_PolyInternalData::IncPISeg(
718   HLRAlgo_Array1OfPISeg*& PISeg1, HLRAlgo_Array1OfPISeg*& PISeg2)
719
720   if (myNbPISeg >= myMxPISeg) {
721 #ifdef OCCT_DEBUG
722     if (HLRAlgo_PolyInternalData_TRACE)
723       std::cout << "HLRAlgo_PolyInternalData::IncPISeg : " << myMxPISeg << std::endl;
724 #endif
725     Standard_Integer i,j,k;
726     j = myMxPISeg;
727     k = 2 * j;
728     Handle(HLRAlgo_HArray1OfPISeg) NwPISeg =
729       new HLRAlgo_HArray1OfPISeg(0,k);
730     HLRAlgo_Array1OfPISeg& oPISeg = myPISeg->ChangeArray1();
731     HLRAlgo_Array1OfPISeg& nPISeg = NwPISeg->ChangeArray1();
732
733     for (i = 1; i <= j; i++)
734     {
735       nPISeg.ChangeValue(i) = oPISeg.Value(i);
736     }
737     myMxPISeg = k;
738     myPISeg = NwPISeg;
739     if (PISeg1 == PISeg2) {
740       PISeg1 = &nPISeg;
741       PISeg2 = PISeg1;
742     }
743     else {
744       PISeg1 = &nPISeg;
745     }
746   }
747   myNbPISeg++;
748 }
749
750 //=======================================================================
751 //function : IncPINod
752 //purpose  : 
753 //=======================================================================
754
755 void HLRAlgo_PolyInternalData::IncPINod(
756   HLRAlgo_Array1OfPINod*& PINod1, HLRAlgo_Array1OfPINod*& PINod2)
757 {
758   if (myNbPINod >= myMxPINod) {
759 #ifdef OCCT_DEBUG
760     if (HLRAlgo_PolyInternalData_TRACE)
761       std::cout << "HLRAlgo_PolyInternalData::IncPINod : " << myMxPINod << std::endl;
762 #endif
763     Standard_Integer i,j,k;
764     j = myMxPINod;
765     k = 2 * j;
766     Handle(HLRAlgo_HArray1OfPINod) NwPINod =
767       new HLRAlgo_HArray1OfPINod(0,k);
768     HLRAlgo_Array1OfPINod& oPINod = myPINod->ChangeArray1();
769     HLRAlgo_Array1OfPINod& nPINod = NwPINod->ChangeArray1();
770     Handle(HLRAlgo_PolyInternalNode)* ON = &(oPINod.ChangeValue(1));
771     Handle(HLRAlgo_PolyInternalNode)* NN = &(nPINod.ChangeValue(1));
772
773     for (i = 1; i <= j; i++) {
774       *NN = *ON;
775       ON++;
776       NN++;
777     }
778     myMxPINod = k;
779     myPINod = NwPINod;
780     if (PINod1 == PINod2) {
781       PINod1 = &nPINod;
782       PINod2 = PINod1;
783     }
784     else {
785       PINod1 = &nPINod;
786     }
787   }
788   myNbPINod++;
789 }