Warning, /include/opencascade/ApproxInt_PrmPrmSvSurfaces.gxx is written in an unsupported language. File is not indexed.
0001 // Created on: 1993-03-17
0002 // Created by: Laurent BUCHARD
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016
0017 #define TOLTANGENCY 0.0000000001
0018
0019
0020 #include <TColStd_Array1OfReal.hxx>
0021 #include <math_FunctionSetRoot.hxx>
0022 #include <Precision.hxx>
0023
0024 #define Debug(expr) std::cout<<" expr :"<<expr;
0025 #define MySurf1 MyIntersectionOn2S.Function().AuxillarSurface1()
0026 #define MySurf2 MyIntersectionOn2S.Function().AuxillarSurface2()
0027
0028
0029 //--------------------------------------------------------------------------------
0030 ApproxInt_PrmPrmSvSurfaces::ApproxInt_PrmPrmSvSurfaces( const ThePSurface& Surf1
0031 ,const ThePSurface& Surf2):
0032 MyIsTangent(Standard_False),
0033 MyHasBeenComputed(Standard_False),
0034 MyIsTangentbis(Standard_False),
0035 MyHasBeenComputedbis(Standard_False),
0036 MyIntersectionOn2S(Surf1,Surf2,TOLTANGENCY)
0037 {
0038 }
0039
0040 //=======================================================================
0041 //function : Compute
0042 //purpose : Computes point on curve, 3D and 2D-tangents of a curve and
0043 // parameters on the surfaces.
0044 //=======================================================================
0045 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Compute( Standard_Real& u1
0046 ,Standard_Real& v1
0047 ,Standard_Real& u2
0048 ,Standard_Real& v2
0049 ,gp_Pnt& P
0050 ,gp_Vec& Tg
0051 ,gp_Vec2d& Tguv1
0052 ,gp_Vec2d& Tguv2) {
0053
0054 Standard_Real tu1=u1;
0055 Standard_Real tu2=u2;
0056 Standard_Real tv1=v1;
0057 Standard_Real tv2=v2;
0058
0059 if(MyHasBeenComputed) {
0060 if( (MyParOnS1.X()==u1)&&(MyParOnS1.Y()==v1)
0061 &&(MyParOnS2.X()==u2)&&(MyParOnS2.Y()==v2)) {
0062 return(MyIsTangent);
0063 }
0064 else if(MyHasBeenComputedbis == Standard_False) {
0065 MyTgbis = MyTg;
0066 MyTguv1bis = MyTguv1;
0067 MyTguv2bis = MyTguv2;
0068 MyPntbis = MyPnt;
0069 MyParOnS1bis = MyParOnS1;
0070 MyParOnS2bis = MyParOnS2;
0071 MyIsTangentbis = MyIsTangent;
0072 MyHasBeenComputedbis = MyHasBeenComputed;
0073 }
0074 }
0075 if(MyHasBeenComputedbis) {
0076 if( (MyParOnS1bis.X()==u1)&&(MyParOnS1bis.Y()==v1)
0077 &&(MyParOnS2bis.X()==u2)&&(MyParOnS2bis.Y()==v2)) {
0078
0079 gp_Vec TV(MyTg);
0080 gp_Vec2d TV1(MyTguv1);
0081 gp_Vec2d TV2(MyTguv2);
0082 gp_Pnt TP(MyPnt);
0083 gp_Pnt2d TP1(MyParOnS1);
0084 gp_Pnt2d TP2(MyParOnS2);
0085 Standard_Boolean TB=MyIsTangent;
0086
0087 MyTg = MyTgbis;
0088 MyTguv1 = MyTguv1bis;
0089 MyTguv2 = MyTguv2bis;
0090 MyPnt = MyPntbis;
0091 MyParOnS1 = MyParOnS1bis;
0092 MyParOnS2 = MyParOnS2bis;
0093 MyIsTangent = MyIsTangentbis;
0094
0095 MyTgbis = TV;
0096 MyTguv1bis = TV1;
0097 MyTguv2bis = TV2;
0098 MyPntbis = TP;
0099 MyParOnS1bis = TP1;
0100 MyParOnS2bis = TP2;
0101 MyIsTangentbis = TB;
0102
0103 return(MyIsTangent);
0104 }
0105 }
0106
0107
0108 MyIsTangent = Standard_True;
0109
0110 Standard_Real aParam[4];//stack vs heap allocation
0111 TColStd_Array1OfReal Param (aParam[0],1,4);
0112 Param(1) = u1; Param(2) = v1;
0113 Param(3) = u2; Param(4) = v2;
0114 math_FunctionSetRoot Rsnld(MyIntersectionOn2S.Function());
0115 MyIntersectionOn2S.Perform(Param,Rsnld);
0116 if (!MyIntersectionOn2S.IsDone()) {
0117 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
0118 return(Standard_False);
0119 }
0120 if (MyIntersectionOn2S.IsEmpty()) {
0121 MyIsTangent=Standard_False;
0122 //cout<<"\n----- Parametree Parametree : IsEmpty ds Compute "<<endl;
0123 //Debug(u1); Debug(u2); Debug(v1); Debug(v2); cout<<endl;
0124 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
0125 return(Standard_False);
0126 }
0127 MyHasBeenComputed = Standard_True;
0128 MyPnt = P = MyIntersectionOn2S.Point().Value();
0129
0130 MyIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
0131 MyParOnS1.SetCoord(tu1,tv1);
0132 MyParOnS2.SetCoord(tu2,tv2);
0133
0134 if(MyIntersectionOn2S.IsTangent()) {
0135 MyIsTangent=Standard_False;
0136 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
0137 return(Standard_False);
0138 }
0139 MyTg = Tg = MyIntersectionOn2S.Direction();
0140 MyTguv1 = Tguv1 = MyIntersectionOn2S.DirectionOnS1();
0141 MyTguv2 = Tguv2 = MyIntersectionOn2S.DirectionOnS2();
0142
0143 //----------------------------------------------------------------------
0144 //-- Si ( Tg ) TU et TV sont normes
0145 //--
0146 //-- On a Tg = DeltaU * TU + DeltaV * TV
0147 //--
0148 //-- soit : Tg.TU = DeltaU TU.TU + DeltaV TU.TV
0149 //-- Tg.TV = DeltaU TV.TU + DeltaV TV.TV
0150 //--
0151 //-- Donc :
0152 //--
0153 //-- Tg.TU TV.TV - Tg.TV * TU.TV
0154 //-- DeltaU = -------------------------------
0155 //-- TU.TU TV.TV - (TU.TV)**2
0156 //--
0157 //-- Tg.TV TU.TU - Tg.TU * TU.TV
0158 //-- DeltaV = -------------------------------
0159 //-- TU.TU TV.TV - (TU.TV)**2
0160 //--
0161 //--
0162
0163 Tg.Normalize(); MyTg = Tg;
0164
0165 Standard_Real DeltaU,DeltaV;
0166 gp_Vec TU,TV;
0167 gp_Pnt Pbid;
0168 Standard_Real TUTV,TgTU,TgTV,TUTU,TVTV,DIS;
0169 //------------------------------------------------------------
0170 //-- Calcul de Tguv1
0171 //--
0172 ThePSurfaceTool::D1(MySurf1,u1,v1,Pbid,TU,TV);
0173
0174 TUTU = TU.Dot(TU);
0175 TVTV = TV.Dot(TV);
0176 TUTV = TU.Dot(TV);
0177 TgTU = Tg.Dot(TU);
0178 TgTV = Tg.Dot(TV);
0179 DIS = TUTU * TVTV - TUTV * TUTV;
0180 if(fabs(DIS)<Precision::Angular()) {
0181 MyIsTangent=Standard_False;
0182 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
0183 return(Standard_False);
0184 }
0185
0186 DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ;
0187 DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
0188
0189 Tguv1.SetCoord(DeltaU,DeltaV); MyTguv1 = Tguv1;
0190
0191 //------------------------------------------------------------
0192 //-- Calcul de Tguv2
0193 //--
0194 ThePSurfaceTool::D1(MySurf2,u2,v2,Pbid,TU,TV);
0195
0196 TUTU = TU.Dot(TU);
0197 TVTV = TV.Dot(TV);
0198 TUTV = TU.Dot(TV);
0199 TgTU = Tg.Dot(TU);
0200 TgTV = Tg.Dot(TV);
0201 DIS = TUTU * TVTV - TUTV * TUTV;
0202 if(fabs(DIS)<Precision::Angular()) {
0203 MyIsTangent=Standard_False;
0204 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
0205 return(Standard_False);
0206 }
0207
0208 DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ;
0209 DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
0210
0211 Tguv2.SetCoord(DeltaU,DeltaV); MyTguv2 = Tguv2;
0212
0213 return(Standard_True);
0214 }
0215 //--------------------------------------------------------------------------------
0216 void ApproxInt_PrmPrmSvSurfaces::Pnt(const Standard_Real u1,
0217 const Standard_Real v1,
0218 const Standard_Real u2,
0219 const Standard_Real v2,
0220 gp_Pnt& P) {
0221 gp_Pnt aP;
0222 gp_Vec aT;
0223 gp_Vec2d aTS1,aTS2;
0224 Standard_Real tu1=u1;
0225 Standard_Real tu2=u2;
0226 Standard_Real tv1=v1;
0227 Standard_Real tv2=v2;
0228 this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
0229 P=MyPnt;
0230 }
0231
0232 //=======================================================================
0233 //function : SeekPoint
0234 //purpose : Computes point on curve and
0235 // parameters on the surfaces.
0236 //=======================================================================
0237 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::SeekPoint(const Standard_Real u1,
0238 const Standard_Real v1,
0239 const Standard_Real u2,
0240 const Standard_Real v2,
0241 IntSurf_PntOn2S& Point)
0242 {
0243 gp_Pnt aP;
0244 gp_Vec aT;
0245 gp_Vec2d aTS1,aTS2;
0246 Standard_Real tu1=u1;
0247 Standard_Real tu2=u2;
0248 Standard_Real tv1=v1;
0249 Standard_Real tv2=v2;
0250 if (!Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2))
0251 return Standard_False;
0252
0253 Point.SetValue(aP, tu1,tv1,tu2,tv2);
0254 return Standard_True;
0255 }
0256 //--------------------------------------------------------------------------------
0257 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Tangency(const Standard_Real u1,
0258 const Standard_Real v1,
0259 const Standard_Real u2,
0260 const Standard_Real v2,
0261 gp_Vec& T) {
0262 gp_Pnt aP;
0263 gp_Vec aT;
0264 gp_Vec2d aTS1,aTS2;
0265 Standard_Real tu1=u1;
0266 Standard_Real tu2=u2;
0267 Standard_Real tv1=v1;
0268 Standard_Real tv2=v2;
0269 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
0270 T=MyTg;
0271 return(t);
0272 }
0273 //--------------------------------------------------------------------------------
0274 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf1(const Standard_Real u1,
0275 const Standard_Real v1,
0276 const Standard_Real u2,
0277 const Standard_Real v2,
0278 gp_Vec2d& T) {
0279 gp_Pnt aP;
0280 gp_Vec aT;
0281 gp_Vec2d aTS1,aTS2;
0282 Standard_Real tu1=u1;
0283 Standard_Real tu2=u2;
0284 Standard_Real tv1=v1;
0285 Standard_Real tv2=v2;
0286 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
0287 T=MyTguv1;
0288 return(t);
0289 }
0290 //--------------------------------------------------------------------------------
0291 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf2(const Standard_Real u1,
0292 const Standard_Real v1,
0293 const Standard_Real u2,
0294 const Standard_Real v2,
0295 gp_Vec2d& T) {
0296 gp_Pnt aP;
0297 gp_Vec aT;
0298 gp_Vec2d aTS1,aTS2;
0299 Standard_Real tu1=u1;
0300 Standard_Real tu2=u2;
0301 Standard_Real tv1=v1;
0302 Standard_Real tv2=v2;
0303 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
0304 T=MyTguv2;
0305 return(t);
0306 }
0307 //--------------------------------------------------------------------------------
0308
0309
0310
0311
0312 #if 0
0313 //------------------------------------------------------------
0314 //-- Calcul de Tguv1
0315 //--
0316 ThePSurfaceTool::D1(MySurf1,u1,v1,P,TU,TV);
0317
0318 TUTV = TU.Dot(TV);
0319 TgTU = Tg.Dot(TU);
0320 TgTV = Tg.Dot(TV);
0321 UmTUTV2 = 1.0 - TUTV * TUTV;
0322
0323 DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ;
0324 DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
0325
0326 Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
0327
0328 Tguv1.Multiplied(Delta); MyTguv1 = Tguv1;
0329
0330 //------------------------------------------------------------
0331 //-- Calcul de Tguv2
0332 //--
0333 ThePSurfaceTool::D1(MySurf2,u2,v2,P,TU,TV);
0334
0335 TUTV = TU.Dot(TV);
0336 TgTU = Tg.Dot(TU);
0337 TgTV = Tg.Dot(TV);
0338 UmTUTV2 = 1.0 - TUTV * TUTV;
0339
0340 DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ;
0341 DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
0342
0343 Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
0344
0345 Tguv2.Multiplied(Delta); MyTguv2 = Tguv2;
0346
0347 return(Standard_True);
0348 }
0349 #endif
0350
0351
0352
0353