1 // Created on: 1999-03-03
2 // Created by: Fabrice SERVANT
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // modified by Edward AGAPOV (eap) Tue Jan 22 12:29:55 2002 (occ53)
18 // Modified by skv - Thu Sep 25 18:24:29 2003 OCC567
20 #include <IntPolyh_Intersection.ixx>
21 #include <IntPolyh_SectionLine.hxx>
22 #include <IntPolyh_StartPoint.hxx>
23 #include <IntPolyh_MaillageAffinage.hxx>
24 #include <IntPolyh_Couple.hxx>
25 #include <IntPolyh_Triangle.hxx>
27 Standard_Integer MYDISPLAY = 0;
28 Standard_Integer MYPRINT = 0;
30 IntPolyh_Intersection::IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& S1,
31 const Handle(Adaptor3d_HSurface)& S2)
39 done = Standard_False;
40 TSectionLines.Init(1000);
41 TTangentZones.Init(10000);
45 IntPolyh_Intersection::IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& S1,
46 const Standard_Integer NbSU1,
47 const Standard_Integer NbSV1,
48 const Handle(Adaptor3d_HSurface)& S2,
49 const Standard_Integer NbSU2,
50 const Standard_Integer NbSV2)
58 done = Standard_False;
59 TSectionLines.Init(1000);
60 TTangentZones.Init(10000);
64 void IntPolyh_Intersection::Perform() {
68 Standard_Boolean startFromAdvanced = Standard_False;
69 Standard_Boolean isStdDone = Standard_False;
70 Standard_Boolean isAdvDone = Standard_False;
71 Standard_Integer nbCouplesStd = 0;
72 Standard_Integer nbCouplesAdv = 0;
74 //GeomAbs_SurfaceType ST1 = mySurf1->GetType();
75 //GeomAbs_SurfaceType ST2 = mySurf2->GetType();
77 // if(ST1 == GeomAbs_Torus || ST2 == GeomAbs_Torus)
78 // startFromAdvanced = Standard_True;
80 IntPolyh_PMaillageAffinage aPMaillageStd = 0;
81 IntPolyh_PMaillageAffinage aPMaillageFF = 0;
82 IntPolyh_PMaillageAffinage aPMaillageFR = 0;
83 IntPolyh_PMaillageAffinage aPMaillageRF = 0;
84 IntPolyh_PMaillageAffinage aPMaillageRR = 0;
87 if(!startFromAdvanced) {
89 isStdDone = PerformStd(aPMaillageStd,nbCouplesStd);
91 // default interference done well, use it
92 if(isStdDone && nbCouplesStd > 10) {
93 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
95 // default interference done, but too few interferences foud;
96 // use advanced interference
97 else if(isStdDone && nbCouplesStd <= 10) {
98 isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
100 // advanced interference found
101 if(isAdvDone && nbCouplesAdv > 10) {
102 aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
103 aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
104 aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
105 aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
108 // use result of default
110 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
113 // default interference faild, use advanced
115 // isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
117 // if(isAdvDone && nbCouplesAdv > 0) {cout << "4adv done, nbc: " << nbCouplesAdv << endl;
118 // aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
119 // aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
120 // aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
121 // aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
124 }// start from default
127 isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
129 // advanced done, interference found; use it
132 if(nbCouplesAdv > 0) {
133 aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
134 aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
135 aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
136 aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
139 isStdDone = PerformStd(aPMaillageStd,nbCouplesStd);
140 if(isStdDone && nbCouplesStd > 0)
141 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
145 isStdDone = PerformStd(aPMaillageStd,nbCouplesStd);
146 if(isStdDone && nbCouplesStd > 0)
147 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
149 } // start from advanced
152 nbsectionlines = TSectionLines.NbItems();
153 nbtangentzones = TTangentZones.NbItems();
156 if(aPMaillageStd) delete aPMaillageStd;
157 if(aPMaillageFF) delete aPMaillageFF;
158 if(aPMaillageFR) delete aPMaillageFR;
159 if(aPMaillageRF) delete aPMaillageRF;
160 if(aPMaillageRR) delete aPMaillageRR;
163 if(!isStdDone && !isAdvDone)
164 done = Standard_False;
168 Standard_Boolean IntPolyh_Intersection::IsDone() const {
173 Standard_Integer IntPolyh_Intersection::NbSectionLines() const {
174 return(nbsectionlines);
178 Standard_Integer IntPolyh_Intersection::NbPointsInLine(const Standard_Integer IndexLine) const {
180 return(TSectionLines[IndexLine-1].NbStartPoints());
184 Standard_Integer IntPolyh_Intersection::NbPointsInTangentZone(const Standard_Integer) const {
185 //-- IndexLine--; (pas implemente) Attention : Tableaux de 0 a n-1
187 // return(TTangentZones.NbTangentZones());
192 Standard_Integer IntPolyh_Intersection::NbTangentZones() const {
193 return(nbtangentzones);
197 void IntPolyh_Intersection::GetLinePoint(const Standard_Integer Indexl,
198 const Standard_Integer Indexp,
206 Standard_Real &incidence) const {
207 const IntPolyh_SectionLine &msl=TSectionLines[Indexl-1];
208 const IntPolyh_StartPoint &sp=msl[Indexp-1];
216 incidence=sp.GetAngle();
220 void IntPolyh_Intersection::GetTangentZonePoint(const Standard_Integer Indexz,
221 const Standard_Integer /*Indexp*/,
228 Standard_Real &v2) const {
229 //-- Indexz--; tableaux C
231 //const IntPolyh_StartPoint &sp=TTangentZones[Indexp-1];
232 const IntPolyh_StartPoint &sp=TTangentZones[Indexz-1];
242 // Modified by skv - Thu Sep 25 18:07:41 2003 OCC567 Begin
243 //=======================================================================
244 //function : PerformMaillage
245 //purpose : Computes MaillageAffinage
246 //=======================================================================
247 Standard_Boolean IntPolyh_Intersection::PerformMaillage
248 (const Standard_Boolean isFirstFwd,
249 const Standard_Boolean isSecondFwd,
250 IntPolyh_PMaillageAffinage &theMaillageS)
253 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, mySurf2, MYPRINT);
255 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, myNbSU1, myNbSV1,
256 mySurf2, myNbSU2, myNbSV2,
259 theMaillageS->FillArrayOfPnt(1, isFirstFwd);
260 theMaillageS->FillArrayOfPnt(2, isSecondFwd);
263 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
264 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
265 xx0, yy0, zz0, xx1, yy1, zz1);
267 theMaillageS->FillArrayOfEdges(1);
268 theMaillageS->FillArrayOfEdges(2);
270 theMaillageS->FillArrayOfTriangles(1);
271 theMaillageS->FillArrayOfTriangles(2);
273 theMaillageS->LinkEdges2Triangles();
275 theMaillageS->TrianglesDeflectionsRefinementBSB();
277 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
279 // if too many intersections, consider surfaces parallel (eap)
281 (FinTTC >= theMaillageS->GetArrayOfTriangles(1).NbItems() ||
282 FinTTC >= theMaillageS->GetArrayOfTriangles(2).NbItems()) ) {
283 return Standard_False;
286 return Standard_True;
289 //=======================================================================
290 //function : PerformMaillage
291 //purpose : Computes MaillageAffinage
292 //=======================================================================
293 Standard_Boolean IntPolyh_Intersection::PerformMaillage(IntPolyh_PMaillageAffinage &theMaillageS)
296 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, mySurf2, MYPRINT);
298 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, myNbSU1, myNbSV1,
299 mySurf2, myNbSU2, myNbSV2,
302 theMaillageS->FillArrayOfPnt(1);
303 theMaillageS->FillArrayOfPnt(2);
306 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
307 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
308 xx0, yy0, zz0, xx1, yy1, zz1);
310 theMaillageS->FillArrayOfEdges(1);
311 theMaillageS->FillArrayOfEdges(2);
313 theMaillageS->FillArrayOfTriangles(1);
314 theMaillageS->FillArrayOfTriangles(2);
316 theMaillageS->LinkEdges2Triangles();
318 theMaillageS->TrianglesDeflectionsRefinementBSB();
320 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
323 Standard_Boolean myZone = Standard_True;
324 theMaillageS->SetEnlargeZone( myZone );
325 theMaillageS->FillArrayOfPnt(1);
326 theMaillageS->FillArrayOfPnt(2);
327 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
328 xx0, yy0, zz0, xx1, yy1, zz1);
329 theMaillageS->FillArrayOfEdges(1);
330 theMaillageS->FillArrayOfEdges(2);
331 theMaillageS->FillArrayOfTriangles(1);
332 theMaillageS->FillArrayOfTriangles(2);
333 theMaillageS->LinkEdges2Triangles();
334 theMaillageS->TrianglesDeflectionsRefinementBSB();
335 FinTTC = theMaillageS->TriangleCompare();
336 myZone = Standard_False;
337 theMaillageS->SetEnlargeZone( myZone );
341 // if too many intersections, consider surfaces parallel (eap)
343 (FinTTC >= theMaillageS->GetArrayOfTriangles(1).NbTriangles() ||
344 FinTTC >= theMaillageS->GetArrayOfTriangles(2).NbTriangles()) ) {
345 return Standard_False;
349 return Standard_True;
352 //=======================================================================
353 //function : MergeCouples
354 //purpose : This method analyzes arrays to find same couples. If some
355 // are detected it leaves the couple in only one array
356 // deleting from others.
357 //=======================================================================
359 void IntPolyh_Intersection::MergeCouples
360 (IntPolyh_ArrayOfCouples &anArrayFF,
361 IntPolyh_ArrayOfCouples &anArrayFR,
362 IntPolyh_ArrayOfCouples &anArrayRF,
363 IntPolyh_ArrayOfCouples &anArrayRR) const
365 // Step 1: Sorting arrays.
366 IntPolyh_ArrayOfCouples *anArrays[4];
367 Standard_Integer aNbCouples[4];
369 IntPolyh_ArrayOfCouples *aTmpPtr;
370 Standard_Integer aTmpNbr;
372 anArrays[0] = &anArrayFF;
373 anArrays[1] = &anArrayFR;
374 anArrays[2] = &anArrayRF;
375 anArrays[3] = &anArrayRR;
377 for (i = 0; i < 4; i++)
378 aNbCouples[i] = anArrays[i]->NbItems();
380 Standard_Boolean isChanged = Standard_True;
383 isChanged = Standard_False;
385 for (i = 0; i < 3; i++) {
386 if (aNbCouples[i] < aNbCouples[i + 1]) {
387 aTmpPtr = anArrays[i];
388 anArrays[i] = anArrays[i + 1];
389 anArrays[i + 1] = aTmpPtr;
390 aTmpNbr = aNbCouples[i];
391 aNbCouples[i] = aNbCouples[i + 1];
392 aNbCouples[i + 1] = aTmpNbr;
393 isChanged = Standard_True;
398 // Step 2: Searching for same couples.
400 Standard_Integer indC1;
401 Standard_Integer indC2;
403 for (i = 0; i < 3; i++) {
404 for (j = i + 1; j < 4; j++) {
405 for (indC1 = 1; indC1 <= aNbCouples[i]; indC1++) {
406 IntPolyh_Couple &aCouple1 = anArrays[i]->ChangeValue(indC1);
408 if (aCouple1.AnalyseFlagValue() == 1)
411 for (indC2 = 1; indC2 <= aNbCouples[j]; indC2++) {
412 IntPolyh_Couple &aCouple2 = anArrays[j]->ChangeValue(indC2);
414 if (aCouple2.AnalyseFlagValue() == 1)
417 if (aCouple1.FirstValue() == aCouple2.FirstValue() &&
418 aCouple1.SecondValue() == aCouple2.SecondValue()) {
419 aCouple2.SetAnalyseFlag(1);
426 // Modified by skv - Thu Sep 25 18:07:42 2003 OCC567 End
428 Standard_Boolean IntPolyh_Intersection::PerformStd(IntPolyh_PMaillageAffinage& MaillageS,
429 Standard_Integer& NbCouples)
431 Standard_Boolean isdone = PerformMaillage(MaillageS);
432 NbCouples = (isdone) ? (MaillageS->GetArrayOfCouples().NbItems()) : 0;
436 Standard_Boolean IntPolyh_Intersection::PerformAdv(IntPolyh_PMaillageAffinage& MaillageFF,
437 IntPolyh_PMaillageAffinage& MaillageFR,
438 IntPolyh_PMaillageAffinage& MaillageRF,
439 IntPolyh_PMaillageAffinage& MaillageRR,
440 Standard_Integer& NbCouples)
442 Standard_Boolean isdone = Standard_True;
445 if(!PerformMaillage(Standard_True,Standard_False,MaillageFR) ||
446 !PerformMaillage(Standard_False,Standard_True,MaillageRF) ||
447 !PerformMaillage(Standard_True,Standard_True,MaillageFF) ||
448 !PerformMaillage(Standard_False,Standard_False,MaillageRR) )
449 isdone = Standard_False;
452 NbCouples = MaillageFF->GetArrayOfCouples().NbItems() +
453 MaillageFR->GetArrayOfCouples().NbItems() +
454 MaillageRF->GetArrayOfCouples().NbItems() +
455 MaillageRR->GetArrayOfCouples().NbItems();
458 MergeCouples(MaillageFF->GetArrayOfCouples(),MaillageFR->GetArrayOfCouples(),
459 MaillageRF->GetArrayOfCouples(),MaillageRR->GetArrayOfCouples());