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