b311480e |
1 | // Created on: 1997-01-24 |
2 | // Created by: Laurent BOURESCHE |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <stdio.h> |
18 | |
19 | #include <BRepBlend_RstRstLineBuilder.ixx> |
20 | #include <BRepBlend_BlendTool.hxx> |
21 | #include <TopAbs.hxx> |
22 | #include <IntSurf.hxx> |
23 | #include <math_FunctionSetRoot.hxx> |
24 | #include <gp_Pnt2d.hxx> |
25 | #include <gp_Pnt.hxx> |
26 | #include <gp_Vec2d.hxx> |
27 | #include <gp_Vec.hxx> |
28 | |
0797d9d3 |
29 | #ifdef OCCT_DEBUG |
7fd59977 |
30 | #include <TColStd_Array1OfInteger.hxx> |
31 | #include <TColStd_Array1OfReal.hxx> |
32 | #include <TColgp_Array1OfPnt2d.hxx> |
33 | #include <TColgp_Array1OfVec.hxx> |
34 | #include <TColgp_Array1OfVec2d.hxx> |
35 | #include <TColgp_Array1OfPnt.hxx> |
36 | #include <Geom_BSplineCurve.hxx> |
37 | #ifdef DRAW |
38 | #include <DrawTrSurf.hxx> |
39 | #endif |
40 | static Standard_Integer IndexOfSection = 0; |
41 | extern Standard_Boolean Blend_GettraceDRAWSECT(); |
42 | |
0797d9d3 |
43 | #ifdef OCCT_DEBUG_BBPP_N_TRDERIV |
7fd59977 |
44 | //----------------------------------------------------- |
81bba717 |
45 | // For debug : visualisation of the section |
7fd59977 |
46 | static Standard_Boolean BBPP(const Standard_Real param, |
47 | Blend_RstRstFunction& Func, |
48 | const math_Vector& sol, |
49 | const Standard_Real tol, |
50 | Blend_Point& BP) |
51 | { |
52 | if(!Func.IsSolution(sol,tol)) return 0; |
53 | gp_Pnt pntrst1 = Func.PointOnRst1(); |
54 | gp_Pnt pntrst2 = Func.PointOnRst2(); |
55 | gp_Pnt2d p2drst1 = Func.Pnt2dOnRst1(); |
56 | gp_Pnt2d p2drst2 = Func.Pnt2dOnRst2(); |
57 | Standard_Real w1 = Func.ParameterOnRst1(); |
58 | Standard_Real w2 = Func.ParameterOnRst2(); |
59 | BP = Blend_Point(pntrst1, pntrst2, param, |
60 | p2drst1.X(), p2drst1.Y(), |
61 | p2drst2.X(), p2drst2.Y(), w1, w2); |
62 | return 1; |
63 | } |
64 | |
65 | |
66 | //----------------------------------------------------- |
67 | static void tracederiv(Blend_RstRstFunction& Func, |
68 | const Blend_Point& BP1, |
69 | const Blend_Point& BP2) |
70 | { |
71 | Standard_Integer hp,hk,hd,hp2d,i; |
72 | Func.GetShape(hp,hk,hd,hp2d); |
73 | TColgp_Array1OfPnt TP1(1,hp); |
74 | TColgp_Array1OfVec TDP1(1,hp); |
75 | TColgp_Array1OfPnt2d TP2d1(1,hp2d); |
76 | TColgp_Array1OfVec2d TDP2d1(1,hp2d); |
77 | TColStd_Array1OfReal TW1(1,hp); |
78 | TColStd_Array1OfReal TDW1(1,hp); |
79 | Func.Section(BP1, TP1,TDP1,TP2d1,TDP2d1,TW1,TDW1); |
80 | |
81 | TColgp_Array1OfPnt TP2(1,hp); |
82 | TColgp_Array1OfVec TDP2(1,hp); |
83 | TColgp_Array1OfPnt2d TP2d2(1,hp2d); |
84 | TColgp_Array1OfVec2d TDP2d2(1,hp2d); |
85 | TColStd_Array1OfReal TW2(1,hp); |
86 | TColStd_Array1OfReal TDW2(1,hp); |
87 | Func.Section(BP2,TP2,TDP2,TP2d2,TDP2d2,TW2,TDW2); |
88 | |
89 | Standard_Real param1 = BP1.Parameter(); |
90 | Standard_Real param2 = BP2.Parameter(); |
91 | Standard_Real scal = 1./ (param1 - param2); |
92 | |
93 | cout<<endl; |
81bba717 |
94 | cout<<"control of derivatives at point : "<<param1<<endl; |
7fd59977 |
95 | |
96 | for(i = 1; i <= hp; i++){ |
97 | cout<<endl; |
98 | cout<<"point : "<<i<<endl; |
81bba717 |
99 | cout<<"dx calculated : "<<TDP1(i).X()<<endl; |
100 | cout<<"dx estimated : "<<scal*(TP1(i).X()-TP2(i).X())<<endl; |
101 | cout<<"dy calculated : "<<TDP1(i).Y()<<endl; |
102 | cout<<"dy estimated : "<<scal*(TP1(i).Y()-TP2(i).Y())<<endl; |
103 | cout<<"dz calculated : "<<TDP1(i).Z()<<endl; |
104 | cout<<"dz estimated : "<<scal*(TP1(i).Z()-TP2(i).Z())<<endl; |
105 | cout<<"dw calculated : "<<TDW1(i)<<endl; |
106 | cout<<"dw estimated : "<<scal*(TW1(i)-TW2(i))<<endl; |
7fd59977 |
107 | } |
108 | for(i = 1; i <= hp2d; i++){ |
109 | cout<<endl; |
110 | cout<<"point 2d : "<<i<<endl; |
81bba717 |
111 | cout<<"dx calculated : "<<TDP2d1(i).X()<<endl; |
112 | cout<<"dx estimated : "<<scal*(TP2d1(i).X()-TP2d2(i).X())<<endl; |
113 | cout<<"dy calculated : "<<TDP2d1(i).Y()<<endl; |
114 | cout<<"dy estimated : "<<scal*(TP2d1(i).Y()-TP2d2(i).Y())<<endl; |
7fd59977 |
115 | } |
116 | } |
4e18e72a |
117 | #endif |
7fd59977 |
118 | |
119 | //----------------------------------------------------- |
120 | static void Drawsect(const Standard_Real param, |
121 | Blend_RstRstFunction& Func) |
122 | { |
123 | gp_Pnt pntrst1 = Func.PointOnRst1(); |
124 | gp_Pnt pntrst2 = Func.PointOnRst2(); |
125 | gp_Pnt2d p2drst1 = Func.Pnt2dOnRst1(); |
126 | gp_Pnt2d p2drst2 = Func.Pnt2dOnRst2(); |
127 | Standard_Real u = Func.ParameterOnRst1(); |
128 | Standard_Real v = Func.ParameterOnRst2(); |
129 | Blend_Point BP(pntrst1, pntrst2, param, |
130 | p2drst1.X(), p2drst1.Y(), |
131 | p2drst2.X(), p2drst2.Y(), u, v); |
132 | Standard_Integer hp,hk,hd,hp2d; |
133 | Func.GetShape(hp,hk,hd,hp2d); |
134 | TColStd_Array1OfReal TK(1,hk); |
135 | Func.Knots(TK); |
136 | TColStd_Array1OfInteger TMul(1,hk); |
137 | Func.Mults(TMul); |
138 | TColgp_Array1OfPnt TP(1,hp); |
139 | TColgp_Array1OfPnt2d TP2d(1,hp2d); |
140 | TColStd_Array1OfReal TW(1,hp); |
141 | Func.Section(BP,TP,TP2d,TW); |
142 | Handle(Geom_BSplineCurve) sect = new Geom_BSplineCurve |
143 | (TP,TW,TK,TMul,hd); |
144 | IndexOfSection++; |
145 | #ifdef DRAW |
146 | char tname[100]; |
147 | Standard_CString name = tname ; |
148 | sprintf(name,"%s_%d","Section",IndexOfSection); |
149 | DrawTrSurf::Set(name,sect); |
150 | #endif |
151 | } |
152 | #endif |
153 | |
154 | //======================================================================= |
155 | //function : BRepBlend_RstRstLineBuilder |
156 | //purpose : |
157 | //======================================================================= |
158 | |
159 | BRepBlend_RstRstLineBuilder::BRepBlend_RstRstLineBuilder |
160 | (const Handle(Adaptor3d_HSurface)& Surf1, |
161 | const Handle(Adaptor2d_HCurve2d)& Rst1, |
162 | const Handle(Adaptor3d_TopolTool)& Domain1, |
163 | const Handle(Adaptor3d_HSurface)& Surf2, |
164 | const Handle(Adaptor2d_HCurve2d)& Rst2, |
165 | const Handle(Adaptor3d_TopolTool)& Domain2): |
166 | sol(1,2), surf1(Surf1), domain1(Domain1), |
167 | surf2(Surf2), domain2(Domain2), rst1(Rst1), rst2(Rst2) |
168 | { |
169 | } |
170 | |
171 | //======================================================================= |
172 | //function : Perform |
81bba717 |
173 | //purpose : launch the processing |
7fd59977 |
174 | //======================================================================= |
175 | |
176 | void BRepBlend_RstRstLineBuilder::Perform(Blend_RstRstFunction& Func, |
177 | Blend_SurfCurvFuncInv& Finv1, |
178 | Blend_CurvPointFuncInv& FinvP1, |
179 | Blend_SurfCurvFuncInv& Finv2, |
180 | Blend_CurvPointFuncInv& FinvP2, |
181 | const Standard_Real Pdep, |
182 | const Standard_Real Pmax, |
183 | const Standard_Real MaxStep, |
184 | const Standard_Real TolGuide, |
185 | const math_Vector& ParDep, |
186 | const Standard_Real Tolesp, |
187 | const Standard_Real Fleche, |
188 | const Standard_Boolean Appro) |
189 | { |
190 | done = Standard_False; |
191 | iscomplete = Standard_False; |
192 | comptra = Standard_False; |
193 | line = new BRepBlend_Line(); |
194 | tolesp = Abs(Tolesp); |
195 | tolgui = Abs(TolGuide); |
196 | fleche = Abs(Fleche); |
197 | rebrou = Standard_False; |
198 | pasmax = Abs(MaxStep); |
199 | |
200 | if (Pmax - Pdep >= 0.) { |
201 | sens = 1.; |
202 | } |
203 | else { |
204 | sens = -1.; |
205 | } |
206 | |
207 | Blend_Status State; |
208 | |
209 | param = Pdep; |
210 | Func.Set(param); |
211 | |
212 | if (Appro) { |
213 | TopAbs_State siturst1, siturst2; |
214 | Blend_DecrochStatus decroch; |
215 | math_Vector tolerance(1, 2), infbound(1, 2), supbound(1, 2); |
216 | Func.GetTolerance(tolerance, tolesp); |
217 | Func.GetBounds(infbound, supbound); |
218 | math_FunctionSetRoot rsnld(Func, tolerance, 30); |
219 | |
220 | rsnld.Perform(Func, ParDep, infbound, supbound); |
221 | |
222 | if (!rsnld.IsDone()) { |
223 | return; |
224 | } |
225 | rsnld.Root(sol); |
226 | if (!CheckInside(Func, siturst1, siturst2, decroch)) { |
227 | return; |
228 | } |
229 | } |
230 | else { |
231 | sol = ParDep; |
232 | } |
233 | |
234 | State = TestArret(Func, Standard_False, Blend_OK); |
235 | if (State != Blend_OK) { |
236 | return; |
237 | } |
0797d9d3 |
238 | #ifdef OCCT_DEBUG |
7fd59977 |
239 | if (Blend_GettraceDRAWSECT()){ |
240 | Drawsect(param, Func); |
241 | } |
242 | #endif |
81bba717 |
243 | // Update the line. |
7fd59977 |
244 | line->Append(previousP); |
245 | Standard_Real U, V; |
246 | U = previousP.ParameterOnC1(); |
247 | V = previousP.ParameterOnC2(); |
248 | BRepBlend_Extremity ptf1 (previousP.PointOnC1(), |
249 | U, previousP.Parameter(),tolesp); |
250 | BRepBlend_Extremity ptf2 (previousP.PointOnC2(), |
251 | V, previousP.Parameter(),tolesp); |
252 | if (!previousP.IsTangencyPoint()) { |
253 | ptf1.SetTangent(previousP.TangentOnC1()); |
254 | ptf2.SetTangent(previousP.TangentOnC2()); |
255 | } |
256 | |
257 | if (sens > 0.) { |
258 | line->SetStartPoints(ptf1, ptf2); |
259 | } |
260 | else { |
261 | line->SetEndPoints(ptf1, ptf2); |
262 | } |
263 | |
264 | InternalPerform(Func, Finv1, FinvP1, Finv2, FinvP2, Pmax); |
265 | done = Standard_True; |
266 | } |
267 | |
268 | //======================================================================= |
269 | //function : PerformFirstSection |
81bba717 |
270 | //purpose : Creation of the first section |
7fd59977 |
271 | //======================================================================= |
272 | |
273 | Standard_Boolean BRepBlend_RstRstLineBuilder::PerformFirstSection |
274 | (Blend_RstRstFunction& Func, |
275 | Blend_SurfCurvFuncInv& Finv1, |
276 | Blend_CurvPointFuncInv& FinvP1, |
277 | Blend_SurfCurvFuncInv& Finv2, |
278 | Blend_CurvPointFuncInv& FinvP2, |
279 | const Standard_Real Pdep, |
280 | const Standard_Real Pmax, |
281 | const math_Vector& ParDep, |
282 | const Standard_Real Tolesp, |
283 | const Standard_Real TolGuide, |
284 | const Standard_Boolean RecRst1, |
285 | const Standard_Boolean RecP1, |
286 | const Standard_Boolean RecRst2, |
287 | const Standard_Boolean RecP2, |
288 | Standard_Real& Psol, |
289 | math_Vector& ParSol) |
290 | { |
291 | done = Standard_False; |
292 | iscomplete = Standard_False; |
293 | comptra = Standard_False; |
294 | line = new BRepBlend_Line(); |
295 | tolesp = Abs(Tolesp); |
296 | tolgui = Abs(TolGuide); |
297 | rebrou = Standard_False; |
298 | |
299 | if (Pmax - Pdep >= 0.) { |
300 | sens = 1.; |
301 | } |
302 | else { |
303 | sens = -1.; |
304 | } |
305 | |
306 | Standard_Boolean recadp1, recadp2, recadrst1, recadrst2; |
307 | Standard_Real wp1, wp2, wrst1, wrst2; |
7fd59977 |
308 | Blend_Status State = Blend_OnRst12; |
309 | Standard_Real trst11 = 0., trst12 = 0., trst21 = 0., trst22 = 0.; |
7fd59977 |
310 | math_Vector infbound(1, 2), supbound(1, 2), tolerance(1, 2); |
311 | math_Vector solinvp1(1, 2), solinvp2(1, 2), solinvrst1(1, 3), solinvrst2(1, 3); |
312 | Handle(Adaptor3d_HVertex) Vtxp1, Vtxp2, Vtxrst1, Vtxrst2, Vtxc; |
313 | Standard_Boolean IsVtxp1 = 0, IsVtxp2 = 0, IsVtxrst1 = 0, IsVtxrst2 = 0; |
314 | Handle(Adaptor2d_HCurve2d) Arc; |
315 | wp1 = wp2 = wrst1 = wrst2 = Pmax; |
316 | param = Pdep; |
317 | Func.Set(param); |
318 | Func.GetTolerance(tolerance, tolesp); |
319 | Func.GetBounds(infbound, supbound); |
320 | |
321 | math_FunctionSetRoot rsnld(Func, tolerance, 30); |
322 | rsnld.Perform(Func, ParDep, infbound, supbound); |
323 | if (!rsnld.IsDone()) return Standard_False; |
324 | rsnld.Root(sol); |
325 | |
326 | recadrst1 = RecRst1 && Recadre1(Func, Finv1, solinvrst1, IsVtxrst1, Vtxrst1); |
327 | if (recadrst1) { |
328 | wrst1 = solinvrst1(1); |
329 | } |
330 | |
331 | recadp1 = RecP1 && Recadre1(FinvP1, solinvp1, IsVtxp1, Vtxp1); |
332 | if (recadp1) { |
333 | wp1 = solinvp1(1); |
334 | } |
335 | |
336 | recadrst2 = RecRst2 && Recadre2(Func, Finv2, solinvrst2, IsVtxrst2, Vtxrst2); |
337 | if (recadrst2) { |
338 | wrst2 = solinvrst2(1); |
339 | } |
340 | |
341 | recadp2 = RecP2 && Recadre2(FinvP2, solinvp2, IsVtxp2, Vtxp2); |
342 | if (recadp2) { |
343 | wp2 = solinvp2(1); |
344 | } |
345 | |
346 | if (!recadrst1 && !recadp1 && !recadrst2 && !recadp2) return Standard_False; |
347 | |
348 | |
81bba717 |
349 | // it is checked if the contact was lost or domain 1 was left |
7fd59977 |
350 | if (recadp1 && recadrst1) { |
81bba717 |
351 | if (sens * (wrst1 - wp1) > tolgui){ //at first one leaves the domain |
7fd59977 |
352 | wrst1 = wp1; |
353 | trst12 = solinvp1(2); |
354 | trst11 = BRepBlend_BlendTool::Parameter(Vtxp1, rst1); |
355 | IsVtxrst2 = IsVtxp1; |
356 | Vtxrst2 = Vtxp1; |
357 | recadrst1 = Standard_False; |
358 | } |
81bba717 |
359 | else { // the contact is lost |
7fd59977 |
360 | trst11 = solinvrst1(3); |
361 | trst12 = solinvrst1(2); |
362 | recadp1 = Standard_False; |
363 | } |
364 | } |
365 | else if (recadp1) { |
366 | wrst1 = wp1; |
367 | trst12 = solinvp1(2); |
368 | trst11 = BRepBlend_BlendTool::Parameter(Vtxp1, rst1); |
369 | IsVtxrst1 = IsVtxp1; |
370 | Vtxrst1 = Vtxp1; |
371 | } |
372 | else if (recadrst1) { |
373 | trst11 = solinvrst1(3); |
374 | trst12 = solinvrst1(2); |
375 | } |
376 | |
81bba717 |
377 | // it is checked if the contact was lost or domain 2 was left |
7fd59977 |
378 | if (recadp2 && recadrst2) { |
81bba717 |
379 | if (sens * (wrst2 - wp2) > tolgui) { //at first one leaves the domain |
7fd59977 |
380 | wrst2 = wp2; |
381 | trst21 = solinvp2(2); |
382 | trst22 = BRepBlend_BlendTool::Parameter(Vtxp2, rst2); |
383 | IsVtxrst2 = IsVtxp2; |
384 | Vtxrst2 = Vtxp2; |
385 | recadrst2 = Standard_False; |
386 | } |
387 | else { |
388 | trst22 = solinvrst2(3); |
389 | trst21 = solinvrst2(2); |
390 | recadp2 = Standard_False; |
391 | } |
392 | } |
393 | else if (recadp2) { |
394 | wrst2 = wp2; |
395 | trst21 = solinvp2(2); |
396 | trst22 = BRepBlend_BlendTool::Parameter(Vtxp2, rst2); |
397 | IsVtxrst2 = IsVtxp2; |
398 | Vtxrst2 = Vtxp2; |
399 | } |
400 | else if (recadrst2) { |
401 | trst22 = solinvrst2(3); |
402 | trst21 = solinvrst2(2); |
403 | } |
404 | |
81bba717 |
405 | // it is checked on which curve the contact is lost earlier |
7fd59977 |
406 | if (recadrst1 && recadrst2) { |
407 | if (Abs(wrst1 - wrst2) < tolgui) { |
408 | State = Blend_OnRst12; |
409 | param = 0.5 * (wrst1 + wrst2); |
410 | sol(1) = trst11; |
411 | sol(2) = trst22; |
412 | } |
413 | else if (sens * (wrst1 - wrst2) < 0) { |
81bba717 |
414 | // contact lost on Rst1 |
7fd59977 |
415 | State = Blend_OnRst1; |
416 | param = wrst1; |
417 | sol(1) = trst11; |
418 | sol(2) = trst12; |
419 | } |
420 | else { |
81bba717 |
421 | // contact lost on rst2 |
7fd59977 |
422 | State = Blend_OnRst2; |
423 | param = wrst2; |
424 | sol(1) = trst21; |
425 | sol(2) = trst22; |
426 | } |
427 | Func.Set(param); |
428 | } |
429 | else if (recadrst1) { |
81bba717 |
430 | // ground on rst1 |
7fd59977 |
431 | State = Blend_OnRst1; |
432 | param = wrst1; |
433 | sol(1) = trst11; |
434 | sol(2) = trst12; |
435 | Func.Set(param); |
436 | } |
437 | else if (recadrst2) { |
81bba717 |
438 | // ground on rst2 |
7fd59977 |
439 | State = Blend_OnRst2; |
440 | param = wrst2; |
441 | sol(1) = trst21; |
442 | sol(2) = trst22; |
443 | Func.Set(param); |
444 | } |
81bba717 |
445 | // it is checked on which curves one leaves first |
7fd59977 |
446 | else if (recadp1 && recadp2) { |
447 | if (Abs(wrst1 - wrst2) < tolgui) { |
448 | State = Blend_OnRst12; |
449 | param = 0.5 * (wrst1 + wrst2); |
450 | sol(1) = trst11; |
451 | sol(2) = trst22; |
452 | } |
453 | else if (sens * (wrst1 - wrst2) < 0) { |
81bba717 |
454 | // sol on Rst1 |
7fd59977 |
455 | State = Blend_OnRst1; |
456 | param = wrst1; |
457 | sol(1) = trst11; |
458 | sol(2) = trst12; |
459 | } |
460 | else { |
81bba717 |
461 | // ground on rst2 |
7fd59977 |
462 | State = Blend_OnRst2; |
463 | param = wrst2; |
464 | sol(1) = trst21; |
465 | sol(2) = trst22; |
466 | } |
467 | Func.Set(param); |
468 | } |
469 | else if (recadp1) { |
81bba717 |
470 | // ground on rst1 |
7fd59977 |
471 | State = Blend_OnRst1; |
472 | param = wrst1; |
473 | sol(1) = trst11; |
474 | sol(2) = trst12; |
475 | Func.Set(param); |
476 | } |
477 | else if (recadp2) { |
81bba717 |
478 | // ground on rst2 |
7fd59977 |
479 | State = Blend_OnRst2; |
480 | param = wrst2; |
481 | sol(1) = trst21; |
482 | sol(2) = trst22; |
483 | Func.Set(param); |
484 | } |
485 | |
486 | State = TestArret(Func, Standard_False, State); |
487 | Psol = param; |
488 | ParSol = sol; |
489 | return Standard_True; |
490 | } |
491 | |
492 | //======================================================================= |
493 | //function : Complete |
494 | //purpose : |
495 | //======================================================================= |
496 | |
497 | Standard_Boolean BRepBlend_RstRstLineBuilder::Complete(Blend_RstRstFunction& Func, |
498 | Blend_SurfCurvFuncInv& Finv1, |
499 | Blend_CurvPointFuncInv& FinvP1, |
500 | Blend_SurfCurvFuncInv& Finv2, |
501 | Blend_CurvPointFuncInv& FinvP2, |
502 | const Standard_Real Pmin) |
503 | { |
504 | if (!done) {StdFail_NotDone::Raise();} |
505 | if (iscomplete) {return Standard_True;} |
506 | if (sens >0.) { |
507 | previousP = line->Point(1); |
508 | } |
509 | else { |
510 | previousP = line->Point(line->NbPoints()); |
511 | } |
512 | sens = -sens; |
513 | param = previousP.Parameter(); |
514 | sol(1) = previousP.ParameterOnC1(); |
515 | sol(2) = previousP.ParameterOnC2(); |
516 | |
517 | InternalPerform(Func, Finv1, FinvP1, Finv2, FinvP2, Pmin); |
518 | iscomplete = Standard_True; |
519 | return Standard_True; |
520 | } |
521 | |
522 | //======================================================================= |
523 | //function : InternalPerform |
81bba717 |
524 | //purpose : algorithm of processing without extremities |
7fd59977 |
525 | //======================================================================= |
526 | |
527 | void BRepBlend_RstRstLineBuilder::InternalPerform(Blend_RstRstFunction& Func, |
528 | Blend_SurfCurvFuncInv& Finv1, |
529 | Blend_CurvPointFuncInv& FinvP1, |
530 | Blend_SurfCurvFuncInv& Finv2, |
531 | Blend_CurvPointFuncInv& FinvP2, |
532 | const Standard_Real Bound) |
533 | { |
534 | Standard_Real stepw = pasmax; |
535 | Standard_Integer nbp = line->NbPoints(); |
81bba717 |
536 | if(nbp >= 2){ //The last step is redone if it is not too small. |
7fd59977 |
537 | if(sens < 0.){ |
538 | stepw = (line->Point(2).Parameter() - line->Point(1).Parameter()); |
539 | } |
540 | else{ |
541 | stepw = (line->Point(nbp).Parameter() - line->Point(nbp - 1).Parameter()); |
542 | } |
543 | stepw = Max(stepw, 100. * tolgui); |
544 | } |
545 | Standard_Real parprec = param; |
546 | if (sens* (parprec - Bound) >= -tolgui) { |
547 | return; |
548 | } |
7fd59977 |
549 | Blend_Status State = Blend_OnRst12; |
550 | Standard_Real trst11 = 0., trst12 = 0., trst21 = 0., trst22 = 0.; |
1d47d8d0 |
551 | TopAbs_State situonc1 = TopAbs_UNKNOWN, situonc2 = TopAbs_UNKNOWN; |
552 | Blend_DecrochStatus decroch = Blend_NoDecroch; |
7fd59977 |
553 | Standard_Boolean Arrive, recadp1, recadp2, recadrst1, recadrst2, echecrecad; |
554 | Standard_Real wp1, wp2, wrst1, wrst2; |
555 | math_Vector infbound(1, 2), supbound(1, 2); |
556 | math_Vector parinit(1, 2), tolerance(1, 2); |
557 | math_Vector solinvp1(1, 2), solinvp2(1, 2), solinvrst1(1, 3), solinvrst2(1, 3); |
558 | Handle(Adaptor3d_HVertex) Vtxp1, Vtxp2, Vtxrst1, Vtxrst2; |
559 | Standard_Boolean IsVtxp1 = 0, IsVtxp2 = 0, IsVtxrst1 = 0, IsVtxrst2 = 0; |
560 | BRepBlend_Extremity Extrst1, Extrst2; |
561 | |
562 | //IntSurf_Transition Tline, Tarc; |
563 | |
564 | Func.GetTolerance(tolerance, tolesp); |
565 | Func.GetBounds(infbound, supbound); |
566 | |
567 | math_FunctionSetRoot rsnld(Func, tolerance, 30); |
568 | parinit = sol; |
569 | |
570 | Arrive = Standard_False; |
571 | param = parprec + sens * stepw; |
572 | if (sens * (param - Bound) > 0.) { |
573 | stepw = sens * (Bound - parprec) * 0.5; |
574 | param = parprec + sens * stepw; |
575 | } |
576 | |
577 | while (!Arrive) { |
578 | Standard_Boolean bonpoint = 1; |
0797d9d3 |
579 | #ifdef OCCT_DEBUG_BBPP_N_TRDERIV |
7fd59977 |
580 | //debdebdebdebdebdeb |
581 | Func.Set(param); |
582 | rsnld.Perform(Func, parinit, infbound, supbound); |
583 | if (rsnld.IsDone()) { |
584 | rsnld.Root(sol); |
585 | Blend_Point bp1; |
586 | if(BBPP(param, Func, sol, tolesp, bp1)){ |
587 | Standard_Real dw = 1.e-10; |
588 | Func.Set(param + dw); |
589 | rsnld.Perform(Func, parinit, infbound, supbound); |
590 | if (rsnld.IsDone()) { |
591 | rsnld.Root(sol); |
592 | Blend_Point bp2; |
593 | if(BBPP(param + dw, Func, sol, tolesp, bp2)){ |
594 | tracederiv(Func, bp1, bp2); |
595 | } |
596 | } |
597 | } |
598 | } |
599 | //debdebdebdebdebdeb |
600 | #endif |
601 | Func.Set(param); |
602 | rsnld.Perform(Func, parinit, infbound, supbound); |
603 | |
604 | if (rsnld.IsDone()) { |
605 | rsnld.Root(sol); |
606 | if(!CheckInside(Func, situonc1, situonc2, decroch) && line->NbPoints() == 1){ |
607 | State = Blend_StepTooLarge; |
608 | bonpoint = 0; |
609 | } |
610 | } |
611 | else { |
612 | State = Blend_StepTooLarge; |
613 | bonpoint = 0; |
614 | } |
615 | if(bonpoint){ |
616 | wp1 = wp2 = wrst1 = wrst2 = Bound; |
617 | recadp1 = recadp2 = recadrst1 = recadrst2 = Standard_False; |
618 | echecrecad = Standard_False; |
619 | if (situonc1 != TopAbs_IN) { |
81bba717 |
620 | // pb inversion rst/rst |
7fd59977 |
621 | recadp1 = Recadre1(FinvP1, solinvp1, IsVtxp1, Vtxp1); |
622 | if (recadp1) { |
623 | wp1 = solinvp1(1); |
624 | } |
625 | else { |
626 | echecrecad = Standard_True; |
627 | } |
628 | } |
629 | |
630 | if (situonc2 != TopAbs_IN) { |
81bba717 |
631 | // pb inversion point/surf |
7fd59977 |
632 | recadp2 = Recadre2(FinvP2, solinvp2, IsVtxp2, Vtxp2); |
633 | if (recadp2) { |
634 | wp2 = solinvp2(1); |
635 | } |
636 | else { |
637 | echecrecad = Standard_True; |
638 | } |
639 | } |
640 | |
641 | if (decroch == Blend_DecrochRst1 || decroch == Blend_DecrochBoth) { |
81bba717 |
642 | // pb inversion rst1/surf1 |
7fd59977 |
643 | recadrst1 = Recadre1(Func, Finv1, solinvrst1, IsVtxrst1, Vtxrst1); |
644 | if (recadrst1) { |
645 | wrst1 = solinvrst1(1); |
646 | } |
647 | else { |
648 | echecrecad = Standard_True; |
649 | } |
650 | } |
651 | |
652 | if (decroch == Blend_DecrochRst2 || decroch == Blend_DecrochBoth) { |
653 | // pb inverse rst2/surf2 |
654 | recadrst2 = Recadre2(Func, Finv2, solinvrst2, IsVtxrst2, Vtxrst2); |
655 | if (recadrst2) { |
656 | wrst2 = solinvrst2(1); |
657 | } |
658 | else { |
659 | echecrecad = Standard_True; |
660 | } |
661 | } |
662 | |
663 | decroch = Blend_NoDecroch; |
664 | if (recadp1 || recadp2 || recadrst1 || recadrst2) echecrecad = Standard_False; |
665 | |
666 | if (!echecrecad) { |
81bba717 |
667 | // it is checked if the contact was lost or domain 1 was left |
7fd59977 |
668 | if (recadp1 && recadrst1) { |
81bba717 |
669 | if (sens * (wrst1 - wp1) > tolgui){ //first one leaves the domain |
7fd59977 |
670 | wrst1 = wp1; |
671 | trst12 = solinvp1(2); |
672 | trst11 = BRepBlend_BlendTool::Parameter(Vtxp1, rst1); |
673 | IsVtxrst2 = IsVtxp1; |
674 | Vtxrst2 = Vtxp1; |
675 | recadrst1 = Standard_False; |
676 | } |
81bba717 |
677 | else { // contact is lost |
7fd59977 |
678 | trst11 = solinvrst1(3); |
679 | trst12 = solinvrst1(2); |
680 | recadp1 = Standard_False; |
681 | } |
682 | } |
683 | else if (recadp1) { |
684 | wrst1 = wp1; |
685 | trst12 = solinvp1(2); |
686 | trst11 = BRepBlend_BlendTool::Parameter(Vtxp1, rst1); |
687 | IsVtxrst1 = IsVtxp1; |
688 | Vtxrst1 = Vtxp1; |
689 | } |
690 | else if (recadrst1) { |
691 | trst11 = solinvrst1(3); |
692 | trst12 = solinvrst1(2); |
693 | } |
694 | |
81bba717 |
695 | // it is checked if the contact was lost or domain 2 was left |
7fd59977 |
696 | if (recadp2 && recadrst2) { |
81bba717 |
697 | if (sens * (wrst2 - wp2) > tolgui) { //first one leaves the domain |
7fd59977 |
698 | wrst2 = wp2; |
699 | trst21 = solinvp2(2); |
700 | trst22 = BRepBlend_BlendTool::Parameter(Vtxp2, rst2); |
701 | IsVtxrst2 = IsVtxp2; |
702 | Vtxrst2 = Vtxp2; |
703 | recadrst2 = Standard_False; |
704 | } |
705 | else { |
706 | trst22 = solinvrst2(3); |
707 | trst21 = solinvrst2(2); |
708 | recadp2 = Standard_False; |
709 | } |
710 | } |
711 | else if (recadp2) { |
712 | wrst2 = wp2; |
713 | trst21 = solinvp2(2); |
714 | trst22 = BRepBlend_BlendTool::Parameter(Vtxp2, rst2); |
715 | IsVtxrst2 = IsVtxp2; |
716 | Vtxrst2 = Vtxp2; |
717 | } |
718 | else if (recadrst2) { |
719 | trst22 = solinvrst2(3); |
720 | trst21 = solinvrst2(2); |
721 | } |
722 | |
81bba717 |
723 | // it is checked on which curve the contact is lost earlier |
7fd59977 |
724 | if (recadrst1 && recadrst2) { |
725 | if (Abs(wrst1 - wrst2) < tolgui) { |
726 | State = Blend_OnRst12; |
727 | decroch = Blend_DecrochBoth; |
728 | param = 0.5 * (wrst1 + wrst2); |
729 | sol(1) = trst11; |
730 | sol(2) = trst22; |
731 | } |
732 | else if (sens * (wrst1 - wrst2) < 0) { |
81bba717 |
733 | // contact is lost on Rst1 |
7fd59977 |
734 | State = Blend_OnRst1; |
735 | decroch = Blend_DecrochRst1; |
736 | param = wrst1; |
737 | sol(1) = trst11; |
738 | sol(2) = trst12; |
739 | } |
740 | else { |
81bba717 |
741 | // contact is lost on rst2 |
7fd59977 |
742 | State = Blend_OnRst2; |
743 | decroch = Blend_DecrochRst2; |
744 | param = wrst2; |
745 | sol(1) = trst21; |
746 | sol(2) = trst22; |
747 | } |
748 | Func.Set(param); |
749 | } |
750 | else if (recadrst1) { |
81bba717 |
751 | // ground on rst1 |
7fd59977 |
752 | State = Blend_OnRst1; |
753 | decroch = Blend_DecrochRst1; |
754 | param = wrst1; |
755 | sol(1) = trst11; |
756 | sol(2) = trst12; |
757 | Func.Set(param); |
758 | } |
759 | else if (recadrst2) { |
81bba717 |
760 | // ground on rst2 |
7fd59977 |
761 | State = Blend_OnRst2; |
762 | decroch = Blend_DecrochRst2; |
763 | param = wrst2; |
764 | sol(1) = trst21; |
765 | sol(2) = trst22; |
766 | Func.Set(param); |
767 | } |
81bba717 |
768 | // it is checked on which curve the contact is lost earlier |
7fd59977 |
769 | else if (recadp1 && recadp2) { |
770 | if (Abs(wrst1 - wrst2) < tolgui) { |
771 | State = Blend_OnRst12; |
772 | param = 0.5 * (wrst1 + wrst2); |
773 | sol(1) = trst11; |
774 | sol(2) = trst22; |
775 | } |
776 | else if (sens * (wrst1 - wrst2) < 0) { |
81bba717 |
777 | // ground on Rst1 |
7fd59977 |
778 | State = Blend_OnRst1; |
779 | param = wrst1; |
780 | sol(1) = trst11; |
781 | sol(2) = trst12; |
782 | } |
783 | else { |
81bba717 |
784 | // ground on rst2 |
7fd59977 |
785 | State = Blend_OnRst2; |
786 | param = wrst2; |
787 | sol(1) = trst21; |
788 | sol(2) = trst22; |
789 | } |
790 | Func.Set(param); |
791 | } |
792 | else if (recadp1) { |
81bba717 |
793 | // ground on rst1 |
7fd59977 |
794 | State = Blend_OnRst1; |
795 | param = wrst1; |
796 | sol(1) = trst11; |
797 | sol(2) = trst12; |
798 | Func.Set(param); |
799 | } |
800 | else if (recadp2) { |
81bba717 |
801 | // ground on rst2 |
7fd59977 |
802 | State = Blend_OnRst2; |
803 | param = wrst2; |
804 | sol(1) = trst21; |
805 | sol(2) = trst22; |
806 | Func.Set(param); |
807 | } |
808 | else { |
809 | State = Blend_OK; |
810 | } |
811 | |
812 | State = TestArret(Func, Standard_True, State); |
813 | } |
814 | else{ |
81bba717 |
815 | // reframing failed. Leave with PointsConfondus |
0797d9d3 |
816 | #ifdef OCCT_DEBUG |
81bba717 |
817 | cout<<"reframing failed"<<endl; |
aefdc31b |
818 | #endif |
7fd59977 |
819 | State = Blend_SamePoints; |
820 | } |
821 | } |
822 | |
823 | switch (State) { |
824 | case Blend_OK : |
825 | { |
0797d9d3 |
826 | #ifdef OCCT_DEBUG |
7fd59977 |
827 | if (Blend_GettraceDRAWSECT()){ |
828 | Drawsect(param, Func); |
829 | } |
830 | #endif |
81bba717 |
831 | // Update the line. |
7fd59977 |
832 | if (sens > 0.) { |
833 | line->Append(previousP); |
834 | } |
835 | else { |
836 | line->Prepend(previousP); |
837 | } |
838 | parinit = sol; |
839 | parprec = param; |
840 | |
841 | if (param == Bound) { |
842 | Arrive = Standard_True; |
843 | Extrst1.SetValue(previousP.PointOnC1(), |
844 | previousP.ParameterOnC1(), |
845 | previousP.Parameter(), tolesp); |
846 | MakeExtremity(Extrst2, Standard_False, rst2, sol(2), IsVtxrst2, Vtxrst2); |
81bba717 |
847 | // Show that end is on Bound. |
7fd59977 |
848 | } |
849 | else { |
850 | param = param + sens * stepw; |
851 | if (sens * (param - Bound) > - tolgui) { |
852 | param = Bound; |
853 | } |
854 | } |
855 | } |
856 | break; |
857 | |
858 | case Blend_StepTooLarge : |
859 | { |
860 | stepw = stepw / 2.; |
861 | if (Abs(stepw) < tolgui) { |
862 | Extrst1.SetValue(previousP.PointOnC1(), |
863 | previousP.ParameterOnC1(), |
864 | previousP.Parameter(), tolesp); |
865 | Extrst2.SetValue(previousP.PointOnC2(), |
866 | previousP.ParameterOnC2(), |
867 | previousP.Parameter(), tolesp); |
868 | Arrive = Standard_True; |
0797d9d3 |
869 | #ifdef OCCT_DEBUG |
7fd59977 |
870 | if (line->NbPoints()>=2) { |
81bba717 |
871 | // Show that there is a stop during processing |
872 | cout<<"No more advancement in the processing"<<endl; |
7fd59977 |
873 | } |
aefdc31b |
874 | #endif |
7fd59977 |
875 | } |
876 | else { |
81bba717 |
877 | param = parprec + sens * stepw; // there is no risk to exceed Bound. |
7fd59977 |
878 | } |
879 | } |
880 | break; |
881 | |
882 | case Blend_StepTooSmall : |
883 | { |
0797d9d3 |
884 | #ifdef OCCT_DEBUG |
7fd59977 |
885 | if (Blend_GettraceDRAWSECT()){ |
886 | Drawsect(param,Func); |
887 | } |
888 | #endif |
81bba717 |
889 | // Update the line. |
7fd59977 |
890 | if (sens > 0.) { |
891 | line->Append(previousP); |
892 | } |
893 | else { |
894 | line->Prepend(previousP); |
895 | } |
896 | parinit = sol; |
897 | parprec = param; |
898 | |
899 | stepw = Min(1.5 * stepw, pasmax); |
900 | if (param == Bound) { |
901 | Arrive = Standard_True; |
902 | Extrst1.SetValue(previousP.PointOnC1(), |
903 | previousP.ParameterOnC1(), |
904 | previousP.Parameter(), tolesp); |
905 | MakeExtremity(Extrst2, Standard_False, rst2, sol(2), IsVtxrst2, Vtxrst2); |
81bba717 |
906 | // Indicate that end is on Bound. |
7fd59977 |
907 | } |
908 | else { |
909 | param = param + sens * stepw; |
910 | if (sens * (param - Bound) > - tolgui) { |
911 | param = Bound; |
912 | } |
913 | } |
914 | } |
915 | break; |
916 | |
917 | case Blend_OnRst1 : |
918 | { |
0797d9d3 |
919 | #ifdef OCCT_DEBUG |
7fd59977 |
920 | if (Blend_GettraceDRAWSECT()){ |
921 | Drawsect(param, Func); |
922 | } |
923 | #endif |
924 | if (sens > 0.) { |
925 | line->Append(previousP); |
926 | } |
927 | else { |
928 | line->Prepend(previousP); |
929 | } |
930 | MakeExtremity(Extrst1, Standard_True, rst1, sol(1), IsVtxrst1, Vtxrst1); |
931 | MakeExtremity(Extrst2, Standard_False, rst2, sol(2), IsVtxrst2, Vtxrst2); |
932 | Arrive = Standard_True; |
933 | } |
934 | break; |
935 | |
936 | case Blend_OnRst2 : |
937 | { |
0797d9d3 |
938 | #ifdef OCCT_DEBUG |
7fd59977 |
939 | if (Blend_GettraceDRAWSECT()){ |
940 | Drawsect(param, Func); |
941 | } |
942 | #endif |
943 | if (sens>0.) { |
944 | line->Append(previousP); |
945 | } |
946 | else { |
947 | line->Prepend(previousP); |
948 | } |
949 | |
950 | MakeExtremity(Extrst1, Standard_True, rst1, sol(1), IsVtxrst1, Vtxrst1); |
951 | MakeExtremity(Extrst2, Standard_False, rst2, sol(2), IsVtxrst2, Vtxrst2); |
952 | Arrive = Standard_True; |
953 | } |
954 | break; |
955 | |
956 | case Blend_OnRst12 : |
957 | { |
0797d9d3 |
958 | #ifdef OCCT_DEBUG |
7fd59977 |
959 | if (Blend_GettraceDRAWSECT()){ |
960 | Drawsect(param, Func); |
961 | } |
962 | #endif |
963 | if (sens > 0.) { |
964 | line->Append(previousP); |
965 | } |
966 | else { |
967 | line->Prepend(previousP); |
968 | } |
969 | |
970 | MakeExtremity(Extrst1, Standard_True, rst1, sol(1), IsVtxrst1, Vtxrst1); |
971 | MakeExtremity(Extrst2, Standard_False, rst2, sol(2), IsVtxrst2, Vtxrst2); |
972 | Arrive = Standard_True; |
973 | } |
974 | break; |
975 | |
976 | case Blend_SamePoints : |
977 | { |
81bba717 |
978 | // Stop |
0797d9d3 |
979 | #ifdef OCCT_DEBUG |
81bba717 |
980 | cout << " Mixed points in the processing" << endl; |
aefdc31b |
981 | #endif |
7fd59977 |
982 | Extrst1.SetValue(previousP.PointOnC1(), |
983 | previousP.ParameterOnC1(), |
984 | previousP.Parameter(), tolesp); |
985 | Extrst2.SetValue(previousP.PointOnC2(), |
986 | previousP.ParameterOnC2(), |
987 | previousP.Parameter(), tolesp); |
988 | Arrive = Standard_True; |
989 | } |
990 | break; |
7fd59977 |
991 | default: |
992 | break; |
7fd59977 |
993 | } |
994 | if (Arrive) { |
995 | if (sens > 0.) { |
996 | line->SetEndPoints(Extrst1, Extrst2); |
997 | decrochfin = decroch; |
998 | } |
999 | else { |
1000 | line->SetStartPoints(Extrst1, Extrst2); |
1001 | decrochdeb = decroch; |
1002 | } |
1003 | } |
1004 | } |
1005 | } |
1006 | |
1007 | |
1008 | //======================================================================= |
1009 | //function : Recadre1 |
81bba717 |
1010 | //purpose : Contact lost on 1 |
7fd59977 |
1011 | //======================================================================= |
1012 | |
1013 | Standard_Boolean BRepBlend_RstRstLineBuilder::Recadre1(Blend_RstRstFunction& Func, |
1014 | Blend_SurfCurvFuncInv& Finv, |
1015 | math_Vector& Solinv, |
1016 | Standard_Boolean& IsVtx, |
1017 | Handle(Adaptor3d_HVertex)& Vtx) |
1018 | { |
1019 | math_Vector toler(1, 3), infb(1, 3), supb(1, 3); |
1020 | Finv.GetTolerance(toler, tolesp); |
1021 | Finv.GetBounds(infb, supb); |
1022 | Solinv(1) = param; |
1023 | Solinv(2) = sol(2); |
1024 | Solinv(3) = sol(1); |
1025 | |
81bba717 |
1026 | // The point where contact is not lost is found |
7fd59977 |
1027 | math_FunctionSetRoot rsnld(Finv, toler, 30); |
1028 | rsnld.Perform(Finv, Solinv, infb, supb); |
1029 | if (!rsnld.IsDone()) { |
0797d9d3 |
1030 | #ifdef OCCT_DEBUG |
7fd59977 |
1031 | cout << "RSNLD not done "<< endl << endl; |
aefdc31b |
1032 | #endif |
7fd59977 |
1033 | return Standard_False; |
1034 | } |
1035 | |
1036 | rsnld.Root(Solinv); |
1037 | |
81bba717 |
1038 | // It is necessary to check if the function value meets the |
1039 | // second restriction |
7fd59977 |
1040 | if (Finv.IsSolution(Solinv, tolesp)) { |
1041 | Standard_Real w = Solinv(2); |
1042 | if(w < rst2->FirstParameter() - toler(2)|| |
1043 | w > rst2->LastParameter() + toler(2)){ |
1044 | return Standard_False; |
1045 | } |
1046 | |
81bba717 |
1047 | // it is checked if it is on a Vertex |
7fd59977 |
1048 | domain1->Initialize(rst1); |
1049 | domain1->InitVertexIterator(); |
1050 | IsVtx = !domain1->MoreVertex(); |
1051 | while (!IsVtx) { |
1052 | Vtx = domain1->Vertex(); |
1053 | if (Abs(BRepBlend_BlendTool::Parameter(Vtx, rst1)-Solinv(3)) <= |
1054 | BRepBlend_BlendTool::Tolerance(Vtx, rst1)) { |
1055 | IsVtx = Standard_True; |
1056 | } |
1057 | else { |
1058 | domain1->NextVertex(); |
1059 | IsVtx = !domain1->MoreVertex(); |
1060 | } |
1061 | } |
1062 | if (!domain1->MoreVertex()) { |
1063 | IsVtx = Standard_False; |
1064 | } |
81bba717 |
1065 | // The section is recalculated by direct solution, otherwise return |
1066 | // incoherences between the parameter and the ground caused by yawn. |
7fd59977 |
1067 | |
1068 | math_Vector infbound(1, 2), supbound(1, 2); |
1069 | math_Vector parinit(1, 2), tolerance(1, 2); |
1070 | Func.GetTolerance(tolerance, tolesp); |
1071 | Func.GetBounds(infbound, supbound); |
1072 | |
1073 | math_FunctionSetRoot rsnld2(Func, tolerance, 30); |
1074 | parinit(1) = Solinv(3); |
1075 | parinit(2) = Solinv(2); |
1076 | Func.Set(Solinv(1)); |
1077 | rsnld2.Perform(Func, parinit, infbound, supbound); |
1078 | if(!rsnld2.IsDone()) return Standard_False; |
1079 | rsnld2.Root(parinit); |
1080 | Solinv(2) = parinit(2); |
1081 | Solinv(3) = parinit(1); |
1082 | return Standard_True; |
1083 | } |
1084 | return Standard_False; |
1085 | } |
1086 | |
1087 | |
1088 | |
1089 | |
1090 | |
1091 | //======================================================================= |
1092 | //function : Recadre2 |
81bba717 |
1093 | //purpose : Contact lost on Rst2 |
7fd59977 |
1094 | //======================================================================= |
1095 | |
1096 | Standard_Boolean BRepBlend_RstRstLineBuilder::Recadre2(Blend_RstRstFunction& Func, |
1097 | Blend_SurfCurvFuncInv& Finv, |
1098 | math_Vector& Solinv, |
1099 | Standard_Boolean& IsVtx, |
1100 | Handle(Adaptor3d_HVertex)& Vtx) |
1101 | { |
1102 | math_Vector toler(1, 3), infb(1, 3), supb(1, 3); |
1103 | Finv.GetTolerance(toler, tolesp); |
1104 | Finv.GetBounds(infb, supb); |
1105 | Solinv(1) = param; |
1106 | Solinv(2) = sol(1); |
1107 | Solinv(3) = sol(2); |
1108 | |
1109 | math_FunctionSetRoot rsnld(Finv, toler, 30); |
1110 | rsnld.Perform(Finv, Solinv, infb, supb); |
1111 | if (!rsnld.IsDone()) { |
0797d9d3 |
1112 | #ifdef OCCT_DEBUG |
7fd59977 |
1113 | cout << "RSNLD not done "<< endl << endl; |
aefdc31b |
1114 | #endif |
7fd59977 |
1115 | return Standard_False; |
1116 | } |
1117 | |
1118 | rsnld.Root(Solinv); |
1119 | |
81bba717 |
1120 | // It is necessary to check the value of the function |
7fd59977 |
1121 | if (Finv.IsSolution(Solinv, tolesp)) { |
1122 | Standard_Real w = Solinv(2); |
1123 | if(w < rst1->FirstParameter() - toler(2)|| |
1124 | w > rst1->LastParameter() + toler(2)){ |
1125 | return Standard_False; |
1126 | } |
1127 | |
1128 | domain2->Initialize(rst2); |
1129 | domain2->InitVertexIterator(); |
1130 | IsVtx = !domain2->MoreVertex(); |
1131 | while (!IsVtx) { |
1132 | Vtx = domain2->Vertex(); |
1133 | if (Abs(BRepBlend_BlendTool::Parameter(Vtx, rst2)-Solinv(3)) <= |
1134 | BRepBlend_BlendTool::Tolerance(Vtx, rst2)) { |
1135 | IsVtx = Standard_True; |
1136 | } |
1137 | else { |
1138 | domain2->NextVertex(); |
1139 | IsVtx = !domain2->MoreVertex(); |
1140 | } |
1141 | } |
1142 | if (!domain2->MoreVertex()) { |
1143 | IsVtx = Standard_False; |
1144 | } |
81bba717 |
1145 | // The section is recalculated by direct solution, otherwise return |
1146 | // incoherences between the parameter and the ground caused by yawn. |
1147 | |
7fd59977 |
1148 | math_Vector infbound(1, 2), supbound(1, 2); |
1149 | math_Vector parinit(1,2), tolerance(1,2); |
1150 | Func.GetTolerance(tolerance, tolesp); |
1151 | Func.GetBounds(infbound, supbound); |
1152 | |
1153 | math_FunctionSetRoot rsnld2(Func, tolerance, 30); |
1154 | parinit(1) = Solinv(2); |
1155 | parinit(2) = Solinv(3); |
1156 | Func.Set(Solinv(1)); |
1157 | rsnld2.Perform(Func, parinit, infbound, supbound); |
1158 | if(!rsnld2.IsDone()) return Standard_False; |
1159 | rsnld2.Root(parinit); |
1160 | Solinv(2) = parinit(1); |
1161 | Solinv(3) = parinit(2); |
1162 | return Standard_True; |
1163 | } |
1164 | return Standard_False; |
1165 | } |
1166 | |
1167 | //======================================================================= |
1168 | //function : Recadre |
81bba717 |
1169 | //purpose : This is the end of curve rst1 |
7fd59977 |
1170 | //======================================================================= |
1171 | |
1172 | Standard_Boolean BRepBlend_RstRstLineBuilder::Recadre1(Blend_CurvPointFuncInv& FinvP, |
1173 | math_Vector& Solinv, |
1174 | Standard_Boolean& IsVtx, |
1175 | Handle(Adaptor3d_HVertex)& Vtx) |
1176 | { |
81bba717 |
1177 | // One is located on the last or the first point, following the |
1178 | // direction of processing. |
7fd59977 |
1179 | gp_Pnt2d p2drst1; |
1180 | Standard_Real firstrst1 = rst1->FirstParameter(); |
1181 | Standard_Real lastrst1 = rst1->LastParameter(); |
1182 | Standard_Real upoint = firstrst1; |
1183 | |
1184 | if((sol(1) - firstrst1) > (lastrst1 - sol(1))) upoint = lastrst1; |
1185 | p2drst1 = rst1->Value(upoint); |
1186 | gp_Pnt thepoint = surf1->Value(p2drst1.X(), p2drst1.Y()); |
1187 | |
1188 | FinvP.Set(thepoint); |
1189 | math_Vector toler(1,2), infb(1, 2), supb(1, 2); |
1190 | FinvP.GetTolerance(toler, tolesp); |
1191 | FinvP.GetBounds(infb, supb); |
1192 | Solinv(1) = param; |
1193 | Solinv(2) = sol(2); |
1194 | |
1195 | math_FunctionSetRoot rsnld(FinvP, toler, 30); |
1196 | rsnld.Perform(FinvP, Solinv, infb, supb); |
1197 | if (!rsnld.IsDone()) { |
0797d9d3 |
1198 | #ifdef OCCT_DEBUG |
7fd59977 |
1199 | cout << "RSNLD not done "<< endl << endl; |
aefdc31b |
1200 | #endif |
7fd59977 |
1201 | return Standard_False; |
1202 | } |
1203 | rsnld.Root(Solinv); |
1204 | |
1205 | if(FinvP.IsSolution(Solinv, tolesp)){ |
1206 | gp_Pnt2d p2drst2 = rst2->Value(Solinv(2)); |
1207 | TopAbs_State situ = domain2->Classify(p2drst2, toler(2), 0); |
1208 | if ((situ != TopAbs_IN) && (situ != TopAbs_ON)) { |
1209 | return Standard_False; |
1210 | } |
1211 | domain1->Initialize(rst1); |
1212 | domain1->InitVertexIterator(); |
1213 | IsVtx = !domain1->MoreVertex(); |
1214 | while (!IsVtx) { |
1215 | Vtx = domain1->Vertex(); |
1216 | if (Abs(BRepBlend_BlendTool::Parameter(Vtx, rst1) - upoint) <= |
1217 | BRepBlend_BlendTool::Tolerance(Vtx, rst1)) { |
1218 | IsVtx = Standard_True; |
1219 | } |
1220 | else { |
1221 | domain1->NextVertex(); |
1222 | IsVtx = !domain1->MoreVertex(); |
1223 | } |
1224 | } |
1225 | if (!domain1->MoreVertex()) { |
1226 | IsVtx = Standard_False; |
1227 | } |
1228 | return Standard_True; |
1229 | } |
1230 | return Standard_False; |
1231 | } |
1232 | |
1233 | |
1234 | |
1235 | //======================================================================= |
1236 | //function : Recadre2 |
81bba717 |
1237 | //purpose : This is the end of curve rst2 |
7fd59977 |
1238 | //======================================================================= |
1239 | |
1240 | Standard_Boolean BRepBlend_RstRstLineBuilder::Recadre2(Blend_CurvPointFuncInv& FinvP, |
1241 | math_Vector& Solinv, |
1242 | Standard_Boolean& IsVtx, |
1243 | Handle(Adaptor3d_HVertex)& Vtx) |
1244 | { |
81bba717 |
1245 | // One is located on the last or the first point, following the |
1246 | // direction of processing. |
7fd59977 |
1247 | gp_Pnt2d p2drst2; |
1248 | Standard_Real firstrst2 = rst2->FirstParameter(); |
1249 | Standard_Real lastrst2 = rst2->LastParameter(); |
1250 | Standard_Real vpoint = firstrst2; |
1251 | |
1252 | if((sol(2) - firstrst2) > (lastrst2 - sol(2))) vpoint = lastrst2; |
1253 | p2drst2 = rst2->Value(vpoint); |
1254 | gp_Pnt thepoint = surf2->Value(p2drst2.X(), p2drst2.Y()); |
1255 | |
1256 | FinvP.Set(thepoint); |
1257 | math_Vector toler(1,2), infb(1, 2), supb(1, 2); |
1258 | FinvP.GetTolerance(toler, tolesp); |
1259 | FinvP.GetBounds(infb, supb); |
1260 | Solinv(1) = param; |
1261 | Solinv(2) = sol(1); |
1262 | |
1263 | math_FunctionSetRoot rsnld(FinvP, toler, 30); |
1264 | rsnld.Perform(FinvP, Solinv, infb, supb); |
1265 | if (!rsnld.IsDone()) { |
0797d9d3 |
1266 | #ifdef OCCT_DEBUG |
7fd59977 |
1267 | cout << "RSNLD not done "<< endl << endl; |
aefdc31b |
1268 | #endif |
7fd59977 |
1269 | return Standard_False; |
1270 | } |
1271 | rsnld.Root(Solinv); |
1272 | |
1273 | if(FinvP.IsSolution(Solinv, tolesp)){ |
1274 | gp_Pnt2d p2drst1 = rst1->Value(Solinv(2)); |
1275 | TopAbs_State situ = domain1->Classify(p2drst1, toler(2), 0); |
1276 | if ((situ != TopAbs_IN) && (situ != TopAbs_ON)) { |
1277 | return Standard_False; |
1278 | } |
1279 | domain2->Initialize(rst2); |
1280 | domain2->InitVertexIterator(); |
1281 | IsVtx = !domain2->MoreVertex(); |
1282 | while (!IsVtx) { |
1283 | Vtx = domain2->Vertex(); |
1284 | if (Abs(BRepBlend_BlendTool::Parameter(Vtx, rst2) - vpoint) <= |
1285 | BRepBlend_BlendTool::Tolerance(Vtx, rst2)) { |
1286 | IsVtx = Standard_True; |
1287 | } |
1288 | else { |
1289 | domain2->NextVertex(); |
1290 | IsVtx = !domain2->MoreVertex(); |
1291 | } |
1292 | } |
1293 | if (!domain2->MoreVertex()) { |
1294 | IsVtx = Standard_False; |
1295 | } |
1296 | return Standard_True; |
1297 | } |
1298 | return Standard_False; |
1299 | } |
1300 | |
1301 | |
1302 | //======================================================================= |
1303 | //function : Transition |
1304 | //purpose : |
1305 | //======================================================================= |
1306 | |
1307 | void BRepBlend_RstRstLineBuilder::Transition(const Standard_Boolean OnFirst, |
1308 | const Handle(Adaptor2d_HCurve2d)& Arc, |
1309 | const Standard_Real Param, |
1310 | IntSurf_Transition& TLine, |
1311 | IntSurf_Transition& TArc) |
1312 | { |
1313 | Standard_Boolean computetranstionaveclacorde = 0; |
1314 | gp_Vec tgline; |
1315 | Blend_Point prevprev; |
1316 | |
1317 | if(previousP.IsTangencyPoint()){ |
1318 | if(line->NbPoints() < 2) return; |
1319 | computetranstionaveclacorde = 1; |
1320 | if(sens < 0){ |
1321 | prevprev = line->Point(2); |
1322 | } |
1323 | else { |
1324 | prevprev = line->Point(line->NbPoints() - 1); |
1325 | } |
1326 | } |
1327 | gp_Pnt2d p2d; |
1328 | gp_Vec2d dp2d; |
1329 | |
1330 | gp_Pnt pbid; |
1331 | gp_Vec d1u, d1v, normale, tgrst; |
1332 | |
1333 | Arc->D1(Param, p2d, dp2d); |
1334 | if (OnFirst) { |
1335 | surf1->D1(p2d.X(), p2d.Y(), pbid, d1u, d1v); |
1336 | if(!computetranstionaveclacorde) tgline = previousP.TangentOnC1(); |
1337 | else tgline = gp_Vec(prevprev.PointOnC1(), previousP.PointOnC1()); |
1338 | } |
1339 | else { |
1340 | surf2->D1(p2d.X(), p2d.Y(), pbid, d1u, d1v); |
1341 | if(!computetranstionaveclacorde) tgline = previousP.TangentOnC2(); |
1342 | else tgline = gp_Vec(prevprev.PointOnC2(), previousP.PointOnC2()); |
1343 | } |
1344 | |
1345 | tgrst.SetLinearForm(dp2d.X(), d1u, dp2d.Y(), d1v); |
1346 | normale = d1u.Crossed(d1v); |
1347 | |
1348 | IntSurf::MakeTransition(tgline, tgrst, normale, TLine, TArc); |
1349 | } |
1350 | |
1351 | //======================================================================= |
1352 | //function : MakeExtremity |
81bba717 |
1353 | //purpose : produce the extremity of a curve |
7fd59977 |
1354 | //======================================================================= |
1355 | |
1356 | void BRepBlend_RstRstLineBuilder::MakeExtremity(BRepBlend_Extremity& Extrem, |
1357 | const Standard_Boolean OnFirst, |
1358 | const Handle(Adaptor2d_HCurve2d)& Arc, |
1359 | const Standard_Real Param, |
1360 | const Standard_Boolean IsVtx, |
1361 | const Handle(Adaptor3d_HVertex)& Vtx) |
1362 | { |
1363 | IntSurf_Transition Tline, Tarc; |
1364 | Standard_Real prm; |
1365 | Handle(Adaptor3d_TopolTool) Iter; |
1366 | if (OnFirst) { |
1367 | Extrem.SetValue(previousP.PointOnC1(), |
1368 | sol(1), |
1369 | previousP.Parameter(), tolesp); |
1370 | if (!previousP.IsTangencyPoint()) |
1371 | Extrem.SetTangent(previousP.TangentOnC1()); |
1372 | Iter = domain1; |
1373 | } |
1374 | else { |
1375 | Extrem.SetValue(previousP.PointOnC2(), |
1376 | sol(2), |
1377 | previousP.Parameter(), tolesp); |
1378 | if (!previousP.IsTangencyPoint()) |
1379 | Extrem.SetTangent(previousP.TangentOnC1()); |
1380 | Iter = domain2; |
1381 | } |
1382 | |
1383 | Iter->Init(); |
1384 | if (!IsVtx) { |
1385 | Transition(OnFirst, Arc, Param, Tline, Tarc); |
1386 | Extrem.AddArc(Arc, Param, Tline, Tarc); |
1387 | } |
1388 | else { |
1389 | Extrem.SetVertex(Vtx); |
1390 | while (Iter->More()) { |
7fd59977 |
1391 | Handle(Adaptor2d_HCurve2d) arc = Iter->Value(); |
7fd59977 |
1392 | if (arc != Arc) { |
1393 | Iter->Initialize(arc); |
1394 | Iter->InitVertexIterator(); |
1395 | while (Iter->MoreVertex()) { |
1396 | if (Iter->Identical(Vtx, Iter->Vertex())) { |
1397 | prm = BRepBlend_BlendTool::Parameter(Vtx, arc); |
1398 | Transition(OnFirst, arc, prm, Tline, Tarc); |
1399 | Extrem.AddArc(arc, prm, Tline, Tarc); |
1400 | } |
1401 | Iter->NextVertex(); |
1402 | } |
1403 | } |
1404 | else { |
1405 | Transition(OnFirst, arc, Param, Tline, Tarc); |
1406 | Extrem.AddArc(arc, Param, Tline, Tarc); |
1407 | } |
1408 | Iter->Next(); |
1409 | } |
1410 | } |
1411 | } |
1412 | |
1413 | //======================================================================= |
1414 | //function : CheckDeflectionOnRst1 |
1415 | //purpose : |
1416 | //======================================================================= |
1417 | |
1418 | Blend_Status BRepBlend_RstRstLineBuilder::CheckDeflectionOnRst1(const Blend_Point& CurPoint) |
1419 | { |
81bba717 |
1420 | //Controls 3d of Blend_CSWalking. |
7fd59977 |
1421 | |
81bba717 |
1422 | // rule by tests in U4 corresponds to 11.478 |
7fd59977 |
1423 | const Standard_Real CosRef3D = 0.98; |
1424 | Standard_Real Cosi, Cosi2; |
1425 | Standard_Boolean curpointistangent = CurPoint.IsTangencyPoint(); |
1426 | Standard_Boolean prevpointistangent = previousP.IsTangencyPoint(); |
1427 | |
1428 | gp_Pnt Psurf = CurPoint.PointOnC1(); |
1429 | gp_Vec Tgsurf; |
1430 | if(!curpointistangent){ |
1431 | Tgsurf = CurPoint.TangentOnC1(); |
1432 | } |
1433 | gp_Pnt prevP = previousP.PointOnC1(); |
1434 | gp_Vec prevTg; |
1435 | if(!prevpointistangent){ |
1436 | prevTg = previousP.TangentOnC1(); |
1437 | } |
96a95605 |
1438 | Standard_Real Norme; |
7fd59977 |
1439 | Standard_Real prevNorme = 0.; |
7fd59977 |
1440 | gp_Vec Corde(prevP, Psurf); |
1441 | Norme = Corde.SquareMagnitude(); |
7fd59977 |
1442 | if (!prevpointistangent) prevNorme = prevTg.SquareMagnitude(); |
1443 | |
1444 | if (Norme <= tolesp * tolesp) { |
81bba717 |
1445 | // it can be necessary to force the same point |
7fd59977 |
1446 | return Blend_SamePoints; |
1447 | } |
1448 | if(!prevpointistangent){ |
1449 | if (prevNorme <= tolesp * tolesp) { |
1450 | return Blend_SamePoints; |
1451 | } |
1452 | Cosi = sens * Corde * prevTg; |
81bba717 |
1453 | if (Cosi < 0.) { // angle 3d>pi/2. --> return back |
7fd59977 |
1454 | return Blend_Backward; |
1455 | } |
1456 | |
1457 | Cosi2 = Cosi * Cosi / prevNorme / Norme; |
1458 | if (Cosi2 < CosRef3D) { |
1459 | return Blend_StepTooLarge; |
1460 | } |
1461 | } |
1462 | |
1463 | if(!curpointistangent){ |
81bba717 |
1464 | // Check if it is necessary to control the sign of prevtg*Tgsurf |
7fd59977 |
1465 | Cosi = sens * Corde * Tgsurf; |
1466 | Cosi2 = Cosi * Cosi / Tgsurf.SquareMagnitude() / Norme; |
1467 | if (Cosi2 < CosRef3D || Cosi < 0.) { |
1468 | return Blend_StepTooLarge; |
1469 | } |
1470 | } |
1471 | |
1472 | if (!curpointistangent && !prevpointistangent) { |
81bba717 |
1473 | // Estimation of the current arrow |
7fd59977 |
1474 | Standard_Real FlecheCourante = |
1475 | (prevTg.Normalized().XYZ() - Tgsurf.Normalized().XYZ()).SquareModulus() * Norme / 64.; |
1476 | |
1477 | if (FlecheCourante <= 0.25 * fleche * fleche) { |
1478 | return Blend_StepTooSmall; |
1479 | } |
1480 | if (FlecheCourante > fleche * fleche) { |
81bba717 |
1481 | // not too great |
7fd59977 |
1482 | return Blend_StepTooLarge; |
1483 | } |
1484 | } |
1485 | return Blend_OK; |
1486 | } |
1487 | |
1488 | |
1489 | //======================================================================= |
1490 | //function : CheckDeflectionOnRst2 |
1491 | //purpose : |
1492 | //======================================================================= |
1493 | |
1494 | Blend_Status BRepBlend_RstRstLineBuilder::CheckDeflectionOnRst2(const Blend_Point& CurPoint) |
1495 | { |
81bba717 |
1496 | //3D Controls of Blend_CSWalking. |
7fd59977 |
1497 | |
81bba717 |
1498 | // rule by tests in U4 corresponding to 11.478 d |
7fd59977 |
1499 | const Standard_Real CosRef3D = 0.98; |
1500 | Standard_Real Cosi, Cosi2; |
1501 | Standard_Boolean curpointistangent = CurPoint.IsTangencyPoint(); |
1502 | Standard_Boolean prevpointistangent = previousP.IsTangencyPoint(); |
1503 | |
1504 | gp_Pnt Psurf = CurPoint.PointOnC2(); |
1505 | gp_Vec Tgsurf; |
1506 | |
1507 | if (!curpointistangent) { |
1508 | Tgsurf = CurPoint.TangentOnC2(); |
1509 | } |
1510 | gp_Pnt prevP = previousP.PointOnC2(); |
1511 | gp_Vec prevTg; |
1512 | if (!prevpointistangent) { |
1513 | prevTg = previousP.TangentOnC2(); |
1514 | } |
96a95605 |
1515 | Standard_Real Norme; |
7fd59977 |
1516 | Standard_Real prevNorme = 0.; |
7fd59977 |
1517 | gp_Vec Corde(prevP, Psurf); |
1518 | Norme = Corde.SquareMagnitude(); |
7fd59977 |
1519 | if (!prevpointistangent) prevNorme = prevTg.SquareMagnitude(); |
1520 | |
1521 | if (Norme <= tolesp * tolesp){ |
81bba717 |
1522 | // it can be necessary to force the same point |
7fd59977 |
1523 | return Blend_SamePoints; |
1524 | } |
1525 | if (!prevpointistangent) { |
1526 | if (prevNorme <= tolesp * tolesp) { |
1527 | return Blend_SamePoints; |
1528 | } |
1529 | Cosi = sens * Corde * prevTg; |
81bba717 |
1530 | if (Cosi < 0.) { // angle 3d>pi/2. --> return back |
7fd59977 |
1531 | return Blend_Backward; |
1532 | } |
1533 | |
1534 | Cosi2 = Cosi * Cosi / prevNorme / Norme; |
1535 | if (Cosi2 < CosRef3D) { |
1536 | return Blend_StepTooLarge; |
1537 | } |
1538 | } |
1539 | |
1540 | if (!curpointistangent) { |
81bba717 |
1541 | // Check if it is necessary to control the sign of prevtg*Tgsurf |
7fd59977 |
1542 | Cosi = sens * Corde * Tgsurf; |
1543 | Cosi2 = Cosi * Cosi / Tgsurf.SquareMagnitude() / Norme; |
1544 | if (Cosi2 < CosRef3D || Cosi < 0.) { |
1545 | return Blend_StepTooLarge; |
1546 | } |
1547 | } |
1548 | |
1549 | if(!curpointistangent && !prevpointistangent){ |
81bba717 |
1550 | // Estimation of the current arrow |
7fd59977 |
1551 | Standard_Real FlecheCourante = |
1552 | (prevTg.Normalized().XYZ() - Tgsurf.Normalized().XYZ()).SquareModulus() * Norme/64.; |
1553 | |
1554 | if (FlecheCourante <= 0.25 * fleche * fleche) { |
1555 | return Blend_StepTooSmall; |
1556 | } |
1557 | if (FlecheCourante > fleche * fleche) { |
81bba717 |
1558 | // not too great |
7fd59977 |
1559 | return Blend_StepTooLarge; |
1560 | } |
1561 | } |
1562 | return Blend_OK; |
1563 | } |
1564 | |
1565 | static IntSurf_TypeTrans ConvOrToTra(const TopAbs_Orientation O) |
1566 | { |
1567 | if(O == TopAbs_FORWARD) return IntSurf_In; |
1568 | return IntSurf_Out; |
1569 | } |
1570 | |
1571 | //======================================================================= |
1572 | //function : TestArret |
1573 | //purpose : |
1574 | //======================================================================= |
1575 | |
1576 | Blend_Status BRepBlend_RstRstLineBuilder::TestArret(Blend_RstRstFunction& Func, |
1577 | const Standard_Boolean TestDeflection, |
1578 | const Blend_Status State) |
1579 | { |
1580 | gp_Pnt ptrst1, ptrst2; |
1581 | gp_Pnt2d pt2drst1, pt2drst2; |
1582 | gp_Vec tgrst1, tgrst2; |
1583 | gp_Vec2d tg2drst1, tg2drst2; |
1584 | Blend_Status StateRst1, StateRst2; |
7fd59977 |
1585 | IntSurf_TypeTrans trarst1 = IntSurf_Undecided, trarst2 = IntSurf_Undecided; |
7fd59977 |
1586 | Blend_Point curpoint; |
1587 | |
1588 | if (Func.IsSolution(sol, tolesp)) { |
1589 | Standard_Boolean curpointistangent = Func.IsTangencyPoint(); |
1590 | ptrst1 = Func.PointOnRst1(); |
1591 | ptrst2 = Func.PointOnRst2(); |
1592 | pt2drst1 = Func.Pnt2dOnRst1(); |
1593 | pt2drst2 = Func.Pnt2dOnRst2(); |
1594 | |
1595 | if(curpointistangent){ |
1596 | curpoint.SetValue(ptrst1, ptrst2, param, pt2drst1.X(), pt2drst1.Y(), |
1597 | pt2drst2.X(), pt2drst2.Y(), sol(1), sol(2)); |
1598 | } |
1599 | else{ |
1600 | tgrst1 = Func.TangentOnRst1(); |
1601 | tgrst2 = Func.TangentOnRst2(); |
1602 | tg2drst1 = Func.Tangent2dOnRst1(); |
1603 | tg2drst2 = Func.Tangent2dOnRst2(); |
1604 | curpoint.SetValue(ptrst1, ptrst2, param, pt2drst1.X(), pt2drst1.Y(), |
1605 | pt2drst2.X(), pt2drst2.Y(), sol(1), sol(2), |
1606 | tgrst1, tgrst2, tg2drst1, tg2drst2); |
1607 | } |
1608 | if (TestDeflection) { |
1609 | StateRst1 = CheckDeflectionOnRst1(curpoint); |
1610 | StateRst2 = CheckDeflectionOnRst2(curpoint); |
1611 | } |
1612 | else { |
1613 | StateRst1 = StateRst2 = Blend_OK; |
1614 | } |
1615 | if (StateRst1 == Blend_Backward) { |
1616 | StateRst1 = Blend_StepTooLarge; |
1617 | rebrou = Standard_True; |
1618 | } |
1619 | if (StateRst2 == Blend_Backward) { |
1620 | StateRst2 = Blend_StepTooLarge; |
1621 | rebrou = Standard_True; |
1622 | } |
1623 | if (StateRst1 == Blend_StepTooLarge || |
1624 | StateRst2 == Blend_StepTooLarge) { |
1625 | return Blend_StepTooLarge; |
1626 | } |
1627 | |
1628 | if (!comptra && !curpointistangent) { |
1629 | gp_Pnt2d p2drstref; |
1630 | gp_Vec2d tg2drstref; |
1631 | rst1->D1(sol(1), p2drstref, tg2drstref); |
1632 | Standard_Real testra = tg2drst1.Dot(tg2drstref); |
1633 | TopAbs_Orientation Or = domain1->Orientation(rst1); |
1634 | |
1635 | if (Abs(testra) > tolesp) { |
1636 | if (testra < 0.) { |
1637 | trarst1 = ConvOrToTra(TopAbs::Reverse(Or)); |
1638 | } |
1639 | else if (testra >0.) { |
1640 | trarst1 = ConvOrToTra(Or); |
1641 | } |
1642 | |
1643 | rst2->D1(sol(2), p2drstref, tg2drstref); |
1644 | testra = tg2drst2.Dot(tg2drstref); |
1645 | |
1646 | Or = domain2->Orientation(rst2); |
1647 | if (Abs(testra) > tolesp) { |
1648 | if (testra < 0.) { |
1649 | trarst2 = ConvOrToTra(TopAbs::Reverse(Or)); |
1650 | } |
1651 | else if (testra >0.) { |
1652 | trarst2 = ConvOrToTra(Or); |
1653 | } |
1654 | comptra = Standard_True; |
1655 | line->Set(trarst1, trarst2); |
1656 | } |
1657 | } |
1658 | } |
1659 | if (StateRst1 == Blend_OK || |
1660 | StateRst2 == Blend_OK ) { |
1661 | previousP = curpoint; |
1662 | return State; |
1663 | } |
1664 | if (StateRst1 == Blend_StepTooSmall && |
1665 | StateRst2 == Blend_StepTooSmall) { |
1666 | previousP = curpoint; |
1667 | if (State == Blend_OK) { |
1668 | return Blend_StepTooSmall; |
1669 | } |
1670 | else { |
1671 | return State; |
1672 | } |
1673 | } |
1674 | if (State == Blend_OK) { |
1675 | return Blend_SamePoints; |
1676 | } |
1677 | else { |
1678 | return State; |
1679 | } |
1680 | } |
1681 | return Blend_StepTooLarge; |
1682 | } |
1683 | |
1684 | //======================================================================= |
1685 | //function : CheckInside |
1686 | //purpose : |
1687 | //======================================================================= |
1688 | |
1689 | Standard_Boolean BRepBlend_RstRstLineBuilder::CheckInside(Blend_RstRstFunction& Func, |
1690 | TopAbs_State& SituOnC1, |
1691 | TopAbs_State& SituOnC2, |
1692 | Blend_DecrochStatus & Decroch) |
1693 | { |
1694 | // Standard_Boolean inside = Standard_True; |
1695 | math_Vector tolerance(1, 2); |
1696 | Func.GetTolerance(tolerance, tolesp); |
1697 | |
81bba717 |
1698 | //face pcurve 1. |
7fd59977 |
1699 | Standard_Real v = sol(1); |
1700 | if(v < rst1->FirstParameter() - tolerance(2)|| |
1701 | v > rst1->LastParameter() + tolerance(2)){ |
1702 | SituOnC1 = TopAbs_OUT; |
1703 | } |
1704 | else if (v > rst1->FirstParameter() && |
1705 | v < rst1->LastParameter()){ |
1706 | SituOnC1 = TopAbs_IN; |
1707 | } |
1708 | else SituOnC1 = TopAbs_ON; |
1709 | |
81bba717 |
1710 | //face pcurve 2. |
7fd59977 |
1711 | v = sol(2); |
1712 | if(v < rst2->FirstParameter() - tolerance(2)|| |
1713 | v > rst2->LastParameter() + tolerance(2)){ |
1714 | SituOnC2 = TopAbs_OUT; |
1715 | } |
1716 | else if (v > rst2->FirstParameter() && |
1717 | v < rst2->LastParameter()){ |
1718 | SituOnC2 = TopAbs_IN; |
1719 | } |
1720 | else SituOnC2 = TopAbs_ON; |
1721 | |
1722 | |
81bba717 |
1723 | //lost contact |
7fd59977 |
1724 | gp_Vec tgrst1, norst1, tgrst2, norst2; |
1725 | Decroch = Func.Decroch(sol,tgrst1, norst1, tgrst2, norst2); |
1726 | |
1727 | return (SituOnC1 == TopAbs_IN && SituOnC2 == TopAbs_IN && Decroch == Blend_NoDecroch); |
1728 | } |
1729 | |
1730 | |
1731 | |