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>
37 Standard_Integer MYDISPLAY = 0;
38 Standard_Integer MYPRINT = 0;
41 // # include "visudebug.hxx"
45 IntPolyh_Intersection::IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& S1,
46 const Handle(Adaptor3d_HSurface)& S2)
54 done = Standard_False;
55 TSectionLines.Init(1000);
56 TTangentZones.Init(10000);
60 IntPolyh_Intersection::IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& S1,
61 const Standard_Integer NbSU1,
62 const Standard_Integer NbSV1,
63 const Handle(Adaptor3d_HSurface)& S2,
64 const Standard_Integer NbSU2,
65 const Standard_Integer NbSV2)
73 done = Standard_False;
74 TSectionLines.Init(1000);
75 TTangentZones.Init(10000);
79 void IntPolyh_Intersection::Perform() {
83 Standard_Boolean startFromAdvanced = Standard_False;
84 Standard_Boolean isStdDone = Standard_False;
85 Standard_Boolean isAdvDone = Standard_False;
86 Standard_Integer nbCouplesStd = 0;
87 Standard_Integer nbCouplesAdv = 0;
89 //GeomAbs_SurfaceType ST1 = mySurf1->GetType();
90 //GeomAbs_SurfaceType ST2 = mySurf2->GetType();
92 // if(ST1 == GeomAbs_Torus || ST2 == GeomAbs_Torus)
93 // startFromAdvanced = Standard_True;
95 IntPolyh_PMaillageAffinage aPMaillageStd = 0;
96 IntPolyh_PMaillageAffinage aPMaillageFF = 0;
97 IntPolyh_PMaillageAffinage aPMaillageFR = 0;
98 IntPolyh_PMaillageAffinage aPMaillageRF = 0;
99 IntPolyh_PMaillageAffinage aPMaillageRR = 0;
102 if(!startFromAdvanced) {
104 isStdDone = PerformStd(aPMaillageStd,nbCouplesStd);
106 // default interference done well, use it
107 if(isStdDone && nbCouplesStd > 10) {
108 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
110 // default interference done, but too few interferences foud;
111 // use advanced interference
112 else if(isStdDone && nbCouplesStd <= 10) {
113 isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
115 // advanced interference found
116 if(isAdvDone && nbCouplesAdv > 10) {
117 aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
118 aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
119 aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
120 aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
123 // use result of default
125 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
128 // default interference faild, use advanced
130 // isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
132 // if(isAdvDone && nbCouplesAdv > 0) {cout << "4adv done, nbc: " << nbCouplesAdv << endl;
133 // aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
134 // aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
135 // aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
136 // aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
139 }// start from default
142 isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
144 // advanced done, interference found; use it
147 if(nbCouplesAdv > 0) {
148 aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
149 aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
150 aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
151 aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
154 isStdDone = PerformStd(aPMaillageStd,nbCouplesStd);
155 if(isStdDone && nbCouplesStd > 0)
156 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
160 isStdDone = PerformStd(aPMaillageStd,nbCouplesStd);
161 if(isStdDone && nbCouplesStd > 0)
162 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
164 } // start from advanced
167 nbsectionlines = TSectionLines.NbSectionLines();
168 nbtangentzones = TTangentZones.NbTangentZones();
171 if(aPMaillageStd) delete aPMaillageStd;
172 if(aPMaillageFF) delete aPMaillageFF;
173 if(aPMaillageFR) delete aPMaillageFR;
174 if(aPMaillageRF) delete aPMaillageRF;
175 if(aPMaillageRR) delete aPMaillageRR;
178 if(!isStdDone && !isAdvDone)
179 done = Standard_False;
183 Standard_Boolean IntPolyh_Intersection::IsDone() const {
188 Standard_Integer IntPolyh_Intersection::NbSectionLines() const {
189 return(nbsectionlines);
193 Standard_Integer IntPolyh_Intersection::NbPointsInLine(const Standard_Integer IndexLine) const {
195 return(TSectionLines[IndexLine-1].NbStartPoints());
199 Standard_Integer IntPolyh_Intersection::NbPointsInTangentZone(const Standard_Integer IndexLine) const {
200 //-- IndexLine--; (pas implemente) Attention : Tableaux de 0 a n-1
202 // return(TTangentZones.NbTangentZones());
207 Standard_Integer IntPolyh_Intersection::NbTangentZones() const {
208 return(nbtangentzones);
212 void IntPolyh_Intersection::GetLinePoint(const Standard_Integer Indexl,
213 const Standard_Integer Indexp,
221 Standard_Real &incidence) const {
222 const IntPolyh_SectionLine &msl=TSectionLines[Indexl-1];
223 const IntPolyh_StartPoint &sp=msl[Indexp-1];
231 incidence=sp.GetAngle();
235 void IntPolyh_Intersection::GetTangentZonePoint(const Standard_Integer Indexz,
236 const Standard_Integer Indexp,
243 Standard_Real &v2) const {
244 //-- Indexz--; tableaux C
246 //const IntPolyh_StartPoint &sp=TTangentZones[Indexp-1];
247 const IntPolyh_StartPoint &sp=TTangentZones[Indexz-1];
257 // Modified by skv - Thu Sep 25 18:07:41 2003 OCC567 Begin
258 //=======================================================================
259 //function : PerformMaillage
260 //purpose : Computes MaillageAffinage
261 //=======================================================================
262 Standard_Boolean IntPolyh_Intersection::PerformMaillage
263 (const Standard_Boolean isFirstFwd,
264 const Standard_Boolean isSecondFwd,
265 IntPolyh_PMaillageAffinage &theMaillageS)
268 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, mySurf2, MYPRINT);
270 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, myNbSU1, myNbSV1,
271 mySurf2, myNbSU2, myNbSV2,
274 theMaillageS->FillArrayOfPnt(1, isFirstFwd);
275 theMaillageS->FillArrayOfPnt(2, isSecondFwd);
278 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
279 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
280 xx0, yy0, zz0, xx1, yy1, zz1);
282 theMaillageS->FillArrayOfEdges(1);
283 theMaillageS->FillArrayOfEdges(2);
285 theMaillageS->FillArrayOfTriangles(1);
286 theMaillageS->FillArrayOfTriangles(2);
288 theMaillageS->LinkEdges2Triangles();
290 theMaillageS->TrianglesDeflectionsRefinementBSB();
292 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
294 // if too many intersections, consider surfaces parallel (eap)
296 (FinTTC >= theMaillageS->GetArrayOfTriangles(1).NbTriangles() ||
297 FinTTC >= theMaillageS->GetArrayOfTriangles(2).NbTriangles()) ) {
298 return Standard_False;
301 return Standard_True;
304 //=======================================================================
305 //function : PerformMaillage
306 //purpose : Computes MaillageAffinage
307 //=======================================================================
308 Standard_Boolean IntPolyh_Intersection::PerformMaillage(IntPolyh_PMaillageAffinage &theMaillageS)
311 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, mySurf2, MYPRINT);
313 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, myNbSU1, myNbSV1,
314 mySurf2, myNbSU2, myNbSV2,
317 theMaillageS->FillArrayOfPnt(1);
318 theMaillageS->FillArrayOfPnt(2);
321 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
322 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
323 xx0, yy0, zz0, xx1, yy1, zz1);
325 theMaillageS->FillArrayOfEdges(1);
326 theMaillageS->FillArrayOfEdges(2);
328 theMaillageS->FillArrayOfTriangles(1);
329 theMaillageS->FillArrayOfTriangles(2);
331 theMaillageS->LinkEdges2Triangles();
333 theMaillageS->TrianglesDeflectionsRefinementBSB();
335 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
338 Standard_Boolean myZone = Standard_True;
339 theMaillageS->SetEnlargeZone( myZone );
340 theMaillageS->FillArrayOfPnt(1);
341 theMaillageS->FillArrayOfPnt(2);
342 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
343 xx0, yy0, zz0, xx1, yy1, zz1);
344 theMaillageS->FillArrayOfEdges(1);
345 theMaillageS->FillArrayOfEdges(2);
346 theMaillageS->FillArrayOfTriangles(1);
347 theMaillageS->FillArrayOfTriangles(2);
348 theMaillageS->LinkEdges2Triangles();
349 theMaillageS->TrianglesDeflectionsRefinementBSB();
350 FinTTC = theMaillageS->TriangleCompare();
351 myZone = Standard_False;
352 theMaillageS->SetEnlargeZone( myZone );
356 // if too many intersections, consider surfaces parallel (eap)
358 (FinTTC >= theMaillageS->GetArrayOfTriangles(1).NbTriangles() ||
359 FinTTC >= theMaillageS->GetArrayOfTriangles(2).NbTriangles()) ) {
360 return Standard_False;
364 return Standard_True;
367 //=======================================================================
368 //function : MergeCouples
369 //purpose : This method analyzes arrays to find same couples. If some
370 // are detected it leaves the couple in only one array
371 // deleting from others.
372 //=======================================================================
374 void IntPolyh_Intersection::MergeCouples
375 (IntPolyh_ArrayOfCouples &anArrayFF,
376 IntPolyh_ArrayOfCouples &anArrayFR,
377 IntPolyh_ArrayOfCouples &anArrayRF,
378 IntPolyh_ArrayOfCouples &anArrayRR) const
380 // Step 1: Sorting arrays.
381 IntPolyh_ArrayOfCouples *anArrays[4];
382 Standard_Integer aNbCouples[4];
384 IntPolyh_ArrayOfCouples *aTmpPtr;
385 Standard_Integer aTmpNbr;
387 anArrays[0] = &anArrayFF;
388 anArrays[1] = &anArrayFR;
389 anArrays[2] = &anArrayRF;
390 anArrays[3] = &anArrayRR;
392 for (i = 0; i < 4; i++)
393 aNbCouples[i] = anArrays[i]->NbCouples();
395 Standard_Boolean isChanged = Standard_True;
398 isChanged = Standard_False;
400 for (i = 0; i < 3; i++) {
401 if (aNbCouples[i] < aNbCouples[i + 1]) {
402 aTmpPtr = anArrays[i];
403 anArrays[i] = anArrays[i + 1];
404 anArrays[i + 1] = aTmpPtr;
405 aTmpNbr = aNbCouples[i];
406 aNbCouples[i] = aNbCouples[i + 1];
407 aNbCouples[i + 1] = aTmpNbr;
408 isChanged = Standard_True;
413 // Step 2: Searching for same couples.
415 Standard_Integer indC1;
416 Standard_Integer indC2;
418 for (i = 0; i < 3; i++) {
419 for (j = i + 1; j < 4; j++) {
420 for (indC1 = 1; indC1 <= aNbCouples[i]; indC1++) {
421 IntPolyh_Couple &aCouple1 = anArrays[i]->ChangeValue(indC1);
423 if (aCouple1.AnalyseFlagValue() == 1)
426 for (indC2 = 1; indC2 <= aNbCouples[j]; indC2++) {
427 IntPolyh_Couple &aCouple2 = anArrays[j]->ChangeValue(indC2);
429 if (aCouple2.AnalyseFlagValue() == 1)
432 if (aCouple1.FirstValue() == aCouple2.FirstValue() &&
433 aCouple1.SecondValue() == aCouple2.SecondValue()) {
434 aCouple2.SetAnalyseFlag(1);
441 // Modified by skv - Thu Sep 25 18:07:42 2003 OCC567 End
443 Standard_Boolean IntPolyh_Intersection::PerformStd(IntPolyh_PMaillageAffinage& MaillageS,
444 Standard_Integer& NbCouples)
446 Standard_Boolean isdone = PerformMaillage(MaillageS);
447 NbCouples = (isdone) ? (MaillageS->GetArrayOfCouples().NbCouples()) : 0;
451 Standard_Boolean IntPolyh_Intersection::PerformAdv(IntPolyh_PMaillageAffinage& MaillageFF,
452 IntPolyh_PMaillageAffinage& MaillageFR,
453 IntPolyh_PMaillageAffinage& MaillageRF,
454 IntPolyh_PMaillageAffinage& MaillageRR,
455 Standard_Integer& NbCouples)
457 Standard_Boolean isdone = Standard_True;
460 if(!PerformMaillage(Standard_True,Standard_False,MaillageFR) ||
461 !PerformMaillage(Standard_False,Standard_True,MaillageRF) ||
462 !PerformMaillage(Standard_True,Standard_True,MaillageFF) ||
463 !PerformMaillage(Standard_False,Standard_False,MaillageRR) )
464 isdone = Standard_False;
467 NbCouples = MaillageFF->GetArrayOfCouples().NbCouples() +
468 MaillageFR->GetArrayOfCouples().NbCouples() +
469 MaillageRF->GetArrayOfCouples().NbCouples() +
470 MaillageRR->GetArrayOfCouples().NbCouples();
473 MergeCouples(MaillageFF->GetArrayOfCouples(),MaillageFR->GetArrayOfCouples(),
474 MaillageRF->GetArrayOfCouples(),MaillageRR->GetArrayOfCouples());