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.
16 #include <IntPolyh_Intersection.ixx>
17 #include <IntPolyh_PMaillageAffinage.hxx>
18 #include <IntPolyh_MaillageAffinage.hxx>
19 #include <IntPolyh_ArrayOfCouples.hxx>
20 #include <IntPolyh_Couple.hxx>
21 #include <IntPolyh_Triangle.hxx>
23 Standard_Integer MYPRINT1 = 0;
26 //=======================================================================
27 //function : IntPolyh_Intersection
29 //=======================================================================
30 IntPolyh_Intersection::IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& S1,
31 const TColStd_Array1OfReal& Upars1,
32 const TColStd_Array1OfReal& Vpars1,
33 const Handle(Adaptor3d_HSurface)& S2,
34 const TColStd_Array1OfReal& Upars2,
35 const TColStd_Array1OfReal& Vpars2)
37 myNbSU1 = Upars1.Length();
38 myNbSV1 = Vpars1.Length();
39 myNbSU2 = Upars2.Length();
40 myNbSV2 = Vpars2.Length();
43 done = Standard_False;
44 TSectionLines.Init(1000);
45 TTangentZones.Init(10000);
46 Perform(Upars1, Vpars1, Upars2, Vpars2);
49 //=======================================================================
52 //=======================================================================
54 void IntPolyh_Intersection::Perform(const TColStd_Array1OfReal& Upars1,
55 const TColStd_Array1OfReal& Vpars1,
56 const TColStd_Array1OfReal& Upars2,
57 const TColStd_Array1OfReal& Vpars2) {
61 Standard_Boolean isStdDone = Standard_False;
62 Standard_Boolean isAdvDone = Standard_False;
63 Standard_Integer nbCouplesStd = 0;
64 Standard_Integer nbCouplesAdv = 0;
67 IntPolyh_PMaillageAffinage aPMaillageStd = 0;
68 IntPolyh_PMaillageAffinage aPMaillageFF = 0;
69 IntPolyh_PMaillageAffinage aPMaillageFR = 0;
70 IntPolyh_PMaillageAffinage aPMaillageRF = 0;
71 IntPolyh_PMaillageAffinage aPMaillageRR = 0;
73 isStdDone = PerformStd( Upars1, Vpars1, Upars2, Vpars2,
74 aPMaillageStd,nbCouplesStd);
76 // default interference done well, use it
77 if(isStdDone && nbCouplesStd > 10) {
78 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
80 // default interference done, but too few interferences foud;
81 // use advanced interference
82 else if(isStdDone && nbCouplesStd <= 10) {
83 isAdvDone = PerformAdv( Upars1, Vpars1, Upars2, Vpars2,
84 aPMaillageFF,aPMaillageFR,aPMaillageRF,
85 aPMaillageRR,nbCouplesAdv);
87 // advanced interference found
88 if(isAdvDone && nbCouplesAdv > 10) {
89 aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
90 aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
91 aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
92 aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
95 // use result of default
97 aPMaillageStd->StartPointsChain(TSectionLines, TTangentZones);
100 // default interference faild, use advanced
102 // isAdvDone = PerformAdv(aPMaillageFF,aPMaillageFR,aPMaillageRF,aPMaillageRR,nbCouplesAdv);
104 // if(isAdvDone && nbCouplesAdv > 0) {cout << "4adv done, nbc: " << nbCouplesAdv << endl;
105 // aPMaillageFF->StartPointsChain(TSectionLines,TTangentZones);
106 // aPMaillageFR->StartPointsChain(TSectionLines,TTangentZones);
107 // aPMaillageRF->StartPointsChain(TSectionLines,TTangentZones);
108 // aPMaillageRR->StartPointsChain(TSectionLines,TTangentZones);
113 nbsectionlines = TSectionLines.NbItems();
114 nbtangentzones = TTangentZones.NbItems();
117 if(aPMaillageStd) delete aPMaillageStd;
118 if(aPMaillageFF) delete aPMaillageFF;
119 if(aPMaillageFR) delete aPMaillageFR;
120 if(aPMaillageRF) delete aPMaillageRF;
121 if(aPMaillageRR) delete aPMaillageRR;
124 if(!isStdDone && !isAdvDone)
125 done = Standard_False;
128 //=======================================================================
129 //function : PerformMaillage
130 //purpose : Computes MaillageAffinage
131 //=======================================================================
132 Standard_Boolean IntPolyh_Intersection::PerformMaillage(const Standard_Boolean isFirstFwd,
133 const Standard_Boolean isSecondFwd,
134 const TColStd_Array1OfReal& Upars1,
135 const TColStd_Array1OfReal& Vpars1,
136 const TColStd_Array1OfReal& Upars2,
137 const TColStd_Array1OfReal& Vpars2,
138 IntPolyh_PMaillageAffinage &theMaillageS)
140 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, Upars1.Length(), Vpars1.Length(),
141 mySurf2, Upars2.Length(), Vpars2.Length(),
145 theMaillageS->FillArrayOfPnt(1, isFirstFwd, Upars1, Vpars1);
146 theMaillageS->FillArrayOfPnt(2, isSecondFwd, Upars2, Vpars2);
150 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
151 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
152 xx0, yy0, zz0, xx1, yy1, zz1);
154 theMaillageS->FillArrayOfEdges(1);
155 theMaillageS->FillArrayOfEdges(2);
157 theMaillageS->FillArrayOfTriangles(1);
158 theMaillageS->FillArrayOfTriangles(2);
160 theMaillageS->LinkEdges2Triangles();
162 theMaillageS->TrianglesDeflectionsRefinementBSB();
164 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
166 // if too many intersections, consider surfaces parallel (eap)
169 (FinTTC >= theMaillageS->GetArrayOfTriangles(1).NbTriangles() ||
170 FinTTC >= theMaillageS->GetArrayOfTriangles(2).NbTriangles()) ) {
171 return Standard_False;
174 //IFV test for parallel surf
176 const Standard_Real eps = .996; //~ cos of 5deg.
177 IntPolyh_ArrayOfCouples& Couples = theMaillageS->GetArrayOfCouples();
179 Standard_Integer i, npara = 0;
180 for(i = 0; i < FinTTC; ++i) {
181 Standard_Real cosa = Abs(Couples[i].AngleValue());
182 if(cosa > eps) ++npara;
184 if(npara >= theMaillageS->GetArrayOfTriangles(1).NbItems() ||
185 npara >= theMaillageS->GetArrayOfTriangles(2).NbItems() ) {
186 return Standard_False;
190 return Standard_True;
193 //=======================================================================
194 //function : PerformMaillage
195 //purpose : Computes MaillageAffinage
196 //=======================================================================
197 Standard_Boolean IntPolyh_Intersection::PerformMaillage(const TColStd_Array1OfReal& Upars1,
198 const TColStd_Array1OfReal& Vpars1,
199 const TColStd_Array1OfReal& Upars2,
200 const TColStd_Array1OfReal& Vpars2,
201 IntPolyh_PMaillageAffinage &theMaillageS)
204 theMaillageS = new IntPolyh_MaillageAffinage(mySurf1, Upars1.Length(), Vpars1.Length(),
205 mySurf2, Upars2.Length(), Vpars2.Length(),
208 theMaillageS->FillArrayOfPnt(1, Upars1, Vpars1);
209 theMaillageS->FillArrayOfPnt(2, Upars2, Vpars2);
212 Standard_Real xx0,yy0,zz0,xx1,yy1,zz1;
213 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
214 xx0, yy0, zz0, xx1, yy1, zz1);
215 theMaillageS->FillArrayOfEdges(1);
216 theMaillageS->FillArrayOfEdges(2);
218 theMaillageS->FillArrayOfTriangles(1);
219 theMaillageS->FillArrayOfTriangles(2);
221 theMaillageS->LinkEdges2Triangles();
223 theMaillageS->TrianglesDeflectionsRefinementBSB();
225 Standard_Integer FinTTC = theMaillageS->TriangleCompare();
228 Standard_Boolean myZone = Standard_True;
229 theMaillageS->SetEnlargeZone( myZone );
230 theMaillageS->FillArrayOfPnt(1);
231 theMaillageS->FillArrayOfPnt(2);
232 theMaillageS->CommonBox(theMaillageS->GetBox(1), theMaillageS->GetBox(2),
233 xx0, yy0, zz0, xx1, yy1, zz1);
234 theMaillageS->FillArrayOfEdges(1);
235 theMaillageS->FillArrayOfEdges(2);
236 theMaillageS->FillArrayOfTriangles(1);
237 theMaillageS->FillArrayOfTriangles(2);
238 theMaillageS->LinkEdges2Triangles();
239 theMaillageS->TrianglesDeflectionsRefinementBSB();
240 FinTTC = theMaillageS->TriangleCompare();
241 myZone = Standard_False;
242 theMaillageS->SetEnlargeZone( myZone );
245 // if too many intersections, consider surfaces parallel (eap)
248 (FinTTC >= theMaillageS->GetArrayOfTriangles(1).NbTriangles() ||
249 FinTTC >= theMaillageS->GetArrayOfTriangles(2).NbTriangles()) ) {
250 return Standard_False;
253 //IFV test for parallel surf
255 const Standard_Real eps = .996; //~ cos of 5deg.
256 IntPolyh_ArrayOfCouples& Couples = theMaillageS->GetArrayOfCouples();
258 Standard_Integer i, npara = 0;
259 for(i = 0; i < FinTTC; ++i) {
260 Standard_Real cosa = Abs(Couples[i].AngleValue());
261 if(cosa > eps) ++npara;
263 if(npara >= theMaillageS->GetArrayOfTriangles(1).NbItems() ||
264 npara >= theMaillageS->GetArrayOfTriangles(2).NbItems() ) {
265 return Standard_False;
269 return Standard_True;
272 //=======================================================================
273 //function : PerformAdv
275 //=======================================================================
276 Standard_Boolean IntPolyh_Intersection::PerformAdv(const TColStd_Array1OfReal& Upars1,
277 const TColStd_Array1OfReal& Vpars1,
278 const TColStd_Array1OfReal& Upars2,
279 const TColStd_Array1OfReal& Vpars2,
280 IntPolyh_PMaillageAffinage& MaillageFF,
281 IntPolyh_PMaillageAffinage& MaillageFR,
282 IntPolyh_PMaillageAffinage& MaillageRF,
283 IntPolyh_PMaillageAffinage& MaillageRR,
284 Standard_Integer& NbCouples)
286 Standard_Boolean isdone = Standard_True;
289 if(!PerformMaillage(Standard_True,Standard_False,
290 Upars1, Vpars1, Upars2, Vpars2,
292 !PerformMaillage(Standard_False,Standard_True,
293 Upars1, Vpars1, Upars2, Vpars2,
295 !PerformMaillage(Standard_True,Standard_True,
296 Upars1, Vpars1, Upars2, Vpars2,
298 !PerformMaillage(Standard_False,Standard_False,
299 Upars1, Vpars1, Upars2, Vpars2,
301 isdone = Standard_False;
304 NbCouples = MaillageFF->GetArrayOfCouples().NbItems() +
305 MaillageFR->GetArrayOfCouples().NbItems() +
306 MaillageRF->GetArrayOfCouples().NbItems() +
307 MaillageRR->GetArrayOfCouples().NbItems();
310 MergeCouples(MaillageFF->GetArrayOfCouples(),MaillageFR->GetArrayOfCouples(),
311 MaillageRF->GetArrayOfCouples(),MaillageRR->GetArrayOfCouples());
315 //=======================================================================
316 //function : PerformStd
318 //=======================================================================
320 Standard_Boolean IntPolyh_Intersection::PerformStd(const TColStd_Array1OfReal& Upars1,
321 const TColStd_Array1OfReal& Vpars1,
322 const TColStd_Array1OfReal& Upars2,
323 const TColStd_Array1OfReal& Vpars2,
324 IntPolyh_PMaillageAffinage& MaillageS,
325 Standard_Integer& NbCouples)
327 Standard_Boolean isdone = PerformMaillage(Upars1, Vpars1, Upars2, Vpars2,
329 NbCouples = (isdone) ? (MaillageS->GetArrayOfCouples().NbItems()) : 0;