Test for 0022778: Bug in BRepMesh
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22// modified by Edward AGAPOV (eap) Tue Jan 22 2002 (bug occ53)
23// - improve SectionLine table management (avoid memory reallocation)
24// - some protection against arrays overflow
25
26// modified by Edward AGAPOV (eap) Thu Feb 14 2002 (occ139)
27// - make Section Line parts rightly connected (prepend 2nd part to the 1st)
28// - TriangleShape() for debugging purpose
29
30// Modified by skv - Thu Sep 25 17:42:42 2003 OCC567
31// modified by ofv Thu Apr 8 14:58:13 2004 fip
32
7fd59977 33
55ab6ed6 34#include <IntPolyh_MaillageAffinage.ixx>
7fd59977 35
36#include <Precision.hxx>
55ab6ed6
P
37#include <gp_Pnt.hxx>
38#include <gp.hxx>
7fd59977 39
40#include <TColStd_ListIteratorOfListOfInteger.hxx>
55ab6ed6 41
7fd59977 42#include <Bnd_BoundSortBox.hxx>
43#include <Bnd_HArray1OfBox.hxx>
7fd59977 44
55ab6ed6 45#include <IntCurveSurface_ThePolyhedronOfHInter.hxx>
7fd59977 46
55ab6ed6
P
47#include <IntPolyh_ArrayOfCouples.hxx>
48#include <IntPolyh_Edge.hxx>
49#include <IntPolyh_Couple.hxx>
7fd59977 50
55ab6ed6
P
51static Standard_Real MyTolerance=10.0e-7;
52static Standard_Real MyConfusionPrecision=10.0e-12;
53static Standard_Real SquareMyConfusionPrecision=10.0e-24;
54//
55static
56 inline Standard_Real maxSR(const Standard_Real a,
57 const Standard_Real b,
58 const Standard_Real c);
59
60static
61 inline Standard_Real minSR(const Standard_Real a,
62 const Standard_Real b,
63 const Standard_Real c);
64static
65 Standard_Integer project6(const IntPolyh_Point &ax,
66 const IntPolyh_Point &p1,
67 const IntPolyh_Point &p2,
68 const IntPolyh_Point &p3,
69 const IntPolyh_Point &q1,
70 const IntPolyh_Point &q2,
71 const IntPolyh_Point &q3);
72static
73 void TestNbPoints(const Standard_Integer ,
74 Standard_Integer &NbPoints,
75 Standard_Integer &NbPointsTotal,
76 const IntPolyh_StartPoint &Pt1,
77 const IntPolyh_StartPoint &Pt2,
78 IntPolyh_StartPoint &SP1,
79 IntPolyh_StartPoint &SP2);
80static
81 void CalculPtsInterTriEdgeCoplanaires(const Standard_Integer TriSurfID,
82 const IntPolyh_Point &NormaleTri,
83 const IntPolyh_Point &PE1,
84 const IntPolyh_Point &PE2,
85 const IntPolyh_Point &Edge,
86 const IntPolyh_Point &PT1,
87 const IntPolyh_Point &PT2,
88 const IntPolyh_Point &Cote,
89 const Standard_Integer CoteIndex,
90 IntPolyh_StartPoint &SP1,
91 IntPolyh_StartPoint &SP2,
92 Standard_Integer &NbPoints);
93static
94 void CalculPtsInterTriEdgeCoplanaires2(const Standard_Integer TriSurfID,
95 const IntPolyh_Point &NormaleTri,
96 const IntPolyh_Triangle &Tri1,
97 const IntPolyh_Triangle &Tri2,
98 const IntPolyh_Point &PE1,
99 const IntPolyh_Point &PE2,
100 const IntPolyh_Point &Edge,
101 const Standard_Integer EdgeIndex,
102 const IntPolyh_Point &PT1,
103 const IntPolyh_Point &PT2,
104 const IntPolyh_Point &Cote,
105 const Standard_Integer CoteIndex,
106 IntPolyh_StartPoint &SP1,
107 IntPolyh_StartPoint &SP2,
108 Standard_Integer &NbPoints);
109static
110 Standard_Integer CheckCoupleAndGetAngle(const Standard_Integer T1,
111 const Standard_Integer T2,
112 Standard_Real& Angle,
113 IntPolyh_ArrayOfCouples &TTrianglesContacts);
114static
115 Standard_Integer CheckCoupleAndGetAngle2(const Standard_Integer T1,
116 const Standard_Integer T2,
117 const Standard_Integer T11,
118 const Standard_Integer T22,
119 Standard_Integer &CT11,
120 Standard_Integer &CT22,
121 Standard_Real & Angle,
122 IntPolyh_ArrayOfCouples &TTrianglesContacts);
123static
124 Standard_Integer CheckNextStartPoint(IntPolyh_SectionLine & SectionLine,
125 IntPolyh_ArrayOfTangentZones & TTangentZones,
126 IntPolyh_StartPoint & SP,
127 const Standard_Boolean Prepend=Standard_False);
128
129//modified by NIZNHY-PKV Fri Jan 20 11:01:30 2012f
130static
131 Standard_Boolean IsDegenerated(const Handle(Adaptor3d_HSurface)& aS,
132 const Standard_Integer aIndex,
133 const Standard_Real aTol2,
134 Standard_Real& aDegX);
135static
136 void DegeneratedIndex(const TColStd_Array1OfReal& Xpars,
137 const Standard_Integer aNbX,
138 const Handle(Adaptor3d_HSurface)& aS,
139 const Standard_Integer aIsoDirection,
140 Standard_Integer& aI1,
141 Standard_Integer& aI2);
142//modified by NIZNHY-PKV Fri Jan 20 11:01:32 2012t
7fd59977 143
144//=======================================================================
145//function : IntPolyh_MaillageAffinage
146//purpose :
147//=======================================================================
55ab6ed6
P
148IntPolyh_MaillageAffinage::IntPolyh_MaillageAffinage
149 (const Handle(Adaptor3d_HSurface)& Surface1,
150 const Handle(Adaptor3d_HSurface)& Surface2,
151 const Standard_Integer )
152:
153 MaSurface1(Surface1),
154 MaSurface2(Surface2),
155 NbSamplesU1(10),
156 NbSamplesU2(10),
157 NbSamplesV1(10),
158 NbSamplesV2(10),
159 FlecheMax1(0.0),
160 FlecheMax2(0.0),
161 FlecheMin1(0.0),
162 FlecheMin2(0.0),
163 FlecheMoy1(0.0),
164 FlecheMoy2(0.0),
165 myEnlargeZone(Standard_False)
7fd59977 166{
7fd59977 167 TPoints1.Init(10000);
168 TEdges1.Init(30000);
169 TTriangles1.Init(20000);
170
171 TPoints2.Init(10000);
172 TEdges2.Init(30000);
173 TTriangles2.Init(20000);
174
175 TStartPoints.Init(10000);
176}
7fd59977 177//=======================================================================
178//function : IntPolyh_MaillageAffinage
179//purpose :
180//=======================================================================
55ab6ed6
P
181IntPolyh_MaillageAffinage::IntPolyh_MaillageAffinage
182 (const Handle(Adaptor3d_HSurface)& Surface1,
183 const Standard_Integer NbSU1,
184 const Standard_Integer NbSV1,
185 const Handle(Adaptor3d_HSurface)& Surface2,
186 const Standard_Integer NbSU2,
187 const Standard_Integer NbSV2,
188 const Standard_Integer )
189:
190 MaSurface1(Surface1),
191 MaSurface2(Surface2),
192 NbSamplesU1(NbSU1),
193 NbSamplesU2(NbSU2),
194 NbSamplesV1(NbSV1),
195 NbSamplesV2(NbSV2),
196 FlecheMax1(0.0),
197 FlecheMax2(0.0),
198 FlecheMin1(0.0),
199 FlecheMin2(0.0),
200 FlecheMoy1(0.0),
201 FlecheMoy2(0.0),
202 myEnlargeZone(Standard_False)
7fd59977 203{
7fd59977 204 TPoints1.Init(10000);
205 TEdges1.Init(30000);
206 TTriangles1.Init(20000);
207
208 TPoints2.Init(10000);
209 TEdges2.Init(30000);
210 TTriangles2.Init(20000);
211
212 TStartPoints.Init(10000);
213 }
7fd59977 214//=======================================================================
215//function : FillArrayOfPnt
216//purpose : Compute points on one surface and fill an array of points
217//=======================================================================
55ab6ed6
P
218void IntPolyh_MaillageAffinage::FillArrayOfPnt
219 (const Standard_Integer SurfID)
7fd59977 220{
55ab6ed6
P
221 Standard_Integer NbSamplesU, NbSamplesV;
222 Standard_Real u0, u1, v0, v1;
223 Handle(Adaptor3d_HSurface) MaSurface;
224 //
225 MaSurface=(SurfID==1)? MaSurface1:MaSurface2;
7fd59977 226 IntPolyh_ArrayOfPoints &TPoints=(SurfID==1)? TPoints1:TPoints2;
55ab6ed6
P
227 NbSamplesU=(SurfID==1)? NbSamplesU1:NbSamplesU2;
228 NbSamplesV=(SurfID==1)? NbSamplesV1:NbSamplesV2;
229 //
230 u0 = (MaSurface)->FirstUParameter();
231 u1 = (MaSurface)->LastUParameter();
232 v0 = (MaSurface)->FirstVParameter();
233 v1 = (MaSurface)->LastVParameter();
7fd59977 234
235 if(myEnlargeZone) {
236 if(MaSurface->GetType() == GeomAbs_BSplineSurface ||
237 MaSurface->GetType() == GeomAbs_BezierSurface) {
238 if((!MaSurface->IsUClosed() && !MaSurface->IsUPeriodic()) &&
239 (Abs(u0) < 1.e+100 && Abs(u1) < 1.e+100) ) {
240 Standard_Real delta_u = Abs(u1 - u0) / 100.;
241 u0 -= delta_u;
242 u1 += delta_u;
243 }
244 if((!MaSurface->IsVClosed() && !MaSurface->IsVPeriodic()) &&
245 (Abs(v0) < 1.e+100 && Abs(v1) < 1.e+100) ) {
246 Standard_Real delta_v = Abs(v1 - v0) / 100.;
247 v0 -= delta_v;
248 v1 += delta_v;
249 }
250 }
251 }
55ab6ed6
P
252 //
253 Standard_Integer iCnt, BoucleU, BoucleV;
254 Standard_Real itU, itV, U, V, Tol;
255 Bnd_Box *PtrBox;
256 gp_Pnt PtXYZ;
257 //
258 iCnt=0;
259 itU=(u1-u0)/Standard_Real(NbSamplesU-1);
260 itV=(v1-v0)/Standard_Real(NbSamplesV-1);
261 PtrBox = (SurfID==1) ? (&MyBox1) : (&MyBox2);
262
263 for(BoucleU=0; BoucleU<NbSamplesU; BoucleU++){
264 U = (BoucleU == (NbSamplesU - 1)) ? u1 : u0+BoucleU*itU;
265 for(BoucleV=0; BoucleV<NbSamplesV; BoucleV++){
266 V = (BoucleV == (NbSamplesV - 1)) ? v1 : v0+BoucleV*itV;
267 PtXYZ = (MaSurface)->Value(U,V);
268 IntPolyh_Point& aIPnt=TPoints[iCnt];
269 aIPnt.Set(PtXYZ.X(), PtXYZ.Y(), PtXYZ.Z(), U, V);
270 iCnt++;
7fd59977 271 PtrBox->Add(PtXYZ);
272 }
273 }
d642ddf5 274 TPoints.SetNbItems(iCnt);
55ab6ed6
P
275 //
276 IntCurveSurface_ThePolyhedronOfHInter polyhedron(MaSurface,
277 NbSamplesU,
278 NbSamplesV,
279 u0,v0,
280 u1,v1);
281 Tol=polyhedron.DeflectionOverEstimation();
7fd59977 282 Tol*=1.2;
55ab6ed6 283 //
7fd59977 284 Standard_Real a1,a2,a3,b1,b2,b3;
55ab6ed6 285 //
7fd59977 286 PtrBox->Get(a1,a2,a3,b1,b2,b3);
287 PtrBox->Update(a1-Tol,a2-Tol,a3-Tol,b1+Tol,b2+Tol,b3+Tol);
288 PtrBox->Enlarge(MyTolerance);
289}
7fd59977 290//=======================================================================
291//function : FillArrayOfPnt
292//purpose : Compute points on one surface and fill an array of points
293// FILL AN ARRAY OF POINTS
294//=======================================================================
55ab6ed6
P
295void IntPolyh_MaillageAffinage::FillArrayOfPnt
296 (const Standard_Integer SurfID,
297 const Standard_Boolean isShiftFwd)
7fd59977 298{
299
300 Handle(Adaptor3d_HSurface) MaSurface=(SurfID==1)? MaSurface1:MaSurface2;
301 IntPolyh_ArrayOfPoints &TPoints=(SurfID==1)? TPoints1:TPoints2;
302 Standard_Integer NbSamplesU=(SurfID==1)? NbSamplesU1:NbSamplesU2;
303 Standard_Integer NbSamplesV=(SurfID==1)? NbSamplesV1:NbSamplesV2;
304
305 Standard_Real u0 = (MaSurface)->FirstUParameter();
306 Standard_Real u1 = (MaSurface)->LastUParameter();
307 Standard_Real v0 = (MaSurface)->FirstVParameter();
308 Standard_Real v1 = (MaSurface)->LastVParameter();
309
310 if(myEnlargeZone) {
311 if(MaSurface->GetType() == GeomAbs_BSplineSurface ||
312 MaSurface->GetType() == GeomAbs_BezierSurface) {
313 if((!MaSurface->IsUClosed() && !MaSurface->IsUPeriodic()) &&
314 (Abs(u0) < 1.e+100 && Abs(u1) < 1.e+100) ) {
315 Standard_Real delta_u = Abs(u1 - u0) / 100.;
316 u0 -= delta_u;
317 u1 += delta_u;
318 }
319 if((!MaSurface->IsVClosed() && !MaSurface->IsVPeriodic()) &&
320 (Abs(v0) < 1.e+100 && Abs(v1) < 1.e+100) ) {
321 Standard_Real delta_v = Abs(v1 - v0) / 100.;
322 v0 -= delta_v;
323 v1 += delta_v;
324 }
325 }
326 }
327
55ab6ed6
P
328 IntCurveSurface_ThePolyhedronOfHInter polyhedron(MaSurface,
329 NbSamplesU,
330 NbSamplesV,
331 u0,v0,
332 u1,v1);
7fd59977 333 Standard_Real Tol=polyhedron.DeflectionOverEstimation();
334
335 Standard_Integer CpteurTabPnt=0;
336 Standard_Real itU=(u1-u0)/Standard_Real(NbSamplesU-1);
337 Standard_Real itV=(v1-v0)/Standard_Real(NbSamplesV-1);
338
339 Bnd_Box *PtrBox = (SurfID==1) ? (&MyBox1) : (&MyBox2);
340 Standard_Real resol = gp::Resolution();
341
342 for(Standard_Integer BoucleU=0; BoucleU<NbSamplesU; BoucleU++){
343 Standard_Real U = (BoucleU == (NbSamplesU - 1)) ? u1 : u0+BoucleU*itU;
344 for(Standard_Integer BoucleV=0; BoucleV<NbSamplesV; BoucleV++){
345 Standard_Real V = (BoucleV == (NbSamplesV - 1)) ? v1 : v0+BoucleV*itV;
346
347 gp_Pnt PtXYZ;
348 gp_Vec aDU;
349 gp_Vec aDV;
350 gp_Vec aNorm;
351
352 MaSurface->D1(U, V, PtXYZ, aDU, aDV);
353
354 aNorm = aDU.Crossed(aDV);
355 Standard_Real aMag = aNorm.Magnitude();
356 if (aMag > resol) {
357 aNorm /= aMag;
358 aNorm.Multiply(Tol*1.5);
359
360 if (isShiftFwd)
361 PtXYZ.Translate(aNorm);
362 else
363 PtXYZ.Translate(aNorm.Reversed());
364 }
365
366 (TPoints[CpteurTabPnt]).Set(PtXYZ.X(), PtXYZ.Y(), PtXYZ.Z(), U, V);
367 CpteurTabPnt++;
368 PtrBox->Add(PtXYZ);
369 }
370 }
d642ddf5 371 TPoints.SetNbItems(CpteurTabPnt);
7fd59977 372
373 Tol*=1.2;
374
375 Standard_Real a1,a2,a3,b1,b2,b3;
376 PtrBox->Get(a1,a2,a3,b1,b2,b3);
377 PtrBox->Update(a1-Tol,a2-Tol,a3-Tol,b1+Tol,b2+Tol,b3+Tol);
378 PtrBox->Enlarge(MyTolerance);
55ab6ed6
P
379}
380//=======================================================================
381//function : FillArrayOfPnt
382//purpose : Compute points on one surface and fill an array of points
383//=======================================================================
384void IntPolyh_MaillageAffinage::FillArrayOfPnt
385 (const Standard_Integer SurfID,
386 const TColStd_Array1OfReal& Upars,
387 const TColStd_Array1OfReal& Vpars)
388{
389 Standard_Boolean bDegI, bDeg;
390 Standard_Integer aNbU, aNbV, iCnt, i, j;
391 Standard_Integer aID1, aID2, aJD1, aJD2;
6e6cd5d9 392 Standard_Real aTol, aU, aV, aX, aY, aZ;
55ab6ed6
P
393 gp_Pnt aP;
394 //
395 aNbU=(SurfID==1)? NbSamplesU1 : NbSamplesU2;
396 aNbV=(SurfID==1)? NbSamplesV1 : NbSamplesV2;
397 Bnd_Box& aBox = (SurfID==1) ? MyBox1 : MyBox2;
398 Handle(Adaptor3d_HSurface)& aS=(SurfID==1)? MaSurface1:MaSurface2;
399 IntPolyh_ArrayOfPoints &TPoints=(SurfID==1)? TPoints1:TPoints2;
400 //
401 //modified by NIZNHY-PKV Fri Jan 20 09:48:57 2012f
402 aJD1=0;
403 aJD2=0;
404 aID1=0;
405 aID2=0;
406 DegeneratedIndex(Vpars, aNbV, aS, 1, aJD1, aJD2);
407 if (!(aJD1 || aJD2)) {
408 DegeneratedIndex(Upars, aNbU, aS, 2, aID1, aID2);
409 }
410 //modified by NIZNHY-PKV Fri Jan 20 09:49:00 2012t
411 //
412 iCnt=0;
413 for(i=1; i<=aNbU; ++i){
414 //modified by NIZNHY-PKV Fri Jan 20 13:59:15 2012f
415 bDegI=(aID1==i || aID2==i);
416 //modified by NIZNHY-PKV Fri Jan 20 13:59:17 2012t
417 aU=Upars(i);
418 for(j=1; j<=aNbV; ++j){
419 aV=Vpars(j);
420 aP=aS->Value(aU, aV);
421 aP.Coord(aX, aY, aZ);
422 IntPolyh_Point& aIP=TPoints[iCnt];
423 aIP.Set(aX, aY, aZ, aU, aV);
424 //
425 //modified by NIZNHY-PKV Fri Jan 20 13:59:06 2012f
426 bDeg=bDegI || (aJD1==j || aJD2==j);
427 if (bDeg) {
428 aIP.SetDegenerated(bDeg);
429 }
430 //modified by NIZNHY-PKV Fri Jan 20 13:59:02 2012t
431 ++iCnt;
432 aBox.Add(aP);
433 }
434 }
435 //
d642ddf5 436 TPoints.SetNbItems(iCnt);
55ab6ed6
P
437 //
438 IntCurveSurface_ThePolyhedronOfHInter polyhedron(aS, Upars, Vpars);
439 //
440 aTol=polyhedron.DeflectionOverEstimation();
441 aTol*=1.2;
442
443 Standard_Real a1,a2,a3,b1,b2,b3;
444 //
445 aBox.Get(a1,a2,a3,b1,b2,b3);
446 aBox.Update(a1-aTol,a2-aTol,a3-aTol,b1+aTol,b2+aTol,b3+aTol);
447 aBox.Enlarge(MyTolerance);
448}
7fd59977 449
55ab6ed6
P
450//=======================================================================
451//function : FillArrayOfPnt
452//purpose : Compute points on one surface and fill an array of points
453// REMPLISSAGE DU TABLEAU DE POINTS
454//=======================================================================
455void IntPolyh_MaillageAffinage::FillArrayOfPnt
456 (const Standard_Integer SurfID,
457 const Standard_Boolean isShiftFwd,
458 const TColStd_Array1OfReal& Upars,
459 const TColStd_Array1OfReal& Vpars)
460{
461 Standard_Boolean bDegI, bDeg;
462 Standard_Integer aNbU, aNbV, iCnt, i, j;
463 Standard_Integer aID1, aID2, aJD1, aJD2;
464 Standard_Real Tol, resol, u0, v0, u1, v1, aU, aV, aMag;
465 Standard_Real aX, aY, aZ;
466 gp_Pnt aP;
467 gp_Vec aDU, aDV, aNorm;
468 //
469 aNbU=(SurfID==1)? NbSamplesU1:NbSamplesU2;
470 aNbV=(SurfID==1)? NbSamplesV1:NbSamplesV2;
471 Bnd_Box& aBox = (SurfID==1) ? MyBox1 : MyBox2;
472 Handle(Adaptor3d_HSurface) aS=(SurfID==1)? MaSurface1:MaSurface2;
473 IntPolyh_ArrayOfPoints &TPoints=(SurfID==1)? TPoints1:TPoints2;
474 //
475 resol = gp::Resolution();
476 u0 = Upars(1);
477 v0 = Vpars(1);
478 u1 = Upars(aNbU);
479 v1 = Vpars(aNbV);
480 //
481 IntCurveSurface_ThePolyhedronOfHInter polyhedron(aS, Upars, Vpars);
482 Tol=polyhedron.DeflectionOverEstimation();
483 //modified by NIZNHY-PKV Fri Jan 20 09:48:57 2012f
484 aJD1=0;
485 aJD2=0;
486 aID1=0;
487 aID2=0;
488 DegeneratedIndex(Vpars, aNbV, aS, 1, aJD1, aJD2);
489 if (!(aJD1 || aJD2)) {
490 DegeneratedIndex(Upars, aNbU, aS, 2, aID1, aID2);
491 }
492 //modified by NIZNHY-PKV Fri Jan 20 09:49:00 2012t
493 //
494 iCnt=0;
495 for(i=1; i<=aNbU; ++i){
496 //modified by NIZNHY-PKV Fri Jan 20 13:59:15 2012f
497 bDegI=(aID1==i || aID2==i);
498 //modified by NIZNHY-PKV Fri Jan 20 13:59:17 2012t
499 aU = Upars(i);
500 for(j=1; j<=aNbV; ++j){
501 aV = Vpars(j);
502 aS->D1(aU, aV, aP, aDU, aDV);
503
504 aNorm = aDU.Crossed(aDV);
505 aMag = aNorm.Magnitude();
506 if (aMag > resol) {
507 aNorm /= aMag;
508 aNorm.Multiply(Tol*1.5);
509 //
510 if (isShiftFwd) {
511 aP.Translate(aNorm);
512 }
513 else{
514 aP.Translate(aNorm.Reversed());
515 }
516 }
517
518 IntPolyh_Point& aIP=TPoints[iCnt];
519 aP.Coord(aX, aY, aZ);
520 aIP.Set(aX, aY, aZ, aU, aV);
521 //
522 //modified by NIZNHY-PKV Fri Jan 20 13:59:06 2012f
523 bDeg=bDegI || (aJD1==j || aJD2==j);
524 if (bDeg) {
525 aIP.SetDegenerated(bDeg);
526 }
527 //modified by NIZNHY-PKV Fri Jan 20 13:59:02 2012t
528 ++iCnt;
529 aBox.Add(aP);
530 }
531 }
532 //
d642ddf5 533 TPoints.SetNbItems(iCnt);
55ab6ed6
P
534 //
535 Tol*=1.2;
536 //
537 Standard_Real a1,a2,a3,b1,b2,b3;
538 //
539 aBox.Get(a1,a2,a3,b1,b2,b3);
540 aBox.Update(a1-Tol,a2-Tol,a3-Tol,b1+Tol,b2+Tol,b3+Tol);
541 aBox.Enlarge(MyTolerance);
542}
7fd59977 543//=======================================================================
544//function : CommonBox
545//purpose : Compute the common box witch is the intersection
546// of the two bounding boxes, and mark the points of
547// the two surfaces that are inside.
548// REJECTION BOUNDING BOXES
549// DETERMINATION OF THE COMMON BOX
550//=======================================================================
55ab6ed6
P
551void IntPolyh_MaillageAffinage::CommonBox (const Bnd_Box &,
552 const Bnd_Box &,
553 Standard_Real &XMin,
554 Standard_Real &YMin,
555 Standard_Real &ZMin,
556 Standard_Real &XMax,
557 Standard_Real &YMax,
558 Standard_Real &ZMax)
559{
7fd59977 560 Standard_Real x10,y10,z10,x11,y11,z11;
561 Standard_Real x20,y20,z20,x21,y21,z21;
562
563 MyBox1.Get(x10,y10,z10,x11,y11,z11);
564 MyBox2.Get(x20,y20,z20,x21,y21,z21);
7fd59977 565 XMin = 0.;
566 YMin = 0.;
567 ZMin = 0.;
568 XMax = 0.;
569 YMax = 0.;
570 ZMax = 0.;
7fd59977 571
572 if((x10>x21)||(x20>x11)||(y10>y21)||(y20>y11)||(z10>z21)||(z20>z11)) {
7fd59977 573 }
574 else {
7fd59977 575 if(x11<=x21) XMax=x11; else { if(x21<=x11) XMax=x21;}
7fd59977 576 if(x20<=x10) XMin=x10; else { if(x10<=x20) XMin=x20;}
7fd59977 577 if(y11<=y21) YMax=y11; else { if(y21<=y11) YMax=y21;}
7fd59977 578 if(y20<=y10) YMin=y10; else { if(y10<=y20) YMin=y20;}
7fd59977 579 if(z11<=z21) ZMax=z11; else { if(z21<=z11) ZMax=z21;}
7fd59977 580 if(z20<=z10) ZMin=z10; else { if(z10<=z20) ZMin=z20;}
7fd59977 581
582 if(((XMin==XMax)&&(!(YMin==YMax)&&!(ZMin==ZMax)))
583 ||((YMin==YMax)&&(!(XMin==XMax)&&!(ZMin==ZMax)))//ou exclusif ??
584 ||((ZMin==ZMax)&&(!(XMin==XMax)&&!(YMin==YMax)))) {
7fd59977 585 }
586 }
55ab6ed6 587 //
7fd59977 588 Standard_Real X,Y,Z;
589 X=XMax-XMin;
590 Y=YMax-YMin;
591 Z=ZMax-ZMin;
592 //extension of the box
593 if( (X==0)&&(Y!=0) ) X=Y*0.1;
594 else if( (X==0)&&(Z!=0) ) X=Z*0.1;
595 else X*=0.1;
596
597 if( (Y==0)&&(X!=0) ) Y=X*0.1;
598 else if( (Y==0)&&(Z!=0) ) Y=Z*0.1;
599 else Y*=0.1;
600
601 if( (Z==0)&&(X!=0) ) Z=X*0.1;
602 else if( (Z==0)&&(Y!=0) ) Z=Y*0.1;
603 else Z*=0.1;
604
605
606 if( (X==0)&&(Y==0)&&(Z==0) ) {
607
55ab6ed6 608
7fd59977 609 }
610 XMin-=X; XMax+=X;
611 YMin-=Y; YMax+=Y;
612 ZMin-=Z; ZMax+=Z;
613
614 //Marking of points included in the common
d642ddf5 615 const Standard_Integer FinTP1 = TPoints1.NbItems();
7fd59977 616// for(Standard_Integer i=0; i<FinTP1; i++) {
617 Standard_Integer i ;
618 for( i=0; i<FinTP1; i++) {
619 IntPolyh_Point & Pt1 = TPoints1[i];
620 Standard_Integer r;
55ab6ed6
P
621 if(Pt1.X()<XMin) {
622 r=1;
623 }
624 else {
625 if(Pt1.X()>XMax) {
626 r=2;
627 } else {
628 r=0;
629 }
630 }
631 if(Pt1.Y()<YMin) {
632 r|=4;
633 }
634 else {
635 if(Pt1.Y()>YMax) {
636 r|=8;
637 }
638 }
639 if(Pt1.Z()<ZMin) {
640 r|=16;
641 } else {
642 if(Pt1.Z()>ZMax) {
643 r|=32;
644 }
645 }
7fd59977 646 Pt1.SetPartOfCommon(r);
647 }
648
d642ddf5 649 const Standard_Integer FinTP2 = TPoints2.NbItems();
7fd59977 650 for(Standard_Integer ii=0; ii<FinTP2; ii++) {
651 IntPolyh_Point & Pt2 = TPoints2[ii];
652 Standard_Integer rr;
55ab6ed6
P
653 if(Pt2.X()<XMin) {
654 rr=1;
655 }
656 else {
657 if(Pt2.X()>XMax) {
658 rr=2;
659 } else {
660 rr=0;
661 }
662 }
663 if(Pt2.Y()<YMin) {
664 rr|=4;
665 }
666 else {
667 if(Pt2.Y()>YMax) {
668 rr|=8;
669 }
670 }
671 if(Pt2.Z()<ZMin) {
672 rr|=16;
673 }
674 else {
675 if(Pt2.Z()>ZMax) {
676 rr|=32;
677 }
678 }
7fd59977 679 Pt2.SetPartOfCommon(rr);
680 }
7fd59977 681}
7fd59977 682//=======================================================================
683//function : FillArrayOfEdges
684//purpose : Compute edges from the array of points
685// FILL THE ARRAY OF EDGES
686//=======================================================================
55ab6ed6
P
687void IntPolyh_MaillageAffinage::FillArrayOfEdges
688 (const Standard_Integer SurfID)
689{
7fd59977 690
691 IntPolyh_ArrayOfEdges &TEdges=(SurfID==1)? TEdges1:TEdges2;
692 Standard_Integer NbSamplesU=(SurfID==1)? NbSamplesU1:NbSamplesU2;
693 Standard_Integer NbSamplesV=(SurfID==1)? NbSamplesV1:NbSamplesV2;
694
695 Standard_Integer CpteurTabEdges=0;
696
697 //maillage u0 v0
698 TEdges[CpteurTabEdges].SetFirstPoint(0); // U V
699 TEdges[CpteurTabEdges].SetSecondPoint(1); // U V+1
700 // TEdges[CpteurTabEdges].SetFirstTriangle(-1);
701 TEdges[CpteurTabEdges].SetSecondTriangle(0);
702 CpteurTabEdges++;
703
704 TEdges[CpteurTabEdges].SetFirstPoint(0); // U V
705 TEdges[CpteurTabEdges].SetSecondPoint(NbSamplesV); // U+1 V
706 TEdges[CpteurTabEdges].SetFirstTriangle(0);
707 TEdges[CpteurTabEdges].SetSecondTriangle(1);
708 CpteurTabEdges++;
709
710 TEdges[CpteurTabEdges].SetFirstPoint(0); // U V
711 TEdges[CpteurTabEdges].SetSecondPoint(NbSamplesV+1); // U+1 V+1
712 TEdges[CpteurTabEdges].SetFirstTriangle(1);
713 // TEdges[CpteurTabEdges].SetSecondTriangle(-1);
714 CpteurTabEdges++;
715
716 //maillage surU=u0
717 Standard_Integer PntInit=1;
7fd59977 718 Standard_Integer BoucleMeshV;
719 for(BoucleMeshV=1; BoucleMeshV<NbSamplesV-1;BoucleMeshV++){
720 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
721 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+1); // U V+1
722 // TEdges[CpteurTabEdges].SetFirstTriangle(-1);
723 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*2);
724 CpteurTabEdges++;
725
726 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
727 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV+1); // U+1 V+1
728 TEdges[CpteurTabEdges].SetFirstTriangle(BoucleMeshV*2);
729 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*2+1);
730 CpteurTabEdges++;
731
732 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
733 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV); // U+1 V
734 TEdges[CpteurTabEdges].SetFirstTriangle(BoucleMeshV*2+1);
735 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*2-2);
736 CpteurTabEdges++;
737 PntInit++;
738 }
739
740 //maillage sur V=v0
741 PntInit=NbSamplesV;
742 for(BoucleMeshV=1; BoucleMeshV<NbSamplesU-1;BoucleMeshV++){
743 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
744 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+1); // U V+1
745 TEdges[CpteurTabEdges].SetFirstTriangle((BoucleMeshV-1)*(NbSamplesV-1)*2+1);
746 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*(NbSamplesV-1)*2);
747 CpteurTabEdges++;
748
749 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
750 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV+1); // U+1 V+1
751 TEdges[CpteurTabEdges].SetFirstTriangle(BoucleMeshV*(NbSamplesV-1)*2);
752 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*(NbSamplesV-1)*2+1);
753 CpteurTabEdges++;
754
755 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
756 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV); // U+1 V
757 TEdges[CpteurTabEdges].SetFirstTriangle(BoucleMeshV*(NbSamplesV-1)*2+1);
758 // TEdges[CpteurTabEdges].SetSecondTriangle(-1);
759 CpteurTabEdges++;
760 PntInit+=NbSamplesV;
761 }
762
763 PntInit=NbSamplesV+1;
764 //To provide recursion I associate a point with three edges
765 for(Standard_Integer BoucleMeshU=1; BoucleMeshU<NbSamplesU-1; BoucleMeshU++){
766 for(Standard_Integer BoucleMeshV=1; BoucleMeshV<NbSamplesV-1;BoucleMeshV++){
767 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
768 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+1); // U V+1
769 TEdges[CpteurTabEdges].SetFirstTriangle((NbSamplesV-1)*2*(BoucleMeshU-1)+BoucleMeshV*2+1);
770 TEdges[CpteurTabEdges].SetSecondTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2);
771 CpteurTabEdges++;
772
773 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
774 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV+1); // U+1 V+1
775 TEdges[CpteurTabEdges].SetFirstTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2);
776 TEdges[CpteurTabEdges].SetSecondTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2+1);
777 CpteurTabEdges++;
778
779 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); // U V
780 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+NbSamplesV); // U+1 V
781 TEdges[CpteurTabEdges].SetFirstTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2+1);
782 TEdges[CpteurTabEdges].SetSecondTriangle((NbSamplesV-1)*2*BoucleMeshU+BoucleMeshV*2-2);
783 CpteurTabEdges++;
784 PntInit++;//Pass to the next point
785 }
786 PntInit++;//Pass the last point of the column
787 PntInit++;//Pass the first point of the next column
788 }
789
790 //close mesh on U=u1
791 PntInit=(NbSamplesU-1)*NbSamplesV; //point U=u1 V=0
792 for(BoucleMeshV=0; BoucleMeshV<NbSamplesV-1; BoucleMeshV++){
793 TEdges[CpteurTabEdges].SetFirstPoint(PntInit); //U=u1 V
794 TEdges[CpteurTabEdges].SetSecondPoint(PntInit+1); //U=u1 V+1
795 TEdges[CpteurTabEdges].SetFirstTriangle((NbSamplesU-2)*(NbSamplesV-1)*2+BoucleMeshV*2+1);
796 // TEdges[CpteurTabEdges].SetSecondTriangle(-1);
797 CpteurTabEdges++;
798 PntInit++;
799 }
800
801 //close mesh on V=v1
802 for(BoucleMeshV=0; BoucleMeshV<NbSamplesU-1;BoucleMeshV++){
803 TEdges[CpteurTabEdges].SetFirstPoint(NbSamplesV-1+BoucleMeshV*NbSamplesV); // U V=v1
804 TEdges[CpteurTabEdges].SetSecondPoint(NbSamplesV-1+(BoucleMeshV+1)*NbSamplesV); //U+1 V=v1
805 // TEdges[CpteurTabEdges].SetFirstTriangle(-1);
806 TEdges[CpteurTabEdges].SetSecondTriangle(BoucleMeshV*2*(NbSamplesV-1)+(NbSamplesV-2)*2);
807 CpteurTabEdges++;
808 }
d642ddf5 809 TEdges.SetNbItems(CpteurTabEdges);
55ab6ed6 810
7fd59977 811}
812
813//=======================================================================
814//function : FillArrayOfTriangles
815//purpose : Compute triangles from the array of points, and --
816// mark the triangles that use marked points by the
817// CommonBox function.
818// FILL THE ARRAY OF TRIANGLES
819//=======================================================================
55ab6ed6
P
820void IntPolyh_MaillageAffinage::FillArrayOfTriangles
821 (const Standard_Integer SurfID)
822{
7fd59977 823 Standard_Integer CpteurTabTriangles=0;
824 Standard_Integer PntInit=0;
825
826 IntPolyh_ArrayOfPoints &TPoints=(SurfID==1)? TPoints1:TPoints2;
827 IntPolyh_ArrayOfTriangles &TTriangles=(SurfID==1)? TTriangles1:TTriangles2;
828 Standard_Integer NbSamplesU=(SurfID==1)? NbSamplesU1:NbSamplesU2;
829 Standard_Integer NbSamplesV=(SurfID==1)? NbSamplesV1:NbSamplesV2;
830
831
832 //To provide recursion, I associate a point with two triangles
833 for(Standard_Integer BoucleMeshU=0; BoucleMeshU<NbSamplesU-1; BoucleMeshU++){
834 for(Standard_Integer BoucleMeshV=0; BoucleMeshV<NbSamplesV-1;BoucleMeshV++){
835
836 // FIRST TRIANGLE
837 TTriangles[CpteurTabTriangles].SetFirstPoint(PntInit); // U V
838 TTriangles[CpteurTabTriangles].SetSecondPoint(PntInit+1); // U V+1
839 TTriangles[CpteurTabTriangles].SetThirdPoint(PntInit+NbSamplesV+1); // U+1 V+1
840
841 // IF ITS EDGE CONTACTS WITH THE COMMON BOX IP REMAINS = A 1
842 if( ( (TPoints[PntInit].PartOfCommon()) & (TPoints[PntInit+1].PartOfCommon()) )
843 &&( (TPoints[PntInit+1].PartOfCommon()) & (TPoints[PntInit+NbSamplesV+1].PartOfCommon()))
844 &&( (TPoints[PntInit+NbSamplesV+1].PartOfCommon()) & (TPoints[PntInit].PartOfCommon())) )
845 //IF NOT IP=0
846 TTriangles[CpteurTabTriangles].SetIndiceIntersectionPossible(0);
847
848 CpteurTabTriangles++;
849
850 //SECOND TRIANGLE
851 TTriangles[CpteurTabTriangles].SetFirstPoint(PntInit); // U V
852 TTriangles[CpteurTabTriangles].SetSecondPoint(PntInit+NbSamplesV+1); // U+1 V+1
853 TTriangles[CpteurTabTriangles].SetThirdPoint(PntInit+NbSamplesV); // U+1 V
854
855
856 if( ( (TPoints[PntInit].PartOfCommon()) & (TPoints[PntInit+NbSamplesV+1].PartOfCommon()) )
857 &&( (TPoints[PntInit+NbSamplesV+1].PartOfCommon()) & (TPoints[PntInit+NbSamplesV].PartOfCommon()))
858 &&( (TPoints[PntInit+NbSamplesV].PartOfCommon()) & (TPoints[PntInit].PartOfCommon())) )
859 TTriangles[CpteurTabTriangles].SetIndiceIntersectionPossible(0);
860
861
862 CpteurTabTriangles++;
863
864 PntInit++;//Pass to the next point
865 }
866 PntInit++;//Pass the last point of the column
867 }
d642ddf5 868 TTriangles.SetNbItems(CpteurTabTriangles);
869 const Standard_Integer FinTT = TTriangles.NbItems();
7fd59977 870 if (FinTT==0) {
7fd59977 871 }
7fd59977 872}
7fd59977 873//=======================================================================
874//function : LinkEdges2Triangles
875//purpose : fill the edge fields in Triangle object for the
876// two array of triangles.
877//=======================================================================
55ab6ed6
P
878void IntPolyh_MaillageAffinage::LinkEdges2Triangles()
879{
d642ddf5 880 const Standard_Integer FinTT1 = TTriangles1.NbItems();
881 const Standard_Integer FinTT2 = TTriangles2.NbItems();
7fd59977 882
883 for(Standard_Integer uiui1=0; uiui1<FinTT1; uiui1++) {
884 IntPolyh_Triangle & MyTriangle1=TTriangles1[uiui1];
885 if ( (MyTriangle1.FirstEdge()) == -1 ) {
886 MyTriangle1.SetEdgeandOrientation(1,TEdges1);
887 MyTriangle1.SetEdgeandOrientation(2,TEdges1);
888 MyTriangle1.SetEdgeandOrientation(3,TEdges1);
889 }
890 }
891 for(Standard_Integer uiui2=0; uiui2<FinTT2; uiui2++) {
892 IntPolyh_Triangle & MyTriangle2=TTriangles2[uiui2];
893 if ( (MyTriangle2.FirstEdge()) == -1 ) {
894 MyTriangle2.SetEdgeandOrientation(1,TEdges2);
895 MyTriangle2.SetEdgeandOrientation(2,TEdges2);
896 MyTriangle2.SetEdgeandOrientation(3,TEdges2);
897 }
898 }
7fd59977 899}
7fd59977 900//=======================================================================
901//function : CommonPartRefinement
902//purpose : Refine systematicaly all marked triangles of both surfaces
903// REFINING OF THE COMMON
904//=======================================================================
55ab6ed6
P
905void IntPolyh_MaillageAffinage::CommonPartRefinement()
906{
d642ddf5 907 Standard_Integer FinInit1 = TTriangles1.NbItems();
7fd59977 908 for(Standard_Integer i=0; i<FinInit1; i++) {
909 if(TTriangles1[i].IndiceIntersectionPossible()!=0)
910 TTriangles1[i].MiddleRefinement(i,MaSurface1,TPoints1,TTriangles1,TEdges1);
911 }
912
d642ddf5 913 Standard_Integer FinInit2=TTriangles2.NbItems();
7fd59977 914 for(Standard_Integer ii=0; ii<FinInit2; ii++) {
915 if(TTriangles2[ii].IndiceIntersectionPossible()!=0)
916 TTriangles2[ii].MiddleRefinement(ii,MaSurface2,TPoints2,TTriangles2,TEdges2);
917 }
7fd59977 918
55ab6ed6 919}
7fd59977 920//=======================================================================
921//function : LocalSurfaceRefinement
922//purpose : Refine systematicaly all marked triangles of ONE surface
923//=======================================================================
7fd59977 924void IntPolyh_MaillageAffinage::LocalSurfaceRefinement(const Standard_Integer SurfID) {
925//refine locally, but systematically the chosen surface
926 if (SurfID==1) {
d642ddf5 927 const Standard_Integer FinInit1 = TTriangles1.NbItems();
7fd59977 928 for(Standard_Integer i=0; i<FinInit1; i++) {
929 if(TTriangles1[i].IndiceIntersectionPossible()!=0)
930 TTriangles1[i].MiddleRefinement(i,MaSurface1,TPoints1,TTriangles1,TEdges1);
931 }
932 }
55ab6ed6 933 //
7fd59977 934 if (SurfID==2) {
d642ddf5 935 const Standard_Integer FinInit2 = TTriangles2.NbItems();
7fd59977 936 for(Standard_Integer ii=0; ii<FinInit2; ii++) {
937 if(TTriangles2[ii].IndiceIntersectionPossible()!=0)
938 TTriangles2[ii].MiddleRefinement(ii,MaSurface2,TPoints2,TTriangles2,TEdges2);
939 }
940 }
941}
7fd59977 942//=======================================================================
943//function : ComputeDeflections
944//purpose : Compute deflection for all triangles of one
945// surface,and sort min and max of deflections
946// REFINING PART
947// Calculation of the deflection of all triangles
948// --> deflection max
949// --> deflection min
950//=======================================================================
55ab6ed6
P
951void IntPolyh_MaillageAffinage::ComputeDeflections
952 (const Standard_Integer SurfID)
953{
7fd59977 954 Handle(Adaptor3d_HSurface) MaSurface=(SurfID==1)? MaSurface1:MaSurface2;
955 IntPolyh_ArrayOfPoints &TPoints=(SurfID==1)? TPoints1:TPoints2;
956 IntPolyh_ArrayOfTriangles &TTriangles=(SurfID==1)? TTriangles1:TTriangles2;
957 Standard_Real &FlecheMin=(SurfID==1)? FlecheMin1:FlecheMin2;
958 Standard_Real &FlecheMoy=(SurfID==1)? FlecheMoy1:FlecheMoy2;
959 Standard_Real &FlecheMax=(SurfID==1)? FlecheMax1:FlecheMax2;
960
961 Standard_Integer CpteurTabFleche=0;
962 FlecheMax=-RealLast();
963 FlecheMin=RealLast();
964 FlecheMoy=0.0;
d642ddf5 965 const Standard_Integer FinTT = TTriangles.NbItems();
7fd59977 966
967 for(CpteurTabFleche=0; CpteurTabFleche<FinTT; CpteurTabFleche++) {
968 IntPolyh_Triangle &Triangle = TTriangles[CpteurTabFleche];
969 if ( Triangle.GetFleche() < 0) { //pas normal
55ab6ed6 970
7fd59977 971 }
972 else{
973 Triangle.TriangleDeflection(MaSurface, TPoints);
974 Standard_Real Fleche=Triangle.GetFleche();
55ab6ed6 975
7fd59977 976 if (Fleche > FlecheMax)
977 FlecheMax=Fleche;
978 if (Fleche < FlecheMin)
979 FlecheMin=Fleche;
7fd59977 980 }
981 }
7fd59977 982}
7fd59977 983//=======================================================================
984//function : TrianglesDeflectionsRefinementBSB
985//purpose : Refine both surfaces using BoundSortBox as --
986// rejection. The criterions used to refine a --
987// triangle are: The deflection The size of the --
988// bounding boxes (one surface may be very small
989// compared to the other)
990//=======================================================================
55ab6ed6
P
991void IntPolyh_MaillageAffinage::TrianglesDeflectionsRefinementBSB()
992{
d642ddf5 993 const Standard_Integer FinTT1 = TTriangles1.NbItems();
994 const Standard_Integer FinTT2 = TTriangles2.NbItems();
7fd59977 995
996 ComputeDeflections(1);
55ab6ed6
P
997 // To estimate a surface in general it can be interesting
998 //to calculate all deflections
7fd59977 999 //-- Check deflection at output
1000
1001 Standard_Real FlecheCritique1;
1002 if(FlecheMin1>FlecheMax1) {
7fd59977 1003 return;
1004 }
55ab6ed6
P
1005 else {//fleche min + (flechemax-flechemin) * 80/100
1006 FlecheCritique1 = FlecheMin1*0.2+FlecheMax1*0.8;
7fd59977 1007 }
1008
1009 ComputeDeflections(2);
1010 //-- Check arrows at output
1011
1012 Standard_Real FlecheCritique2;
1013 if(FlecheMin2>FlecheMax2) {
55ab6ed6 1014
7fd59977 1015 return;
1016 }
55ab6ed6
P
1017 else {//fleche min + (flechemax-flechemin) * 80/100
1018 FlecheCritique2 = FlecheMin2*0.2+FlecheMax2*0.8;
7fd59977 1019 }
1020
1021 //Bounding boxes
1022 Bnd_BoundSortBox BndBSB;
1023 Standard_Real diag1,diag2;
1024 Standard_Real x0,y0,z0,x1,y1,z1;
1025
1026 //The greatest of two bounding boxes created in FillArrayOfPoints is found.
55ab6ed6
P
1027 //Then this value is weighted depending on the discretization
1028 //(NbSamplesU and NbSamplesV)
7fd59977 1029 MyBox1.Get(x0,y0,z0,x1,y1,z1);
1030 x0-=x1; y0-=y1; z0-=z1;
1031 diag1=x0*x0+y0*y0+z0*z0;
1032 const Standard_Real NbSamplesUV1=Standard_Real(NbSamplesU1) * Standard_Real(NbSamplesV1);
1033 diag1/=NbSamplesUV1;
1034
1035 MyBox2.Get(x0,y0,z0,x1,y1,z1);
1036 x0-=x1; y0-=y1; z0-=z1;
1037 diag2=x0*x0+y0*y0+z0*z0;
1038 const Standard_Real NbSamplesUV2=Standard_Real(NbSamplesU2) * Standard_Real(NbSamplesV2);
1039 diag2/=NbSamplesUV2;
1040
1041 //-- The surface with the greatest bounding box is "discretized"
1042
1043 //Standard_Integer NbInterTentees=0;
1044
1045 if(diag1<diag2) {
1046
1047 if(FlecheCritique2<diag1) {//the corresponding sizes are not too disproportional
1048
1049 Handle(Bnd_HArray1OfBox) HBnd = new Bnd_HArray1OfBox(1,FinTT2);
1050
1051 for(Standard_Integer i=0; i<FinTT2; i++){
1052 if (TTriangles2[i].IndiceIntersectionPossible()!=0) {
1053 Bnd_Box b;
1054 const IntPolyh_Triangle& T=TTriangles2[i];
1055 const IntPolyh_Point& PA=TPoints2[T.FirstPoint()];
1056 const IntPolyh_Point& PB=TPoints2[T.SecondPoint()];
1057 const IntPolyh_Point& PC=TPoints2[T.ThirdPoint()];
1058 gp_Pnt pntA(PA.X(),PA.Y(),PA.Z());
1059 gp_Pnt pntB(PB.X(),PB.Y(),PB.Z());
1060 gp_Pnt pntC(PC.X(),PC.Y(),PC.Z());
1061 b.Add(pntA);//Box b, which contains triangle i of surface 2 is created./
1062 b.Add(pntB);
1063 b.Add(pntC);
1064 b.Enlarge(T.GetFleche()+MyTolerance);
1065 HBnd->SetValue(i+1,b);//Box b is added in the array HBnd
1066 }
1067 }
1068
1069 //Inititalization of the boundary, sorting of boxes
1070 BndBSB.Initialize(HBnd);//contains boxes of 2
1071
1072 Standard_Integer FinTT1Init=FinTT1;
1073 for(Standard_Integer i_S1=0; i_S1<FinTT1Init; i_S1++) {
1074 if(TTriangles1[i_S1].IndiceIntersectionPossible()!=0) {
1075 //-- Loop on the boxes of mesh 1
1076 Bnd_Box b;
1077 const IntPolyh_Triangle& T=TTriangles1[i_S1];
1078 const IntPolyh_Point& PA=TPoints1[T.FirstPoint()];
1079 const IntPolyh_Point& PB=TPoints1[T.SecondPoint()];
1080 const IntPolyh_Point& PC=TPoints1[T.ThirdPoint()];
1081 gp_Pnt pntA(PA.X(),PA.Y(),PA.Z());
1082 gp_Pnt pntB(PB.X(),PB.Y(),PB.Z());
1083 gp_Pnt pntC(PC.X(),PC.Y(),PC.Z());
1084 b.Add(pntA);
1085 b.Add(pntB);
1086 b.Add(pntC);
1087 b.Enlarge(T.GetFleche());
1088 //-- List of boxes of 2, which touch this box (of 1)
1089 const TColStd_ListOfInteger& ListeOf2 = BndBSB.Compare(b);
1090
1091 if((ListeOf2.IsEmpty())==0) {
1092 IntPolyh_Triangle &Triangle1 = TTriangles1[i_S1];
1093 if(Triangle1.GetFleche()>FlecheCritique1)
1094 Triangle1.MiddleRefinement(i_S1,MaSurface1,TPoints1,
1095 TTriangles1, TEdges1);
1096
1097 for (TColStd_ListIteratorOfListOfInteger Iter(ListeOf2);
1098 Iter.More();
1099 Iter.Next()) {
1100 Standard_Integer i_S2=Iter.Value()-1;
55ab6ed6
P
1101 //if the box of s1 contacts with the boxes of s2
1102 //the arrow of the triangle is checked
7fd59977 1103 IntPolyh_Triangle & Triangle2 = TTriangles2[i_S2];
1104 if(Triangle2.IndiceIntersectionPossible()!=0)
1105 if(Triangle2.GetFleche()>FlecheCritique2)
1106 Triangle2.MiddleRefinement( i_S2, MaSurface2, TPoints2,
1107 TTriangles2, TEdges2);
1108 }
1109 }
1110 }
1111 }
1112 }
1113
1114 //--------------------------------------------------------------------
1115 //FlecheCritique2 > diag1
1116 else {
1117 //2 is discretized
1118
1119 Handle(Bnd_HArray1OfBox) HBnd = new Bnd_HArray1OfBox(1,FinTT2);
1120
1121 for(Standard_Integer i=0; i<FinTT2; i++){
1122 if (TTriangles2[i].IndiceIntersectionPossible()!=0) {
1123 Bnd_Box b;
1124 const IntPolyh_Triangle& T=TTriangles2[i];
1125 const IntPolyh_Point& PA=TPoints2[T.FirstPoint()];
1126 const IntPolyh_Point& PB=TPoints2[T.SecondPoint()];
1127 const IntPolyh_Point& PC=TPoints2[T.ThirdPoint()];
1128 gp_Pnt pntA(PA.X(),PA.Y(),PA.Z());
1129 gp_Pnt pntB(PB.X(),PB.Y(),PB.Z());
1130 gp_Pnt pntC(PC.X(),PC.Y(),PC.Z());
1131 b.Add(pntA);//Box b, which contains triangle i of surface 2 is created/
1132 b.Add(pntB);
1133 b.Add(pntC);
1134 b.Enlarge(T.GetFleche()+MyTolerance);
1135 //-- BndBSB.Add(b,i+1);
1136 HBnd->SetValue(i+1,b);//Box b is added in array HBnd
1137 }
1138 }
1139
1140 //Inititalization of the ouput bounding box
1141 BndBSB.Initialize(HBnd);//contains boxes of 2
1142
1143
1144 //The bounding box Be1 of surface1 is compared BSB of surface2
1145 const TColStd_ListOfInteger& ListeOf2 = BndBSB.Compare(MyBox1);
1146
1147 if((ListeOf2.IsEmpty())==0) {
55ab6ed6
P
1148 //if the bounding box Be1 of s1 contacts with
1149 //the boxes of s2 the deflection of triangle of s2 is checked
7fd59977 1150
1151 // Be1 is very small in relation to Be2
1152 //The criterion of refining for surface2 depends on the size of Be1
1153 //As it is known that this criterion should be minimized,
1154 //the smallest side of the bounding box is taken
1155 Standard_Real x0,x1,y0,y1,z0,z1;
1156 MyBox1.Get(x0,y0,z0,x1,y1,z1);
1157 Standard_Real dx=Abs(x1-x0);
1158 Standard_Real dy=Abs(y1-y0);
1159 Standard_Real diag=Abs(z1-z0);
1160 Standard_Real dd=-1.0;
1161 if (dx>dy)
1162 dd=dy;
1163 else
1164 dd=dx;
1165 if (diag>dd) diag=dd;
1166
55ab6ed6
P
1167 //if Be1 contacts with the boxes of s2, the deflection
1168 //of the triangles of s2 is checked (greater)
7fd59977 1169 //in relation to the size of Be1 (smaller)
1170 for (TColStd_ListIteratorOfListOfInteger Iter(ListeOf2);
1171 Iter.More();
1172 Iter.Next()) {
1173 Standard_Integer i_S2=Iter.Value()-1;
1174
1175 IntPolyh_Triangle & Triangle2=TTriangles2[i_S2];
1176 if(Triangle2.IndiceIntersectionPossible()) {
1177
1178 //calculation of the criterion of refining
1179 //The deflection of the greater is compared to the size of the smaller
1180 Standard_Real CritereAffinage=0.0;
1181 Standard_Real DiagPonderation=0.5;
1182 CritereAffinage = diag*DiagPonderation;
1183 if(Triangle2.GetFleche()>CritereAffinage)
1184 Triangle2.MultipleMiddleRefinement2(CritereAffinage, MyBox1, i_S2,
1185 MaSurface2, TPoints2,
1186 TTriangles2,TEdges2);
1187
1188 else Triangle2.MiddleRefinement(i_S2,MaSurface2,TPoints2,
1189 TTriangles2, TEdges2);
1190 }
1191 }
1192 }
1193 }
1194 }
1195
1196
1197 else { //-- The greater is discretised
1198
1199 if(FlecheCritique1<diag2) {//the respective sizes are not to much disproportional
1200
1201 Handle(Bnd_HArray1OfBox) HBnd = new Bnd_HArray1OfBox(1,FinTT1);
1202
1203 for(Standard_Integer i=0; i<FinTT1; i++){
1204 if(TTriangles1[i].IndiceIntersectionPossible()!=0) {
1205 Bnd_Box b;
1206 const IntPolyh_Triangle& T=TTriangles1[i];
1207 const IntPolyh_Point& PA=TPoints1[T.FirstPoint()];
1208 const IntPolyh_Point& PB=TPoints1[T.SecondPoint()];
1209 const IntPolyh_Point& PC=TPoints1[T.ThirdPoint()];
1210 gp_Pnt pntA(PA.X(),PA.Y(),PA.Z());
1211 gp_Pnt pntB(PB.X(),PB.Y(),PB.Z());
1212 gp_Pnt pntC(PC.X(),PC.Y(),PC.Z());
1213 b.Add(pntA);//Box b, which contains triangle i of surface 2 is created.
1214 b.Add(pntB);
1215 b.Add(pntC);
1216 b.Enlarge(T.GetFleche()+MyTolerance);
1217 HBnd->SetValue(i+1,b);//Boite b is added in the array HBnd
1218 }
1219 }
1220 BndBSB.Initialize(HBnd);
1221
1222 Standard_Integer FinTT2init=FinTT2;
1223 for(Standard_Integer i_S2=0; i_S2<FinTT2init; i_S2++) {
1224 if (TTriangles2[i_S2].IndiceIntersectionPossible()!=0) {
1225 //-- Loop on the boxes of mesh 2
1226 Bnd_Box b;
1227 const IntPolyh_Triangle& T=TTriangles2[i_S2];
1228 const IntPolyh_Point& PA=TPoints2[T.FirstPoint()];
1229 const IntPolyh_Point& PB=TPoints2[T.SecondPoint()];
1230 const IntPolyh_Point& PC=TPoints2[T.ThirdPoint()];
1231 gp_Pnt pntA(PA.X(),PA.Y(),PA.Z());
1232 gp_Pnt pntB(PB.X(),PB.Y(),PB.Z());
1233 gp_Pnt pntC(PC.X(),PC.Y(),PC.Z());
1234 b.Add(pntA);
1235 b.Add(pntB);
1236 b.Add(pntC);
1237 b.Enlarge(T.GetFleche()+MyTolerance);
1238 //-- List of boxes of 1 touching this box (of 2)
1239 const TColStd_ListOfInteger& ListeOf1 = BndBSB.Compare(b);
1240 IntPolyh_Triangle & Triangle2=TTriangles2[i_S2];
1241 if((ListeOf1.IsEmpty())==0) {
1242
1243 if(Triangle2.GetFleche()>FlecheCritique2)
1244 Triangle2.MiddleRefinement(i_S2,MaSurface2,TPoints2,
1245 TTriangles2, TEdges2);
1246
1247 for (TColStd_ListIteratorOfListOfInteger Iter(ListeOf1);
1248 Iter.More();
1249 Iter.Next()) {
1250 Standard_Integer i_S1=Iter.Value()-1;
1251 IntPolyh_Triangle & Triangle1=TTriangles1[i_S1];
1252 if (Triangle1.IndiceIntersectionPossible())
1253 if(Triangle1.GetFleche()>FlecheCritique1)
1254 Triangle1.MiddleRefinement(i_S1,MaSurface1,TPoints1,
1255 TTriangles1, TEdges1);
1256 }
1257 }
1258 }
1259 }
1260 }
1261 //-----------------------------------------------------------------------------
1262 else {// FlecheCritique1>diag2
1263 // 1 is discretized
1264
1265 Handle(Bnd_HArray1OfBox) HBnd = new Bnd_HArray1OfBox(1,FinTT1);
1266
1267 for(Standard_Integer i=0; i<FinTT1; i++){
1268 if (TTriangles1[i].IndiceIntersectionPossible()!=0) {
1269 Bnd_Box b;
1270 const IntPolyh_Triangle& T=TTriangles1[i];
1271 const IntPolyh_Point& PA=TPoints1[T.FirstPoint()];
1272 const IntPolyh_Point& PB=TPoints1[T.SecondPoint()];
1273 const IntPolyh_Point& PC=TPoints1[T.ThirdPoint()];
1274 gp_Pnt pntA(PA.X(),PA.Y(),PA.Z());
1275 gp_Pnt pntB(PB.X(),PB.Y(),PB.Z());
1276 gp_Pnt pntC(PC.X(),PC.Y(),PC.Z());
1277 b.Add(pntA);//Box b, which contains triangle i of surface 1 is created./
1278 b.Add(pntB);
1279 b.Add(pntC);
1280 b.Enlarge(T.GetFleche()+MyTolerance);
1281 HBnd->SetValue(i+1,b);//Box b is added in the array HBnd
1282 }
1283 }
1284
1285 //Inititalisation of the boundary output box
1286 BndBSB.Initialize(HBnd);//contains boxes of 1
1287
1288 //Bounding box Be2 of surface2 is compared to BSB of surface1
1289 const TColStd_ListOfInteger& ListeOf1 = BndBSB.Compare(MyBox2);
1290
1291 if((ListeOf1.IsEmpty())==0) {
55ab6ed6
P
1292 //if the bounding box Be2 of s2 contacts
1293 //with boxes of s1 the deflection of the triangle of s1 is checked
7fd59977 1294
1295 // Be2 is very small compared to Be1
1296 //The criterion of refining for surface1 depends on the size of Be2
55ab6ed6
P
1297 //As this criterion should be minimized,
1298 //the smallest side of the bounding box is taken
7fd59977 1299 Standard_Real x0,x1,y0,y1,z0,z1;
1300 MyBox2.Get(x0,y0,z0,x1,y1,z1);
1301 Standard_Real dx=Abs(x1-x0);
1302 Standard_Real dy=Abs(y1-y0);
1303 Standard_Real diag=Abs(z1-z0);
1304 Standard_Real dd=-1.0;
1305 if (dx>dy)
1306 dd=dy;
1307 else
1308 dd=dx;
1309 if (diag>dd) diag=dd;
1310
55ab6ed6
P
1311 //if Be2 contacts with boxes of s1, the deflection of
1312 //triangles of s1 (greater) is checked
7fd59977 1313 //comparatively to the size of Be2 (smaller).
1314 for (TColStd_ListIteratorOfListOfInteger Iter(ListeOf1);
1315 Iter.More();
1316 Iter.Next()) {
1317 Standard_Integer i_S1=Iter.Value()-1;
1318
1319 IntPolyh_Triangle & Triangle1=TTriangles1[i_S1];
1320 if(Triangle1.IndiceIntersectionPossible()) {
1321
1322 //calculation of the criterion of refining
55ab6ed6
P
1323 //The deflection of the greater is compared
1324 //with the size of the smaller.
7fd59977 1325 Standard_Real CritereAffinage=0.0;
1326 Standard_Real DiagPonderation=0.5;
1327 CritereAffinage = diag*DiagPonderation;;
1328 if(Triangle1.GetFleche()>CritereAffinage)
1329 Triangle1.MultipleMiddleRefinement2(CritereAffinage,MyBox2, i_S1,
1330 MaSurface1, TPoints1,
1331 TTriangles1, TEdges1);
1332
1333 else Triangle1.MiddleRefinement(i_S1,MaSurface1,TPoints1,
1334 TTriangles1, TEdges1);
1335
1336 }
1337 }
1338 }
1339 }
1340 }
7fd59977 1341}
7fd59977 1342//=======================================================================
1343//function : maxSR
1344//purpose : This function is used for the function project6
1345//=======================================================================
55ab6ed6
P
1346inline Standard_Real maxSR(const Standard_Real a,
1347 const Standard_Real b,
1348 const Standard_Real c)
1349{
7fd59977 1350 Standard_Real t = a;
1351 if (b > t) t = b;
1352 if (c > t) t = c;
1353 return t;
1354}
7fd59977 1355//=======================================================================
1356//function : minSR
1357//purpose : This function is used for the function project6
1358//=======================================================================
55ab6ed6
P
1359inline Standard_Real minSR(const Standard_Real a,
1360 const Standard_Real b,
1361 const Standard_Real c)
1362{
7fd59977 1363 Standard_Real t = a;
1364 if (b < t) t = b;
1365 if (c < t) t = c;
1366 return t;
1367}
7fd59977 1368//=======================================================================
1369//function : project6
1370//purpose : This function is used for the function TriContact
1371//=======================================================================
7fd59977 1372Standard_Integer project6(const IntPolyh_Point &ax,
55ab6ed6
P
1373 const IntPolyh_Point &p1,
1374 const IntPolyh_Point &p2,
1375 const IntPolyh_Point &p3,
1376 const IntPolyh_Point &q1,
1377 const IntPolyh_Point &q2,
1378 const IntPolyh_Point &q3)
1379{
7fd59977 1380 Standard_Real P1 = ax.Dot(p1);
1381 Standard_Real P2 = ax.Dot(p2);
1382 Standard_Real P3 = ax.Dot(p3);
1383 Standard_Real Q1 = ax.Dot(q1);
1384 Standard_Real Q2 = ax.Dot(q2);
1385 Standard_Real Q3 = ax.Dot(q3);
1386
1387 Standard_Real mx1 = maxSR(P1, P2, P3);
1388 Standard_Real mn1 = minSR(P1, P2, P3);
1389 Standard_Real mx2 = maxSR(Q1, Q2, Q3);
1390 Standard_Real mn2 = minSR(Q1, Q2, Q3);
1391
1392 if (mn1 > mx2) return 0;
1393 if (mn2 > mx1) return 0;
1394 return 1;
1395}
7fd59977 1396//=======================================================================
1397//function : TriContact
1398//purpose : This fonction Check if two triangles are in
1399// contact or no, return 1 if yes, return 0
1400// if no.
1401//=======================================================================
55ab6ed6
P
1402Standard_Integer IntPolyh_MaillageAffinage::TriContact
1403 (const IntPolyh_Point &P1,
1404 const IntPolyh_Point &P2,
1405 const IntPolyh_Point &P3,
1406 const IntPolyh_Point &Q1,
1407 const IntPolyh_Point &Q2,
1408 const IntPolyh_Point &Q3,
1409 Standard_Real &Angle) const
1410{
7fd59977 1411 /**
1412 The first triangle is (p1,p2,p3). The other is (q1,q2,q3).
1413 The edges are (e1,e2,e3) and (f1,f2,f3).
1414 The normals are n1 and m1
1415 Outwards are (g1,g2,g3) and (h1,h2,h3).*/
1416
1417 IntPolyh_Point p1, p2, p3;
1418 IntPolyh_Point q1, q2, q3;
1419 IntPolyh_Point e1, e2, e3;
1420 IntPolyh_Point f1, f2, f3;
1421 IntPolyh_Point g1, g2, g3;
1422 IntPolyh_Point h1, h2, h3;
1423 IntPolyh_Point n1, m1;
1424 IntPolyh_Point z;
1425
1426 IntPolyh_Point ef11, ef12, ef13;
1427 IntPolyh_Point ef21, ef22, ef23;
1428 IntPolyh_Point ef31, ef32, ef33;
1429
1430 z.SetX(0.0); z.SetY(0.0); z.SetZ(0.0);
1431
1432 if(maxSR(P1.X(),P2.X(),P3.X())<minSR(Q1.X(),Q2.X(),Q3.X())) return(0);
1433 if(maxSR(P1.Y(),P2.Y(),P3.Y())<minSR(Q1.Y(),Q2.Y(),Q3.Y())) return(0);
1434 if(maxSR(P1.Z(),P2.Z(),P3.Z())<minSR(Q1.Z(),Q2.Z(),Q3.Z())) return(0);
1435
1436 if(minSR(P1.X(),P2.X(),P3.X())>maxSR(Q1.X(),Q2.X(),Q3.X())) return(0);
1437 if(minSR(P1.Y(),P2.Y(),P3.Y())>maxSR(Q1.Y(),Q2.Y(),Q3.Y())) return(0);
1438 if(minSR(P1.Z(),P2.Z(),P3.Z())>maxSR(Q1.Z(),Q2.Z(),Q3.Z())) return(0);
1439
1440 p1.SetX(P1.X() - P1.X()); p1.SetY(P1.Y() - P1.Y()); p1.SetZ(P1.Z() - P1.Z());
1441 p2.SetX(P2.X() - P1.X()); p2.SetY(P2.Y() - P1.Y()); p2.SetZ(P2.Z() - P1.Z());
1442 p3.SetX(P3.X() - P1.X()); p3.SetY(P3.Y() - P1.Y()); p3.SetZ(P3.Z() - P1.Z());
1443
1444 q1.SetX(Q1.X() - P1.X()); q1.SetY(Q1.Y() - P1.Y()); q1.SetZ(Q1.Z() - P1.Z());
1445 q2.SetX(Q2.X() - P1.X()); q2.SetY(Q2.Y() - P1.Y()); q2.SetZ(Q2.Z() - P1.Z());
1446 q3.SetX(Q3.X() - P1.X()); q3.SetY(Q3.Y() - P1.Y()); q3.SetZ(Q3.Z() - P1.Z());
1447
1448 e1.SetX(p2.X() - p1.X()); e1.SetY(p2.Y() - p1.Y()); e1.SetZ(p2.Z() - p1.Z());
1449 e2.SetX(p3.X() - p2.X()); e2.SetY(p3.Y() - p2.Y()); e2.SetZ(p3.Z() - p2.Z());
1450 e3.SetX(p1.X() - p3.X()); e3.SetY(p1.Y() - p3.Y()); e3.SetZ(p1.Z() - p3.Z());
1451
1452 f1.SetX(q2.X() - q1.X()); f1.SetY(q2.Y() - q1.Y()); f1.SetZ(q2.Z() - q1.Z());
1453 f2.SetX(q3.X() - q2.X()); f2.SetY(q3.Y() - q2.Y()); f2.SetZ(q3.Z() - q2.Z());
1454 f3.SetX(q1.X() - q3.X()); f3.SetY(q1.Y() - q3.Y()); f3.SetZ(q1.Z() - q3.Z());
1455
1456 n1.Cross(e1, e2); //normal to the first triangle
1457 m1.Cross(f1, f2); //normal to the second triangle
1458
1459 g1.Cross(e1, n1);
1460 g2.Cross(e2, n1);
1461 g3.Cross(e3, n1);
1462 h1.Cross(f1, m1);
1463 h2.Cross(f2, m1);
1464 h3.Cross(f3, m1);
1465
1466 ef11.Cross(e1, f1);
1467 ef12.Cross(e1, f2);
1468 ef13.Cross(e1, f3);
1469 ef21.Cross(e2, f1);
1470 ef22.Cross(e2, f2);
1471 ef23.Cross(e2, f3);
1472 ef31.Cross(e3, f1);
1473 ef32.Cross(e3, f2);
1474 ef33.Cross(e3, f3);
1475
1476 // Now the testing is done
1477
1478 if (!project6(n1, p1, p2, p3, q1, q2, q3)) return 0; //T2 is not higher or lower than T1
1479 if (!project6(m1, p1, p2, p3, q1, q2, q3)) return 0; //T1 is not higher of lower than T2
1480
1481 if (!project6(ef11, p1, p2, p3, q1, q2, q3)) return 0;
1482 if (!project6(ef12, p1, p2, p3, q1, q2, q3)) return 0;
1483 if (!project6(ef13, p1, p2, p3, q1, q2, q3)) return 0;
1484 if (!project6(ef21, p1, p2, p3, q1, q2, q3)) return 0;
1485 if (!project6(ef22, p1, p2, p3, q1, q2, q3)) return 0;
1486 if (!project6(ef23, p1, p2, p3, q1, q2, q3)) return 0;
1487 if (!project6(ef31, p1, p2, p3, q1, q2, q3)) return 0;
1488 if (!project6(ef32, p1, p2, p3, q1, q2, q3)) return 0;
1489 if (!project6(ef33, p1, p2, p3, q1, q2, q3)) return 0;
1490
1491 if (!project6(g1, p1, p2, p3, q1, q2, q3)) return 0; //T2 is outside of T1 in the plane of T1
1492 if (!project6(g2, p1, p2, p3, q1, q2, q3)) return 0; //T2 is outside of T1 in the plane of T1
1493 if (!project6(g3, p1, p2, p3, q1, q2, q3)) return 0; //T2 is outside of T1 in the plane of T1
1494 if (!project6(h1, p1, p2, p3, q1, q2, q3)) return 0; //T1 is outside of T2 in the plane of T2
1495 if (!project6(h2, p1, p2, p3, q1, q2, q3)) return 0; //T1 is outside of T2 in the plane of T2
1496 if (!project6(h3, p1, p2, p3, q1, q2, q3)) return 0; //T1 is outside of T2 in the plane of T2
1497
1498 //Calculation of cosinus angle between two normals
1499 Standard_Real SqModn1=-1.0;
1500 Standard_Real SqModm1=-1.0;
1501 SqModn1=n1.SquareModulus();
55ab6ed6
P
1502 if (SqModn1>SquareMyConfusionPrecision){
1503 SqModm1=m1.SquareModulus();
1504 }
1505 if (SqModm1>SquareMyConfusionPrecision) {
1506 Angle=(n1.Dot(m1))/(sqrt(SqModn1)*sqrt(SqModm1));
7fd59977 1507 }
1508 return 1;
1509}
7fd59977 1510//=======================================================================
1511//function : TestNbPoints
1512//purpose : This function is used by StartingPointsResearch() to control
1513// the number of points found keep the result in conformity (1 or 2 points)
1514// void TestNbPoints(const Standard_Integer TriSurfID,
1515//=======================================================================
7fd59977 1516void TestNbPoints(const Standard_Integer ,
1517 Standard_Integer &NbPoints,
1518 Standard_Integer &NbPointsTotal,
1519 const IntPolyh_StartPoint &Pt1,
1520 const IntPolyh_StartPoint &Pt2,
55ab6ed6
P
1521 IntPolyh_StartPoint &SP1,
1522 IntPolyh_StartPoint &SP2)
1523{
7fd59977 1524 // already checked in TriangleEdgeContact2
1525 // if( (NbPoints==2)&&(Pt1.CheckSameSP(Pt2)) ) NbPoints=1;
1526
1527 if(NbPoints>2) {
55ab6ed6 1528
7fd59977 1529 }
1530 else {
1531 if ( (NbPoints==1)&&(NbPointsTotal==0) ) {
1532 SP1=Pt1;
1533 NbPointsTotal=1;
1534 }
1535 else if ( (NbPoints==1)&&(NbPointsTotal==1) ) {
1536 if(Pt1.CheckSameSP(SP1)!=1) {
1537 SP2=Pt1;
1538 NbPointsTotal=2;
1539 }
1540 }
1541 else if( (NbPoints==1)&&(NbPointsTotal==2) ) {
1542 if ( (SP1.CheckSameSP(Pt1))||(SP2.CheckSameSP(Pt1)) )
1543 NbPointsTotal=2;
1544 else NbPointsTotal=3;
1545 }
1546 else if( (NbPoints==2)&&(NbPointsTotal==0) ) {
1547 SP1=Pt1;
1548 SP2=Pt2;
1549 NbPointsTotal=2;
1550 }
1551 else if( (NbPoints==2)&&(NbPointsTotal==1) ) {//there is also Pt1 != Pt2
1552 if(SP1.CheckSameSP(Pt1)) {
1553 SP2=Pt2;
1554 NbPointsTotal=2;
1555 }
1556 else if (SP1.CheckSameSP(Pt2)) {
1557 SP2=Pt1;
1558 NbPointsTotal=2;
1559 }
1560 else NbPointsTotal=3;///case SP1!=Pt1 && SP1!=Pt2!
1561 }
1562 else if( (NbPoints==2)&&(NbPointsTotal==2) ) {//there is also SP1!=SP2
1563 if( (SP1.CheckSameSP(Pt1))||(SP1.CheckSameSP(Pt2)) ) {
1564 if( (SP2.CheckSameSP(Pt1))||(SP2.CheckSameSP(Pt2)) )
1565 NbPointsTotal=2;
1566 else NbPointsTotal=3;
1567 }
1568 else NbPointsTotal=3;
1569 }
1570 }
7fd59977 1571}
7fd59977 1572//=======================================================================
1573//function : StartingPointsResearch
1574//purpose :
1575//=======================================================================
55ab6ed6
P
1576Standard_Integer IntPolyh_MaillageAffinage::StartingPointsResearch
1577 (const Standard_Integer T1,
1578 const Standard_Integer T2,
1579 IntPolyh_StartPoint &SP1,
1580 IntPolyh_StartPoint &SP2) const
1581{
7fd59977 1582 const IntPolyh_Point &P1=TPoints1[TTriangles1[T1].FirstPoint()];
1583 const IntPolyh_Point &P2=TPoints1[TTriangles1[T1].SecondPoint()];
1584 const IntPolyh_Point &P3=TPoints1[TTriangles1[T1].ThirdPoint()];
1585 const IntPolyh_Point &Q1=TPoints2[TTriangles2[T2].FirstPoint()];
1586 const IntPolyh_Point &Q2=TPoints2[TTriangles2[T2].SecondPoint()];
1587 const IntPolyh_Point &Q3=TPoints2[TTriangles2[T2].ThirdPoint()];
1588
1589
1590 /* The first triangle is (p1,p2,p3). The other is (q1,q2,q3).
1591 The sides are (e1,e2,e3) and (f1,f2,f3).
1592 The normals are n1 and m1*/
1593
1594 const IntPolyh_Point e1=P2-P1;
1595 const IntPolyh_Point e2=P3-P2;
1596 const IntPolyh_Point e3=P1-P3;
1597
1598 const IntPolyh_Point f1=Q2-Q1;
1599 const IntPolyh_Point f2=Q3-Q2;
1600 const IntPolyh_Point f3=Q1-Q3;
1601
1602
1603 IntPolyh_Point nn1,mm1;
1604 nn1.Cross(e1, e2); //normal of the first triangle
1605 mm1.Cross(f1, f2); //normal of the second triangle
1606
1607 Standard_Real nn1modulus, mm1modulus;
1608 nn1modulus=sqrt(nn1.SquareModulus());
1609 mm1modulus=sqrt(mm1.SquareModulus());
1610
1611 //-------------------------------------------------------
1612 ///calculation of intersection points between two triangles
1613 //-------------------------------------------------------
1614 Standard_Integer NbPoints=0;
1615 Standard_Integer NbPointsTotal=0;
1616 IntPolyh_StartPoint Pt1,Pt2;
1617
1618
1619 ///check T1 normal
1620 if(Abs(nn1modulus)<MyConfusionPrecision){//10.0e-20) {
55ab6ed6 1621
7fd59977 1622 }
1623 else {
1624 const IntPolyh_Point n1=nn1.Divide(nn1modulus);
1625 ///T2 edges with T1
1626 if(NbPointsTotal<2) {
1627 NbPoints=TriangleEdgeContact(1,1,P1,P2,P3,e1,e2,e3,Q1,Q2,f1,n1,Pt1,Pt2);
1628 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1629 }
1630
1631 if(NbPointsTotal<2) {
1632 NbPoints=TriangleEdgeContact(1,2,P1,P2,P3,e1,e2,e3,Q2,Q3,f2,n1,Pt1,Pt2);
1633 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1634 }
1635
1636 if(NbPointsTotal<2) {
1637 NbPoints=TriangleEdgeContact(1,3,P1,P2,P3,e1,e2,e3,Q3,Q1,f3,n1,Pt1,Pt2);
1638 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1639 }
1640 }
1641
1642 ///check T2 normal
1643 if(Abs(mm1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1644
7fd59977 1645 }
1646 else {
1647 const IntPolyh_Point m1=mm1.Divide(mm1modulus);
1648 ///T1 edges with T2
1649 if(NbPointsTotal<2) {
1650 NbPoints=TriangleEdgeContact(2,1,Q1,Q2,Q3,f1,f2,f3,P1,P2,e1,m1,Pt1,Pt2);
1651 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1652 }
1653
1654 if(NbPointsTotal<2) {
1655 NbPoints=TriangleEdgeContact(2,2,Q1,Q2,Q3,f1,f2,f3,P2,P3,e2,m1,Pt1,Pt2);
1656 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1657 }
1658
1659 if(NbPointsTotal<2) {
1660 NbPoints=TriangleEdgeContact(2,3,Q1,Q2,Q3,f1,f2,f3,P3,P1,e3,m1,Pt1,Pt2);
1661 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1662 }
1663 }
1664
1665 /* if( (NbPointsTotal >1)&&( Abs(SP1.U1()-SP2.U1())<MyConfusionPrecision)
1666 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) )*/
1667 if( (NbPoints)&&(SP1.CheckSameSP(SP2)) )
1668 NbPointsTotal=1;
1669
1670 SP1.SetCoupleValue(T1,T2);
1671 SP2.SetCoupleValue(T1,T2);
1672 return (NbPointsTotal);
1673}
7fd59977 1674//=======================================================================
1675//function : StartingPointsResearch2
1676//purpose : From two triangles compute intersection points.
1677// If I found more than two intersection points
1678// it means that those triangle are coplanar
1679//=======================================================================
55ab6ed6
P
1680Standard_Integer IntPolyh_MaillageAffinage::StartingPointsResearch2
1681 (const Standard_Integer T1,
1682 const Standard_Integer T2,
1683 IntPolyh_StartPoint &SP1,
1684 IntPolyh_StartPoint &SP2) const
1685{
7fd59977 1686 const IntPolyh_Triangle &Tri1=TTriangles1[T1];
1687 const IntPolyh_Triangle &Tri2=TTriangles2[T2];
1688
1689 const IntPolyh_Point &P1=TPoints1[Tri1.FirstPoint()];
1690 const IntPolyh_Point &P2=TPoints1[Tri1.SecondPoint()];
1691 const IntPolyh_Point &P3=TPoints1[Tri1.ThirdPoint()];
1692 const IntPolyh_Point &Q1=TPoints2[Tri2.FirstPoint()];
1693 const IntPolyh_Point &Q2=TPoints2[Tri2.SecondPoint()];
1694 const IntPolyh_Point &Q3=TPoints2[Tri2.ThirdPoint()];
1695
1696
1697
1698 /* The first triangle is (p1,p2,p3). The other is (q1,q2,q3).
1699 The sides are (e1,e2,e3) and (f1,f2,f3).
1700 The normals are n1 and m1*/
1701
1702 const IntPolyh_Point e1=P2-P1;
1703 const IntPolyh_Point e2=P3-P2;
1704 const IntPolyh_Point e3=P1-P3;
1705
1706 const IntPolyh_Point f1=Q2-Q1;
1707 const IntPolyh_Point f2=Q3-Q2;
1708 const IntPolyh_Point f3=Q1-Q3;
1709
1710
1711 IntPolyh_Point nn1,mm1;
1712 nn1.Cross(e1, e2); //normal to the first triangle
1713 mm1.Cross(f1, f2); //normal to the second triangle
1714
1715 Standard_Real nn1modulus, mm1modulus;
1716 nn1modulus=sqrt(nn1.SquareModulus());
1717 mm1modulus=sqrt(mm1.SquareModulus());
1718
1719 //-------------------------------------------------
1720 ///calculation of intersections points between triangles
1721 //-------------------------------------------------
1722 Standard_Integer NbPoints=0;
1723 Standard_Integer NbPointsTotal=0;
1724
1725
1726 ///check T1 normal
1727 if(Abs(nn1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1728
7fd59977 1729 }
1730 else {
1731 const IntPolyh_Point n1=nn1.Divide(nn1modulus);
1732 ///T2 edges with T1
1733 if(NbPointsTotal<3) {
1734 IntPolyh_StartPoint Pt1,Pt2;
1735 NbPoints=TriangleEdgeContact2(1,1,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q1,Q2,f1,n1,Pt1,Pt2);
1736 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1737 }
1738
1739 if(NbPointsTotal<3) {
1740 IntPolyh_StartPoint Pt1,Pt2;
1741 NbPoints=TriangleEdgeContact2(1,2,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q2,Q3,f2,n1,Pt1,Pt2);
1742 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1743 }
1744
1745 if(NbPointsTotal<3) {
1746 IntPolyh_StartPoint Pt1,Pt2;
1747 NbPoints=TriangleEdgeContact2(1,3,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q3,Q1,f3,n1,Pt1,Pt2);
1748 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1749 }
1750 }
1751
1752 ///check T2 normal
1753 if(Abs(mm1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1754
7fd59977 1755 }
1756 else {
1757 const IntPolyh_Point m1=mm1.Divide(mm1modulus);
1758 ///T1 edges with T2
1759 if(NbPointsTotal<3) {
1760 IntPolyh_StartPoint Pt1,Pt2;
1761 NbPoints=TriangleEdgeContact2(2,1,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P1,P2,e1,m1,Pt1,Pt2);
1762 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1763 }
1764
1765 if(NbPointsTotal<3) {
1766 IntPolyh_StartPoint Pt1,Pt2;
1767 NbPoints=TriangleEdgeContact2(2,2,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P2,P3,e2,m1,Pt1,Pt2);
1768 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1769 }
1770
1771 if(NbPointsTotal<3) {
1772 IntPolyh_StartPoint Pt1,Pt2;
1773 NbPoints=TriangleEdgeContact2(2,3,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P3,P1,e3,m1,Pt1,Pt2);
1774 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1775 }
1776 }
1777 // no need already checked in TestNbPoints
1778 // if( (NbPointsTotal==2)&&(SP1.CheckSameSP(SP2)) ) {
1779 // NbPointsTotal=1;
1780 //SP1.SetCoupleValue(T1,T2);
1781 // }
1782 // else
1783 if(NbPointsTotal==2) {
1784 SP1.SetCoupleValue(T1,T2);
1785 SP2.SetCoupleValue(T1,T2);
1786 }
1787 else if(NbPointsTotal==1)
1788 SP1.SetCoupleValue(T1,T2);
1789 else if(NbPointsTotal==3)
1790 SP1.SetCoupleValue(T1,T2);
1791
1792 return (NbPointsTotal);
1793}
7fd59977 1794//=======================================================================
1795//function : NextStartingPointsResearch
1796//purpose :
1797//=======================================================================
55ab6ed6
P
1798Standard_Integer IntPolyh_MaillageAffinage::NextStartingPointsResearch
1799 (const Standard_Integer T1,
1800 const Standard_Integer T2,
1801 const IntPolyh_StartPoint &SPInit,
1802 IntPolyh_StartPoint &SPNext) const
1803{
7fd59977 1804 Standard_Integer NbPointsTotal=0;
1805 if( (T1<0)||(T2<0) ) NbPointsTotal=0;
1806 else {
1807 const IntPolyh_Point &P1=TPoints1[TTriangles1[T1].FirstPoint()];
1808 const IntPolyh_Point &P2=TPoints1[TTriangles1[T1].SecondPoint()];
1809 const IntPolyh_Point &P3=TPoints1[TTriangles1[T1].ThirdPoint()];
1810 const IntPolyh_Point &Q1=TPoints2[TTriangles2[T2].FirstPoint()];
1811 const IntPolyh_Point &Q2=TPoints2[TTriangles2[T2].SecondPoint()];
1812 const IntPolyh_Point &Q3=TPoints2[TTriangles2[T2].ThirdPoint()];
1813
1814 /* The first triangle is (p1,p2,p3). The other is (q1,q2,q3).
1815 The sides are (e1,e2,e3) and (f1,f2,f3).
1816 The normals are n1 and m1*/
1817
1818 const IntPolyh_Point e1=P2-P1;
1819 const IntPolyh_Point e2=P3-P2;
1820 const IntPolyh_Point e3=P1-P3;
1821
1822 const IntPolyh_Point f1=Q2-Q1;
1823 const IntPolyh_Point f2=Q3-Q2;
1824 const IntPolyh_Point f3=Q1-Q3;
1825
1826 IntPolyh_Point nn1,mm1;
1827 nn1.Cross(e1, e2); //normal to the first triangle
1828 mm1.Cross(f1, f2); //normal to the second triangle
1829
1830 Standard_Real nn1modulus, mm1modulus;
1831 nn1modulus=sqrt(nn1.SquareModulus());
1832 mm1modulus=sqrt(mm1.SquareModulus());
1833
1834 //-------------------------------------------------
1835 ///calculation of intersections points between triangles
1836 //-------------------------------------------------
1837 Standard_Integer NbPoints=0;
1838 IntPolyh_StartPoint SP1,SP2;
1839
1840 ///check T1 normal
1841 if(Abs(nn1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1842
7fd59977 1843 }
1844 else {
1845 const IntPolyh_Point n1=nn1.Divide(nn1modulus);
1846 ///T2 edges with T1
1847 if(NbPointsTotal<3) {
1848 IntPolyh_StartPoint Pt1,Pt2;
1849 NbPoints=TriangleEdgeContact(1,1,P1,P2,P3,e1,e2,e3,Q1,Q2,f1,n1,Pt1,Pt2);
1850 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1851 }
1852
1853 if(NbPointsTotal<3) {
1854 IntPolyh_StartPoint Pt1,Pt2;
1855 NbPoints=TriangleEdgeContact(1,2,P1,P2,P3,e1,e2,e3,Q2,Q3,f2,n1,Pt1,Pt2);
1856 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1857 }
1858
1859 if(NbPointsTotal<3) {
1860 IntPolyh_StartPoint Pt1,Pt2;
1861 NbPoints=TriangleEdgeContact(1,3,P1,P2,P3,e1,e2,e3,Q3,Q1,f3,n1,Pt1,Pt2);
1862 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1863 }
1864 }
1865
1866 ///check T2 normal
1867 if(Abs(mm1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1868
7fd59977 1869 }
1870 else {
1871 const IntPolyh_Point m1=mm1.Divide(mm1modulus);
1872 ///T1 edges with T2
1873 if(NbPointsTotal<3) {
1874 IntPolyh_StartPoint Pt1,Pt2;
1875 NbPoints=TriangleEdgeContact(2,1,Q1,Q2,Q3,f1,f2,f3,P1,P2,e1,m1,Pt1,Pt2);
1876 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1877 }
1878
1879 if(NbPointsTotal<3) {
1880 IntPolyh_StartPoint Pt1,Pt2;
1881 NbPoints=TriangleEdgeContact(2,2,Q1,Q2,Q3,f1,f2,f3,P2,P3,e2,m1,Pt1,Pt2);
1882 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1883 }
1884
1885 if(NbPointsTotal<3) {
1886 IntPolyh_StartPoint Pt1,Pt2;
1887 NbPoints=TriangleEdgeContact(2,3,Q1,Q2,Q3,f1,f2,f3,P3,P1,e3,m1,Pt1,Pt2);
1888 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1889 }
1890 }
1891
1892 if (NbPointsTotal==1) {
1893 /* if( (Abs(SP1.U1()-SPInit.U1())<MyConfusionPrecision)
1894 &&(Abs(SP1.V1()-SPInit.V1())<MyConfusionPrecision) ) */
1895 if(SP1.CheckSameSP(SP2))
1896 NbPointsTotal=0;
1897 else {
55ab6ed6 1898
7fd59977 1899 NbPointsTotal=0;
1900 }
1901 }
1902
1903 // if ( (NbPointsTotal==2)&&( Abs(SP1.U1()-SPInit.U1())<MyConfusionPrecision)
1904 //&&( Abs(SP1.V1()-SPInit.V1())<MyConfusionPrecision) ) {
1905 if( (NbPointsTotal==2)&&(SP1.CheckSameSP(SPInit)) ) {
1906 NbPointsTotal=1;//SP1 et SPInit sont identiques
1907 SPNext=SP2;
1908 }
1909 // if( (NbPointsTotal==2)&&( Abs(SP2.U1()-SPInit.U1())<MyConfusionPrecision)
1910 //&&( Abs(SP2.V1()-SPInit.V1())<MyConfusionPrecision) ) {
1911 if( (NbPointsTotal==2)&&(SP2.CheckSameSP(SPInit)) ) {
1912 NbPointsTotal=1;//SP2 et SPInit sont identiques
1913 SPNext=SP1;
1914 }
1915 if(NbPointsTotal>1) {
55ab6ed6 1916
7fd59977 1917 }
1918 }
1919 SPNext.SetCoupleValue(T1,T2);
1920 return (NbPointsTotal);
1921}
7fd59977 1922//=======================================================================
1923//function : NextStartingPointsResearch2
1924//purpose : from two triangles and an intersection point I
1925// seach the other point (if it exist).
1926// This function is used by StartPointChain
1927//=======================================================================
55ab6ed6
P
1928Standard_Integer IntPolyh_MaillageAffinage::NextStartingPointsResearch2
1929 (const Standard_Integer T1,
1930 const Standard_Integer T2,
1931 const IntPolyh_StartPoint &SPInit,
1932 IntPolyh_StartPoint &SPNext) const
1933{
7fd59977 1934 Standard_Integer NbPointsTotal=0;
1935 Standard_Integer EdgeInit1=SPInit.E1();
1936 Standard_Integer EdgeInit2=SPInit.E2();
1937 if( (T1<0)||(T2<0) ) NbPointsTotal=0;
1938 else {
1939
1940 const IntPolyh_Triangle &Tri1=TTriangles1[T1];
1941 const IntPolyh_Triangle &Tri2=TTriangles2[T2];
1942
1943 const IntPolyh_Point &P1=TPoints1[Tri1.FirstPoint()];
1944 const IntPolyh_Point &P2=TPoints1[Tri1.SecondPoint()];
1945 const IntPolyh_Point &P3=TPoints1[Tri1.ThirdPoint()];
1946 const IntPolyh_Point &Q1=TPoints2[Tri2.FirstPoint()];
1947 const IntPolyh_Point &Q2=TPoints2[Tri2.SecondPoint()];
1948 const IntPolyh_Point &Q3=TPoints2[Tri2.ThirdPoint()];
1949
1950 /* The first triangle is (p1,p2,p3). The other is (q1,q2,q3).
1951 The edges are (e1,e2,e3) and (f1,f2,f3).
1952 The normals are n1 and m1*/
1953
1954 const IntPolyh_Point e1=P2-P1;
1955 const IntPolyh_Point e2=P3-P2;
1956 const IntPolyh_Point e3=P1-P3;
1957
1958 const IntPolyh_Point f1=Q2-Q1;
1959 const IntPolyh_Point f2=Q3-Q2;
1960 const IntPolyh_Point f3=Q1-Q3;
1961
1962 IntPolyh_Point nn1,mm1;
1963 nn1.Cross(e1, e2); //normal to the first triangle
1964 mm1.Cross(f1, f2); //normal to the second triangle
1965
1966 Standard_Real nn1modulus, mm1modulus;
1967 nn1modulus=sqrt(nn1.SquareModulus());
1968 mm1modulus=sqrt(mm1.SquareModulus());
1969
1970 //-------------------------------------------------
1971 ///calculation of intersections points between triangles
1972 //-------------------------------------------------
1973
1974 Standard_Integer NbPoints=0;
1975 IntPolyh_StartPoint SP1,SP2;
1976
1977 ///check T1 normal
1978 if(Abs(nn1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 1979
7fd59977 1980 }
1981 else {
1982 const IntPolyh_Point n1=nn1.Divide(nn1modulus);
1983 ///T2 edges with T1
1984 if( (NbPointsTotal<3)&&(EdgeInit2!=Tri2.FirstEdge()) ) {
1985 IntPolyh_StartPoint Pt1,Pt2;
1986 NbPoints=TriangleEdgeContact2(1,1,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q1,Q2,f1,n1,Pt1,Pt2);
1987 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1988 }
1989
1990 if( (NbPointsTotal<3)&&(EdgeInit2!=Tri2.SecondEdge()) ) {
1991 IntPolyh_StartPoint Pt1,Pt2;
1992 NbPoints=TriangleEdgeContact2(1,2,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q2,Q3,f2,n1,Pt1,Pt2);
1993 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
1994 }
1995
1996 if( (NbPointsTotal<3)&&(EdgeInit2!=Tri2.ThirdEdge()) ) {
1997 IntPolyh_StartPoint Pt1,Pt2;
1998 NbPoints=TriangleEdgeContact2(1,3,Tri1,Tri2,P1,P2,P3,e1,e2,e3,Q3,Q1,f3,n1,Pt1,Pt2);
1999 TestNbPoints(1,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
2000 }
2001 }
2002 ///check T2 normal
2003 if(Abs(mm1modulus)<MyConfusionPrecision) {//10.0e-20){
55ab6ed6 2004
7fd59977 2005 }
2006 else {
2007 const IntPolyh_Point m1=mm1.Divide(mm1modulus);
2008 ///T1 edges with T2
2009 if( (NbPointsTotal<3)&&(EdgeInit1!=Tri1.FirstEdge()) ) {
2010 IntPolyh_StartPoint Pt1,Pt2;
2011 NbPoints=TriangleEdgeContact2(2,1,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P1,P2,e1,m1,Pt1,Pt2);
2012 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
2013 }
2014
2015 if( (NbPointsTotal<3)&&(EdgeInit1!=Tri1.SecondEdge()) ) {
2016 IntPolyh_StartPoint Pt1,Pt2;
2017 NbPoints=TriangleEdgeContact2(2,2,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P2,P3,e2,m1,Pt1,Pt2);
2018 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
2019 }
2020
2021 if( (NbPointsTotal<3)&&(EdgeInit1!=Tri1.ThirdEdge()) ) {
2022 IntPolyh_StartPoint Pt1,Pt2;
2023 NbPoints=TriangleEdgeContact2(2,3,Tri1,Tri2,Q1,Q2,Q3,f1,f2,f3,P3,P1,e3,m1,Pt1,Pt2);
2024 TestNbPoints(2,NbPoints,NbPointsTotal,Pt1,Pt2,SP1,SP2);
2025 }
2026 }
2027
2028 if (NbPointsTotal==1) {
2029 if(SP1.CheckSameSP(SPInit))
2030 NbPointsTotal=0;
2031 else {
2032 SPNext=SP1;
2033 }
2034 }
2035 else if( (NbPointsTotal==2)&&(SP1.CheckSameSP(SPInit)) ) {
2036 NbPointsTotal=1;//SP1 et SPInit sont identiques
2037 SPNext=SP2;
2038 }
2039 else if( (NbPointsTotal==2)&&(SP2.CheckSameSP(SPInit)) ) {
2040 NbPointsTotal=1;//SP2 et SPInit sont identiques
2041 SPNext=SP1;
2042 }
2043
2044 else if(NbPointsTotal>1) {
55ab6ed6 2045
7fd59977 2046 }
2047 }
2048 SPNext.SetCoupleValue(T1,T2);
2049 return (NbPointsTotal);
2050}
7fd59977 2051//=======================================================================
2052//function : CalculPtsInterTriEdgeCoplanaires
2053//purpose :
2054//=======================================================================
7fd59977 2055void CalculPtsInterTriEdgeCoplanaires(const Standard_Integer TriSurfID,
2056 const IntPolyh_Point &NormaleTri,
2057 const IntPolyh_Point &PE1,
2058 const IntPolyh_Point &PE2,
2059 const IntPolyh_Point &Edge,
2060 const IntPolyh_Point &PT1,
2061 const IntPolyh_Point &PT2,
2062 const IntPolyh_Point &Cote,
2063 const Standard_Integer CoteIndex,
2064 IntPolyh_StartPoint &SP1,
2065 IntPolyh_StartPoint &SP2,
55ab6ed6
P
2066 Standard_Integer &NbPoints)
2067{
7fd59977 2068 IntPolyh_Point TestParalleles;
2069 TestParalleles.Cross(Edge,Cote);
2070 if(sqrt(TestParalleles.SquareModulus())<MyConfusionPrecision) {
2071 IntPolyh_Point Per;
2072 Per.Cross(NormaleTri,Cote);
2073 Standard_Real p1p = Per.Dot(PE1);
2074 Standard_Real p2p = Per.Dot(PE2);
2075 Standard_Real p0p = Per.Dot(PT1);
2076 if ( ( (p1p>=p0p)&&(p2p<=p0p) )||( (p1p<=p0p)&&(p2p>=p0p) ) ) {
2077 Standard_Real lambda=(p1p-p0p)/(p1p-p2p);
2078 if (lambda<-MyConfusionPrecision) {
55ab6ed6 2079
7fd59977 2080 }
2081 IntPolyh_Point PIE=PE1+Edge*lambda;
2082 Standard_Real alpha=RealLast();
2083 if(Cote.X()!=0) alpha=(PIE.X()-PT1.X())/Cote.X();
2084 else if (Cote.Y()!=0) alpha=(PIE.Y()-PT1.Y())/Cote.Y();
2085 else if (Cote.Z()!=0) alpha=(PIE.Z()-PT1.Z())/Cote.Z();
2086 else {
55ab6ed6 2087
7fd59977 2088 }
2089 if (alpha<-MyConfusionPrecision) {
55ab6ed6 2090
7fd59977 2091 }
2092 else {
2093 if (NbPoints==0) {
2094 SP1.SetXYZ(PIE.X(),PIE.Y(),PIE.Z());
2095 if (TriSurfID==1) {
2096 SP1.SetUV1(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
2097 SP1.SetUV2(PIE.U(),PIE.V());
2098 SP1.SetEdge1(CoteIndex);
2099 NbPoints++;
2100 }
2101 else if (TriSurfID==2) {
2102 SP1.SetUV1(PIE.U(),PIE.V());
2103 SP1.SetUV2(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
2104 SP1.SetEdge2(CoteIndex);
2105 NbPoints++;
2106 }
2107 else {
55ab6ed6 2108
7fd59977 2109 }
2110 }
2111
2112 else if (NbPoints==1) {
2113 SP2.SetXYZ(PIE.X(),PIE.Y(),PIE.Z());
2114 if (TriSurfID==1) {
2115 SP2.SetUV1(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
2116 SP2.SetUV2(PIE.U(),PIE.V());
2117 SP2.SetEdge1(CoteIndex);
2118 NbPoints++;
2119 }
2120 else if (TriSurfID==2) {
2121 SP2.SetUV1(PIE.U(),PIE.V());
2122 SP2.SetUV2(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
2123 SP2.SetEdge2(CoteIndex);
2124 NbPoints++;
2125 }
2126 else {
55ab6ed6 2127
7fd59977 2128 }
2129 }
2130
2131 else if( (NbPoints>2)||(NbPoints<0) ) {
55ab6ed6 2132
7fd59977 2133 }
2134 }
2135 }
2136 }
2137 else { //Cote et Edge paralleles, avec les rejections precedentes ils sont sur la meme droite
2138 //On projette les points sur cette droite
2139 Standard_Real pe1p= Cote.Dot(PE1);
2140 Standard_Real pe2p= Cote.Dot(PE2);
2141 Standard_Real pt1p= Cote.Dot(PT1);
2142 Standard_Real pt2p= Cote.Dot(PT2);
2143
2144 IntPolyh_Point PEP1,PTP1,PEP2,PTP2;
2145
2146 //PEP1 et PEP2 sont les points de contact entre le triangle et l'edge dans le repere UV de l'edge
2147 //PTP1 et PTP2 sont les correspondants respectifs a PEP1 et PEP2 dans le repere UV du triangle
2148
2149
2150 if (pe1p>pe2p) {
2151 if ( (pt1p<pe1p)&&(pe1p<=pt2p) ) {
2152 PEP1=PE1;
2153 PTP1=PT1+Cote*((pe1p-pt1p)/(pt2p-pt1p));
2154 NbPoints=1;
2155 if (pt1p<=pe2p) {
2156 PEP2=PE2;
2157 PTP2=PT1+Cote*((pe2p-pt1p)/(pt2p-pt1p));
2158 NbPoints=2;
2159 }
2160 else {
2161 PEP2=PE1+Edge*((pt1p-pe1p)/(pe2p-pe1p));
2162 PTP2=PT1;
2163 NbPoints=2;
2164 }
2165 }
2166 else if( (pt2p<pe1p)&&(pe1p<=pt1p) ) {
2167 PEP1=PE1;
2168 PTP1=PT1+Cote*((pt1p-pe1p)/(pt1p-pt2p));
2169 NbPoints=1;
2170 if (pt2p<=pe2p) {
2171 PEP2=PE2;
2172 PTP2=PT1+Cote*((pe2p-pt1p)/(pt2p-pt1p));
2173 NbPoints=2;
2174 }
2175 else {
2176 PEP2=PE1+Edge*((pt2p-pe1p)/(pe2p-pe1p));
2177 PTP2=PT2;
2178 NbPoints=2;
2179 }
2180 }
2181 }
2182
2183 if (pe1p<pe2p) {
2184 if ( (pt1p<pe2p)&&(pe2p<=pt2p) ) {
2185 PEP1=PE2;
2186 PTP1=PT1+Cote*((pe2p-pt1p)/(pt2p-pt1p));
2187 NbPoints=1;
2188 if (pt1p<=pe1p) {
2189 PEP2=PE1;
2190 PTP2=PT1+Cote*((pe1p-pt1p)/(pt2p-pt1p));
2191 NbPoints=2;
2192 }
2193 else {
2194 PEP2=PE2+Edge*((pt1p-pe1p)/(pe2p-pe1p));
2195 PTP2=PT1;
2196 NbPoints=2;
2197 }
2198 }
2199 else if( (pt2p<pe2p)&&(pe2p<=pt1p) ) {
2200 PEP1=PE2;
2201 PTP1=PT1+Cote*((pt1p-pe2p)/(pt1p-pt2p));
2202 NbPoints=1;
2203 if (pt2p<=pe1p) {
2204 PEP2=PE1;
2205 PTP2=PT1+Cote*((pe1p-pt1p)/(pt2p-pt1p));
2206 NbPoints=2;
2207 }
2208 else {
2209 PEP2=PE1+Edge*((pt2p-pe1p)/(pe2p-pe1p));
2210 PTP2=PT2;
2211 NbPoints=2;
2212 }
2213 }
2214 }
2215
2216 if (NbPoints!=0) {
35958a58 2217 if (Abs(PEP1.U()-PEP2.U())<MyConfusionPrecision
7fd59977 2218 &&(Abs(PEP1.V()-PEP2.V())<MyConfusionPrecision) ) NbPoints=1;
2219
2220 SP1.SetXYZ(PEP1.X(),PEP1.Y(),PEP1.Z());
2221 if (TriSurfID==1) {
2222 SP1.SetUV1(PTP1.U(),PTP1.V());
2223 SP1.SetUV2(PEP1.U(),PEP1.V());
2224 SP1.SetEdge1(CoteIndex);
2225 }
2226 if (TriSurfID==2) {
2227 SP1.SetUV1(PEP1.U(),PTP1.V());
2228 SP1.SetUV2(PTP1.U(),PEP1.V());
2229 SP1.SetEdge2(CoteIndex);
2230 }
2231
2232 if (NbPoints==2) {
2233 SP2.SetXYZ(PEP2.X(),PEP2.Y(),PEP2.Z());
2234 if (TriSurfID==1) {
2235 SP2.SetUV1(PTP2.U(),PTP2.V());
2236 SP2.SetUV2(PEP2.U(),PEP2.V());
2237 SP2.SetEdge1(CoteIndex);
2238 }
2239 if (TriSurfID==2) {
2240 SP2.SetUV1(PEP2.U(),PTP2.V());
2241 SP2.SetUV2(PTP2.U(),PEP2.V());
2242 SP2.SetEdge2(CoteIndex);
2243 }
2244 }
2245 }
2246 }
2247}
7fd59977 2248//=======================================================================
2249//function : CalculPtsInterTriEdgeCoplanaires2
2250//purpose :
2251//=======================================================================
7fd59977 2252void CalculPtsInterTriEdgeCoplanaires2(const Standard_Integer TriSurfID,
2253 const IntPolyh_Point &NormaleTri,
2254 const IntPolyh_Triangle &Tri1,
2255 const IntPolyh_Triangle &Tri2,
2256 const IntPolyh_Point &PE1,
2257 const IntPolyh_Point &PE2,
2258 const IntPolyh_Point &Edge,
2259 const Standard_Integer EdgeIndex,
2260 const IntPolyh_Point &PT1,
2261 const IntPolyh_Point &PT2,
2262 const IntPolyh_Point &Cote,
2263 const Standard_Integer CoteIndex,
2264 IntPolyh_StartPoint &SP1,
2265 IntPolyh_StartPoint &SP2,
55ab6ed6
P
2266 Standard_Integer &NbPoints)
2267 {
7fd59977 2268 IntPolyh_Point TestParalleles;
2269 TestParalleles.Cross(Edge,Cote);
2270
2271 if(sqrt(TestParalleles.SquareModulus())>MyConfusionPrecision) {
2272 ///Edge and side are not parallel
2273 IntPolyh_Point Per;
2274 Per.Cross(NormaleTri,Cote);
2275 Standard_Real p1p = Per.Dot(PE1);
2276 Standard_Real p2p = Per.Dot(PE2);
2277 Standard_Real p0p = Per.Dot(PT1);
2278 ///The edge are PT1 are projected on the perpendicular of the side in the plane of the triangle
2279 if ( ( (p1p>=p0p)&&(p0p>=p2p) )||( (p1p<=p0p)&&(p0p<=p2p) ) ) {
2280 Standard_Real lambda=(p1p-p0p)/(p1p-p2p);
2281 if (lambda<-MyConfusionPrecision) {
55ab6ed6 2282
7fd59977 2283 }
2284 IntPolyh_Point PIE;
2285 if (Abs(lambda)<MyConfusionPrecision)//lambda=0
2286 PIE=PE1;
2287 else if (Abs(lambda)>1.0-MyConfusionPrecision)//lambda=1
2288 PIE=PE2;
2289 else
2290 PIE=PE1+Edge*lambda;
2291
2292 Standard_Real alpha=RealLast();
2293 if(Cote.X()!=0) alpha=(PIE.X()-PT1.X())/Cote.X();
2294 else if (Cote.Y()!=0) alpha=(PIE.Y()-PT1.Y())/Cote.Y();
2295 else if (Cote.Z()!=0) alpha=(PIE.Z()-PT1.Z())/Cote.Z();
2296 else {
55ab6ed6 2297
7fd59977 2298 }
2299
2300 if (alpha<-MyConfusionPrecision) {
55ab6ed6 2301
7fd59977 2302 }
2303 else {
2304 if (NbPoints==0) {
2305 SP1.SetXYZ(PIE.X(),PIE.Y(),PIE.Z());
2306 if (TriSurfID==1) {
2307 if(Abs(alpha)<MyConfusionPrecision) {//alpha=0
2308 SP1.SetUV1(PT1.U(),PT1.V());
2309 SP1.SetUV1(PIE.U(),PIE.V());
2310 SP1.SetEdge1(-1);
2311 }
2312 if(Abs(alpha)>1.0-MyConfusionPrecision) {//alpha=1
2313 SP1.SetUV1(PT2.U(),PT2.V());
2314 SP1.SetUV1(PIE.U(),PIE.V());
2315 SP1.SetEdge1(-1);
2316 }
2317 else {
2318 SP1.SetUV1(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
2319 SP1.SetUV2(PIE.U(),PIE.V());
2320 SP1.SetEdge1(Tri1.GetEdgeNumber(CoteIndex));
2321 if (Tri1.GetEdgeOrientation(CoteIndex)>0) SP1.SetLambda1(alpha);
2322 else SP1.SetLambda1(1.0-alpha);
2323 }
2324 NbPoints++;
2325 }
2326 else if (TriSurfID==2) {
2327 if(Abs(alpha)<MyConfusionPrecision) {//alpha=0
2328 SP1.SetUV1(PT1.U(),PT1.V());
2329 SP1.SetUV1(PIE.U(),PIE.V());
2330 SP1.SetEdge2(-1);
2331 }
2332 if(Abs(alpha)>1.0-MyConfusionPrecision) {//alpha=1
2333 SP1.SetUV1(PT2.U(),PT2.V());
2334 SP1.SetUV1(PIE.U(),PIE.V());
2335 SP1.SetEdge2(-1);
2336 }
2337 else {
2338 SP1.SetUV1(PIE.U(),PIE.V());
2339 SP1.SetUV2(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
2340 SP1.SetEdge2(Tri2.GetEdgeNumber(CoteIndex));
2341 if (Tri2.GetEdgeOrientation(CoteIndex)>0) SP1.SetLambda2(alpha);
2342 else SP1.SetLambda2(1.0-alpha);
2343 }
2344 NbPoints++;
2345 }
2346 else {
55ab6ed6 2347
7fd59977 2348 }
2349 }
2350
2351 else if (NbPoints==1) {
2352 SP2.SetXYZ(PIE.X(),PIE.Y(),PIE.Z());
2353 if (TriSurfID==1) {
2354 if(Abs(alpha)<MyConfusionPrecision) {//alpha=0
2355 SP2.SetUV1(PT1.U(),PT1.V());
2356 SP2.SetUV1(PIE.U(),PIE.V());
2357 SP2.SetEdge1(-1);
2358 }
2359 if(Abs(alpha)>1.0-MyConfusionPrecision) {//alpha=1
2360 SP2.SetUV1(PT2.U(),PT2.V());
2361 SP2.SetUV1(PIE.U(),PIE.V());
2362 SP2.SetEdge1(-1);
2363 }
2364 else {
2365 SP2.SetUV1(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
2366 SP2.SetUV2(PIE.U(),PIE.V());
2367 SP2.SetEdge1(Tri1.GetEdgeNumber(CoteIndex));
2368 if (Tri1.GetEdgeOrientation(CoteIndex)>0) SP2.SetLambda1(alpha);
2369 else SP2.SetLambda1(1.0-alpha);
2370 }
2371 NbPoints++;
2372 }
2373 else if (TriSurfID==2) {
2374 if(Abs(alpha)<MyConfusionPrecision) {//alpha=0
2375 SP2.SetUV1(PT1.U(),PT1.V());
2376 SP2.SetUV1(PIE.U(),PIE.V());
2377 SP2.SetEdge2(-1);
2378 }
2379 if(Abs(alpha)>1.0-MyConfusionPrecision) {//alpha=1
2380 SP2.SetUV1(PT2.U(),PT2.V());
2381 SP2.SetUV1(PIE.U(),PIE.V());
2382 SP2.SetEdge2(-1);
2383 }
2384 else {
2385 SP2.SetUV1(PIE.U(),PIE.V());
2386 SP2.SetUV2(PT1.U()+Cote.U()*alpha,PT1.V()+Cote.V()*alpha);
2387 SP2.SetEdge2(Tri2.GetEdgeNumber(CoteIndex));
2388 if (Tri1.GetEdgeOrientation(CoteIndex)>0) SP2.SetLambda2(alpha);
2389 else SP2.SetLambda2(1.0-alpha);
2390 }
2391 NbPoints++;
2392 }
2393 else {
55ab6ed6 2394
7fd59977 2395 }
2396 }
2397
2398 else if( (NbPoints>2)||(NbPoints<0) ) {
55ab6ed6 2399
7fd59977 2400 }
2401 }
2402 }
2403 }
55ab6ed6
P
2404 else {
2405 //Side and Edge are parallel, with previous
2406 //rejections they are at the same side
7fd59977 2407 //The points are projected on that side
2408 Standard_Real pe1p= Cote.Dot(PE1);
2409 Standard_Real pe2p= Cote.Dot(PE2);
2410 Standard_Real pt1p= Cote.Dot(PT1);
2411 Standard_Real pt2p= Cote.Dot(PT2);
7fd59977 2412 Standard_Real lambda1 =0.,lambda2 =0.,alpha1 =0.,alpha2 =0.;
7fd59977 2413 IntPolyh_Point PEP1,PTP1,PEP2,PTP2;
2414
7fd59977 2415 if (pe1p>pe2p) {
2416 if ( (pt1p<pe1p)&&(pe1p<=pt2p) ) {
2417 lambda1=0.0;
2418 PEP1=PE1;
2419 alpha1=((pe1p-pt1p)/(pt2p-pt1p));
2420 PTP1=PT1+Cote*alpha1;
2421 NbPoints=1;
2422 if (pt1p<=pe2p) {
2423 lambda2=1.0;
2424 PEP2=PE2;
2425 alpha2=((pe2p-pt1p)/(pt2p-pt1p));
2426 PTP2=PT1+Cote*alpha2;
2427 NbPoints=2;
2428 }
2429 else {
2430 lambda2=((pt1p-pe1p)/(pe2p-pe1p));
2431 PEP2=PE1+Edge*lambda2;
2432 alpha2=0.0;
2433 PTP2=PT1;
2434 NbPoints=2;
2435 }
2436 }
2437 else if( (pt2p<pe1p)&&(pe1p<=pt1p) ) {
2438 lambda1=0.0;
2439 PEP1=PE1;
2440 alpha1=((pt1p-pe1p)/(pt1p-pt2p));
2441 PTP1=PT1+Cote*alpha1;
2442 NbPoints=1;
2443 if (pt2p<=pe2p) {
2444 lambda2=1.0;
2445 PEP2=PE2;
2446 alpha2=((pe2p-pt1p)/(pt2p-pt1p));
2447 PTP2=PT1+Cote*alpha2;
2448 NbPoints=2;
2449 }
2450 else {
2451 lambda2=((pt2p-pe1p)/(pe2p-pe1p));
2452 PEP2=PE1+Edge*lambda2;
2453 alpha2=1.0;
2454 PTP2=PT2;
2455 NbPoints=2;
2456 }
2457 }
2458 }
2459
2460 if (pe1p<pe2p) {
2461 if ( (pt1p<pe2p)&&(pe2p<=pt2p) ) {
2462 lambda1=1.0;
2463 PEP1=PE2;
2464 alpha1=((pe2p-pt1p)/(pt2p-pt1p));
2465 PTP1=PT1+Cote*alpha1;
2466 NbPoints=1;
2467 if (pt1p<=pe1p) {
2468 lambda2=0.0;
2469 PEP2=PE1;
2470 alpha2=((pe1p-pt1p)/(pt2p-pt1p));
2471 PTP2=PT1+Cote*alpha2;
2472 NbPoints=2;
2473 }
2474 else {
2475 lambda2=((pt1p-pe1p)/(pe2p-pe1p));
2476 PEP2=PE2+Edge*lambda2;
2477 alpha2=0.0;
2478 PTP2=PT1;
2479 NbPoints=2;
2480 }
2481 }
2482 else if( (pt2p<pe2p)&&(pe2p<=pt1p) ) {
2483 lambda1=1.0;
2484 PEP1=PE2;
2485 alpha1=((pt1p-pe2p)/(pt1p-pt2p));
2486 PTP1=PT1+Cote*alpha1;
2487 NbPoints=1;
2488 if (pt2p<=pe1p) {
2489 lambda2=0.0;
2490 PEP2=PE1;
2491 alpha2=((pe1p-pt1p)/(pt2p-pt1p));
2492 PTP2=PT1+Cote*alpha2;
2493 NbPoints=2;
2494 }
2495 else {
2496 lambda2=((pt2p-pe1p)/(pe2p-pe1p));
2497 PEP2=PE1+Edge*lambda2;
2498 alpha2=1.0;
2499 PTP2=PT2;
2500 NbPoints=2;
2501 }
2502 }
2503 }
2504
2505 if (NbPoints!=0) {
2506 SP1.SetXYZ(PEP1.X(),PEP1.Y(),PEP1.Z());
2507 if (TriSurfID==1) {///cote appartient a Tri1
2508 SP1.SetUV1(PTP1.U(),PTP1.V());
2509 SP1.SetUV2(PEP1.U(),PEP1.V());
2510 SP1.SetEdge1(Tri1.GetEdgeNumber(CoteIndex));
2511
2512 if(Tri1.GetEdgeOrientation(CoteIndex)>0) SP1.SetLambda1(alpha1);
2513 else SP1.SetLambda1(1.0-alpha1);
2514
2515 if(Tri2.GetEdgeOrientation(EdgeIndex)>0) SP1.SetLambda2(lambda1);
2516 else SP1.SetLambda2(1.0-lambda1);
2517 }
2518 if (TriSurfID==2) {///cote appartient a Tri2
2519 SP1.SetUV1(PEP1.U(),PTP1.V());
2520 SP1.SetUV2(PTP1.U(),PEP1.V());
2521 SP1.SetEdge2(Tri2.GetEdgeNumber(CoteIndex));
2522
2523 if(Tri2.GetEdgeOrientation(CoteIndex)>0) SP1.SetLambda1(alpha1);
2524 else SP1.SetLambda1(1.0-alpha1);
2525
2526 if(Tri1.GetEdgeOrientation(EdgeIndex)>0) SP1.SetLambda2(lambda1);
2527 else SP1.SetLambda2(1.0-lambda1);
2528 }
2529
2530 //It is checked if PEP1!=PEP2
2531 if ( (NbPoints==2)&&(Abs(PEP1.U()-PEP2.U())<MyConfusionPrecision)
2532 &&(Abs(PEP1.V()-PEP2.V())<MyConfusionPrecision) ) NbPoints=1;
2533 if (NbPoints==2) {
2534 SP2.SetXYZ(PEP2.X(),PEP2.Y(),PEP2.Z());
2535 if (TriSurfID==1) {
2536 SP2.SetUV1(PTP2.U(),PTP2.V());
2537 SP2.SetUV2(PEP2.U(),PEP2.V());
2538 SP2.SetEdge1(Tri1.GetEdgeNumber(CoteIndex));
2539
2540 if(Tri1.GetEdgeOrientation(CoteIndex)>0) SP2.SetLambda1(alpha1);
2541 else SP2.SetLambda1(1.0-alpha1);
2542
2543 if(Tri2.GetEdgeOrientation(EdgeIndex)>0) SP2.SetLambda2(lambda1);
2544 else SP2.SetLambda2(1.0-lambda1);
2545 }
2546 if (TriSurfID==2) {
2547 SP2.SetUV1(PEP2.U(),PTP2.V());
2548 SP2.SetUV2(PTP2.U(),PEP2.V());
2549 SP2.SetEdge2(Tri2.GetEdgeNumber(CoteIndex));
2550
2551 if(Tri1.GetEdgeOrientation(CoteIndex)>0) SP2.SetLambda1(alpha1);
2552 else SP2.SetLambda1(1.0-alpha1);
2553
2554 if(Tri2.GetEdgeOrientation(EdgeIndex)>0) SP2.SetLambda2(lambda1);
2555 else SP2.SetLambda2(1.0-lambda1);
2556 }
2557 }
2558 }
2559 }
2560 //Filter if the point is placed on top, the edge is set to -1
2561 if (NbPoints>0) {
2562 if(Abs(SP1.Lambda1())<MyConfusionPrecision)
2563 SP1.SetEdge1(-1);
2564 if(Abs(SP1.Lambda1()-1)<MyConfusionPrecision)
2565 SP1.SetEdge1(-1);
2566 if(Abs(SP1.Lambda2())<MyConfusionPrecision)
2567 SP1.SetEdge2(-1);
2568 if(Abs(SP1.Lambda2()-1)<MyConfusionPrecision)
2569 SP1.SetEdge2(-1);
2570 }
2571 if (NbPoints==2) {
2572 if(Abs(SP2.Lambda1())<MyConfusionPrecision)
2573 SP2.SetEdge1(-1);
2574 if(Abs(SP2.Lambda1()-1)<MyConfusionPrecision)
2575 SP2.SetEdge1(-1);
2576 if(Abs(SP2.Lambda2())<MyConfusionPrecision)
2577 SP2.SetEdge2(-1);
2578 if(Abs(SP2.Lambda2()-1)<MyConfusionPrecision)
2579 SP2.SetEdge2(-1);
2580 }
2581}
7fd59977 2582//=======================================================================
2583//function : TriangleEdgeContact
2584//purpose :
2585//=======================================================================
55ab6ed6
P
2586Standard_Integer IntPolyh_MaillageAffinage::TriangleEdgeContact
2587 (const Standard_Integer TriSurfID,
2588 const Standard_Integer EdgeIndex,
2589 const IntPolyh_Point &PT1,
2590 const IntPolyh_Point &PT2,
2591 const IntPolyh_Point &PT3,
2592 const IntPolyh_Point &Cote12,
2593 const IntPolyh_Point &Cote23,
2594 const IntPolyh_Point &Cote31,
2595 const IntPolyh_Point &PE1,const IntPolyh_Point &PE2,
2596 const IntPolyh_Point &Edge,
2597 const IntPolyh_Point &NormaleT,
2598 IntPolyh_StartPoint &SP1,IntPolyh_StartPoint &SP2) const
2599{
7fd59977 2600
7fd59977 2601 Standard_Real lambda =0.;
2602 Standard_Real alpha =0.;
2603 Standard_Real beta =0.;
55ab6ed6 2604
7fd59977 2605
2606 //The edge, on which the point is located, is known.
2607 if (TriSurfID==1) {
2608 SP1.SetEdge2(EdgeIndex);
2609 SP2.SetEdge2(EdgeIndex);
2610 }
2611 else if (TriSurfID==2) {
2612 SP1.SetEdge1(EdgeIndex);
2613 SP2.SetEdge1(EdgeIndex);
2614 }
2615 else {
55ab6ed6 2616
7fd59977 2617 }
2618
2619/**The edge is projected on the normal of the triangle if yes
2620 --> free intersection (point I)--> start point is found*/
2621 Standard_Integer NbPoints=0;
2622
2623 if(NormaleT.SquareModulus()==0) {
55ab6ed6 2624
7fd59977 2625 }
2626 else if( (Cote12.SquareModulus()==0)
2627 ||(Cote23.SquareModulus()==0)
2628 ||(Cote31.SquareModulus()==0) ) {
55ab6ed6 2629
7fd59977 2630 }
2631 else if(Edge.SquareModulus()==0) {
55ab6ed6 2632
7fd59977 2633 }
2634 else {
2635 Standard_Real pe1 = NormaleT.Dot(PE1);
2636 Standard_Real pe2 = NormaleT.Dot(PE2);
2637 Standard_Real pt1 = NormaleT.Dot(PT1);
2638
2639 // PE1I = lambda.Edge
2640
2641 if( (Abs(pe1-pe2)<MyConfusionPrecision)&&(Abs(pe1-pt1)<MyConfusionPrecision) ) {
2642 //edge and triangle are coplanar (two contact points maximum)
55ab6ed6 2643
7fd59977 2644 //The tops of the triangle are projected on the perpendicular of the edge
2645
2646 IntPolyh_Point PerpEdge;
2647 PerpEdge.Cross(NormaleT,Edge);
2648 Standard_Real pp1 = PerpEdge.Dot(PT1);
2649 Standard_Real pp2 = PerpEdge.Dot(PT2);
2650 Standard_Real pp3 = PerpEdge.Dot(PT3);
2651 Standard_Real ppe1 = PerpEdge.Dot(PE1);
2652
2653 if ( ( (pp1>ppe1)&&(pp2<=ppe1)&&(pp3<=ppe1) ) || ( (pp1<ppe1)&&(pp2>=ppe1)&&(pp3>=ppe1) ) ){
2654 //there are two sides (commun top PT1) that can cut the edge
2655
2656 //first side
55ab6ed6
P
2657 CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,
2658 PE1,PE2,Edge,PT1,PT2,
2659 Cote12,1,SP1,SP2,NbPoints);
7fd59977 2660
2661 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2662 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2663
2664 //second side
55ab6ed6
P
2665 if (NbPoints<2) {
2666 CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,
2667 PE1,PE2,Edge,PT3,PT1,
2668 Cote31,3,SP1,SP2,NbPoints);
2669 }
7fd59977 2670 }
2671
2672 if ( (NbPoints>1)&&(Abs(SP1.U1()-SP2.U1())<MyConfusionPrecision)
2673 &&(Abs(SP1.V2()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2674 if (NbPoints>=2) return(NbPoints);
2675
2676 else if ( ( ( (pp2>ppe1)&&(pp1<=ppe1)&&(pp3<=ppe1) ) || ( (pp2<ppe1)&&(pp1>=ppe1)&&(pp3>=ppe1) ) )
2677 && (NbPoints<2) ) {
2678 //there are two sides (common top PT2) that can cut the edge
2679
2680 //first side
55ab6ed6
P
2681 CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,
2682 PE1,PE2,Edge,PT1,PT2,
2683 Cote12,1,SP1,SP2,NbPoints);
7fd59977 2684
2685 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2686 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2687
2688 //second side
55ab6ed6
P
2689 if(NbPoints<2) CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,
2690 PE1,PE2,Edge,PT2,PT3,
2691 Cote23,2,SP1,SP2,NbPoints);
7fd59977 2692 }
2693 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2694 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2695 if (NbPoints>=2) return(NbPoints);
2696 //= remove
2697 else if ( ( (pp3>ppe1)&&(pp1<=ppe1)&&(pp2<=ppe1) ) || ( (pp3<ppe1)&&(pp1>=ppe1)&&(pp2>=ppe1) )
2698 && (NbPoints<2) ) {
2699 //there are two sides (common top PT3) that can cut the edge
2700
2701 //first side
55ab6ed6
P
2702 CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,
2703 PE1,PE2,Edge,PT3,PT1,Cote31,
2704 3,SP1,SP2,NbPoints);
7fd59977 2705
2706 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2707 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2708
2709 //second side
55ab6ed6
P
2710 if (NbPoints<2) CalculPtsInterTriEdgeCoplanaires(TriSurfID,NormaleT,
2711 PE1,PE2,Edge,PT2,PT3,
2712 Cote23,2,SP1,SP2,NbPoints);
7fd59977 2713 }
2714 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2715 &&(Abs(SP2.V1()-SP1.V1())<MyConfusionPrecision) ) NbPoints=1;
2716 if (NbPoints>=2) return(NbPoints);
2717 }
2718
2719
2720 //------------------------------------------------------
2721 // edge and triangle NON COPLANAR (a contact point)
2722 //------------------------------------------------------
2723 else if( ( (pe1>=pt1)&&(pe2<=pt1) ) || ( (pe1<=pt1)&&(pe2>=pt1) ) ) {
2724 lambda=(pe1-pt1)/(pe1-pe2);
2725 IntPolyh_Point PI;
2726 if (lambda<-MyConfusionPrecision) {
55ab6ed6 2727
7fd59977 2728 }
2729 else if (Abs(lambda)<MyConfusionPrecision) {//lambda==0
2730 PI=PE1;
2731 if(TriSurfID==1) SP1.SetEdge2(0);
2732 else SP1.SetEdge1(0);
2733 }
2734 else if (Abs(lambda-1.0)<MyConfusionPrecision) {//lambda==1
2735 PI=PE2;
2736 if(TriSurfID==1) SP1.SetEdge2(0);
2737 else SP1.SetEdge1(0);
2738 }
2739 else {
2740 PI=PE1+Edge*lambda;
2741 if(TriSurfID==1) SP1.SetEdge2(EdgeIndex);
2742 else SP1.SetEdge1(EdgeIndex);
2743 }
55ab6ed6 2744
7fd59977 2745 if(Abs(Cote23.X())>MyConfusionPrecision) {
2746 Standard_Real D=(Cote12.Y()-Cote12.X()*Cote23.Y()/Cote23.X());
2747 if(D!=0) alpha = (PI.Y()-PT1.Y()-(PI.X()-PT1.X())*Cote23.Y()/Cote23.X())/D;
2748 else {
55ab6ed6 2749
7fd59977 2750 }
2751 if ((alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision))) return(0);
2752 else beta = (PI.X()-PT1.X()-alpha*Cote12.X())/Cote23.X();
2753 }
2754
2755 else if (Abs(Cote12.X())>MyConfusionPrecision) { //On a Cote23.X()==0
2756 alpha = (PI.X()-PT1.X())/Cote12.X();
2757
2758 if ((alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision))) return(0);
2759
2760 else if (Abs(Cote23.Y())>MyConfusionPrecision) beta = (PI.Y()-PT1.Y()-alpha*Cote12.Y())/Cote23.Y();
2761 else if (Abs(Cote23.Z())>MyConfusionPrecision) beta = (PI.Z()-PT1.Z()-alpha*Cote12.Z())/Cote23.Z();
2762 else {
55ab6ed6 2763
7fd59977 2764 }
2765 }
2766
55ab6ed6
P
2767 else if (Abs(Cote23.Y())>MyConfusionPrecision) {
2768 //On a Cote23.X()==0 et Cote12.X()==0 ==> equation can't be used
7fd59977 2769 Standard_Real D=(Cote12.Z()-Cote12.Y()*Cote23.Z()/Cote23.Y());
2770
2771 if(D!=0) alpha = (PI.Z()-PT1.Z()-(PI.Y()-PT1.Y())*Cote23.Z()/Cote23.Y())/D;
2772 else{
55ab6ed6 2773
7fd59977 2774 }
2775
2776 if ( (alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision)) ) return(0);
2777 else beta = (PI.Y()-PT1.Y()-alpha*Cote12.Y())/Cote23.Y();
2778 }
2779
55ab6ed6
P
2780 else if (Abs(Cote12.Y())>MyConfusionPrecision) {
2781 //On a Cote23.X()==0, Cote12.X()==0 et Cote23.Y()==0
7fd59977 2782 alpha = (PI.Y()-PT1.Y())/Cote12.Y();
2783
2784 if ((Abs(alpha)<MyConfusionPrecision)||(Abs(alpha-1.0)<MyConfusionPrecision)) return(0);
2785
2786 else if (Abs(Cote23.Z())>MyConfusionPrecision) beta = (PI.Z()-PT1.Z()-alpha*Cote12.Z())/Cote23.Z();
2787
2788 else {
55ab6ed6 2789
7fd59977 2790 }
2791 }
2792
2793 else { //two equations of three can't be used
55ab6ed6 2794
7fd59977 2795 alpha=RealLast();
2796 beta=RealLast();
2797 }
2798
2799 if( (beta<-MyConfusionPrecision)||(beta>(alpha+MyConfusionPrecision)) ) return(0);
2800 else {
2801 SP1.SetXYZ(PI.X(),PI.Y(),PI.Z());
2802
2803 if (TriSurfID==1) {
2804 SP1.SetUV2(PI.U(),PI.V());
2805 SP1.SetUV1(PT1.U()+Cote12.U()*alpha+Cote23.U()*beta, PT1.V()+Cote12.V()*alpha+Cote23.V()*beta);
2806 NbPoints++;
2807 if (beta<MyConfusionPrecision) {//beta==0 && alpha
2808 SP1.SetEdge1(1);
2809 SP1.SetLambda1(alpha);
2810 }
2811 if (Abs(beta-alpha)<MyConfusionPrecision) {//beta==alpha
2812 SP1.SetEdge1(3);
2813 SP1.SetLambda1(1.0-alpha);
2814 }
2815 if (Abs(alpha-1)<MyConfusionPrecision)//alpha==1
2816 SP1.SetEdge1(2);
2817 if (alpha<MyConfusionPrecision) {//alpha=0 --> beta==0
2818 SP1.SetXYZ(PT1.X(),PT1.Y(),PT1.Z());
2819 SP1.SetUV1(PT1.U(),PT1.V());
2820 SP1.SetEdge1(0);
2821 }
2822 if ( (beta<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==0 alpha==1
2823 SP1.SetXYZ(PT2.X(),PT2.Y(),PT2.Z());
2824 SP1.SetUV1(PT2.U(),PT2.V());
2825 SP1.SetEdge1(0);
2826 }
2827 if ( (Abs(beta-1)<MyConfusionPrecision)||(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==1 alpha==1
2828 SP1.SetXYZ(PT3.X(),PT3.Y(),PT3.Z());
2829 SP1.SetUV1(PT3.U(),PT3.V());
2830 SP1.SetEdge1(0);
2831 }
2832 }
2833 else if(TriSurfID==2) {
2834 SP1.SetUV1(PI.U(),PI.V());
2835 SP1.SetUV2(PT1.U()+Cote12.U()*alpha+Cote23.U()*beta, PT1.V()+Cote12.V()*alpha+Cote23.V()*beta);
2836 NbPoints++;
2837 if (beta<MyConfusionPrecision) { //beta==0
2838 SP1.SetEdge2(1);
2839 }
2840 if (Abs(beta-alpha)<MyConfusionPrecision)//beta==alpha
2841 SP1.SetEdge2(3);
2842 if (Abs(alpha-1)<MyConfusionPrecision)//alpha==1
2843 SP1.SetEdge2(2);
2844 if (alpha<MyConfusionPrecision) {//alpha=0 --> beta==0
2845 SP1.SetXYZ(PT1.X(),PT1.Y(),PT1.Z());
2846 SP1.SetUV2(PT1.U(),PT1.V());
2847 SP1.SetEdge2(0);
2848 }
2849 if ( (beta<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==0 alpha==1
2850 SP1.SetXYZ(PT2.X(),PT2.Y(),PT2.Z());
2851 SP1.SetUV2(PT2.U(),PT2.V());
2852 SP1.SetEdge2(0);
2853 }
2854 if ( (Abs(beta-1)<MyConfusionPrecision)||(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==1 alpha==1
2855 SP1.SetXYZ(PT3.X(),PT3.Y(),PT3.Z());
2856 SP1.SetUV2(PT3.U(),PT3.V());
2857 SP1.SetEdge2(0);
2858 }
2859 }
2860 else{
55ab6ed6 2861
7fd59977 2862 }
2863 }
2864 }
2865 else return 0;
2866 }
2867 return (NbPoints);
2868}
2869
2870//=======================================================================
2871//function : TriangleEdgeContact2
2872//purpose :
2873//=======================================================================
55ab6ed6
P
2874Standard_Integer IntPolyh_MaillageAffinage::TriangleEdgeContact2
2875 (const Standard_Integer TriSurfID,
2876 const Standard_Integer EdgeIndex,
2877 const IntPolyh_Triangle &Tri1,
2878 const IntPolyh_Triangle &Tri2,
2879 const IntPolyh_Point &PT1,
2880 const IntPolyh_Point &PT2,
2881 const IntPolyh_Point &PT3,
2882 const IntPolyh_Point &Cote12,
2883 const IntPolyh_Point &Cote23,
2884 const IntPolyh_Point &Cote31,
2885 const IntPolyh_Point &PE1,const IntPolyh_Point &PE2,
2886 const IntPolyh_Point &Edge,
2887 const IntPolyh_Point &NormaleT,
2888 IntPolyh_StartPoint &SP1,IntPolyh_StartPoint &SP2) const
2889{
7fd59977 2890
7fd59977 2891 Standard_Real lambda =0., alpha =0., beta =0.;
7fd59977 2892
2893 //One of edges on which the point is located is known
2894 if (TriSurfID==1) {
2895 SP1.SetEdge2(Tri2.GetEdgeNumber(EdgeIndex));
2896 SP2.SetEdge2(Tri2.GetEdgeNumber(EdgeIndex));
2897 }
2898 else if (TriSurfID==2) {
2899 SP1.SetEdge1(Tri1.GetEdgeNumber(EdgeIndex));
2900 SP2.SetEdge1(Tri1.GetEdgeNumber(EdgeIndex));
2901 }
2902 else {
55ab6ed6 2903
7fd59977 2904 }
2905
2906 /**The edge is projected on the normal in the triangle if yes
2907 --> a free intersection (point I)--> Start point is found */
2908 Standard_Integer NbPoints=0;
2909 if(NormaleT.SquareModulus()==0) {
55ab6ed6 2910
7fd59977 2911 }
2912 else if( (Cote12.SquareModulus()==0)
2913 ||(Cote23.SquareModulus()==0)
2914 ||(Cote31.SquareModulus()==0) ) {
55ab6ed6 2915
7fd59977 2916 }
2917 else if(Edge.SquareModulus()==0) {
55ab6ed6 2918
7fd59977 2919 }
2920 else {
2921 Standard_Real pe1 = NormaleT.Dot(PE1);
2922 Standard_Real pe2 = NormaleT.Dot(PE2);
2923 Standard_Real pt1 = NormaleT.Dot(PT1);
2924
2925 // PE1I = lambda.Edge
2926
2927 if( (Abs(pe1-pt1)<MyConfusionPrecision)&&(Abs(pe2-pt1)<MyConfusionPrecision)) {
2928 //edge and triangle are coplanar (two contact points at maximum)
55ab6ed6 2929
7fd59977 2930
2931 //the tops of the triangle are projected on the perpendicular to the edge
2932 IntPolyh_Point PerpEdge;
2933 PerpEdge.Cross(NormaleT,Edge);
2934 Standard_Real pp1 = PerpEdge.Dot(PT1);
2935 Standard_Real pp2 = PerpEdge.Dot(PT2);
2936 Standard_Real pp3 = PerpEdge.Dot(PT3);
2937 Standard_Real ppe1 = PerpEdge.Dot(PE1);
2938
2939
2940 if ( (Abs(pp1-pp2)<MyConfusionPrecision)&&(Abs(pp1-pp3)<MyConfusionPrecision) ) {
55ab6ed6 2941
7fd59977 2942 }
2943 else {
2944 if ( ( (pp1>=ppe1)&&(pp2<=ppe1)&&(pp3<=ppe1) ) || ( (pp1<=ppe1)&&(pp2>=ppe1)&&(pp3>=ppe1) ) ){
2945 //there are two sides (common top PT1) that can cut the edge
2946
2947 //first side
2948 CalculPtsInterTriEdgeCoplanaires2(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2949 PT1,PT2,Cote12,1,SP1,SP2,NbPoints);
2950
2951 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2952 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2953
2954 //second side
2955 if (NbPoints<2) CalculPtsInterTriEdgeCoplanaires2(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2956 PT3,PT1,Cote31,3,SP1,SP2,NbPoints);
2957 }
2958
2959 if ( (NbPoints>1)&&(Abs(SP1.U1()-SP2.U1())<MyConfusionPrecision)
2960 &&(Abs(SP1.V2()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2961 if (NbPoints>=2) return(NbPoints);
2962
2963 else if ( ( ( (pp2>=ppe1)&&(pp1<=ppe1)&&(pp3<=ppe1) ) || ( (pp2<=ppe1)&&(pp1>=ppe1)&&(pp3>=ppe1) ) )
2964 && (NbPoints<2) ) {
2965 //there are two sides (common top PT2) that can cut the edge
2966
2967 //first side
2968 CalculPtsInterTriEdgeCoplanaires2(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2969 PT1,PT2,Cote12,1,SP1,SP2,NbPoints);
2970
2971 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2972 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2973
2974 //second side
2975 if(NbPoints<2) CalculPtsInterTriEdgeCoplanaires2(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2976 PT2,PT3,Cote23,2,SP1,SP2,NbPoints);
2977 }
2978 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2979 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2980 if (NbPoints>=2) return(NbPoints);
2981
2982 else if ( ( (pp3>=ppe1)&&(pp1<=ppe1)&&(pp2<=ppe1) ) || ( (pp3<=ppe1)&&(pp1>=ppe1)&&(pp2>=ppe1) )
2983 && (NbPoints<2) ) {
2984 //there are two sides (common top PT3) that can cut the edge
2985
2986 //first side
2987 CalculPtsInterTriEdgeCoplanaires2(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2988 PT3,PT1,Cote31,3,SP1,SP2,NbPoints);
2989
2990 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2991 &&(Abs(SP1.V1()-SP2.V1())<MyConfusionPrecision) ) NbPoints=1;
2992
2993 //second side
2994 if (NbPoints<2) CalculPtsInterTriEdgeCoplanaires2(TriSurfID,NormaleT,Tri1,Tri2,PE1,PE2,Edge,EdgeIndex,
2995 PT2,PT3,Cote23,2,SP1,SP2,NbPoints);
2996 }
2997 if ( (NbPoints>1)&&(Abs(SP2.U1()-SP1.U1())<MyConfusionPrecision)
2998 &&(Abs(SP2.V1()-SP1.V1())<MyConfusionPrecision) ) NbPoints=1;
2999 if (NbPoints>=2) return(NbPoints);
3000 }
3001 }
3002
3003 //------------------------------------------------------
3004 // NON COPLANAR edge and triangle (a contact point)
3005 //------------------------------------------------------
3006 else if( ( (pe1>=pt1)&&(pt1>=pe2) ) || ( (pe1<=pt1)&&(pt1<=pe2) ) ) { //
3007 lambda=(pe1-pt1)/(pe1-pe2);
3008 IntPolyh_Point PI;
3009 if (lambda<-MyConfusionPrecision) {
55ab6ed6 3010
7fd59977 3011 }
3012 else if (Abs(lambda)<MyConfusionPrecision) {//lambda==0
3013 PI=PE1;
3014 if(TriSurfID==1) SP1.SetEdge2(-1);
3015 else SP1.SetEdge1(-1);
3016 }
3017 else if (Abs(lambda-1.0)<MyConfusionPrecision) {//lambda==1
3018 PI=PE2;
3019 if(TriSurfID==1) SP1.SetEdge2(-1);
3020 else SP1.SetEdge1(-1);
3021 }
3022 else {
3023 PI=PE1+Edge*lambda;
3024 if(TriSurfID==1)
3025 if(Tri2.GetEdgeOrientation(EdgeIndex)>0)
3026 SP1.SetLambda2(lambda);
3027 else SP1.SetLambda2(1.0-lambda);
3028 if(TriSurfID==2)
3029 if(Tri1.GetEdgeOrientation(EdgeIndex)>0)
3030 SP1.SetLambda1(lambda);
3031 else SP1.SetLambda1(1.0-lambda);
3032
3033 }
55ab6ed6 3034
7fd59977 3035 Standard_Real Cote23X=Cote23.X();
3036 Standard_Real D1=0.0;
3037 Standard_Real D3,D4;
3038
3039 //Combination Eq1 Eq2
3040 if(Abs(Cote23X)>MyConfusionPrecision) {
3041 D1=Cote12.Y()-Cote12.X()*Cote23.Y()/Cote23X;
3042 }
3043 if(Abs(D1)>MyConfusionPrecision) {
3044 alpha = ( PI.Y()-PT1.Y()-(PI.X()-PT1.X())*Cote23.Y()/Cote23X )/D1;
3045
3046 ///It is checked if 1.0>=alpha>=0.0
3047 if ((alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision))) return(0);
3048 else beta = (PI.X()-PT1.X()-alpha*Cote12.X())/Cote23X;
3049 }
3050 //Combination Eq1 and Eq2 with Cote23.X()==0
3051 else if ( (Abs(Cote12.X())>MyConfusionPrecision)
3052 &&(Abs(Cote23X)<MyConfusionPrecision) ) { //There is Cote23.X()==0
3053 alpha = (PI.X()-PT1.X())/Cote12.X();
3054
3055 if ((alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision))) return(0);
3056
3057 else if (Abs(Cote23.Y())>MyConfusionPrecision) beta = (PI.Y()-PT1.Y()-alpha*Cote12.Y())/Cote23.Y();
3058 else if (Abs(Cote23.Z())>MyConfusionPrecision) beta = (PI.Z()-PT1.Z()-alpha*Cote12.Z())/Cote23.Z();
3059 else {
55ab6ed6 3060
7fd59977 3061 }
3062 }
3063 //Combination Eq1 and Eq3
3064 else if ( (Abs(Cote23.X())>MyConfusionPrecision)
3065 &&(Abs( D3= (Cote12.Z()-Cote12.X()*Cote23.Z()/Cote23.X()) ) > MyConfusionPrecision) ) {
3066
3067 alpha = (PI.Z()-PT1.Z()-(PI.X()-PT1.X())*Cote23.Z()/Cote23.X())/D3;
3068
3069 if ( (alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision)) ) return(0);
3070 else beta = (PI.X()-PT1.X()-alpha*Cote12.X())/Cote23.X();
3071 }
3072 //Combination Eq2 and Eq3
3073 else if ( (Abs(Cote23.Y())>MyConfusionPrecision)
3074 &&(Abs( D4= (Cote12.Z()-Cote12.Y()*Cote23.Z()/Cote23.Y()) ) > MyConfusionPrecision) ) {
3075
3076 alpha = (PI.Z()-PT1.Z()-(PI.Y()-PT1.Y())*Cote23.Z()/Cote23.Y())/D4;
3077
3078 if ( (alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision)) ) return(0);
3079 else beta = (PI.Y()-PT1.Y()-alpha*Cote12.Y())/Cote23.Y();
3080 }
3081 //Combination Eq2 and Eq3 with Cote23.Y()==0
3082 else if ( (Abs(Cote12.Y())>MyConfusionPrecision)
3083 && (Abs(Cote23.Y())<MyConfusionPrecision) ) {
3084 alpha = (PI.Y()-PT1.Y())/Cote12.Y();
3085
3086 if ( (alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision)) ) return(0);
3087
3088 else if (Abs(Cote23.Z())>MyConfusionPrecision) beta = (PI.Z()-PT1.Z()-alpha*Cote12.Z())/Cote23.Z();
3089
3090 else {
3091 printf("\nCote PT2PT3 nul1\n");
3092 PT2.Dump(2004);
3093 PT3.Dump(3004);
3094 }
3095 }
3096 //Combination Eq1 and Eq3 with Cote23.Z()==0
3097 else if ( (Abs(Cote12.Z())>MyConfusionPrecision)
3098 && (Abs(Cote23.Z())<MyConfusionPrecision) ) {
3099 alpha = (PI.Z()-PT1.Z())/Cote12.Z();
3100
3101 if ( (alpha<-MyConfusionPrecision)||(alpha>(1.0+MyConfusionPrecision)) ) return(0);
3102
3103 else if (Abs(Cote23.X())>MyConfusionPrecision) beta = (PI.X()-PT1.X()-alpha*Cote12.X())/Cote23.X();
3104
3105 else {
55ab6ed6 3106
7fd59977 3107 }
3108 }
3109
3110 else { //Particular case not processed ?
55ab6ed6 3111
7fd59977 3112 alpha=RealLast();
3113 beta=RealLast();
3114 }
3115
3116 if( (beta<-MyConfusionPrecision)||(beta>(alpha+MyConfusionPrecision)) ) return(0);
3117 else {
3118 SP1.SetXYZ(PI.X(),PI.Y(),PI.Z());
3119
3120 if (TriSurfID==1) {
3121 SP1.SetUV2(PI.U(),PI.V());
3122 SP1.SetUV1(PT1.U()+Cote12.U()*alpha+Cote23.U()*beta, PT1.V()+Cote12.V()*alpha+Cote23.V()*beta);
3123 NbPoints++;
3124 if (alpha<MyConfusionPrecision) {//alpha=0 --> beta==0
3125 SP1.SetXYZ(PT1.X(),PT1.Y(),PT1.Z());
3126 SP1.SetUV1(PT1.U(),PT1.V());
3127 SP1.SetEdge1(-1);
3128 }
3129 else if ( (beta<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==0 alpha==1
3130 SP1.SetXYZ(PT2.X(),PT2.Y(),PT2.Z());
3131 SP1.SetUV1(PT2.U(),PT2.V());
3132 SP1.SetEdge1(-1);
3133 }
3134 else if ( (Abs(beta-1)<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==1 alpha==1
3135 SP1.SetXYZ(PT3.X(),PT3.Y(),PT3.Z());
3136 SP1.SetUV1(PT3.U(),PT3.V());
3137 SP1.SetEdge1(-1);
3138 }
3139 else if (beta<MyConfusionPrecision) {//beta==0
3140 SP1.SetEdge1(Tri1.GetEdgeNumber(1));
3141 if(Tri1.GetEdgeOrientation(1)>0)
3142 SP1.SetLambda1(alpha);
3143 else SP1.SetLambda1(1.0-alpha);
3144 }
3145 else if (Abs(beta-alpha)<MyConfusionPrecision) {//beta==alpha
3146 SP1.SetEdge1(Tri1.GetEdgeNumber(3));
3147 if(Tri1.GetEdgeOrientation(3)>0)
3148 SP1.SetLambda1(1.0-alpha);
3149 else SP1.SetLambda1(alpha);
3150 }
3151 else if (Abs(alpha-1)<MyConfusionPrecision) {//alpha==1
3152 SP1.SetEdge1(Tri1.GetEdgeNumber(2));
3153 if(Tri1.GetEdgeOrientation(2)>0)
3154 SP1.SetLambda1(beta);
3155 else SP1.SetLambda1(1.0-beta);
3156 }
3157 }
3158 else if(TriSurfID==2) {
3159 SP1.SetUV1(PI.U(),PI.V());
3160 SP1.SetUV2(PT1.U()+Cote12.U()*alpha+Cote23.U()*beta, PT1.V()+Cote12.V()*alpha+Cote23.V()*beta);
3161 NbPoints++;
3162 if (alpha<MyConfusionPrecision) {//alpha=0 --> beta==0
3163 SP1.SetXYZ(PT1.X(),PT1.Y(),PT1.Z());
3164 SP1.SetUV2(PT1.U(),PT1.V());
3165 SP1.SetEdge2(-1);
3166 }
3167 else if ( (beta<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==0 alpha==1
3168 SP1.SetXYZ(PT2.X(),PT2.Y(),PT2.Z());
3169 SP1.SetUV2(PT2.U(),PT2.V());
3170 SP1.SetEdge2(-1);
3171 }
3172 else if ( (Abs(beta-1)<MyConfusionPrecision)&&(Abs(1-alpha)<MyConfusionPrecision) ) {//beta==1 alpha==1
3173 SP1.SetXYZ(PT3.X(),PT3.Y(),PT3.Z());
3174 SP1.SetUV2(PT3.U(),PT3.V());
3175 SP1.SetEdge2(-1);
3176 }
3177 else if (beta<MyConfusionPrecision) { //beta==0
3178 SP1.SetEdge2(Tri2.GetEdgeNumber(1));
3179 if(Tri2.GetEdgeOrientation(1)>0)
3180 SP1.SetLambda2(alpha);
3181 else SP1.SetLambda2(1.0-alpha);
3182 }
3183 else if (Abs(beta-alpha)<MyConfusionPrecision) {//beta==alpha
3184 SP1.SetEdge2(Tri2.GetEdgeNumber(3));
3185 if(Tri2.GetEdgeOrientation(3)>0)
3186 SP1.SetLambda2(1.0-alpha);
3187 else SP1.SetLambda2(alpha);
3188 }
3189 else if (Abs(alpha-1)<MyConfusionPrecision) {//alpha==1
3190 SP1.SetEdge2(Tri2.GetEdgeNumber(2));
3191 if(Tri2.GetEdgeOrientation(2)>0)
3192 SP1.SetLambda2(alpha);
3193 else SP1.SetLambda2(1.0-alpha);
3194 }
3195 }
3196 else {
55ab6ed6 3197
7fd59977 3198 }
3199 }
3200 }
3201 else return 0;
3202 }
3203 return (NbPoints);
3204}
7fd59977 3205//=======================================================================
3206//function : TriangleComparePSP
3207//purpose : The same as TriangleCompare, plus compute the
3208// StartPoints without chaining them.
3209//=======================================================================
55ab6ed6
P
3210Standard_Integer IntPolyh_MaillageAffinage::TriangleComparePSP ()
3211{
7fd59977 3212 Standard_Integer CpteurTab=0;
3213 Standard_Integer CpteurTabSP=0;
3214 Standard_Real CoupleAngle=-2.0;
d642ddf5 3215 const Standard_Integer FinTT1 = TTriangles1.NbItems();
3216 const Standard_Integer FinTT2 = TTriangles2.NbItems();
7fd59977 3217
3218 for(Standard_Integer i_S1=0; i_S1<FinTT1; i_S1++) {
3219 for(Standard_Integer i_S2=0; i_S2<FinTT2; i_S2++){
3220 if ( (TTriangles1[i_S1].IndiceIntersectionPossible() != 0)
3221 &&(TTriangles1[i_S1].GetFleche() >= 0.0)
3222 && (TTriangles2[i_S2].IndiceIntersectionPossible() != 0)
3223 && (TTriangles2[i_S2].GetFleche() >= 0.0) ) {
3224 IntPolyh_StartPoint SP1, SP2;
3225 //If a triangle is dead or not in BSB, comparison is not possible
3226 if (TriContact(TPoints1[TTriangles1[i_S1].FirstPoint()],
3227 TPoints1[TTriangles1[i_S1].SecondPoint()],
3228 TPoints1[TTriangles1[i_S1].ThirdPoint()],
3229 TPoints2[TTriangles2[i_S2].FirstPoint()],
3230 TPoints2[TTriangles2[i_S2].SecondPoint()],
3231 TPoints2[TTriangles2[i_S2].ThirdPoint()],
3232 CoupleAngle)){
3233
55ab6ed6 3234
7fd59977 3235 TTriangles1[i_S1].SetIndiceIntersection(1);//The triangle is cut by another
3236 TTriangles2[i_S2].SetIndiceIntersection(1);
3237
3238 Standard_Integer NbPoints;
3239 NbPoints=StartingPointsResearch(i_S1,i_S2,SP1, SP2);
3240
3241 if (NbPoints==0) {
55ab6ed6 3242
7fd59977 3243 }
3244
3245 if ( (NbPoints>0)&&(NbPoints<3) ) {
3246 SP1.SetCoupleValue(i_S1,i_S2);
3247 TStartPoints[CpteurTabSP]=SP1;
3248 CpteurTabSP++;
55ab6ed6
P
3249
3250
7fd59977 3251 }
3252
3253 if(NbPoints==2) {
3254 SP2.SetCoupleValue(i_S1,i_S2);
3255 TStartPoints[CpteurTabSP]=SP2;
3256 CpteurTabSP++;
55ab6ed6
P
3257
3258
7fd59977 3259 }
3260
3261 if(NbPoints>2) {
55ab6ed6 3262
7fd59977 3263 }
3264 CpteurTab++;
3265 }
3266 }
3267 }
3268 }
3269 return(CpteurTabSP);
3270}
7fd59977 3271//=======================================================================
3272//function : TriangleCompare
3273//purpose : Analyze each couple of triangles from the two --
3274// array of triangles, to see if they are in
3275// contact, and compute the incidence. Then put
3276// couples in contact in the array of couples
3277//=======================================================================
55ab6ed6
P
3278Standard_Integer IntPolyh_MaillageAffinage::TriangleCompare ()
3279{
7fd59977 3280 Standard_Integer CpteurTab=0;
55ab6ed6 3281
d642ddf5 3282 const Standard_Integer FinTT1 = TTriangles1.NbItems();
3283 const Standard_Integer FinTT2 = TTriangles2.NbItems();
7fd59977 3284
3285 Standard_Integer TTClimit = 200;
3286 Standard_Integer NbTTC = FinTT1 * FinTT2 / 10;
3287 if (NbTTC < TTClimit)
3288 NbTTC = TTClimit;
3289 TTrianglesContacts.Init(NbTTC);
3290 // eap
3291 //TTrianglesContacts.Init(FinTT1 * FinTT2 / 10);
3292
3293 Standard_Real CoupleAngle=-2.0;
3294 for(Standard_Integer i_S1=0; i_S1<FinTT1; i_S1++) {
3295 for(Standard_Integer i_S2=0; i_S2<FinTT2; i_S2++){
3296 if ( (TTriangles1[i_S1].IndiceIntersectionPossible() != 0)
3297 &&(TTriangles1[i_S1].GetFleche() >= 0.0)
3298 && (TTriangles2[i_S2].IndiceIntersectionPossible() != 0)
3299 && (TTriangles2[i_S2].GetFleche() >= 0.0) ) {
3300 //If a triangle is dead or not in BSB, comparison is not possible
3301 IntPolyh_Triangle &Triangle1 = TTriangles1[i_S1];
3302 IntPolyh_Triangle &Triangle2 = TTriangles2[i_S2];
55ab6ed6 3303
7fd59977 3304 if (TriContact(TPoints1[Triangle1.FirstPoint()],
3305 TPoints1[Triangle1.SecondPoint()],
3306 TPoints1[Triangle1.ThirdPoint()],
3307 TPoints2[Triangle2.FirstPoint()],
3308 TPoints2[Triangle2.SecondPoint()],
3309 TPoints2[Triangle2.ThirdPoint()],
3310 CoupleAngle)){
55ab6ed6 3311
7fd59977 3312 if (CpteurTab >= NbTTC)
3313 {
d642ddf5 3314 TTrianglesContacts.SetNbItems(CpteurTab);
55ab6ed6 3315
7fd59977 3316 return(CpteurTab);
3317 }
3318 TTrianglesContacts[CpteurTab].SetCoupleValue(i_S1, i_S2);
3319 TTrianglesContacts[CpteurTab].SetAngleValue(CoupleAngle);
3320//test TTrianglesContacts[CpteurTab].Dump(CpteurTab);
3321
3322 Triangle1.SetIndiceIntersection(1);//The triangle is cut by another
3323 Triangle2.SetIndiceIntersection(1);
3324 CpteurTab++;
3325 }
3326 }
3327 }
3328 }
d642ddf5 3329 TTrianglesContacts.SetNbItems(CpteurTab);
55ab6ed6 3330
7fd59977 3331 return(CpteurTab);
3332}
3333
3334//=======================================================================
3335//function : StartPointsCalcul
3336//purpose : From the array of couples compute all the start
3337// points and display them on the screen
3338//=======================================================================
55ab6ed6
P
3339void IntPolyh_MaillageAffinage::StartPointsCalcul() const
3340{
d642ddf5 3341 const Standard_Integer FinTTC = TTrianglesContacts.NbItems();
7fd59977 3342// printf("StartPointsCalcul() from IntPolyh_MaillageAffinage.cxx : StartPoints:\n");
3343 for(Standard_Integer ii=0; ii<FinTTC; ii++) {
3344 IntPolyh_StartPoint SP1,SP2;
3345 Standard_Integer T1,T2;
3346 T1=TTrianglesContacts[ii].FirstValue();
3347 T2=TTrianglesContacts[ii].SecondValue();
3348 StartingPointsResearch(T1,T2,SP1,SP2);
3349 if ( (SP1.E1()!=-1)&&(SP1.E2()!=-1) ) SP1.Dump(ii);
3350 if ( (SP2.E1()!=-1)&&(SP2.E2()!=-1) ) SP2.Dump(ii);
3351 }
3352}
7fd59977 3353//=======================================================================
3354//function : CheckCoupleAndGetAngle
3355//purpose :
3356//=======================================================================
55ab6ed6
P
3357Standard_Integer CheckCoupleAndGetAngle(const Standard_Integer T1,
3358 const Standard_Integer T2,
3359 Standard_Real& Angle,
3360 IntPolyh_ArrayOfCouples &TTrianglesContacts)
3361{
7fd59977 3362 Standard_Integer Test=0;
d642ddf5 3363 const Standard_Integer FinTTC = TTrianglesContacts.NbItems();
7fd59977 3364 for (Standard_Integer oioi=0; oioi<FinTTC; oioi++) {
3365 IntPolyh_Couple TestCouple = TTrianglesContacts[oioi];
3366 if ( (TestCouple.FirstValue()==T1)&&(TestCouple.AnalyseFlagValue()!=1) ) {
3367 if (TestCouple.SecondValue()==T2) {
3368 Test=oioi;
3369 TTrianglesContacts[oioi].SetAnalyseFlag(1);
3370 Angle=TTrianglesContacts[oioi].AngleValue();
3371 oioi=FinTTC;
3372 }
3373 }
3374 }
3375 return(Test);
3376}
7fd59977 3377//=======================================================================
3378//function : CheckCoupleAndGetAngle2
3379//purpose :
3380//=======================================================================
55ab6ed6
P
3381Standard_Integer CheckCoupleAndGetAngle2(const Standard_Integer T1,
3382 const Standard_Integer T2,
3383 const Standard_Integer T11,
3384 const Standard_Integer T22,
3385 Standard_Integer &CT11,
3386 Standard_Integer &CT22,
3387 Standard_Real & Angle,
3388 IntPolyh_ArrayOfCouples &TTrianglesContacts)
3389{
7fd59977 3390 ///couple T1 T2 is found in the list
3391 ///T11 and T22 are two other triangles implied in the contact edge edge
3392 /// CT11 couple( T1,T22) and CT22 couple (T2,T11)
3393 /// these couples will be marked if there is a start point
3394 Standard_Integer Test1=0;
3395 Standard_Integer Test2=0;
3396 Standard_Integer Test3=0;
d642ddf5 3397 const Standard_Integer FinTTC = TTrianglesContacts.NbItems();
7fd59977 3398 for (Standard_Integer oioi=0; oioi<FinTTC; oioi++) {
3399 IntPolyh_Couple TestCouple = TTrianglesContacts[oioi];
3400 if( (Test1==0)||(Test2==0)||(Test3==0) ) {
3401 if ( (TestCouple.FirstValue()==T1)&&(TestCouple.AnalyseFlagValue()!=1) ) {
3402 if (TestCouple.SecondValue()==T2) {
3403 Test1=1;
3404 TTrianglesContacts[oioi].SetAnalyseFlag(1);
3405 Angle=TTrianglesContacts[oioi].AngleValue();
3406 }
3407 else if (TestCouple.SecondValue()==T22) {
3408 Test2=1;
3409 CT11=oioi;
3410 Angle=TTrianglesContacts[oioi].AngleValue();
3411 }
3412 }
3413 else if( (TestCouple.FirstValue()==T11)&&(TestCouple.AnalyseFlagValue()!=1) ) {
3414 if (TestCouple.SecondValue()==T2) {
3415 Test3=1;
3416 CT22=oioi;
3417 Angle=TTrianglesContacts[oioi].AngleValue();
3418 }
3419 }
3420 }
3421 else
3422 oioi=FinTTC;
3423 }
3424 return(Test1);
3425}
7fd59977 3426//=======================================================================
3427//function : CheckNextStartPoint
3428//purpose : it is checked if the point is not a top
55ab6ed6
P
3429// then it is stored in one or several valid arrays with
3430// the proper list number
7fd59977 3431//=======================================================================
7fd59977 3432Standard_Integer CheckNextStartPoint(IntPolyh_SectionLine & SectionLine,
3433 IntPolyh_ArrayOfTangentZones & TTangentZones,
3434 IntPolyh_StartPoint & SP,
55ab6ed6
P
3435 const Standard_Boolean Prepend)//=Standard_False)
3436{
7fd59977 3437 Standard_Integer Test=1;
3438 if( (SP.E1()==-1)||(SP.E2()==-1) ) {
3439 //The tops of triangle are analyzed
3440 //It is checked if they are not in the array TTangentZones
d642ddf5 3441 Standard_Integer FinTTZ=TTangentZones.NbItems();
7fd59977 3442 for(Standard_Integer uiui=0; uiui<FinTTZ; uiui++) {
3443 IntPolyh_StartPoint TestSP=TTangentZones[uiui];
3444 if ( (Abs(SP.U1()-TestSP.U1())<MyConfusionPrecision)
3445 &&(Abs(SP.V1()-TestSP.V1())<MyConfusionPrecision) ) {
3446 if ( (Abs(SP.U2()-TestSP.U2())<MyConfusionPrecision)
3447 &&(Abs(SP.V2()-TestSP.V2())<MyConfusionPrecision) ) {
3448 Test=0;//SP is already in the list of tops
3449 uiui=FinTTZ;
3450 }
3451 }
3452 }
3453 if (Test) {//the top does not belong to the list of TangentZones
3454 SP.SetChainList(-1);
3455 TTangentZones[FinTTZ]=SP;
d642ddf5 3456 TTangentZones.IncrementNbItems();
7fd59977 3457 Test=0;//the examined point is a top
3458 }
3459 }
3460 else if (Test) {
3461 if (Prepend)
3462 SectionLine.Prepend(SP);
3463 else {
3464 SectionLine[SectionLine.NbStartPoints()]=SP;
3465 SectionLine.IncrementNbStartPoints();
3466 }
55ab6ed6 3467
7fd59977 3468 }
55ab6ed6
P
3469 //if the point is not a top Test=1
3470 //The chain is continued
3471 return(Test);
7fd59977 3472}
7fd59977 3473//=======================================================================
3474//function : StartPointsChain
3475//purpose : Loop on the array of couples. Compute StartPoints.
3476// Try to chain the StartPoints into SectionLines or
3477// put the point in the ArrayOfTangentZones if
3478// chaining it, is not possible.
3479//=======================================================================
55ab6ed6
P
3480Standard_Integer IntPolyh_MaillageAffinage::StartPointsChain
3481 (IntPolyh_ArrayOfSectionLines& TSectionLines,
3482 IntPolyh_ArrayOfTangentZones& TTangentZones)
3483{
7fd59977 3484//Loop on the array of couples filled in the function COMPARE()
d642ddf5 3485 const Standard_Integer FinTTC = TTrianglesContacts.NbItems();
7fd59977 3486
3487//Array of tops of triangles
7fd59977 3488 for(Standard_Integer IndexA=0; IndexA<FinTTC; IndexA++) {
3489 //First couple of triangles.
3490 //It is checked if the couple of triangles has not been already examined.
3491 if(TTrianglesContacts[IndexA].AnalyseFlagValue()!=1) {
3492
d642ddf5 3493 Standard_Integer SectionLineIndex=TSectionLines.NbItems();
7fd59977 3494 // fill last section line if still empty (eap)
3495 if (SectionLineIndex > 0
3496 &&
3497 TSectionLines[SectionLineIndex-1].NbStartPoints() == 0)
3498 SectionLineIndex -= 1;
3499 else
d642ddf5 3500 TSectionLines.IncrementNbItems();
7fd59977 3501
3502 IntPolyh_SectionLine & MySectionLine=TSectionLines[SectionLineIndex];
3503 if (MySectionLine.GetN() == 0) // eap
3504 MySectionLine.Init(10000);//Initialisation of array of StartPoint
3505
3506 Standard_Integer NbPoints=-1;
3507 Standard_Integer T1I, T2I;
3508 T1I = TTrianglesContacts[IndexA].FirstValue();
3509 T2I = TTrianglesContacts[IndexA].SecondValue();
3510
3511 // Start points for the current couple are found
3512 IntPolyh_StartPoint SP1, SP2;
3513 NbPoints=StartingPointsResearch2(T1I,T2I,SP1, SP2);//first calculation
3514 TTrianglesContacts[IndexA].SetAnalyseFlag(1);//the couple is marked
3515
3516 if(NbPoints==1) {// particular case top/triangle or edge/edge
3517 //the start point is input in the array
3518 SP1.SetChainList(SectionLineIndex);
3519 SP1.SetAngle(TTrianglesContacts[IndexA].AngleValue());
3520 //it is checked if the point is not atop of the triangle
3521 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP1)) {
3522 IntPolyh_StartPoint SPNext1;
3523 Standard_Integer TestSP1=0;
3524
3525 //chain of a side
3526 IntPolyh_StartPoint SP11;//=SP1;
3527 if(SP1.E1()>=0) { //&&(SP1.E2()!=-1) already tested if the point is not a top
3528 Standard_Integer NextTriangle1=0;
3529 if (TEdges1[SP1.E1()].FirstTriangle()!=T1I) NextTriangle1=TEdges1[SP1.E1()].FirstTriangle();
3530 else NextTriangle1=TEdges1[SP1.E1()].SecondTriangle();
3531
3532 Standard_Real Angle=-2.0;
55ab6ed6
P
3533 if (CheckCoupleAndGetAngle(NextTriangle1,T2I,Angle,TTrianglesContacts)) {
3534 //it is checked if the couple exists and is marked
7fd59977 3535 Standard_Integer NbPoints11=0;
3536 NbPoints11=NextStartingPointsResearch2(NextTriangle1,T2I,SP1,SP11);
3537 if (NbPoints11==1) {
3538 SP11.SetChainList(SectionLineIndex);
3539 SP11.SetAngle(Angle);
3540
3541 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP11)) {
3542 Standard_Integer EndChainList=1;
3543 while (EndChainList!=0) {
3544 TestSP1=GetNextChainStartPoint(SP11,SPNext1,MySectionLine,TTangentZones);
3545 if(TestSP1==1) {
3546 SPNext1.SetChainList(SectionLineIndex);
3547 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext1))
3548 SP11=SPNext1;
3549 else EndChainList=0;
3550 }
3551 else EndChainList=0; //There is no next point
3552 }
3553 }
3554
3555 }
3556 else {
3557 if(NbPoints11>1) {//The point is input in the array TTangentZones
d642ddf5 3558 TTangentZones[TTangentZones.NbItems()]=SP11;//default list number = -1
3559 TTangentZones.IncrementNbItems();
7fd59977 3560 }
3561 else {
55ab6ed6 3562
7fd59977 3563 }
3564 }
3565 }
3566 }
3567 else if (SP1.E2()<0){
55ab6ed6 3568
7fd59977 3569 }
3570 //chain of the other side
3571 IntPolyh_StartPoint SP12;//=SP1;
3572 if (SP1.E2()>=0) { //&&(SP1.E1()!=-1) already tested
3573 Standard_Integer NextTriangle2;
3574 if (TEdges2[SP1.E2()].FirstTriangle()!=T2I) NextTriangle2=TEdges2[SP1.E2()].FirstTriangle();
3575 else NextTriangle2=TEdges2[SP1.E2()].SecondTriangle();
3576
3577 Standard_Real Angle=-2.0;
3578 if(CheckCoupleAndGetAngle(T1I,NextTriangle2,Angle,TTrianglesContacts)) {
3579 Standard_Integer NbPoints12=0;
3580 NbPoints12=NextStartingPointsResearch2(T1I,NextTriangle2,SP1, SP12);
3581 if (NbPoints12==1) {
3582
3583 SP12.SetChainList(SectionLineIndex);
3584 SP12.SetAngle(Angle);
3585 Standard_Boolean Prepend = Standard_True; // eap
3586
3587 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP12, Prepend)) {
3588 Standard_Integer EndChainList=1;
3589 while (EndChainList!=0) {
3590 TestSP1=GetNextChainStartPoint(SP12,SPNext1,
3591 MySectionLine,TTangentZones,
3592 Prepend); // eap
3593 if(TestSP1==1) {
3594 SPNext1.SetChainList(SectionLineIndex);
3595 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext1,Prepend))
3596 SP12=SPNext1;
3597 else EndChainList=0;
3598 }
3599 else EndChainList=0; //there is no next point
3600 }
3601 }
3602
3603 else {
3604 if(NbPoints12>1) {//The points are input in the array TTangentZones
d642ddf5 3605 TTangentZones[TTangentZones.NbItems()]=SP12;//default list number = -1
3606 TTangentZones.IncrementNbItems();
7fd59977 3607 }
3608 else {
55ab6ed6 3609
7fd59977 3610 }
3611 }
3612 }
3613 }
3614 }
3615 else if(SP1.E1()<0){
55ab6ed6 3616
7fd59977 3617 }
3618 }
3619 }
3620 else if(NbPoints==2) {
3621 //the start points are input in the array
3622 IntPolyh_StartPoint SPNext2;
3623 Standard_Integer TestSP2=0;
3624 Standard_Integer EndChainList=1;
3625
3626 SP1.SetChainList(SectionLineIndex);
3627 SP1.SetAngle(TTrianglesContacts[IndexA].AngleValue());
3628 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP1)) {
3629
3630 //chain of a side
3631 while (EndChainList!=0) {
3632 TestSP2=GetNextChainStartPoint(SP1,SPNext2,MySectionLine,TTangentZones);
3633 if(TestSP2==1) {
3634 SPNext2.SetChainList(SectionLineIndex);
3635 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext2))
3636 SP1=SPNext2;
3637 else EndChainList=0;
3638 }
3639 else EndChainList=0; //there is no next point
3640 }
3641 }
3642
3643 SP2.SetChainList(SectionLineIndex);
3644 SP2.SetAngle(TTrianglesContacts[IndexA].AngleValue());
3645 Standard_Boolean Prepend = Standard_True; // eap
3646
3647 if(CheckNextStartPoint(MySectionLine,TTangentZones,SP2,Prepend)) {
3648
3649 //chain of the other side
3650 EndChainList=1;
3651 while (EndChainList!=0) {
3652 TestSP2=GetNextChainStartPoint(SP2,SPNext2,
3653 MySectionLine,TTangentZones,
3654 Prepend); // eap
3655 if(TestSP2==1) {
3656 SPNext2.SetChainList(SectionLineIndex);
3657 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext2,Prepend))
3658 SP2=SPNext2;
3659 else EndChainList=0;
3660 }
3661 else EndChainList=0; //there is no next point
3662 }
3663 }
3664 }
3665
3666 else if( (NbPoints>2)&&(NbPoints<7) ) {
3667 //More than two start points
3668 //the start point is input in the table
3669 SP1.SetChainList(SectionLineIndex);
3670 CheckNextStartPoint(MySectionLine,TTangentZones,SP1);
3671 }
3672
3673 else {
55ab6ed6 3674
7fd59977 3675 }
3676 }
3677 }
55ab6ed6 3678
7fd59977 3679 return(1);
3680}
7fd59977 3681//=======================================================================
3682//function : GetNextChainStartPoint
3683//purpose : Mainly used by StartPointsChain(), this function
3684// try to compute the next StartPoint.
3685// GetNextChainStartPoint is used only if it is known that there are 2 contact points
3686//=======================================================================
55ab6ed6
P
3687Standard_Integer IntPolyh_MaillageAffinage::GetNextChainStartPoint
3688 (const IntPolyh_StartPoint & SP,
3689 IntPolyh_StartPoint & SPNext,
3690 IntPolyh_SectionLine & MySectionLine,
3691 IntPolyh_ArrayOfTangentZones & TTangentZones,
3692 const Standard_Boolean Prepend)
3693{
7fd59977 3694 Standard_Integer NbPoints=0;
3695 if( (SP.E1()>=0)&&(SP.E2()==-2) ) {
3696 //case if the point is on edge of T1
3697 Standard_Integer NextTriangle1;
3698 if (TEdges1[SP.E1()].FirstTriangle()!=SP.T1()) NextTriangle1=TEdges1[SP.E1()].FirstTriangle();
3699 else
3700 NextTriangle1=TEdges1[SP.E1()].SecondTriangle();
3701 //If is checked if two triangles intersect
3702 Standard_Real Angle= -2.0;
3703 if (CheckCoupleAndGetAngle(NextTriangle1,SP.T2(),Angle,TTrianglesContacts)) {
3704 NbPoints=NextStartingPointsResearch2(NextTriangle1,SP.T2(),SP,SPNext);
3705 if( NbPoints!=1 ) {
3706 if (NbPoints>1)
3707 CheckNextStartPoint(MySectionLine,TTangentZones,SPNext,Prepend);
3708 else {
55ab6ed6 3709
7fd59977 3710 NbPoints=0;
3711 }
3712 }
3713 else
3714 SPNext.SetAngle(Angle);
3715 }
3716 else NbPoints=0;//this couple does not intersect
3717 }
3718 else if( (SP.E1()==-2)&&(SP.E2()>=0) ) {
3719 //case if the point is on edge of T2
3720 Standard_Integer NextTriangle2;
3721 if (TEdges2[SP.E2()].FirstTriangle()!=SP.T2()) NextTriangle2=TEdges2[SP.E2()].FirstTriangle();
3722 else
3723 NextTriangle2=TEdges2[SP.E2()].SecondTriangle();
3724 Standard_Real Angle= -2.0;
3725 if (CheckCoupleAndGetAngle(SP.T1(),NextTriangle2,Angle,TTrianglesContacts)) {
3726 NbPoints=NextStartingPointsResearch2(SP.T1(),NextTriangle2,SP,SPNext);
3727 if( NbPoints!=1 ) {
3728 if (NbPoints>1)
3729 CheckNextStartPoint(MySectionLine,TTangentZones,SPNext,Prepend);
3730 else {
55ab6ed6 3731
7fd59977 3732 NbPoints=0;
3733 }
3734 }
3735 else
3736 SPNext.SetAngle(Angle);
3737 }
3738 else NbPoints=0;
3739 }
3740 else if( (SP.E1()==-2)&&(SP.E2()==-2) ) {
3741 ///no edge is touched or cut
55ab6ed6 3742
7fd59977 3743 NbPoints=0;
3744 }
3745 else if( (SP.E1()>=0)&&(SP.E2()>=0) ) {
3746 ///the point is located on two edges
3747 Standard_Integer NextTriangle1;
3748 Standard_Integer CpleT11=-1;
3749 Standard_Integer CpleT22=-1;
3750 if (TEdges1[SP.E1()].FirstTriangle()!=SP.T1()) NextTriangle1=TEdges1[SP.E1()].FirstTriangle();
3751 else
3752 NextTriangle1=TEdges1[SP.E1()].SecondTriangle();
3753 Standard_Integer NextTriangle2;
3754 if (TEdges2[SP.E2()].FirstTriangle()!=SP.T2()) NextTriangle2=TEdges2[SP.E2()].FirstTriangle();
3755 else
3756 NextTriangle2=TEdges2[SP.E2()].SecondTriangle();
3757 Standard_Real Angle= -2.0;
55ab6ed6
P
3758 if (CheckCoupleAndGetAngle2(NextTriangle1,NextTriangle2,
3759 SP.T1(),SP.T2(),CpleT11,CpleT22,
3760 Angle,TTrianglesContacts)) {
7fd59977 3761 NbPoints=NextStartingPointsResearch2(NextTriangle1,NextTriangle2,SP,SPNext);
3762 if( NbPoints!=1 ) {
3763 if (NbPoints>1) {
3764 ///The new point is checked
3765 if(CheckNextStartPoint(MySectionLine,TTangentZones,SPNext,Prepend)>0) {
3766 }
3767 else {
55ab6ed6 3768
7fd59977 3769 }
3770 }
3771 NbPoints=0;
3772 }
3773 else {//NbPoints==1
3774 SPNext.SetAngle(Angle);
3775 //The couples (Ti,Tj) (Ti',Tj') are marked
3776 if (CpleT11>=0) TTrianglesContacts[CpleT11].SetAnalyseFlag(1);
3777 else {
55ab6ed6 3778
7fd59977 3779 }
3780 if (CpleT22>=0) TTrianglesContacts[CpleT22].SetAnalyseFlag(1);
3781 else {
55ab6ed6 3782
7fd59977 3783 }
3784 }
3785 }
3786 else NbPoints=0;
3787 }
3788 else if( (SP.E1()==-1)||(SP.E2()==-1) ) {
3789 ///the points are tops of triangle
3790 ///the point is atored in an intermediary array
3791 }
3792 return(NbPoints);
3793}
7fd59977 3794//=======================================================================
3795//function : GetArrayOfPoints
3796//purpose :
3797//=======================================================================
55ab6ed6
P
3798const IntPolyh_ArrayOfPoints& IntPolyh_MaillageAffinage::GetArrayOfPoints
3799 (const Standard_Integer SurfID)const
3800{
7fd59977 3801 if (SurfID==1)
3802 return(TPoints1);
3803 return(TPoints2);
3804}
7fd59977 3805//=======================================================================
3806//function : GetArrayOfEdges
3807//purpose :
3808//=======================================================================
55ab6ed6
P
3809const IntPolyh_ArrayOfEdges& IntPolyh_MaillageAffinage::GetArrayOfEdges
3810 (const Standard_Integer SurfID)const
3811{
7fd59977 3812 if (SurfID==1)
3813 return(TEdges1);
3814 return(TEdges2);
3815}
7fd59977 3816//=======================================================================
3817//function : GetArrayOfTriangles
3818//purpose :
3819//=======================================================================
55ab6ed6
P
3820const IntPolyh_ArrayOfTriangles&
3821 IntPolyh_MaillageAffinage::GetArrayOfTriangles
3822 (const Standard_Integer SurfID)const{
7fd59977 3823 if (SurfID==1)
3824 return(TTriangles1);
3825 return(TTriangles2);
3826}
3827
3828//=======================================================================
3829//function : GetBox
3830//purpose :
3831//=======================================================================
55ab6ed6
P
3832Bnd_Box IntPolyh_MaillageAffinage::GetBox(const Standard_Integer SurfID) const
3833{
7fd59977 3834 if (SurfID==1)
3835 return(MyBox1);
3836 return(MyBox2);
3837}
3838
3839//=======================================================================
3840//function : GetBoxDraw
3841//purpose :
3842//=======================================================================
55ab6ed6
P
3843void IntPolyh_MaillageAffinage::GetBoxDraw(const Standard_Integer SurfID)const
3844{
7fd59977 3845Standard_Real x0,y0,z0,x1,y1,z1;
3846 if (SurfID==1) {
3847 MyBox1.Get(x0,y0,z0,x1,y1,z1);
7fd59977 3848 }
3849 else {
3850 MyBox2.Get(x0,y0,z0,x1,y1,z1);
7fd59977 3851 }
3852}
7fd59977 3853//=======================================================================
3854//function : GetArrayOfCouples
3855//purpose :
3856//=======================================================================
7fd59977 3857IntPolyh_ArrayOfCouples &IntPolyh_MaillageAffinage::GetArrayOfCouples()
3858{
3859 return TTrianglesContacts;
3860}
55ab6ed6
P
3861//=======================================================================
3862//function : SetEnlargeZone
3863//purpose :
3864//=======================================================================
7fd59977 3865void IntPolyh_MaillageAffinage::SetEnlargeZone(Standard_Boolean& EnlargeZone)
3866{
3867 myEnlargeZone = EnlargeZone;
3868}
55ab6ed6
P
3869//=======================================================================
3870//function : GetEnlargeZone
3871//purpose :
3872//=======================================================================
7fd59977 3873Standard_Boolean IntPolyh_MaillageAffinage::GetEnlargeZone() const
3874{
3875 return myEnlargeZone;
3876}
55ab6ed6
P
3877//modified by NIZNHY-PKV Fri Jan 20 10:06:13 2012f
3878//=======================================================================
3879//function : DegeneratedIndex
3880//purpose :
3881//=======================================================================
3882void DegeneratedIndex(const TColStd_Array1OfReal& aXpars,
3883 const Standard_Integer aNbX,
3884 const Handle(Adaptor3d_HSurface)& aS,
3885 const Standard_Integer aIsoDirection,
3886 Standard_Integer& aI1,
3887 Standard_Integer& aI2)
3888{
3889 Standard_Integer i;
3890 Standard_Boolean bDegX1, bDegX2;
3891 Standard_Real aDegX1, aDegX2, aTol2, aX;
3892 //
3893 aI1=0;
3894 aI2=0;
3895 aTol2=MyTolerance*MyTolerance;
3896 //
3897 if (aIsoDirection==1){ // V=const
3898 bDegX1=IsDegenerated(aS, 1, aTol2, aDegX1);
3899 bDegX2=IsDegenerated(aS, 2, aTol2, aDegX2);
3900 }
3901 else if (aIsoDirection==2){ // U=const
3902 bDegX1=IsDegenerated(aS, 3, aTol2, aDegX1);
3903 bDegX2=IsDegenerated(aS, 4, aTol2, aDegX2);
3904 }
3905 else {
3906 return;
3907 }
3908 //
3909 if (!(bDegX1 || bDegX2)) {
3910 return;
3911 }
3912 //
3913 for(i=1; i<=aNbX; ++i) {
3914 aX=aXpars(i);
3915 if (bDegX1) {
3916 if (fabs(aX-aDegX1) < MyTolerance) {
3917 aI1=i;
3918 }
3919 }
3920 if (bDegX2) {
3921 if (fabs(aX-aDegX2) < MyTolerance) {
3922 aI2=i;
3923 }
3924 }
3925 }
3926}
3927//=======================================================================
3928//function : IsDegenerated
3929//purpose :
3930//=======================================================================
3931Standard_Boolean IsDegenerated(const Handle(Adaptor3d_HSurface)& aS,
3932 const Standard_Integer aIndex,
3933 const Standard_Real aTol2,
3934 Standard_Real& aDegX)
3935{
3936 Standard_Boolean bRet;
3937 Standard_Integer i, aNbP;
3938 Standard_Real aU, dU, aU1, aU2, aV, dV, aV1, aV2, aD2;
3939 gp_Pnt aP1, aP2;
3940 //
3941 bRet=Standard_False;
3942 aNbP=3;
3943 aDegX=99;
3944 //
3945 aU1=aS->FirstUParameter();
3946 aU2=aS->LastUParameter();
3947 aV1=aS->FirstVParameter();
3948 aV2=aS->LastVParameter();
3949 //
3950 if (aIndex<3) { // V=const
3951 aV=aV1;
3952 if (aIndex==2) {
3953 aV=aV2;
3954 }
3955 dU=(aU2-aU1)/(aNbP-1);
3956 aU=aU1;
3957 aP1=aS->Value(aU, aV);
3958 for (i=1; i<aNbP; ++i) {
3959 aU=i*dU;
3960 if (i==aNbP-1){
3961 aU=aU2;
3962 }
3963 aP2=aS->Value(aU, aV);
3964 aD2=aP1.SquareDistance(aP2);
3965 if (aD2>aTol2) {
3966 return bRet;
3967 }
3968 aP1=aP2;
3969 }
3970 aDegX=aV;
3971 bRet=!bRet;
3972 }
3973 else {// U=const
3974 aU=aU1;
3975 if (aIndex==4) {
3976 aU=aU2;
3977 }
3978 dV=(aV2-aV1)/(aNbP-1);
3979 aV=aV1;
3980 aP1=aS->Value(aU, aV);
3981 for (i=1; i<aNbP; ++i) {
3982 aV=i*dV;
3983 if (i==aNbP-1){
3984 aV=aV2;
3985 }
3986 aP2=aS->Value(aU, aV);
3987 aD2=aP1.SquareDistance(aP2);
3988 if (aD2>aTol2) {
3989 return bRet;
3990 }
3991 aP1=aP2;
3992 }
3993 bRet=!bRet;
3994 aDegX=aU;
3995 }
3996 //
3997 return bRet;
3998}
3999//modified by NIZNHY-PKV Fri Jan 20 10:06:15 2012t
4000#ifdef DEB
4001
4002#include <TopoDS_Shape.hxx>
4003#include <Poly_Triangulation.hxx>
4004#include <TColgp_Array1OfPnt.hxx>
4005#include <Poly_Array1OfTriangle.hxx>
4006#include <BRep_TFace.hxx>
4007#include <TopoDS_Face.hxx>
4008
4009//=======================================================================
4010//function : TriangleShape
4011//purpose : shape with triangulation containing triangles
4012//=======================================================================
4013static TopoDS_Shape TriangleShape(const IntPolyh_ArrayOfTriangles & TTriangles,
4014 const IntPolyh_ArrayOfPoints & TPoints)
4015{
4016 TopoDS_Face aFace;
d642ddf5 4017 if (TPoints.NbItems() < 1 || TTriangles.NbItems() < 1) return aFace;
55ab6ed6
P
4018
4019 Handle(Poly_Triangulation) aPTriangulation =
d642ddf5 4020 new Poly_Triangulation(TPoints.NbItems(),TTriangles.NbItems(),Standard_False);
55ab6ed6
P
4021 TColgp_Array1OfPnt & aPNodes = aPTriangulation->ChangeNodes();
4022 Poly_Array1OfTriangle & aPTrialgles = aPTriangulation->ChangeTriangles();
4023
4024 Standard_Integer i;
d642ddf5 4025 for (i=0; i<TPoints.NbItems(); i++) {
55ab6ed6
P
4026 const IntPolyh_Point& P = TPoints[i];
4027 aPNodes(i+1).SetCoord(P.X(), P.Y(), P.Z());
4028 }
d642ddf5 4029 for (i=0; i<TTriangles.NbItems(); i++) {
55ab6ed6
P
4030 const IntPolyh_Triangle& T = TTriangles[i];
4031 aPTrialgles(i+1).Set(T.FirstPoint()+1, T.SecondPoint()+1, T.ThirdPoint()+1);
4032 }
4033
4034 Handle(BRep_TFace) aTFace = new BRep_TFace;
4035 aTFace->Triangulation(aPTriangulation);
4036 aFace.TShape(aTFace);
4037 return aFace;
4038}
4039#endif
4040
4041//#define MyTolerance 10.0e-7
4042//#define MyConfusionPrecision 10.0e-12
4043//#define SquareMyConfusionPrecision 10.0e-24