Integration of OCCT 6.5.0 from SVN
[occt.git] / src / ApproxInt / ApproxInt_PrmPrmSvSurfaces.gxx
1 // File:        ApproxInt_PrmPrmSvSurfaces.gxx
2 // Created:     Wed Mar 17 12:42:28 1993
3 // Author:      Laurent BUCHARD
4 //              <lbr@topsn3>
5
6 #define TOLTANGENCY 0.0000000001
7
8
9 #include <TColStd_Array1OfReal.hxx>
10 #include <math_FunctionSetRoot.hxx>
11
12 #define Debug(expr)  cout<<" expr :"<<expr;
13 #define MySurf1 MyIntersectionOn2S.Function().AuxillarSurface1()
14 #define MySurf2 MyIntersectionOn2S.Function().AuxillarSurface2()
15
16
17 //--------------------------------------------------------------------------------
18 ApproxInt_PrmPrmSvSurfaces::ApproxInt_PrmPrmSvSurfaces( const ThePSurface& Surf1
19                                                        ,const ThePSurface& Surf2):
20        MyHasBeenComputed(Standard_False),
21        MyHasBeenComputedbis(Standard_False),
22        MyIntersectionOn2S(Surf1,Surf2,TOLTANGENCY)
23
24 }
25 //--------------------------------------------------------------------------------
26 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Compute( Standard_Real& u1
27                                                      ,Standard_Real& v1
28                                                      ,Standard_Real& u2
29                                                      ,Standard_Real& v2
30                                                      ,gp_Pnt& P
31                                                      ,gp_Vec& Tg
32                                                      ,gp_Vec2d& Tguv1
33                                                      ,gp_Vec2d& Tguv2) { 
34   
35   Standard_Real tu1=u1;
36   Standard_Real tu2=u2;
37   Standard_Real tv1=v1;
38   Standard_Real tv2=v2;
39   
40   if(MyHasBeenComputed) { 
41     if(  (MyParOnS1.X()==u1)&&(MyParOnS1.Y()==v1)
42        &&(MyParOnS2.X()==u2)&&(MyParOnS2.Y()==v2)) {
43       return(MyIsTangent);
44     }
45     else if(MyHasBeenComputedbis == Standard_False) { 
46       MyTgbis         = MyTg;
47       MyTguv1bis      = MyTguv1;
48       MyTguv2bis      = MyTguv2;
49       MyPntbis        = MyPnt;
50       MyParOnS1bis    = MyParOnS1;
51       MyParOnS2bis    = MyParOnS2;
52       MyIsTangentbis  = MyIsTangent;
53       MyHasBeenComputedbis = MyHasBeenComputed; 
54     }
55   }
56   if(MyHasBeenComputedbis) { 
57     if(  (MyParOnS1bis.X()==u1)&&(MyParOnS1bis.Y()==v1)
58        &&(MyParOnS2bis.X()==u2)&&(MyParOnS2bis.Y()==v2)) {
59
60       gp_Vec            TV(MyTg);
61       gp_Vec2d          TV1(MyTguv1);
62       gp_Vec2d          TV2(MyTguv2);
63       gp_Pnt            TP(MyPnt);
64       gp_Pnt2d          TP1(MyParOnS1);
65       gp_Pnt2d          TP2(MyParOnS2);
66       Standard_Boolean  TB=MyIsTangent;
67
68       MyTg        = MyTgbis;
69       MyTguv1     = MyTguv1bis;
70       MyTguv2     = MyTguv2bis;
71       MyPnt       = MyPntbis;
72       MyParOnS1   = MyParOnS1bis;
73       MyParOnS2   = MyParOnS2bis;
74       MyIsTangent = MyIsTangentbis;
75
76       MyTgbis         = TV;
77       MyTguv1bis      = TV1;
78       MyTguv2bis      = TV2;
79       MyPntbis        = TP;
80       MyParOnS1bis    = TP1;
81       MyParOnS2bis    = TP2;
82       MyIsTangentbis  = TB;
83
84       return(MyIsTangent);
85     }
86   }
87
88
89   MyIsTangent = Standard_True;
90
91   static TColStd_Array1OfReal Param(1,4);
92   Param(1) = u1; Param(2) = v1;
93   Param(3) = u2; Param(4) = v2;
94   math_FunctionSetRoot  Rsnld(MyIntersectionOn2S.Function());
95 #ifdef DEB
96   IntImp_ConstIsoparametric ChoixIso = MyIntersectionOn2S.Perform(Param,Rsnld);
97 #else
98   MyIntersectionOn2S.Perform(Param,Rsnld);
99 #endif
100   if (!MyIntersectionOn2S.IsDone())  { 
101     MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
102     return(Standard_False);
103   }
104   if (MyIntersectionOn2S.IsEmpty()) {
105     MyIsTangent=Standard_False;
106     //cout<<"\n----- Parametree Parametree : IsEmpty ds Compute "<<endl;
107     //Debug(u1); Debug(u2); Debug(v1); Debug(v2);   cout<<endl;
108     MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
109     return(Standard_False);
110   }
111   MyHasBeenComputed = Standard_True;
112   MyPnt = P = MyIntersectionOn2S.Point().Value();
113   
114   MyIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
115   MyParOnS1.SetCoord(tu1,tv1);
116   MyParOnS2.SetCoord(tu2,tv2);
117   
118   if(MyIntersectionOn2S.IsTangent()) { 
119     MyIsTangent=Standard_False;
120     MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
121     return(Standard_False); 
122   }
123   MyTg    = Tg    = MyIntersectionOn2S.Direction();
124   MyTguv1 = Tguv1 = MyIntersectionOn2S.DirectionOnS1();
125   MyTguv2 = Tguv2 = MyIntersectionOn2S.DirectionOnS2();
126
127   //----------------------------------------------------------------------
128   //-- Si ( Tg )    TU et TV sont normes 
129   //-- 
130   //-- On a    Tg   =  DeltaU  *  TU    +   DeltaV  *  TV
131   //-- 
132   //-- soit :  Tg.TU  =  DeltaU  TU.TU  +   DeltaV  TU.TV
133   //--         Tg.TV  =  DeltaU  TV.TU  +   DeltaV  TV.TV 
134   //-- 
135   //-- Donc : 
136   //--
137   //--               Tg.TU TV.TV  - Tg.TV * TU.TV
138   //--   DeltaU = -------------------------------
139   //--               TU.TU TV.TV  - (TU.TV)**2
140   //-- 
141   //--               Tg.TV TU.TU  - Tg.TU * TU.TV
142   //--   DeltaV = -------------------------------
143   //--               TU.TU TV.TV  - (TU.TV)**2
144   //--
145   //--
146
147   Tg.Normalize();    MyTg = Tg; 
148
149   Standard_Real DeltaU,DeltaV;
150   gp_Vec TU,TV;
151   gp_Pnt Pbid;
152   Standard_Real TUTV,TgTU,TgTV,TUTU,TVTV,DIS;
153   //------------------------------------------------------------
154   //-- Calcul de Tguv1
155   //--
156   ThePSurfaceTool::D1(MySurf1,u1,v1,Pbid,TU,TV);
157   
158   TUTU = TU.Dot(TU);
159   TVTV = TV.Dot(TV);
160   TUTV = TU.Dot(TV);
161   TgTU = Tg.Dot(TU);
162   TgTV = Tg.Dot(TV);
163   DIS  = TUTU * TVTV - TUTV * TUTV;
164   
165   DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ; 
166   DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
167
168   Tguv1.SetCoord(DeltaU,DeltaV);  MyTguv1 = Tguv1;
169
170   //------------------------------------------------------------
171   //-- Calcul de Tguv2
172   //--  
173   ThePSurfaceTool::D1(MySurf2,u2,v2,Pbid,TU,TV);
174
175   TUTU = TU.Dot(TU);
176   TVTV = TV.Dot(TV);
177   TUTV = TU.Dot(TV);
178   TgTU = Tg.Dot(TU);
179   TgTV = Tg.Dot(TV);
180   DIS  = TUTU * TVTV - TUTV * TUTV;
181
182   DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ; 
183   DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
184   
185   Tguv2.SetCoord(DeltaU,DeltaV);  MyTguv2 = Tguv2;
186
187   return(Standard_True);
188 }
189 //--------------------------------------------------------------------------------
190 void ApproxInt_PrmPrmSvSurfaces::Pnt(const Standard_Real u1,
191                                      const Standard_Real v1,
192                                      const Standard_Real u2,
193                                      const Standard_Real v2,
194                                      gp_Pnt& P) { 
195   gp_Pnt aP;
196   gp_Vec aT;
197   gp_Vec2d aTS1,aTS2;
198   Standard_Real tu1=u1;
199   Standard_Real tu2=u2;
200   Standard_Real tv1=v1;
201   Standard_Real tv2=v2;
202 #ifdef DEB
203   Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
204 #else
205   this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
206 #endif
207   P=MyPnt;
208 }
209 //--------------------------------------------------------------------------------
210 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Tangency(const Standard_Real u1,
211                                                       const Standard_Real v1,
212                                                       const Standard_Real u2,
213                                                       const Standard_Real v2,
214                                                       gp_Vec& T) { 
215   gp_Pnt aP;
216   gp_Vec aT;
217   gp_Vec2d aTS1,aTS2;
218   Standard_Real tu1=u1;
219   Standard_Real tu2=u2;
220   Standard_Real tv1=v1;
221   Standard_Real tv2=v2;
222   Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
223   T=MyTg;
224   return(t);
225 }
226 //--------------------------------------------------------------------------------
227 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf1(const Standard_Real u1,
228                                                              const Standard_Real v1,
229                                                              const Standard_Real u2,
230                                                              const Standard_Real v2,
231                                                              gp_Vec2d& T) { 
232   gp_Pnt aP;
233   gp_Vec aT;
234   gp_Vec2d aTS1,aTS2;
235   Standard_Real tu1=u1;
236   Standard_Real tu2=u2;
237   Standard_Real tv1=v1;
238   Standard_Real tv2=v2;
239   Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
240   T=MyTguv1;
241   return(t);
242 }
243 //--------------------------------------------------------------------------------
244 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf2(const Standard_Real u1,
245                                                              const Standard_Real v1,
246                                                              const Standard_Real u2,
247                                                              const Standard_Real v2,
248                                                              gp_Vec2d& T) { 
249   gp_Pnt aP;
250   gp_Vec aT;
251   gp_Vec2d aTS1,aTS2;
252   Standard_Real tu1=u1;
253   Standard_Real tu2=u2;
254   Standard_Real tv1=v1;
255   Standard_Real tv2=v2;
256   Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
257   T=MyTguv2;
258   return(t);
259 }
260 //--------------------------------------------------------------------------------
261
262
263
264
265 #if 0 
266   //------------------------------------------------------------
267   //-- Calcul de Tguv1
268   //--
269   ThePSurfaceTool::D1(MySurf1,u1,v1,P,TU,TV);
270   
271   TUTV = TU.Dot(TV);
272   TgTU = Tg.Dot(TU);
273   TgTV = Tg.Dot(TV);
274   UmTUTV2 = 1.0 - TUTV * TUTV;
275   
276   DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ; 
277   DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
278
279   Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
280   
281   Tguv1.Multiplied(Delta);  MyTguv1 = Tguv1;
282
283   //------------------------------------------------------------
284   //-- Calcul de Tguv2
285   //--  
286   ThePSurfaceTool::D1(MySurf2,u2,v2,P,TU,TV);
287
288   TUTV = TU.Dot(TV);
289   TgTU = Tg.Dot(TU);
290   TgTV = Tg.Dot(TV);
291   UmTUTV2 = 1.0 - TUTV * TUTV;
292   
293   DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ; 
294   DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
295   
296   Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
297   
298   Tguv2.Multiplied(Delta);  MyTguv2 = Tguv2;
299
300   return(Standard_True);
301 }
302 #endif
303
304
305
306