0022790: Boolean opeation Fuse fails.
[occt.git] / src / IntImp / IntImp_ComputeTangence.cxx
1 //-- File IntImp_ComputeTangence.cxx
2
3 #include <IntImp_ConstIsoparametric.hxx>
4
5 static const IntImp_ConstIsoparametric staticChoixRef [4] = {
6 IntImp_UIsoparametricOnCaro1,
7 IntImp_VIsoparametricOnCaro1,
8 IntImp_UIsoparametricOnCaro2,
9 IntImp_VIsoparametricOnCaro2,
10 };
11
12 Standard_EXPORT const IntImp_ConstIsoparametric *ChoixRef = staticChoixRef ;
13
14 #include <IntImp_ComputeTangence.hxx>
15
16 //=======================================================================
17 //function : IntImp_ComputeTangence
18 //purpose  : 
19 //=======================================================================
20 Standard_Boolean IntImp_ComputeTangence(const gp_Vec DPuv[],
21                                         const Standard_Real EpsUV[],
22                                         Standard_Real Tgduv[],
23                                         IntImp_ConstIsoparametric TabIso[]) 
24 //                 arguments d entree:
25 // DPuv [0] =derivee en u sur caro 1    
26 // DPuv [1] =derivee en v sur caro 1
27 // DPuv [2] =derivee en u sur caro 2
28 // DPuv [3] =derivee en v sur caro 2
29 // EpsUV[0] tolerance en u sur caro1
30 // EpsUV[1] tolerance en v sur caro1
31 // EpsUV[2] tolerance en u sur caro2
32 // EpsUV[3] tolerance en v sur caro2
33 //                 arguments de sortie:
34 // Tgduv[0] composante sup dp/du de caro1 de la tangente a l intersection
35 // Tgduv[1] composante sup dp/dv de caro1 de la tangente a l intersection
36 // Tgduv[2] composante sup dp/du de caro2 de la tangente a l intersection
37 // Tgduv[3] composante sup dp/dv de caro2 de la tangente a l intersection
38 // TabIso[0...3] meilleure iso range par ordre decroissant candidate 
39 //               a l intersection
40 //         algorithme
41 // calculer la tangente a l 'intersection ;en utilisant la propriete suivante
42 // du produit scalaire a^(b^c)=b(ac)-c(ab) on obtient les composantes de la
43 // tangente a l intersection dans les 2 plans tangents (t=n1^n2 ou n1 normale
44 // au premier carreau n2 au 2ieme)
45 // on s assurera que les plans tangents des 2 carreaux ne sont pas //
46 // les composantes de l intersection dans les plans tangents permettent de 
47 //determiner l  angle entre les isoparametriques d un carreau avec le carreau
48 //reciproque 
49 //on triera par ordre croissant les cosinus :le plus petit cosinus determine le
50 // meilleure angle donc la meilleure iso a choisir pour trouver
51 // l intersection 
52
53 {
54    Standard_Real NormDuv[4], aM2, aTol2;
55    Standard_Integer i;
56    //
57    aTol2=1.e-32;
58    //
59    for (i=0; i<4; ++i) {
60      NormDuv[i] = DPuv[i].SquareMagnitude();    
61      if(NormDuv[i]<=aTol2) { 
62        return Standard_True;
63      } 
64    }
65    //
66    //-------------------------------------------------
67    gp_Vec N1 = DPuv[0];
68    N1.Cross(DPuv[1]);
69    //
70    //modified by NIZNHY-PKV Tue Nov 01 08:37:32 2011f
71    aM2=N1.SquareMagnitude();
72    if (aM2<aTol2) {
73      return Standard_True;
74    }
75    //modified by NIZNHY-PKV Tue Nov 01 08:37:34 2011t
76    N1.Normalize();
77    //-------------------------------------------------
78    gp_Vec N2 = DPuv[2];
79    N2.Cross(DPuv[3]);
80    //modified by NIZNHY-PKV Tue Nov 01 08:37:32 2011f
81    aM2=N2.SquareMagnitude();
82    if (aM2<aTol2) {
83      return Standard_True;
84    }
85    //modified by NIZNHY-PKV Tue Nov 01 08:37:34 2011t
86    N2.Normalize();
87    //
88    //modified by NIZNHY-PKV Tue Nov 01 08:31:25 2011f
89    for (i=0; i<4; ++i) {
90      NormDuv[i]=sqrt(NormDuv[i]);
91    }  
92    //modified by NIZNHY-PKV Tue Nov 01 08:31:29 2011t
93    Tgduv[0] = -DPuv[1].Dot(N2);
94    Tgduv[1] =  DPuv[0].Dot(N2);
95    Tgduv[2] =  DPuv[3].Dot(N1); 
96    Tgduv[3] = -DPuv[2].Dot(N1);
97
98
99    Standard_Boolean tangent = (Abs(Tgduv[0]) <= EpsUV[0]*NormDuv[1] &&
100                                Abs(Tgduv[1]) <= EpsUV[1]*NormDuv[0] &&
101                                Abs(Tgduv[2]) <= EpsUV[2]*NormDuv[3] &&
102                                Abs(Tgduv[3]) <= EpsUV[3]*NormDuv[2]  );
103    if(!tangent) { 
104      Standard_Real t=N1.Dot(N2);
105      if(t<0.0) t=-t;
106      if(t>0.999999999) { 
107        tangent=Standard_True; 
108      }
109    }
110
111    if (!tangent) {
112      NormDuv[0] = Abs(Tgduv[1]) /NormDuv[0]; //iso u sur caro1
113      NormDuv[1] = Abs(Tgduv[0]) /NormDuv[1]; //iso v sur caro1
114      NormDuv[2] = Abs(Tgduv[3]) /NormDuv[2]; // iso u sur caro2
115      NormDuv[3] = Abs(Tgduv[2]) /NormDuv[3]; //iso v sur caro2
116
117
118
119      //-- Tri sur NormDuv  ( en para. avec ChoixRef ) 
120      Standard_Boolean triOk = Standard_False;
121      Standard_Real t;
122      IntImp_ConstIsoparametric ti;
123      for ( i=0;i<=3;i++)  TabIso[i] = ChoixRef[i];
124      do { 
125        triOk = Standard_True;
126        for(i=1;i<=3;i++) { 
127          if(NormDuv[i-1]>NormDuv[i]) { 
128            triOk=Standard_False;
129            t=NormDuv[i]; 
130            NormDuv[i]=NormDuv[i-1];
131            NormDuv[i-1]=t;
132            
133            ti = TabIso[i];
134            TabIso[i] = TabIso[i-1];
135            TabIso[i-1] = ti;
136          }
137        }
138      }
139      while(!triOk);
140
141
142 #if 0     
143      // trier par ordre croissant le tableau NormDuv
144      Standard_Integer II;
145      for (j =0;j<=3;j++) Irang[j]=j;
146      for (j =0;j<=3;j++) {
147        Tampon = NormDuv[j];
148        II=j;
149        for (i =j+1;i<=3;i++) {
150          if (NormDuv[i] < Tampon) {
151            Tampon = NormDuv[i];
152            II = i;
153          }
154        }
155        Irang[j] = Irang[II];
156        Irang[II] = j;
157        NormDuv[II] = NormDuv[j];
158        NormDuv[j] = Tampon;
159      }
160      for (j=0; j<=3;j++) TabIso[j]=ChoixRef[Irang[j]];     
161 #endif
162    }
163    return tangent;
164  }
165
166