b311480e |
1 | // Created on: 1993-01-11 |
2 | // Created by: Christophe MARION |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
733a0e55 |
16 | |
7fd59977 |
17 | #ifndef No_Exception |
18 | //#define No_Exception |
19 | #endif |
20 | #include <HLRAlgo_PolyData.ixx> |
21 | |
22 | #define EMskGrALin1 ((Standard_Boolean) 8) |
23 | #define EMskGrALin2 ((Standard_Boolean) 16) |
24 | #define EMskGrALin3 ((Standard_Boolean) 32) |
25 | #define FMskHiding ((Standard_Boolean) 256) |
26 | |
27 | #define FIndex myIndices[0] |
28 | #define MinFac myIndices[1] |
29 | #define MaxFac myIndices[2] |
30 | |
31 | #define TriNode1 ((Standard_Integer*)TriIndices)[0] |
32 | #define TriNode2 ((Standard_Integer*)TriIndices)[1] |
33 | #define TriNode3 ((Standard_Integer*)TriIndices)[2] |
34 | #define TriFlags ((Standard_Boolean*)TriIndices)[3] |
35 | |
36 | #define Crossing ((Standard_Boolean*)BooleanPtr)[0] |
37 | #define HideBefore ((Standard_Boolean*)BooleanPtr)[1] |
38 | #define TrFlags ((Standard_Boolean*)BooleanPtr)[2] |
39 | |
40 | #define Crosi BooleanPtr[0] |
41 | #define HdBef BooleanPtr[1] |
42 | #define TFlag BooleanPtr[2] |
43 | |
44 | #define PntX1 ((Standard_Real*)Coordinates)[ 0] |
45 | #define PntY1 ((Standard_Real*)Coordinates)[ 1] |
46 | #define PntZ1 ((Standard_Real*)Coordinates)[ 2] |
47 | #define PntX2 ((Standard_Real*)Coordinates)[ 3] |
48 | #define PntY2 ((Standard_Real*)Coordinates)[ 4] |
49 | #define PntZ2 ((Standard_Real*)Coordinates)[ 5] |
50 | #define PntXP1 ((Standard_Real*)Coordinates)[ 6] |
51 | #define PntYP1 ((Standard_Real*)Coordinates)[ 7] |
52 | #define PntZP1 ((Standard_Real*)Coordinates)[ 8] |
53 | #define PntXP2 ((Standard_Real*)Coordinates)[ 9] |
54 | #define PntYP2 ((Standard_Real*)Coordinates)[10] |
55 | #define PntZP2 ((Standard_Real*)Coordinates)[11] |
56 | |
57 | #define XV1 ((Standard_Real*)RealPtr)[0] |
58 | #define XV2 ((Standard_Real*)RealPtr)[1] |
59 | #define XV3 ((Standard_Real*)RealPtr)[2] |
60 | #define YV1 ((Standard_Real*)RealPtr)[3] |
61 | #define YV2 ((Standard_Real*)RealPtr)[4] |
62 | #define YV3 ((Standard_Real*)RealPtr)[5] |
63 | #define Param ((Standard_Real*)RealPtr)[6] |
64 | #define TolParam ((Standard_Real*)RealPtr)[7] |
65 | #define TolAng ((Standard_Real*)RealPtr)[8] |
66 | #define Tolerance ((Standard_Real*)RealPtr)[9] |
67 | |
68 | #define TotXMin ((Standard_Real*)TotMinMax)[0] |
69 | #define TotYMin ((Standard_Real*)TotMinMax)[1] |
70 | #define TotZMin ((Standard_Real*)TotMinMax)[2] |
71 | #define TotXMax ((Standard_Real*)TotMinMax)[3] |
72 | #define TotYMax ((Standard_Real*)TotMinMax)[4] |
73 | #define TotZMax ((Standard_Real*)TotMinMax)[5] |
74 | |
75 | #define IndexTri ((Standard_Integer*)MinMaxPtr)[0] |
76 | #define MinTri ((Standard_Integer*)MinMaxPtr)[1] |
77 | #define MaxTri ((Standard_Integer*)MinMaxPtr)[2] |
78 | |
79 | #define APlan ((Standard_Real*)PlanPtr)[0] |
80 | #define BPlan ((Standard_Real*)PlanPtr)[1] |
81 | #define CPlan ((Standard_Real*)PlanPtr)[2] |
82 | #define DPlan ((Standard_Real*)PlanPtr)[3] |
83 | |
84 | #define ShapeIndex ((Standard_Integer*)Indices)[0] |
85 | #define FaceConex1 ((Standard_Integer*)Indices)[1] |
86 | #define Face1Pt1 ((Standard_Integer*)Indices)[2] |
87 | #define Face1Pt2 ((Standard_Integer*)Indices)[3] |
88 | #define FaceConex2 ((Standard_Integer*)Indices)[4] |
89 | #define Face2Pt1 ((Standard_Integer*)Indices)[5] |
90 | #define Face2Pt2 ((Standard_Integer*)Indices)[6] |
91 | #define MinSeg ((Standard_Integer*)Indices)[7] |
92 | #define MaxSeg ((Standard_Integer*)Indices)[8] |
93 | #define SegFlags ((Standard_Integer*)Indices)[9] |
0797d9d3 |
94 | #ifdef OCCT_DEBUG |
7fd59977 |
95 | static Standard_Integer ERROR = Standard_False; |
96 | #endif |
97 | //======================================================================= |
98 | //function : PolyData |
99 | //purpose : |
100 | //======================================================================= |
101 | |
102 | HLRAlgo_PolyData::HLRAlgo_PolyData () |
103 | {} |
104 | |
105 | //======================================================================= |
106 | //function : HNodes |
107 | //purpose : |
108 | //======================================================================= |
109 | |
110 | void HLRAlgo_PolyData::HNodes(const Handle(TColgp_HArray1OfXYZ)& HNodes) |
111 | { myHNodes = HNodes; } |
112 | |
113 | //======================================================================= |
114 | //function : HTData |
115 | //purpose : |
116 | //======================================================================= |
117 | |
118 | void HLRAlgo_PolyData::HTData(const Handle(HLRAlgo_HArray1OfTData)& HTData) |
119 | { myHTData = HTData; } |
120 | |
121 | //======================================================================= |
122 | //function : HPHDat |
123 | //purpose : |
124 | //======================================================================= |
125 | |
126 | void HLRAlgo_PolyData::HPHDat(const Handle(HLRAlgo_HArray1OfPHDat)& HPHDat) |
127 | { myHPHDat = HPHDat; } |
128 | |
129 | //======================================================================= |
130 | //function : UpdateGlobalMinMax |
131 | //purpose : |
132 | //======================================================================= |
133 | |
134 | void |
135 | HLRAlgo_PolyData::UpdateGlobalMinMax (const Standard_Address TotMinMax) |
136 | { |
137 | Standard_Integer i; |
138 | Standard_Real X1,X2,X3,Y1,Y2,Y3,Z1,Z2,Z3; |
139 | const TColgp_Array1OfXYZ& Nodes = myHNodes->Array1(); |
140 | HLRAlgo_Array1OfTData& TData = myHTData->ChangeArray1(); |
141 | Standard_Integer nbT = TData.Upper(); |
142 | HLRAlgo_TriangleData* TD = &(TData.ChangeValue(1)); |
143 | |
144 | for (i = 1; i <= nbT; i++) { |
145 | const Standard_Address TriIndices = TD->Indices(); |
146 | if (TriFlags & FMskHiding) { |
147 | const gp_XYZ& P1 = Nodes(TriNode1); |
148 | const gp_XYZ& P2 = Nodes(TriNode2); |
149 | const gp_XYZ& P3 = Nodes(TriNode3); |
150 | X1 = P1.X(); |
151 | Y1 = P1.Y(); |
152 | Z1 = P1.Z(); |
153 | X2 = P2.X(); |
154 | Y2 = P2.Y(); |
155 | Z2 = P2.Z(); |
156 | X3 = P3.X(); |
157 | Y3 = P3.Y(); |
158 | Z3 = P3.Z(); |
159 | if (TotXMin > X1) TotXMin = X1; |
160 | else if (TotXMax < X1) TotXMax = X1; |
161 | if (TotYMin > Y1) TotYMin = Y1; |
162 | else if (TotYMax < Y1) TotYMax = Y1; |
163 | if (TotZMin > Z1) TotZMin = Z1; |
164 | else if (TotZMax < Z1) TotZMax = Z1; |
165 | if (TotXMin > X2) TotXMin = X2; |
166 | else if (TotXMax < X2) TotXMax = X2; |
167 | if (TotYMin > Y2) TotYMin = Y2; |
168 | else if (TotYMax < Y2) TotYMax = Y2; |
169 | if (TotZMin > Z2) TotZMin = Z2; |
170 | else if (TotZMax < Z2) TotZMax = Z2; |
171 | if (TotXMin > X3) TotXMin = X3; |
172 | else if (TotXMax < X3) TotXMax = X3; |
173 | if (TotYMin > Y3) TotYMin = Y3; |
174 | else if (TotYMax < Y3) TotYMax = Y3; |
175 | if (TotZMin > Z3) TotZMin = Z3; |
176 | else if (TotZMax < Z3) TotZMax = Z3; |
177 | } |
178 | TD++; |
179 | } |
180 | } |
181 | |
182 | //======================================================================= |
183 | //function : HideByPolyData |
184 | //purpose : |
185 | //======================================================================= |
186 | |
187 | void HLRAlgo_PolyData::HideByPolyData (const Standard_Address Coordinates, |
188 | const Standard_Address RealPtr, |
189 | const Standard_Address Indices, |
190 | const Standard_Boolean HidingShell, |
191 | HLRAlgo_EdgeStatus& status) |
192 | { |
193 | if (((MaxFac - MinSeg) & 0x80100200) == 0 && |
194 | ((MaxSeg - MinFac) & 0x80100000) == 0) { |
195 | HLRAlgo_Array1OfPHDat& PHDat = myHPHDat->ChangeArray1(); |
196 | const HLRAlgo_Array1OfTData& TData = myHTData->Array1(); |
197 | Standard_Real d1,d2; |
198 | Standard_Boolean NotConnex,BooleanPtr[3]; |
199 | Standard_Address PlanPtr,MinMaxPtr,TriIndices; |
200 | Standard_Integer h,h2 = PHDat.Upper(); |
201 | HLRAlgo_PolyHidingData* PH = &(PHDat(1)); |
202 | |
203 | for (h = 1; h <= h2; h++) { |
204 | MinMaxPtr = PH->IndexAndMinMax(); |
205 | if (((MaxTri - MinSeg) & 0x80100200) == 0 && |
206 | ((MaxSeg - MinTri) & 0x80100000) == 0) { |
207 | TriIndices = TData(IndexTri).Indices(); |
208 | NotConnex = Standard_True; |
209 | if (HidingShell) { |
210 | if (FIndex == FaceConex1) { |
211 | if (Face1Pt1 == TriNode1) |
212 | NotConnex = Face1Pt2 != TriNode2 && Face1Pt2 != TriNode3; |
213 | else if (Face1Pt1 == TriNode2) |
214 | NotConnex = Face1Pt2 != TriNode3 && Face1Pt2 != TriNode1; |
215 | else if (Face1Pt1 == TriNode3) |
216 | NotConnex = Face1Pt2 != TriNode1 && Face1Pt2 != TriNode2; |
217 | } |
218 | else if (FIndex == FaceConex2) { |
219 | if (Face2Pt1 == TriNode1) |
220 | NotConnex = Face2Pt2 != TriNode2 && Face2Pt2 != TriNode3; |
221 | else if (Face2Pt1 == TriNode2) |
222 | NotConnex = Face2Pt2 != TriNode3 && Face2Pt2 != TriNode1; |
223 | else if (Face2Pt1 == TriNode3) |
224 | NotConnex = Face2Pt2 != TriNode1 && Face2Pt2 != TriNode2; |
225 | } |
226 | } |
227 | if (NotConnex) { |
228 | PlanPtr = PH->Plan(); |
229 | d1 = APlan * PntXP1 + BPlan * PntYP1 + CPlan * PntZP1 - DPlan; |
230 | d2 = APlan * PntXP2 + BPlan * PntYP2 + CPlan * PntZP2 - DPlan; |
231 | if (d1 > Tolerance) { |
232 | if (d2 < -Tolerance) { |
233 | Param = d1 / ( d1 - d2 ); |
234 | HdBef = Standard_False; |
235 | Crosi = Standard_True; |
236 | TFlag = TriFlags; |
237 | const TColgp_Array1OfXYZ& Nodes = myHNodes->Array1(); |
238 | const gp_XYZ & P1 = Nodes(TriNode1); |
239 | const gp_XYZ & P2 = Nodes(TriNode2); |
240 | const gp_XYZ & P3 = Nodes(TriNode3); |
241 | XV1 = P1.X(); |
242 | YV1 = P1.Y(); |
243 | XV2 = P2.X(); |
244 | YV2 = P2.Y(); |
245 | XV3 = P3.X(); |
246 | YV3 = P3.Y(); |
247 | HideByOneTriangle(Coordinates, |
248 | RealPtr, |
249 | &BooleanPtr, |
250 | PlanPtr, |
251 | status); |
252 | } |
253 | } |
254 | else if (d1 < -Tolerance) { |
255 | if (d2 > Tolerance) { |
256 | Param = d1 / ( d1 - d2 ); |
257 | HdBef = Standard_True; |
258 | Crosi = Standard_True; |
259 | TFlag = TriFlags; |
260 | const TColgp_Array1OfXYZ& Nodes = myHNodes->Array1(); |
261 | const gp_XYZ & P1 = Nodes(TriNode1); |
262 | const gp_XYZ & P2 = Nodes(TriNode2); |
263 | const gp_XYZ & P3 = Nodes(TriNode3); |
264 | XV1 = P1.X(); |
265 | YV1 = P1.Y(); |
266 | XV2 = P2.X(); |
267 | YV2 = P2.Y(); |
268 | XV3 = P3.X(); |
269 | YV3 = P3.Y(); |
270 | HideByOneTriangle(Coordinates, |
271 | RealPtr, |
272 | &BooleanPtr, |
273 | PlanPtr, |
274 | status); |
275 | } |
276 | else { |
277 | Crosi = Standard_False; |
278 | TFlag = TriFlags; |
279 | const TColgp_Array1OfXYZ& Nodes = myHNodes->Array1(); |
280 | const gp_XYZ & P1 = Nodes(TriNode1); |
281 | const gp_XYZ & P2 = Nodes(TriNode2); |
282 | const gp_XYZ & P3 = Nodes(TriNode3); |
283 | XV1 = P1.X(); |
284 | YV1 = P1.Y(); |
285 | XV2 = P2.X(); |
286 | YV2 = P2.Y(); |
287 | XV3 = P3.X(); |
288 | YV3 = P3.Y(); |
289 | HideByOneTriangle(Coordinates, |
290 | RealPtr, |
291 | &BooleanPtr, |
292 | PlanPtr, |
293 | status); |
294 | } |
295 | } |
296 | else if (d2 < -Tolerance) { |
297 | Crosi = Standard_False; |
298 | TFlag = TriFlags; |
299 | const TColgp_Array1OfXYZ& Nodes = myHNodes->Array1(); |
300 | const gp_XYZ & P1 = Nodes(TriNode1); |
301 | const gp_XYZ & P2 = Nodes(TriNode2); |
302 | const gp_XYZ & P3 = Nodes(TriNode3); |
303 | XV1 = P1.X(); |
304 | YV1 = P1.Y(); |
305 | XV2 = P2.X(); |
306 | YV2 = P2.Y(); |
307 | XV3 = P3.X(); |
308 | YV3 = P3.Y(); |
309 | HideByOneTriangle(Coordinates, |
310 | RealPtr, |
311 | &BooleanPtr, |
312 | PlanPtr, |
313 | status); |
314 | } |
315 | } |
316 | } |
317 | PH++; |
318 | } |
319 | } |
320 | } |
321 | |
322 | //======================================================================= |
323 | //function : HideByOneTriangle |
324 | //purpose : |
325 | //======================================================================= |
326 | |
327 | void HLRAlgo_PolyData:: |
328 | HideByOneTriangle (const Standard_Address Coordinates, |
329 | const Standard_Address RealPtr, |
330 | const Standard_Address BooleanPtr, |
331 | const Standard_Address , |
332 | HLRAlgo_EdgeStatus& status) |
333 | { |
334 | Standard_Boolean o[2],m[2]; |
335 | Standard_Integer l,n1=0,nn1,nn2,npi=-1,npiRej=0; |
336 | Standard_Real a,b,c,da,db,d1,d2,p[2]={0.,0.},pd1,pd2,pdp,pp,psta=0.,pend=1.; |
337 | Standard_Boolean CrosSeg; |
338 | |
339 | da = XV2 - XV1; |
340 | db = YV2 - YV1; |
341 | a = -db; |
342 | b = da; |
343 | c = sqrt( a * a + b * b); |
344 | a /= c; |
345 | b /= c; |
346 | c = a * XV1 + b * YV1; |
347 | d1 = a * PntXP1 + b * PntYP1 - c; |
348 | d2 = a * PntXP2 + b * PntYP2 - c; |
349 | if (d1 > Tolerance) { |
350 | if (d2 < -Tolerance) { |
351 | n1 = 2; |
352 | CrosSeg = Standard_True; |
353 | } |
354 | else |
355 | CrosSeg = Standard_False; |
356 | } |
357 | else if (d1 < -Tolerance) { |
358 | if (d2 > Tolerance) { |
359 | n1 = -1; |
360 | CrosSeg = Standard_True; |
361 | } |
362 | else return; |
363 | } |
364 | else { |
365 | if (d2 > Tolerance) |
366 | CrosSeg = Standard_False; |
367 | else if (d2 < -Tolerance) return; |
368 | else { |
369 | CrosSeg = Standard_False; |
370 | if (TrFlags & EMskGrALin1) { |
371 | pd1 = (PntXP1 - XV1) / da; |
372 | pd2 = (PntXP2 - XV1) / da; |
373 | } |
374 | else { |
375 | pd1 = (PntYP1 - YV1) / db; |
376 | pd2 = (PntYP2 - YV1) / db; |
377 | } |
378 | if (pd1 < -TolParam) nn1 = 1; |
379 | else if (pd1 < TolParam) nn1 = 2; |
380 | else if (pd1 - 1. < -TolParam) nn1 = 3; |
381 | else if (pd1 - 1. < TolParam) nn1 = 4; |
382 | else nn1 = 5; |
383 | if (pd2 < -TolParam) nn2 = 1; |
384 | else if (pd2 < TolParam) nn2 = 2; |
385 | else if (pd2 - 1. < -TolParam) nn2 = 3; |
386 | else if (pd2 - 1. < TolParam) nn2 = 4; |
387 | else nn2 = 5; |
388 | if (nn1 == 3) { |
389 | if (nn2 == 1) pend = pd1 / (pd1 - pd2); |
390 | else if (nn2 == 5) pend = (1. - pd1) / (pd2 - pd1); |
391 | } |
392 | else if (nn1 == 1) { |
393 | if (nn2 <= 2) return; |
394 | else { |
395 | psta = - pd1 / (pd2 - pd1); |
396 | if (nn2 == 5) pend = (1. - pd1) / (pd2 - pd1); |
397 | } |
398 | } |
399 | else if (nn1 == 5) { |
400 | if (nn2 >= 4) return; |
401 | else { |
402 | psta = (pd1 - 1.) / (pd1 - pd2); |
403 | if (nn2 == 1) pend = pd1 / (pd1 - pd2); |
404 | } |
405 | } |
406 | else if (nn1 == 2) { |
407 | if (nn2 == 1) return; |
408 | else if (nn2 == 5) pend = (1. - pd1) / (pd2 - pd1); |
409 | } |
410 | else if (nn1 == 4) { |
411 | if (nn2 == 5) return; |
412 | else if (nn2 == 1) pend = pd1 / (pd1 - pd2); |
413 | } |
414 | } |
415 | } |
416 | if (CrosSeg) { |
417 | Standard_Real ad1 = d1; |
418 | if (d1 < 0) ad1 = -d1; |
419 | Standard_Real ad2 = d2; |
420 | if (d2 < 0) ad2 = -d2; |
421 | pp = ad1 / ( ad1 + ad2 ); |
422 | if (TrFlags & EMskGrALin1) |
423 | pdp = (PntXP1 + (PntXP2 - PntXP1) * pp - XV1) / da; |
424 | else |
425 | pdp = (PntYP1 + (PntYP2 - PntYP1) * pp - YV1) / db; |
426 | Standard_Boolean OutSideP = Standard_False; |
427 | Standard_Boolean Multiple = Standard_False; |
428 | if (pdp < -TolParam) OutSideP = Standard_True; |
429 | else if (pdp < TolParam) { |
430 | Multiple = Standard_True; |
431 | |
432 | for (l = 0; l <= npi; l++) { |
433 | if (m[l]) { |
434 | OutSideP = Standard_True; |
435 | |
436 | if (o[l] != (Standard_Boolean)(n1 == -1)) { |
437 | if (l == 0 && npi == 1) { |
438 | p[0] = p[1]; |
439 | o[0] = o[1]; |
440 | m[0] = m[1]; |
441 | } |
442 | npi--; |
443 | npiRej++; |
444 | } |
445 | } |
446 | } |
447 | } |
448 | else if (pdp - 1. < -TolParam) {} |
449 | else if (pdp - 1. < TolParam) { |
450 | Multiple = Standard_True; |
451 | |
452 | for (l = 0; l <= npi; l++) { |
453 | if (m[l]) { |
454 | OutSideP = Standard_True; |
455 | if (o[l] != (Standard_Boolean)(n1 == -1)) { |
456 | if (l == 0 && npi == 1) { |
457 | p[0] = p[1]; |
458 | o[0] = o[1]; |
459 | m[0] = m[1]; |
460 | } |
461 | npi--; |
462 | npiRej++; |
463 | } |
464 | } |
465 | } |
466 | } |
467 | else OutSideP = Standard_True; |
468 | if (OutSideP) npiRej++; |
469 | else { |
470 | npi++; |
471 | if (npi < 2) { |
472 | p[npi] = pp; |
473 | o[npi] = n1 == -1; |
474 | m[npi] = Multiple; |
475 | } |
0797d9d3 |
476 | #ifdef OCCT_DEBUG |
7fd59977 |
477 | else if (ERROR) { |
478 | cout << " error : HLRAlgo_PolyData::HideByOneTriangle " << endl; |
479 | cout << " ( more than 2 points )." << endl; |
480 | } |
481 | #endif |
482 | } |
483 | } |
484 | |
485 | da = XV3 - XV2; |
486 | db = YV3 - YV2; |
487 | a = -db; |
488 | b = da; |
489 | c = sqrt(a * a + b * b); |
490 | a /= c; |
491 | b /= c; |
492 | c = a * XV2 + b * YV2; |
493 | d1 = a * PntXP1 + b * PntYP1 - c; |
494 | d2 = a * PntXP2 + b * PntYP2 - c; |
495 | if (d1 > Tolerance) { |
496 | if (d2 < -Tolerance) { |
497 | n1 = 2; |
498 | CrosSeg = Standard_True; |
499 | } |
500 | else |
501 | CrosSeg = Standard_False; |
502 | } |
503 | else if (d1 < -Tolerance) { |
504 | if (d2 > Tolerance) { |
505 | n1 = -1; |
506 | CrosSeg = Standard_True; |
507 | } |
508 | else return; |
509 | } |
510 | else { |
511 | if (d2 > Tolerance) |
512 | CrosSeg = Standard_False; |
513 | else if (d2 < -Tolerance) return; |
514 | else { |
515 | CrosSeg = Standard_False; |
516 | if (TrFlags & EMskGrALin2) { |
517 | pd1 = (PntXP1 - XV2) / da; |
518 | pd2 = (PntXP2 - XV2) / da; |
519 | } |
520 | else { |
521 | pd1 = (PntYP1 - YV2) / db; |
522 | pd2 = (PntYP2 - YV2) / db; |
523 | } |
524 | if (pd1 < -TolParam) nn1 = 1; |
525 | else if (pd1 < TolParam) nn1 = 2; |
526 | else if (pd1 - 1. < -TolParam) nn1 = 3; |
527 | else if (pd1 - 1. < TolParam) nn1 = 4; |
528 | else nn1 = 5; |
529 | if (pd2 < -TolParam) nn2 = 1; |
530 | else if (pd2 < TolParam) nn2 = 2; |
531 | else if (pd2 - 1. < -TolParam) nn2 = 3; |
532 | else if (pd2 - 1. < TolParam) nn2 = 4; |
533 | else nn2 = 5; |
534 | if (nn1 == 3) { |
535 | if (nn2 == 1) pend = pd1 / (pd1 - pd2); |
536 | else if (nn2 == 5) pend = (1. - pd1) / (pd2 - pd1); |
537 | } |
538 | else if (nn1 == 1) { |
539 | if (nn2 <= 2) return; |
540 | else { |
541 | psta = - pd1 / (pd2 - pd1); |
542 | if (nn2 == 5) pend = (1. - pd1) / (pd2 - pd1); |
543 | } |
544 | } |
545 | else if (nn1 == 5) { |
546 | if (nn2 >= 4) return; |
547 | else { |
548 | psta = (pd1 - 1.) / (pd1 - pd2); |
549 | if (nn2 == 1) pend = pd1 / (pd1 - pd2); |
550 | } |
551 | } |
552 | else if (nn1 == 2) { |
553 | if (nn2 == 1) return; |
554 | else if (nn2 == 5) pend = (1. - pd1) / (pd2 - pd1); |
555 | } |
556 | else if (nn1 == 4) { |
557 | if (nn2 == 5) return; |
558 | else if (nn2 == 1) pend = pd1 / (pd1 - pd2); |
559 | } |
560 | } |
561 | } |
562 | if (CrosSeg) { |
563 | Standard_Real ad1 = d1; |
564 | if (d1 < 0) ad1 = -d1; |
565 | Standard_Real ad2 = d2; |
566 | if (d2 < 0) ad2 = -d2; |
567 | pp = ad1 / ( ad1 + ad2 ); |
568 | if (TrFlags & EMskGrALin2) |
569 | pdp = (PntXP1 + (PntXP2 - PntXP1) * pp - XV2) / da; |
570 | else |
571 | pdp = (PntYP1 + (PntYP2 - PntYP1) * pp - YV2) / db; |
572 | Standard_Boolean OutSideP = Standard_False; |
573 | Standard_Boolean Multiple = Standard_False; |
574 | if (pdp < -TolParam) OutSideP = Standard_True; |
575 | else if (pdp < TolParam) { |
576 | Multiple = Standard_True; |
577 | |
578 | for (l = 0; l <= npi; l++) { |
579 | if (m[l]) { |
580 | OutSideP = Standard_True; |
581 | if (o[l] != (Standard_Boolean)(n1 == -1)) { |
582 | if (l == 0 && npi == 1) { |
583 | p[0] = p[1]; |
584 | o[0] = o[1]; |
585 | m[0] = m[1]; |
586 | } |
587 | npi--; |
588 | npiRej++; |
589 | } |
590 | } |
591 | } |
592 | } |
593 | else if (pdp - 1. < -TolParam) {} |
594 | else if (pdp - 1. < TolParam) { |
595 | Multiple = Standard_True; |
596 | |
597 | for (l = 0; l <= npi; l++) { |
598 | if (m[l]) { |
599 | OutSideP = Standard_True; |
600 | if (o[l] != (Standard_Boolean)(n1 == -1)) { |
601 | if (l == 0 && npi == 1) { |
602 | p[0] = p[1]; |
603 | o[0] = o[1]; |
604 | m[0] = m[1]; |
605 | } |
606 | npi--; |
607 | npiRej++; |
608 | } |
609 | } |
610 | } |
611 | } |
612 | else OutSideP = Standard_True; |
613 | if (OutSideP) npiRej++; |
614 | else { |
615 | npi++; |
616 | if (npi < 2) { |
617 | p[npi] = pp; |
618 | o[npi] = n1 == -1; |
619 | m[npi] = Multiple; |
620 | } |
0797d9d3 |
621 | #ifdef OCCT_DEBUG |
7fd59977 |
622 | else if (ERROR) { |
623 | cout << " error : HLRAlgo_PolyData::HideByOneTriangle " << endl; |
624 | cout << " ( more than 2 points )." << endl; |
625 | } |
626 | #endif |
627 | } |
628 | } |
629 | |
630 | da = XV1 - XV3; |
631 | db = YV1 - YV3; |
632 | a = -db; |
633 | b = da; |
634 | c = sqrt(a * a + b * b); |
635 | a /= c; |
636 | b /= c; |
637 | c = a * XV3 + b * YV3; |
638 | d1 = a * PntXP1 + b * PntYP1 - c; |
639 | d2 = a * PntXP2 + b * PntYP2 - c; |
640 | if (d1 > Tolerance) { |
641 | if (d2 < -Tolerance) { |
642 | n1 = 2; |
643 | CrosSeg = Standard_True; |
644 | } |
645 | else |
646 | CrosSeg = Standard_False; |
647 | } |
648 | else if (d1 < -Tolerance) { |
649 | if (d2 > Tolerance) { |
650 | n1 = -1; |
651 | CrosSeg = Standard_True; |
652 | } |
653 | else return; |
654 | } |
655 | else { |
656 | if (d2 > Tolerance) |
657 | CrosSeg = Standard_False; |
658 | else if (d2 < -Tolerance) return; |
659 | else { |
660 | CrosSeg = Standard_False; |
661 | if (TrFlags & EMskGrALin3) { |
662 | pd1 = (PntXP1 - XV3) / da; |
663 | pd2 = (PntXP2 - XV3) / da; |
664 | } |
665 | else { |
666 | pd1 = (PntYP1 - YV3) / db; |
667 | pd2 = (PntYP2 - YV3) / db; |
668 | } |
669 | if (pd1 < -TolParam) nn1 = 1; |
670 | else if (pd1 < TolParam) nn1 = 2; |
671 | else if (pd1 - 1. < -TolParam) nn1 = 3; |
672 | else if (pd1 - 1. < TolParam) nn1 = 4; |
673 | else nn1 = 5; |
674 | if (pd2 < -TolParam) nn2 = 1; |
675 | else if (pd2 < TolParam) nn2 = 2; |
676 | else if (pd2 - 1. < -TolParam) nn2 = 3; |
677 | else if (pd2 - 1. < TolParam) nn2 = 4; |
678 | else nn2 = 5; |
679 | if (nn1 == 3) { |
680 | if (nn2 == 1) pend = pd1 / (pd1 - pd2); |
681 | else if (nn2 == 5) pend = (1. - pd1) / (pd2 - pd1); |
682 | } |
683 | else if (nn1 == 1) { |
684 | if (nn2 <= 2) return; |
685 | else { |
686 | psta = - pd1 / (pd2 - pd1); |
687 | if (nn2 == 5) pend = (1. - pd1) / (pd2 - pd1); |
688 | } |
689 | } |
690 | else if (nn1 == 5) { |
691 | if (nn2 >= 4) return; |
692 | else { |
693 | psta = (pd1 - 1.) / (pd1 - pd2); |
694 | if (nn2 == 1) pend = pd1 / (pd1 - pd2); |
695 | } |
696 | } |
697 | else if (nn1 == 2) { |
698 | if (nn2 == 1) return; |
699 | else if (nn2 == 5) pend = (1. - pd1) / (pd2 - pd1); |
700 | } |
701 | else if (nn1 == 4) { |
702 | if (nn2 == 5) return; |
703 | else if (nn2 == 1) pend = pd1 / (pd1 - pd2); |
704 | } |
705 | } |
706 | } |
707 | if (CrosSeg) { |
708 | Standard_Real ad1 = d1; |
709 | if (d1 < 0) ad1 = -d1; |
710 | Standard_Real ad2 = d2; |
711 | if (d2 < 0) ad2 = -d2; |
712 | pp = ad1 / ( ad1 + ad2 ); |
713 | if (TrFlags & EMskGrALin3) |
714 | pdp = (PntXP1 + (PntXP2 - PntXP1) * pp - XV3) / da; |
715 | else |
716 | pdp = (PntYP1 + (PntYP2 - PntYP1) * pp - YV3) / db; |
717 | Standard_Boolean OutSideP = Standard_False; |
718 | Standard_Boolean Multiple = Standard_False; |
719 | if (pdp < -TolParam) OutSideP = Standard_True; |
720 | else if (pdp < TolParam) { |
721 | Multiple = Standard_True; |
722 | |
723 | for (l = 0; l <= npi; l++) { |
724 | if (m[l]) { |
725 | OutSideP = Standard_True; |
726 | if (o[l] != (Standard_Boolean)(n1 == -1)) { |
727 | if (l == 0 && npi == 1) { |
728 | p[0] = p[1]; |
729 | o[0] = o[1]; |
730 | m[0] = m[1]; |
731 | } |
732 | npi--; |
733 | npiRej++; |
734 | } |
735 | } |
736 | } |
737 | } |
738 | else if (pdp - 1. < -TolParam) {} |
739 | else if (pdp - 1. < TolParam) { |
740 | Multiple = Standard_True; |
741 | |
742 | for (l = 0; l <= npi; l++) { |
743 | if (m[l]) { |
744 | OutSideP = Standard_True; |
745 | if (o[l] != (Standard_Boolean)(n1 == -1)) { |
746 | if (l == 0 && npi == 1) { |
747 | p[0] = p[1]; |
748 | o[0] = o[1]; |
749 | m[0] = m[1]; |
750 | } |
751 | npi--; |
752 | npiRej++; |
753 | } |
754 | } |
755 | } |
756 | } |
757 | else OutSideP = Standard_True; |
758 | if (OutSideP) npiRej++; |
759 | else { |
760 | npi++; |
761 | if (npi < 2) { |
762 | p[npi] = pp; |
763 | o[npi] = n1 == -1; |
764 | m[npi] = Multiple; |
765 | } |
0797d9d3 |
766 | #ifdef OCCT_DEBUG |
7fd59977 |
767 | else if (ERROR) { |
768 | cout << " error : HLRAlgo_PolyData::HideByOneTriangle " << endl; |
769 | cout << " ( more than 2 points )." << endl; |
770 | } |
771 | #endif |
772 | } |
773 | } |
774 | |
775 | if (npi == -1) { |
776 | if (npiRej >= 2) return; |
777 | } |
778 | else if (npi == 0) { |
779 | if (o[0]) { |
780 | psta = p[0]; |
781 | pend = 1.; |
782 | } |
783 | else { |
784 | psta = 0.; |
785 | pend = p[0]; |
786 | } |
787 | } |
788 | else if (npi == 1) { |
789 | if (p[0] > p[1]) { |
790 | psta = p[1]; |
791 | pend = p[0]; |
792 | } |
793 | else { |
794 | psta = p[0]; |
795 | pend = p[1]; |
796 | } |
797 | } |
798 | |
799 | if (Crossing) { |
800 | if (HideBefore) { |
801 | if (Param-psta < TolParam) return; |
802 | else if (Param < pend) pend = Param; |
803 | } |
804 | else { |
805 | if (pend-Param < TolParam) return; |
806 | else if (psta < Param) psta = Param; |
807 | } |
808 | } |
809 | |
810 | Standard_Boolean total; |
811 | if (psta > 0) total = psta < TolParam; |
812 | else total = psta > -TolParam; |
813 | if (total) { |
814 | Standard_Real pfin = pend - 1.; |
815 | if (pfin > 0) total = pfin < TolParam; |
816 | else total = pfin > -TolParam; |
817 | } |
818 | if (total) status.HideAll(); |
819 | else status.Hide(psta,(Standard_ShortReal)TolParam,pend,(Standard_ShortReal)TolParam, |
820 | Standard_False,Standard_False); |
821 | } |