0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / IntPatch / IntPatch_ImpImpIntersection_6.gxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 static 
19   Standard_Boolean TreatResultTorus(const IntSurf_Quadric& theQuad1,
20                                     const IntSurf_Quadric& theQuad2,
21                                     const IntAna_QuadQuadGeo& anInt,
22                                     Standard_Boolean& bEmpty,
23                                     IntPatch_SequenceOfLine& theSeqLin);
24
25 //=======================================================================
26 //function : IntCyTo
27 //purpose  : 
28 //=======================================================================
29 Standard_Boolean IntCyTo(const IntSurf_Quadric& theQuad1,
30                          const IntSurf_Quadric& theQuad2,
31                          const Standard_Real theTolTang,
32                          const Standard_Boolean bReversed,
33                          Standard_Boolean& bEmpty,
34                          IntPatch_SequenceOfLine& theSeqLin)
35 {
36   const gp_Cylinder aCyl = bReversed ? theQuad2.Cylinder() : theQuad1.Cylinder();
37   const gp_Torus aTorus = bReversed ? theQuad1.Torus() : theQuad2.Torus();
38   //
39   IntAna_QuadQuadGeo anInt(aCyl, aTorus, theTolTang);
40   Standard_Boolean bRet = 
41     TreatResultTorus(theQuad1, theQuad2, anInt, bEmpty, theSeqLin);
42   //
43   return bRet;
44 }
45
46 //=======================================================================
47 //function : IntCoTo
48 //purpose  : 
49 //=======================================================================
50 Standard_Boolean IntCoTo(const IntSurf_Quadric& theQuad1,
51                          const IntSurf_Quadric& theQuad2,
52                          const Standard_Real theTolTang,
53                          const Standard_Boolean bReversed,
54                          Standard_Boolean& bEmpty,
55                          IntPatch_SequenceOfLine& theSeqLin)
56 {
57   const gp_Cone aCone = bReversed ? theQuad2.Cone() : theQuad1.Cone();
58   const gp_Torus aTorus = bReversed ? theQuad1.Torus() : theQuad2.Torus();
59   //
60   IntAna_QuadQuadGeo anInt(aCone, aTorus, theTolTang);
61   Standard_Boolean bRet = 
62     TreatResultTorus(theQuad1, theQuad2, anInt, bEmpty, theSeqLin);
63   //
64   return bRet;
65 }
66
67 //=======================================================================
68 //function : IntSpTo
69 //purpose  : 
70 //=======================================================================
71 Standard_Boolean IntSpTo(const IntSurf_Quadric& theQuad1,
72                          const IntSurf_Quadric& theQuad2,
73                          const Standard_Real theTolTang,
74                          const Standard_Boolean bReversed,
75                          Standard_Boolean& bEmpty,
76                          IntPatch_SequenceOfLine& theSeqLin)
77 {
78   const gp_Sphere aSphere = bReversed ? theQuad2.Sphere() : theQuad1.Sphere();
79   const gp_Torus aTorus = bReversed ? theQuad1.Torus() : theQuad2.Torus();
80   //
81   IntAna_QuadQuadGeo anInt(aSphere, aTorus, theTolTang);
82   Standard_Boolean bRet = 
83     TreatResultTorus(theQuad1, theQuad2, anInt, bEmpty, theSeqLin);
84   //
85   return bRet;
86 }
87
88 //=======================================================================
89 //function : IntToTo
90 //purpose  : 
91 //=======================================================================
92 Standard_Boolean IntToTo(const IntSurf_Quadric& theQuad1,
93                          const IntSurf_Quadric& theQuad2,
94                          const Standard_Real theTolTang,
95                          Standard_Boolean& bSameSurf,
96                          Standard_Boolean& bEmpty,
97                          IntPatch_SequenceOfLine& theSeqLin)
98 {
99   const gp_Torus aTorus1 = theQuad1.Torus();
100   const gp_Torus aTorus2 = theQuad2.Torus();
101   //
102   IntAna_QuadQuadGeo anInt(aTorus1, aTorus2, theTolTang);
103   Standard_Boolean bRet = anInt.IsDone();
104   if (bRet) {
105     if (anInt.TypeInter() == IntAna_Same) {
106       bEmpty = Standard_False;
107       bSameSurf = Standard_True;
108     } else {
109       bRet = TreatResultTorus(theQuad1, theQuad2, anInt, bEmpty, theSeqLin);
110     }
111   }
112   //
113   return bRet;
114 }
115
116 //=======================================================================
117 //function : TreatResultTorus
118 //purpose  : 
119 //=======================================================================
120 static Standard_Boolean TreatResultTorus(const IntSurf_Quadric& theQuad1,
121                                          const IntSurf_Quadric& theQuad2,
122                                          const IntAna_QuadQuadGeo& anInt,
123                                          Standard_Boolean& bEmpty,
124                                          IntPatch_SequenceOfLine& theSeqLin)
125 {
126   Standard_Boolean bRet = anInt.IsDone();
127   //
128   if (!bRet) {
129     return bRet;
130   }
131   //
132   IntAna_ResultType typint = anInt.TypeInter();
133   Standard_Integer NbSol = anInt.NbSolutions();
134   bEmpty = Standard_False;
135   //
136   switch (typint) {
137   case IntAna_Empty :
138     bEmpty = Standard_True;
139     break;
140   //
141   case IntAna_Circle : {
142     Standard_Integer i;
143     IntSurf_TypeTrans trans1, trans2;
144     gp_Vec Tgt;
145     gp_Pnt ptref;
146     //
147     for (i = 1; i <= NbSol; ++i) {
148       gp_Circ aC = anInt.Circle(i);
149       if (theQuad1.TypeQuadric() == theQuad2.TypeQuadric()) {
150         AdjustToSeam(theQuad1.Torus(), aC);
151       }
152       ElCLib::D1(0., aC, ptref, Tgt);
153       Standard_Real qwe = Tgt.DotCross(theQuad2.Normale(ptref),
154                                        theQuad1.Normale(ptref));
155       if(qwe> 0.00000001) {
156         trans1 = IntSurf_Out;
157         trans2 = IntSurf_In;
158       }
159       else if(qwe< -0.00000001) {
160         trans1 = IntSurf_In;
161         trans2 = IntSurf_Out;
162       }
163       else { 
164         trans1=trans2=IntSurf_Undecided; 
165       }
166       //
167       Handle(IntPatch_GLine) glig = 
168         new IntPatch_GLine(aC, Standard_False, trans1, trans2);
169       theSeqLin.Append(glig);
170     }
171   }
172     break;
173   //
174   case IntAna_NoGeometricSolution:
175   default:
176     bRet = Standard_False;
177     break;
178   }
179   //
180   return bRet;
181 }