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