b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | //-- |
b1c5c4e6 |
16 | //-- Modif of 5 October 94 (LBR) |
7fd59977 |
17 | //-- if(Trouve) ... |
b1c5c4e6 |
18 | //-- outpasses a border, Duv[.] = -1 -1 -1 -1 |
19 | //-- keep the same iso limited (see if(k!=1) ) |
7fd59977 |
20 | //-- |
21 | |
b1c5c4e6 |
22 | //-- Modif of 8 July 96 (LBR) |
23 | //-- simplify processing of auto-intersections. |
24 | //-- Idea : Test closed loop in 3d and in 2d. |
7fd59977 |
25 | //-- |
26 | |
27 | #include <gp_Pnt2d.hxx> |
28 | |
29 | |
30 | Standard_Boolean IntWalk_PWalking:: |
31 | TestArret(const Standard_Boolean DejaReparti, |
32 | TColStd_Array1OfReal& Param, |
33 | IntImp_ConstIsoparametric& ChoixIso) |
34 | |
35 | // |
b1c5c4e6 |
36 | // test if the point of intersection set by these parameters remains in the |
37 | // natural domain of each square. |
38 | // if the point outpasses reframe to find the best iso (border) |
39 | // that intersects easiest the other square |
40 | // otherwise test if closed line is present |
7fd59977 |
41 | // |
42 | { |
43 | Standard_Real Uvd[4],Uvf[4],Epsuv[4],Duv[4],Uvp[4],dv,dv2,ParC[4]; |
44 | Standard_Real DPc,DPb; |
7fd59977 |
45 | Standard_Integer i = 0, k = 0; |
7fd59977 |
46 | Epsuv[0] = ResoU1; |
47 | Epsuv[1] = ResoV1; |
48 | Epsuv[2] = ResoU2; |
49 | Epsuv[3] = ResoV2; |
50 | previousPoint.Parameters(Uvp[0],Uvp[1],Uvp[2],Uvp[3]); |
b1c5c4e6 |
51 | |
52 | Standard_Real SolParam[4]; |
53 | myIntersectionOn2S.Point().Parameters(SolParam[0],SolParam[1],SolParam[2],SolParam[3]); |
54 | |
7fd59977 |
55 | Standard_Boolean Trouve = Standard_False; |
56 | |
57 | Uvd[0]=Um1; Uvf[0]=UM1; Uvd[1]=Vm1; Uvf[1]=VM1; |
58 | Uvd[2]=Um2; Uvf[2]=UM2; Uvd[3]=Vm2; Uvf[3]=VM2; |
59 | |
60 | Standard_Integer im1; |
61 | for ( i = 1,im1 = 0;i<=4;i++,im1++) { |
62 | switch(i) { |
63 | case 1: k=2; break; |
64 | case 2: k=1; break; |
65 | case 3: k=4; break; |
66 | case 4: k=3; break; |
67 | } |
b1c5c4e6 |
68 | if (Param(i) < (Uvd[im1]-Epsuv[im1]) || |
69 | SolParam[im1] < (Uvd[im1]-Epsuv[im1])) //-- Current ----- Bound Inf ----- Previous |
70 | { |
7fd59977 |
71 | Trouve = Standard_True; //-- |
72 | DPc = Uvp[im1]-Param(i); //-- Previous - Current |
73 | DPb = Uvp[im1]-Uvd[im1]; //-- Previous - Bound Inf |
74 | ParC[im1] = Uvd[im1]; //-- ParamCorrige |
b1c5c4e6 |
75 | dv = Param(k)-Uvp[k-1]; //-- Current - Previous (other Direction) |
7fd59977 |
76 | dv2 = dv*dv; |
b1c5c4e6 |
77 | if(dv2>RealEpsilon()) { //-- Progress at the other Direction ? |
7fd59977 |
78 | Duv[im1] = DPc*DPb + dv2; |
79 | Duv[im1] = Duv[im1]*Duv[im1]/(DPc*DPc+dv2)/(DPb*DPb+dv2); |
80 | } |
81 | else { |
b1c5c4e6 |
82 | Duv[im1]=-1.0; //-- If no progress, do not change |
83 | } //-- the choice of iso |
7fd59977 |
84 | } |
b1c5c4e6 |
85 | else if (Param(i) > (Uvf[im1] + Epsuv[im1]) || |
86 | SolParam[im1] > (Uvf[im1] + Epsuv[im1]))//-- Previous ----- Bound Sup ----- Current |
87 | { |
7fd59977 |
88 | Trouve = Standard_True; //-- |
89 | DPc = Param(i)-Uvp[im1]; //-- Current - Previous |
90 | DPb = Uvf[im1]-Uvp[im1]; //-- Bound Sup - Previous |
91 | ParC[im1] = Uvf[im1]; //-- Param Corrige |
b1c5c4e6 |
92 | dv = Param(k)-Uvp[k-1]; //-- Current - Previous (other Direction) |
7fd59977 |
93 | dv2 = dv*dv; |
b1c5c4e6 |
94 | if(dv2>RealEpsilon()) { //-- Progress in other Direction ? |
7fd59977 |
95 | Duv[im1] = DPc*DPb + dv2; |
96 | Duv[im1] = Duv[im1]*Duv[im1]/(DPc*DPc+dv2)/(DPb*DPb+dv2); |
97 | } |
98 | else { |
b1c5c4e6 |
99 | Duv[im1]=-1.0; //-- If no progress, do not change |
100 | } //-- the choice of iso |
7fd59977 |
101 | } |
102 | else { |
103 | Duv[im1]= -1.; |
104 | ParC[im1]=Param(i); |
105 | } |
106 | } |
107 | |
108 | if (Trouve) { |
109 | //-------------------------------------------------- |
b1c5c4e6 |
110 | //-- One of Parameters u1,v1,u2,v2 is outside of -- |
111 | //-- the natural limits. -- |
112 | //-- Find the best direction of -- |
113 | //-- progress and reframe the parameters. -- |
7fd59977 |
114 | //-------------------------------------------------- |
115 | Standard_Real ddv = -1.0; |
116 | k=-1; |
117 | for (i=0;i<=3;i++) { |
118 | Param(i+1) = ParC[i]; |
119 | if(Duv[i]>ddv) { |
120 | ddv = Duv[i]; |
121 | k=i; |
122 | } |
123 | } |
124 | if(k!=-1) { |
125 | ChoixIso = ChoixRef[k]; |
126 | } |
127 | else { |
128 | if((ParC[0]<=Uvd[0]+Epsuv[0]) || (ParC[0]>=Uvf[0]-Epsuv[0])) { |
129 | ChoixIso = IntImp_UIsoparametricOnCaro1; |
130 | } |
131 | else if((ParC[1]<=Uvd[1]+Epsuv[1]) || (ParC[1]>=Uvf[1]-Epsuv[1])) { |
132 | ChoixIso = IntImp_VIsoparametricOnCaro1; |
133 | } |
134 | else if((ParC[2]<=Uvd[2]+Epsuv[2]) || (ParC[2]>=Uvf[2]-Epsuv[2])) { |
135 | ChoixIso = IntImp_UIsoparametricOnCaro2; |
136 | } |
137 | else if((ParC[3]<=Uvd[3]+Epsuv[3]) || (ParC[3]>=Uvf[3]-Epsuv[3])) { |
138 | ChoixIso = IntImp_VIsoparametricOnCaro2; |
139 | } |
140 | } |
141 | close = Standard_False; |
142 | return Standard_True; |
143 | } |
144 | else |
145 | { |
b1c5c4e6 |
146 | if (!DejaReparti) { // find if line closed |
7fd59977 |
147 | |
d42d1867 |
148 | Standard_Real u,v; |
7fd59977 |
149 | const IntSurf_PntOn2S& POn2S1=line->Value(1); |
d42d1867 |
150 | //On S1 |
7fd59977 |
151 | POn2S1.ParametersOnS1(u,v); |
d42d1867 |
152 | gp_Pnt2d P1uvS1(u,v); |
7fd59977 |
153 | previousPoint.ParametersOnS1(u,v); |
d42d1867 |
154 | gp_Pnt2d PrevuvS1(u,v); |
7fd59977 |
155 | myIntersectionOn2S.Point().ParametersOnS1(u,v); |
d42d1867 |
156 | gp_Pnt2d myIntersuvS1(u,v); |
157 | Standard_Boolean close2dS1 = (P1uvS1.XY()-PrevuvS1.XY())* |
158 | (P1uvS1.XY()-myIntersuvS1.XY()) < 0.0; |
159 | //On S2 |
160 | POn2S1.ParametersOnS2(u,v); |
161 | gp_Pnt2d P1uvS2(u,v); |
162 | previousPoint.ParametersOnS2(u,v); |
163 | gp_Pnt2d PrevuvS2(u,v); |
164 | myIntersectionOn2S.Point().ParametersOnS2(u,v); |
165 | gp_Pnt2d myIntersuvS2(u,v); |
166 | Standard_Boolean close2dS2 = (P1uvS2.XY()-PrevuvS2.XY())* |
167 | (P1uvS2.XY()-myIntersuvS2.XY()) < 0.0; |
7fd59977 |
168 | |
d42d1867 |
169 | close = close2dS1 && close2dS2; |
170 | return close; |
7fd59977 |
171 | } |
172 | else return Standard_False; |
173 | } |
174 | } |
175 | |
176 | |