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 | Blend_Status Blend_CSWalking::TestArret(Blend_CSFunction& Function, |
16 | const math_Vector& Sol, |
17 | const Standard_Boolean TestDefl, |
18 | const Blend_Status State) |
19 | |
20 | // On regarde si le point donne est solution. |
21 | // Si c est le cas, |
22 | // On verifie le critere de fleche sur surf et curv |
23 | // Si OK, on classifie les point sur surf |
24 | // Si le point est dedans : on retourne Blend_OK |
25 | // sinon on resout le pb inverse sur la surface |
26 | // sinon (fleche non OK) |
27 | // on renvoie Blend_StepTooLarge. |
28 | // sinon on renvoie Blend_StepTooLarge. |
29 | // |
30 | |
31 | |
32 | { |
33 | gp_Pnt pt1,pt2; |
34 | gp_Vec V1,V2; |
35 | gp_Vec Tgp1,Nor1; |
36 | gp_Vec2d V12d; |
37 | gp_Pnt2d pt2d; |
38 | Standard_Real pOnC; |
39 | Blend_Status State1,State2; |
7fd59977 |
40 | IntSurf_TypeTrans tras = IntSurf_Undecided; |
1d47d8d0 |
41 | |
7fd59977 |
42 | if (Function.IsSolution(Sol,tolesp)) { |
43 | |
44 | pt1 = Function.PointOnS(); |
45 | pt2 = Function.PointOnC(); |
46 | pt2d = Function.Pnt2d(); |
47 | pOnC = Function.ParameterOnC(); |
48 | V1 = Function.TangentOnS(); |
49 | V2 = Function.TangentOnC(); |
50 | V12d = Function.Tangent2d(); |
51 | |
52 | if (TestDefl) { |
53 | |
54 | |
55 | // Verification du critere de fleche sur chaque surface |
56 | //et sur la ligne guide |
57 | |
58 | State1 = CheckDeflectionOnSurf(pt1, |
59 | // gp_Pnt2d(sol(1),sol(2)), |
60 | pt2d, |
61 | V1,V12d); |
62 | // State2 = CheckDeflectionOnCurv(pt2,sol(3),V2); |
63 | // Pour des pb dans les cheminements point/face on met |
64 | // temporairement le test sur la courbe au placard. |
65 | // State2 = CheckDeflectionOnCurv(pt2,pOnC,V2); |
66 | State2 = Blend_StepTooSmall; |
67 | } |
68 | else { |
69 | State1 = Blend_OK; |
70 | State2 = Blend_OK; |
71 | } |
72 | |
73 | if (State1 == Blend_Backward) { |
74 | State1 = Blend_StepTooLarge; |
75 | rebrou= Standard_True; |
76 | } |
77 | |
78 | if (State2 == Blend_Backward) { |
79 | State2 = Blend_StepTooLarge; |
80 | rebrou = Standard_True; |
81 | } |
82 | |
83 | if (State1 == Blend_StepTooLarge || |
84 | State2 == Blend_StepTooLarge) { |
85 | |
86 | return Blend_StepTooLarge; |
87 | } |
88 | |
89 | |
90 | if (!comptra) { |
91 | // Function.Tangent(sol(1),sol(2),Tgp1,Nor1); |
92 | Function.Tangent(pt2d.X(),pt2d.Y(),Tgp1,Nor1); |
93 | Standard_Real testra = Tgp1.Dot(Nor1.Crossed(V1)); |
94 | if (Abs(testra) > Precision::Confusion()) { |
95 | if (testra < 0.) { |
96 | tras = IntSurf_In; |
97 | } |
98 | else if (testra >0.) { |
99 | tras = IntSurf_Out; |
100 | } |
101 | comptra = Standard_True; |
102 | line->Set(tras); |
103 | } |
104 | } |
105 | |
106 | if (State1 == Blend_OK || |
107 | State2 == Blend_OK ) { |
108 | |
109 | previousP.SetValue(Function.PointOnS(), |
110 | Function.PointOnC(), |
111 | param, |
112 | // sol(1),sol(2), |
113 | // sol(3), |
114 | pt2d.X(),pt2d.Y(), |
115 | pOnC, |
116 | V1,V2, |
117 | V12d); |
118 | |
119 | |
120 | return State; |
121 | } |
122 | if (State1 == Blend_StepTooSmall && |
123 | State2 == Blend_StepTooSmall) { |
124 | |
125 | previousP.SetValue(Function.PointOnS(), |
126 | Function.PointOnC(), |
127 | param, |
128 | // sol(1),sol(2), |
129 | // sol(3), |
130 | pt2d.X(),pt2d.Y(), |
131 | pOnC, |
132 | V1,V2, |
133 | V12d); |
134 | if (State == Blend_OK) { |
135 | return Blend_StepTooSmall; |
136 | } |
137 | else { |
138 | return State; |
139 | } |
140 | } |
141 | |
142 | if (State == Blend_OK) { |
143 | return Blend_SamePoints; |
144 | } |
145 | else { |
146 | return State; |
147 | } |
148 | |
149 | } |
150 | else { |
151 | return Blend_StepTooLarge; |
152 | } |
153 | } |
154 | |
155 | |
156 | Blend_Status Blend_CSWalking::CheckDeflectionOnSurf |
157 | (const gp_Pnt& Psurf, |
158 | const gp_Pnt2d& Ponsurf, |
159 | const gp_Vec& Tgsurf, |
160 | const gp_Vec2d& Tgonsurf) |
161 | { |
162 | // regle par tests dans U4 correspond a 11.478 d |
163 | const Standard_Real CosRef3D = 0.98; |
164 | |
165 | const Standard_Real CosRef2D = 0.88; // correspond a 25 d |
166 | |
167 | Standard_Real Norme, prevNorme, Cosi, Cosi2; // JAG MODIF 25.04.94 |
168 | Standard_Real FlecheCourante; |
96a95605 |
169 | Standard_Real Du,Dv,Duv; |
7fd59977 |
170 | Standard_Real paramu,paramv,tolu,tolv; |
171 | // TColgp_Array1OfPnt Poles(1,4); |
172 | // gp_Pnt POnCurv,Milieu; |
173 | gp_Pnt prevP; |
174 | gp_Vec prevTg; |
175 | gp_Vec2d previousd2d; |
176 | |
177 | prevP = previousP.PointOnS(); |
178 | prevTg = previousP.TangentOnS(); |
179 | tolu = TheSurfaceTool::UResolution(surf,tolesp); |
180 | tolv = TheSurfaceTool::VResolution(surf,tolesp); |
181 | |
182 | gp_Vec Corde(prevP,Psurf); |
183 | Norme = Corde.SquareMagnitude(); |
184 | prevNorme = prevTg.SquareMagnitude(); // JAG MODIF 25.04.94 |
185 | |
186 | |
187 | if (Norme <= tolesp*tolesp || prevNorme <= tolesp*tolesp) { // JAG MODIF 25.04.94 |
188 | // il faudra peut etre forcer meme point JAG MODIF 25.04.94 |
189 | return Blend_SamePoints; |
190 | } |
191 | Cosi = sens*Corde*prevTg; |
192 | if (Cosi <0.) { // angle 3d>pi/2. --> retour arriere |
193 | return Blend_Backward; |
194 | } |
195 | |
196 | Cosi2 = Cosi * Cosi / prevNorme / Norme; |
197 | if (Cosi2 < CosRef3D) { |
198 | return Blend_StepTooLarge; |
199 | } |
200 | |
201 | previousP.ParametersOnS(paramu,paramv); |
202 | previousd2d = previousP.Tangent2d(); |
203 | |
204 | Du = Ponsurf.X() - paramu; |
205 | Dv = Ponsurf.Y() - paramv; |
206 | Duv = Du * Du + Dv * Dv; |
7fd59977 |
207 | if ((Abs(Du) < tolu && Abs(Dv) < tolv) || // JAG MODIF 25.04.94 |
208 | (Abs(previousd2d.X()) < tolu && Abs(previousd2d.Y()) < tolv)){ |
209 | // il faudra peut etre forcer meme point JAG MODIF 25.04.94 |
210 | return Blend_SamePoints; //point confondu 2d |
211 | } |
212 | Cosi = sens*(Du * previousd2d.X() + Dv * previousd2d.Y()); |
213 | if (Cosi < 0) { |
214 | return Blend_Backward; |
215 | } |
216 | |
217 | // Voir s il faut faire le controle sur le signe de prevtg*Tgsurf |
218 | Cosi = sens*Corde*Tgsurf; |
219 | Cosi2 = Cosi * Cosi / Tgsurf.SquareMagnitude() / Norme; |
220 | if (Cosi2 < CosRef3D || Cosi < 0.) { |
221 | return Blend_StepTooLarge; |
222 | } |
223 | |
224 | // Voir s il faut faire le controle sur le signe de Cosi |
225 | Cosi = sens*(Du * Tgonsurf.X() + Dv * Tgonsurf.Y())/Tgonsurf.Magnitude(); |
226 | Cosi2 = Cosi * Cosi / Duv; |
227 | if (Cosi2 < CosRef2D || Cosi <0.) { |
228 | return Blend_StepTooLarge; |
229 | } |
230 | |
231 | // Estimation de la fleche courante |
232 | /* |
233 | Norme = Sqrt(Norme)/3.; |
234 | Poles(1) = prevP; |
235 | Poles(4) = Psurf; |
236 | Poles(2) = Poles(1).XYZ() + sens*Norme* prevTg.Normalized().XYZ(); |
237 | Poles(3) = Poles(4).XYZ() - sens*Norme* Tgsurf.Normalized().XYZ(); |
238 | BzCLib::PntPole(0.5,Poles,POnCurv); |
239 | Milieu = (Poles(1).XYZ() + Poles(4).XYZ())*0.5; |
240 | FlecheCourante = Milieu.Distance(POnCurv); |
241 | |
242 | if (FlecheCourante <= 0.5*fleche) { |
243 | */ |
244 | FlecheCourante = (prevTg.Normalized().XYZ()-Tgsurf.Normalized().XYZ()).SquareModulus()*Norme/64.; |
245 | |
246 | if (FlecheCourante <= 0.25*fleche*fleche) { |
247 | |
248 | return Blend_StepTooSmall; |
249 | } |
250 | if (FlecheCourante > fleche*fleche) { |
251 | // pas trop grand : commentaire interessant |
252 | return Blend_StepTooLarge; |
253 | } |
254 | |
255 | return Blend_OK; |
256 | } |
257 | |
258 | |
259 | |
260 | Blend_Status Blend_CSWalking::CheckDeflectionOnCurv |
261 | (const gp_Pnt& Pcurv, |
262 | const Standard_Real Param, |
263 | const gp_Vec& Tgcurv) |
264 | { |
265 | // regle par tests dans U4 correspond a 11.478 d |
266 | const Standard_Real CosRef3D = 0.98; |
267 | |
268 | Standard_Real Norme, prevNorme, Cosi, Cosi2; // JAG MODIF 25.04.94 |
269 | Standard_Real FlecheCourante; |
270 | Standard_Real Du,paramu,tolu; |
271 | // TColgp_Array1OfPnt Poles(1,4); |
272 | // gp_Pnt POnCurv,Milieu; |
273 | gp_Pnt prevP; |
274 | gp_Vec prevTg; |
275 | |
276 | prevP = previousP.PointOnC(); |
277 | prevTg = previousP.TangentOnC(); |
278 | tolu = TheCurveTool::Resolution(curv,tolesp); |
279 | |
280 | gp_Vec Corde(prevP,Pcurv); |
281 | Norme = Corde.SquareMagnitude(); |
282 | prevNorme = prevTg.SquareMagnitude(); // JAG MODIF 25.04.94 |
283 | |
284 | |
285 | // if (Norme <= tolesp*tolesp || prevNorme <= tolesp*tolesp) { // JAG MODIF 25.04.94 |
286 | if (Norme <= tolesp*tolesp) { // le 95.01.10 |
287 | // il faudra peut etre forcer meme point JAG MODIF 25.04.94 |
288 | return Blend_SamePoints; |
289 | } |
290 | else if (prevNorme > tolesp*tolesp) { |
291 | Cosi = sens*Corde*prevTg; |
292 | if (Cosi <0.) { // angle 3d>pi/2. --> retour arriere |
293 | return Blend_Backward; |
294 | } |
295 | |
296 | Cosi2 = Cosi * Cosi / prevNorme / Norme; |
297 | if (Cosi2 < CosRef3D) { |
298 | return Blend_StepTooLarge; |
299 | } |
300 | } |
301 | |
302 | paramu = previousP.ParameterOnC(); |
303 | Du = Param - paramu; |
304 | if (Abs(Du) < tolu){ |
305 | // il faudra peut etre forcer meme point JAG MODIF 25.04.94 |
306 | return Blend_SamePoints; //point confondu 2d |
307 | } |
308 | |
309 | // Voir s il faut faire le controle sur le signe de prevtg*Tgsurf |
310 | |
311 | if (Tgcurv.Magnitude() <= tolesp) { |
312 | return Blend_SamePoints; // GROS BOBARD EN ATTENDANT |
313 | } |
314 | |
315 | Cosi = sens*Corde*Tgcurv; |
316 | Cosi2 = Cosi * Cosi / Tgcurv.SquareMagnitude() / Norme; |
317 | if (Cosi2 < CosRef3D || Cosi < 0.) { |
318 | return Blend_StepTooLarge; |
319 | } |
320 | |
321 | if (prevNorme > tolesp*tolesp) { |
322 | |
323 | // Estimation de la fleche courante |
324 | /* |
325 | Norme = Sqrt(Norme)/3.; |
326 | Poles(1) = prevP; |
327 | Poles(4) = Pcurv; |
328 | Poles(2) = Poles(1).XYZ() + sens*Norme* prevTg.Normalized().XYZ(); |
329 | Poles(3) = Poles(4).XYZ() - sens*Norme* Tgcurv.Normalized().XYZ(); |
330 | BzCLib::PntPole(0.5,Poles,POnCurv); |
331 | Milieu = (Poles(1).XYZ() + Poles(4).XYZ())*0.5; |
332 | FlecheCourante = Milieu.Distance(POnCurv); |
333 | if (FlecheCourante <= 0.5*fleche) { |
334 | */ |
335 | FlecheCourante = (prevTg.Normalized().XYZ()-Tgcurv.Normalized().XYZ()).SquareModulus()*Norme/64.; |
336 | |
337 | if (FlecheCourante <= 0.25*fleche*fleche) { |
338 | return Blend_StepTooSmall; |
339 | } |
340 | if (FlecheCourante > fleche*fleche) { |
341 | // pas trop grand : commentaire interessant |
342 | return Blend_StepTooLarge; |
343 | } |
344 | } |
345 | return Blend_OK; |
346 | } |
347 | |
348 | |
349 | |
350 | |
351 | |
352 | |