1 // Created on: 1992-05-07
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1992-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.
18 Standard_Integer SetQuad(const Handle(Adaptor3d_HSurface)& theS,
19 GeomAbs_SurfaceType& theTS,
20 IntSurf_Quadric& theQuad);
22 //=======================================================================
23 //function : IntPatch_ImpImpIntersection
25 //=======================================================================
26 IntPatch_ImpImpIntersection::IntPatch_ImpImpIntersection ():
30 //=======================================================================
31 //function : IntPatch_ImpImpIntersection
33 //=======================================================================
34 IntPatch_ImpImpIntersection::IntPatch_ImpImpIntersection
35 (const Handle(Adaptor3d_HSurface)& S1,
36 const Handle(Adaptor3d_TopolTool)& D1,
37 const Handle(Adaptor3d_HSurface)& S2,
38 const Handle(Adaptor3d_TopolTool)& D2,
39 const Standard_Real TolArc,
40 const Standard_Real TolTang)
42 Perform(S1,D1,S2,D2,TolArc,TolTang);
44 //=======================================================================
47 //=======================================================================
48 void IntPatch_ImpImpIntersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
49 const Handle(Adaptor3d_TopolTool)& D1,
50 const Handle(Adaptor3d_HSurface)& S2,
51 const Handle(Adaptor3d_TopolTool)& D2,
52 const Standard_Real TolArc,
53 const Standard_Real TolTang) {
54 done = Standard_False;
59 tgte = Standard_False;
60 oppo = Standard_False;
62 Standard_Boolean all1 = Standard_False;
63 Standard_Boolean all2 = Standard_False;
64 Standard_Boolean SameSurf = Standard_False;
65 Standard_Boolean multpoint = Standard_False;
67 Standard_Boolean nosolonS1 = Standard_False;
68 // indique s il y a des points sur restriction du carreau 1
69 Standard_Boolean nosolonS2 = Standard_False;
70 // indique s il y a des points sur restriction du carreau 2
71 Standard_Integer i, nbpt, nbseg;
72 IntPatch_SequenceOfSegmentOfTheSOnBounds edg1,edg2;
73 IntPatch_SequenceOfPathPointOfTheSOnBounds pnt1,pnt2;
75 // On commence par intersecter les supports des surfaces
76 IntSurf_Quadric quad1, quad2;
77 IntPatch_ArcFunction AFunc;
78 const Standard_Real Tolang = 1.e-8;
79 GeomAbs_SurfaceType typs1, typs2;
80 Standard_Boolean bEmpty = Standard_False;
82 const Standard_Integer iT1 = SetQuad(S1, typs1, quad1);
83 const Standard_Integer iT2 = SetQuad(S2, typs2, quad2);
86 Standard_ConstructionError::Raise();
90 const Standard_Boolean bReverse = iT1 > iT2;
91 const Standard_Integer iTT = iT1*10 + iT2;
94 case 11: { // Plane/Plane
95 if (!IntPP(quad1, quad2, Tolang, TolTang, SameSurf, slin)) {
102 case 21: { // Plane/Cylinder
103 Standard_Real VMin, VMax, H;
105 const Handle(Adaptor3d_HSurface)& aSCyl = bReverse ? S2 : S1;
106 VMin = aSCyl->FirstVParameter();
107 VMax = aSCyl->LastVParameter();
108 H = (Precision::IsNegativeInfinite(VMin) ||
109 Precision::IsPositiveInfinite(VMax)) ? 0 : (VMax - VMin);
111 if (!IntPCy(quad1, quad2, Tolang, TolTang, bReverse, empt, slin, H)) {
119 case 31: { // Plane/Cone
120 if (!IntPCo(quad1, quad2, Tolang, TolTang, bReverse, empt, multpoint, slin, spnt)) {
128 case 41: { // Plane/Sphere
129 if (!IntPSp(quad1, quad2, Tolang, TolTang, bReverse, empt, slin, spnt)) {
137 case 51: { // Plane/Torus
138 if (!IntPTo(quad1, quad2, TolTang, bReverse, empt, slin)) {
145 case 22: { // Cylinder/Cylinder
146 if (!IntCyCy(quad1, quad2, TolTang, empt, SameSurf, multpoint, slin, spnt)) {
154 case 32: { // Cylinder/Cone
155 if (!IntCyCo(quad1, quad2, TolTang, bReverse, empt, multpoint, slin, spnt)) {
163 case 42: { // Cylinder/Sphere
164 if (!IntCySp(quad1, quad2, TolTang, bReverse, empt, multpoint, slin, spnt)) {
172 case 52: { // Cylinder/Torus
173 if (!IntCyTo(quad1, quad2, TolTang, bReverse, empt, slin)) {
180 case 33: { // Cone/Cone
181 if (!IntCoCo(quad1, quad2, TolTang, empt, SameSurf, multpoint, slin, spnt)) {
189 case 43: { // Cone/Sphere
190 if (!IntCoSp(quad1, quad2, TolTang, bReverse, empt, multpoint, slin, spnt)) {
198 case 53: { // Cone/Torus
199 if (!IntCoTo(quad1, quad2, TolTang, bReverse, empt, slin)) {
205 case 44: { // Sphere/Sphere
206 if (!IntSpSp(quad1, quad2, TolTang, empt, SameSurf, slin, spnt)) {
214 case 54: { // Sphere/Torus
215 if (!IntSpTo(quad1, quad2, TolTang, bReverse, empt, slin)) {
222 case 55: { // Torus/Torus
223 if (!IntToTo(quad1, quad2, TolTang, SameSurf, empt, slin)) {
231 Standard_ConstructionError::Raise();
237 done = Standard_True;
242 AFunc.SetQuadric(quad2);
245 solrst.Perform(AFunc, D1, TolArc, TolTang);
246 if (!solrst.IsDone()) {
250 if (solrst.AllArcSolution() && typs1 == typs2) {
251 all1 = Standard_True;
253 nbpt = solrst.NbPoints();
254 nbseg= solrst.NbSegments();
255 for (i=1; i<= nbpt; i++) {
256 pnt1.Append(solrst.Point(i));
258 for (i=1; i<= nbseg; i++) {
259 edg1.Append(solrst.Segment(i));
261 nosolonS1 = (nbpt == 0) && (nbseg == 0);
263 if (nosolonS1 && all1) { // cas de face sans restrictions
264 all1 = Standard_False;
268 nosolonS1 = Standard_True;
272 AFunc.SetQuadric(quad1);
275 solrst.Perform(AFunc, D2, TolArc, TolTang);
276 if (!solrst.IsDone()) {
280 if (solrst.AllArcSolution() && typs1 == typs2) {
281 all2 = Standard_True;
283 nbpt = solrst.NbPoints();
284 nbseg= solrst.NbSegments();
285 for (i=1; i<= nbpt; i++) {
286 pnt2.Append(solrst.Point(i));
289 for (i=1; i<= nbseg; i++) {
290 edg2.Append(solrst.Segment(i));
292 nosolonS2 = (nbpt == 0) && (nbseg == 0);
294 if (nosolonS2 && all2) { // cas de face sans restrictions
295 all2 = Standard_False;
299 nosolonS2 = Standard_True;
302 if (SameSurf || (all1 && all2)) {
303 // faces "paralleles" parfaites
304 empt = Standard_False;
305 tgte = Standard_True;
312 case GeomAbs_Plane: {
313 Ptreference = (S1->Plane()).Location();
316 case GeomAbs_Cylinder: {
317 Ptreference = ElSLib::Value(0.,0.,S1->Cylinder());
320 case GeomAbs_Sphere: {
321 Ptreference = ElSLib::Value(M_PI/4.,M_PI/4.,S1->Sphere());
325 Ptreference = ElSLib::Value(0.,10.,S1->Cone());
328 case GeomAbs_Torus: {
329 Ptreference = ElSLib::Value(0.,0.,S1->Torus());
336 oppo = quad1.Normale(Ptreference).Dot(quad2.Normale(Ptreference)) < 0.0;
337 done = Standard_True;
339 }// if (SameSurf || (all1 && all2)) {
341 if (!nosolonS1 || !nosolonS2) {
342 empt = Standard_False;
343 // C est la qu il faut commencer a bosser...
344 PutPointsOnLine(S1,S2,pnt1, slin, Standard_True, D1, quad1,quad2,
347 PutPointsOnLine(S1,S2,pnt2, slin, Standard_False,D2, quad2,quad1,
350 if (edg1.Length() != 0) {
351 ProcessSegments(edg1,slin,quad1,quad2,Standard_True,TolArc);
354 if (edg2.Length() != 0) {
355 ProcessSegments(edg2,slin,quad1,quad2,Standard_False,TolArc);
358 if (edg1.Length() !=0 || edg2.Length() !=0) {
359 // ProcessRLine(slin,S1,S2,TolArc);
360 ProcessRLine(slin,quad1,quad2,TolArc);
362 }//if (!nosolonS1 || !nosolonS2) {
364 empt = ((slin.Length()==0) && (spnt.Length()==0));
367 Standard_Integer nblin, aNbPnt;
369 //modified by NIZNHY-PKV Tue Sep 06 10:03:35 2011f
370 aNbPnt=spnt.Length();
372 IntPatch_SequenceOfPoint aSIP;
374 for(i=1; i<=aNbPnt; ++i) {
375 Standard_Real aU1, aV1, aU2, aV2;
377 TopAbs_State aState1, aState2;
379 const IntPatch_Point& aIP=spnt(i);
380 aIP.Parameters(aU1, aV1, aU2, aV2);
382 aP2D.SetCoord(aU1, aV1);
383 aState1=D1->Classify(aP2D, TolArc);
385 aP2D.SetCoord(aU2, aV2);
386 aState2=D2->Classify(aP2D, TolArc);
388 if(aState1!=TopAbs_OUT && aState2!=TopAbs_OUT) {
395 aNbPnt=aSIP.Length();
396 for(i=1; i<=aNbPnt; ++i) {
397 const IntPatch_Point& aIP=aSIP(i);
402 //modified by NIZNHY-PKV Tue Sep 06 10:18:20 2011t
404 nblin = slin.Length();
405 for(i=1; i<=nblin; i++) {
406 IntPatch_IType thetype = slin.Value(i)->ArcType();
407 if( (thetype == IntPatch_Ellipse)
408 ||(thetype == IntPatch_Circle)
409 ||(thetype == IntPatch_Lin)
410 ||(thetype == IntPatch_Parabola)
411 ||(thetype == IntPatch_Hyperbola)) {
412 Handle(IntPatch_GLine)& glin = *((Handle(IntPatch_GLine)*)&slin.Value(i));
413 glin->ComputeVertexParameters(TolArc);
415 else if(thetype == IntPatch_Analytic) {
416 Handle(IntPatch_ALine)& aligold = *((Handle(IntPatch_ALine)*)&slin.Value(i));
417 aligold->ComputeVertexParameters(TolArc);
419 else if(thetype == IntPatch_Restriction) {
420 Handle(IntPatch_RLine)& rlig = *((Handle(IntPatch_RLine)*)&slin.Value(i));
421 rlig->ComputeVertexParameters(TolArc);
425 //----------------------------------------------------------------
426 //-- On place 2 vertex sur les courbes de GLine qui n en
427 //-- contiennent pas.
428 for(i=1; i<=nblin; i++) {
430 IntPatch_Point point;
431 Standard_Real u1,v1,u2,v2;
432 if(slin.Value(i)->ArcType() == IntPatch_Circle) {
433 const Handle(IntPatch_GLine)& glin = *((Handle(IntPatch_GLine)*)&slin.Value(i));
434 if(glin->NbVertex() == 0) {
435 gp_Circ Circ = glin->Circle();
436 P=ElCLib::Value(0.0,Circ);
437 quad1.Parameters(P,u1,v1);
438 quad2.Parameters(P,u2,v2);
439 point.SetValue(P,TolArc,Standard_False);
440 point.SetParameters(u1,v1,u2,v2);
441 point.SetParameter(0.0);
442 glin->AddVertex(point);
444 P=ElCLib::Value(0.0,Circ);
445 quad1.Parameters(P,u1,v1);
446 quad2.Parameters(P,u2,v2);
447 point.SetValue(P,TolArc,Standard_False);
448 point.SetParameters(u1,v1,u2,v2);
449 point.SetParameter(M_PI+M_PI);
450 glin->AddVertex(point);
454 else if(slin.Value(i)->ArcType() == IntPatch_Ellipse) {
455 const Handle(IntPatch_GLine)& glin = *((Handle(IntPatch_GLine)*)&slin.Value(i));
456 if(glin->NbVertex() == 0) {
457 gp_Elips Elips = glin->Ellipse();
458 P=ElCLib::Value(0.0,Elips);
459 quad1.Parameters(P,u1,v1);
460 quad2.Parameters(P,u2,v2);
461 point.SetValue(P,TolArc,Standard_False);
462 point.SetParameters(u1,v1,u2,v2);
463 point.SetParameter(0.0);
464 glin->AddVertex(point);
466 P=ElCLib::Value(0.0,Elips);
467 quad1.Parameters(P,u1,v1);
468 quad2.Parameters(P,u2,v2);
469 point.SetValue(P,TolArc,Standard_False);
470 point.SetParameters(u1,v1,u2,v2);
471 point.SetParameter(M_PI+M_PI);
472 glin->AddVertex(point);
476 done = Standard_True;
479 //=======================================================================
482 //=======================================================================
483 Standard_Integer SetQuad(const Handle(Adaptor3d_HSurface)& theS,
484 GeomAbs_SurfaceType& theTS,
485 IntSurf_Quadric& theQuad)
487 theTS = theS->GetType();
488 Standard_Integer iRet = 0;
491 theQuad.SetValue(theS->Plane());
494 case GeomAbs_Cylinder:
495 theQuad.SetValue(theS->Cylinder());
499 theQuad.SetValue(theS->Cone());
503 theQuad.SetValue(theS->Sphere());
507 theQuad.SetValue(theS->Torus());