1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
20 //-- Modif du 5 Octobre 94 (LBR)
22 //-- On deborde sur une frontiere, Duv[.] = -1 -1 -1 -1
23 //-- donc on garde la meme iso bloquee (voir if(k!=1) )
26 //-- Modif du 8 juillet 96 (LBR)
27 //-- simplifaication du traitement des auto-intersections.
29 //-- Tester la boucle fermee en 3d et en 2d.
32 #include <gp_Pnt2d.hxx>
35 Standard_Boolean IntWalk_PWalking::
36 TestArret(const Standard_Boolean DejaReparti,
37 TColStd_Array1OfReal& Param,
38 IntImp_ConstIsoparametric& ChoixIso)
41 // tester si le point d intersection donne par ces parametres reste dans le
42 // domaine naturelle de chaque carreau.
43 // si le point deborde cadrer de facon a trouver la meilleure iso (frontiere)
44 // qui intersecte le plus franchement l autre carreau
45 // sinon tester si presence de ligne fermee
48 Standard_Real Uvd[4],Uvf[4],Epsuv[4],Duv[4],Uvp[4],dv,dv2,ParC[4];
49 Standard_Real DPc,DPb;
51 Standard_Integer i = 0, k = 0;
59 previousPoint.Parameters(Uvp[0],Uvp[1],Uvp[2],Uvp[3]);
60 Standard_Boolean Trouve = Standard_False;
62 Uvd[0]=Um1; Uvf[0]=UM1; Uvd[1]=Vm1; Uvf[1]=VM1;
63 Uvd[2]=Um2; Uvf[2]=UM2; Uvd[3]=Vm2; Uvf[3]=VM2;
66 for ( i = 1,im1 = 0;i<=4;i++,im1++) {
73 if (Param(i) < (Uvd[im1]-Epsuv[im1])) { //-- Current ----- Bound Inf ----- Previous
74 Trouve = Standard_True; //--
75 DPc = Uvp[im1]-Param(i); //-- Previous - Current
76 DPb = Uvp[im1]-Uvd[im1]; //-- Previous - Bound Inf
77 ParC[im1] = Uvd[im1]; //-- ParamCorrige
78 dv = Param(k)-Uvp[k-1]; //-- Current - Previous (Sur Autre Direction)
80 if(dv2>RealEpsilon()) { //-- Progression sur l autre Direction ?
81 Duv[im1] = DPc*DPb + dv2;
82 Duv[im1] = Duv[im1]*Duv[im1]/(DPc*DPc+dv2)/(DPb*DPb+dv2);
85 Duv[im1]=-1.0; //-- Si Pas de prgogression, on ne change pas
86 } //-- le choix de l iso
88 else if (Param(i) > (Uvf[im1] + Epsuv[im1])) { //-- Previous ----- Bound Sup ----- Current
89 Trouve = Standard_True; //--
90 DPc = Param(i)-Uvp[im1]; //-- Current - Previous
91 DPb = Uvf[im1]-Uvp[im1]; //-- Bound Sup - Previous
92 ParC[im1] = Uvf[im1]; //-- Param Corrige
93 dv = Param(k)-Uvp[k-1]; //-- Current - Previous (Sur autre Direction)
95 if(dv2>RealEpsilon()) { //-- Progression sur l autre Direction ?
96 Duv[im1] = DPc*DPb + dv2;
97 Duv[im1] = Duv[im1]*Duv[im1]/(DPc*DPc+dv2)/(DPb*DPb+dv2);
100 Duv[im1]=-1.0; //-- Si Pas de prgogression, on ne change pas
101 } //-- le choix de l iso
110 //--------------------------------------------------
111 //-- Un des Parametres u1,v1,u2,v2 est en dehors --
112 //-- des bornes naturelles. --
113 //-- On cherche la meilleure direction de --
114 //-- progression et on recadre les params. --
115 //--------------------------------------------------
116 Standard_Real ddv = -1.0;
119 Param(i+1) = ParC[i];
126 ChoixIso = ChoixRef[k];
129 if((ParC[0]<=Uvd[0]+Epsuv[0]) || (ParC[0]>=Uvf[0]-Epsuv[0])) {
130 ChoixIso = IntImp_UIsoparametricOnCaro1;
132 else if((ParC[1]<=Uvd[1]+Epsuv[1]) || (ParC[1]>=Uvf[1]-Epsuv[1])) {
133 ChoixIso = IntImp_VIsoparametricOnCaro1;
135 else if((ParC[2]<=Uvd[2]+Epsuv[2]) || (ParC[2]>=Uvf[2]-Epsuv[2])) {
136 ChoixIso = IntImp_UIsoparametricOnCaro2;
138 else if((ParC[3]<=Uvd[3]+Epsuv[3]) || (ParC[3]>=Uvf[3]-Epsuv[3])) {
139 ChoixIso = IntImp_VIsoparametricOnCaro2;
142 close = Standard_False;
143 return Standard_True;
147 if (!DejaReparti) { // recherche si ligne fermee
149 Standard_Real u,v,up,vp;
150 const IntSurf_PntOn2S& POn2S1=line->Value(1);
151 POn2S1.ParametersOnS1(u,v);
153 previousPoint.ParametersOnS1(u,v);
155 gp_Pnt2d Prevuv(u,v);
156 myIntersectionOn2S.Point().ParametersOnS1(u,v);
157 gp_Pnt2d myIntersuv(u,v);
158 Standard_Boolean close2d = (P1uv.XY()-Prevuv.XY())*
159 (P1uv.XY()-myIntersuv.XY()) <0.0;
161 const gp_Pnt &P1 = line->Value(1).Value();
162 close = (P1.XYZ() - previousPoint.Value().XYZ())*
163 (P1.XYZ() - myIntersectionOn2S.Point().Value().XYZ()) < 0;
164 if(close != close2d) {
166 cout<<"\n PWalking_4 TestArret - close2d"<<close2d<<endl;
169 Standard_Boolean autoclose = Standard_False;
170 previousPoint.ParametersOnS2(u,v);
171 if( myIntersectionOn2S.Function().AuxillarSurface1()
172 == myIntersectionOn2S.Function().AuxillarSurface2()) {
173 if(Abs(u-up)<=1e-7 && Abs(v-vp)<=1e-7) {
174 autoclose=Standard_True;
180 return (autoclose || (close&&close2d));
182 else return Standard_False;