1 // Created on: 1992-05-07
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1992-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 NIZNHY-PKV Thu Sep 15 11:09:12 2011
24 void SeamPosition(const gp_Pnt& aPLoc,
28 void AdjustToSeam (const gp_Cylinder& aQuad,
31 void AdjustToSeam (const gp_Sphere& aQuad,
33 const Standard_Real aTolAng);
35 void AdjustToSeam (const gp_Cone& aQuad,
37 //modified by NIZNHY-PKV Thu Sep 15 11:09:13 2011
39 //=======================================================================
42 // Traitement du cas Plan/Plan
43 //=======================================================================
44 Standard_Boolean IntPP (const IntSurf_Quadric& Quad1,
45 const IntSurf_Quadric& Quad2,
46 const Standard_Real Tolang,
47 const Standard_Real TolTang,
48 Standard_Boolean& Same,
49 IntPatch_SequenceOfLine& slin)
52 IntSurf_TypeTrans trans1,trans2;
53 IntAna_ResultType typint;
54 gp_Pln pl1(Quad1.Plane());
55 gp_Pln pl2(Quad2.Plane());
57 IntAna_QuadQuadGeo inter(pl1,pl2,Tolang,TolTang);
58 if (!inter.IsDone()) {return Standard_False;}
59 Same = Standard_False;
60 typint = inter.TypeInter();
61 if (typint == IntAna_Same) { // cas faces confondues
64 else if (typint != IntAna_Empty) { // on a une ligne
65 gp_Lin linsol = inter.Line(1);
66 Standard_Real discri = linsol.Direction().DotCross
67 (Quad2.Normale(linsol.Location()),
68 Quad1.Normale(linsol.Location()));
78 Handle(IntPatch_GLine) glig =
79 new IntPatch_GLine (linsol,Standard_False,trans1,trans2);
84 //=======================================================================
87 // Traitement du cas Plan/Cylindre et reciproquement
88 //=======================================================================
89 Standard_Boolean IntPCy (const IntSurf_Quadric& Quad1,
90 const IntSurf_Quadric& Quad2,
91 const Standard_Real Tolang,
92 const Standard_Real TolTang,
93 const Standard_Boolean Reversed,
94 Standard_Boolean& Empty,
95 IntPatch_SequenceOfLine& slin)
101 IntSurf_TypeTrans trans1,trans2;
102 IntAna_ResultType typint;
104 IntAna_QuadQuadGeo inter;
107 Cy = Quad2.Cylinder();
111 Cy = Quad1.Cylinder();
113 inter.Perform(Pl,Cy,Tolang,TolTang);
114 if (!inter.IsDone()) {return Standard_False;}
115 typint = inter.TypeInter();
116 Standard_Integer NbSol = inter.NbSolutions();
117 Empty = Standard_False;
121 case IntAna_Empty : {
122 Empty = Standard_True;
127 gp_Lin linsol = inter.Line(1);
128 gp_Pnt orig(linsol.Location());
129 if (NbSol == 1) { // ligne de tangence
130 gp_Vec TestCurvature(orig,Cy.Location());
131 gp_Vec Normp,Normcyl;
133 Normp = Quad1.Normale(orig);
134 Normcyl = Quad2.Normale(orig);
137 Normp = Quad2.Normale(orig);
138 Normcyl = Quad1.Normale(orig);
141 IntSurf_Situation situcyl;
142 IntSurf_Situation situp;
144 if (Normp.Dot(TestCurvature) > 0.) {
145 situcyl = IntSurf_Outside;
146 if (Normp.Dot(Normcyl) > 0.) {
147 situp = IntSurf_Inside;
150 situp = IntSurf_Outside;
154 situcyl = IntSurf_Inside;
155 if (Normp.Dot(Normcyl) > 0.) {
156 situp = IntSurf_Outside;
159 situp = IntSurf_Inside;
162 Handle(IntPatch_GLine) glig;
164 glig = new IntPatch_GLine(linsol, Standard_True, situp, situcyl);
167 glig = new IntPatch_GLine(linsol, Standard_True, situcyl, situp);
172 // on a 2 droites. Il faut determiner les transitions
175 if (linsol.Direction().DotCross(Quad2.Normale(orig),
176 Quad1.Normale(orig)) >0.) {
177 trans1 = IntSurf_Out;
182 trans2 = IntSurf_Out;
184 Handle(IntPatch_GLine) glig =
185 new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
188 linsol = inter.Line(2);
189 orig = linsol.Location();
191 if (linsol.Direction().DotCross(Quad2.Normale(orig),
192 Quad1.Normale(orig)) >0.) {
193 trans1 = IntSurf_Out;
198 trans2 = IntSurf_Out;
200 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
206 case IntAna_Circle: {
211 cirsol = inter.Circle(1);
212 //modified by NIZNHY-PKV Thu Sep 15 11:30:03 2011f
213 AdjustToSeam(Cy, cirsol);
214 //modified by NIZNHY-PKV Thu Sep 15 11:30:15 2011t
215 ElCLib::D1(0.,cirsol,ptref,Tgt);
217 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) > 0.0) {
218 trans1 = IntSurf_Out;
223 trans2 = IntSurf_Out;
225 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
230 case IntAna_Ellipse: {
231 gp_Elips elipsol = inter.Ellipse(1);
234 ElCLib::D1(0.,elipsol,ptref,Tgt);
236 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) > 0.0) {
237 trans1 = IntSurf_Out;
242 trans2 = IntSurf_Out;
244 Handle(IntPatch_GLine) glig = new IntPatch_GLine(elipsol,Standard_False,trans1,trans2);
250 return Standard_False; // on ne doit pas passer ici
253 return Standard_True;
255 //=======================================================================
258 // Traitement du cas Plan/Sphere et reciproquement
259 //=======================================================================
260 Standard_Boolean IntPSp (const IntSurf_Quadric& Quad1,
261 const IntSurf_Quadric& Quad2,
262 //modified by NIZNHY-PKV Tue Sep 20 08:59:36 2011f
263 const Standard_Real Tolang,
264 //modified by NIZNHY-PKV Tue Sep 20 08:59:39 2011t
265 const Standard_Real TolTang,
266 const Standard_Boolean Reversed,
267 Standard_Boolean& Empty,
268 IntPatch_SequenceOfLine& slin,
269 IntPatch_SequenceOfPoint& spnt)
276 IntSurf_TypeTrans trans1,trans2;
277 IntAna_ResultType typint;
279 IntAna_QuadQuadGeo inter;
288 inter.Perform(Pl,Sp);
290 if (!inter.IsDone()) {return Standard_False;}
292 typint = inter.TypeInter();
293 Empty = Standard_False;
296 case IntAna_Empty : {
297 Empty = Standard_True;
302 gp_Pnt psol = inter.Point(1);
303 Standard_Real U1,V1,U2,V2;
304 Quad1.Parameters(psol,U1,V1);
305 Quad2.Parameters(psol,U2,V2);
306 IntPatch_Point ptsol;
307 ptsol.SetValue(psol,TolTang,Standard_True);
308 ptsol.SetParameters(U1,V1,U2,V2);
313 case IntAna_Circle: {
314 cirsol = inter.Circle(1);
315 //modified by NIZNHY-PKV Thu Sep 15 11:30:03 2011f
316 AdjustToSeam(Sp, cirsol, Tolang);
317 //modified by NIZNHY-PKV Thu Sep 15 11:30:15 2011t
320 ElCLib::D1(0.,cirsol,ptref,Tgt);
322 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) >0.) {
323 trans1 = IntSurf_Out;
328 trans2 = IntSurf_Out;
330 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
336 return Standard_False; // on ne doit pas passer ici
339 return Standard_True;
341 //=======================================================================
344 // Traitement du cas Plan/Cone et reciproquement
345 //=======================================================================
346 Standard_Boolean IntPCo (const IntSurf_Quadric& Quad1,
347 const IntSurf_Quadric& Quad2,
348 const Standard_Real Tolang,
349 const Standard_Real TolTang,
350 const Standard_Boolean Reversed,
351 Standard_Boolean& Empty,
352 Standard_Boolean& Multpoint,
353 IntPatch_SequenceOfLine& slin,
354 IntPatch_SequenceOfPoint& spnt)
363 IntSurf_TypeTrans trans1,trans2;
364 IntAna_ResultType typint;
366 IntAna_QuadQuadGeo inter;
378 inter.Perform(Pl,Co,Tolang,TolTang);
379 if (!inter.IsDone()) {
380 return Standard_False;
383 typint = inter.TypeInter();
384 Standard_Integer NbSol = inter.NbSolutions();
385 Empty = Standard_False;
389 gp_Pnt psol = inter.Point(1);
390 Standard_Real U1,V1,U2,V2;
391 Quad1.Parameters(psol,U1,V1);
392 Quad2.Parameters(psol,U2,V2);
393 IntPatch_Point ptsol;
394 ptsol.SetValue(psol,TolTang,Standard_False);
395 ptsol.SetParameters(U1,V1,U2,V2);
401 gp_Lin linsol = inter.Line(1);
402 if (linsol.Direction().Dot(Co.Axis().Direction()) <0.) {
403 linsol.SetDirection(linsol.Direction().Reversed());
405 Standard_Real para = ElCLib::Parameter(linsol, apex);
406 gp_Pnt ptbid (ElCLib::Value(para+5.,linsol));
407 Standard_Real U1,V1,U2,V2;
408 Quad1.Parameters(apex,U1,V1);
409 Quad2.Parameters(apex,U2,V2);
411 if (NbSol == 1) { // ligne de tangence
412 IntPatch_Point ptsol;
413 ptsol.SetValue(apex,TolTang,Standard_False);
414 ptsol.SetParameters(U1,V1,U2,V2);
415 ptsol.SetParameter(para);
416 gp_Pnt ptbid2(apex.XYZ() + 5.*Co.Axis().Direction().XYZ());
417 gp_Vec TestCurvature(ptbid,ptbid2);
420 Normp = Quad1.Normale(ptbid);
421 Normco = Quad2.Normale(ptbid);
424 Normp = Quad2.Normale(ptbid);
425 Normco = Quad1.Normale(ptbid);
427 IntSurf_Situation situco,situco_otherside;
428 IntSurf_Situation situp,situp_otherside;
430 if (Normp.Dot(TestCurvature) > 0.) {
431 situco = IntSurf_Outside;
432 situco_otherside = IntSurf_Inside;
433 if (Normp.Dot(Normco) > 0.) {
434 situp = IntSurf_Inside;
435 situp_otherside = IntSurf_Outside;
438 situp = IntSurf_Outside;
439 situp_otherside = IntSurf_Inside;
443 situco = IntSurf_Inside;
444 situco_otherside = IntSurf_Outside;
445 if (Normp.Dot(Normco) > 0.) {
446 situp = IntSurf_Outside;
447 situp_otherside = IntSurf_Inside;
450 situp = IntSurf_Inside;
451 situp_otherside = IntSurf_Outside;
454 //----------------------------------------------------------
455 //-- Apex ---> Cone.Direction
457 Handle(IntPatch_GLine) glig;
459 glig = new IntPatch_GLine(linsol, Standard_True, situp, situco);
462 glig = new IntPatch_GLine(linsol, Standard_True, situco, situp);
464 glig->AddVertex(ptsol);
465 glig->SetFirstPoint(1);
467 //----------------------------------------------------------
468 //-- -Cone.Direction <------- Apex
470 linsol.SetDirection(linsol.Direction().Reversed());
472 glig = new IntPatch_GLine(linsol, Standard_True, situp_otherside, situco_otherside);
475 glig = new IntPatch_GLine(linsol, Standard_True, situco_otherside, situp_otherside);
477 glig->AddVertex(ptsol);
478 glig->SetFirstPoint(1);
482 // on a 2 droites. Il faut determiner les transitions
483 // de chacune. On oriente chaque ligne dans le sens
484 // de l axe du cone. Les transitions de chaque ligne seront
485 // inverses l une de l autre => on ne fait le calcul que sur
487 if (linsol.Direction().DotCross
488 (Quad2.Normale(ptbid),Quad1.Normale(ptbid)) >0.) {
489 trans1 = IntSurf_Out;
494 trans2 = IntSurf_Out;
497 Multpoint = Standard_True;
498 //------------------------------------------- Ligne 1 -------
499 IntPatch_Point ptsol;
500 ptsol.SetValue(apex,TolTang,Standard_False);
501 ptsol.SetParameters(U1,V1,U2,V2);
502 ptsol.SetParameter(para);
503 ptsol.SetMultiple(Standard_True);
504 Handle(IntPatch_GLine) glig;
505 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
506 glig->AddVertex(ptsol);
507 glig->SetFirstPoint(1);
509 //-----------------------------------------------------------
510 //-- Other Side : Les transitions restent les memes
511 //-- linsol -> -linsol et Quad1(2).N -> -Quad1(2).N
513 linsol.SetDirection(linsol.Direction().Reversed());
514 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
515 para = ElCLib::Parameter(linsol, apex);
516 ptsol.SetParameter(para);
517 glig->AddVertex(ptsol);
518 glig->SetFirstPoint(1);
521 //------------------------------------------- Ligne 2 -------
522 linsol = inter.Line(2);
523 if (linsol.Direction().Dot(Co.Axis().Direction()) <0.) {
524 linsol.SetDirection(linsol.Direction().Reversed());
526 para = ElCLib::Parameter(linsol, apex);
527 ptbid = ElCLib::Value(para+5.,linsol);
528 if (linsol.Direction().DotCross
529 (Quad2.Normale(ptbid),Quad1.Normale(ptbid)) >0.) {
530 trans1 = IntSurf_Out;
535 trans2 = IntSurf_Out;
537 ptsol.SetParameter(para);
538 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
539 para = ElCLib::Parameter(linsol, apex);
540 ptsol.SetParameter(para);
541 glig->AddVertex(ptsol);
542 glig->SetFirstPoint(1);
544 //-----------------------------------------------------------
545 //-- Other Side : Les transitions restent les memes
546 //-- linsol -> -linsol et Quad1(2).N -> -Quad1(2).N
548 linsol.SetDirection(linsol.Direction().Reversed());
549 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
550 para = ElCLib::Parameter(linsol, apex);
551 ptsol.SetParameter(para);
552 glig->AddVertex(ptsol);
553 glig->SetFirstPoint(1);
559 case IntAna_Circle: {
560 gp_Circ cirsol = inter.Circle(1);
561 //modified by NIZNHY-PKV Thu Sep 15 11:34:04 2011f
562 AdjustToSeam(Co, cirsol);
563 //modified by NIZNHY-PKV Thu Sep 15 11:36:08 2011t
566 ElCLib::D1(0.,cirsol,ptref,Tgt);
568 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) >0.) {
569 trans1 = IntSurf_Out;
574 trans2 = IntSurf_Out;
576 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
581 case IntAna_Ellipse: {
582 gp_Elips elipsol = inter.Ellipse(1);
585 ElCLib::D1(0.,elipsol,ptref,Tgt);
587 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) >0.) {
588 trans1 = IntSurf_Out;
593 trans2 = IntSurf_Out;
595 Handle(IntPatch_GLine) glig = new IntPatch_GLine(elipsol,Standard_False,trans1,trans2);
600 case IntAna_Parabola: {
601 gp_Parab parabsol = inter.Parabola(1);
603 gp_Vec Tgtorig(parabsol.YAxis().Direction());
604 Standard_Real ptran = Tgtorig.DotCross(Quad2.Normale(parabsol.Location()),
605 Quad1.Normale(parabsol.Location()));
606 if (ptran >0.00000001) {
607 trans1 = IntSurf_Out;
610 else if (ptran <-0.00000001) {
612 trans2 = IntSurf_Out;
615 trans1=trans2=IntSurf_Undecided;
617 Handle(IntPatch_GLine) glig = new IntPatch_GLine(parabsol,Standard_False,trans1,trans2);
622 case IntAna_Hyperbola: {
626 for(Standard_Integer i=1; i<=2; i++) {
627 gp_Hypr hyprsol = inter.Hyperbola(i);
628 tophypr = ElCLib::Value(hyprsol.MajorRadius(),
630 Tgttop = hyprsol.YAxis().Direction();
631 Standard_Real qwe = Tgttop.DotCross(Quad2.Normale(tophypr),
632 Quad1.Normale(tophypr));
634 if (qwe>0.00000001) {
635 trans1 = IntSurf_Out;
638 else if (qwe<-0.00000001){
640 trans2 = IntSurf_Out;
643 trans1=trans2=IntSurf_Undecided;
645 Handle(IntPatch_GLine) glig = new IntPatch_GLine(hyprsol,Standard_False,trans1,trans2);
652 return Standard_False;
655 return Standard_True;
658 //modified by NIZNHY-PKV Thu Sep 15 10:53:39 2011f
659 //=======================================================================
660 //function : AdjustToSeam
662 //=======================================================================
663 void AdjustToSeam (const gp_Cone& aQuad,
668 const gp_Pnt& aPLoc=aCirc.Location();
669 const gp_Ax3& aAx3=aQuad.Position();
670 SeamPosition(aPLoc, aAx3, aAx2);
671 aCirc.SetPosition(aAx2);
673 //=======================================================================
674 //function : AdjustToSeam
676 //=======================================================================
677 void AdjustToSeam (const gp_Sphere& aQuad,
679 const Standard_Real aTolAng)
683 const gp_Ax1& aAx1C=aCirc.Axis();
684 const gp_Ax3& aAx3=aQuad.Position();
685 const gp_Ax1& aAx1Q=aAx3.Axis();
687 const gp_Dir& aDirC=aAx1C.Direction();
688 const gp_Dir& aDirQ=aAx1Q.Direction();
689 if (aDirC.IsParallel(aDirQ, aTolAng)) {
690 const gp_Pnt& aPLoc=aCirc.Location();
691 SeamPosition(aPLoc, aAx3, aAx2);
692 aCirc.SetPosition(aAx2);
695 //=======================================================================
696 //function : AdjustToSeam
698 //=======================================================================
699 void AdjustToSeam (const gp_Cylinder& aQuad,
704 const gp_Pnt& aPLoc=aCirc.Location();
705 const gp_Ax3& aAx3=aQuad.Position();
706 SeamPosition(aPLoc, aAx3, aAx2);
707 aCirc.SetPosition(aAx2);
709 //=======================================================================
710 //function : SeamPosition
712 //=======================================================================
713 void SeamPosition(const gp_Pnt& aPLoc,
717 const gp_Dir& aDZ=aPos.Direction();
718 const gp_Dir& aDX=aPos.XDirection();
719 gp_Ax2 aAx2(aPLoc, aDZ, aDX);
723 //modified by NIZNHY-PKV Thu Sep 15 10:53:41 2011t