0028599: Replacement of old Boolean operations with new ones in BRepProj_Projection...
[occt.git] / src / IntPolyh / IntPolyh_MaillageAffinage.cxx
CommitLineData
b311480e 1// Created on: 1999-03-05
2// Created by: Fabrice SERVANT
3// Copyright (c) 1999-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17// modified by Edward AGAPOV (eap) Tue Jan 22 2002 (bug occ53)
18// - improve SectionLine table management (avoid memory reallocation)
19// - some protection against arrays overflow
7fd59977 20// modified by Edward AGAPOV (eap) Thu Feb 14 2002 (occ139)
21// - make Section Line parts rightly connected (prepend 2nd part to the 1st)
22// - TriangleShape() for debugging purpose
7fd59977 23// Modified by skv - Thu Sep 25 17:42:42 2003 OCC567
24// modified by ofv Thu Apr 8 14:58:13 2004 fip
25
42cf5bc1 26#include <Adaptor3d_HSurface.hxx>
7fd59977 27#include <Bnd_BoundSortBox.hxx>
42cf5bc1 28#include <Bnd_Box.hxx>
29#include <Bnd_HArray1OfBox.hxx>
30#include <gp.hxx>
31#include <gp_Pnt.hxx>
68b07699 32#include <IntPolyh_ListOfCouples.hxx>
55ab6ed6 33#include <IntPolyh_Couple.hxx>
42cf5bc1 34#include <IntPolyh_Edge.hxx>
35#include <IntPolyh_MaillageAffinage.hxx>
36#include <IntPolyh_Point.hxx>
37#include <IntPolyh_SectionLine.hxx>
38#include <IntPolyh_StartPoint.hxx>
03cca6f7 39#include <IntPolyh_Tools.hxx>
42cf5bc1 40#include <IntPolyh_Triangle.hxx>
41#include <Precision.hxx>
68b07699 42#include <TColStd_Array1OfInteger.hxx>
43#include <TColStd_MapOfInteger.hxx>
42cf5bc1 44#include <TColStd_ListIteratorOfListOfInteger.hxx>
68b07699 45#include <NCollection_UBTree.hxx>
46#include <NCollection_UBTreeFiller.hxx>
47#include <algorithm>
48#include <NCollection_IndexedDataMap.hxx>
49
50typedef NCollection_Array1<Standard_Integer> IntPolyh_ArrayOfInteger;
51typedef NCollection_IndexedDataMap
52 <Standard_Integer,
53 IntPolyh_ArrayOfInteger,
54 TColStd_MapIntegerHasher> IntPolyh_IndexedDataMapOfIntegerArrayOfInteger;
55
7fd59977 56
55ab6ed6
P
57static Standard_Real MyTolerance=10.0e-7;
58static Standard_Real MyConfusionPrecision=10.0e-12;
59static Standard_Real SquareMyConfusionPrecision=10.0e-24;
60//
61static
62 inline Standard_Real maxSR(const Standard_Real a,
87696ff7 63 const Standard_Real b,
64 const Standard_Real c);
55ab6ed6
P
65
66static
67 inline Standard_Real minSR(const Standard_Real a,
87696ff7 68 const Standard_Real b,
69 const Standard_Real c);
55ab6ed6
P
70static
71 Standard_Integer project6(const IntPolyh_Point &ax,
87696ff7 72 const IntPolyh_Point &p1,
73 const IntPolyh_Point &p2,
74 const IntPolyh_Point &p3,
75 const IntPolyh_Point &q1,
76 const IntPolyh_Point &q2,
77 const IntPolyh_Point &q3);
55ab6ed6
P
78static
79 void TestNbPoints(const Standard_Integer ,
87696ff7 80 Standard_Integer &NbPoints,
81 Standard_Integer &NbPointsTotal,
82 const IntPolyh_StartPoint &Pt1,
83 const IntPolyh_StartPoint &Pt2,
84 IntPolyh_StartPoint &SP1,
85 IntPolyh_StartPoint &SP2);
55ab6ed6
P
86static
87 void CalculPtsInterTriEdgeCoplanaires(const Standard_Integer TriSurfID,
87696ff7 88 const IntPolyh_Point &NormaleTri,
68b07699 89 const IntPolyh_Triangle &Tri1,
90 const IntPolyh_Triangle &Tri2,
87696ff7 91 const IntPolyh_Point &PE1,
92 const IntPolyh_Point &PE2,
93 const IntPolyh_Point &Edge,
68b07699 94 const Standard_Integer EdgeIndex,
87696ff7 95 const IntPolyh_Point &PT1,
96 const IntPolyh_Point &PT2,
97 const IntPolyh_Point &Cote,
98 const Standard_Integer CoteIndex,
99 IntPolyh_StartPoint &SP1,
100 IntPolyh_StartPoint &SP2,
68b07699 101 Standard_Integer &NbPoints);
55ab6ed6 102static
68b07699 103 Standard_Boolean CheckCoupleAndGetAngle(const Standard_Integer T1,
87696ff7 104 const Standard_Integer T2,
105 Standard_Real& Angle,
68b07699 106 IntPolyh_ListOfCouples &TTrianglesContacts);
55ab6ed6 107static
68b07699 108 Standard_Boolean CheckCoupleAndGetAngle2(const Standard_Integer T1,
87696ff7 109 const Standard_Integer T2,
110 const Standard_Integer T11,
111 const Standard_Integer T22,
68b07699 112 IntPolyh_ListIteratorOfListOfCouples& theItCT11,
113 IntPolyh_ListIteratorOfListOfCouples& theItCT22,
87696ff7 114 Standard_Real & Angle,
68b07699 115 IntPolyh_ListOfCouples &TTrianglesContacts);
55ab6ed6
P
116static
117 Standard_Integer CheckNextStartPoint(IntPolyh_SectionLine & SectionLine,
87696ff7 118 IntPolyh_ArrayOfTangentZones & TTangentZones,
119 IntPolyh_StartPoint & SP,
120 const Standard_Boolean Prepend=Standard_False);
55ab6ed6 121
55ab6ed6
P
122static
123 Standard_Boolean IsDegenerated(const Handle(Adaptor3d_HSurface)& aS,
87696ff7 124 const Standard_Integer aIndex,
125 const Standard_Real aTol2,
126 Standard_Real& aDegX);
55ab6ed6
P
127static
128 void DegeneratedIndex(const TColStd_Array1OfReal& Xpars,
87696ff7 129 const Standard_Integer aNbX,
130 const Handle(Adaptor3d_HSurface)& aS,
131 const Standard_Integer aIsoDirection,
132 Standard_Integer& aI1,
133 Standard_Integer& aI2);
68b07699 134
135//=======================================================================
136//class : IntPolyh_BoxBndTreeSelector
137//purpose : Select interfering bounding boxes
138//=======================================================================
139typedef NCollection_UBTree<Standard_Integer, Bnd_Box> IntPolyh_BoxBndTree;
140class IntPolyh_BoxBndTreeSelector : public IntPolyh_BoxBndTree::Selector {
141 public:
142 IntPolyh_BoxBndTreeSelector(const Bnd_Box& theBox) : myBox(theBox) {}
143 //
144 virtual Standard_Boolean Reject(const Bnd_Box& theOther) const
145 {
146 return myBox.IsOut(theOther);
147 }
148 //
149 virtual Standard_Boolean Accept(const Standard_Integer &theInd)
150 {
151 myIndices.Append(theInd);
152 return Standard_True;
153 }
154 //
155 const TColStd_ListOfInteger& Indices() const
156 {
157 return myIndices;
158 }
159 private:
160 Bnd_Box myBox;
161 TColStd_ListOfInteger myIndices;
162};
163
164//=======================================================================
165//function : GetInterferingTriangles
166//purpose : Returns indices of the triangles with interfering bounding boxes
167//=======================================================================
168static
169 void GetInterferingTriangles(IntPolyh_ArrayOfTriangles& theTriangles1,
170 const IntPolyh_ArrayOfPoints& thePoints1,
171 IntPolyh_ArrayOfTriangles& theTriangles2,
172 const IntPolyh_ArrayOfPoints& thePoints2,
173 IntPolyh_IndexedDataMapOfIntegerArrayOfInteger& theCouples)
174{
175 // To find the triangles with interfering bounding boxes
176 // use the algorithm of unbalanced binary tree of overlapping bounding boxes
177 IntPolyh_BoxBndTree aBBTree;
178 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
179 // 1. Fill the tree with the boxes of the triangles from second surface
180 Standard_Integer i, aNbT2 = theTriangles2.NbItems();
03cca6f7 181 Standard_Boolean bAdded = Standard_False;
68b07699 182 for (i = 0; i < aNbT2; ++i) {
183 IntPolyh_Triangle& aT = theTriangles2[i];
184 if (!aT.IsIntersectionPossible() || aT.IsDegenerated()) {
185 continue;
186 }
187 //
188 const Bnd_Box& aBox = aT.BoundingBox(thePoints2);
189 aTreeFiller.Add(i, aBox);
03cca6f7 190 bAdded = Standard_True;
68b07699 191 }
192 //
03cca6f7 193 if (!bAdded)
194 // Intersection is not possible for all triangles in theTriangles2
195 return;
196
68b07699 197 // 2. Shake the tree filler
198 aTreeFiller.Fill();
199 //
200 // 3. Find boxes interfering with the first triangles
201 Standard_Integer aNbT1 = theTriangles1.NbItems();
202 for (i = 0; i < aNbT1; ++i) {
203 IntPolyh_Triangle& aT = theTriangles1[i];
204 if (!aT.IsIntersectionPossible() || aT.IsDegenerated()) {
205 continue;
206 }
207 //
208 const Bnd_Box& aBox = aT.BoundingBox(thePoints1);
209 //
210 IntPolyh_BoxBndTreeSelector aSelector(aBox);
211 if (!aBBTree.Select(aSelector)) {
212 continue;
213 }
214 //
215 const TColStd_ListOfInteger& aLI = aSelector.Indices();
216 // Sort the indices
217 IntPolyh_ArrayOfInteger anArr(1, aLI.Extent());
218 TColStd_ListIteratorOfListOfInteger aItLI(aLI);
219 for (Standard_Integer j = 1; aItLI.More(); aItLI.Next(), ++j) {
220 anArr(j) = aItLI.Value();
221 }
222 //
223 std::sort(anArr.begin(), anArr.end());
224 //
225 theCouples.Add(i, anArr);
226 }
227}
228
7fd59977 229//=======================================================================
230//function : IntPolyh_MaillageAffinage
231//purpose :
232//=======================================================================
55ab6ed6
P
233IntPolyh_MaillageAffinage::IntPolyh_MaillageAffinage
234 (const Handle(Adaptor3d_HSurface)& Surface1,
235 const Handle(Adaptor3d_HSurface)& Surface2,
236 const Standard_Integer )
237:
238 MaSurface1(Surface1),
239 MaSurface2(Surface2),
240 NbSamplesU1(10),
241 NbSamplesU2(10),
242 NbSamplesV1(10),
243 NbSamplesV2(10),
244 FlecheMax1(0.0),
245 FlecheMax2(0.0),
246 FlecheMin1(0.0),
247 FlecheMin2(0.0),
55ab6ed6 248 myEnlargeZone(Standard_False)
7fd59977 249{
7fd59977 250}
7fd59977 251//=======================================================================
252//function : IntPolyh_MaillageAffinage
253//purpose :
254//=======================================================================
55ab6ed6
P
255IntPolyh_MaillageAffinage::IntPolyh_MaillageAffinage
256 (const Handle(Adaptor3d_HSurface)& Surface1,
257 const Standard_Integer NbSU1,
258 const Standard_Integer NbSV1,
259 const Handle(Adaptor3d_HSurface)& Surface2,
260 const Standard_Integer NbSU2,
261 const Standard_Integer NbSV2,
262 const Standard_Integer )
263:
264 MaSurface1(Surface1),
265 MaSurface2(Surface2),
266 NbSamplesU1(NbSU1),
267 NbSamplesU2(NbSU2),
268 NbSamplesV1(NbSV1),
269 NbSamplesV2(NbSV2),
270 FlecheMax1(0.0),
271 FlecheMax2(0.0),
272 FlecheMin1(0.0),
273 FlecheMin2(0.0),
55ab6ed6 274 myEnlargeZone(Standard_False)
7fd59977 275{
fee4fa0f 276}
7fd59977 277//=======================================================================
03cca6f7 278//function : MakeSampling
279//purpose :
280//=======================================================================
281void IntPolyh_MaillageAffinage::MakeSampling(const Standard_Integer SurfID,
282 TColStd_Array1OfReal& theUPars,
283 TColStd_Array1OfReal& theVPars)
284{
285 if (SurfID == 1)
286 IntPolyh_Tools::MakeSampling(MaSurface1, NbSamplesU1, NbSamplesV1, myEnlargeZone, theUPars, theVPars);
287 else
288 IntPolyh_Tools::MakeSampling(MaSurface2, NbSamplesU2, NbSamplesV2, myEnlargeZone, theUPars, theVPars);
289}
290
291//=======================================================================
7fd59977 292//function : FillArrayOfPnt
293//purpose : Compute points on one surface and fill an array of points
294//=======================================================================
55ab6ed6
P
295void IntPolyh_MaillageAffinage::FillArrayOfPnt
296 (const Standard_Integer SurfID)
7fd59977 297{
03cca6f7 298 // Make sampling
299 TColStd_Array1OfReal aUpars, aVpars;
300 MakeSampling(SurfID, aUpars, aVpars);
301 // Fill array of points
24261684 302 FillArrayOfPnt(SurfID, aUpars, aVpars);
7fd59977 303}
7fd59977 304//=======================================================================
305//function : FillArrayOfPnt
306//purpose : Compute points on one surface and fill an array of points
307// FILL AN ARRAY OF POINTS
308//=======================================================================
55ab6ed6
P
309void IntPolyh_MaillageAffinage::FillArrayOfPnt
310 (const Standard_Integer SurfID,
311 const Standard_Boolean isShiftFwd)
7fd59977 312{
03cca6f7 313 // Make sampling
314 TColStd_Array1OfReal aUpars, aVpars;
315 MakeSampling(SurfID, aUpars, aVpars);
316 // Fill array of points
317 FillArrayOfPnt(SurfID, isShiftFwd, aUpars, aVpars);
55ab6ed6
P
318}
319//=======================================================================
320//function : FillArrayOfPnt
321//purpose : Compute points on one surface and fill an array of points
322//=======================================================================
323void IntPolyh_MaillageAffinage::FillArrayOfPnt
324 (const Standard_Integer SurfID,
325 const TColStd_Array1OfReal& Upars,
03cca6f7 326 const TColStd_Array1OfReal& Vpars,
327 const Standard_Real *theDeflTol)
55ab6ed6
P
328{
329 Standard_Boolean bDegI, bDeg;
330 Standard_Integer aNbU, aNbV, iCnt, i, j;
331 Standard_Integer aID1, aID2, aJD1, aJD2;
6e6cd5d9 332 Standard_Real aTol, aU, aV, aX, aY, aZ;
55ab6ed6
P
333 gp_Pnt aP;
334 //
335 aNbU=(SurfID==1)? NbSamplesU1 : NbSamplesU2;
336 aNbV=(SurfID==1)? NbSamplesV1 : NbSamplesV2;
337 Bnd_Box& aBox = (SurfID==1) ? MyBox1 : MyBox2;
338 Handle(Adaptor3d_HSurface)& aS=(SurfID==1)? MaSurface1:MaSurface2;
339 IntPolyh_ArrayOfPoints &TPoints=(SurfID==1)? TPoints1:TPoints2;
340 //
55ab6ed6
P
341 aJD1=0;
342 aJD2=0;
343 aID1=0;
344 aID2=0;
345 DegeneratedIndex(Vpars, aNbV, aS, 1, aJD1, aJD2);
346 if (!(aJD1 || aJD2)) {
347 DegeneratedIndex(Upars, aNbU, aS, 2, aID1, aID2);
348 }
55ab6ed6 349 //
fee4fa0f 350 TPoints.Init(aNbU*aNbV);
55ab6ed6
P
351 iCnt=0;
352 for(i=1; i<=aNbU; ++i){
55ab6ed6 353 bDegI=(aID1==i || aID2==i);
55ab6ed6
P
354 aU=Upars(i);
355 for(j=1; j<=aNbV; ++j){
356 aV=Vpars(j);
357 aP=aS->Value(aU, aV);
358 aP.Coord(aX, aY, aZ);
359 IntPolyh_Point& aIP=TPoints[iCnt];
360 aIP.Set(aX, aY, aZ, aU, aV);
361 //
55ab6ed6
P
362 bDeg=bDegI || (aJD1==j || aJD2==j);
363 if (bDeg) {
fee4fa0f 364 aIP.SetDegenerated(bDeg);
55ab6ed6 365 }
55ab6ed6
P
366 ++iCnt;
367 aBox.Add(aP);
368 }
369 }
370 //
d642ddf5 371 TPoints.SetNbItems(iCnt);
55ab6ed6 372 //
03cca6f7 373 aTol = !theDeflTol ? IntPolyh_Tools::ComputeDeflection(aS, Upars, Vpars) : *theDeflTol;
374 aTol *= 1.2;
55ab6ed6
P
375
376 Standard_Real a1,a2,a3,b1,b2,b3;
377 //
378 aBox.Get(a1,a2,a3,b1,b2,b3);
379 aBox.Update(a1-aTol,a2-aTol,a3-aTol,b1+aTol,b2+aTol,b3+aTol);
380 aBox.Enlarge(MyTolerance);
381}
7fd59977 382
383//=======================================================================
55ab6ed6 384//function : FillArrayOfPnt
03cca6f7 385//purpose :
386//=======================================================================
387void IntPolyh_MaillageAffinage::FillArrayOfPnt(const Standard_Integer SurfID,
388 const Standard_Boolean isShiftFwd,
389 const IntPolyh_ArrayOfPointNormal& thePointsNorm,
390 const TColStd_Array1OfReal& theUPars,
391 const TColStd_Array1OfReal& theVPars,
392 const Standard_Real theDeflTol)
55ab6ed6 393{
03cca6f7 394 Handle(Adaptor3d_HSurface) aS = (SurfID == 1) ? MaSurface1 : MaSurface2;
395 IntPolyh_ArrayOfPoints& TPoints = (SurfID == 1) ? TPoints1 : TPoints2;
396 Standard_Integer aNbU = (SurfID == 1) ? NbSamplesU1 : NbSamplesU2;
397 Standard_Integer aNbV = (SurfID == 1) ? NbSamplesV1 : NbSamplesV2;
55ab6ed6 398 Bnd_Box& aBox = (SurfID==1) ? MyBox1 : MyBox2;
03cca6f7 399
400 Standard_Integer aJD1(0), aJD2(0), aID1(0), aID2(0);
401 DegeneratedIndex(theVPars, aNbV, aS, 1, aJD1, aJD2);
402 if (!(aJD1 || aJD2))
403 DegeneratedIndex(theUPars, aNbU, aS, 2, aID1, aID2);
404
405 Standard_Boolean bDegI, bDeg;
406 Standard_Integer iCnt(0), i, j;
407 Standard_Real aX, aY, aZ, aU, aV;
408
409 TPoints.Init(thePointsNorm.NbItems());
410
411 for (i = 1; i <= aNbU; ++i)
412 {
413 aU = theUPars(i);
414 bDegI = (aID1 == i || aID2 == i);
415 for (j = 1; j <= aNbV; ++j)
416 {
417 aV = theVPars(j);
418
419 const IntPolyh_PointNormal& aPN = thePointsNorm.Value(iCnt);
420 gp_Vec aNorm = aPN.Normal.Multiplied(1.5*theDeflTol);
421 if (!isShiftFwd)
422 aNorm.Reverse();
423 gp_Pnt aP = aPN.Point.Translated(aNorm);
424
425 IntPolyh_Point& aIP = TPoints[iCnt];
55ab6ed6
P
426 aP.Coord(aX, aY, aZ);
427 aIP.Set(aX, aY, aZ, aU, aV);
03cca6f7 428 bDeg = bDegI || (aJD1 == j || aJD2 == j);
429 if (bDeg)
87696ff7 430 aIP.SetDegenerated(bDeg);
03cca6f7 431
55ab6ed6
P
432 ++iCnt;
433 aBox.Add(aP);
434 }
435 }
03cca6f7 436
d642ddf5 437 TPoints.SetNbItems(iCnt);
03cca6f7 438
439 // Update box
440 Standard_Real Tol = theDeflTol*1.2;
55ab6ed6 441 Standard_Real a1,a2,a3,b1,b2,b3;
55ab6ed6
P
442 aBox.Get(a1,a2,a3,b1,b2,b3);
443 aBox.Update(a1-Tol,a2-Tol,a3-Tol,b1+Tol,b2+Tol,b3+Tol);
444 aBox.Enlarge(MyTolerance);
445}
03cca6f7 446
447//=======================================================================
448//function : FillArrayOfPnt
449//purpose : Compute points on one surface and fill an array of points
450//=======================================================================
451void IntPolyh_MaillageAffinage::FillArrayOfPnt
452 (const Standard_Integer SurfID,
453 const Standard_Boolean isShiftFwd,
454 const TColStd_Array1OfReal& Upars,
455 const TColStd_Array1OfReal& Vpars,
456 const Standard_Real *theDeflTol)
457{
458 Handle(Adaptor3d_HSurface) aS = (SurfID == 1) ? MaSurface1 : MaSurface2;
459 // Compute the tolerance
460 Standard_Real aTol = theDeflTol != NULL ? * theDeflTol :
461 IntPolyh_Tools::ComputeDeflection(aS, Upars, Vpars);
462 // Fill array of point normal
463 IntPolyh_ArrayOfPointNormal aPoints;
464 IntPolyh_Tools::FillArrayOfPointNormal(aS, Upars, Vpars, aPoints);
465
466 // Fill array of points
467 FillArrayOfPnt(1, isShiftFwd, aPoints, Upars, Vpars, aTol);
468}
469
470//=======================================================================
471//function : CommonBox
472//purpose :
473//=======================================================================
474void IntPolyh_MaillageAffinage::CommonBox()
475{
476 Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax;
477 CommonBox(GetBox(1), GetBox(2), XMin, YMin, ZMin, XMax, YMax, ZMax);
478}
479
55ab6ed6 480//=======================================================================
7fd59977 481//function : CommonBox
482//purpose : Compute the common box witch is the intersection
483// of the two bounding boxes, and mark the points of
484// the two surfaces that are inside.
485// REJECTION BOUNDING BOXES
486// DETERMINATION OF THE COMMON BOX
487//=======================================================================
55ab6ed6 488void IntPolyh_MaillageAffinage::CommonBox (const Bnd_Box &,
87696ff7 489 const Bnd_Box &,
490 Standard_Real &XMin,
491 Standard_Real &YMin,
492 Standard_Real &ZMin,
493 Standard_Real &XMax,
494 Standard_Real &YMax,
495 Standard_Real &ZMax)
55ab6ed6 496{
7fd59977 497 Standard_Real x10,y10,z10,x11,y11,z11;
498 Standard_Real x20,y20,z20,x21,y21,z21;
499
500 MyBox1.Get(x10,y10,z10,x11,y11,z11);
501 MyBox2.Get(x20,y20,z20,x21,y21,z21);
7fd59977 502 XMin = 0.;
503 YMin = 0.;
504 ZMin = 0.;
505 XMax = 0.;
506 YMax = 0.;
507 ZMax = 0.;
7fd59977 508
509 if((x10>x21)||(x20>x11)||(y10>y21)||(y20>y11)||(z10>z21)||(z20>z11)) {
7fd59977 510 }
511 else {
7fd59977 512 if(x11<=x21) XMax=x11; else { if(x21<=x11) XMax=x21;}
7fd59977 513 if(x20<=x10) XMin=x10; else { if(x10<=x20) XMin=x20;}
7fd59977 514 if(y11<=y21) YMax=y11; else { if(y21<=y11) YMax=y21;}
7fd59977 515 if(y20<=y10) YMin=y10; else { if(y10<=y20) YMin=y20;}
7fd59977 516 if(z11<=z21) ZMax=z11; else { if(z21<=z11) ZMax=z21;}
7fd59977 517 if(z20<=z10) ZMin=z10; else { if(z10<=z20) ZMin=z20;}
7fd59977 518
519 if(((XMin==XMax)&&(!(YMin==YMax)&&!(ZMin==ZMax)))
87696ff7 520 ||((YMin==YMax)&&(!(XMin==XMax)&&!(ZMin==ZMax)))//ou exclusif ??
521 ||((ZMin==ZMax)&&(!(XMin==XMax)&&!(YMin==YMax)))) {
7fd59977 522 }
523 }
55ab6ed6 524 //
7fd59977 525 Standard_Real X,Y,Z;
526 X=XMax-XMin;
527 Y=YMax-YMin;
528 Z=ZMax-ZMin;
529 //extension of the box
530 if( (X==0)&&(Y!=0) ) X=Y*0.1;
531 else if( (X==0)&&(Z!=0) ) X=Z*0.1;
532 else X*=0.1;
533
534 if( (Y==0)&&(X!=0) ) Y=X*0.1;
535 else if( (Y==0)&&(Z!=0) ) Y=Z*0.1;
536 else Y*=0.1;
537
538 if( (Z==0)&&(X!=0) ) Z=X*0.1;
539 else if( (Z==0)&&(Y!=0) ) Z=Y*0.1;
540 else Z*=0.1;
541
542
543 if( (X==0)&&(Y==0)&&(Z==0) ) {
544
55ab6ed6 545
7fd59977 546 }
547 XMin-=X; XMax+=X;
548 YMin-=Y; YMax+=Y;
549 ZMin-=Z; ZMax+=Z;
550
551 //Marking of points included in the common
d642ddf5 552 const Standard_Integer FinTP1 = TPoints1.NbItems();
7fd59977 553// for(Standard_Integer i=0; i<FinTP1; i++) {
554 Standard_Integer i ;
555 for( i=0; i<FinTP1; i++) {
556 IntPolyh_Point & Pt1 = TPoints1[i];
557 Standard_Integer r;
55ab6ed6
P
558 if(Pt1.X()<XMin) {
559 r=1;
560 }
561 else {
562 if(Pt1.X()>XMax) {
87696ff7 563 r=2;
55ab6ed6 564 } else {
87696ff7 565 r=0;
55ab6ed6
P
566 }
567 }
568 if(Pt1.Y()<YMin) {
569 r|=4;
570 }
571 else {
572 if(Pt1.Y()>YMax) {
87696ff7 573 r|=8;
55ab6ed6
P
574 }
575 }
576 if(Pt1.Z()<ZMin) {
577 r|=16;
578 } else {
579 if(Pt1.Z()>ZMax) {
87696ff7 580 r|=32;
55ab6ed6
P
581 }
582 }
7fd59977 583 Pt1.SetPartOfCommon(r);
584 }
585
d642ddf5 586 const Standard_Integer FinTP2 = TPoints2.NbItems();
7fd59977 587 for(Standard_Integer ii=0; ii<FinTP2; ii++) {
588 IntPolyh_Point & Pt2 = TPoints2[ii];
589 Standard_Integer rr;
55ab6ed6
P
590 if(Pt2.X()<XMin) {
591 rr=1;
592 }
593 else {
594 if(Pt2.X()>XMax) {
87696ff7 595 rr=2;
55ab6ed6 596 } else {
87696ff7 597 rr=0;
55ab6ed6
P
598 }
599 }
600 if(Pt2.Y()<YMin) {
601 rr|=4;
602 }
603 else {
604 if(Pt2.Y()>YMax) {
87696ff7 605 rr|=8;
55ab6ed6
P
606 }
607 }
608 if(Pt2.Z()<ZMin) {
609 rr|=16;
610 }
611 else {
612 if(Pt2.Z()>ZMax) {
87696ff7 613 rr|=32;
55ab6ed6
P
614 }
615 }
7fd59977 616 Pt2.SetPartOfCommon(rr);
617 }
7fd59977 618}
7fd59977 619//=======================================================================
620//function : FillArrayOfEdges
621//purpose : Compute edges from the array of points
622// FILL THE ARRAY OF EDGES
623//=======================================================================
55ab6ed6
P
624void IntPolyh_MaillageAffinage::FillArrayOfEdges
625 (const Standard_Integer SurfID)
626{
7fd59977 627
628 IntPolyh_ArrayOfEdges &TEdges=(SurfID==1)? TEdges1:TEdges2;
68b07699 629 IntPolyh_ArrayOfTriangles &TTriangles=(SurfID==1)? TTriangles1:TTriangles2;
7fd59977 630 Standard_Integer NbSamplesU=(SurfID==1)? NbSamplesU1:NbSamplesU2;
631 Standard_Integer NbSamplesV=(SurfID==1)? NbSamplesV1:NbSamplesV2;
632
fee4fa0f 633 //NbEdges = 3 + 3*(NbSamplesV-2) + 3*(NbSamplesU-2) +
634 // + 3*(NbSamplesU-2)*(NbSamplesV-2) + (NbSamplesV-1) + (NbSamplesU-1);
635 //NbSamplesU and NbSamples cannot be less than 2, so
636 Standard_Integer NbEdges = 3*NbSamplesU*NbSamplesV - 2*(NbSamplesU+NbSamplesV) + 1;
637 TEdges.Init(NbEdges);
638
7fd59977 639 Standard_Integer CpteurTabEdges=0;
640
641 //maillage u0 v0
642 TEdges[CpteurTabEdges].SetFirstPoint(0); // U V
643 TEdges[CpteurTabEdges].SetSecondPoint(1); // U V+1
7fd59977 644 TEdges[CpteurTabEdges].SetSecondTriangle(0);
68b07699 645 TTriangles[0].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 646 CpteurTabEdges++;
68b07699 647
7fd59977 648 TEdges[CpteurTabEdges].SetFirstPoint(0); // U V
649 TEdges[CpteurTabEdges].SetSecondPoint(NbSamplesV); // U+1 V
68b07699 650 TEdges[CpteurTabEdges].SetFirstTriangle(1);
651 TTriangles[1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 652 CpteurTabEdges++;
653
654 TEdges[CpteurTabEdges].SetFirstPoint(0); // U V
655 TEdges[CpteurTabEdges].SetSecondPoint(NbSamplesV+1); // U+1 V+1
68b07699 656 TEdges[CpteurTabEdges].SetFirstTriangle(0);
657 TTriangles[0].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
658 TEdges[CpteurTabEdges].SetSecondTriangle(1);
659 TTriangles[1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 660 CpteurTabEdges++;
661
662 //maillage surU=u0
663 Standard_Integer PntInit=1;
7fd59977 664 Standard_Integer BoucleMeshV;
665 for(BoucleMeshV=1; BoucleMeshV<NbSamplesV-1;BoucleMeshV++){
666 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
667 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+1); // U V+1
668 // TEdges[CpteurTabEdges].SetFirstTriangle(-1);
669 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*2);
68b07699 670 TTriangles[BoucleMeshV*2].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 671 CpteurTabEdges++;
672
673 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
674 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV+1); // U+1 V+1
675 TEdges[CpteurTabEdges].SetFirstTriangle(BoucleMeshV*2);
68b07699 676 TTriangles[BoucleMeshV*2].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 677 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*2+1);
68b07699 678 TTriangles[BoucleMeshV*2+1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 679 CpteurTabEdges++;
680
681 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
682 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV); // U+1 V
683 TEdges[CpteurTabEdges].SetFirstTriangle(BoucleMeshV*2+1);
68b07699 684 TTriangles[BoucleMeshV*2+1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 685 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*2-2);
68b07699 686 TTriangles[BoucleMeshV*2-2].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 687 CpteurTabEdges++;
688 PntInit++;
689 }
87696ff7 690
7fd59977 691 //maillage sur V=v0
692 PntInit=NbSamplesV;
693 for(BoucleMeshV=1; BoucleMeshV<NbSamplesU-1;BoucleMeshV++){
694 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
695 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+1); // U V+1
696 TEdges[CpteurTabEdges].SetFirstTriangle((BoucleMeshV-1)*(NbSamplesV-1)*2+1);
68b07699 697 TTriangles[(BoucleMeshV-1)*(NbSamplesV-1)*2+1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 698 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*(NbSamplesV-1)*2);
68b07699 699 TTriangles[BoucleMeshV*(NbSamplesV-1)*2].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 700 CpteurTabEdges++;
701
702 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
703 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV+1); // U+1 V+1
704 TEdges[CpteurTabEdges].SetFirstTriangle(BoucleMeshV*(NbSamplesV-1)*2);
68b07699 705 TTriangles[BoucleMeshV*(NbSamplesV-1)*2].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 706 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*(NbSamplesV-1)*2+1);
68b07699 707 TTriangles[BoucleMeshV*(NbSamplesV-1)*2+1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 708 CpteurTabEdges++;
709
710 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
711 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV); // U+1 V
712 TEdges[CpteurTabEdges].SetFirstTriangle(BoucleMeshV*(NbSamplesV-1)*2+1);
68b07699 713 TTriangles[BoucleMeshV*(NbSamplesV-1)*2+1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 714 CpteurTabEdges++;
715 PntInit+=NbSamplesV;
716 }
717
718 PntInit=NbSamplesV+1;
719 //To provide recursion I associate a point with three edges
720 for(Standard_Integer BoucleMeshU=1; BoucleMeshU<NbSamplesU-1; BoucleMeshU++){
51740958 721 for(BoucleMeshV=1; BoucleMeshV<NbSamplesV-1;BoucleMeshV++){
7fd59977 722 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
723 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+1); // U V+1
724 TEdges[CpteurTabEdges].SetFirstTriangle((NbSamplesV-1)*2*(BoucleMeshU-1)+BoucleMeshV*2+1);
68b07699 725 TTriangles[(NbSamplesV-1)*2*(BoucleMeshU-1)+BoucleMeshV*2+1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 726 TEdges[CpteurTabEdges].SetSecondTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2);
68b07699 727 TTriangles[(NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 728 CpteurTabEdges++;
729
730 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
731 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV+1); // U+1 V+1
732 TEdges[CpteurTabEdges].SetFirstTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2);
68b07699 733 TTriangles[(NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 734 TEdges[CpteurTabEdges].SetSecondTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2+1);
68b07699 735 TTriangles[(NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2+1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 736 CpteurTabEdges++;
737
738 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
739 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV); // U+1 V
740 TEdges[CpteurTabEdges].SetFirstTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2+1);
68b07699 741 TTriangles[(NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2+1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 742 TEdges[CpteurTabEdges].SetSecondTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2-2);
68b07699 743 TTriangles[(NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2-2].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
87696ff7 744 CpteurTabEdges++;
7fd59977 745 PntInit++;//Pass to the next point
746 }
747 PntInit++;//Pass the last point of the column
748 PntInit++;//Pass the first point of the next column
749 }
87696ff7 750
7fd59977 751 //close mesh on U=u1
752 PntInit=(NbSamplesU-1)*NbSamplesV; //point U=u1 V=0
753 for(BoucleMeshV=0; BoucleMeshV<NbSamplesV-1; BoucleMeshV++){
754 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); //U=u1 V
755 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+1); //U=u1 V+1
756 TEdges[CpteurTabEdges].SetFirstTriangle((NbSamplesU-2)*(NbSamplesV-1)*2+BoucleMeshV*2+1);
68b07699 757 TTriangles[(NbSamplesU-2)*(NbSamplesV-1)*2+BoucleMeshV*2+1].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 758 CpteurTabEdges++;
759 PntInit++;
760 }
761
762 //close mesh on V=v1
763 for(BoucleMeshV=0; BoucleMeshV<NbSamplesU-1;BoucleMeshV++){
764 TEdges[CpteurTabEdges].SetFirstPoint(NbSamplesV-1+BoucleMeshV*NbSamplesV); // U V=v1
765 TEdges[CpteurTabEdges].SetSecondPoint(NbSamplesV-1+(BoucleMeshV+1)*NbSamplesV); //U+1 V=v1
7fd59977 766 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*2*(NbSamplesV-1)+(NbSamplesV-2)*2);
68b07699 767 TTriangles[BoucleMeshV*2*(NbSamplesV-1)+(NbSamplesV-2)*2].SetEdgeAndOrientation(TEdges[CpteurTabEdges], CpteurTabEdges);
7fd59977 768 CpteurTabEdges++;
769 }
d642ddf5 770 TEdges.SetNbItems(CpteurTabEdges);
7fd59977 771}
772
773//=======================================================================
774//function : FillArrayOfTriangles
775//purpose : Compute triangles from the array of points, and --
776// mark the triangles that use marked points by the
777// CommonBox function.
778// FILL THE ARRAY OF TRIANGLES
779//=======================================================================
55ab6ed6
P
780void IntPolyh_MaillageAffinage::FillArrayOfTriangles
781 (const Standard_Integer SurfID)
782{
7fd59977 783 Standard_Integer CpteurTabTriangles=0;
784 Standard_Integer PntInit=0;
785
786 IntPolyh_ArrayOfPoints &TPoints=(SurfID==1)? TPoints1:TPoints2;
787 IntPolyh_ArrayOfTriangles &TTriangles=(SurfID==1)? TTriangles1:TTriangles2;
788 Standard_Integer NbSamplesU=(SurfID==1)? NbSamplesU1:NbSamplesU2;
789 Standard_Integer NbSamplesV=(SurfID==1)? NbSamplesV1:NbSamplesV2;
790
fee4fa0f 791 TTriangles.Init(2*(NbSamplesU-1)*(NbSamplesV-1));
7fd59977 792 //To provide recursion, I associate a point with two triangles
793 for(Standard_Integer BoucleMeshU=0; BoucleMeshU<NbSamplesU-1; BoucleMeshU++){
794 for(Standard_Integer BoucleMeshV=0; BoucleMeshV<NbSamplesV-1;BoucleMeshV++){
795
796 // FIRST TRIANGLE
797 TTriangles[CpteurTabTriangles].SetFirstPoint(PntInit); // U V
798 TTriangles[CpteurTabTriangles].SetSecondPoint(PntInit+1); // U V+1
799 TTriangles[CpteurTabTriangles].SetThirdPoint(PntInit+NbSamplesV+1); // U+1 V+1
800
801 // IF ITS EDGE CONTACTS WITH THE COMMON BOX IP REMAINS = A 1
802 if( ( (TPoints[PntInit].PartOfCommon()) & (TPoints[PntInit+1].PartOfCommon()) )
fee4fa0f 803 &&( (TPoints[PntInit+1].PartOfCommon()) & (TPoints[PntInit+NbSamplesV+1].PartOfCommon()))
804 &&( (TPoints[PntInit+NbSamplesV+1].PartOfCommon()) & (TPoints[PntInit].PartOfCommon())) )
805 //IF NOT IP=0
68b07699 806 TTriangles[CpteurTabTriangles].SetIntersectionPossible(Standard_False);
7fd59977 807
808 CpteurTabTriangles++;
809
810 //SECOND TRIANGLE
811 TTriangles[CpteurTabTriangles].SetFirstPoint(PntInit); // U V
812 TTriangles[CpteurTabTriangles].SetSecondPoint(PntInit+NbSamplesV+1); // U+1 V+1
813 TTriangles[CpteurTabTriangles].SetThirdPoint(PntInit+NbSamplesV); // U+1 V
814
815
816 if( ( (TPoints[PntInit].PartOfCommon()) & (TPoints[PntInit+NbSamplesV+1].PartOfCommon()) )
fee4fa0f 817 &&( (TPoints[PntInit+NbSamplesV+1].PartOfCommon()) & (TPoints[PntInit+NbSamplesV].PartOfCommon()))
818 &&( (TPoints[PntInit+NbSamplesV].PartOfCommon()) & (TPoints[PntInit].PartOfCommon())) )
68b07699 819 TTriangles[CpteurTabTriangles].SetIntersectionPossible(Standard_False);
7fd59977 820
821
822 CpteurTabTriangles++;
823
824 PntInit++;//Pass to the next point
825 }
826 PntInit++;//Pass the last point of the column
827 }
d642ddf5 828 TTriangles.SetNbItems(CpteurTabTriangles);
829 const Standard_Integer FinTT = TTriangles.NbItems();
7fd59977 830 if (FinTT==0) {
7fd59977 831 }
7fd59977 832}
7fd59977 833//=======================================================================
7fd59977 834//function : CommonPartRefinement
835//purpose : Refine systematicaly all marked triangles of both surfaces
836// REFINING OF THE COMMON
837//=======================================================================
55ab6ed6
P
838void IntPolyh_MaillageAffinage::CommonPartRefinement()
839{
d642ddf5 840 Standard_Integer FinInit1 = TTriangles1.NbItems();
7fd59977 841 for(Standard_Integer i=0; i<FinInit1; i++) {
68b07699 842 if(TTriangles1[i].IsIntersectionPossible())
7fd59977 843 TTriangles1[i].MiddleRefinement(i,MaSurface1,TPoints1,TTriangles1,TEdges1);
844 }
845
d642ddf5 846 Standard_Integer FinInit2=TTriangles2.NbItems();
7fd59977 847 for(Standard_Integer ii=0; ii<FinInit2; ii++) {
68b07699 848 if(TTriangles2[ii].IsIntersectionPossible())
7fd59977 849 TTriangles2[ii].MiddleRefinement(ii,MaSurface2,TPoints2,TTriangles2,TEdges2);
850 }
7fd59977 851
55ab6ed6 852}
7fd59977 853//=======================================================================
854//function : LocalSurfaceRefinement
855//purpose : Refine systematicaly all marked triangles of ONE surface
856//=======================================================================
7fd59977 857void IntPolyh_MaillageAffinage::LocalSurfaceRefinement(const Standard_Integer SurfID) {
858//refine locally, but systematically the chosen surface
859 if (SurfID==1) {
d642ddf5 860 const Standard_Integer FinInit1 = TTriangles1.NbItems();
7fd59977 861 for(Standard_Integer i=0; i<FinInit1; i++) {
68b07699 862 if(TTriangles1[i].IsIntersectionPossible())
87696ff7 863 TTriangles1[i].MiddleRefinement(i,MaSurface1,TPoints1,TTriangles1,TEdges1);
7fd59977 864 }
865 }
55ab6ed6 866 //
7fd59977 867 if (SurfID==2) {
d642ddf5 868 const Standard_Integer FinInit2 = TTriangles2.NbItems();
7fd59977 869 for(Standard_Integer ii=0; ii<FinInit2; ii++) {
68b07699 870 if(TTriangles2[ii].IsIntersectionPossible())
87696ff7 871 TTriangles2[ii].MiddleRefinement(ii,MaSurface2,TPoints2,TTriangles2,TEdges2);
7fd59977 872 }
873 }
874}
7fd59977 875//=======================================================================
876//function : ComputeDeflections
877//purpose : Compute deflection for all triangles of one
878// surface,and sort min and max of deflections
879// REFINING PART
880// Calculation of the deflection of all triangles
881// --> deflection max
882// --> deflection min
883//=======================================================================
55ab6ed6
P
884void IntPolyh_MaillageAffinage::ComputeDeflections
885 (const Standard_Integer SurfID)
886{
68b07699 887 Handle(Adaptor3d_HSurface) aSurface=(SurfID==1)? MaSurface1:MaSurface2;
7fd59977 888 IntPolyh_ArrayOfPoints &TPoints=(SurfID==1)? TPoints1:TPoints2;
889 IntPolyh_ArrayOfTriangles &TTriangles=(SurfID==1)? TTriangles1:TTriangles2;
890 Standard_Real &FlecheMin=(SurfID==1)? FlecheMin1:FlecheMin2;
7fd59977 891 Standard_Real &FlecheMax=(SurfID==1)? FlecheMax1:FlecheMax2;
892
7fd59977 893 FlecheMax=-RealLast();
894 FlecheMin=RealLast();
d642ddf5 895 const Standard_Integer FinTT = TTriangles.NbItems();
7fd59977 896
68b07699 897 for(Standard_Integer i = 0; i < FinTT; i++) {
898 IntPolyh_Triangle& aTriangle = TTriangles[i];
899 Standard_Real Fleche = aTriangle.ComputeDeflection(aSurface, TPoints);
900 if (Fleche > FlecheMax)
901 FlecheMax = Fleche;
902 if (Fleche < FlecheMin)
903 FlecheMin = Fleche;
904 }
905}
55ab6ed6 906
68b07699 907//=======================================================================
908//function : TrianglesDeflectionsRefinement
909//purpose : Refinement of the triangles depending on the deflection
910//=======================================================================
911static
912 void TrianglesDeflectionsRefinement(const Handle(Adaptor3d_HSurface)& theS1,
913 IntPolyh_ArrayOfTriangles& theTriangles1,
914 IntPolyh_ArrayOfEdges& theEdges1,
915 IntPolyh_ArrayOfPoints& thePoints1,
916 const Standard_Real theFlecheCritique1,
917 const Handle(Adaptor3d_HSurface)& theS2,
918 IntPolyh_ArrayOfTriangles& theTriangles2,
919 IntPolyh_ArrayOfEdges& theEdges2,
920 IntPolyh_ArrayOfPoints& thePoints2,
921 const Standard_Real theFlecheCritique2)
922{
923 // Find the intersecting triangles
924 IntPolyh_IndexedDataMapOfIntegerArrayOfInteger aDMILI;
925 GetInterferingTriangles(theTriangles1, thePoints1, theTriangles2, thePoints2, aDMILI);
926 //
927 // Interfering triangles of second surface
928 TColStd_MapOfInteger aMIntS2;
929 // Since the number of the triangles may change during refinement,
930 // save the number of triangles before refinement
931 Standard_Integer FinTT1 = theTriangles1.NbItems();
932 Standard_Integer FinTT2 = theTriangles2.NbItems();
933 //
934 // Analyze interfering triangles
935 for (Standard_Integer i_S1 = 0; i_S1 < FinTT1; i_S1++) {
936 IntPolyh_Triangle& aTriangle1 = theTriangles1[i_S1];
937 if (!aTriangle1.IsIntersectionPossible()) {
938 continue;
7fd59977 939 }
68b07699 940 //
941 const IntPolyh_ArrayOfInteger *pLI = aDMILI.Seek(i_S1);
942 if (!pLI || !pLI->Length()) {
943 // Mark non-interfering triangles of S1 to avoid their repeated usage
944 aTriangle1.SetIntersectionPossible(Standard_False);
945 continue;
946 }
947 //
948 if (aTriangle1.Deflection() > theFlecheCritique1) {
949 aTriangle1.MiddleRefinement(i_S1, theS1, thePoints1, theTriangles1, theEdges1);
950 }
951 //
952 IntPolyh_ArrayOfInteger::Iterator Iter(*pLI);
953 for (; Iter.More(); Iter.Next()) {
954 Standard_Integer i_S2 = Iter.Value();
955 if (aMIntS2.Add(i_S2)) {
956 IntPolyh_Triangle & aTriangle2 = theTriangles2[i_S2];
957 if (aTriangle2.Deflection() > theFlecheCritique2) {
958 // Refinement of the larger triangles
959 aTriangle2.MiddleRefinement(i_S2, theS2, thePoints2, theTriangles2, theEdges2);
960 }
961 }
962 }
963 }
964 //
965 // Mark non-interfering triangles of S2 to avoid their repeated usage
966 if (aMIntS2.Extent() < FinTT2) {
967 for (Standard_Integer i_S2 = 0; i_S2 < FinTT2; i_S2++) {
968 if (!aMIntS2.Contains(i_S2)) {
969 theTriangles2[i_S2].SetIntersectionPossible(Standard_False);
970 }
971 }
972 }
973}
974//=======================================================================
975//function : LargeTrianglesDeflectionsRefinement
976//purpose : Refinement of the large triangles in case one surface is
977// much smaller then the other.
978//=======================================================================
979static
980 void LargeTrianglesDeflectionsRefinement(const Handle(Adaptor3d_HSurface)& theS,
981 IntPolyh_ArrayOfTriangles& theTriangles,
982 IntPolyh_ArrayOfEdges& theEdges,
983 IntPolyh_ArrayOfPoints& thePoints,
984 const Bnd_Box& theOppositeBox)
985{
986 // Find all triangles of the bigger surface with bounding boxes
987 // overlapping the bounding box the other surface
988 TColStd_ListOfInteger aLIT;
989 Standard_Integer i, aNbT = theTriangles.NbItems();
990 for (i = 0; i < aNbT; ++i) {
991 IntPolyh_Triangle& aTriangle = theTriangles[i];
992 if (!aTriangle.IsIntersectionPossible() || aTriangle.IsDegenerated()) {
993 continue;
994 }
995 //
996 const Bnd_Box& aBox = aTriangle.BoundingBox(thePoints);
997 if (aBox.IsVoid()) {
998 continue;
999 }
1000 //
1001 if (aBox.IsOut(theOppositeBox)) {
1002 aTriangle.SetIntersectionPossible(Standard_False);
1003 continue;
1004 }
1005 //
1006 aLIT.Append(i);
1007 }
1008 //
1009 if (aLIT.IsEmpty()) {
1010 return;
1011 }
1012 //
1013 // One surface is very small relatively to the other.
1014 // The criterion of refining for large surface depends on the size of
1015 // the bounding box of the other - since the criterion should be minimized,
1016 // the smallest side of the bounding box is taken
1017 Standard_Real x0, y0, z0, x1, y1, z1;
1018 theOppositeBox.Get(x0, y0, z0, x1, y1, z1);
1019 Standard_Real dx = Abs(x1 - x0);
1020 Standard_Real dy = Abs(y1 - y0);
1021 Standard_Real diag = Abs(z1 - z0);
1022 Standard_Real dd = (dx > dy) ? dy : dx;
1023 if (diag > dd) diag = dd;
1024
1025 // calculation of the criterion of refining
1026 Standard_Real CritereAffinage = 0.0;
1027 Standard_Real DiagPonderation = 0.5;
1028 CritereAffinage = diag*DiagPonderation;
1029 //
1030 // The deflection of the greater is compared to the size of the smaller
1031 TColStd_ListIteratorOfListOfInteger Iter(aLIT);
1032 for (; Iter.More(); Iter.Next()) {
1033 i = Iter.Value();
1034 IntPolyh_Triangle & aTriangle = theTriangles[i];
1035 if (aTriangle.Deflection() > CritereAffinage) {
1036 aTriangle.MultipleMiddleRefinement(CritereAffinage, theOppositeBox, i,
1037 theS, thePoints, theTriangles, theEdges);
1038 }
1039 else {
1040 aTriangle.MiddleRefinement(i, theS, thePoints, theTriangles, theEdges);
7fd59977 1041 }
1042 }
7fd59977 1043}
7fd59977 1044//=======================================================================
1045//function : TrianglesDeflectionsRefinementBSB
68b07699 1046//purpose : Refine both surfaces using UBTree as rejection.
1047// The criterion used to refine a triangle are:
1048// - The deflection;
1049// - The size of the - bounding boxes (one surface may be
1050// very small compared to the other).
7fd59977 1051//=======================================================================
68b07699 1052void IntPolyh_MaillageAffinage::TrianglesDeflectionsRefinementBSB()
55ab6ed6 1053{
68b07699 1054 // To estimate a surface in general it can be interesting
1055 // to calculate all deflections
7fd59977 1056 ComputeDeflections(1);
68b07699 1057 // Check deflection at output
7fd59977 1058 Standard_Real FlecheCritique1;
68b07699 1059 if (FlecheMin1 > FlecheMax1) {
1060 return;
7fd59977 1061 }
68b07699 1062 else {
1063 // fleche min + (flechemax-flechemin) * 80/100
1064 FlecheCritique1 = FlecheMin1*0.2 + FlecheMax1*0.8;
7fd59977 1065 }
68b07699 1066
1067 // Compute deflections for the second surface
7fd59977 1068 ComputeDeflections(2);
68b07699 1069
7fd59977 1070 //-- Check arrows at output
7fd59977 1071 Standard_Real FlecheCritique2;
68b07699 1072 if (FlecheMin2 > FlecheMax2) {
7fd59977 1073 return;
1074 }
68b07699 1075 else {
1076 //fleche min + (flechemax-flechemin) * 80/100
1077 FlecheCritique2 = FlecheMin2*0.2 + FlecheMax2*0.8;
1078 }
1079
1080 // The greatest of two bounding boxes created in FillArrayOfPoints is found.
1081 // Then this value is weighted depending on the discretization
1082 // (NbSamplesU and NbSamplesV)
1083 Standard_Real diag1, diag2;
1084 Standard_Real x0, y0, z0, x1, y1, z1;
1085
1086 MyBox1.Get(x0, y0, z0, x1, y1, z1);
1087 x0 -= x1; y0 -= y1; z0 -= z1;
1088 diag1 = x0*x0 + y0*y0 + z0*z0;
1089 const Standard_Real NbSamplesUV1 = Standard_Real(NbSamplesU1) * Standard_Real(NbSamplesV1);
1090 diag1 /= NbSamplesUV1;
1091
1092 MyBox2.Get(x0, y0, z0, x1, y1, z1);
1093 x0 -= x1; y0 -= y1; z0 -= z1;
1094 diag2 = x0*x0 + y0*y0 + z0*z0;
1095 const Standard_Real NbSamplesUV2 = Standard_Real(NbSamplesU2) * Standard_Real(NbSamplesV2);
1096 diag2 /= NbSamplesUV2;
1097
1098 // The surface with the greatest bounding box is "discretized"
1099 if (diag1 < diag2) {
1100 // second is discretized
1101 if (FlecheCritique2 < diag1) {
1102 // The corresponding sizes are not too disproportional
1103 TrianglesDeflectionsRefinement(MaSurface1, TTriangles1, TEdges1, TPoints1, FlecheCritique1,
1104 MaSurface2, TTriangles2, TEdges2, TPoints2, FlecheCritique2);
7fd59977 1105 }
7fd59977 1106 else {
68b07699 1107 // second surface is much larger then the first
1108 LargeTrianglesDeflectionsRefinement(MaSurface2, TTriangles2, TEdges2, TPoints2, MyBox1);
7fd59977 1109 }
1110 }
68b07699 1111 else {
1112 // first is discretized
1113 if (FlecheCritique1 < diag2) {
1114 // The corresponding sizes are not too disproportional
1115 TrianglesDeflectionsRefinement(MaSurface2, TTriangles2, TEdges2, TPoints2, FlecheCritique2,
1116 MaSurface1, TTriangles1, TEdges1, TPoints1, FlecheCritique1);
7fd59977 1117 }
68b07699 1118 else {
1119 // first surface is much larger then the second
1120 LargeTrianglesDeflectionsRefinement(MaSurface1, TTriangles1, TEdges1, TPoints1, MyBox2);
7fd59977 1121 }
1122 }
7fd59977 1123}
7fd59977 1124//=======================================================================
1125//function : maxSR
1126//purpose : This function is used for the function project6
1127//=======================================================================
55ab6ed6 1128inline Standard_Real maxSR(const Standard_Real a,
87696ff7 1129 const Standard_Real b,
1130 const Standard_Real c)
55ab6ed6 1131{
7fd59977 1132 Standard_Real t = a;
1133 if (b > t) t = b;
1134 if (c > t) t = c;
1135 return t;
1136}
7fd59977 1137//=======================================================================
1138//function : minSR
1139//purpose : This function is used for the function project6
1140//=======================================================================
55ab6ed6 1141inline Standard_Real minSR(const Standard_Real a,
87696ff7 1142 const Standard_Real b,
1143 const Standard_Real c)
55ab6ed6 1144{
7fd59977 1145 Standard_Real t = a;
1146 if (b < t) t = b;
1147 if (c < t) t = c;
1148 return t;
1149}
7fd59977 1150//=======================================================================
1151//function : project6
1152//purpose : This function is used for the function TriContact
1153//=======================================================================
7fd59977 1154Standard_Integer project6(const IntPolyh_Point &ax,
55ab6ed6 1155 const IntPolyh_Point &p1,
87696ff7 1156 const IntPolyh_Point &p2,
1157 const IntPolyh_Point &p3,
55ab6ed6 1158 const IntPolyh_Point &q1,
87696ff7 1159 const IntPolyh_Point &q2,
1160 const IntPolyh_Point &q3)
55ab6ed6 1161{
7fd59977 1162 Standard_Real P1 = ax.Dot(p1);
1163 Standard_Real P2 = ax.Dot(p2);
1164 Standard_Real P3 = ax.Dot(p3);
1165 Standard_Real Q1 = ax.Dot(q1);
1166 Standard_Real Q2 = ax.Dot(q2);
1167 Standard_Real Q3 = ax.Dot(q3);
1168
1169 Standard_Real mx1 = maxSR(P1, P2, P3);
1170 Standard_Real mn1 = minSR(P1, P2, P3);
1171 Standard_Real mx2 = maxSR(Q1, Q2, Q3);
1172 Standard_Real mn2 = minSR(Q1, Q2, Q3);
1173
1174 if (mn1 > mx2) return 0;
1175 if (mn2 > mx1) return 0;
1176 return 1;
1177}
7fd59977 1178//=======================================================================
1179//function : TriContact
1180//purpose : This fonction Check if two triangles are in
1181// contact or no, return 1 if yes, return 0
1182// if no.
1183//=======================================================================
55ab6ed6
P
1184Standard_Integer IntPolyh_MaillageAffinage::TriContact
1185 (const IntPolyh_Point &P1,
1186 const IntPolyh_Point &P2,
1187 const IntPolyh_Point &P3,
1188 const IntPolyh_Point &Q1,
1189 const IntPolyh_Point &Q2,
1190 const IntPolyh_Point &Q3,
1191 Standard_Real &Angle) const
1192{
7fd59977 1193 /**
1194 The first triangle is (p1,p2,p3). The other is (q1,q2,q3).
1195 The edges are (e1,e2,e3) and (f1,f2,f3).
1196 The normals are n1 and m1
1197 Outwards are (g1,g2,g3) and (h1,h2,h3).*/
dba608bb
IC
1198
1199 if(maxSR(P1.X(),P2.X(),P3.X())<minSR(Q1.X(),Q2.X(),Q3.X())) return(0);
1200 if(maxSR(P1.Y(),P2.Y(),P3.Y())<minSR(Q1.Y(),Q2.Y(),Q3.Y())) return(0);
1201 if(maxSR(P1.Z(),P2.Z(),P3.Z())<minSR(Q1.Z(),Q2.Z(),Q3.Z())) return(0);
7fd59977 1202
dba608bb
IC
1203 if(minSR(P1.X(),P2.X(),P3.X())>maxSR(Q1.X(),Q2.X(),Q3.X())) return(0);
1204 if(minSR(P1.Y(),P2.Y(),P3.Y())>maxSR(Q1.Y(),Q2.Y(),Q3.Y())) return(0);
1205 if(minSR(P1.Z(),P2.Z(),P3.Z())>maxSR(Q1.Z(),Q2.Z(),Q3.Z())) return(0);
1206
7fd59977 1207 IntPolyh_Point p1, p2, p3;
1208 IntPolyh_Point q1, q2, q3;
1209 IntPolyh_Point e1, e2, e3;
1210 IntPolyh_Point f1, f2, f3;
1211 IntPolyh_Point g1, g2, g3;
1212 IntPolyh_Point h1, h2, h3;
1213 IntPolyh_Point n1, m1;
1214 IntPolyh_Point z;
1215
1216 IntPolyh_Point ef11, ef12, ef13;
1217 IntPolyh_Point ef21, ef22, ef23;
1218 IntPolyh_Point ef31, ef32, ef33;
dba608bb 1219
7fd59977 1220 z.SetX(0.0); z.SetY(0.0); z.SetZ(0.0);
7fd59977 1221
7fd59977 1222
1223 p1.SetX(P1.X() - P1.X()); p1.SetY(P1.Y() - P1.Y()); p1.SetZ(P1.Z() - P1.Z());
1224 p2.SetX(P2.X() - P1.X()); p2.SetY(P2.Y() - P1.Y()); p2.SetZ(P2.Z() - P1.Z());
1225 p3.SetX(P3.X() - P1.X()); p3.SetY(P3.Y() - P1.Y()); p3.SetZ(P3.Z() - P1.Z());
1226
1227 q1.SetX(Q1.X() - P1.X()); q1.SetY(Q1.Y() - P1.Y()); q1.SetZ(Q1.Z() - P1.Z());
1228 q2.SetX(Q2.X() - P1.X()); q2.SetY(Q2.Y() - P1.Y()); q2.SetZ(Q2.Z() - P1.Z());
1229 q3.SetX(Q3.X() - P1.X()); q3.SetY(Q3.Y() - P1.Y()); q3.SetZ(Q3.Z() - P1.Z());
1230
1231 e1.SetX(p2.X() - p1.X()); e1.SetY(p2.Y() - p1.Y()); e1.SetZ(p2.Z() - p1.Z());
1232 e2.SetX(p3.X() - p2.X()); e2.SetY(p3.Y() - p2.Y()); e2.SetZ(p3.Z() - p2.Z());
1233 e3.SetX(p1.X() - p3.X()); e3.SetY(p1.Y() - p3.Y()); e3.SetZ(p1.Z() - p3.Z());
1234
1235 f1.SetX(q2.X() - q1.X()); f1.SetY(q2.Y() - q1.Y()); f1.SetZ(q2.Z() - q1.Z());
1236 f2.SetX(q3.X() - q2.X()); f2.SetY(q3.Y() - q2.Y()); f2.SetZ(q3.Z() - q2.Z());
1237 f3.SetX(q1.X() - q3.X()); f3.SetY(q1.Y() - q3.Y()); f3.SetZ(q1.Z() - q3.Z());
1238
1239 n1.Cross(e1, e2); //normal to the first triangle
1240 m1.Cross(f1, f2); //normal to the second triangle
1241
1242 g1.Cross(e1, n1);
1243 g2.Cross(e2, n1);
1244 g3.Cross(e3, n1);
1245 h1.Cross(f1, m1);
1246 h2.Cross(f2, m1);
1247 h3.Cross(f3, m1);
1248
1249 ef11.Cross(e1, f1);
1250 ef12.Cross(e1, f2);
1251 ef13.Cross(e1, f3);
1252 ef21.Cross(e2, f1);
1253 ef22.Cross(e2, f2);
1254 ef23.Cross(e2, f3);
1255 ef31.Cross(e3, f1);
1256 ef32.Cross(e3, f2);
1257 ef33.Cross(e3, f3);
1258
1259 // Now the testing is done
1260
1261 if (!project6(n1, p1, p2, p3, q1, q2, q3)) return 0; //T2 is not higher or lower than T1
1262 if (!project6(m1, p1, p2, p3, q1, q2, q3)) return 0; //T1 is not higher of lower than T2
1263
1264 if (!project6(ef11, p1, p2, p3, q1, q2, q3)) return 0;
1265 if (!project6(ef12, p1, p2, p3, q1, q2, q3)) return 0;
1266 if (!project6(ef13, p1, p2, p3, q1, q2, q3)) return 0;
1267 if (!project6(ef21, p1, p2, p3, q1, q2, q3)) return 0;
1268 if (!project6(ef22, p1, p2, p3, q1, q2, q3)) return 0;
1269 if (!project6(ef23, p1, p2, p3, q1, q2, q3)) return 0;
1270 if (!project6(ef31, p1, p2, p3, q1, q2, q3)) return 0;
1271 if (!project6(ef32, p1, p2, p3, q1, q2, q3)) return 0;
1272 if (!project6(ef33, p1, p2, p3, q1, q2, q3)) return 0;
1273
1274 if (!project6(g1, p1, p2, p3, q1, q2, q3)) return 0; //T2 is outside of T1 in the plane of T1
1275 if (!project6(g2, p1, p2, p3, q1, q2, q3)) return 0; //T2 is outside of T1 in the plane of T1
1276 if (!project6(g3, p1, p2, p3, q1, q2, q3)) return 0; //T2 is outside of T1 in the plane of T1
1277 if (!project6(h1, p1, p2, p3, q1, q2, q3)) return 0; //T1 is outside of T2 in the plane of T2
1278 if (!project6(h2, p1, p2, p3, q1, q2, q3)) return 0; //T1 is outside of T2 in the plane of T2
1279 if (!project6(h3, p1, p2, p3, q1, q2, q3)) return 0; //T1 is outside of T2 in the plane of T2
1280
1281 //Calculation of cosinus angle between two normals
1282 Standard_Real SqModn1=-1.0;
1283 Standard_Real SqModm1=-1.0;
1284 SqModn1=n1.SquareModulus();
55ab6ed6
P
1285 if (SqModn1>SquareMyConfusionPrecision){
1286 SqModm1=m1.SquareModulus();
1287 }
1288 if (SqModm1>SquareMyConfusionPrecision) {
1289 Angle=(n1.Dot(m1))/(sqrt(SqModn1)*sqrt(SqModm1));
7fd59977 1290 }
1291 return 1;
1292}
7fd59977 1293//=======================================================================
1294//function : TestNbPoints
1295//purpose : This function is used by StartingPointsResearch() to control
1296// the number of points found keep the result in conformity (1 or 2 points)
1297// void TestNbPoints(const Standard_Integer TriSurfID,
1298//=======================================================================
7fd59977 1299void TestNbPoints(const Standard_Integer ,
87696ff7 1300 Standard_Integer &NbPoints,
1301 Standard_Integer &NbPointsTotal,
1302 const IntPolyh_StartPoint &Pt1,
1303 const IntPolyh_StartPoint &Pt2,
1304 IntPolyh_StartPoint &SP1,
1305 IntPolyh_StartPoint &SP2)
55ab6ed6 1306{
68b07699 1307 // already checked in TriangleEdgeContact
7fd59977 1308 // if( (NbPoints==2)&&(Pt1.CheckSameSP(Pt2)) ) NbPoints=1;
1309
1310 if(NbPoints>2) {
55ab6ed6 1311
7fd59977 1312 }
1313 else {
1314 if ( (NbPoints==1)&&(NbPointsTotal==0) ) {
1315 SP1=Pt1;
1316 NbPointsTotal=1;
1317 }
1318 else if ( (NbPoints==1)&&(NbPointsTotal==1) ) {
1319 if(Pt1.CheckSameSP(SP1)!=1) {
87696ff7 1320 SP2=Pt1;
1321 NbPointsTotal=2;
7fd59977 1322 }
1323 }
1324 else if( (NbPoints==1)&&(NbPointsTotal==2) ) {
1325 if ( (SP1.CheckSameSP(Pt1))||(SP2.CheckSameSP(Pt1)) )
87696ff7 1326 NbPointsTotal=2;
7fd59977 1327 else NbPointsTotal=3;
1328 }
1329 else if( (NbPoints==2)&&(NbPointsTotal==0) ) {
1330 SP1=Pt1;
1331 SP2=Pt2;
1332 NbPointsTotal=2;
1333 }
1334 else if( (NbPoints==2)&&(NbPointsTotal==1) ) {//there is also Pt1 != Pt2
1335 if(SP1.CheckSameSP(Pt1)) {
87696ff7 1336 SP2=Pt2;
1337 NbPointsTotal=2;
7fd59977 1338 }
1339 else if (SP1.CheckSameSP(Pt2)) {
87696ff7 1340 SP2=Pt1;
1341 NbPointsTotal=2;
7fd59977 1342 }
1343 else NbPointsTotal=3;///case SP1!=Pt1 && SP1!=Pt2!
1344 }
1345 else if( (NbPoints==2)&&(NbPointsTotal==2) ) {//there is also SP1!=SP2
1346 if( (SP1.CheckSameSP(Pt1))||(SP1.CheckSameSP(Pt2)) ) {
87696ff7 1347 if( (SP2.CheckSameSP(Pt1))||(SP2.CheckSameSP(Pt2)) )
1348 NbPointsTotal=2;
1349 else NbPointsTotal=3;
7fd59977 1350 }
1351 else NbPointsTotal=3;
1352 }
1353 }
7fd59977 1354}
7fd59977 1355//=======================================================================
1356//function : StartingPointsResearch
7fd59977 1357//purpose : From two triangles compute intersection points.
1358// If I found more than two intersection points
1359// it means that those triangle are coplanar
1360//=======================================================================
68b07699 1361Standard_Integer IntPolyh_MaillageAffinage::StartingPointsResearch
55ab6ed6
P
1362 (const Standard_Integer T1,
1363 const Standard_Integer T2,
1364 IntPolyh_StartPoint &SP1,
1365 IntPolyh_StartPoint &SP2) const
1366{
7fd59977 1367 const IntPolyh_Triangle &Tri1=TTriangles1[T1];
1368 const IntPolyh_Triangle &Tri2=TTriangles2[T2];
1369
1370 const IntPolyh_Point &P1=TPoints1[Tri1.FirstPoint()];
1371 const IntPolyh_Point &P2=TPoints1[Tri1.SecondPoint()];
1372 const IntPolyh_Point &P3=TPoints1[Tri1.ThirdPoint()];
1373 const IntPolyh_Point &Q1=TPoints2[Tri2.FirstPoint()];
1374 const IntPolyh_Point &Q2=TPoints2[Tri2.SecondPoint()];
1375 const IntPolyh_Point &Q3=TPoints2[Tri2.ThirdPoint()];
1376
1377
1378
1379 /* The first triangle is (p1,p2,p3). The other is (q1,q2,q3).
1380 The sides are (e1,e2,e3) and (f1,f2,f3).
1381 The normals are n1 and m1*/
1382
1383 const IntPolyh_Point e1=P2-P1;
1384 const IntPolyh_Point e2=P3-P2;
1385 const IntPolyh_Point e3=P1-P3;
1386
1387 const IntPolyh_Point f1=Q2-Q1;
1388 const IntPolyh_Point f2=Q3-Q2;
1389 const IntPolyh_Point f3=Q1-Q3;
1390
1391
1392 IntPolyh_Point nn1,mm1;
1393 nn1.Cross(e1, e2); //normal to the first triangle
1394 mm1.Cross(f1, f2); //normal to the second triangle
1395
1396 Standard_Real nn1modulus, mm1modulus;
1397 nn1modulus=sqrt(nn1.SquareModulus());
1398 mm1modulus=sqrt(mm1.SquareModulus());
1399
1400 //-------------------------------------------------
1401 ///calculation of intersections points between triangles
1402 //-------------------------------------------------
1403 Standard_Integer NbPoints=0;
1404 Standard_Integer NbPointsTotal=0;
1405
1406
1407 ///check T1 normal
1408 if(Abs(nn1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1409
7fd59977 1410 }
1411 else {
1412 const IntPolyh_Point n1=nn1.Divide(nn1modulus);
1413 ///T2 edges with T1
1414 if(NbPointsTotal<3) {
87696ff7 1415 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1416 NbPoints=TriangleEdgeContact(1,1,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q1,Q2,f1,n1,Pt1,Pt2);
87696ff7 1417 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1418 }
1419
1420 if(NbPointsTotal<3) {
87696ff7 1421 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1422 NbPoints=TriangleEdgeContact(1,2,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q2,Q3,f2,n1,Pt1,Pt2);
87696ff7 1423 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1424 }
1425
1426 if(NbPointsTotal<3) {
87696ff7 1427 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1428 NbPoints=TriangleEdgeContact(1,3,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q3,Q1,f3,n1,Pt1,Pt2);
87696ff7 1429 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1430 }
1431 }
1432
1433 ///check T2 normal
1434 if(Abs(mm1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1435
7fd59977 1436 }
1437 else {
1438 const IntPolyh_Point m1=mm1.Divide(mm1modulus);
1439 ///T1 edges with T2
1440 if(NbPointsTotal<3) {
87696ff7 1441 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1442 NbPoints=TriangleEdgeContact(2,1,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P1,P2,e1,m1,Pt1,Pt2);
87696ff7 1443 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1444 }
1445
1446 if(NbPointsTotal<3) {
87696ff7 1447 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1448 NbPoints=TriangleEdgeContact(2,2,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P2,P3,e2,m1,Pt1,Pt2);
87696ff7 1449 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1450 }
1451
1452 if(NbPointsTotal<3) {
87696ff7 1453 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1454 NbPoints=TriangleEdgeContact(2,3,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P3,P1,e3,m1,Pt1,Pt2);
87696ff7 1455 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1456 }
1457 }
1458 // no need already checked in TestNbPoints
1459 // if( (NbPointsTotal==2)&&(SP1.CheckSameSP(SP2)) ) {
1460 // NbPointsTotal=1;
1461 //SP1.SetCoupleValue(T1,T2);
1462 // }
1463 // else
1464 if(NbPointsTotal==2) {
1465 SP1.SetCoupleValue(T1,T2);
1466 SP2.SetCoupleValue(T1,T2);
1467 }
1468 else if(NbPointsTotal==1)
1469 SP1.SetCoupleValue(T1,T2);
1470 else if(NbPointsTotal==3)
1471 SP1.SetCoupleValue(T1,T2);
1472
1473 return (NbPointsTotal);
1474}
7fd59977 1475//=======================================================================
1476//function : NextStartingPointsResearch
68b07699 1477//purpose : from two triangles and an intersection point I
1478// seach the other point (if it exist).
1479// This function is used by StartPointChain
7fd59977 1480//=======================================================================
55ab6ed6
P
1481Standard_Integer IntPolyh_MaillageAffinage::NextStartingPointsResearch
1482 (const Standard_Integer T1,
1483 const Standard_Integer T2,
1484 const IntPolyh_StartPoint &SPInit,
1485 IntPolyh_StartPoint &SPNext) const
1486{
7fd59977 1487 Standard_Integer NbPointsTotal=0;
68b07699 1488 Standard_Integer EdgeInit1=SPInit.E1();
1489 Standard_Integer EdgeInit2=SPInit.E2();
7fd59977 1490 if( (T1<0)||(T2<0) ) NbPointsTotal=0;
1491 else {
68b07699 1492
1493 const IntPolyh_Triangle &Tri1=TTriangles1[T1];
1494 const IntPolyh_Triangle &Tri2=TTriangles2[T2];
1495
1496 const IntPolyh_Point &P1=TPoints1[Tri1.FirstPoint()];
1497 const IntPolyh_Point &P2=TPoints1[Tri1.SecondPoint()];
1498 const IntPolyh_Point &P3=TPoints1[Tri1.ThirdPoint()];
1499 const IntPolyh_Point &Q1=TPoints2[Tri2.FirstPoint()];
1500 const IntPolyh_Point &Q2=TPoints2[Tri2.SecondPoint()];
1501 const IntPolyh_Point &Q3=TPoints2[Tri2.ThirdPoint()];
7fd59977 1502
1503 /* The first triangle is (p1,p2,p3). The other is (q1,q2,q3).
68b07699 1504 The edges are (e1,e2,e3) and (f1,f2,f3).
7fd59977 1505 The normals are n1 and m1*/
1506
1507 const IntPolyh_Point e1=P2-P1;
1508 const IntPolyh_Point e2=P3-P2;
1509 const IntPolyh_Point e3=P1-P3;
1510
1511 const IntPolyh_Point f1=Q2-Q1;
1512 const IntPolyh_Point f2=Q3-Q2;
1513 const IntPolyh_Point f3=Q1-Q3;
1514
1515 IntPolyh_Point nn1,mm1;
1516 nn1.Cross(e1, e2); //normal to the first triangle
1517 mm1.Cross(f1, f2); //normal to the second triangle
1518
1519 Standard_Real nn1modulus, mm1modulus;
1520 nn1modulus=sqrt(nn1.SquareModulus());
1521 mm1modulus=sqrt(mm1.SquareModulus());
68b07699 1522
7fd59977 1523 //-------------------------------------------------
1524 ///calculation of intersections points between triangles
1525 //-------------------------------------------------
68b07699 1526
7fd59977 1527 Standard_Integer NbPoints=0;
1528 IntPolyh_StartPoint SP1,SP2;
68b07699 1529
7fd59977 1530 ///check T1 normal
1531 if(Abs(nn1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1532
7fd59977 1533 }
1534 else {
1535 const IntPolyh_Point n1=nn1.Divide(nn1modulus);
1536 ///T2 edges with T1
1537 if( (NbPointsTotal<3)&&(EdgeInit2!=Tri2.FirstEdge()) ) {
87696ff7 1538 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1539 NbPoints=TriangleEdgeContact(1,1,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q1,Q2,f1,n1,Pt1,Pt2);
87696ff7 1540 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1541 }
1542
1543 if( (NbPointsTotal<3)&&(EdgeInit2!=Tri2.SecondEdge()) ) {
87696ff7 1544 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1545 NbPoints=TriangleEdgeContact(1,2,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q2,Q3,f2,n1,Pt1,Pt2);
87696ff7 1546 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1547 }
1548
1549 if( (NbPointsTotal<3)&&(EdgeInit2!=Tri2.ThirdEdge()) ) {
87696ff7 1550 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1551 NbPoints=TriangleEdgeContact(1,3,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q3,Q1,f3,n1,Pt1,Pt2);
87696ff7 1552 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1553 }
1554 }
1555 ///check T2 normal
1556 if(Abs(mm1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1557
7fd59977 1558 }
1559 else {
1560 const IntPolyh_Point m1=mm1.Divide(mm1modulus);
1561 ///T1 edges with T2
1562 if( (NbPointsTotal<3)&&(EdgeInit1!=Tri1.FirstEdge()) ) {
87696ff7 1563 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1564 NbPoints=TriangleEdgeContact(2,1,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P1,P2,e1,m1,Pt1,Pt2);
87696ff7 1565 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1566 }
1567
1568 if( (NbPointsTotal<3)&&(EdgeInit1!=Tri1.SecondEdge()) ) {
87696ff7 1569 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1570 NbPoints=TriangleEdgeContact(2,2,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P2,P3,e2,m1,Pt1,Pt2);
87696ff7 1571 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1572 }
1573
1574 if( (NbPointsTotal<3)&&(EdgeInit1!=Tri1.ThirdEdge()) ) {
87696ff7 1575 IntPolyh_StartPoint Pt1,Pt2;
68b07699 1576 NbPoints=TriangleEdgeContact(2,3,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P3,P1,e3,m1,Pt1,Pt2);
87696ff7 1577 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
7fd59977 1578 }
1579 }
1580
1581 if (NbPointsTotal==1) {
1582 if(SP1.CheckSameSP(SPInit))
87696ff7 1583 NbPointsTotal=0;
7fd59977 1584 else {
87696ff7 1585 SPNext=SP1;
7fd59977 1586 }
1587 }
1588 else if( (NbPointsTotal==2)&&(SP1.CheckSameSP(SPInit)) ) {
1589 NbPointsTotal=1;//SP1 et SPInit sont identiques
1590 SPNext=SP2;
1591 }
1592 else if( (NbPointsTotal==2)&&(SP2.CheckSameSP(SPInit)) ) {
1593 NbPointsTotal=1;//SP2 et SPInit sont identiques
1594 SPNext=SP1;
1595 }
1596
1597 else if(NbPointsTotal>1) {
55ab6ed6 1598
7fd59977 1599 }
1600 }
1601 SPNext.SetCoupleValue(T1,T2);
1602 return (NbPointsTotal);
1603}
7fd59977 1604//=======================================================================
1605//function : CalculPtsInterTriEdgeCoplanaires
1606//purpose :
1607//=======================================================================
7fd59977 1608void CalculPtsInterTriEdgeCoplanaires(const Standard_Integer TriSurfID,
87696ff7 1609 const IntPolyh_Point &NormaleTri,
68b07699 1610 const IntPolyh_Triangle &Tri1,
1611 const IntPolyh_Triangle &Tri2,
87696ff7 1612 const IntPolyh_Point &PE1,
1613 const IntPolyh_Point &PE2,
1614 const IntPolyh_Point &Edge,
68b07699 1615 const Standard_Integer EdgeIndex,
87696ff7 1616 const IntPolyh_Point &PT1,
1617 const IntPolyh_Point &PT2,
1618 const IntPolyh_Point &Cote,
1619 const Standard_Integer CoteIndex,
1620 IntPolyh_StartPoint &SP1,
1621 IntPolyh_StartPoint &SP2,
68b07699 1622 Standard_Integer &NbPoints)
87696ff7 1623{
1624 Standard_Real aDE, aDC;
1625 //
1626 gp_Vec aVE(Edge.X(), Edge.Y(), Edge.Z());
1627 gp_Vec aVC(Cote.X(), Cote.Y(), Cote.Z());
1628 //
1629 aDE = aVE.SquareMagnitude();
1630 aDC = aVC.SquareMagnitude();
1631 //
1632 if (aDE > SquareMyConfusionPrecision) {
1633 aVE.Divide(aDE);
1634 }
1635 //
1636 if (aDC > SquareMyConfusionPrecision) {
1637 aVC.Divide(aDC);
1638 }
1639 //
1640 if (!aVE.IsParallel(aVC, MyConfusionPrecision)) {
7fd59977 1641 ///Edge and side are not parallel
1642 IntPolyh_Point Per;
1643 Per.Cross(NormaleTri,Cote);
1644 Standard_Real p1p = Per.Dot(PE1);
1645 Standard_Real p2p = Per.Dot(PE2);
1646 Standard_Real p0p = Per.Dot(PT1);
1647 ///The edge are PT1 are projected on the perpendicular of the side in the plane of the triangle
f4dee9bb 1648 if ( ( ((p1p>=p0p)&&(p0p>=p2p) )||( (p1p<=p0p)&&(p0p<=p2p) )) && (Abs(p1p-p2p) > MyConfusionPrecision)) {
7fd59977 1649 Standard_Real lambda=(p1p-p0p)/(p1p-p2p);
1650 if (lambda<-MyConfusionPrecision) {
55ab6ed6 1651
7fd59977 1652 }
1653 IntPolyh_Point PIE;
1654 if (Abs(lambda)<MyConfusionPrecision)//lambda=0
87696ff7 1655 PIE=PE1;
7fd59977 1656 else if (Abs(lambda)>1.0-MyConfusionPrecision)//lambda=1
87696ff7 1657 PIE=PE2;
7fd59977 1658 else
87696ff7 1659 PIE=PE1+Edge*lambda;
7fd59977 1660
1661 Standard_Real alpha=RealLast();
1662 if(Cote.X()!=0) alpha=(PIE.X()-PT1.X())/Cote.X();
1663 else if (Cote.Y()!=0) alpha=(PIE.Y()-PT1.Y())/Cote.Y();
1664 else if (Cote.Z()!=0) alpha=(PIE.Z()-PT1.Z())/Cote.Z();
1665 else {
55ab6ed6 1666
7fd59977 1667 }
1668
1669 if (alpha<-MyConfusionPrecision) {
55ab6ed6 1670
7fd59977 1671 }
1672 else {
87696ff7 1673 if (NbPoints==0) {
1674 SP1.SetXYZ(PIE.X(),PIE.Y(),PIE.Z());
1675 if (TriSurfID==1) {
1676 if(Abs(alpha)<MyConfusionPrecision) {//alpha=0
1677 SP1.SetUV1(PT1.U(),PT1.V());
1678 SP1.SetUV1(PIE.U(),PIE.V());
1679 SP1.SetEdge1(-1);
1680 }
1681 if(Abs(alpha)>1.0-MyConfusionPrecision) {//alpha=1
1682 SP1.SetUV1(PT2.U(),PT2.V());
1683 SP1.SetUV1(PIE.U(),PIE.V());
1684 SP1.SetEdge1(-1);
1685 }
1686 else {
1687 SP1.SetUV1(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
1688 SP1.SetUV2(PIE.U(),PIE.V());
1689 SP1.SetEdge1(Tri1.GetEdgeNumber(CoteIndex));
1690 if (Tri1.GetEdgeOrientation(CoteIndex)>0) SP1.SetLambda1(alpha);
1691 else SP1.SetLambda1(1.0-alpha);
1692 }
1693 NbPoints++;
1694 }
1695 else if (TriSurfID==2) {
1696 if(Abs(alpha)<MyConfusionPrecision) {//alpha=0
1697 SP1.SetUV1(PT1.U(),PT1.V());
1698 SP1.SetUV1(PIE.U(),PIE.V());
1699 SP1.SetEdge2(-1);
1700 }
1701 if(Abs(alpha)>1.0-MyConfusionPrecision) {//alpha=1
1702 SP1.SetUV1(PT2.U(),PT2.V());
1703 SP1.SetUV1(PIE.U(),PIE.V());
1704 SP1.SetEdge2(-1);
1705 }
1706 else {
1707 SP1.SetUV1(PIE.U(),PIE.V());
1708 SP1.SetUV2(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
1709 SP1.SetEdge2(Tri2.GetEdgeNumber(CoteIndex));
1710 if (Tri2.GetEdgeOrientation(CoteIndex)>0) SP1.SetLambda2(alpha);
1711 else SP1.SetLambda2(1.0-alpha);
1712 }
1713 NbPoints++;
1714 }
1715 else {
1716
1717 }
1718 }
1719
1720 else if (NbPoints==1) {
1721 SP2.SetXYZ(PIE.X(),PIE.Y(),PIE.Z());
1722 if (TriSurfID==1) {
1723 if(Abs(alpha)<MyConfusionPrecision) {//alpha=0
1724 SP2.SetUV1(PT1.U(),PT1.V());
1725 SP2.SetUV1(PIE.U(),PIE.V());
1726 SP2.SetEdge1(-1);
1727 }
1728 if(Abs(alpha)>1.0-MyConfusionPrecision) {//alpha=1
1729 SP2.SetUV1(PT2.U(),PT2.V());
1730 SP2.SetUV1(PIE.U(),PIE.V());
1731 SP2.SetEdge1(-1);
1732 }
1733 else {
1734 SP2.SetUV1(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
1735 SP2.SetUV2(PIE.U(),PIE.V());
1736 SP2.SetEdge1(Tri1.GetEdgeNumber(CoteIndex));
1737 if (Tri1.GetEdgeOrientation(CoteIndex)>0) SP2.SetLambda1(alpha);
1738 else SP2.SetLambda1(1.0-alpha);
1739 }
1740 NbPoints++;
1741 }
1742 else if (TriSurfID==2) {
1743 if(Abs(alpha)<MyConfusionPrecision) {//alpha=0
1744 SP2.SetUV1(PT1.U(),PT1.V());
1745 SP2.SetUV1(PIE.U(),PIE.V());
1746 SP2.SetEdge2(-1);
1747 }
1748 if(Abs(alpha)>1.0-MyConfusionPrecision) {//alpha=1
1749 SP2.SetUV1(PT2.U(),PT2.V());
1750 SP2.SetUV1(PIE.U(),PIE.V());
1751 SP2.SetEdge2(-1);
1752 }
1753 else {
1754 SP2.SetUV1(PIE.U(),PIE.V());
1755 SP2.SetUV2(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
1756 SP2.SetEdge2(Tri2.GetEdgeNumber(CoteIndex));
1757 if (Tri1.GetEdgeOrientation(CoteIndex)>0) SP2.SetLambda2(alpha);
1758 else SP2.SetLambda2(1.0-alpha);
1759 }
1760 NbPoints++;
1761 }
1762 else {
1763
1764 }
1765 }
1766
1767 else if( (NbPoints>2)||(NbPoints<0) ) {
1768
1769 }
7fd59977 1770 }
1771 }
1772 }
55ab6ed6
P
1773 else {
1774 //Side and Edge are parallel, with previous
1775 //rejections they are at the same side
7fd59977 1776 //The points are projected on that side
1777 Standard_Real pe1p= Cote.Dot(PE1);
1778 Standard_Real pe2p= Cote.Dot(PE2);
1779 Standard_Real pt1p= Cote.Dot(PT1);
1780 Standard_Real pt2p= Cote.Dot(PT2);
4e57c75e 1781 Standard_Real lambda1=0., lambda2=0., alpha1=0., alpha2=0.;
7fd59977 1782 IntPolyh_Point PEP1,PTP1,PEP2,PTP2;
1783
7fd59977 1784 if (pe1p>pe2p) {
1785 if ( (pt1p<pe1p)&&(pe1p<=pt2p) ) {
87696ff7 1786 lambda1=0.0;
1787 PEP1=PE1;
1788 alpha1=((pe1p-pt1p)/(pt2p-pt1p));
1789 PTP1=PT1+Cote*alpha1;
1790 NbPoints=1;
1791 if (pt1p<=pe2p) {
1792 lambda2=1.0;
1793 PEP2=PE2;
1794 alpha2=((pe2p-pt1p)/(pt2p-pt1p));
1795 PTP2=PT1+Cote*alpha2;
1796 NbPoints=2;
1797 }
1798 else {
1799 lambda2=((pt1p-pe1p)/(pe2p-pe1p));
1800 PEP2=PE1+Edge*lambda2;
1801 alpha2=0.0;
1802 PTP2=PT1;
1803 NbPoints=2;
1804 }
7fd59977 1805 }
1806 else if( (pt2p<pe1p)&&(pe1p<=pt1p) ) {
87696ff7 1807 lambda1=0.0;
1808 PEP1=PE1;
1809 alpha1=((pt1p-pe1p)/(pt1p-pt2p));
1810 PTP1=PT1+Cote*alpha1;
1811 NbPoints=1;
1812 if (pt2p<=pe2p) {
1813 lambda2=1.0;
1814 PEP2=PE2;
1815 alpha2=((pe2p-pt1p)/(pt2p-pt1p));
1816 PTP2=PT1+Cote*alpha2;
1817 NbPoints=2;
1818 }
1819 else {
1820 lambda2=((pt2p-pe1p)/(pe2p-pe1p));
1821 PEP2=PE1+Edge*lambda2;
1822 alpha2=1.0;
1823 PTP2=PT2;
1824 NbPoints=2;
1825 }
7fd59977 1826 }
1827 }
1828
1829 if (pe1p<pe2p) {
1830 if ( (pt1p<pe2p)&&(pe2p<=pt2p) ) {
87696ff7 1831 lambda1=1.0;
1832 PEP1=PE2;
1833 alpha1=((pe2p-pt1p)/(pt2p-pt1p));
1834 PTP1=PT1+Cote*alpha1;
1835 NbPoints=1;
1836 if (pt1p<=pe1p) {
1837 lambda2=0.0;
1838 PEP2=PE1;
1839 alpha2=((pe1p-pt1p)/(pt2p-pt1p));
1840 PTP2=PT1+Cote*alpha2;
1841 NbPoints=2;
1842 }
1843 else {
1844 lambda2=((pt1p-pe1p)/(pe2p-pe1p));
1845 PEP2=PE2+Edge*lambda2;
1846 alpha2=0.0;
1847 PTP2=PT1;
1848 NbPoints=2;
1849 }
7fd59977 1850 }
1851 else if( (pt2p<pe2p)&&(pe2p<=pt1p) ) {
87696ff7 1852 lambda1=1.0;
1853 PEP1=PE2;
1854 alpha1=((pt1p-pe2p)/(pt1p-pt2p));
1855 PTP1=PT1+Cote*alpha1;
1856 NbPoints=1;
1857 if (pt2p<=pe1p) {
1858 lambda2=0.0;
1859 PEP2=PE1;
1860 alpha2=((pe1p-pt1p)/(pt2p-pt1p));
1861 PTP2=PT1+Cote*alpha2;
1862 NbPoints=2;
1863 }
68b07699 1864 else {
1865 lambda2=((pt2p-pe1p)/(pe2p-pe1p));
1866 PEP2=PE1+Edge*lambda2;
1867 alpha2=1.0;
1868 PTP2=PT2;
1869 NbPoints=2;
87696ff7 1870 }
7fd59977 1871 }
7fd59977 1872 }
68b07699 1873
1874 if (NbPoints!=0) {
1875 SP1.SetXYZ(PEP1.X(),PEP1.Y(),PEP1.Z());
1876 if (TriSurfID==1) {///cote appartient a Tri1
1877 SP1.SetUV1(PTP1.U(),PTP1.V());
1878 SP1.SetUV2(PEP1.U(),PEP1.V());
1879 SP1.SetEdge1(Tri1.GetEdgeNumber(CoteIndex));
55ab6ed6 1880
68b07699 1881 if(Tri1.GetEdgeOrientation(CoteIndex)>0) SP1.SetLambda1(alpha1);
1882 else SP1.SetLambda1(1.0-alpha1);
87696ff7 1883
68b07699 1884 if(Tri2.GetEdgeOrientation(EdgeIndex)>0) SP1.SetLambda2(lambda1);
1885 else SP1.SetLambda2(1.0-lambda1);
7fd59977 1886 }
68b07699 1887 if (TriSurfID==2) {///cote appartient a Tri2
1888 SP1.SetUV1(PEP1.U(),PTP1.V());
1889 SP1.SetUV2(PTP1.U(),PEP1.V());
1890 SP1.SetEdge2(Tri2.GetEdgeNumber(CoteIndex));
55ab6ed6 1891
68b07699 1892 if(Tri2.GetEdgeOrientation(CoteIndex)>0) SP1.SetLambda1(alpha1);
1893 else SP1.SetLambda1(1.0-alpha1);
87696ff7 1894
68b07699 1895 if(Tri1.GetEdgeOrientation(EdgeIndex)>0) SP1.SetLambda2(lambda1);
1896 else SP1.SetLambda2(1.0-lambda1);
7fd59977 1897 }
1898
68b07699 1899 //It is checked if PEP1!=PEP2
1900 if ( (NbPoints==2)&&(Abs(PEP1.U()-PEP2.U())<MyConfusionPrecision)
1901 &&(Abs(PEP1.V()-PEP2.V())<MyConfusionPrecision) ) NbPoints=1;
1902 if (NbPoints==2) {
1903 SP2.SetXYZ(PEP2.X(),PEP2.Y(),PEP2.Z());
87696ff7 1904 if (TriSurfID==1) {
68b07699 1905 SP2.SetUV1(PTP2.U(),PTP2.V());
1906 SP2.SetUV2(PEP2.U(),PEP2.V());
1907 SP2.SetEdge1(Tri1.GetEdgeNumber(CoteIndex));
87696ff7 1908
68b07699 1909 if(Tri1.GetEdgeOrientation(CoteIndex)>0) SP2.SetLambda1(alpha1);
1910 else SP2.SetLambda1(1.0-alpha1);
1911
1912 if(Tri2.GetEdgeOrientation(EdgeIndex)>0) SP2.SetLambda2(lambda1);
1913 else SP2.SetLambda2(1.0-lambda1);
87696ff7 1914 }
68b07699 1915 if (TriSurfID==2) {
1916 SP2.SetUV1(PEP2.U(),PTP2.V());
1917 SP2.SetUV2(PTP2.U(),PEP2.V());
1918 SP2.SetEdge2(Tri2.GetEdgeNumber(CoteIndex));
1919
1920 if(Tri1.GetEdgeOrientation(CoteIndex)>0) SP2.SetLambda1(alpha1);
1921 else SP2.SetLambda1(1.0-alpha1);
1922
1923 if(Tri2.GetEdgeOrientation(EdgeIndex)>0) SP2.SetLambda2(lambda1);
1924 else SP2.SetLambda2(1.0-lambda1);
1925 }
7fd59977 1926 }
1927 }
7fd59977 1928 }
68b07699 1929 //Filter if the point is placed on top, the edge is set to -1
1930 if (NbPoints>0) {
1931 if(Abs(SP1.Lambda1())<MyConfusionPrecision)
1932 SP1.SetEdge1(-1);
1933 if(Abs(SP1.Lambda1()-1)<MyConfusionPrecision)
1934 SP1.SetEdge1(-1);
1935 if(Abs(SP1.Lambda2())<MyConfusionPrecision)
1936 SP1.SetEdge2(-1);
1937 if(Abs(SP1.Lambda2()-1)<MyConfusionPrecision)
1938 SP1.SetEdge2(-1);
1939 }
1940 if (NbPoints==2) {
1941 if(Abs(SP2.Lambda1())<MyConfusionPrecision)
1942 SP2.SetEdge1(-1);
1943 if(Abs(SP2.Lambda1()-1)<MyConfusionPrecision)
1944 SP2.SetEdge1(-1);
1945 if(Abs(SP2.Lambda2())<MyConfusionPrecision)
1946 SP2.SetEdge2(-1);
1947 if(Abs(SP2.Lambda2()-1)<MyConfusionPrecision)
1948 SP2.SetEdge2(-1);
1949 }
7fd59977 1950}
1951
1952//=======================================================================
68b07699 1953//function : TriangleEdgeContact
7fd59977 1954//purpose :
1955//=======================================================================
68b07699 1956Standard_Integer IntPolyh_MaillageAffinage::TriangleEdgeContact
55ab6ed6
P
1957 (const Standard_Integer TriSurfID,
1958 const Standard_Integer EdgeIndex,
1959 const IntPolyh_Triangle &Tri1,
1960 const IntPolyh_Triangle &Tri2,
1961 const IntPolyh_Point &PT1,
1962 const IntPolyh_Point &PT2,
1963 const IntPolyh_Point &PT3,
1964 const IntPolyh_Point &Cote12,
1965 const IntPolyh_Point &Cote23,
1966 const IntPolyh_Point &Cote31,
1967 const IntPolyh_Point &PE1,const IntPolyh_Point &PE2,
1968 const IntPolyh_Point &Edge,
1969 const IntPolyh_Point &NormaleT,
1970 IntPolyh_StartPoint &SP1,IntPolyh_StartPoint &SP2) const
1971{
7fd59977 1972
7fd59977 1973 Standard_Real lambda =0., alpha =0., beta =0.;
7fd59977 1974
1975 //One of edges on which the point is located is known
1976 if (TriSurfID==1) {
1977 SP1.SetEdge2(Tri2.GetEdgeNumber(EdgeIndex));
1978 SP2.SetEdge2(Tri2.GetEdgeNumber(EdgeIndex));
1979 }
1980 else if (TriSurfID==2) {
1981 SP1.SetEdge1(Tri1.GetEdgeNumber(EdgeIndex));
1982 SP2.SetEdge1(Tri1.GetEdgeNumber(EdgeIndex));
1983 }
1984 else {
55ab6ed6 1985
7fd59977 1986 }
1987
1988 /**The edge is projected on the normal in the triangle if yes
1989 --> a free intersection (point I)--> Start point is found */
1990 Standard_Integer NbPoints=0;
1991 if(NormaleT.SquareModulus()==0) {
55ab6ed6 1992
7fd59977 1993 }
1994 else if( (Cote12.SquareModulus()==0)
1995 ||(Cote23.SquareModulus()==0)
1996 ||(Cote31.SquareModulus()==0) ) {
55ab6ed6 1997
7fd59977 1998 }
1999 else if(Edge.SquareModulus()==0) {
55ab6ed6 2000
7fd59977 2001 }
2002 else {
2003 Standard_Real pe1 = NormaleT.Dot(PE1);
2004 Standard_Real pe2 = NormaleT.Dot(PE2);
2005 Standard_Real pt1 = NormaleT.Dot(PT1);
2006
2007 // PE1I = lambda.Edge
2008
2009 if( (Abs(pe1-pt1)<MyConfusionPrecision)&&(Abs(pe2-pt1)<MyConfusionPrecision)) {
2010 //edge and triangle are coplanar (two contact points at maximum)
55ab6ed6 2011
7fd59977 2012
2013 //the tops of the triangle are projected on the perpendicular to the edge
2014 IntPolyh_Point PerpEdge;
2015 PerpEdge.Cross(NormaleT,Edge);
2016 Standard_Real pp1 = PerpEdge.Dot(PT1);
2017 Standard_Real pp2 = PerpEdge.Dot(PT2);
2018 Standard_Real pp3 = PerpEdge.Dot(PT3);
2019 Standard_Real ppe1 = PerpEdge.Dot(PE1);
2020
2021
2022 if ( (Abs(pp1-pp2)<MyConfusionPrecision)&&(Abs(pp1-pp3)<MyConfusionPrecision) ) {
55ab6ed6 2023
7fd59977 2024 }
2025 else {
87696ff7 2026 if ( ( (pp1>=ppe1)&&(pp2<=ppe1)&&(pp3<=ppe1) ) || ( (pp1<=ppe1)&&(pp2>=ppe1)&&(pp3>=ppe1) ) ){
2027 //there are two sides (common top PT1) that can cut the edge
2028
2029 //first side
68b07699 2030 CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2031 PT1,PT2,Cote12,1,SP1,SP2,NbPoints);
87696ff7 2032
2033 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2034 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2035
2036 //second side
68b07699 2037 if (NbPoints<2) CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2038 PT3,PT1,Cote31,3,SP1,SP2,NbPoints);
87696ff7 2039 }
2040
2041 if ( (NbPoints>1)&&(Abs(SP1.U1()-SP2.U1())<MyConfusionPrecision)
2042 &&(Abs(SP1.V2()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2043 if (NbPoints>=2) return(NbPoints);
2044
2045 else if ( ( ( (pp2>=ppe1)&&(pp1<=ppe1)&&(pp3<=ppe1) ) || ( (pp2<=ppe1)&&(pp1>=ppe1)&&(pp3>=ppe1) ) )
2046 && (NbPoints<2) ) {
2047 //there are two sides (common top PT2) that can cut the edge
2048
2049 //first side
68b07699 2050 CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2051 PT1,PT2,Cote12,1,SP1,SP2,NbPoints);
87696ff7 2052
2053 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2054 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2055
2056 //second side
68b07699 2057 if(NbPoints<2) CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2058 PT2,PT3,Cote23,2,SP1,SP2,NbPoints);
87696ff7 2059 }
2060 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2061 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2062 if (NbPoints>=2) return(NbPoints);
2063
2064 else if ( (( (pp3>=ppe1)&&(pp1<=ppe1)&&(pp2<=ppe1) ) || ( (pp3<=ppe1)&&(pp1>=ppe1)&&(pp2>=ppe1) ))
0ebaa4db 2065 && (NbPoints<2) ) {
87696ff7 2066 //there are two sides (common top PT3) that can cut the edge
2067
2068 //first side
68b07699 2069 CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2070 PT3,PT1,Cote31,3,SP1,SP2,NbPoints);
87696ff7 2071
2072 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2073 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2074
2075 //second side
68b07699 2076 if (NbPoints<2) CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2077 PT2,PT3,Cote23,2,SP1,SP2,NbPoints);
87696ff7 2078 }
2079 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2080 &&(Abs(SP2.V1()-SP1.V1())<MyConfusionPrecision) ) NbPoints=1;
2081 if (NbPoints>=2) return(NbPoints);
7fd59977 2082 }
2083 }
2084
2085 //------------------------------------------------------
2086 // NON COPLANAR edge and triangle (a contact point)
2087 //------------------------------------------------------
2088 else if( ( (pe1>=pt1)&&(pt1>=pe2) ) || ( (pe1<=pt1)&&(pt1<=pe2) ) ) { //
2089 lambda=(pe1-pt1)/(pe1-pe2);
2090 IntPolyh_Point PI;
2091 if (lambda<-MyConfusionPrecision) {
55ab6ed6 2092
7fd59977 2093 }
2094 else if (Abs(lambda)<MyConfusionPrecision) {//lambda==0
87696ff7 2095 PI=PE1;
2096 if(TriSurfID==1) SP1.SetEdge2(-1);
2097 else SP1.SetEdge1(-1);
7fd59977 2098 }
2099 else if (Abs(lambda-1.0)<MyConfusionPrecision) {//lambda==1
87696ff7 2100 PI=PE2;
2101 if(TriSurfID==1) SP1.SetEdge2(-1);
2102 else SP1.SetEdge1(-1);
7fd59977 2103 }
2104 else {
eafb234b 2105 PI=PE1+Edge*lambda;
2106 if(TriSurfID==1) {
2107 if(Tri2.GetEdgeOrientation(EdgeIndex)>0)
2108 SP1.SetLambda2(lambda);
2109 else SP1.SetLambda2(1.0-lambda);
2110 }
2111 if(TriSurfID==2) {
2112 if(Tri1.GetEdgeOrientation(EdgeIndex)>0)
2113 SP1.SetLambda1(lambda);
2114 else SP1.SetLambda1(1.0-lambda);
2115 }
7fd59977 2116 }
55ab6ed6 2117
7fd59977 2118 Standard_Real Cote23X=Cote23.X();
2119 Standard_Real D1=0.0;
2120 Standard_Real D3,D4;
2121
2122 //Combination Eq1 Eq2
2123 if(Abs(Cote23X)>MyConfusionPrecision) {
87696ff7 2124 D1=Cote12.Y()-Cote12.X()*Cote23.Y()/Cote23X;
7fd59977 2125 }
2126 if(Abs(D1)>MyConfusionPrecision) {
87696ff7 2127 alpha = ( PI.Y()-PT1.Y()-(PI.X()-PT1.X())*Cote23.Y()/Cote23X )/D1;
7fd59977 2128
87696ff7 2129 ///It is checked if 1.0>=alpha>=0.0
2130 if ((alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision))) return(0);
2131 else beta = (PI.X()-PT1.X()-alpha*Cote12.X())/Cote23X;
7fd59977 2132 }
2133 //Combination Eq1 and Eq2 with Cote23.X()==0
2134 else if ( (Abs(Cote12.X())>MyConfusionPrecision)
87696ff7 2135 &&(Abs(Cote23X)<MyConfusionPrecision) ) { //There is Cote23.X()==0
2136 alpha = (PI.X()-PT1.X())/Cote12.X();
2137
2138 if ((alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision))) return(0);
2139
2140 else if (Abs(Cote23.Y())>MyConfusionPrecision) beta = (PI.Y()-PT1.Y()-alpha*Cote12.Y())/Cote23.Y();
2141 else if (Abs(Cote23.Z())>MyConfusionPrecision) beta = (PI.Z()-PT1.Z()-alpha*Cote12.Z())/Cote23.Z();
2142 else {
55ab6ed6 2143
87696ff7 2144 }
7fd59977 2145 }
2146 //Combination Eq1 and Eq3
2147 else if ( (Abs(Cote23.X())>MyConfusionPrecision)
87696ff7 2148 &&(Abs( D3= (Cote12.Z()-Cote12.X()*Cote23.Z()/Cote23.X()) ) > MyConfusionPrecision) ) {
2149
2150 alpha = (PI.Z()-PT1.Z()-(PI.X()-PT1.X())*Cote23.Z()/Cote23.X())/D3;
2151
2152 if ( (alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision)) ) return(0);
2153 else beta = (PI.X()-PT1.X()-alpha*Cote12.X())/Cote23.X();
7fd59977 2154 }
2155 //Combination Eq2 and Eq3
2156 else if ( (Abs(Cote23.Y())>MyConfusionPrecision)
87696ff7 2157 &&(Abs( D4= (Cote12.Z()-Cote12.Y()*Cote23.Z()/Cote23.Y()) ) > MyConfusionPrecision) ) {
2158
2159 alpha = (PI.Z()-PT1.Z()-(PI.Y()-PT1.Y())*Cote23.Z()/Cote23.Y())/D4;
2160
2161 if ( (alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision)) ) return(0);
2162 else beta = (PI.Y()-PT1.Y()-alpha*Cote12.Y())/Cote23.Y();
7fd59977 2163 }
2164 //Combination Eq2 and Eq3 with Cote23.Y()==0
2165 else if ( (Abs(Cote12.Y())>MyConfusionPrecision)
87696ff7 2166 && (Abs(Cote23.Y())<MyConfusionPrecision) ) {
2167 alpha = (PI.Y()-PT1.Y())/Cote12.Y();
2168
2169 if ( (alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision)) ) return(0);
2170
2171 else if (Abs(Cote23.Z())>MyConfusionPrecision) beta = (PI.Z()-PT1.Z()-alpha*Cote12.Z())/Cote23.Z();
2172
2173 else {
2174 printf("\nCote PT2PT3 nul1\n");
2175 PT2.Dump(2004);
2176 PT3.Dump(3004);
2177 }
7fd59977 2178 }
2179 //Combination Eq1 and Eq3 with Cote23.Z()==0
2180 else if ( (Abs(Cote12.Z())>MyConfusionPrecision)
87696ff7 2181 && (Abs(Cote23.Z())<MyConfusionPrecision) ) {
2182 alpha = (PI.Z()-PT1.Z())/Cote12.Z();
2183
2184 if ( (alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision)) ) return(0);
2185
2186 else if (Abs(Cote23.X())>MyConfusionPrecision) beta = (PI.X()-PT1.X()-alpha*Cote12.X())/Cote23.X();
2187
2188 else {
55ab6ed6 2189
87696ff7 2190 }
7fd59977 2191 }
2192
2193 else { //Particular case not processed ?
55ab6ed6 2194
87696ff7 2195 alpha=RealLast();
2196 beta=RealLast();
7fd59977 2197 }
2198
2199 if( (beta<-MyConfusionPrecision)||(beta>(alpha+MyConfusionPrecision)) ) return(0);
2200 else {
87696ff7 2201 SP1.SetXYZ(PI.X(),PI.Y(),PI.Z());
2202
2203 if (TriSurfID==1) {
2204 SP1.SetUV2(PI.U(),PI.V());
2205 SP1.SetUV1(PT1.U()+Cote12.U()*alpha+Cote23.U()*beta, PT1.V()+Cote12.V()*alpha+Cote23.V()*beta);
2206 NbPoints++;
2207 if (alpha<MyConfusionPrecision) {//alpha=0 --> beta==0
2208 SP1.SetXYZ(PT1.X(),PT1.Y(),PT1.Z());
2209 SP1.SetUV1(PT1.U(),PT1.V());
2210 SP1.SetEdge1(-1);
2211 }
2212 else if ( (beta<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==0 alpha==1
2213 SP1.SetXYZ(PT2.X(),PT2.Y(),PT2.Z());
2214 SP1.SetUV1(PT2.U(),PT2.V());
2215 SP1.SetEdge1(-1);
2216 }
2217 else if ( (Abs(beta-1)<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==1 alpha==1
2218 SP1.SetXYZ(PT3.X(),PT3.Y(),PT3.Z());
2219 SP1.SetUV1(PT3.U(),PT3.V());
2220 SP1.SetEdge1(-1);
2221 }
2222 else if (beta<MyConfusionPrecision) {//beta==0
2223 SP1.SetEdge1(Tri1.GetEdgeNumber(1));
2224 if(Tri1.GetEdgeOrientation(1)>0)
2225 SP1.SetLambda1(alpha);
2226 else SP1.SetLambda1(1.0-alpha);
2227 }
2228 else if (Abs(beta-alpha)<MyConfusionPrecision) {//beta==alpha
2229 SP1.SetEdge1(Tri1.GetEdgeNumber(3));
2230 if(Tri1.GetEdgeOrientation(3)>0)
2231 SP1.SetLambda1(1.0-alpha);
2232 else SP1.SetLambda1(alpha);
2233 }
2234 else if (Abs(alpha-1)<MyConfusionPrecision) {//alpha==1
2235 SP1.SetEdge1(Tri1.GetEdgeNumber(2));
2236 if(Tri1.GetEdgeOrientation(2)>0)
2237 SP1.SetLambda1(beta);
2238 else SP1.SetLambda1(1.0-beta);
2239 }
2240 }
2241 else if(TriSurfID==2) {
2242 SP1.SetUV1(PI.U(),PI.V());
2243 SP1.SetUV2(PT1.U()+Cote12.U()*alpha+Cote23.U()*beta, PT1.V()+Cote12.V()*alpha+Cote23.V()*beta);
2244 NbPoints++;
2245 if (alpha<MyConfusionPrecision) {//alpha=0 --> beta==0
2246 SP1.SetXYZ(PT1.X(),PT1.Y(),PT1.Z());
2247 SP1.SetUV2(PT1.U(),PT1.V());
2248 SP1.SetEdge2(-1);
2249 }
2250 else if ( (beta<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==0 alpha==1
2251 SP1.SetXYZ(PT2.X(),PT2.Y(),PT2.Z());
2252 SP1.SetUV2(PT2.U(),PT2.V());
2253 SP1.SetEdge2(-1);
2254 }
2255 else if ( (Abs(beta-1)<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==1 alpha==1
2256 SP1.SetXYZ(PT3.X(),PT3.Y(),PT3.Z());
2257 SP1.SetUV2(PT3.U(),PT3.V());
2258 SP1.SetEdge2(-1);
2259 }
2260 else if (beta<MyConfusionPrecision) { //beta==0
2261 SP1.SetEdge2(Tri2.GetEdgeNumber(1));
2262 if(Tri2.GetEdgeOrientation(1)>0)
2263 SP1.SetLambda2(alpha);
2264 else SP1.SetLambda2(1.0-alpha);
2265 }
2266 else if (Abs(beta-alpha)<MyConfusionPrecision) {//beta==alpha
2267 SP1.SetEdge2(Tri2.GetEdgeNumber(3));
2268 if(Tri2.GetEdgeOrientation(3)>0)
2269 SP1.SetLambda2(1.0-alpha);
2270 else SP1.SetLambda2(alpha);
2271 }
2272 else if (Abs(alpha-1)<MyConfusionPrecision) {//alpha==1
2273 SP1.SetEdge2(Tri2.GetEdgeNumber(2));
2274 if(Tri2.GetEdgeOrientation(2)>0)
2275 SP1.SetLambda2(alpha);
2276 else SP1.SetLambda2(1.0-alpha);
2277 }
2278 }
2279 else {
2280
2281 }
7fd59977 2282 }
2283 }
2284 else return 0;
2285 }
2286 return (NbPoints);
2287}
7fd59977 2288//=======================================================================
7fd59977 2289//function : TriangleCompare
2290//purpose : Analyze each couple of triangles from the two --
2291// array of triangles, to see if they are in
2292// contact, and compute the incidence. Then put
2293// couples in contact in the array of couples
2294//=======================================================================
55ab6ed6
P
2295Standard_Integer IntPolyh_MaillageAffinage::TriangleCompare ()
2296{
68b07699 2297 // Find couples with interfering bounding boxes
2298 IntPolyh_IndexedDataMapOfIntegerArrayOfInteger aDMILI;
2299 GetInterferingTriangles(TTriangles1, TPoints1,
2300 TTriangles2, TPoints2,
2301 aDMILI);
2302 if (aDMILI.IsEmpty()) {
2303 return 0;
2304 }
2305 //
2306 Standard_Real CoupleAngle = -2.0;
2307 //
2308 // Intersection of the triangles
2309 Standard_Integer i, aNb = aDMILI.Extent();
2310 for (i = 1; i <= aNb; ++i) {
2311 const Standard_Integer i_S1 = aDMILI.FindKey(i);
fee4fa0f 2312 IntPolyh_Triangle &Triangle1 = TTriangles1[i_S1];
68b07699 2313 const IntPolyh_Point& P1 = TPoints1[Triangle1.FirstPoint()];
2314 const IntPolyh_Point& P2 = TPoints1[Triangle1.SecondPoint()];
2315 const IntPolyh_Point& P3 = TPoints1[Triangle1.ThirdPoint()];
2316 //
2317 const IntPolyh_ArrayOfInteger& aLI2 = aDMILI(i);
2318 IntPolyh_ArrayOfInteger::Iterator aItLI(aLI2);
2319 for (; aItLI.More(); aItLI.Next()) {
2320 const Standard_Integer i_S2 = aItLI.Value();
fee4fa0f 2321 IntPolyh_Triangle &Triangle2 = TTriangles2[i_S2];
68b07699 2322 const IntPolyh_Point& Q1 = TPoints2[Triangle2.FirstPoint()];
2323 const IntPolyh_Point& Q2 = TPoints2[Triangle2.SecondPoint()];
2324 const IntPolyh_Point& Q3 = TPoints2[Triangle2.ThirdPoint()];
2325 //
2326 if (TriContact(P1, P2, P3, Q1, Q2, Q3, CoupleAngle)) {
2327 IntPolyh_Couple aCouple(i_S1, i_S2, CoupleAngle);
2328 TTrianglesContacts.Append(aCouple);
fee4fa0f 2329 //
68b07699 2330 Triangle1.SetIntersection(Standard_True);
2331 Triangle2.SetIntersection(Standard_True);
7fd59977 2332 }
2333 }
2334 }
68b07699 2335 return TTrianglesContacts.Extent();
7fd59977 2336}
2337
2338//=======================================================================
7fd59977 2339//function : CheckCoupleAndGetAngle
2340//purpose :
2341//=======================================================================
68b07699 2342Standard_Boolean CheckCoupleAndGetAngle(const Standard_Integer T1,
87696ff7 2343 const Standard_Integer T2,
2344 Standard_Real& Angle,
68b07699 2345 IntPolyh_ListOfCouples &TTrianglesContacts)
55ab6ed6 2346{
68b07699 2347 IntPolyh_ListIteratorOfListOfCouples aIt(TTrianglesContacts);
2348 for (; aIt.More(); aIt.Next()) {
2349 IntPolyh_Couple& TestCouple = aIt.ChangeValue();
2350 if (!TestCouple.IsAnalyzed()) {
2351 if (TestCouple.FirstValue() == T1 && TestCouple.SecondValue() == T2) {
2352 TestCouple.SetAnalyzed(Standard_True);
2353 Angle = TestCouple.Angle();
2354 return Standard_True;
7fd59977 2355 }
2356 }
2357 }
68b07699 2358 return Standard_False;
7fd59977 2359}
7fd59977 2360//=======================================================================
2361//function : CheckCoupleAndGetAngle2
2362//purpose :
2363//=======================================================================
68b07699 2364Standard_Boolean CheckCoupleAndGetAngle2(const Standard_Integer T1,
87696ff7 2365 const Standard_Integer T2,
68b07699 2366 const Standard_Integer T11,
87696ff7 2367 const Standard_Integer T22,
68b07699 2368 IntPolyh_ListIteratorOfListOfCouples& theItCT11,
2369 IntPolyh_ListIteratorOfListOfCouples& theItCT22,
87696ff7 2370 Standard_Real & Angle,
68b07699 2371 IntPolyh_ListOfCouples &TTrianglesContacts)
55ab6ed6 2372{
7fd59977 2373 ///couple T1 T2 is found in the list
2374 ///T11 and T22 are two other triangles implied in the contact edge edge
2375 /// CT11 couple( T1,T22) and CT22 couple (T2,T11)
2376 /// these couples will be marked if there is a start point
68b07699 2377 Standard_Boolean Test1 , Test2, Test3;
2378 Test1 = Test2 = Test3 = Standard_False;
2379 //
2380 IntPolyh_ListIteratorOfListOfCouples aIt(TTrianglesContacts);
2381 for (; aIt.More(); aIt.Next()) {
2382 IntPolyh_Couple& TestCouple = aIt.ChangeValue();
2383 if (TestCouple.IsAnalyzed()) {
2384 continue;
2385 }
2386 //
2387 if (TestCouple.FirstValue() == T1) {
2388 if (TestCouple.SecondValue() == T2) {
2389 Test1 = Standard_True;
2390 TestCouple.SetAnalyzed(Standard_True);
2391 Angle = TestCouple.Angle();
7fd59977 2392 }
68b07699 2393 else if (TestCouple.SecondValue() == T22) {
2394 Test2 = Standard_True;
2395 theItCT11 = aIt;
2396 Angle = TestCouple.Angle();
2397 }
2398 }
2399 else if (TestCouple.FirstValue() == T11) {
2400 if (TestCouple.SecondValue() == T2) {
2401 Test3 = Standard_True;
2402 theItCT22 = aIt;
2403 Angle = TestCouple.Angle();
7fd59977 2404 }
2405 }
68b07699 2406 //
2407 if (Test1 && Test2 && Test3) {
2408 break;
2409 }
7fd59977 2410 }
68b07699 2411 return Test1;
7fd59977 2412}
7fd59977 2413//=======================================================================
2414//function : CheckNextStartPoint
2415//purpose : it is checked if the point is not a top
55ab6ed6
P
2416// then it is stored in one or several valid arrays with
2417// the proper list number
7fd59977 2418//=======================================================================
7fd59977 2419Standard_Integer CheckNextStartPoint(IntPolyh_SectionLine & SectionLine,
87696ff7 2420 IntPolyh_ArrayOfTangentZones & TTangentZones,
2421 IntPolyh_StartPoint & SP,
2422 const Standard_Boolean Prepend)//=Standard_False)
55ab6ed6 2423{
7fd59977 2424 Standard_Integer Test=1;
2425 if( (SP.E1()==-1)||(SP.E2()==-1) ) {
2426 //The tops of triangle are analyzed
2427 //It is checked if they are not in the array TTangentZones
d642ddf5 2428 Standard_Integer FinTTZ=TTangentZones.NbItems();
7fd59977 2429 for(Standard_Integer uiui=0; uiui<FinTTZ; uiui++) {
2430 IntPolyh_StartPoint TestSP=TTangentZones[uiui];
2431 if ( (Abs(SP.U1()-TestSP.U1())<MyConfusionPrecision)
87696ff7 2432 &&(Abs(SP.V1()-TestSP.V1())<MyConfusionPrecision) ) {
2433 if ( (Abs(SP.U2()-TestSP.U2())<MyConfusionPrecision)
2434 &&(Abs(SP.V2()-TestSP.V2())<MyConfusionPrecision) ) {
2435 Test=0;//SP is already in the list of tops
2436 uiui=FinTTZ;
2437 }
7fd59977 2438 }
2439 }
2440 if (Test) {//the top does not belong to the list of TangentZones
2441 SP.SetChainList(-1);
2442 TTangentZones[FinTTZ]=SP;
d642ddf5 2443 TTangentZones.IncrementNbItems();
7fd59977 2444 Test=0;//the examined point is a top
2445 }
2446 }
2447 else if (Test) {
2448 if (Prepend)
2449 SectionLine.Prepend(SP);
2450 else {
2451 SectionLine[SectionLine.NbStartPoints()]=SP;
2452 SectionLine.IncrementNbStartPoints();
2453 }
55ab6ed6 2454
7fd59977 2455 }
55ab6ed6
P
2456 //if the point is not a top Test=1
2457 //The chain is continued
2458 return(Test);
7fd59977 2459}
7fd59977 2460//=======================================================================
2461//function : StartPointsChain
2462//purpose : Loop on the array of couples. Compute StartPoints.
2463// Try to chain the StartPoints into SectionLines or
2464// put the point in the ArrayOfTangentZones if
2465// chaining it, is not possible.
2466//=======================================================================
55ab6ed6
P
2467Standard_Integer IntPolyh_MaillageAffinage::StartPointsChain
2468 (IntPolyh_ArrayOfSectionLines& TSectionLines,
2469 IntPolyh_ArrayOfTangentZones& TTangentZones)
2470{
68b07699 2471 //Loop on the array of couples filled in the function COMPARE()
2472 IntPolyh_ListIteratorOfListOfCouples aIt(TTrianglesContacts);
2473 for (; aIt.More(); aIt.Next()) {
2474 IntPolyh_Couple& aCouple = aIt.ChangeValue();
2475 // Check if the couple of triangles has not been already examined.
2476 if(!aCouple.IsAnalyzed()) {
7fd59977 2477
d642ddf5 2478 Standard_Integer SectionLineIndex=TSectionLines.NbItems();
7fd59977 2479 // fill last section line if still empty (eap)
2480 if (SectionLineIndex > 0
87696ff7 2481 &&
2482 TSectionLines[SectionLineIndex-1].NbStartPoints() == 0)
2483 SectionLineIndex -= 1;
7fd59977 2484 else
87696ff7 2485 TSectionLines.IncrementNbItems();
7fd59977 2486
2487 IntPolyh_SectionLine & MySectionLine=TSectionLines[SectionLineIndex];
2488 if (MySectionLine.GetN() == 0) // eap
87696ff7 2489 MySectionLine.Init(10000);//Initialisation of array of StartPoint
7fd59977 2490
2491 Standard_Integer NbPoints=-1;
2492 Standard_Integer T1I, T2I;
68b07699 2493 T1I = aCouple.FirstValue();
2494 T2I = aCouple.SecondValue();
7fd59977 2495
2496 // Start points for the current couple are found
2497 IntPolyh_StartPoint SP1, SP2;
68b07699 2498 NbPoints=StartingPointsResearch(T1I,T2I,SP1, SP2);//first calculation
2499 aCouple.SetAnalyzed(Standard_True);//the couple is marked
7fd59977 2500
2501 if(NbPoints==1) {// particular case top/triangle or edge/edge
87696ff7 2502 //the start point is input in the array
2503 SP1.SetChainList(SectionLineIndex);
68b07699 2504 SP1.SetAngle(aCouple.Angle());
87696ff7 2505 //it is checked if the point is not atop of the triangle
2506 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP1)) {
2507 IntPolyh_StartPoint SPNext1;
2508 Standard_Integer TestSP1=0;
2509
2510 //chain of a side
2511 IntPolyh_StartPoint SP11;//=SP1;
2512 if(SP1.E1()>=0) { //&&(SP1.E2()!=-1) already tested if the point is not a top
2513 Standard_Integer NextTriangle1=0;
2514 if (TEdges1[SP1.E1()].FirstTriangle()!=T1I) NextTriangle1=TEdges1[SP1.E1()].FirstTriangle();
2515 else NextTriangle1=TEdges1[SP1.E1()].SecondTriangle();
2516
2517 Standard_Real Angle=-2.0;
2518 if (CheckCoupleAndGetAngle(NextTriangle1,T2I,Angle,TTrianglesContacts)) {
2519 //it is checked if the couple exists and is marked
2520 Standard_Integer NbPoints11=0;
68b07699 2521 NbPoints11=NextStartingPointsResearch(NextTriangle1,T2I,SP1,SP11);
87696ff7 2522 if (NbPoints11==1) {
2523 SP11.SetChainList(SectionLineIndex);
2524 SP11.SetAngle(Angle);
2525
2526 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP11)) {
2527 Standard_Integer EndChainList=1;
2528 while (EndChainList!=0) {
2529 TestSP1=GetNextChainStartPoint(SP11,SPNext1,MySectionLine,TTangentZones);
2530 if(TestSP1==1) {
2531 SPNext1.SetChainList(SectionLineIndex);
2532 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext1))
2533 SP11=SPNext1;
2534 else EndChainList=0;
2535 }
2536 else EndChainList=0; //There is no next point
2537 }
2538 }
2539
2540 }
2541 else {
2542 if(NbPoints11>1) {//The point is input in the array TTangentZones
2543 TTangentZones[TTangentZones.NbItems()]=SP11;//default list number = -1
2544 TTangentZones.IncrementNbItems();
2545 }
2546 else {
2547
2548 }
2549 }
2550 }
2551 }
2552 else if (SP1.E2()<0){
2553
2554 }
2555 //chain of the other side
2556 IntPolyh_StartPoint SP12;//=SP1;
2557 if (SP1.E2()>=0) { //&&(SP1.E1()!=-1) already tested
2558 Standard_Integer NextTriangle2;
2559 if (TEdges2[SP1.E2()].FirstTriangle()!=T2I) NextTriangle2=TEdges2[SP1.E2()].FirstTriangle();
2560 else NextTriangle2=TEdges2[SP1.E2()].SecondTriangle();
2561
2562 Standard_Real Angle=-2.0;
2563 if(CheckCoupleAndGetAngle(T1I,NextTriangle2,Angle,TTrianglesContacts)) {
2564 Standard_Integer NbPoints12=0;
68b07699 2565 NbPoints12=NextStartingPointsResearch(T1I,NextTriangle2,SP1, SP12);
87696ff7 2566 if (NbPoints12==1) {
2567
2568 SP12.SetChainList(SectionLineIndex);
2569 SP12.SetAngle(Angle);
2570 Standard_Boolean Prepend = Standard_True; // eap
2571
2572 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP12, Prepend)) {
2573 Standard_Integer EndChainList=1;
2574 while (EndChainList!=0) {
2575 TestSP1=GetNextChainStartPoint(SP12,SPNext1,
2576 MySectionLine,TTangentZones,
2577 Prepend); // eap
2578 if(TestSP1==1) {
2579 SPNext1.SetChainList(SectionLineIndex);
2580 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext1,Prepend))
2581 SP12=SPNext1;
2582 else EndChainList=0;
2583 }
2584 else EndChainList=0; //there is no next point
2585 }
2586 }
2587
2588 else {
2589 if(NbPoints12>1) {//The points are input in the array TTangentZones
2590 TTangentZones[TTangentZones.NbItems()]=SP12;//default list number = -1
2591 TTangentZones.IncrementNbItems();
2592 }
2593 else {
2594
2595 }
2596 }
2597 }
2598 }
2599 }
2600 else if(SP1.E1()<0){
2601
2602 }
2603 }
7fd59977 2604 }
2605 else if(NbPoints==2) {
87696ff7 2606 //the start points are input in the array
2607 IntPolyh_StartPoint SPNext2;
2608 Standard_Integer TestSP2=0;
2609 Standard_Integer EndChainList=1;
2610
2611 SP1.SetChainList(SectionLineIndex);
68b07699 2612 SP1.SetAngle(aCouple.Angle());
87696ff7 2613 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP1)) {
2614
2615 //chain of a side
2616 while (EndChainList!=0) {
2617 TestSP2=GetNextChainStartPoint(SP1,SPNext2,MySectionLine,TTangentZones);
2618 if(TestSP2==1) {
2619 SPNext2.SetChainList(SectionLineIndex);
2620 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext2))
2621 SP1=SPNext2;
2622 else EndChainList=0;
2623 }
2624 else EndChainList=0; //there is no next point
2625 }
2626 }
2627
7fd59977 2628 SP2.SetChainList(SectionLineIndex);
68b07699 2629 SP2.SetAngle(aCouple.Angle());
87696ff7 2630 Standard_Boolean Prepend = Standard_True; // eap
2631
2632 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP2,Prepend)) {
2633
2634 //chain of the other side
2635 EndChainList=1;
2636 while (EndChainList!=0) {
2637 TestSP2=GetNextChainStartPoint(SP2,SPNext2,
2638 MySectionLine,TTangentZones,
2639 Prepend); // eap
2640 if(TestSP2==1) {
2641 SPNext2.SetChainList(SectionLineIndex);
2642 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext2,Prepend))
2643 SP2=SPNext2;
2644 else EndChainList=0;
2645 }
2646 else EndChainList=0; //there is no next point
2647 }
2648 }
7fd59977 2649 }
2650
2651 else if( (NbPoints>2)&&(NbPoints<7) ) {
87696ff7 2652 //More than two start points
2653 //the start point is input in the table
2654 SP1.SetChainList(SectionLineIndex);
2655 CheckNextStartPoint(MySectionLine,TTangentZones,SP1);
7fd59977 2656 }
2657
2658 else {
55ab6ed6 2659
7fd59977 2660 }
2661 }
2662 }
55ab6ed6 2663
7fd59977 2664 return(1);
2665}
7fd59977 2666//=======================================================================
2667//function : GetNextChainStartPoint
2668//purpose : Mainly used by StartPointsChain(), this function
2669// try to compute the next StartPoint.
2670// GetNextChainStartPoint is used only if it is known that there are 2 contact points
2671//=======================================================================
55ab6ed6
P
2672Standard_Integer IntPolyh_MaillageAffinage::GetNextChainStartPoint
2673 (const IntPolyh_StartPoint & SP,
2674 IntPolyh_StartPoint & SPNext,
2675 IntPolyh_SectionLine & MySectionLine,
2676 IntPolyh_ArrayOfTangentZones & TTangentZones,
2677 const Standard_Boolean Prepend)
2678{
7fd59977 2679 Standard_Integer NbPoints=0;
2680 if( (SP.E1()>=0)&&(SP.E2()==-2) ) {
2681 //case if the point is on edge of T1
2682 Standard_Integer NextTriangle1;
2683 if (TEdges1[SP.E1()].FirstTriangle()!=SP.T1()) NextTriangle1=TEdges1[SP.E1()].FirstTriangle();
2684 else
2685 NextTriangle1=TEdges1[SP.E1()].SecondTriangle();
2686 //If is checked if two triangles intersect
2687 Standard_Real Angle= -2.0;
2688 if (CheckCoupleAndGetAngle(NextTriangle1,SP.T2(),Angle,TTrianglesContacts)) {
68b07699 2689 NbPoints=NextStartingPointsResearch(NextTriangle1,SP.T2(),SP,SPNext);
7fd59977 2690 if( NbPoints!=1 ) {
87696ff7 2691 if (NbPoints>1)
2692 CheckNextStartPoint(MySectionLine,TTangentZones,SPNext,Prepend);
2693 else {
55ab6ed6 2694
87696ff7 2695 NbPoints=0;
2696 }
7fd59977 2697 }
2698 else
87696ff7 2699 SPNext.SetAngle(Angle);
7fd59977 2700 }
2701 else NbPoints=0;//this couple does not intersect
2702 }
2703 else if( (SP.E1()==-2)&&(SP.E2()>=0) ) {
2704 //case if the point is on edge of T2
2705 Standard_Integer NextTriangle2;
2706 if (TEdges2[SP.E2()].FirstTriangle()!=SP.T2()) NextTriangle2=TEdges2[SP.E2()].FirstTriangle();
2707 else
2708 NextTriangle2=TEdges2[SP.E2()].SecondTriangle();
2709 Standard_Real Angle= -2.0;
2710 if (CheckCoupleAndGetAngle(SP.T1(),NextTriangle2,Angle,TTrianglesContacts)) {
68b07699 2711 NbPoints=NextStartingPointsResearch(SP.T1(),NextTriangle2,SP,SPNext);
7fd59977 2712 if( NbPoints!=1 ) {
87696ff7 2713 if (NbPoints>1)
2714 CheckNextStartPoint(MySectionLine,TTangentZones,SPNext,Prepend);
2715 else {
55ab6ed6 2716
87696ff7 2717 NbPoints=0;
2718 }
7fd59977 2719 }
2720 else
87696ff7 2721 SPNext.SetAngle(Angle);
7fd59977 2722 }
2723 else NbPoints=0;
2724 }
2725 else if( (SP.E1()==-2)&&(SP.E2()==-2) ) {
2726 ///no edge is touched or cut
55ab6ed6 2727
7fd59977 2728 NbPoints=0;
2729 }
2730 else if( (SP.E1()>=0)&&(SP.E2()>=0) ) {
2731 ///the point is located on two edges
2732 Standard_Integer NextTriangle1;
7fd59977 2733 if (TEdges1[SP.E1()].FirstTriangle()!=SP.T1()) NextTriangle1=TEdges1[SP.E1()].FirstTriangle();
2734 else
87696ff7 2735 NextTriangle1=TEdges1[SP.E1()].SecondTriangle();
7fd59977 2736 Standard_Integer NextTriangle2;
2737 if (TEdges2[SP.E2()].FirstTriangle()!=SP.T2()) NextTriangle2=TEdges2[SP.E2()].FirstTriangle();
2738 else
87696ff7 2739 NextTriangle2=TEdges2[SP.E2()].SecondTriangle();
7fd59977 2740 Standard_Real Angle= -2.0;
68b07699 2741
2742 IntPolyh_ListIteratorOfListOfCouples aItCT11, aItCT22;
55ab6ed6 2743 if (CheckCoupleAndGetAngle2(NextTriangle1,NextTriangle2,
68b07699 2744 SP.T1(),SP.T2(), aItCT11, aItCT22,
87696ff7 2745 Angle,TTrianglesContacts)) {
68b07699 2746 NbPoints=NextStartingPointsResearch(NextTriangle1,NextTriangle2,SP,SPNext);
87696ff7 2747 if( NbPoints!=1 ) {
2748 if (NbPoints>1) {
2749 ///The new point is checked
2750 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext,Prepend)>0) {
2751 }
2752 else {
2753
2754 }
2755 }
2756 NbPoints=0;
2757 }
2758 else {//NbPoints==1
68b07699 2759 SPNext.SetAngle(Angle);
2760 if (aItCT11.More()) aItCT11.ChangeValue().SetAnalyzed(Standard_True);
2761 if (aItCT22.More()) aItCT22.ChangeValue().SetAnalyzed(Standard_True);
87696ff7 2762 }
7fd59977 2763 }
2764 else NbPoints=0;
2765 }
2766 else if( (SP.E1()==-1)||(SP.E2()==-1) ) {
2767 ///the points are tops of triangle
2768 ///the point is atored in an intermediary array
2769 }
2770 return(NbPoints);
2771}
7fd59977 2772//=======================================================================
2773//function : GetArrayOfPoints
2774//purpose :
2775//=======================================================================
55ab6ed6
P
2776const IntPolyh_ArrayOfPoints& IntPolyh_MaillageAffinage::GetArrayOfPoints
2777 (const Standard_Integer SurfID)const
2778{
7fd59977 2779 if (SurfID==1)
2780 return(TPoints1);
2781 return(TPoints2);
2782}
7fd59977 2783//=======================================================================
2784//function : GetArrayOfEdges
2785//purpose :
2786//=======================================================================
55ab6ed6
P
2787const IntPolyh_ArrayOfEdges& IntPolyh_MaillageAffinage::GetArrayOfEdges
2788 (const Standard_Integer SurfID)const
2789{
7fd59977 2790 if (SurfID==1)
2791 return(TEdges1);
2792 return(TEdges2);
2793}
7fd59977 2794//=======================================================================
2795//function : GetArrayOfTriangles
2796//purpose :
2797//=======================================================================
55ab6ed6
P
2798const IntPolyh_ArrayOfTriangles&
2799 IntPolyh_MaillageAffinage::GetArrayOfTriangles
2800 (const Standard_Integer SurfID)const{
7fd59977 2801 if (SurfID==1)
2802 return(TTriangles1);
2803 return(TTriangles2);
2804}
2805
2806//=======================================================================
2807//function : GetBox
2808//purpose :
2809//=======================================================================
55ab6ed6
P
2810Bnd_Box IntPolyh_MaillageAffinage::GetBox(const Standard_Integer SurfID) const
2811{
7fd59977 2812 if (SurfID==1)
2813 return(MyBox1);
2814 return(MyBox2);
2815}
7fd59977 2816//=======================================================================
2817//function : GetArrayOfCouples
2818//purpose :
2819//=======================================================================
68b07699 2820IntPolyh_ListOfCouples &IntPolyh_MaillageAffinage::GetCouples()
7fd59977 2821{
2822 return TTrianglesContacts;
2823}
55ab6ed6
P
2824//=======================================================================
2825//function : SetEnlargeZone
2826//purpose :
2827//=======================================================================
03cca6f7 2828void IntPolyh_MaillageAffinage::SetEnlargeZone(const Standard_Boolean EnlargeZone)
7fd59977 2829{
2830 myEnlargeZone = EnlargeZone;
2831}
55ab6ed6
P
2832//=======================================================================
2833//function : GetEnlargeZone
2834//purpose :
2835//=======================================================================
7fd59977 2836Standard_Boolean IntPolyh_MaillageAffinage::GetEnlargeZone() const
2837{
2838 return myEnlargeZone;
2839}
d0820f2e 2840
2841//=======================================================================
2842//function : GetMinDeflection
2843//purpose :
2844//=======================================================================
2845Standard_Real IntPolyh_MaillageAffinage::GetMinDeflection(const Standard_Integer SurfID) const
2846{
2847 return (SurfID==1)? FlecheMin1:FlecheMin2;
2848}
2849
2850//=======================================================================
2851//function : GetMaxDeflection
2852//purpose :
2853//=======================================================================
2854Standard_Real IntPolyh_MaillageAffinage::GetMaxDeflection(const Standard_Integer SurfID) const
2855{
2856 return (SurfID==1)? FlecheMax1:FlecheMax2;
2857}
2858
55ab6ed6
P
2859//=======================================================================
2860//function : DegeneratedIndex
2861//purpose :
2862//=======================================================================
2863void DegeneratedIndex(const TColStd_Array1OfReal& aXpars,
87696ff7 2864 const Standard_Integer aNbX,
2865 const Handle(Adaptor3d_HSurface)& aS,
2866 const Standard_Integer aIsoDirection,
2867 Standard_Integer& aI1,
2868 Standard_Integer& aI2)
55ab6ed6
P
2869{
2870 Standard_Integer i;
2871 Standard_Boolean bDegX1, bDegX2;
2872 Standard_Real aDegX1, aDegX2, aTol2, aX;
2873 //
2874 aI1=0;
2875 aI2=0;
2876 aTol2=MyTolerance*MyTolerance;
2877 //
2878 if (aIsoDirection==1){ // V=const
2879 bDegX1=IsDegenerated(aS, 1, aTol2, aDegX1);
2880 bDegX2=IsDegenerated(aS, 2, aTol2, aDegX2);
2881 }
2882 else if (aIsoDirection==2){ // U=const
2883 bDegX1=IsDegenerated(aS, 3, aTol2, aDegX1);
2884 bDegX2=IsDegenerated(aS, 4, aTol2, aDegX2);
2885 }
2886 else {
2887 return;
2888 }
2889 //
2890 if (!(bDegX1 || bDegX2)) {
2891 return;
2892 }
2893 //
2894 for(i=1; i<=aNbX; ++i) {
2895 aX=aXpars(i);
2896 if (bDegX1) {
2897 if (fabs(aX-aDegX1) < MyTolerance) {
87696ff7 2898 aI1=i;
55ab6ed6
P
2899 }
2900 }
2901 if (bDegX2) {
2902 if (fabs(aX-aDegX2) < MyTolerance) {
87696ff7 2903 aI2=i;
55ab6ed6
P
2904 }
2905 }
2906 }
2907}
2908//=======================================================================
2909//function : IsDegenerated
2910//purpose :
2911//=======================================================================
2912Standard_Boolean IsDegenerated(const Handle(Adaptor3d_HSurface)& aS,
87696ff7 2913 const Standard_Integer aIndex,
2914 const Standard_Real aTol2,
2915 Standard_Real& aDegX)
55ab6ed6
P
2916{
2917 Standard_Boolean bRet;
2918 Standard_Integer i, aNbP;
2919 Standard_Real aU, dU, aU1, aU2, aV, dV, aV1, aV2, aD2;
2920 gp_Pnt aP1, aP2;
2921 //
2922 bRet=Standard_False;
2923 aNbP=3;
2924 aDegX=99;
2925 //
2926 aU1=aS->FirstUParameter();
2927 aU2=aS->LastUParameter();
2928 aV1=aS->FirstVParameter();
2929 aV2=aS->LastVParameter();
2930 //
2931 if (aIndex<3) { // V=const
2932 aV=aV1;
2933 if (aIndex==2) {
2934 aV=aV2;
2935 }
2936 dU=(aU2-aU1)/(aNbP-1);
2937 aU=aU1;
2938 aP1=aS->Value(aU, aV);
2939 for (i=1; i<aNbP; ++i) {
2940 aU=i*dU;
2941 if (i==aNbP-1){
87696ff7 2942 aU=aU2;
55ab6ed6
P
2943 }
2944 aP2=aS->Value(aU, aV);
2945 aD2=aP1.SquareDistance(aP2);
2946 if (aD2>aTol2) {
87696ff7 2947 return bRet;
55ab6ed6
P
2948 }
2949 aP1=aP2;
2950 }
2951 aDegX=aV;
2952 bRet=!bRet;
2953 }
2954 else {// U=const
2955 aU=aU1;
2956 if (aIndex==4) {
2957 aU=aU2;
2958 }
2959 dV=(aV2-aV1)/(aNbP-1);
2960 aV=aV1;
2961 aP1=aS->Value(aU, aV);
2962 for (i=1; i<aNbP; ++i) {
2963 aV=i*dV;
2964 if (i==aNbP-1){
87696ff7 2965 aV=aV2;
55ab6ed6
P
2966 }
2967 aP2=aS->Value(aU, aV);
2968 aD2=aP1.SquareDistance(aP2);
2969 if (aD2>aTol2) {
87696ff7 2970 return bRet;
55ab6ed6
P
2971 }
2972 aP1=aP2;
2973 }
2974 bRet=!bRet;
2975 aDegX=aU;
2976 }
2977 //
2978 return bRet;
2979}