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.
17 #include <IntPatch_WLine.hxx>
20 Standard_Integer SetQuad(const Handle(Adaptor3d_HSurface)& theS,
21 GeomAbs_SurfaceType& theTS,
22 IntSurf_Quadric& theQuad);
24 //=======================================================================
25 //function : IntPatch_ImpImpIntersection
27 //=======================================================================
28 IntPatch_ImpImpIntersection::IntPatch_ImpImpIntersection ():
29 myDone(IntStatus_Fail)
32 //=======================================================================
33 //function : IntPatch_ImpImpIntersection
35 //=======================================================================
36 IntPatch_ImpImpIntersection::IntPatch_ImpImpIntersection
37 (const Handle(Adaptor3d_HSurface)& S1,
38 const Handle(Adaptor3d_TopolTool)& D1,
39 const Handle(Adaptor3d_HSurface)& S2,
40 const Handle(Adaptor3d_TopolTool)& D2,
41 const Standard_Real TolArc,
42 const Standard_Real TolTang,
43 const Standard_Boolean theIsReqToKeepRLine)
45 Perform(S1,D1,S2,D2,TolArc,TolTang, theIsReqToKeepRLine);
47 //=======================================================================
50 //=======================================================================
51 void IntPatch_ImpImpIntersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
52 const Handle(Adaptor3d_TopolTool)& D1,
53 const Handle(Adaptor3d_HSurface)& S2,
54 const Handle(Adaptor3d_TopolTool)& D2,
55 const Standard_Real TolArc,
56 const Standard_Real TolTang,
57 const Standard_Boolean theIsReqToKeepRLine)
59 myDone = IntStatus_Fail;
63 Standard_Boolean isPostProcessingRequired = Standard_True;
66 tgte = Standard_False;
67 oppo = Standard_False;
69 Standard_Boolean all1 = Standard_False;
70 Standard_Boolean all2 = Standard_False;
71 Standard_Boolean SameSurf = Standard_False;
72 Standard_Boolean multpoint = Standard_False;
74 Standard_Boolean nosolonS1 = Standard_False;
75 // indique s il y a des points sur restriction du carreau 1
76 Standard_Boolean nosolonS2 = Standard_False;
77 // indique s il y a des points sur restriction du carreau 2
78 Standard_Integer i, nbpt, nbseg;
79 IntPatch_SequenceOfSegmentOfTheSOnBounds edg1,edg2;
80 IntPatch_SequenceOfPathPointOfTheSOnBounds pnt1,pnt2;
82 // On commence par intersecter les supports des surfaces
83 IntSurf_Quadric quad1, quad2;
84 IntPatch_ArcFunction AFunc;
85 const Standard_Real Tolang = 1.e-8;
86 GeomAbs_SurfaceType typs1, typs2;
87 Standard_Boolean bEmpty = Standard_False;
89 const Standard_Integer iT1 = SetQuad(S1, typs1, quad1);
90 const Standard_Integer iT2 = SetQuad(S2, typs2, quad2);
93 throw Standard_ConstructionError();
97 const Standard_Boolean bReverse = iT1 > iT2;
98 const Standard_Integer iTT = iT1*10 + iT2;
101 case 11: { // Plane/Plane
102 if (!IntPP(quad1, quad2, Tolang, TolTang, SameSurf, slin)) {
109 case 21: { // Plane/Cylinder
110 Standard_Real VMin, VMax, H;
112 const Handle(Adaptor3d_HSurface)& aSCyl = bReverse ? S2 : S1;
113 VMin = aSCyl->FirstVParameter();
114 VMax = aSCyl->LastVParameter();
115 H = (Precision::IsNegativeInfinite(VMin) ||
116 Precision::IsPositiveInfinite(VMax)) ? 0 : (VMax - VMin);
118 if (!IntPCy(quad1, quad2, Tolang, TolTang, bReverse, empt, slin, H)) {
126 case 31: { // Plane/Cone
127 if (!IntPCo(quad1, quad2, Tolang, TolTang, bReverse, empt, multpoint, slin, spnt)) {
135 case 41: { // Plane/Sphere
136 if (!IntPSp(quad1, quad2, Tolang, TolTang, bReverse, empt, slin, spnt)) {
144 case 51: { // Plane/Torus
145 if (!IntPTo(quad1, quad2, TolTang, bReverse, empt, slin)) {
153 { // Cylinder/Cylinder
154 Bnd_Box2d aBox1, aBox2;
156 const Standard_Real aU1f = S1->FirstUParameter();
157 Standard_Real aU1l = S1->LastUParameter();
158 const Standard_Real aU2f = S2->FirstUParameter();
159 Standard_Real aU2l = S2->LastUParameter();
161 const Standard_Real anUperiod = 2.0*M_PI;
163 if(aU1l - aU1f > anUperiod)
164 aU1l = aU1f + anUperiod;
166 if(aU2l - aU2f > anUperiod)
167 aU2l = aU2f + anUperiod;
169 aBox1.Add(gp_Pnt2d(aU1f, S1->FirstVParameter()));
170 aBox1.Add(gp_Pnt2d(aU1l, S1->LastVParameter()));
171 aBox2.Add(gp_Pnt2d(aU2f, S2->FirstVParameter()));
172 aBox2.Add(gp_Pnt2d(aU2l, S2->LastVParameter()));
174 // Resolution is too big if the cylinder radius is
175 // too small. Therefore, we shall bind its value above.
176 // Here, we use simple constant.
177 const Standard_Real a2DTol = Min(1.0e-4, Min( S1->UResolution(TolTang),
178 S2->UResolution(TolTang)));
180 myDone = IntCyCy(quad1, quad2, TolTang, a2DTol, aBox1, aBox2,
181 empt, SameSurf, multpoint, slin, spnt);
183 if (myDone == IntPatch_ImpImpIntersection::IntStatus_Fail)
191 const Handle(IntPatch_WLine)& aWLine =
192 Handle(IntPatch_WLine)::DownCast(slin.Value(1));
195 {//No geometric solution
196 isPostProcessingRequired = Standard_False;
204 case 32: { // Cylinder/Cone
205 if (!IntCyCo(quad1, quad2, TolTang, bReverse, empt, multpoint, slin, spnt)) {
213 case 42: { // Cylinder/Sphere
214 if (!IntCySp(quad1, quad2, TolTang, bReverse, empt, multpoint, slin, spnt)) {
222 case 52: { // Cylinder/Torus
223 if (!IntCyTo(quad1, quad2, TolTang, bReverse, empt, slin)) {
230 case 33: { // Cone/Cone
231 if (!IntCoCo(quad1, quad2, TolTang, empt, SameSurf, multpoint, slin, spnt)) {
239 case 43: { // Cone/Sphere
240 if (!IntCoSp(quad1, quad2, TolTang, bReverse, empt, multpoint, slin, spnt)) {
248 case 53: { // Cone/Torus
249 if (!IntCoTo(quad1, quad2, TolTang, bReverse, empt, slin)) {
255 case 44: { // Sphere/Sphere
256 if (!IntSpSp(quad1, quad2, TolTang, empt, SameSurf, slin, spnt)) {
264 case 54: { // Sphere/Torus
265 if (!IntSpTo(quad1, quad2, TolTang, bReverse, empt, slin)) {
272 case 55: { // Torus/Torus
273 if (!IntToTo(quad1, quad2, TolTang, SameSurf, empt, slin)) {
281 throw Standard_ConstructionError();
287 if (myDone == IntStatus_Fail)
288 myDone = IntStatus_OK;
294 if(isPostProcessingRequired)
297 AFunc.SetQuadric(quad2);
300 solrst.Perform(AFunc, D1, TolArc, TolTang);
301 if (!solrst.IsDone()) {
305 if (solrst.AllArcSolution() && typs1 == typs2) {
306 all1 = Standard_True;
308 nbpt = solrst.NbPoints();
309 nbseg= solrst.NbSegments();
310 for (i=1; i<= nbpt; i++) {
311 pnt1.Append(solrst.Point(i));
313 for (i=1; i<= nbseg; i++) {
314 edg1.Append(solrst.Segment(i));
316 nosolonS1 = (nbpt == 0) && (nbseg == 0);
318 if (nosolonS1 && all1) { // cas de face sans restrictions
319 all1 = Standard_False;
323 nosolonS1 = Standard_True;
327 AFunc.SetQuadric(quad1);
330 solrst.Perform(AFunc, D2, TolArc, TolTang);
331 if (!solrst.IsDone()) {
335 if (solrst.AllArcSolution() && typs1 == typs2) {
336 all2 = Standard_True;
338 nbpt = solrst.NbPoints();
339 nbseg= solrst.NbSegments();
340 for (i=1; i<= nbpt; i++) {
341 pnt2.Append(solrst.Point(i));
344 for (i=1; i<= nbseg; i++) {
345 edg2.Append(solrst.Segment(i));
347 nosolonS2 = (nbpt == 0) && (nbseg == 0);
349 if (nosolonS2 && all2) { // cas de face sans restrictions
350 all2 = Standard_False;
354 nosolonS2 = Standard_True;
357 if (SameSurf || (all1 && all2)) {
358 // faces "paralleles" parfaites
359 empt = Standard_False;
360 tgte = Standard_True;
367 case GeomAbs_Plane: {
368 Ptreference = (S1->Plane()).Location();
371 case GeomAbs_Cylinder: {
372 Ptreference = ElSLib::Value(0.,0.,S1->Cylinder());
375 case GeomAbs_Sphere: {
376 Ptreference = ElSLib::Value(M_PI/4.,M_PI/4.,S1->Sphere());
380 Ptreference = ElSLib::Value(0.,10.,S1->Cone());
383 case GeomAbs_Torus: {
384 Ptreference = ElSLib::Value(0.,0.,S1->Torus());
391 oppo = quad1.Normale(Ptreference).Dot(quad2.Normale(Ptreference)) < 0.0;
392 myDone = IntStatus_OK;
394 }// if (SameSurf || (all1 && all2)) {
396 if (!nosolonS1 || !nosolonS2) {
397 empt = Standard_False;
398 // C est la qu il faut commencer a bosser...
399 PutPointsOnLine(S1,S2,pnt1, slin, Standard_True, D1, quad1,quad2,
402 PutPointsOnLine(S1,S2,pnt2, slin, Standard_False,D2, quad2,quad1,
405 if (edg1.Length() != 0) {
406 ProcessSegments(edg1,slin,quad1,quad2,Standard_True,TolArc);
409 if (edg2.Length() != 0) {
410 ProcessSegments(edg2,slin,quad1,quad2,Standard_False,TolArc);
413 if (edg1.Length() !=0 || edg2.Length() !=0) {
414 // ProcessRLine(slin,S1,S2,TolArc);
415 ProcessRLine(slin,quad1,quad2,TolArc, theIsReqToKeepRLine);
417 }//if (!nosolonS1 || !nosolonS2) {
419 empt = ((slin.Length()==0) && (spnt.Length()==0));
423 Standard_Integer nblin = slin.Length(),
424 aNbPnt = spnt.Length();
426 //modified by NIZNHY-PKV Tue Sep 06 10:03:35 2011f
428 IntPatch_SequenceOfPoint aSIP;
430 for(i=1; i<=aNbPnt; ++i) {
431 Standard_Real aU1, aV1, aU2, aV2;
433 TopAbs_State aState1, aState2;
435 const IntPatch_Point& aIP=spnt(i);
436 aIP.Parameters(aU1, aV1, aU2, aV2);
438 aP2D.SetCoord(aU1, aV1);
439 aState1=D1->Classify(aP2D, TolArc);
441 aP2D.SetCoord(aU2, aV2);
442 aState2=D2->Classify(aP2D, TolArc);
444 if(aState1!=TopAbs_OUT && aState2!=TopAbs_OUT) {
451 aNbPnt=aSIP.Length();
452 for(i=1; i<=aNbPnt; ++i) {
453 const IntPatch_Point& aIP=aSIP(i);
458 //modified by NIZNHY-PKV Tue Sep 06 10:18:20 2011t
460 for(i=1; i<=nblin; i++) {
461 IntPatch_IType thetype = slin.Value(i)->ArcType();
462 if( (thetype == IntPatch_Ellipse)
463 ||(thetype == IntPatch_Circle)
464 ||(thetype == IntPatch_Lin)
465 ||(thetype == IntPatch_Parabola)
466 ||(thetype == IntPatch_Hyperbola)) {
467 Handle(IntPatch_GLine)& glin = *((Handle(IntPatch_GLine)*)&slin.Value(i));
468 glin->ComputeVertexParameters(TolArc);
470 else if(thetype == IntPatch_Analytic) {
471 Handle(IntPatch_ALine)& aligold = *((Handle(IntPatch_ALine)*)&slin.Value(i));
472 aligold->ComputeVertexParameters(TolArc);
474 else if(thetype == IntPatch_Restriction) {
475 Handle(IntPatch_RLine)& rlig = *((Handle(IntPatch_RLine)*)&slin.Value(i));
476 rlig->ComputeVertexParameters(TolArc);
480 //----------------------------------------------------------------
481 //-- On place 2 vertex sur les courbes de GLine qui n en
482 //-- contiennent pas.
483 for(i=1; i<=nblin; i++) {
485 IntPatch_Point point;
486 Standard_Real u1,v1,u2,v2;
487 if(slin.Value(i)->ArcType() == IntPatch_Circle) {
488 const Handle(IntPatch_GLine)& glin = *((Handle(IntPatch_GLine)*)&slin.Value(i));
489 if(glin->NbVertex() == 0) {
490 gp_Circ Circ = glin->Circle();
491 P=ElCLib::Value(0.0,Circ);
492 quad1.Parameters(P,u1,v1);
493 quad2.Parameters(P,u2,v2);
494 point.SetValue(P,TolArc,Standard_False);
495 point.SetParameters(u1,v1,u2,v2);
496 point.SetParameter(0.0);
497 glin->AddVertex(point);
499 P=ElCLib::Value(0.0,Circ);
500 quad1.Parameters(P,u1,v1);
501 quad2.Parameters(P,u2,v2);
502 point.SetValue(P,TolArc,Standard_False);
503 point.SetParameters(u1,v1,u2,v2);
504 point.SetParameter(M_PI+M_PI);
505 glin->AddVertex(point);
509 else if(slin.Value(i)->ArcType() == IntPatch_Ellipse) {
510 const Handle(IntPatch_GLine)& glin = *((Handle(IntPatch_GLine)*)&slin.Value(i));
511 if(glin->NbVertex() == 0) {
512 gp_Elips Elips = glin->Ellipse();
513 P=ElCLib::Value(0.0,Elips);
514 quad1.Parameters(P,u1,v1);
515 quad2.Parameters(P,u2,v2);
516 point.SetValue(P,TolArc,Standard_False);
517 point.SetParameters(u1,v1,u2,v2);
518 point.SetParameter(0.0);
519 glin->AddVertex(point);
521 P=ElCLib::Value(0.0,Elips);
522 quad1.Parameters(P,u1,v1);
523 quad2.Parameters(P,u2,v2);
524 point.SetValue(P,TolArc,Standard_False);
525 point.SetParameters(u1,v1,u2,v2);
526 point.SetParameter(M_PI+M_PI);
527 glin->AddVertex(point);
531 myDone = IntStatus_OK;
534 //=======================================================================
537 //=======================================================================
538 Standard_Integer SetQuad(const Handle(Adaptor3d_HSurface)& theS,
539 GeomAbs_SurfaceType& theTS,
540 IntSurf_Quadric& theQuad)
542 theTS = theS->GetType();
543 Standard_Integer iRet = 0;
546 theQuad.SetValue(theS->Plane());
549 case GeomAbs_Cylinder:
550 theQuad.SetValue(theS->Cylinder());
554 theQuad.SetValue(theS->Cone());
558 theQuad.SetValue(theS->Sphere());
562 theQuad.SetValue(theS->Torus());