1 // Created on: 2005-09-26
2 // Created by: Igor FEOKTISTOV
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <Adaptor3d_HSurface.hxx>
18 #include <IntPolyh_ListOfCouples.hxx>
19 #include <IntPolyh_Couple.hxx>
20 #include <IntPolyh_Intersection.hxx>
21 #include <IntPolyh_MaillageAffinage.hxx>
22 #include <IntPolyh_PMaillageAffinage.hxx>
23 #include <IntPolyh_Triangle.hxx>
25 Standard_Integer MYPRINT1 = 0;
28 //=======================================================================
29 //function : IntPolyh_Intersection
31 //=======================================================================
32 IntPolyh_Intersection::IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& S1,
33 const TColStd_Array1OfReal& Upars1,
34 const TColStd_Array1OfReal& Vpars1,
35 const Handle(Adaptor3d_HSurface)& S2,
36 const TColStd_Array1OfReal& Upars2,
37 const TColStd_Array1OfReal& Vpars2)
39 myNbSU1 = Upars1.Length();
40 myNbSV1 = Vpars1.Length();
41 myNbSU2 = Upars2.Length();
42 myNbSV2 = Vpars2.Length();
45 done = Standard_False;
46 TSectionLines.Init(1000);
47 TTangentZones.Init(10000);
48 Perform(Upars1, Vpars1, Upars2, Vpars2);
51 //=======================================================================
54 //=======================================================================
56 void IntPolyh_Intersection::Perform(const TColStd_Array1OfReal& Upars1,
57 const TColStd_Array1OfReal& Vpars1,
58 const TColStd_Array1OfReal& Upars2,
59 const TColStd_Array1OfReal& Vpars2) {
63 Standard_Boolean isStdDone = Standard_False;
64 Standard_Boolean isAdvDone = Standard_False;
65 Standard_Integer nbCouplesStd = 0;
66 Standard_Integer nbCouplesAdv = 0;
69 IntPolyh_PMaillageAffinage aPMaillageStd = 0;
70 IntPolyh_PMaillageAffinage aPMaillageFF = 0;
71 IntPolyh_PMaillageAffinage aPMaillageFR = 0;
72 IntPolyh_PMaillageAffinage aPMaillageRF = 0;
73 IntPolyh_PMaillageAffinage aPMaillageRR = 0;
75 isStdDone = PerformStd( Upars1, Vpars1, Upars2, Vpars2,
76 aPMaillageStd,nbCouplesStd);
78 // default interference done well, use it
79 if(isStdDone && nbCouplesStd > 10) {
80 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
82 // default interference done, but too few interferences foud;
83 // use advanced interference
84 else if(isStdDone && nbCouplesStd <= 10) {
85 isAdvDone = PerformAdv( Upars1, Vpars1, Upars2, Vpars2,
86 aPMaillageFF,aPMaillageFR,aPMaillageRF,
87 aPMaillageRR,nbCouplesAdv);
89 // advanced interference found
90 if(isAdvDone && nbCouplesAdv > 0) {
91 aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
92 aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
93 aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
94 aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
97 // use result of default
99 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
102 // default interference faild, use advanced
104 // isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
106 // if(isAdvDone && nbCouplesAdv > 0) {cout << "4adv done, nbc: " << nbCouplesAdv << endl;
107 // aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
108 // aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
109 // aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
110 // aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
115 nbsectionlines = TSectionLines.NbItems();
116 nbtangentzones = TTangentZones.NbItems();
119 if(aPMaillageStd) delete aPMaillageStd;
120 if(aPMaillageFF) delete aPMaillageFF;
121 if(aPMaillageFR) delete aPMaillageFR;
122 if(aPMaillageRF) delete aPMaillageRF;
123 if(aPMaillageRR) delete aPMaillageRR;
126 if(!isStdDone && !isAdvDone)
127 done = Standard_False;
130 //=======================================================================
131 //function : PerformMaillage
132 //purpose : Computes MaillageAffinage
133 //=======================================================================
134 Standard_Boolean IntPolyh_Intersection::PerformMaillage(const Standard_Boolean isFirstFwd,
135 const Standard_Boolean isSecondFwd,
136 const TColStd_Array1OfReal& Upars1,
137 const TColStd_Array1OfReal& Vpars1,
138 const TColStd_Array1OfReal& Upars2,
139 const TColStd_Array1OfReal& Vpars2,
140 IntPolyh_PMaillageAffinage &theMaillageS)
142 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, Upars1.Length(), Vpars1.Length(),
143 mySurf2, Upars2.Length(), Vpars2.Length(),
147 theMaillageS->FillArrayOfPnt(1, isFirstFwd, Upars1, Vpars1);
148 theMaillageS->FillArrayOfPnt(2, isSecondFwd, Upars2, Vpars2);
152 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
153 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
154 xx0, yy0, zz0, xx1, yy1, zz1);
156 theMaillageS->FillArrayOfTriangles(1);
157 theMaillageS->FillArrayOfTriangles(2);
159 theMaillageS->FillArrayOfEdges(1);
160 theMaillageS->FillArrayOfEdges(2);
162 theMaillageS->TrianglesDeflectionsRefinementBSB();
164 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
166 // if too many intersections, consider surfaces parallel (eap)
167 // test for parallel surf
169 const Standard_Real eps = .996; //~ cos of 5deg.
170 IntPolyh_ListOfCouples& Couples = theMaillageS->GetCouples();
172 Standard_Integer npara = 0;
173 IntPolyh_ListIteratorOfListOfCouples aIt(Couples);
174 for(; aIt.More(); aIt.Next()) {
175 Standard_Real cosa = Abs(aIt.Value().Angle());
176 if(cosa > eps) ++npara;
178 if(npara >= theMaillageS->GetArrayOfTriangles(1).NbItems() ||
179 npara >= theMaillageS->GetArrayOfTriangles(2).NbItems() ) {
180 return Standard_False;
184 return Standard_True;
187 //=======================================================================
188 //function : PerformMaillage
189 //purpose : Computes MaillageAffinage
190 //=======================================================================
191 Standard_Boolean IntPolyh_Intersection::PerformMaillage(const TColStd_Array1OfReal& Upars1,
192 const TColStd_Array1OfReal& Vpars1,
193 const TColStd_Array1OfReal& Upars2,
194 const TColStd_Array1OfReal& Vpars2,
195 IntPolyh_PMaillageAffinage &theMaillageS)
198 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, Upars1.Length(), Vpars1.Length(),
199 mySurf2, Upars2.Length(), Vpars2.Length(),
202 theMaillageS->FillArrayOfPnt(1, Upars1, Vpars1);
203 theMaillageS->FillArrayOfPnt(2, Upars2, Vpars2);
206 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
207 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
208 xx0, yy0, zz0, xx1, yy1, zz1);
210 theMaillageS->FillArrayOfTriangles(1);
211 theMaillageS->FillArrayOfTriangles(2);
213 theMaillageS->FillArrayOfEdges(1);
214 theMaillageS->FillArrayOfEdges(2);
216 theMaillageS->TrianglesDeflectionsRefinementBSB();
218 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
221 Standard_Boolean myZone = Standard_True;
222 theMaillageS->SetEnlargeZone( myZone );
223 theMaillageS->FillArrayOfPnt(1);
224 theMaillageS->FillArrayOfPnt(2);
225 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
226 xx0, yy0, zz0, xx1, yy1, zz1);
227 theMaillageS->FillArrayOfTriangles(1);
228 theMaillageS->FillArrayOfTriangles(2);
229 theMaillageS->FillArrayOfEdges(1);
230 theMaillageS->FillArrayOfEdges(2);
231 theMaillageS->TrianglesDeflectionsRefinementBSB();
232 FinTTC = theMaillageS->TriangleCompare();
233 myZone = Standard_False;
234 theMaillageS->SetEnlargeZone( myZone );
237 // if too many intersections, consider surfaces parallel (eap)
238 //IFV test for parallel surf
240 const Standard_Real eps = .996; //~ cos of 5deg.
241 IntPolyh_ListOfCouples& Couples = theMaillageS->GetCouples();
243 Standard_Integer npara = 0;
244 IntPolyh_ListIteratorOfListOfCouples aIt(Couples);
245 for(; aIt.More(); aIt.Next()) {
246 Standard_Real cosa = Abs(aIt.Value().Angle());
247 if(cosa > eps) ++npara;
249 if(npara >= theMaillageS->GetArrayOfTriangles(1).NbItems() ||
250 npara >= theMaillageS->GetArrayOfTriangles(2).NbItems() ) {
251 return Standard_False;
255 return Standard_True;
258 //=======================================================================
259 //function : PerformAdv
261 //=======================================================================
262 Standard_Boolean IntPolyh_Intersection::PerformAdv(const TColStd_Array1OfReal& Upars1,
263 const TColStd_Array1OfReal& Vpars1,
264 const TColStd_Array1OfReal& Upars2,
265 const TColStd_Array1OfReal& Vpars2,
266 IntPolyh_PMaillageAffinage& MaillageFF,
267 IntPolyh_PMaillageAffinage& MaillageFR,
268 IntPolyh_PMaillageAffinage& MaillageRF,
269 IntPolyh_PMaillageAffinage& MaillageRR,
270 Standard_Integer& NbCouples)
272 Standard_Boolean isdone = Standard_True;
275 if(!PerformMaillage(Standard_True,Standard_False,
276 Upars1, Vpars1, Upars2, Vpars2,
278 !PerformMaillage(Standard_False,Standard_True,
279 Upars1, Vpars1, Upars2, Vpars2,
281 !PerformMaillage(Standard_True,Standard_True,
282 Upars1, Vpars1, Upars2, Vpars2,
284 !PerformMaillage(Standard_False,Standard_False,
285 Upars1, Vpars1, Upars2, Vpars2,
287 isdone = Standard_False;
290 NbCouples = MaillageFF->GetCouples().Extent() +
291 MaillageFR->GetCouples().Extent() +
292 MaillageRF->GetCouples().Extent() +
293 MaillageRR->GetCouples().Extent();
296 MergeCouples(MaillageFF->GetCouples(),MaillageFR->GetCouples(),
297 MaillageRF->GetCouples(),MaillageRR->GetCouples());
301 //=======================================================================
302 //function : PerformStd
304 //=======================================================================
306 Standard_Boolean IntPolyh_Intersection::PerformStd(const TColStd_Array1OfReal& Upars1,
307 const TColStd_Array1OfReal& Vpars1,
308 const TColStd_Array1OfReal& Upars2,
309 const TColStd_Array1OfReal& Vpars2,
310 IntPolyh_PMaillageAffinage& MaillageS,
311 Standard_Integer& NbCouples)
313 Standard_Boolean isdone = PerformMaillage(Upars1, Vpars1, Upars2, Vpars2,
315 NbCouples = (isdone) ? (MaillageS->GetCouples().Extent()) : 0;