1 // Created on: 1999-03-03
2 // Created by: Fabrice SERVANT
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 // modified by Edward AGAPOV (eap) Tue Jan 22 12:29:55 2002 (occ53)
23 // Modified by skv - Thu Sep 25 18:24:29 2003 OCC567
25 #include <IntPolyh_Intersection.ixx>
26 #include <IntPolyh_SectionLine.hxx>
27 #include <IntPolyh_StartPoint.hxx>
28 #include <IntPolyh_MaillageAffinage.hxx>
29 #include <IntPolyh_Couple.hxx>
30 #include <IntPolyh_Triangle.hxx>
38 Standard_Integer MYDISPLAY = 0;
39 Standard_Integer MYPRINT = 0;
42 // # include "visudebug.hxx"
46 IntPolyh_Intersection::IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& S1,
47 const Handle(Adaptor3d_HSurface)& S2)
55 done = Standard_False;
56 TSectionLines.Init(1000);
57 TTangentZones.Init(10000);
61 IntPolyh_Intersection::IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& S1,
62 const Standard_Integer NbSU1,
63 const Standard_Integer NbSV1,
64 const Handle(Adaptor3d_HSurface)& S2,
65 const Standard_Integer NbSU2,
66 const Standard_Integer NbSV2)
74 done = Standard_False;
75 TSectionLines.Init(1000);
76 TTangentZones.Init(10000);
80 void IntPolyh_Intersection::Perform() {
84 Standard_Boolean startFromAdvanced = Standard_False;
85 Standard_Boolean isStdDone = Standard_False;
86 Standard_Boolean isAdvDone = Standard_False;
87 Standard_Integer nbCouplesStd = 0;
88 Standard_Integer nbCouplesAdv = 0;
90 //GeomAbs_SurfaceType ST1 = mySurf1->GetType();
91 //GeomAbs_SurfaceType ST2 = mySurf2->GetType();
93 // if(ST1 == GeomAbs_Torus || ST2 == GeomAbs_Torus)
94 // startFromAdvanced = Standard_True;
96 IntPolyh_PMaillageAffinage aPMaillageStd = 0;
97 IntPolyh_PMaillageAffinage aPMaillageFF = 0;
98 IntPolyh_PMaillageAffinage aPMaillageFR = 0;
99 IntPolyh_PMaillageAffinage aPMaillageRF = 0;
100 IntPolyh_PMaillageAffinage aPMaillageRR = 0;
103 if(!startFromAdvanced) {
105 isStdDone = PerformStd(aPMaillageStd,nbCouplesStd);
107 // default interference done well, use it
108 if(isStdDone && nbCouplesStd > 10) {
109 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
111 // default interference done, but too few interferences foud;
112 // use advanced interference
113 else if(isStdDone && nbCouplesStd <= 10) {
114 isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
116 // advanced interference found
117 if(isAdvDone && nbCouplesAdv > 10) {
118 aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
119 aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
120 aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
121 aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
124 // use result of default
126 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
129 // default interference faild, use advanced
131 // isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
133 // if(isAdvDone && nbCouplesAdv > 0) {cout << "4adv done, nbc: " << nbCouplesAdv << endl;
134 // aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
135 // aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
136 // aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
137 // aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
140 }// start from default
143 isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
145 // advanced done, interference found; use it
148 if(nbCouplesAdv > 0) {
149 aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
150 aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
151 aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
152 aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
155 isStdDone = PerformStd(aPMaillageStd,nbCouplesStd);
156 if(isStdDone && nbCouplesStd > 0)
157 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
161 isStdDone = PerformStd(aPMaillageStd,nbCouplesStd);
162 if(isStdDone && nbCouplesStd > 0)
163 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
165 } // start from advanced
168 nbsectionlines = TSectionLines.NbItems();
169 nbtangentzones = TTangentZones.NbItems();
172 if(aPMaillageStd) delete aPMaillageStd;
173 if(aPMaillageFF) delete aPMaillageFF;
174 if(aPMaillageFR) delete aPMaillageFR;
175 if(aPMaillageRF) delete aPMaillageRF;
176 if(aPMaillageRR) delete aPMaillageRR;
179 if(!isStdDone && !isAdvDone)
180 done = Standard_False;
184 Standard_Boolean IntPolyh_Intersection::IsDone() const {
189 Standard_Integer IntPolyh_Intersection::NbSectionLines() const {
190 return(nbsectionlines);
194 Standard_Integer IntPolyh_Intersection::NbPointsInLine(const Standard_Integer IndexLine) const {
196 return(TSectionLines[IndexLine-1].NbStartPoints());
200 Standard_Integer IntPolyh_Intersection::NbPointsInTangentZone(const Standard_Integer IndexLine) const {
201 //-- IndexLine--; (pas implemente) Attention : Tableaux de 0 a n-1
203 // return(TTangentZones.NbTangentZones());
208 Standard_Integer IntPolyh_Intersection::NbTangentZones() const {
209 return(nbtangentzones);
213 void IntPolyh_Intersection::GetLinePoint(const Standard_Integer Indexl,
214 const Standard_Integer Indexp,
222 Standard_Real &incidence) const {
223 const IntPolyh_SectionLine &msl=TSectionLines[Indexl-1];
224 const IntPolyh_StartPoint &sp=msl[Indexp-1];
232 incidence=sp.GetAngle();
236 void IntPolyh_Intersection::GetTangentZonePoint(const Standard_Integer Indexz,
237 const Standard_Integer Indexp,
244 Standard_Real &v2) const {
245 //-- Indexz--; tableaux C
247 //const IntPolyh_StartPoint &sp=TTangentZones[Indexp-1];
248 const IntPolyh_StartPoint &sp=TTangentZones[Indexz-1];
258 // Modified by skv - Thu Sep 25 18:07:41 2003 OCC567 Begin
259 //=======================================================================
260 //function : PerformMaillage
261 //purpose : Computes MaillageAffinage
262 //=======================================================================
263 Standard_Boolean IntPolyh_Intersection::PerformMaillage
264 (const Standard_Boolean isFirstFwd,
265 const Standard_Boolean isSecondFwd,
266 IntPolyh_PMaillageAffinage &theMaillageS)
269 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, mySurf2, MYPRINT);
271 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, myNbSU1, myNbSV1,
272 mySurf2, myNbSU2, myNbSV2,
275 theMaillageS->FillArrayOfPnt(1, isFirstFwd);
276 theMaillageS->FillArrayOfPnt(2, isSecondFwd);
279 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
280 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
281 xx0, yy0, zz0, xx1, yy1, zz1);
283 theMaillageS->FillArrayOfEdges(1);
284 theMaillageS->FillArrayOfEdges(2);
286 theMaillageS->FillArrayOfTriangles(1);
287 theMaillageS->FillArrayOfTriangles(2);
289 theMaillageS->LinkEdges2Triangles();
291 theMaillageS->TrianglesDeflectionsRefinementBSB();
293 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
295 // if too many intersections, consider surfaces parallel (eap)
297 (FinTTC >= theMaillageS->GetArrayOfTriangles(1).NbItems() ||
298 FinTTC >= theMaillageS->GetArrayOfTriangles(2).NbItems()) ) {
299 return Standard_False;
302 return Standard_True;
305 //=======================================================================
306 //function : PerformMaillage
307 //purpose : Computes MaillageAffinage
308 //=======================================================================
309 Standard_Boolean IntPolyh_Intersection::PerformMaillage(IntPolyh_PMaillageAffinage &theMaillageS)
312 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, mySurf2, MYPRINT);
314 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, myNbSU1, myNbSV1,
315 mySurf2, myNbSU2, myNbSV2,
318 theMaillageS->FillArrayOfPnt(1);
319 theMaillageS->FillArrayOfPnt(2);
322 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
323 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
324 xx0, yy0, zz0, xx1, yy1, zz1);
326 theMaillageS->FillArrayOfEdges(1);
327 theMaillageS->FillArrayOfEdges(2);
329 theMaillageS->FillArrayOfTriangles(1);
330 theMaillageS->FillArrayOfTriangles(2);
332 theMaillageS->LinkEdges2Triangles();
334 theMaillageS->TrianglesDeflectionsRefinementBSB();
336 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
339 Standard_Boolean myZone = Standard_True;
340 theMaillageS->SetEnlargeZone( myZone );
341 theMaillageS->FillArrayOfPnt(1);
342 theMaillageS->FillArrayOfPnt(2);
343 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
344 xx0, yy0, zz0, xx1, yy1, zz1);
345 theMaillageS->FillArrayOfEdges(1);
346 theMaillageS->FillArrayOfEdges(2);
347 theMaillageS->FillArrayOfTriangles(1);
348 theMaillageS->FillArrayOfTriangles(2);
349 theMaillageS->LinkEdges2Triangles();
350 theMaillageS->TrianglesDeflectionsRefinementBSB();
351 FinTTC = theMaillageS->TriangleCompare();
352 myZone = Standard_False;
353 theMaillageS->SetEnlargeZone( myZone );
357 // if too many intersections, consider surfaces parallel (eap)
359 (FinTTC >= theMaillageS->GetArrayOfTriangles(1).NbTriangles() ||
360 FinTTC >= theMaillageS->GetArrayOfTriangles(2).NbTriangles()) ) {
361 return Standard_False;
365 return Standard_True;
368 //=======================================================================
369 //function : MergeCouples
370 //purpose : This method analyzes arrays to find same couples. If some
371 // are detected it leaves the couple in only one array
372 // deleting from others.
373 //=======================================================================
375 void IntPolyh_Intersection::MergeCouples
376 (IntPolyh_ArrayOfCouples &anArrayFF,
377 IntPolyh_ArrayOfCouples &anArrayFR,
378 IntPolyh_ArrayOfCouples &anArrayRF,
379 IntPolyh_ArrayOfCouples &anArrayRR) const
381 // Step 1: Sorting arrays.
382 IntPolyh_ArrayOfCouples *anArrays[4];
383 Standard_Integer aNbCouples[4];
385 IntPolyh_ArrayOfCouples *aTmpPtr;
386 Standard_Integer aTmpNbr;
388 anArrays[0] = &anArrayFF;
389 anArrays[1] = &anArrayFR;
390 anArrays[2] = &anArrayRF;
391 anArrays[3] = &anArrayRR;
393 for (i = 0; i < 4; i++)
394 aNbCouples[i] = anArrays[i]->NbItems();
396 Standard_Boolean isChanged = Standard_True;
399 isChanged = Standard_False;
401 for (i = 0; i < 3; i++) {
402 if (aNbCouples[i] < aNbCouples[i + 1]) {
403 aTmpPtr = anArrays[i];
404 anArrays[i] = anArrays[i + 1];
405 anArrays[i + 1] = aTmpPtr;
406 aTmpNbr = aNbCouples[i];
407 aNbCouples[i] = aNbCouples[i + 1];
408 aNbCouples[i + 1] = aTmpNbr;
409 isChanged = Standard_True;
414 // Step 2: Searching for same couples.
416 Standard_Integer indC1;
417 Standard_Integer indC2;
419 for (i = 0; i < 3; i++) {
420 for (j = i + 1; j < 4; j++) {
421 for (indC1 = 1; indC1 <= aNbCouples[i]; indC1++) {
422 IntPolyh_Couple &aCouple1 = anArrays[i]->ChangeValue(indC1);
424 if (aCouple1.AnalyseFlagValue() == 1)
427 for (indC2 = 1; indC2 <= aNbCouples[j]; indC2++) {
428 IntPolyh_Couple &aCouple2 = anArrays[j]->ChangeValue(indC2);
430 if (aCouple2.AnalyseFlagValue() == 1)
433 if (aCouple1.FirstValue() == aCouple2.FirstValue() &&
434 aCouple1.SecondValue() == aCouple2.SecondValue()) {
435 aCouple2.SetAnalyseFlag(1);
442 // Modified by skv - Thu Sep 25 18:07:42 2003 OCC567 End
444 Standard_Boolean IntPolyh_Intersection::PerformStd(IntPolyh_PMaillageAffinage& MaillageS,
445 Standard_Integer& NbCouples)
447 Standard_Boolean isdone = PerformMaillage(MaillageS);
448 NbCouples = (isdone) ? (MaillageS->GetArrayOfCouples().NbItems()) : 0;
452 Standard_Boolean IntPolyh_Intersection::PerformAdv(IntPolyh_PMaillageAffinage& MaillageFF,
453 IntPolyh_PMaillageAffinage& MaillageFR,
454 IntPolyh_PMaillageAffinage& MaillageRF,
455 IntPolyh_PMaillageAffinage& MaillageRR,
456 Standard_Integer& NbCouples)
458 Standard_Boolean isdone = Standard_True;
461 if(!PerformMaillage(Standard_True,Standard_False,MaillageFR) ||
462 !PerformMaillage(Standard_False,Standard_True,MaillageRF) ||
463 !PerformMaillage(Standard_True,Standard_True,MaillageFF) ||
464 !PerformMaillage(Standard_False,Standard_False,MaillageRR) )
465 isdone = Standard_False;
468 NbCouples = MaillageFF->GetArrayOfCouples().NbItems() +
469 MaillageFR->GetArrayOfCouples().NbItems() +
470 MaillageRF->GetArrayOfCouples().NbItems() +
471 MaillageRR->GetArrayOfCouples().NbItems();
474 MergeCouples(MaillageFF->GetArrayOfCouples(),MaillageFR->GetArrayOfCouples(),
475 MaillageRF->GetArrayOfCouples(),MaillageRR->GetArrayOfCouples());