0024096: Eliminate compiler warning C4505 in MSVC++ with warning level 4
[occt.git] / src / HLRBRep / HLRBRep_Data.cxx
CommitLineData
b311480e 1// Created on: 1997-04-17
2// Created by: Christophe MARION
3// Copyright (c) 1997-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//#define No_Standard_OutOfRange
23
24#define OCC191 // jfa 26/02/2002 Bug of cone display
25
26#include <HLRBRep_Data.ixx>
27
28#include <StdFail_UndefinedDerivative.hxx>
29#include <Precision.hxx>
30#include <gp_Dir.hxx>
31#include <Geom2d_Curve.hxx>
32#include <IntRes2d_IntersectionPoint.hxx>
33#include <IntRes2d_IntersectionSegment.hxx>
34#include <IntCurveSurface_IntersectionPoint.hxx>
35#include <IntCurveSurface_TransitionOnCurve.hxx>
36#include <TColStd_ListIteratorOfListOfInteger.hxx>
37#include <HLRAlgo.hxx>
38#include <HLRAlgo_ListIteratorOfInterferenceList.hxx>
39#include <HLRBRep_EdgeFaceTool.hxx>
40#include <ElCLib.hxx>
41#include <gp.hxx>
42#include <stdio.h>
43#include <BRepTopAdaptor_Tool.hxx>
44
45Standard_Integer nbOkIntersection;
46Standard_Integer nbPtIntersection;
47Standard_Integer nbSegIntersection;
48Standard_Integer nbClassification;
49Standard_Integer nbCal1Intersection; // pairs of unrejected edges
50Standard_Integer nbCal2Intersection; // true intersections (not vertex)
51Standard_Integer nbCal3Intersection; // Curve-Surface intersections
52
53static const Standard_Real CutLar = 2.e-1;
54static const Standard_Real CutBig = 1.e-1;
55
56//-- voir HLRAlgo.cxx
57
58#define MinShap1 ((Standard_Integer*)MinMaxShap)[ 0]
59#define MinShap2 ((Standard_Integer*)MinMaxShap)[ 1]
60#define MinShap3 ((Standard_Integer*)MinMaxShap)[ 2]
61#define MinShap4 ((Standard_Integer*)MinMaxShap)[ 3]
62#define MinShap5 ((Standard_Integer*)MinMaxShap)[ 4]
63#define MinShap6 ((Standard_Integer*)MinMaxShap)[ 5]
64#define MinShap7 ((Standard_Integer*)MinMaxShap)[ 6]
65#define MinShap8 ((Standard_Integer*)MinMaxShap)[ 7]
66
67#define MaxShap1 ((Standard_Integer*)MinMaxShap)[ 8]
68#define MaxShap2 ((Standard_Integer*)MinMaxShap)[ 9]
69#define MaxShap3 ((Standard_Integer*)MinMaxShap)[10]
70#define MaxShap4 ((Standard_Integer*)MinMaxShap)[11]
71#define MaxShap5 ((Standard_Integer*)MinMaxShap)[12]
72#define MaxShap6 ((Standard_Integer*)MinMaxShap)[13]
73#define MaxShap7 ((Standard_Integer*)MinMaxShap)[14]
74#define MaxShap8 ((Standard_Integer*)MinMaxShap)[15]
75
76#define MinFace1 ((Standard_Integer*)iFaceMinMax)[ 0]
77#define MinFace2 ((Standard_Integer*)iFaceMinMax)[ 1]
78#define MinFace3 ((Standard_Integer*)iFaceMinMax)[ 2]
79#define MinFace4 ((Standard_Integer*)iFaceMinMax)[ 3]
80#define MinFace5 ((Standard_Integer*)iFaceMinMax)[ 4]
81#define MinFace6 ((Standard_Integer*)iFaceMinMax)[ 5]
82#define MinFace7 ((Standard_Integer*)iFaceMinMax)[ 6]
83#define MinFace8 ((Standard_Integer*)iFaceMinMax)[ 7]
84
85#define MaxFace1 ((Standard_Integer*)iFaceMinMax)[ 8]
86#define MaxFace2 ((Standard_Integer*)iFaceMinMax)[ 9]
87#define MaxFace3 ((Standard_Integer*)iFaceMinMax)[10]
88#define MaxFace4 ((Standard_Integer*)iFaceMinMax)[11]
89#define MaxFace5 ((Standard_Integer*)iFaceMinMax)[12]
90#define MaxFace6 ((Standard_Integer*)iFaceMinMax)[13]
91#define MaxFace7 ((Standard_Integer*)iFaceMinMax)[14]
92#define MaxFace8 ((Standard_Integer*)iFaceMinMax)[15]
93
94#define MinWire1 ((Standard_Integer*)MinMaxWire)[ 0]
95#define MinWire2 ((Standard_Integer*)MinMaxWire)[ 1]
96#define MinWire3 ((Standard_Integer*)MinMaxWire)[ 2]
97#define MinWire4 ((Standard_Integer*)MinMaxWire)[ 3]
98#define MinWire5 ((Standard_Integer*)MinMaxWire)[ 4]
99#define MinWire6 ((Standard_Integer*)MinMaxWire)[ 5]
100#define MinWire7 ((Standard_Integer*)MinMaxWire)[ 6]
101#define MinWire8 ((Standard_Integer*)MinMaxWire)[ 7]
102
103#define MaxWire1 ((Standard_Integer*)MinMaxWire)[ 8]
104#define MaxWire2 ((Standard_Integer*)MinMaxWire)[ 9]
105#define MaxWire3 ((Standard_Integer*)MinMaxWire)[10]
106#define MaxWire4 ((Standard_Integer*)MinMaxWire)[11]
107#define MaxWire5 ((Standard_Integer*)MinMaxWire)[12]
108#define MaxWire6 ((Standard_Integer*)MinMaxWire)[13]
109#define MaxWire7 ((Standard_Integer*)MinMaxWire)[14]
110#define MaxWire8 ((Standard_Integer*)MinMaxWire)[15]
111
112#define MinLEdg1 ((Standard_Integer*)myLEMinMax)[ 0]
113#define MinLEdg2 ((Standard_Integer*)myLEMinMax)[ 1]
114#define MinLEdg3 ((Standard_Integer*)myLEMinMax)[ 2]
115#define MinLEdg4 ((Standard_Integer*)myLEMinMax)[ 3]
116#define MinLEdg5 ((Standard_Integer*)myLEMinMax)[ 4]
117#define MinLEdg6 ((Standard_Integer*)myLEMinMax)[ 5]
118#define MinLEdg7 ((Standard_Integer*)myLEMinMax)[ 6]
119#define MinLEdg8 ((Standard_Integer*)myLEMinMax)[ 7]
120
121#define MaxLEdg1 ((Standard_Integer*)myLEMinMax)[ 8]
122#define MaxLEdg2 ((Standard_Integer*)myLEMinMax)[ 9]
123#define MaxLEdg3 ((Standard_Integer*)myLEMinMax)[10]
124#define MaxLEdg4 ((Standard_Integer*)myLEMinMax)[11]
125#define MaxLEdg5 ((Standard_Integer*)myLEMinMax)[12]
126#define MaxLEdg6 ((Standard_Integer*)myLEMinMax)[13]
127#define MaxLEdg7 ((Standard_Integer*)myLEMinMax)[14]
128#define MaxLEdg8 ((Standard_Integer*)myLEMinMax)[15]
129
130#define MinFEdg1 ((Standard_Integer*)MinMaxFEdg)[ 0]
131#define MinFEdg2 ((Standard_Integer*)MinMaxFEdg)[ 1]
132#define MinFEdg3 ((Standard_Integer*)MinMaxFEdg)[ 2]
133#define MinFEdg4 ((Standard_Integer*)MinMaxFEdg)[ 3]
134#define MinFEdg5 ((Standard_Integer*)MinMaxFEdg)[ 4]
135#define MinFEdg6 ((Standard_Integer*)MinMaxFEdg)[ 5]
136#define MinFEdg7 ((Standard_Integer*)MinMaxFEdg)[ 6]
137#define MinFEdg8 ((Standard_Integer*)MinMaxFEdg)[ 7]
138
139#define MaxFEdg1 ((Standard_Integer*)MinMaxFEdg)[ 8]
140#define MaxFEdg2 ((Standard_Integer*)MinMaxFEdg)[ 9]
141#define MaxFEdg3 ((Standard_Integer*)MinMaxFEdg)[10]
142#define MaxFEdg4 ((Standard_Integer*)MinMaxFEdg)[11]
143#define MaxFEdg5 ((Standard_Integer*)MinMaxFEdg)[12]
144#define MaxFEdg6 ((Standard_Integer*)MinMaxFEdg)[13]
145#define MaxFEdg7 ((Standard_Integer*)MinMaxFEdg)[14]
146#define MaxFEdg8 ((Standard_Integer*)MinMaxFEdg)[15]
147
148#define MinVert1 MinMaxVert[ 0]
149#define MinVert2 MinMaxVert[ 1]
150#define MinVert3 MinMaxVert[ 2]
151#define MinVert4 MinMaxVert[ 3]
152#define MinVert5 MinMaxVert[ 4]
153#define MinVert6 MinMaxVert[ 5]
154#define MinVert7 MinMaxVert[ 6]
155#define MinVert8 MinMaxVert[ 7]
156#define MaxVert1 MinMaxVert[ 8]
157#define MaxVert2 MinMaxVert[ 9]
158#define MaxVert3 MinMaxVert[10]
159#define MaxVert4 MinMaxVert[11]
160#define MaxVert5 MinMaxVert[12]
161#define MaxVert6 MinMaxVert[13]
162#define MaxVert7 MinMaxVert[14]
163#define MaxVert8 MinMaxVert[15]
164
165#define DERIVEE_PREMIERE_NULLE 0.000000000001
166
167//-- ======================================================================
168//--
169
170#include <IntRes2d_TypeTrans.hxx>
171#include <IntRes2d_Position.hxx>
172#include <IntRes2d_IntersectionPoint.hxx>
173#include <IntRes2d_Transition.hxx>
174
175static long unsigned Mask32[32] = { 1,2,4,8, 16,32,64,128, 256,512,1024,2048,
176 4096,8192,16384,32768,
177 65536,131072,262144,524288,
178 1048576,2097152,4194304,8388608,
179 16777216,33554432,67108864,134217728,
180 268435456,536870912,1073741824,2147483648U};
181
182#define SIZEUV 8
183
184class TableauRejection {
185public:
186 Standard_Real **UV; //-- UV[i][j] contient le param (U sur Ci) de l intersection de Ci avec C(IndUV[j])
187 Standard_Integer **IndUV; //-- IndUV[i][j] = J0 -> Intersection entre i et J0
188 Standard_Integer *nbUV; //-- nbUV[i][j] nombre de valeurs pour la ligne i
189 Standard_Integer N;
190
191 long unsigned **TabBit;
192 Standard_Integer nTabBit;
193
194#ifdef DEB
195 Standard_Integer StNbLect,StNbEcr,StNbMax,StNbMoy,StNbMoyNonNul; //-- STAT
196#endif
197
198public:
199 //-- ============================================================
200 TableauRejection() {
201 N=0; nTabBit=0; UV=NULL; nbUV=NULL; IndUV=NULL; TabBit=NULL;
202#ifdef DEB
203 StNbLect=StNbEcr=StNbMax=StNbMoy=StNbMoyNonNul=0;
204#endif
205 }
206 //-- ============================================================
207 void SetDim(const Standard_Integer n) {
208#ifdef DEB
209 cout<<"\n@#@#@#@#@# SetDim "<<n<<endl;
210#endif
211 if(UV)
212 Destroy();
213#ifdef DEB
214 StNbLect=StNbEcr=StNbMax=StNbMoy=0;
215#endif
216 N=n;
217 UV = (Standard_Real **) malloc(N*sizeof(Standard_Real *));
218 IndUV = (Standard_Integer **) malloc(N*sizeof(Standard_Integer *));
219 nbUV = (Standard_Integer *) malloc(N*sizeof(Standard_Integer));
220// for(Standard_Integer i=0;i<N;i++) {
221 Standard_Integer i;
222 for( i=0;i<N;i++) {
223 UV[i]=(Standard_Real *) malloc(SIZEUV*sizeof(Standard_Real));
224 }
225 for(i=0;i<N;i++) {
226 IndUV[i]=(Standard_Integer *) malloc(SIZEUV*sizeof(Standard_Integer));
227 for(Standard_Integer k=0;k<SIZEUV;k++) {
228 IndUV[i][k]=-1;
229 }
230 nbUV[i]=SIZEUV;
231 }
232 InitTabBit(n);
233 }
234 //-- ============================================================
235 ~TableauRejection() {
236 //-- cout<<"\n Destructeur TableauRejection"<<endl;
237 Destroy();
238 }
239 //-- ============================================================
240 void Destroy() {
241#ifdef DEB
242 if(N) {
243 Standard_Integer nnn=0;
244 StNbMoy=StNbMoyNonNul=0;
245 StNbMax=0;
246 for(Standard_Integer i=0; i<N; i++) {
247 Standard_Integer nb=0;
248 for(Standard_Integer j=0; IndUV[i][j]!=-1 && j<nbUV[i]; j++,nb++);
249 if(nb>StNbMax) StNbMax=nb;
250 StNbMoy+=nb;
251 if(nb) { StNbMoyNonNul+=nb; nnn++; }
252 }
253
254 printf("\n----------------------------------------");
255 printf("\nNbLignes : %10d",N);
256 printf("\nNbLect : %10d",StNbLect);
257 printf("\nNbEcr : %10d",StNbEcr);
258 printf("\nNbMax : %10d",StNbMax);
259 printf("\nNbMoy : %10d / %10d -> %d",StNbMoy,N,StNbMoy/N);
260 if(nnn) {
261 printf("\nNbMoy !=0 : %10d / %10d -> %d",StNbMoyNonNul,nnn,StNbMoyNonNul/nnn);
262 }
263 printf("\n----------------------------------------\n");
264 }
265#endif
266 if(N) {
267 ResetTabBit(N);
268// for(Standard_Integer i=0;i<N;i++) {
269 Standard_Integer i;
270 for(i=0;i<N;i++) {
271 if(IndUV[i]) {
272 free(IndUV[i]);
273 IndUV[i]=NULL;
274 }
275 else { cout<<" IndUV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; }
276
277 }
278 for(i=0;i<N;i++) {
279 if(UV[i]) {
280 free(UV[i]);
281 UV[i]=NULL;
282 }
283 else { cout<<" UV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; }
284 }
285
286 if(nbUV) { free(nbUV); nbUV=NULL; } else { cout<<" nbUV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; }
287 if(IndUV) { free(IndUV); IndUV=NULL;} else { cout<<" IndUV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; }
288 if(UV) { free(UV); UV=NULL; } else { cout<<" UV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; }
289 N=0;
290 }
291 }
292 //-- ============================================================
293 void Set(Standard_Integer i0,Standard_Integer j0,const Standard_Real u) {
294 i0--; j0--;
295#ifdef DEB
296 StNbEcr++;
297#endif
298 Standard_Integer k=-1;
299// for(Standard_Integer i=0; k==-1 && i<nbUV[i0]; i++) {
300 Standard_Integer i;
301 for( i=0; k==-1 && i<nbUV[i0]; i++) {
302 if(IndUV[i0][i]==-1) {
303 k=i;
304 }
305 }
306 if(k==-1) { //-- on agrandit le tableau
307 //--
308 //-- declaration de la Nv ligne de taille : ancienne taille + SIZEUV
309 //--
310
311 //-- cout<<" \n alloc nbUV["<<i0<<"]="<<nbUV[i0];
312
313 Standard_Real *NvLigneUV = (Standard_Real *) malloc((nbUV[i0]+SIZEUV)*sizeof(Standard_Real));
314 Standard_Integer *NvLigneInd = (Standard_Integer *)malloc((nbUV[i0]+SIZEUV)*sizeof(Standard_Integer));
315 //--
316 //-- Recopie des anciennes valeurs ds la nouvelle ligne
317 //--
318 for(i=0;i<nbUV[i0];i++) {
319 NvLigneUV[i]=UV[i0][i];
320 NvLigneInd[i]=IndUV[i0][i];
321 }
322
323 //-- mise a jour de la nouvelle dimension ; free des anciennes lignes et affectation
324 k=nbUV[i0];
325 nbUV[i0]+=SIZEUV;
326 free(UV[i0]);
327 free(IndUV[i0]);
328 UV[i0]=NvLigneUV;
329 IndUV[i0]=NvLigneInd;
330 for(Standard_Integer kk=k ; kk<nbUV[i0];kk++) {
331 IndUV[i0][kk]=-1;
332 }
333 }
334 IndUV[i0][k]=j0;
335 UV[i0][k]=u;
336
337 //-- tri par ordre decroissant
338 Standard_Boolean TriOk;
339 do {
340 TriOk=Standard_True;
341 Standard_Integer im1=0;
342 for(i=1; IndUV[i0][i]!=-1 && i<nbUV[i0]; i++,im1++) {
343 if(IndUV[i0][i]>IndUV[i0][im1]) {
344 TriOk=Standard_False;
345 k=IndUV[i0][i]; IndUV[i0][i]=IndUV[i0][im1]; IndUV[i0][im1]=k;
346 Standard_Real t=UV[i0][i]; UV[i0][i]=UV[i0][im1]; UV[i0][im1]=t;
347 }
348 }
349 }
350 while(TriOk==Standard_False);
351 }
352 //-- ============================================================
353 Standard_Real Get(Standard_Integer i0,Standard_Integer j0) {
354 i0--; j0--;
355#ifdef DEB
356 StNbLect++;
357#endif
358
359//-- for(Standard_Integer i=0; IndUV[i0][i]!=-1 && i<nbUV[i0]; i++) {
360//-- if(IndUV[i0][i]==j0) {
361//-- return(UV[i0][i]);
362//-- }
363//-- }
364 //-- ordre decroissant
365 Standard_Integer a=0,b=nbUV[i0]-1,ab;
366 if(IndUV[i0][a]==-1) return(RealLast());
367 if(IndUV[i0][a]==j0) return(UV[i0][a]);
368 if(IndUV[i0][b]==j0) return(UV[i0][b]);
369 while((IndUV[i0][a]>j0) && (IndUV[i0][b]<j0)) {
370 ab=(a+b)>>1;
371 if(IndUV[i0][ab] < j0) { if(b==ab) return(RealLast()); else b=ab; }
372 else if(IndUV[i0][ab] > j0) { if(a==ab) return(RealLast()); else a=ab; }
373 else { return(UV[i0][ab]); }
374 }
375
376 return(RealLast());
377 }
378 //-- ============================================================
379 void ResetTabBit(const Standard_Integer nbedgs) {
380 //-- cout<<"\n ResetTabBit"<<endl;
381 if(TabBit) {
382 for(Standard_Integer i=0;i<nbedgs;i++) {
383 if(TabBit[i]) {
384 free(TabBit[i]);
385 TabBit[i]=NULL;
386 }
387 }
388 free(TabBit);
389 TabBit=NULL;
390 nTabBit=0;
391 }
392 }
393 //-- ============================================================
394 void InitTabBit(const Standard_Integer nbedgs) {
395 //-- cout<<"\n InitTabBit"<<endl;
396 if(TabBit && nTabBit) {
397 ResetTabBit(nTabBit);
398 }
399 TabBit = (long unsigned **) malloc((nbedgs)*sizeof(long unsigned *));
400 nTabBit=nbedgs;
401 Standard_Integer n=1+(nbedgs>>5);
402
403 for(Standard_Integer i=0;i<nbedgs;i++) {
404 TabBit[i]=(long unsigned *) malloc(n*sizeof(long unsigned));
405 for(Standard_Integer j=0;j<n;j++) {
406 TabBit[i][j]=0;
407 }
408 }
409 }
410 //-- ============================================================
411 void SetNoIntersection(Standard_Integer i0,Standard_Integer i1) {
412 // cout<<" SetNoIntersection : "<<i0<<" "<<i1<<endl;
413 i0--;
414 i1--;
415 if(i0>i1) {
416 Standard_Integer t = i0; i0=i1; i1=t;
417 }
418 Standard_Integer c=i1>>5;
419 Standard_Integer o=i1 & 31;
420 TabBit[i0][c] |= Mask32[o];
421 }
422 //-- ============================================================
423 Standard_Boolean NoIntersection(Standard_Integer i0,Standard_Integer i1) {
424 // cout<<" ??NoIntersection : "<<i0<<" "<<i1<<" ";
425 i0--;
426 i1--;
427 if(i0>i1) {
428 Standard_Integer t = i0; i0=i1; i1=t;
429 }
430 Standard_Integer c=i1>>5;
431 Standard_Integer o=i1 & 31;
432 if(TabBit[i0][c] & Mask32[o]) {
433 //-- cout<<" TRUE "<<endl;
434 return(Standard_True);
435 }
436 //-- cout<<" FALSE "<<endl;
437 return(Standard_False);
438 }
439 //-- ============================================================
440 void SetIntersection(Standard_Integer i0,
441 Standard_Integer i1,
442 const IntRes2d_IntersectionPoint& IP) {
443 const IntRes2d_Transition& T1=IP.TransitionOfFirst();
444 const IntRes2d_Transition& T2=IP.TransitionOfSecond();
445 if(T1.PositionOnCurve()==IntRes2d_Middle) {
446 if(T2.PositionOnCurve()==IntRes2d_Middle) {
447 if( T1.TransitionType()==IntRes2d_In
448 || T1.TransitionType()==IntRes2d_Out) {
449 Set(i0,i1,IP.ParamOnFirst());
450 Set(i1,i0,IP.ParamOnSecond());
451 }
452 }
453 }
454 }
455 //-- ============================================================
456 void GetSingleIntersection(Standard_Integer i0,Standard_Integer i1,
457 Standard_Real& u,Standard_Real& v ) {
458 u=Get(i0,i1);
459 if(u!=RealLast()) {
460 v=Get(i1,i0);
461 }
462 else {
463 v=RealLast();
464 }
465 }
466};
4e18e72a 467
7fd59977 468//-- ================================================================================
469
470
471//=======================================================================
7fd59977 472//function : AdjustParameter
473//purpose :
474//=======================================================================
475
476static void AdjustParameter (HLRBRep_EdgeData* E,
477 const Standard_Boolean h,
478 Standard_Real& p,
479 Standard_ShortReal& t)
480{
481 Standard_Real p1,p2;
482 Standard_ShortReal t1,t2;
483 if (h) {
484 E->Status().Bounds(p,t,p2,t2);
485 if (E->VerAtSta()) p = p + (p2 - p) * CutBig;
486 }
487 else {
488 E->Status().Bounds(p1,t1,p,t);
489 if (E->VerAtEnd()) p = p - (p - p1) * CutBig;
490 }
491}
492
493//=======================================================================
494//function : Data
495//purpose :
496//=======================================================================
497
498HLRBRep_Data::HLRBRep_Data (const Standard_Integer NV,
499 const Standard_Integer NE,
500 const Standard_Integer NF) :
501 myNbVertices (NV),
502 myNbEdges (NE),
503 myNbFaces (NF),
504 myEData (0,NE),
505 myFData (0,NF),
506 myEdgeIndices(0,NE),
507 myToler((Standard_ShortReal)1e-5),
508 myLLProps(2,Epsilon(1.)),
509 myFLProps(2,Epsilon(1.)),
510 mySLProps(2,Epsilon(1.)),
511 myHideCount(0)
512{
513 myReject=(void *)(new TableauRejection());
514 ((TableauRejection *)myReject)->SetDim(myNbEdges);
515}
516
517void HLRBRep_Data::Destroy() {
518 //-- cout<<"\n HLRBRep_Data::~HLRBRep_Data()"<<endl;
519 ((TableauRejection *)myReject)->Destroy();
520 delete ((TableauRejection *)myReject);
521}
522//=======================================================================
523//function : Write
524//purpose :
525//=======================================================================
526
527void HLRBRep_Data::Write (const Handle(HLRBRep_Data)& DS,
528 const Standard_Integer dv,
529 const Standard_Integer de,
530 const Standard_Integer df)
531{
7fd59977 532 Standard_Integer n1edge = DS->NbEdges();
533 Standard_Integer n1face = DS->NbFaces();
534
535 HLRBRep_EdgeData* ed = &(myEData .ChangeValue(de));
536 HLRBRep_EdgeData* e1 = &(DS->EDataArray().ChangeValue(0 ));
537 ed++;
538 e1++;
539
540 HLRBRep_FaceData* fd = &(myFData .ChangeValue(df));
541 HLRBRep_FaceData* f1 = &(DS->FDataArray().ChangeValue(0 ));
542 fd++;
543 f1++;
544
545 for (Standard_Integer iedge = 1; iedge <= n1edge; iedge++) {
546 *ed = *e1;
547
548 if (dv != 0) {
549 ed->VSta(ed->VSta() + dv);
550 ed->VEnd(ed->VEnd() + dv);
551 }
552
553 myEMap.Add(DS->EdgeMap().FindKey(iedge));
554
555 ed++;
556 e1++;
557 }
558
559 for (Standard_Integer iface = 1; iface <= n1face; iface++) {
560 *fd = *f1;
561
562 if (de != 0) {
563 const Handle(HLRAlgo_WiresBlock)& wb = fd->Wires();
564 Standard_Integer nw = wb->NbWires();
565
566 for (Standard_Integer iw = 1; iw <= nw; iw++) {
567 const Handle(HLRAlgo_EdgesBlock)& eb = wb->Wire(iw);
568 Standard_Integer ne = eb->NbEdges();
569
570 for (Standard_Integer ie = 1; ie <= ne; ie++)
571 eb->Edge(ie,eb->Edge(ie) + de);
572 }
573 }
574
575 myFMap.Add(DS->FaceMap().FindKey(iface));
576
577 fd++;
578 f1++;
579 }
580}
581
582//=======================================================================
583//function : Update
584//purpose :
585//=======================================================================
586
587void HLRBRep_Data::Update (const HLRAlgo_Projector& P)
588{
589 myProj = P;
590 const gp_Trsf& T = myProj.Transformation();
591 Standard_Integer i;
592 Standard_Real tolMinMax = 0;
593
594 Standard_Integer FaceMin[16],FaceMax[16],MinMaxFace[16];
595 Standard_Integer WireMin[16],WireMax[16],MinMaxWire[16];
596 Standard_Integer EdgeMin[16],EdgeMax[16],MinMaxEdge[16];
597 Standard_Real TotMin[16],TotMax[16];
598 HLRAlgo::InitMinMax(Precision::Infinite(),
599 (Standard_Address)TotMin,
600 (Standard_Address)TotMax);
601 HLRBRep_EdgeData* ed;
602 HLRBRep_FaceData* fd;
603 ed = &(myEData.ChangeValue(1));
604
605 // compute the global MinMax
606 // *************************
607// for (Standard_Integer edge = 1; edge <= myNbEdges; edge++) {
608 Standard_Integer edge;
609 for ( edge = 1; edge <= myNbEdges; edge++) {
610 HLRBRep_Curve& EC = ed->ChangeGeometry();
611 EC.Projector(&myProj);
612 Standard_Real enl =EC.Update((Standard_Address)TotMin,
613 (Standard_Address)TotMax);
614 if (enl > tolMinMax) tolMinMax = enl;
615 ed++;
616 }
617 HLRAlgo::EnlargeMinMax(tolMinMax,
618 (Standard_Address)TotMin,
619 (Standard_Address)TotMax);
620 Standard_Real d[16];
621 Standard_Real precad = -Precision::Infinite();
622
623 for (i = 0; i <= 15; i++) {
624 d[i] = TotMax[i] - TotMin[i];
625 if (precad < d[i]) precad = d[i];
626 }
627 myBigSize = precad;
628 precad = precad * 0.0005;
629
630 for (i = 0; i <= 15; i++)
631 mySurD[i] = 0x00007fff / (d[i] + precad);
632 precad = precad * 0.5;
633
634 for (i = 0; i <= 15; i++)
635 myDeca[i] = - TotMin[i] + precad;
636
637 Standard_Real tol;
638 Standard_Boolean ver1,ver2;
639
640 ed = &(myEData.ChangeValue(1));
641 fd = &(myFData.ChangeValue(1));
642
643 // update the edges
644 // ****************
645
646 for (edge = 1; edge <= myNbEdges; edge++) {
647
648 HLRBRep_Curve& EC = ed->ChangeGeometry();
649 HLRAlgo::InitMinMax(Precision::Infinite(),
650 (Standard_Address)TotMin,
651 (Standard_Address)TotMax);
652 tolMinMax = EC.UpdateMinMax((Standard_Address)TotMin,
653 (Standard_Address)TotMax);
654 tol = (Standard_Real)(ed->Tolerance());
655 ed->Vertical(TotMax[0] - TotMin[0] < tol &&
656 TotMax[1] - TotMin[1] < tol &&
657 TotMax[2] - TotMin[2] < tol &&
658 TotMax[3] - TotMin[3] < tol &&
659 TotMax[4] - TotMin[4] < tol &&
660 TotMax[5] - TotMin[5] < tol &&
661 TotMax[6] - TotMin[6] < tol );
662 HLRAlgo::EnlargeMinMax(tolMinMax,
663 (Standard_Address)TotMin,
664 (Standard_Address)TotMax);
665// Linux warning : assignment to `int' from `double'. Cast has been added.
666 EdgeMin[ 0] = (Standard_Integer)( (myDeca[ 0] + TotMin[ 0]) * mySurD[ 0]);
667 EdgeMax[ 0] = (Standard_Integer)( (myDeca[ 0] + TotMax[ 0]) * mySurD[ 0]);
668 EdgeMin[ 1] = (Standard_Integer)( (myDeca[ 1] + TotMin[ 1]) * mySurD[ 1]);
669 EdgeMax[ 1] = (Standard_Integer)( (myDeca[ 1] + TotMax[ 1]) * mySurD[ 1]);
670 EdgeMin[ 2] = (Standard_Integer)( (myDeca[ 2] + TotMin[ 2]) * mySurD[ 2]);
671 EdgeMax[ 2] = (Standard_Integer)( (myDeca[ 2] + TotMax[ 2]) * mySurD[ 2]);
672 EdgeMin[ 3] = (Standard_Integer)( (myDeca[ 3] + TotMin[ 3]) * mySurD[ 3]);
673 EdgeMax[ 3] = (Standard_Integer)( (myDeca[ 3] + TotMax[ 3]) * mySurD[ 3]);
674 EdgeMin[ 4] = (Standard_Integer)( (myDeca[ 4] + TotMin[ 4]) * mySurD[ 4]);
675 EdgeMax[ 4] = (Standard_Integer)( (myDeca[ 4] + TotMax[ 4]) * mySurD[ 4]);
676 EdgeMin[ 5] = (Standard_Integer)( (myDeca[ 5] + TotMin[ 5]) * mySurD[ 5]);
677 EdgeMax[ 5] = (Standard_Integer)( (myDeca[ 5] + TotMax[ 5]) * mySurD[ 5]);
678 EdgeMin[ 6] = (Standard_Integer)( (myDeca[ 6] + TotMin[ 6]) * mySurD[ 6]);
679 EdgeMax[ 6] = (Standard_Integer)( (myDeca[ 6] + TotMax[ 6]) * mySurD[ 6]);
680 EdgeMin[ 7] = (Standard_Integer)( (myDeca[ 7] + TotMin[ 7]) * mySurD[ 7]);
681 EdgeMax[ 7] = (Standard_Integer)( (myDeca[ 7] + TotMax[ 7]) * mySurD[ 7]);
682 EdgeMin[ 8] = (Standard_Integer)( (myDeca[ 8] + TotMin[ 8]) * mySurD[ 8]);
683 EdgeMax[ 8] = (Standard_Integer)( (myDeca[ 8] + TotMax[ 8]) * mySurD[ 8]);
684 EdgeMin[ 9] = (Standard_Integer)( (myDeca[ 9] + TotMin[ 9]) * mySurD[ 9]);
685 EdgeMax[ 9] = (Standard_Integer)( (myDeca[ 9] + TotMax[ 9]) * mySurD[ 9]);
686 EdgeMin[10] = (Standard_Integer)( (myDeca[10] + TotMin[10]) * mySurD[10]);
687 EdgeMax[10] = (Standard_Integer)( (myDeca[10] + TotMax[10]) * mySurD[10]);
688 EdgeMin[11] = (Standard_Integer)( (myDeca[11] + TotMin[11]) * mySurD[11]);
689 EdgeMax[11] = (Standard_Integer)( (myDeca[11] + TotMax[11]) * mySurD[11]);
690 EdgeMin[12] = (Standard_Integer)( (myDeca[12] + TotMin[12]) * mySurD[12]);
691 EdgeMax[12] = (Standard_Integer)( (myDeca[12] + TotMax[12]) * mySurD[12]);
692 EdgeMin[13] = (Standard_Integer)( (myDeca[13] + TotMin[13]) * mySurD[13]);
693 EdgeMax[13] = (Standard_Integer)( (myDeca[13] + TotMax[13]) * mySurD[13]);
694 EdgeMin[14] = (Standard_Integer)( (myDeca[14] + TotMin[14]) * mySurD[14]);
695 EdgeMax[14] = (Standard_Integer)( (myDeca[14] + TotMax[14]) * mySurD[14]);
696 EdgeMin[15] = (Standard_Integer)( (myDeca[15] + TotMin[15]) * mySurD[15]);
697 EdgeMax[15] = (Standard_Integer)( (myDeca[15] + TotMax[15]) * mySurD[15]);
698
699 HLRAlgo::EncodeMinMax((Standard_Address)EdgeMin,
700 (Standard_Address)EdgeMax,
701 (Standard_Address)MinMaxEdge);
702 ed->UpdateMinMax((Standard_Address)MinMaxEdge);
703 if (ed->Vertical()) {
704 ver1 = Standard_True;
705 ver2 = Standard_True;
706 Standard_Integer vsta = ed->VSta();
707 Standard_Integer vend = ed->VEnd();
708 Standard_Boolean vout = ed->OutLVSta() || ed->OutLVEnd();
709 Standard_Boolean vcut = ed->CutAtSta() || ed->CutAtEnd();
710 HLRBRep_EdgeData* eb = &(myEData.ChangeValue(1));
711
712 for (Standard_Integer ebis = 1; ebis <= myNbEdges; ebis++) {
713 if (vsta == eb->VSta()) {
714 eb->VSta (vend);
715 eb->OutLVSta(vout);
716 eb->CutAtSta(vcut);
717 }
718 else if (vsta == eb->VEnd()) {
719 eb->VEnd (vend);
720 eb->OutLVEnd(vout);
721 eb->CutAtEnd(vcut);
722 }
723 eb++;
724 }
725 }
726 else {
727 gp_Pnt Pt;
728 gp_Vec Tg1,Tg2;
729 EC.D1(EC.Parameter3d(EC.FirstParameter()),Pt,Tg1);
730 EC.D1(EC.Parameter3d(EC.LastParameter ()),Pt,Tg2);
731 Tg1.Transform(T);
732 Tg2.Transform(T);
733 if (Abs(Tg1.X()) + Abs(Tg1.Y()) < myToler * 10) ver1 = Standard_True;
734 else {
735 gp_Dir Dir1(Tg1);
736 ver1 = Abs(Dir1.X()) + Abs(Dir1.Y()) < myToler * 10;
737 }
738 if (Abs(Tg2.X()) + Abs(Tg2.Y()) < myToler * 10) ver2 = Standard_True;
739 else {
740 gp_Dir Dir2(Tg2);
741 ver2 = Abs(Dir2.X()) + Abs(Dir2.Y()) < myToler * 10;
742 }
743 }
744 ed->VerAtSta(ed->Vertical() || ver1);
745 ed->VerAtEnd(ed->Vertical() || ver2);
746 ed->AutoIntersectionDone(Standard_True);
747 ed->Simple(Standard_True);
748 ed++;
749 }
750
751 // update the faces
752 // ****************
753
754 for (Standard_Integer face = 1; face <= myNbFaces; face++) {
755
756 HLRBRep_Surface& FS = fd->Geometry();
757 iFaceGeom = &(fd->Geometry());
758 mySLProps.SetSurface(iFaceGeom);
759 FS.Projector(&myProj);
760 iFaceType = FS.GetType();
761
762 // Is the face cut by an outline
763
764 Standard_Boolean cut = Standard_False;
765 Standard_Boolean withOutL = Standard_False;
766
767 for (myFaceItr1.InitEdge(*fd);
768 myFaceItr1.MoreEdge() && !cut && !withOutL;
769 myFaceItr1.NextEdge()) {
770 if (myFaceItr1.Internal()) {
771 withOutL = Standard_True;
772 cut = Standard_True;
773 }
774 else if (myFaceItr1.OutLine()) {
775 withOutL = Standard_True;
776 if (myFaceItr1.Double()) cut = Standard_True;
777 }
778 }
779 fd->Cut (cut);
780 fd->WithOutL(withOutL);
781
782 // Is the face simple = no auto-hiding
783 // not cut and simple surface
784
785 if (!withOutL &&
786 (iFaceType == GeomAbs_Plane ||
787 iFaceType == GeomAbs_Cylinder ||
788 iFaceType == GeomAbs_Cone ||
789 iFaceType == GeomAbs_Sphere ||
790 iFaceType == GeomAbs_Torus )) fd->Simple(Standard_True );
791 else fd->Simple(Standard_False);
792
793 fd->Plane (iFaceType == GeomAbs_Plane );
794 fd->Cylinder(iFaceType == GeomAbs_Cylinder);
795 fd->Cone (iFaceType == GeomAbs_Cone );
796 fd->Sphere (iFaceType == GeomAbs_Sphere );
797 fd->Torus (iFaceType == GeomAbs_Torus );
798 tol = (Standard_Real)(fd->Tolerance());
799 fd->Side(FS.IsSide(tol,myToler*10));
800 Standard_Boolean inverted = Standard_False;
801 if (fd->WithOutL() && !fd->Side()) {
0a768f56 802 //inverted = OrientOutLine(face,*fd);
7fd59977 803 OrientOthEdge(face,*fd);
804 }
805 if (fd->Side()) {
806 fd->Hiding(Standard_False);
807 fd->Back(Standard_False);
808 }
809 else if (!fd->WithOutL()) {
810 Standard_Real p,pu,pv,r;
811 fd->Back(Standard_False);
812 Standard_Boolean found = Standard_False;
813
814 for (myFaceItr1.InitEdge(*fd);
815 myFaceItr1.MoreEdge() && !found;
816 myFaceItr1.NextEdge()) {
817 myFE = myFaceItr1.Edge ();
818 myFEOri = myFaceItr1.Orientation();
819 myFEOutLine = myFaceItr1.OutLine ();
820 myFEInternal = myFaceItr1.Internal ();
821 myFEDouble = myFaceItr1.Double ();
822 HLRBRep_EdgeData* ed = &(myEData(myFE));
823 if (!myFEDouble &&
824 (myFEOri == TopAbs_FORWARD ||
825 myFEOri == TopAbs_REVERSED)) {
826 myFEGeom = &(ed->ChangeGeometry());
827 const HLRBRep_Curve& EC = ed->Geometry();
828 p = EC.Parameter3d((EC.LastParameter () +
829 EC.FirstParameter()) / 2);
830 if (HLRBRep_EdgeFaceTool::UVPoint(p,myFEGeom,iFaceGeom,pu,pv)) {
831 mySLProps.SetParameters(pu,pv);
832 gp_Pnt Pt;
833 Pt = EC.Value3D(p);
834#ifdef OCC191
835 if (mySLProps.IsNormalDefined())
836#endif
837 {
838 gp_Vec Nm = mySLProps.Normal();
839 Pt.Transform(T);
840 Nm.Transform(T);
841 if (myProj.Perspective()) {
842 r = Nm.Z() * myProj.Focus() -
843 ( Nm.X() * Pt.X() + Nm.Y() * Pt.Y() + Nm.Z() * Pt.Z() );
844 }
845 else r = Nm.Z();
846 if (Abs(r) > myToler*10) {
847 fd->Back( r < 0 );
848 found = Standard_True;
849 break;
850 }
851 }
852 }
853 }
854 }
855
856 if (!found) {
857 fd->Side(Standard_True);
858 fd->Hiding(Standard_False);
859 fd->Back(Standard_False);
860 }
861 else if (fd->Closed()) {
862 switch (fd->Orientation()) {
863 case TopAbs_REVERSED : fd->Hiding( fd->Back() ); break;
864 case TopAbs_FORWARD : fd->Hiding(!fd->Back() ); break;
865 case TopAbs_EXTERNAL : fd->Hiding(Standard_True ); break;
866 case TopAbs_INTERNAL : fd->Hiding(Standard_False); break;
867 }
868 }
869 else fd->Hiding(Standard_True);
870 }
871 else {
872 if (inverted) {
873 fd->Hiding(Standard_False);
874 fd->Back(Standard_True);
875 }
876 else {
877 fd->Hiding(Standard_True);
878 fd->Back(Standard_False);
879 }
880 }
881
882 Standard_Boolean FirstTime = Standard_True;
883
884 for (myFaceItr1.InitEdge(*fd);
885 myFaceItr1.MoreEdge();
886 myFaceItr1.NextEdge()) {
887 myFE = myFaceItr1.Edge();
888 HLRBRep_EdgeData* ed = &(myEData(myFE));
889 if (!fd->Simple()) ed->AutoIntersectionDone(Standard_False);
890 HLRAlgo::DecodeMinMax(ed->MinMax(),
891 (Standard_Address)EdgeMin,
892 (Standard_Address)EdgeMax);
893 if (myFaceItr1.BeginningOfWire())
894 HLRAlgo::CopyMinMax((Standard_Address)EdgeMin,
895 (Standard_Address)EdgeMax,
896 (Standard_Address)WireMin,
897 (Standard_Address)WireMax);
898 else
899 HLRAlgo::AddMinMax((Standard_Address)EdgeMin,
900 (Standard_Address)EdgeMax,
901 (Standard_Address)WireMin,
902 (Standard_Address)WireMax);
903 if (myFaceItr1.EndOfWire()) {
904 HLRAlgo::EncodeMinMax((Standard_Address)WireMin,
905 (Standard_Address)WireMax,
906 (Standard_Address)MinMaxWire);
907 myFaceItr1.Wire()->UpdateMinMax((Standard_Address)MinMaxWire);
908 if (FirstTime) {
909 FirstTime = Standard_False;
910 HLRAlgo::CopyMinMax((Standard_Address)WireMin,
911 (Standard_Address)WireMax,
912 (Standard_Address)FaceMin,
913 (Standard_Address)FaceMax);
914 }
915 else
916 HLRAlgo::AddMinMax((Standard_Address)WireMin,
917 (Standard_Address)WireMax,
918 (Standard_Address)FaceMin,
919 (Standard_Address)FaceMax);
920 }
921 }
922 HLRAlgo::EncodeMinMax((Standard_Address)FaceMin,
923 (Standard_Address)FaceMax,
924 (Standard_Address)MinMaxFace);
925 fd->Wires()->UpdateMinMax((Standard_Address)MinMaxFace);
926 fd->Size(HLRAlgo::SizeBox(FaceMin,FaceMax));
927 fd++;
928 }
929}
930
931//=======================================================================
932//function : InitBoundSort
933//purpose :
934//=======================================================================
935
936void
937HLRBRep_Data::InitBoundSort (const Standard_Address MinMaxTot,
938 const Standard_Integer e1,
939 const Standard_Integer e2)
940{
941 myNbrSortEd = 0;
942 HLRBRep_EdgeData* ed = &(myEData(e1));
943 Standard_Address MinMaxShap = MinMaxTot;
944
945 for (Standard_Integer e = e1; e <= e2; e++) {
946 if (!ed->Status().AllHidden()) {
947 myLEMinMax = ed->MinMax();
948 if (((MaxShap1 - MinLEdg1) & 0x80008000) == 0 &&
949 ((MaxLEdg1 - MinShap1) & 0x80008000) == 0 &&
950 ((MaxShap2 - MinLEdg2) & 0x80008000) == 0 &&
951 ((MaxLEdg2 - MinShap2) & 0x80008000) == 0 &&
952 ((MaxShap3 - MinLEdg3) & 0x80008000) == 0 &&
953 ((MaxLEdg3 - MinShap3) & 0x80008000) == 0 &&
954 ((MaxShap4 - MinLEdg4) & 0x80008000) == 0 &&
955 ((MaxLEdg4 - MinShap4) & 0x80008000) == 0 &&
956 ((MaxShap5 - MinLEdg5) & 0x80008000) == 0 &&
957 ((MaxLEdg5 - MinShap5) & 0x80008000) == 0 &&
958 ((MaxShap6 - MinLEdg6) & 0x80008000) == 0 &&
959 ((MaxLEdg6 - MinShap6) & 0x80008000) == 0 &&
960 ((MaxShap7 - MinLEdg7) & 0x80008000) == 0 &&
961 ((MaxLEdg7 - MinShap7) & 0x80008000) == 0 &&
962 ((MaxShap8 - MinLEdg8) & 0x80008000) == 0) { //- rejection en z
963 myNbrSortEd++;
964 myEdgeIndices(myNbrSortEd) = e;
965 }
966 }
967 ed++;
968 }
969}
970
971//=======================================================================
972//function : InitEdge
973//purpose :
974//=======================================================================
975void HLRBRep_Data::InitEdge (const Standard_Integer FI,
976 BRepTopAdaptor_MapOfShapeTool& MST)
977{
978 myHideCount++;
979 myHideCount++;
980
981 iFace = FI;
982 iFaceData = &myFData(iFace);
983 iFaceGeom = &(((HLRBRep_FaceData*)iFaceData)->Geometry());
984 iFaceBack = ((HLRBRep_FaceData*)iFaceData)->Back();
985 iFaceSimp = ((HLRBRep_FaceData*)iFaceData)->Simple();
986 iFaceMinMax = ((HLRBRep_FaceData*)iFaceData)->Wires()->MinMax();
987 iFaceType = ((HLRBRep_Surface*)iFaceGeom)->GetType();
988 iFaceTest = !iFaceSimp;
989 mySLProps.SetSurface(iFaceGeom);
990 myIntersector.Load(iFaceGeom);
991
992
993 HLRBRep_Surface *p1 = (HLRBRep_Surface*)iFaceGeom;
994 const BRepAdaptor_Surface& bras=p1->Surface();
995
996
997 const TopoDS_Face& topodsface=bras.Face();
998
999
1000
1001
1002 if(MST.IsBound(topodsface)) {
1003 BRepTopAdaptor_Tool& BRT = MST.ChangeFind(topodsface);
1004 myClassifier = BRT.GetTopolTool();
1005 }
1006 else {
1007 BRepTopAdaptor_Tool BRT(topodsface,Precision::PConfusion());
1008 MST.Bind(topodsface,BRT);
1009 myClassifier = BRT.GetTopolTool();
1010 }
1011
1012 if (iFaceTest) {
1013 iFaceSmpl = !((HLRBRep_FaceData*)iFaceData)->Cut();
1014 myFaceItr2.InitEdge(*((HLRBRep_FaceData*)iFaceData));
1015 }
1016 else {
1017
1018 for (myFaceItr1.InitEdge(*((HLRBRep_FaceData*)iFaceData));
1019 myFaceItr1.MoreEdge();
1020 myFaceItr1.NextEdge()) {
1021 myFE = myFaceItr1.Edge(); // edges of a simple hiding
1022 myEData(myFE).HideCount(myHideCount-1); // face must be jumped.
1023 }
1024 myCurSortEd = 1;
1025 }
1026 NextEdge(Standard_False);
1027}
1028
1029//=======================================================================
1030//function : MoreEdge
1031//purpose :
1032//=======================================================================
1033
1034Standard_Boolean HLRBRep_Data::MoreEdge ()
1035{
1036
1037
1038 if (iFaceTest) {
1039 if (myFaceItr2.MoreEdge()) { // all edges must be tested if
1040 myLE = myFaceItr2.Edge (); // the face is not a simple
1041 myLEOutLine = myFaceItr2.OutLine (); // one.
1042 myLEInternal = myFaceItr2.Internal();
1043 myLEDouble = myFaceItr2.Double ();
1044 myLEIsoLine = myFaceItr2.IsoLine ();
1045 myLEData = &myEData(myLE);
1046 myLEGeom = &(((HLRBRep_EdgeData*)myLEData)->ChangeGeometry());
1047 myLEMinMax = ((HLRBRep_EdgeData*)myLEData)->MinMax();
1048 myLETol = ((HLRBRep_EdgeData*)myLEData)->Tolerance();
1049 myLEType = ((HLRBRep_Curve *)myLEGeom)->GetType();
1050 if (!myLEDouble)
1051 ((HLRBRep_EdgeData*)myLEData)->HideCount(myHideCount-1);
1052 return Standard_True;
1053 }
1054 else {
1055 iFaceTest = Standard_False; // at the end of the test
1056 iFaceSimp = iFaceSmpl; // we know if it is a simple face
1057 ((HLRBRep_FaceData*)iFaceData)->Simple(iFaceSimp);
1058 myCurSortEd = 1;
1059 NextEdge(Standard_False);
1060 }
1061 }
1062 return myCurSortEd <= myNbrSortEd;
1063}
1064//=======================================================================
1065//function : NextEdge
1066//purpose :
1067//=======================================================================
1068
1069void HLRBRep_Data::NextEdge (const Standard_Boolean skip)
1070{
1071
1072 if (skip) {
1073 if (iFaceTest) myFaceItr2.NextEdge();
1074 else myCurSortEd++;
1075 }
1076 if (!MoreEdge()) return;
1077 if (iFaceTest) {
1078 myLE = myFaceItr2.Edge ();
1079 myLEOutLine = myFaceItr2.OutLine ();
1080 myLEInternal = myFaceItr2.Internal();
1081 myLEDouble = myFaceItr2.Double ();
1082 myLEIsoLine = myFaceItr2.IsoLine ();
1083 myLEData = &myEData(myLE);
1084 myLEGeom = &(((HLRBRep_EdgeData*)myLEData)->ChangeGeometry());
1085 myLEMinMax = ((HLRBRep_EdgeData*)myLEData)->MinMax();
1086 myLETol = ((HLRBRep_EdgeData*)myLEData)->Tolerance();
1087 myLEType = ((HLRBRep_Curve *)myLEGeom)->GetType();
1088 if (((HLRBRep_EdgeData*)myLEData)->Vertical() ||
1089 (myLEDouble &&
1090 ((HLRBRep_EdgeData*)myLEData)->HideCount() == myHideCount-1))
1091 NextEdge();
1092 ((HLRBRep_EdgeData*)myLEData)->HideCount(myHideCount-1);
1093 return;
1094 }
1095 else {
1096 myLE = Edge();
1097 myLEOutLine = Standard_False;
1098 myLEInternal = Standard_False;
1099 myLEDouble = Standard_False;
1100 myLEIsoLine = Standard_False;
1101 myLEData = &myEData(myLE);
1102 myLEGeom = &(((HLRBRep_EdgeData*)myLEData)->ChangeGeometry());
1103 myLEMinMax = ((HLRBRep_EdgeData*)myLEData)->MinMax();
1104 myLETol = ((HLRBRep_EdgeData*)myLEData)->Tolerance();
1105 myLEType = ((HLRBRep_Curve *)myLEGeom)->GetType();
1106 }
1107 if (((HLRBRep_EdgeData*)myLEData)->Vertical()) {
1108 NextEdge();
1109 return;
1110 }
1111 if (((HLRBRep_EdgeData*)myLEData)->HideCount() > myHideCount-2) {
1112 NextEdge();
1113 return;
1114 }
1115 if (((HLRBRep_EdgeData*)myLEData)->Status().AllHidden()) {
1116 NextEdge();
1117 return;
1118 }
1119 if (((MaxFace1 - MinLEdg1) & 0x80008000) != 0 ||
1120 ((MaxLEdg1 - MinFace1) & 0x80008000) != 0 ||
1121 ((MaxFace2 - MinLEdg2) & 0x80008000) != 0 ||
1122 ((MaxLEdg2 - MinFace2) & 0x80008000) != 0 ||
1123 ((MaxFace3 - MinLEdg3) & 0x80008000) != 0 ||
1124 ((MaxLEdg3 - MinFace3) & 0x80008000) != 0 ||
1125 ((MaxFace4 - MinLEdg4) & 0x80008000) != 0 ||
1126 ((MaxLEdg4 - MinFace4) & 0x80008000) != 0 ||
1127 ((MaxFace5 - MinLEdg5) & 0x80008000) != 0 ||
1128 ((MaxLEdg5 - MinFace5) & 0x80008000) != 0 ||
1129 ((MaxFace6 - MinLEdg6) & 0x80008000) != 0 ||
1130 ((MaxLEdg6 - MinFace6) & 0x80008000) != 0 ||
1131 ((MaxFace7 - MinLEdg7) & 0x80008000) != 0 ||
1132 ((MaxLEdg7 - MinFace7) & 0x80008000) != 0 ||
1133 ((MaxFace8 - MinLEdg8) & 0x80008000) != 0) { //-- rejection en z
1134 NextEdge();
1135 return;
1136 }
1137 if (((HLRBRep_Surface*)iFaceGeom)->IsAbove
1138 (iFaceBack,myLEGeom,(Standard_Real)myLETol)) {
1139 NextEdge();
1140 return;
1141 }
1142 return; // edge is OK
1143}
1144
1145//=======================================================================
1146//function : Edge
1147//purpose :
1148//=======================================================================
1149
1150Standard_Integer HLRBRep_Data::Edge () const
1151{
1152 if (iFaceTest) return myFaceItr2.Edge();
1153 else return myEdgeIndices(myCurSortEd);
1154}
1155
1156//=======================================================================
1157//function : InitInterference
1158//purpose :
1159//=======================================================================
1160
1161void HLRBRep_Data::InitInterference ()
1162{
1163 myLLProps.SetCurve(myLEGeom);
1164 myFaceItr1.InitEdge(*((HLRBRep_FaceData*)iFaceData));
1165 myNbPoints = myNbSegments = iInterf = 0;
1166 NextInterference();
1167}
1168
1169//=======================================================================
1170//function : NextInterference
1171//purpose :
1172//=======================================================================
1173
1174void HLRBRep_Data::NextInterference ()
1175{
1176 // are there more intersections on the current edge
1177 iInterf++;
1178// Standard_Integer miniWire1,miniWire2;
1179// Standard_Integer maxiWire1,maxiWire2,maxiWire3,maxiWire4;
1180
1181 while (!MoreInterference() && myFaceItr1.MoreEdge()) {
1182
1183 // rejection of current wire
1184 if (myFaceItr1.BeginningOfWire()) {
1185 Standard_Address MinMaxWire = myFaceItr1.Wire()->MinMax();
1186 if (((MaxWire1 - MinLEdg1) & 0x80008000) != 0 ||
1187 ((MaxLEdg1 - MinWire1) & 0x80008000) != 0 ||
1188 ((MaxWire2 - MinLEdg2) & 0x80008000) != 0 ||
1189 ((MaxLEdg2 - MinWire2) & 0x80008000) != 0 ||
1190 ((MaxWire3 - MinLEdg3) & 0x80008000) != 0 ||
1191 ((MaxLEdg3 - MinWire3) & 0x80008000) != 0 ||
1192 ((MaxWire4 - MinLEdg4) & 0x80008000) != 0 ||
1193 ((MaxLEdg4 - MinWire4) & 0x80008000) != 0 ||
1194 ((MaxWire5 - MinLEdg5) & 0x80008000) != 0 ||
1195 ((MaxLEdg5 - MinWire5) & 0x80008000) != 0 ||
1196 ((MaxWire6 - MinLEdg6) & 0x80008000) != 0 ||
1197 ((MaxLEdg6 - MinWire6) & 0x80008000) != 0 ||
1198 ((MaxWire7 - MinLEdg7) & 0x80008000) != 0 ||
1199 ((MaxLEdg7 - MinWire7) & 0x80008000) != 0 ||
1200 ((MaxWire8 - MinLEdg8) & 0x80008000) != 0) { //-- Rejection en Z
1201 myFaceItr1.SkipWire();
1202 continue;
1203 }
1204 }
1205 myFE = myFaceItr1.Edge();
1206 myFEOri = myFaceItr1.Orientation();
1207 myFEOutLine = myFaceItr1.OutLine ();
1208 myFEInternal = myFaceItr1.Internal ();
1209 myFEDouble = myFaceItr1.Double ();
1210 myFEData = &myEData(myFE);
1211 myFEGeom = &(((HLRBRep_EdgeData*)myFEData)->ChangeGeometry());
1212 myFETol = ((HLRBRep_EdgeData*)myFEData)->Tolerance();
1213 myFEType = ((HLRBRep_Curve *)myFEGeom)->GetType();
1214
1215
1216 if (myFEOri == TopAbs_FORWARD ||
1217 myFEOri == TopAbs_REVERSED) {
1218 // Edge from the boundary
1219 if (!((HLRBRep_EdgeData*)myFEData)->Vertical() && !myFEDouble) {
1220 // not a vertical edge and not a double Edge
1221 Standard_Address MinMaxFEdg = ((HLRBRep_EdgeData*)myFEData)->MinMax();
1222 //-- -----------------------------------------------------------------------
1223 //-- Max - Min doit etre positif pour toutes les directions
1224 //--
1225 //-- Rejection 1 (FEMax-LEMin)& 0x80008000 !=0
1226 //--
1227 //-- FE Min ........... FE Max
1228 //-- LE Min .... LE Max
1229 //--
1230 //-- Rejection 2 (LEMax-FEMin)& 0x80008000 !=0
1231 //-- FE Min ........... FE Max
1232 //-- LE Min .... LE Max
1233 //-- ----------------------------------------------------------------------
1234
1235 if(((TableauRejection *)myReject)->
1236 NoIntersection(myLE,myFE) == Standard_False) {
1237
1238
1239 if (((MaxFEdg1 - MinLEdg1) & 0x80008000) == 0 &&
1240 ((MaxLEdg1 - MinFEdg1) & 0x80008000) == 0 &&
1241 ((MaxFEdg2 - MinLEdg2) & 0x80008000) == 0 &&
1242 ((MaxLEdg2 - MinFEdg2) & 0x80008000) == 0 &&
1243 ((MaxFEdg3 - MinLEdg3) & 0x80008000) == 0 &&
1244 ((MaxLEdg3 - MinFEdg3) & 0x80008000) == 0 &&
1245 ((MaxFEdg4 - MinLEdg4) & 0x80008000) == 0 &&
1246 ((MaxLEdg4 - MinFEdg4) & 0x80008000) == 0 &&
1247 ((MaxFEdg5 - MinLEdg5) & 0x80008000) == 0 &&
1248 ((MaxLEdg5 - MinFEdg5) & 0x80008000) == 0 &&
1249 ((MaxFEdg6 - MinLEdg6) & 0x80008000) == 0 &&
1250 ((MaxLEdg6 - MinFEdg6) & 0x80008000) == 0 &&
1251 ((MaxFEdg7 - MinLEdg7) & 0x80008000) == 0 &&
1252 ((MaxLEdg7 - MinFEdg7) & 0x80008000) == 0 &&
1253 ((MaxFEdg8 - MinLEdg8) & 0x80008000) == 0) { //-- Rejection en Z
1254 // not rejected perform intersection
1255 Standard_Boolean rej = Standard_False;
1256 if (myLE == myFE) { // test if an auto-intersection is not usefull
1257 if (((HLRBRep_EdgeData*)myLEData)->AutoIntersectionDone()) {
1258 ((HLRBRep_EdgeData*)myLEData)->
1259 AutoIntersectionDone(Standard_True);
1260 if (((HLRBRep_EdgeData*)myLEData)->Simple()) {
1261 rej = Standard_True;
1262 }
1263 }
1264 }
1265 if (!rej) {
1266 nbCal1Intersection++;
1267 Standard_Boolean h1 = Standard_False;
1268 Standard_Boolean e1 = Standard_False;
1269 Standard_Boolean h2 = Standard_False;
1270 Standard_Boolean e2 = Standard_False;
1271 mySameVertex = Standard_False;
1272
1273 if (myLE == myFE) {
1274 myIntersected = Standard_True;
1275 mySameVertex = Standard_False;
1276 }
1277 else {
1278 myIntersected = Standard_True;
1279 if (SameVertex(Standard_True ,Standard_True )) {
1280 mySameVertex = Standard_True;
1281 h1 = Standard_True;
1282 h2 = Standard_True;
1283 }
1284 if (SameVertex(Standard_True ,Standard_False)) {
1285 mySameVertex = Standard_True;
1286 h1 = Standard_True;
1287 e2 = Standard_True;
1288 }
1289 if (SameVertex(Standard_False,Standard_True )) {
1290 mySameVertex = Standard_True;
1291 e1 = Standard_True;
1292 h2 = Standard_True;
1293 }
1294 if (SameVertex(Standard_False,Standard_False)) {
1295 mySameVertex = Standard_True;
1296 e1 = Standard_True;
1297 e2 = Standard_True;
1298 }
1299 }
1300
1301 myNbPoints = myNbSegments = 0;
1302 iInterf = 1;
1303
1304 if (myIntersected) { // compute real intersection
1305 nbCal2Intersection++;
1306
1307 Standard_Real da1 = 0;
1308 Standard_Real db1 = 0;
1309 Standard_Real da2 = 0;
1310 Standard_Real db2 = 0;
1311
1312 if (mySameVertex || myLE == myFE) {
1313 if (h1) da1 = CutLar;
1314 if (e1) db1 = CutLar;
1315 if (h2) da2 = CutLar;
1316 if (e2) db2 = CutLar;
1317 }
1318 Standard_Integer NoInter=0;
1319 if (myLE == myFE) {
1320 myIntersector.Perform(myLEData,da1,db1);
1321 }
1322 else {
1323 Standard_Real su,sv;
1324 ((TableauRejection *)myReject)->
1325 GetSingleIntersection(myLE,myFE,su,sv);
1326 if(su!=RealLast()) {
1327 myIntersector.SimulateOnePoint(myLEData,su,myFEData,sv);
1328 //-- cout<<"p";
1329 }
1330 else {
1331 myIntersector.Perform
1332 (myLE,myLEData,da1,db1,
1333 myFE,myFEData,da2,db2,mySameVertex);
1334 if(myIntersector.IsDone()) {
1335 if(myIntersector.NbPoints() == 1 &&
1336 myIntersector.NbSegments()==0) {
1337 ((TableauRejection *)myReject)->
1338 SetIntersection(myLE,myFE,myIntersector.Point(1));
1339 }
1340 }
1341 }
1342 NoInter=0;
1343 }
1344 if(NoInter) {
1345 myNbPoints = myNbSegments = 0;
1346 }
1347 else {
1348 if (myIntersector.IsDone()) {
1349 myNbPoints = myIntersector.NbPoints();
1350 myNbSegments = myIntersector.NbSegments();
1351 if ((myNbSegments + myNbPoints) > 0) {
1352 nbOkIntersection++;
1353 }
1354 else {
1355 ((TableauRejection *)myReject)->
1356 SetNoIntersection(myLE,myFE);
1357 }
1358 }
1359 else {
1360 myNbPoints = myNbSegments = 0;
1361#ifdef DEB
1362 cout << "HLRBRep_Data::NextInterference : ";
1363 if (myLE == myFE)
1364 cout << "Edge " << myLE
1365 << " : Intersection not done" << endl;
1366 else
1367 cout << "Edges " << myLE << " , " << myFE
1368 << " : Intersection not done" << endl;
1369#endif
1370 }
1371 }
1372 }
1373 nbPtIntersection += myNbPoints;
1374 nbSegIntersection += myNbSegments;
1375 }
1376 }
1377 else {
1378#if 0
1379 printf("\n Rejection myFE:%5d myLE:%5d\n",myFE,myLE);
1380#endif
1381 }
1382 }
1383 else {
1384 //-- cout<<"+";
1385 }
1386 }
1387 }
1388 // next edge in face
1389 myFaceItr1.NextEdge();
1390 }
1391}
1392
1393//=======================================================================
1394//function : RejectedInterference
1395//purpose :
1396//=======================================================================
1397
1398Standard_Boolean HLRBRep_Data::RejectedInterference ()
1399{
1400 if (iInterf <= myNbPoints) {
1401 return RejectedPoint(myIntersector.Point(iInterf),
1402 TopAbs_EXTERNAL,0);
1403 }
1404 else {
1405 Standard_Integer n = iInterf - myNbPoints;
1406 Standard_Boolean firstPoint = (n & 1) != 0;
1407 Standard_Integer nseg=n>>1;
1408 if (firstPoint)
1409 nseg++;
1410 Standard_Real pf = ((HLRBRep_Curve*)myLEGeom)->Parameter3d
1411 (myIntersector.Segment(nseg).FirstPoint().ParamOnFirst());
1412 Standard_Real pl = ((HLRBRep_Curve*)myLEGeom)->Parameter3d
1413 (myIntersector.Segment(nseg).LastPoint ().ParamOnFirst());
1414 if (pf > pl)
1415 firstPoint = !firstPoint;
1416
1417 if (firstPoint) {
1418 Standard_Boolean ret1 = RejectedPoint
1419 (myIntersector.Segment(nseg).FirstPoint(),TopAbs_FORWARD,nseg);
1420 return(ret1);
1421 }
1422 else {
1423 Standard_Boolean ret2 = RejectedPoint
1424 (myIntersector.Segment(nseg).LastPoint (),TopAbs_REVERSED,-nseg);
1425 return(ret2);
1426 }
1427 }
1428}
1429
1430//=======================================================================
1431//function : AboveInterference
1432//purpose :
1433//=======================================================================
1434
1435Standard_Boolean HLRBRep_Data::AboveInterference ()
1436{ return myAboveIntf; }
1437
1438//=======================================================================
1439//function : LocalLEGeometry2D
1440//purpose :
1441//=======================================================================
1442
1443void HLRBRep_Data::LocalLEGeometry2D (const Standard_Real Param,
1444 gp_Dir2d& Tg,
1445 gp_Dir2d& Nm,
1446 Standard_Real& Cu)
1447{
1448 myLLProps.SetParameter(Param);
1449 if (!myLLProps.IsTangentDefined())
1450 Standard_Failure::Raise("HLRBRep_Data::LocalGeometry2D");
1451 myLLProps.Tangent(Tg);
1452 Cu = myLLProps.Curvature();
1453 if (Cu > Epsilon(1.) && !Precision::IsInfinite(Cu)) myLLProps.Normal(Nm);
1454 else Nm = gp_Dir2d(-Tg.Y(),Tg.X());
1455}
1456
1457//=======================================================================
1458//function : LocalFEGeometry2D
1459//purpose :
1460//=======================================================================
1461
1462void HLRBRep_Data::LocalFEGeometry2D (const Standard_Integer FE,
1463 const Standard_Real Param,
1464 gp_Dir2d& Tg,
1465 gp_Dir2d& Nm,
1466 Standard_Real& Cu)
1467{
1468 myFLProps.SetCurve(&(myEData(FE).ChangeGeometry()));
1469 myFLProps.SetParameter(Param);
1470 if (!myFLProps.IsTangentDefined())
1471 Standard_Failure::Raise("HLRBRep_Data::LocalGeometry2D");
1472 myFLProps.Tangent(Tg);
1473 Cu = myFLProps.Curvature();
1474 if (Cu > Epsilon(1.) && !Precision::IsInfinite(Cu)) myFLProps.Normal(Nm);
1475 else Nm = gp_Dir2d(-Tg.Y(),Tg.X());
1476}
1477
1478//=======================================================================
1479//function : EdgeState
1480//purpose :
1481//=======================================================================
1482
1483void HLRBRep_Data::EdgeState (const Standard_Real p1,
733a0e55
S
1484 const Standard_Real p2,
1485 TopAbs_State& stbef,
1486 TopAbs_State& staft)
7fd59977 1487{
1488 // compute the state of The Edge near the Intersection
1489 // this method should give the states before and after
1490 // it should get the parameters on the surface
733a0e55 1491
7fd59977 1492 Standard_Real pu,pv;
733a0e55
S
1493 if (HLRBRep_EdgeFaceTool::UVPoint(p2,myFEGeom,iFaceGeom,pu,pv))
1494 {
7fd59977 1495 mySLProps.SetParameters(pu,pv);
733a0e55
S
1496 if (mySLProps.IsNormalDefined())
1497 {
1498 gp_Dir NrmFace = mySLProps.Normal();
1499
1500 gp_Pnt Pbid;
1501 gp_Vec TngEdge;
1502 ((HLRBRep_Curve*)myLEGeom)->D1(p1,Pbid,TngEdge);
1503
1504 const gp_Trsf& TI = myProj.InvertedTransformation();
1505 gp_Dir V;
1506 if (myProj.Perspective()) {
1507 gp_Pnt2d P2d;
1508 myProj.Project(Pbid,P2d);
1509 V = gp_Dir(P2d.X(),P2d.Y(),-myProj.Focus());
1510 }
1511 else {
1512 V = gp_Dir(0,0,-1);
1513 }
1514 V.Transform(TI);
1515 if (NrmFace.Dot(V) > 0.)
1516 NrmFace.Reverse();
1517
1518 const Standard_Real scal = (TngEdge.SquareMagnitude()>1.e-10)? NrmFace.Dot(gp_Dir(TngEdge)) : 0.;
1519
1520 if (scal > myToler*10) {stbef = TopAbs_IN ;staft = TopAbs_OUT;}
1521 else if (scal < -myToler*10) {stbef = TopAbs_OUT;staft = TopAbs_IN ;}
1522 else {stbef = TopAbs_ON ;staft = TopAbs_ON ;}
7fd59977 1523 }
1524 else {
733a0e55
S
1525 stbef = TopAbs_OUT;
1526 staft = TopAbs_OUT;
1527#ifdef DEB
1528 cout << "HLRBRep_Data::EdgeState : undefined" << endl;
1529#endif
7fd59977 1530 }
7fd59977 1531 }
1532 else {
1533 stbef = TopAbs_OUT;
1534 staft = TopAbs_OUT;
1535#ifdef DEB
733a0e55 1536 cout << "HLRBRep_Data::EdgeState : undefined" << endl;
7fd59977 1537#endif
1538 }
1539}
1540
1541//=======================================================================
1542//function : HidingStartLevel
1543//purpose :
1544//=======================================================================
1545
1546Standard_Integer
1547HLRBRep_Data::HidingStartLevel (const Standard_Integer E,
1548 const HLRBRep_EdgeData& ED,
1549 const HLRAlgo_InterferenceList& IL)
1550{
1551 Standard_Boolean Loop;
1552 HLRAlgo_ListIteratorOfInterferenceList It;
1553 const HLRBRep_Curve& EC = ED.Geometry();
1554 Standard_Real sta = EC.Parameter3d(EC.FirstParameter());
1555 Standard_Real end = EC.Parameter3d(EC.LastParameter());
1556 Standard_Real tolpar = (end - sta) * 0.01;
1557 Standard_Real param;
1558 Loop = Standard_True;
1559 It.Initialize(IL);
1560
1561 while(It.More() && Loop) {
1562 param = It.Value().Intersection().Parameter();
1563 if (param > end)
1564 Loop = Standard_False;
1565 else {
1566 if (Abs(param-sta) > Abs(param-end))
733a0e55 1567 end = param;
7fd59977 1568 else
733a0e55 1569 sta = param;
7fd59977 1570 }
1571 It.Next();
1572 }
733a0e55 1573 param = 0.5 * (sta + end);
7fd59977 1574 Standard_Integer level = 0;
733a0e55 1575 /*TopAbs_State st = */Classify(E,ED,Standard_True,level,param);
7fd59977 1576 Loop = Standard_True;
1577 It.Initialize(IL);
1578
1579 while(It.More() && Loop) {
1580 HLRAlgo_Interference& Int = It.Value();
1581 Standard_Real p = Int.Intersection().Parameter();
1582 if (p < param - tolpar) {
1583 switch (Int.Transition()) {
1584
1585 case TopAbs_FORWARD :
733a0e55
S
1586 level -= Int.Intersection().Level();
1587 break;
7fd59977 1588 case TopAbs_REVERSED :
733a0e55
S
1589 level += Int.Intersection().Level();
1590 break;
7fd59977 1591 case TopAbs_EXTERNAL :
1592 case TopAbs_INTERNAL :
733a0e55
S
1593 default :
1594 break;
7fd59977 1595 }
1596 }
1597 else if (p > param + tolpar)
1598 Loop = Standard_False;
1599 else {
1600#ifdef DEB
1601 cout << "HLRBRep_Data::HidingStartLevel : ";
1602 cout << "Bad Parameter." << endl;
1603#endif
1604 }
1605 It.Next();
1606 }
1607 return level;
1608}
1609
1610//=======================================================================
1611//function : Compare
1612//purpose :
1613//=======================================================================
1614
1615TopAbs_State HLRBRep_Data::Compare (const Standard_Integer E,
733a0e55 1616 const HLRBRep_EdgeData& ED)
7fd59977 1617{
733a0e55
S
1618 Standard_Integer level = 0;
1619 Standard_Real parbid = 0.;
7fd59977 1620 return Classify(E,ED,Standard_False,level,parbid);
1621}
1622
1623//=======================================================================
1624//function : OrientOutLine
1625//purpose :
1626//=======================================================================
1627
1628Standard_Boolean
1629HLRBRep_Data::OrientOutLine (const Standard_Integer I,
1630 HLRBRep_FaceData& FD)
1631{
1632 const Handle(HLRAlgo_WiresBlock)& wb = FD.Wires();
1633 Standard_Integer nw = wb->NbWires();
1634 Standard_Integer iw1,ie1,ne1;
1635 const gp_Trsf& T = myProj.Transformation();
1636 const gp_Trsf& TI = myProj.InvertedTransformation();
1637 Standard_Boolean inverted = Standard_False;
1638 Standard_Boolean FirstInversion = Standard_True;
1639
1640 for (iw1 = 1; iw1 <= nw; iw1++) {
1641 const Handle(HLRAlgo_EdgesBlock)& eb1 = wb->Wire(iw1);
1642 ne1 = eb1->NbEdges();
1643
1644 for (ie1 = 1; ie1 <= ne1; ie1++) {
1645 myFE = eb1->Edge(ie1);
1646 HLRBRep_EdgeData* ed1 = &(myEData(myFE));
1647 if (eb1->Double (ie1) ||
1648 eb1->IsoLine(ie1) ||
1649 ed1->Vertical()) ed1->Used(Standard_True );
1650 else ed1->Used(Standard_False);
1651 if ((eb1->OutLine(ie1) || eb1->Internal(ie1)) &&
1652 !ed1->Vertical()) {
1653 Standard_Real p,pu,pv,r;
1654 myFEGeom = &(ed1->ChangeGeometry());
1655 const HLRBRep_Curve& EC = ed1->Geometry();
1656 Standard_Integer vsta = ed1->VSta();
1657 Standard_Integer vend = ed1->VEnd();
1658 if (vsta == 0 &&
1659 vend == 0) p = 0;
1660 else if (vsta == 0) p = EC.Parameter3d(EC.LastParameter ());
1661 else if (vend == 0) p = EC.Parameter3d(EC.FirstParameter());
1662 else p = EC.Parameter3d((EC.LastParameter () +
1663 EC.FirstParameter()) / 2);
1664 if (HLRBRep_EdgeFaceTool::UVPoint(p,myFEGeom,iFaceGeom,pu,pv)) {
1665 gp_Pnt Pt;
1666 gp_Vec Tg;
1667 mySLProps.SetParameters(pu,pv);
1668 EC.D1(p,Pt,Tg);
1669 gp_Dir V;
1670 if (myProj.Perspective()) {
1671 gp_Pnt2d P2d;
1672 myProj.Project(Pt,P2d);
1673 V = gp_Dir(P2d.X(),P2d.Y(),-myProj.Focus());
1674 }
1675 else {
1676 V = gp_Dir(0,0,-1);
1677 }
1678 V.Transform(TI);
1679 Standard_Real curv = HLRBRep_EdgeFaceTool::CurvatureValue
1680 (iFaceGeom,pu,pv,V);
1681 gp_Vec Nm = mySLProps.Normal();
1682 if (curv == 0) {
1683#ifdef DEB
1684 cout << "HLRBRep_Data::OrientOutLine " << I;
1685 cout << " Edge " << myFE << " : ";
1686 cout << "CurvatureValue == 0." << endl;
1687#endif
1688 }
1689 if (curv > 0)
1690 Nm.Reverse();
1691 Tg.Transform(T);
1692 Pt.Transform(T);
1693 Nm.Transform(T);
1694 Nm.Cross(Tg);
1695 if (Tg.Magnitude() < gp::Resolution()) {
1696#ifdef DEB
1697 cout << "HLRBRep_Data::OrientOutLine " << I;
1698 cout << " Edge " << myFE << " : ";
1699 cout << "Tg.Magnitude() == 0." << endl;
1700#endif
1701 }
1702 if (myProj.Perspective())
1703 r = Nm.Z() * myProj.Focus() -
1704 ( Nm.X() * Pt.X() + Nm.Y() * Pt.Y() + Nm.Z() * Pt.Z() );
1705 else
1706 r = Nm.Z();
1707 myFEOri = (r > 0) ? TopAbs_FORWARD : TopAbs_REVERSED;
1708 if (!FD.Cut() && FD.Closed() && FirstInversion) {
1709 if ((eb1->Orientation(ie1) == myFEOri) !=
1710 (FD.Orientation() == TopAbs_FORWARD)) {
1711 FirstInversion = Standard_False;
1712 inverted = Standard_True;
1713 }
1714 }
1715 eb1->Orientation(ie1,myFEOri);
1716 }
1717 else {
1718#ifdef DEB
1719 cout << "HLRBRep_Data::OrientOutLine " << I;
1720 cout << " Edge " << myFE << " : ";
1721 cout << "UVPoint not found, OutLine not Oriented" << endl;
1722#endif
1723 }
1724 ed1->Used(Standard_True);
1725 }
1726 }
1727 }
1728 return inverted;
1729}
1730
1731//=======================================================================
1732//function : OrientOthEdge
1733//purpose :
1734//=======================================================================
1735
1736void HLRBRep_Data::OrientOthEdge (const Standard_Integer I,
1737 HLRBRep_FaceData& FD)
1738{
1739 Standard_Real p,pu,pv,r;
1740 const Handle(HLRAlgo_WiresBlock)& wb = FD.Wires();
1741 Standard_Integer nw = wb->NbWires();
1742 Standard_Integer iw1,ie1,ne1;
1743 const gp_Trsf& T = myProj.Transformation();
1744
1745 for (iw1 = 1; iw1 <= nw; iw1++) {
1746 const Handle(HLRAlgo_EdgesBlock)& eb1 = wb->Wire(iw1);
1747 ne1 = eb1->NbEdges();
1748
1749 for (ie1 = 1; ie1 <= ne1; ie1++) {
1750 myFE = eb1->Edge (ie1);
1751 myFEOri = eb1->Orientation(ie1);
1752 HLRBRep_EdgeData* ed1 = &(myEData(myFE));
1753
1754 if (!ed1->Used()) {
1755 ed1->Used(Standard_True);
1756 myFEGeom = &(ed1->ChangeGeometry());
1757 const HLRBRep_Curve& EC = ed1->Geometry();
1758 p = EC.Parameter3d((EC.LastParameter () +
1759 EC.FirstParameter()) / 2);
1760 if (HLRBRep_EdgeFaceTool::UVPoint(p,myFEGeom,iFaceGeom,pu,pv)) {
1761 gp_Pnt Pt = EC.Value3D(p);
1762 mySLProps.SetParameters(pu,pv);
1763 gp_Vec Nm = mySLProps.Normal();
1764 Pt.Transform(T);
1765 Nm.Transform(T);
1766 if (myProj.Perspective()) {
1767 r = Nm.Z() * myProj.Focus() -
1768 ( Nm.X() * Pt.X() + Nm.Y() * Pt.Y() + Nm.Z() * Pt.Z() );
1769 }
1770 else {
1771 r = Nm.Z();
1772 }
1773 if (r < 0) {
1774 myFEOri = TopAbs::Reverse(myFEOri);
1775 eb1->Orientation(ie1,myFEOri);
1776 }
1777 }
1778 else {
1779 cout << "HLRBRep_Data::OrientOthEdge " << I;
1780 cout << " Edge " << myFE << " : ";
1781 cout << "UVPoint not found, Edge not Oriented" << endl;
1782 }
1783 }
1784 }
1785 }
1786}
1787
1788//=======================================================================
1789//function : Classify
1790//purpose :
1791//=======================================================================
1792
1793#define REJECT1 \
1794 VertMin[ 0] = (Standard_Integer)((myDeca[ 0]+TotMin[ 0])*mySurD[ 0]); \
1795 VertMax[ 0] = (Standard_Integer)((myDeca[ 0]+TotMax[ 0])*mySurD[ 0]); \
1796 VertMin[ 1] = (Standard_Integer)((myDeca[ 1]+TotMin[ 1])*mySurD[ 1]); \
1797 VertMax[ 1] = (Standard_Integer)((myDeca[ 1]+TotMax[ 1])*mySurD[ 1]); \
1798 VertMin[ 2] = (Standard_Integer)((myDeca[ 2]+TotMin[ 2])*mySurD[ 2]); \
1799 VertMax[ 2] = (Standard_Integer)((myDeca[ 2]+TotMax[ 2])*mySurD[ 2]); \
1800 VertMin[ 3] = (Standard_Integer)((myDeca[ 3]+TotMin[ 3])*mySurD[ 3]); \
1801 VertMax[ 3] = (Standard_Integer)((myDeca[ 3]+TotMax[ 3])*mySurD[ 3]); \
1802 VertMin[ 4] = (Standard_Integer)((myDeca[ 4]+TotMin[ 4])*mySurD[ 4]); \
1803 VertMax[ 4] = (Standard_Integer)((myDeca[ 4]+TotMax[ 4])*mySurD[ 4]); \
1804 VertMin[ 5] = (Standard_Integer)((myDeca[ 5]+TotMin[ 5])*mySurD[ 5]); \
1805 VertMax[ 5] = (Standard_Integer)((myDeca[ 5]+TotMax[ 5])*mySurD[ 5]); \
1806 VertMin[ 6] = (Standard_Integer)((myDeca[ 6]+TotMin[ 6])*mySurD[ 6]); \
1807 VertMax[ 6] = (Standard_Integer)((myDeca[ 6]+TotMax[ 6])*mySurD[ 6]); \
1808 VertMin[ 7] = (Standard_Integer)((myDeca[ 7]+TotMin[ 7])*mySurD[ 7]); \
1809 VertMax[ 7] = (Standard_Integer)((myDeca[ 7]+TotMax[ 7])*mySurD[ 7]); \
1810 VertMin[ 8] = (Standard_Integer)((myDeca[ 8]+TotMin[ 8])*mySurD[ 8]); \
1811 VertMax[ 8] = (Standard_Integer)((myDeca[ 8]+TotMax[ 8])*mySurD[ 8]); \
1812 VertMin[ 9] = (Standard_Integer)((myDeca[ 9]+TotMin[ 9])*mySurD[ 9]); \
1813 VertMax[ 9] = (Standard_Integer)((myDeca[ 9]+TotMax[ 9])*mySurD[ 9]); \
1814 VertMin[10] = (Standard_Integer)((myDeca[10]+TotMin[10])*mySurD[10]); \
1815 VertMax[10] = (Standard_Integer)((myDeca[10]+TotMax[10])*mySurD[10]); \
1816 VertMin[11] = (Standard_Integer)((myDeca[11]+TotMin[11])*mySurD[11]); \
1817 VertMax[11] = (Standard_Integer)((myDeca[11]+TotMax[11])*mySurD[11]); \
1818 VertMin[12] = (Standard_Integer)((myDeca[12]+TotMin[12])*mySurD[12]); \
1819 VertMax[12] = (Standard_Integer)((myDeca[12]+TotMax[12])*mySurD[12]); \
1820 VertMin[13] = (Standard_Integer)((myDeca[13]+TotMin[13])*mySurD[13]); \
1821 VertMax[13] = (Standard_Integer)((myDeca[13]+TotMax[13])*mySurD[13]); \
1822 VertMin[14] = (Standard_Integer)((myDeca[14]+TotMin[14])*mySurD[14]); \
1823 VertMax[14] = (Standard_Integer)((myDeca[14]+TotMax[14])*mySurD[14]); \
1824 VertMin[15] = (Standard_Integer)((myDeca[15]+TotMin[15])*mySurD[15]); \
1825 VertMax[15] = (Standard_Integer)((myDeca[15]+TotMax[15])*mySurD[15]);
1826
1827TopAbs_State
35e08fe8 1828HLRBRep_Data::Classify (const Standard_Integer /*E*/,
7fd59977 1829 const HLRBRep_EdgeData& ED,
1830 const Standard_Boolean LevelFlag,
1831 Standard_Integer& Level,
1832 const Standard_Real param)
1833{
1834 nbClassification++;
1835 Standard_Integer VertMin[16],VertMax[16],MinMaxVert[16];
1836 Standard_Real TotMin[16],TotMax[16];
1837
1838 Standard_Integer i;
1839 Level = 0;
1840 TopAbs_State state = TopAbs_OUT;
1841// Standard_Boolean rej = Standard_False;
1842 const HLRBRep_Curve& EC = ED.Geometry();
1843 Standard_Real sta,xsta,ysta,zsta,end,xend,yend,zend;
1844 Standard_Real tol = (Standard_Real)(ED.Tolerance());
1845
1846 if (LevelFlag) {
1847 sta = param;
1848 myProj.Project(EC.Value3D(sta),xsta,ysta,zsta);
1849
1850 //-- les rejections sont faites dans l intersecteur a moindre frais
1851 //-- puisque la surface sera chargee
1852 HLRAlgo::InitMinMax(Precision::Infinite(),
1853 (Standard_Address)TotMin,
1854 (Standard_Address)TotMax);
1855 HLRAlgo::UpdateMinMax(xsta,ysta,zsta,
1856 (Standard_Address)TotMin,
1857 (Standard_Address)TotMax);
1858 HLRAlgo::EnlargeMinMax(tol,
1859 (Standard_Address)TotMin,
1860 (Standard_Address)TotMax);
1861 REJECT1;
1862
1863 HLRAlgo::EncodeMinMax((Standard_Address)VertMin,
1864 (Standard_Address)VertMax,
1865 (Standard_Address)MinMaxVert);
1866 if (((MaxFace1 - MinVert1) & 0x80008000) != 0 ||
1867 ((MaxVert1 - MinFace1) & 0x80008000) != 0 ||
1868 ((MaxFace2 - MinVert2) & 0x80008000) != 0 ||
1869 ((MaxVert2 - MinFace2) & 0x80008000) != 0 ||
1870 ((MaxFace3 - MinVert3) & 0x80008000) != 0 ||
1871 ((MaxVert3 - MinFace3) & 0x80008000) != 0 ||
1872 ((MaxFace4 - MinVert4) & 0x80008000) != 0 ||
1873 ((MaxVert4 - MinFace4) & 0x80008000) != 0 ||
1874 ((MaxFace5 - MinVert5) & 0x80008000) != 0 ||
1875 ((MaxVert5 - MinFace5) & 0x80008000) != 0 ||
1876 ((MaxFace6 - MinVert6) & 0x80008000) != 0 ||
1877 ((MaxVert6 - MinFace6) & 0x80008000) != 0 ||
1878 ((MaxFace7 - MinVert7) & 0x80008000) != 0 ||
1879 ((MaxVert7 - MinFace7) & 0x80008000) != 0 ||
1880 ((MaxFace8 - MinVert8) & 0x80008000) != 0) { //-- Rejection en Z
1881 return state;
1882 }
1883 }
1884 else {
1885 sta = EC.Parameter3d(EC.FirstParameter());
1886 myProj.Project(EC.Value3D(sta),xsta,ysta,zsta);
1887
1888 //-- les rejections sont faites dans l intersecteur a moindre frais
1889 //-- puisque la surface sera chargee
1890 HLRAlgo::InitMinMax(Precision::Infinite(),
1891 (Standard_Address)TotMin,
1892 (Standard_Address)TotMax);
1893 HLRAlgo::UpdateMinMax(xsta,ysta,zsta,
1894 (Standard_Address)TotMin,
1895 (Standard_Address)TotMax);
1896 HLRAlgo::EnlargeMinMax(tol,
1897 (Standard_Address)TotMin,
1898 (Standard_Address)TotMax);
1899
1900 REJECT1;
1901
1902 HLRAlgo::EncodeMinMax((Standard_Address)VertMin,
1903 (Standard_Address)VertMax,
1904 (Standard_Address)MinMaxVert);
1905 if (((MaxFace1 - MinVert1) & 0x80008000) != 0 ||
1906 ((MaxVert1 - MinFace1) & 0x80008000) != 0 ||
1907 ((MaxFace2 - MinVert2) & 0x80008000) != 0 ||
1908 ((MaxVert2 - MinFace2) & 0x80008000) != 0 ||
1909 ((MaxFace3 - MinVert3) & 0x80008000) != 0 ||
1910 ((MaxVert3 - MinFace3) & 0x80008000) != 0 ||
1911 ((MaxFace4 - MinVert4) & 0x80008000) != 0 ||
1912 ((MaxVert4 - MinFace4) & 0x80008000) != 0 ||
1913 ((MaxFace5 - MinVert5) & 0x80008000) != 0 ||
1914 ((MaxVert5 - MinFace5) & 0x80008000) != 0 ||
1915 ((MaxFace6 - MinVert6) & 0x80008000) != 0 ||
1916 ((MaxVert6 - MinFace6) & 0x80008000) != 0 ||
1917 ((MaxFace7 - MinVert7) & 0x80008000) != 0 ||
1918 ((MaxVert7 - MinFace7) & 0x80008000) != 0 ||
1919 ((MaxFace8 - MinVert8) & 0x80008000) != 0) { //-- Rejection en Z
1920 return state;
1921 }
1922 end = EC.Parameter3d(EC.LastParameter());
1923 myProj.Project(EC.Value3D(end),xend,yend,zend);
1924
1925 HLRAlgo::InitMinMax(Precision::Infinite(),
1926 (Standard_Address)TotMin,
1927 (Standard_Address)TotMax);
1928 HLRAlgo::UpdateMinMax(xend,yend,zend,
1929 (Standard_Address)TotMin,
1930 (Standard_Address)TotMax);
1931 HLRAlgo::EnlargeMinMax(tol,
1932 (Standard_Address)TotMin,
1933 (Standard_Address)TotMax);
1934
1935 REJECT1;
1936
1937 HLRAlgo::EncodeMinMax((Standard_Address)VertMin,
1938 (Standard_Address)VertMax,
1939 (Standard_Address)MinMaxVert);
1940 if (((MaxFace1 - MinVert1) & 0x80008000) != 0 ||
1941 ((MaxVert1 - MinFace1) & 0x80008000) != 0 ||
1942 ((MaxFace2 - MinVert2) & 0x80008000) != 0 ||
1943 ((MaxVert2 - MinFace2) & 0x80008000) != 0 ||
1944 ((MaxFace3 - MinVert3) & 0x80008000) != 0 ||
1945 ((MaxVert3 - MinFace3) & 0x80008000) != 0 ||
1946 ((MaxFace4 - MinVert4) & 0x80008000) != 0 ||
1947 ((MaxVert4 - MinFace4) & 0x80008000) != 0 ||
1948 ((MaxFace5 - MinVert5) & 0x80008000) != 0 ||
1949 ((MaxVert5 - MinFace5) & 0x80008000) != 0 ||
1950 ((MaxFace6 - MinVert6) & 0x80008000) != 0 ||
1951 ((MaxVert6 - MinFace6) & 0x80008000) != 0 ||
1952 ((MaxFace7 - MinVert7) & 0x80008000) != 0 ||
1953 ((MaxVert7 - MinFace7) & 0x80008000) != 0 ||
1954 ((MaxFace8 - MinVert8) & 0x80008000) != 0) { //-- Rejection en Z
1955 return state;
1956 }
1957 sta = 0.4 * sta + 0.6 * end; // dangerous if it is the middle
1958 myProj.Project(EC.Value3D(sta),xsta,ysta,zsta);
1959
1960 //-- les rejections sont faites dans l intersecteur a moindre frais
1961 //-- puisque la surface sera chargee
1962 HLRAlgo::InitMinMax(Precision::Infinite(),
1963 (Standard_Address)TotMin,
1964 (Standard_Address)TotMax);
1965 HLRAlgo::UpdateMinMax(xsta,ysta,zsta,
1966 (Standard_Address)TotMin,
1967 (Standard_Address)TotMax);
1968 HLRAlgo::EnlargeMinMax(tol,
1969 (Standard_Address)TotMin,
1970 (Standard_Address)TotMax);
1971 REJECT1;
1972
1973 HLRAlgo::EncodeMinMax((Standard_Address)VertMin,
1974 (Standard_Address)VertMax,
1975 (Standard_Address)MinMaxVert);
1976
1977
1978
1979#if 0
1980 {
1981 Standard_Integer qwe,qwep8,q,q1,q2;
1982 printf("\n E:%d -------\n",E);
1983 for(qwe=0; qwe<8; qwe++) {
1984 q1 = (((Standard_Integer*)iFaceMinMax)[qwe ]) & 0x0000FFFF;
1985 q2 = (((Standard_Integer*)iFaceMinMax)[qwe+8]) & 0x0000FFFF;
1986 printf("\nFace: %3d %6d -> %6d delta : %6d ",qwe,q1,q2,q2-q1);
1987
1988 q1 = (((Standard_Integer*)MinMaxVert)[qwe ]) & 0x0000FFFF;
1989 q2 = (((Standard_Integer*)MinMaxVert)[qwe+8]) & 0x0000FFFF;
1990 printf(" | Vtx: %3d %6d -> %6d delta : %6d ",qwe,q1,q2,q2-q1);
1991
1992 q1 = ((((Standard_Integer*)iFaceMinMax)[qwe ])>>16) & 0x0000FFFF;
1993 q2 = ((((Standard_Integer*)iFaceMinMax)[qwe+8])>>16) & 0x0000FFFF;
1994 printf("\nFace: %3d %6d -> %6d delta : %6d ",qwe,q1,q2,q2-q1);
1995
1996 q1 = ((((Standard_Integer*)MinMaxVert)[qwe ])>>16) & 0x0000FFFF;
1997 q2 = ((((Standard_Integer*)MinMaxVert)[qwe+8])>>16) & 0x0000FFFF;
1998 printf(" | Vtx: %3d %6d -> %6d delta : %6d ",qwe,q1,q2,q2-q1);
1999 }
2000 printf("\n");
2001
2002
2003 for(qwe=0,qwep8=8; qwe<8; qwe++,qwep8++) {
2004 q = ((Standard_Integer*)iFaceMinMax)[qwep8]- ((Standard_Integer*)MinMaxVert)[qwe];
2005 q1 = q>>16;
2006 q2 = (q& 0x0000FFFF);
2007 printf("\nmot: %3d q1 = %+10d q2=%+10d Mask : %d",qwe,(q1>32768)? (32768-q1) : q1,(q2>32768)? (32768-q2) : q2,q&0x80008000);
2008 }
2009 for(qwe=0,qwep8=8; qwe<8; qwe++,qwep8++) {
2010 q = ((Standard_Integer*)MinMaxVert)[qwep8]- ((Standard_Integer*)iFaceMinMax)[qwe];
2011 q1 = q>>16;
2012 q2 = (q& 0x0000FFFF);
2013 printf("\nmot: %3d q1 = %+10d q2=%+10d Mask : %d",qwe+8,(q1>32768)? (32768-q1) : q1,(q2>32768)? (32768-q2) : q2,q&0x80008000);
2014 }
2015 cout<<endl;
2016 }
2017 #endif
2018
2019
2020
2021
2022 if (((MaxFace1 - MinVert1) & 0x80008000) != 0 ||
2023 ((MaxVert1 - MinFace1) & 0x80008000) != 0 ||
2024 ((MaxFace2 - MinVert2) & 0x80008000) != 0 ||
2025 ((MaxVert2 - MinFace2) & 0x80008000) != 0 ||
2026 ((MaxFace3 - MinVert3) & 0x80008000) != 0 ||
2027 ((MaxVert3 - MinFace3) & 0x80008000) != 0 ||
2028 ((MaxFace4 - MinVert4) & 0x80008000) != 0 ||
2029 ((MaxVert4 - MinFace4) & 0x80008000) != 0 ||
2030 ((MaxFace5 - MinVert5) & 0x80008000) != 0 ||
2031 ((MaxVert5 - MinFace5) & 0x80008000) != 0 ||
2032 ((MaxFace6 - MinVert6) & 0x80008000) != 0 ||
2033 ((MaxVert6 - MinFace6) & 0x80008000) != 0 ||
2034 ((MaxFace7 - MinVert7) & 0x80008000) != 0 ||
2035 ((MaxVert7 - MinFace7) & 0x80008000) != 0 ||
2036 ((MaxFace8 - MinVert8) & 0x80008000) != 0) { //-- Rejection en Z
2037 return state;
2038 }
2039 }
2040
2041 nbCal3Intersection++;
2042 gp_Pnt PLim;
2043 gp_Pnt2d Psta;
2044 Psta = EC.Value (sta);
2045 PLim = EC.Value3D(sta);
2046
2047
2048 static int aff=0;
2049 if(aff) {
2050 static Standard_Integer nump1=0;
2051 printf("\npoint PNR%d %g %g %g",++nump1,PLim.X(),PLim.Y(),PLim.Z());
2052 }
2053
2054 gp_Lin L = myProj.Shoot(Psta.X(),Psta.Y());
2055 Standard_Real wLim = ElCLib::Parameter(L,PLim);
2056 myIntersector.Perform(L,wLim);
2057 if (myIntersector.IsDone()) {
2058 Standard_Integer nbPoints = myIntersector.NbPoints();
2059 if (nbPoints > 0) {
2060 Standard_Real TolZ = myBigSize * 0.000001;
2061 if (iFaceTest) {
2062 if (!myLEOutLine && !myLEInternal) TolZ = myBigSize * 0.001;
2063 else TolZ = myBigSize * 0.01;
2064 }
2065 wLim -= TolZ;
2066 Standard_Real PeriodU,PeriodV,UMin =0.,UMax =0.,VMin =0.,VMax =0.;
2067 if (((HLRBRep_Surface*)iFaceGeom)->IsUPeriodic()) {
2068 PeriodU = ((HLRBRep_Surface*)iFaceGeom)->UPeriod();
2069 UMin = ((HLRBRep_Surface*)iFaceGeom)->FirstUParameter();
2070 UMax = ((HLRBRep_Surface*)iFaceGeom)->LastUParameter();
2071 }
2072 else
2073 PeriodU = 0.;
2074 if (((HLRBRep_Surface*)iFaceGeom)->IsVPeriodic()) {
2075 PeriodV = ((HLRBRep_Surface*)iFaceGeom)->VPeriod();
2076 VMin = ((HLRBRep_Surface*)iFaceGeom)->FirstVParameter();
2077 VMax = ((HLRBRep_Surface*)iFaceGeom)->LastVParameter();
2078 }
2079 else
2080 PeriodV = 0;
2081 gp_Pnt PInter;
2082 Standard_Real u,v,w;
2083 IntCurveSurface_TransitionOnCurve Tr;
2084
2085 for (i = 1; i <= nbPoints; i++) {
2086 Standard_Boolean InsideRestriction = Standard_False;
2087 myIntersector.CSPoint(i).Values(PInter,u,v,w,Tr);
2088 if (w < wLim) {
2089 if (PeriodU)
2090 while (u > UMin)
2091 u -= PeriodU;
2092 if (PeriodV)
2093 while (v > VMin)
2094 v -= PeriodV;
2095// Standard_Real UInit = u;
2096 Standard_Real VInit = v;
2097
2098 do {
2099 v = VInit;
2100
2101 do {
2102 gp_Pnt2d pnt2d(u,v);
2103 if (myClassifier->Classify(pnt2d,0.0)!=TopAbs_OUT) {
2104 InsideRestriction = Standard_True;
2105 state = TopAbs_IN;
2106 Level++;
2107 if (!LevelFlag) {
2108 return state;
2109 }
2110 }
2111 v += PeriodV;
2112 }
2113 while (PeriodV && v < VMax && !InsideRestriction);
2114 u += PeriodU;
2115 }
2116 while (PeriodU && u < UMax && !InsideRestriction);
2117 }
2118 }
2119 }
2120 }
2121 return state;
2122}
2123
2124
2125//=======================================================================
2126//function : SimplClassify
2127//purpose :
2128//=======================================================================
2129
35e08fe8 2130TopAbs_State HLRBRep_Data::SimplClassify (const Standard_Integer /*E*/,
7fd59977 2131 const HLRBRep_EdgeData& ED,
2132 const Standard_Integer Nbp,
2133 const Standard_Real p1,
2134 const Standard_Real p2)
2135{
2136 nbClassification++;
2137 Standard_Integer VertMin[16],VertMax[16],MinMaxVert[16];
2138 Standard_Real TotMin[16],TotMax[16];
2139
2140 Standard_Integer i;
2141 TopAbs_State state = TopAbs_IN;
2142// Standard_Boolean rej = Standard_False;
2143 const HLRBRep_Curve& EC = ED.Geometry();
2144 Standard_Real sta,xsta,ysta,zsta, dp;
2145 Standard_Real tol = (Standard_Real)(ED.Tolerance());
2146
2147 dp = (p2 - p1)/(Nbp+1);
2148
2149 for(sta = p1+dp,i = 1; i <= Nbp; ++i, sta += dp) {
2150 myProj.Project(EC.Value3D(sta),xsta,ysta,zsta);
2151
2152 //-- les rejections sont faites dans l intersecteur a moindre frais
2153 //-- puisque la surface sera chargee
2154 HLRAlgo::InitMinMax(Precision::Infinite(),
2155 (Standard_Address)TotMin,
2156 (Standard_Address)TotMax);
2157 HLRAlgo::UpdateMinMax(xsta,ysta,zsta,
2158 (Standard_Address)TotMin,
2159 (Standard_Address)TotMax);
2160 HLRAlgo::EnlargeMinMax(tol,
2161 (Standard_Address)TotMin,
2162 (Standard_Address)TotMax);
2163 REJECT1;
2164
2165 HLRAlgo::EncodeMinMax((Standard_Address)VertMin,
2166 (Standard_Address)VertMax,
2167 (Standard_Address)MinMaxVert);
2168 if (((MaxFace1 - MinVert1) & 0x80008000) != 0 ||
2169 ((MaxVert1 - MinFace1) & 0x80008000) != 0 ||
2170 ((MaxFace2 - MinVert2) & 0x80008000) != 0 ||
2171 ((MaxVert2 - MinFace2) & 0x80008000) != 0 ||
2172 ((MaxFace3 - MinVert3) & 0x80008000) != 0 ||
2173 ((MaxVert3 - MinFace3) & 0x80008000) != 0 ||
2174 ((MaxFace4 - MinVert4) & 0x80008000) != 0 ||
2175 ((MaxVert4 - MinFace4) & 0x80008000) != 0 ||
2176 ((MaxFace5 - MinVert5) & 0x80008000) != 0 ||
2177 ((MaxVert5 - MinFace5) & 0x80008000) != 0 ||
2178 ((MaxFace6 - MinVert6) & 0x80008000) != 0 ||
2179 ((MaxVert6 - MinFace6) & 0x80008000) != 0 ||
2180 ((MaxFace7 - MinVert7) & 0x80008000) != 0 ||
2181 ((MaxVert7 - MinFace7) & 0x80008000) != 0 ||
2182 ((MaxFace8 - MinVert8) & 0x80008000) != 0) { //-- Rejection en Z
2183 return TopAbs_OUT;
2184 }
2185 }
2186 return state;
2187}
2188
2189//=======================================================================
2190//function : RejectedPoint
2191//purpose : build an interference if non Rejected intersection point
2192//=======================================================================
2193
2194Standard_Boolean
2195HLRBRep_Data::RejectedPoint (const IntRes2d_IntersectionPoint& PInter,
2196 const TopAbs_Orientation BoundOri,
2197 const Standard_Integer NumSeg)
2198{
2199 Standard_Integer Ind = 0;
2200 Standard_Integer decal;
2201 Standard_Real p1,p2,dz;
2202 Standard_ShortReal t1,t2;
2203 TopAbs_State st;
7fd59977 2204 TopAbs_Orientation Orie =TopAbs_FORWARD ;
7fd59977 2205 TopAbs_Orientation Or2 = TopAbs_INTERNAL;
2206 Standard_Boolean inverted = Standard_False;
2207 const IntRes2d_Transition* Tr1;
2208 const IntRes2d_Transition* Tr2;
2209 Standard_Real TolZ = myBigSize * 0.00001;
2210
2211 p1 = ((HLRBRep_Curve*)myLEGeom)->Parameter3d(PInter.ParamOnFirst ());
2212 p2 = ((HLRBRep_Curve*)myFEGeom)->Parameter3d(PInter.ParamOnSecond());
2213 dz = ((HLRBRep_Curve*)myLEGeom)->Z(p1)-((HLRBRep_Curve*)myFEGeom)->Z(p2);
2214
2215 if (myLE == myFE) { // auto intersection can be inverted
2216 if (dz >= TolZ) {
2217 inverted = Standard_True;
2218 Standard_Real p = p1;
2219 p1 = p2;
2220 p2 = p;
2221 dz = -dz;
2222 }
2223 }
2224
2225 if (dz >= TolZ) {
2226 myAboveIntf = Standard_True;
2227 return Standard_True;
2228 }
2229 myAboveIntf = Standard_False;
2230 st = (dz <= -TolZ) ? TopAbs_IN : TopAbs_ON;
2231
2232 if (inverted) {
2233 Tr1 = &(PInter.TransitionOfSecond());
2234 Tr2 = &(PInter.TransitionOfFirst ());
2235 }
2236 else {
2237 Tr1 = &(PInter.TransitionOfFirst ());
2238 Tr2 = &(PInter.TransitionOfSecond());
2239 }
2240
2241 if (iFaceTest) {
2242 if (myLE == myFE) {
2243 if (st == TopAbs_IN)
2244 ((HLRBRep_EdgeData*)myLEData)->Simple(Standard_False);
2245 }
2246 else {
2247 if (mySameVertex) {
2248 if ((st == TopAbs_ON) ||
2249 (Tr1->PositionOnCurve() != IntRes2d_Middle) ||
2250 (Tr2->PositionOnCurve() != IntRes2d_Middle))
2251 return Standard_True;
2252 }
2253 }
2254 if (st == TopAbs_IN) iFaceSmpl = Standard_False;
2255 }
2256
2257 switch (Tr1->TransitionType()) { // compute the transition
2258 case IntRes2d_In :
2259 if (myFEOri == TopAbs_REVERSED) Orie = TopAbs_REVERSED;
2260 else Orie = TopAbs_FORWARD ; break;
2261 case IntRes2d_Out :
2262 if (myFEOri == TopAbs_REVERSED) Orie = TopAbs_FORWARD ;
2263 else Orie = TopAbs_REVERSED; break;
2264 case IntRes2d_Touch :
2265 switch (Tr1->Situation()) {
2266 case IntRes2d_Inside :
2267 if (myFEOri == TopAbs_REVERSED) Orie = TopAbs_EXTERNAL;
2268 else Orie = TopAbs_INTERNAL; break;
2269 case IntRes2d_Outside :
2270 if (myFEOri == TopAbs_REVERSED) Orie = TopAbs_INTERNAL;
2271 else Orie = TopAbs_EXTERNAL; break;
2272 case IntRes2d_Unknown :
2273 return Standard_True;
2274 } break;
2275 case IntRes2d_Undecided :
2276 return Standard_True;
2277 }
2278
2279 if (iFaceBack) Orie = TopAbs::Complement(Orie); // change the transition
7fd59977 2280 TopAbs_Orientation Ori = TopAbs_FORWARD;
7fd59977 2281 switch (Tr1->PositionOnCurve()) {
2282 case IntRes2d_Head : Ori = TopAbs_FORWARD ; break;
2283 case IntRes2d_Middle : Ori = TopAbs_INTERNAL; break;
2284 case IntRes2d_End : Ori = TopAbs_REVERSED; break;
2285 }
2286
2287 if (st != TopAbs_OUT) {
2288 if (Tr2->PositionOnCurve() != IntRes2d_Middle) { // correction de la transition sur myFE
2289 if (mySameVertex) return Standard_True; // si intersection a une extremite verticale !
2290
2291 Standard_Boolean douteux = Standard_False;
2292 Standard_Real psav = p2;
2293 gp_Pnt2d Ptsav;
2294 gp_Vec2d Tgsav,Nmsav;
2295 if (Tr2->PositionOnCurve() == IntRes2d_Head) {
2296 Ind = ((HLRBRep_EdgeData*)myFEData)->VSta();
2297 Or2 = TopAbs_FORWARD ;
2298 AdjustParameter((HLRBRep_EdgeData*)myFEData,Standard_True ,p2,t2);
2299 if (((HLRBRep_EdgeData*)myFEData)->VerAtSta()) {
2300 douteux = Standard_True;
2301 ((HLRBRep_Curve*)myFEGeom)->D2(psav,Ptsav,Tgsav,Nmsav);
2302 if (Tgsav.SquareMagnitude() <= DERIVEE_PREMIERE_NULLE)
2303 Tgsav = Nmsav;
2304 }
2305 }
2306 else {
2307 Ind = ((HLRBRep_EdgeData*)myFEData)->VEnd();
2308 Or2 = TopAbs_REVERSED;
2309 AdjustParameter((HLRBRep_EdgeData*)myFEData,Standard_False,p2,t2);
2310 if (((HLRBRep_EdgeData*)myFEData)->VerAtEnd()) {
2311 douteux = Standard_True;
2312 ((HLRBRep_Curve*)myFEGeom)->D2(psav,Ptsav,Tgsav,Nmsav);
2313 if (Tgsav.SquareMagnitude() <= DERIVEE_PREMIERE_NULLE)
2314 Tgsav = Nmsav;
2315 }
2316 }
2317 gp_Vec2d TgFE;
2318 ((HLRBRep_Curve*)myFEGeom)->D1(p2,Ptsav,TgFE);
2319 if (douteux) {
2320 if (TgFE.XY().Dot(Tgsav.XY()) < 0.0) {
2321 if (Orie == TopAbs_FORWARD ) Orie = TopAbs_REVERSED;
2322 else if (Orie == TopAbs_REVERSED) Orie = TopAbs_FORWARD ;
2323 }
2324 }
2325 myIntf.ChangeBoundary().Set2D(myFE,p2);
2326 }
2327 if (Ori != TopAbs_INTERNAL) { // correction de la transition sur myLE
2328 Standard_Boolean douteux = Standard_False; // si intersection a une extremite verticale !
2329 Standard_Real psav = p1;
2330 gp_Pnt2d Ptsav;
2331 gp_Vec2d Tgsav,Nmsav;
2332 if (Ori == TopAbs_FORWARD) {
2333 AdjustParameter((HLRBRep_EdgeData*)myLEData,Standard_True ,p1,t1);
2334 if (((HLRBRep_EdgeData*)myLEData)->VerAtSta()) {
2335 douteux = Standard_True;
2336 ((HLRBRep_Curve*)myLEGeom)->D2(psav,Ptsav,Tgsav,Nmsav);
2337 if (Tgsav.SquareMagnitude() <= DERIVEE_PREMIERE_NULLE)
2338 Tgsav=Nmsav;
2339 }
2340 }
2341 else {
2342 AdjustParameter((HLRBRep_EdgeData*)myLEData,Standard_False,p1,t1);
2343 if (((HLRBRep_EdgeData*)myLEData)->VerAtEnd()) {
2344 douteux = Standard_True;
2345 ((HLRBRep_Curve*)myLEGeom)->D2(psav,Ptsav,Tgsav,Nmsav);
2346 if (Tgsav.SquareMagnitude() <= DERIVEE_PREMIERE_NULLE)
2347 Tgsav=Nmsav;
2348 }
2349 }
2350 if (douteux) {
2351 gp_Vec2d TgLE;
2352 ((HLRBRep_Curve*)myLEGeom)->D1(p1,Ptsav,TgLE);
2353 if (TgLE.XY().Dot(Tgsav.XY()) < 0.0) {
2354 if (Orie == TopAbs_FORWARD ) Orie = TopAbs_REVERSED;
2355 else if (Orie == TopAbs_REVERSED) Orie = TopAbs_FORWARD ;
2356 }
2357 }
2358 }
2359 if (st == TopAbs_ON) {
2360 TopAbs_State stbef,staft;
2361 EdgeState(p1,p2,stbef,staft);
2362 myIntf.ChangeBoundary().SetState3D(stbef,staft);
2363 }
2364 }
2365
2366 if (myFEInternal) {
2367 decal = 2;
2368 }
2369 else {
2370 decal = 1;
2371 if (st == TopAbs_IN &&
2372 Ori == TopAbs_FORWARD &&
2373 Orie == TopAbs_FORWARD)
2374 decal = 0;
2375 }
2376 HLRAlgo_Intersection& inter = myIntf.ChangeIntersection();
2377 inter.Orientation(Ori);
2378 inter.Level(decal);
2379 inter.SegIndex(NumSeg);
2380 inter.Index(Ind);
2381 inter.Parameter(p1);
2382 inter.Tolerance(myLETol);
2383 inter.State(st);
2384 myIntf.Orientation(Or2);
2385 myIntf.Transition(Orie);
2386 myIntf.BoundaryTransition(BoundOri);
2387 myIntf.ChangeBoundary().Set2D(myFE,p2);
2388 return Standard_False;
2389}
2390
2391//=======================================================================
2392//function : SameVertex
2393//purpose :
2394//=======================================================================
2395
2396Standard_Boolean
2397HLRBRep_Data::SameVertex (const Standard_Boolean h1,
2398 const Standard_Boolean h2)
2399{
2400 Standard_Integer v1,v2;
2401 if (h1) v1 = ((HLRBRep_EdgeData*)myLEData)->VSta();
2402 else v1 = ((HLRBRep_EdgeData*)myLEData)->VEnd();
2403 if (h2) v2 = ((HLRBRep_EdgeData*)myFEData)->VSta();
2404 else v2 = ((HLRBRep_EdgeData*)myFEData)->VEnd();
2405 Standard_Boolean SameV = v1 == v2;
2406 if (SameV) {
2407 myIntersected = Standard_True; // compute the intersections
2408 if ((myLEType == GeomAbs_Line ||
2409 myLEType == GeomAbs_Circle ||
2410 myLEType == GeomAbs_Ellipse ) &&
2411 (myFEType == GeomAbs_Line ||
2412 myFEType == GeomAbs_Circle ||
2413 myFEType == GeomAbs_Ellipse ))
2414 myIntersected = Standard_False; // no other intersection
2415
2416 Standard_Boolean otherCase = Standard_True;
2417
2418 if (( h1 && ((HLRBRep_EdgeData*)myLEData)->OutLVSta()) ||
2419 (!h1 && ((HLRBRep_EdgeData*)myLEData)->OutLVEnd())) {
2420 if (iFaceTest || myLEInternal)
2421 otherCase = Standard_False;
2422 }
2423 else if (iFaceTest)
2424 otherCase = Standard_False;
2425
2426 if (otherCase) {
2427 if (( h1 && ((HLRBRep_EdgeData*)myLEData)->CutAtSta()) ||
2428 (!h1 && ((HLRBRep_EdgeData*)myLEData)->CutAtEnd())) {
2429 myIntersected = Standard_False; // two connected OutLines do not
2430 } // intersect themselves.
2431 }
2432 }
2433 return SameV;
2434}