7fd59977 |
1 | // File: GeomAPI_Interpolate.cxx |
2 | // Created: Thu Aug 18 15:53:59 1994 |
3 | // Author: Laurent PAINNOT |
4 | // <lpa@metrox> |
5 | // 8-Aug-95 : xab : interpolation uses BSplCLib::Interpolate |
6 | // |
7 | |
8 | #include <Geom2dAPI_Interpolate.ixx> |
9 | #include <Standard_ConstructionError.hxx> |
10 | #include <PLib.hxx> |
11 | #include <BSplCLib.hxx> |
12 | #include <gp_Vec2d.hxx> |
13 | #include <TColgp_Array1OfPnt2d.hxx> |
14 | #include <TColStd_HArray1OfReal.hxx> |
15 | #include <TColStd_Array1OfBoolean.hxx> |
16 | #include <TColStd_Array1OfInteger.hxx> |
17 | #include <TColStd_HArray1OfBoolean.hxx> |
18 | |
19 | //======================================================================= |
20 | //function : CheckPoints |
21 | //purpose : |
22 | //======================================================================= |
23 | |
24 | static Standard_Boolean CheckPoints(const TColgp_Array1OfPnt2d& PointArray, |
25 | const Standard_Real Tolerance) |
26 | { |
27 | Standard_Integer ii ; |
28 | Standard_Real tolerance_squared = Tolerance * Tolerance, |
29 | distance_squared ; |
30 | Standard_Boolean result = Standard_True ; |
31 | for (ii = PointArray.Lower() ; result && ii < PointArray.Upper() ; ii++) { |
32 | distance_squared = |
33 | PointArray.Value(ii).SquareDistance(PointArray.Value(ii+1)) ; |
34 | result = (distance_squared >= tolerance_squared) ; |
35 | } |
36 | return result ; |
37 | |
38 | } |
39 | //======================================================================= |
40 | //function : CheckTangents |
41 | //purpose : |
42 | //======================================================================= |
43 | static Standard_Boolean CheckTangents( |
44 | const TColgp_Array1OfVec2d& Tangents, |
45 | const TColStd_Array1OfBoolean& TangentFlags, |
46 | const Standard_Real Tolerance) |
47 | { |
48 | Standard_Integer ii, |
49 | index ; |
50 | Standard_Real tolerance_squared = Tolerance * Tolerance, |
51 | distance_squared ; |
52 | Standard_Boolean result = Standard_True ; |
53 | index = TangentFlags.Lower() ; |
54 | for (ii = Tangents.Lower(); result && ii <= Tangents.Upper() ; ii++) { |
55 | if(TangentFlags.Value(index)) { |
56 | distance_squared = |
57 | Tangents.Value(ii).SquareMagnitude() ; |
58 | result = (distance_squared >= tolerance_squared) ; |
59 | } |
60 | index += 1 ; |
61 | } |
62 | return result ; |
63 | |
64 | } |
65 | //======================================================================= |
66 | //function : CheckParameters |
67 | //purpose : |
68 | //======================================================================= |
69 | static Standard_Boolean CheckParameters(const |
70 | TColStd_Array1OfReal& Parameters) |
71 | { |
72 | Standard_Integer ii ; |
73 | Standard_Real distance ; |
74 | Standard_Boolean result = Standard_True ; |
75 | for (ii = Parameters.Lower() ; result && ii < Parameters.Upper() ; ii++) { |
76 | distance = |
77 | Parameters.Value(ii+1) - Parameters.Value(ii) ; |
78 | result = (distance >= RealSmall()) ; |
79 | } |
80 | return result ; |
81 | } |
82 | //======================================================================= |
83 | //function : BuildParameters |
84 | //purpose : |
85 | //======================================================================= |
86 | static void BuildParameters(const Standard_Boolean PeriodicFlag, |
87 | const TColgp_Array1OfPnt2d& PointsArray, |
88 | Handle_TColStd_HArray1OfReal& ParametersPtr) |
89 | { |
90 | Standard_Integer ii, |
91 | index ; |
92 | Standard_Real distance ; |
93 | Standard_Integer |
94 | num_parameters = PointsArray.Length() ; |
95 | if (PeriodicFlag) { |
96 | num_parameters += 1 ; |
97 | } |
98 | ParametersPtr = |
99 | new TColStd_HArray1OfReal(1, |
100 | num_parameters) ; |
101 | ParametersPtr->SetValue(1,0.0e0) ; |
102 | index = 2 ; |
103 | for (ii = PointsArray.Lower() ; ii < PointsArray.Upper() ; ii++) { |
104 | distance = |
105 | PointsArray.Value(ii).Distance(PointsArray.Value(ii+1)) ; |
106 | ParametersPtr->SetValue(index, |
107 | ParametersPtr->Value(ii) + distance) ; |
108 | index += 1 ; |
109 | } |
110 | if (PeriodicFlag) { |
111 | distance = |
112 | PointsArray.Value(PointsArray.Upper()). |
113 | Distance(PointsArray.Value(PointsArray.Lower())) ; |
114 | ParametersPtr->SetValue(index, |
115 | ParametersPtr->Value(ii) + distance) ; |
116 | } |
117 | } |
118 | //======================================================================= |
119 | //function : BuildPeriodicTangents |
120 | //purpose : |
121 | //======================================================================= |
122 | |
123 | static void BuildPeriodicTangent( |
124 | const TColgp_Array1OfPnt2d& PointsArray, |
125 | TColgp_Array1OfVec2d& TangentsArray, |
126 | TColStd_Array1OfBoolean& TangentFlags, |
127 | const TColStd_Array1OfReal& ParametersArray) |
128 | { |
129 | Standard_Integer |
130 | ii, |
131 | degree ; |
132 | Standard_Real *point_array, |
133 | *parameter_array, |
134 | eval_result[2][2] ; |
135 | |
136 | gp_Vec2d a_vector ; |
137 | |
138 | if (PointsArray.Length() < 3) { |
139 | Standard_ConstructionError::Raise(); |
140 | } |
141 | |
142 | if (!TangentFlags.Value(1)) { |
143 | degree = 3 ; |
144 | if (PointsArray.Length() == 3) { |
145 | degree = 2 ; |
146 | } |
147 | point_array = (Standard_Real *) &PointsArray.Value(PointsArray.Lower()) ; |
148 | parameter_array = |
149 | (Standard_Real *) &ParametersArray.Value(1) ; |
150 | TangentFlags.SetValue(1,Standard_True) ; |
151 | PLib::EvalLagrange(ParametersArray.Value(1), |
152 | 1, |
153 | degree, |
154 | 2, |
155 | point_array[0], |
156 | parameter_array[0], |
157 | eval_result[0][0]) ; |
158 | for (ii = 1 ; ii <= 2 ; ii++) { |
159 | a_vector.SetCoord(ii,eval_result[1][ii-1]) ; |
160 | } |
161 | TangentsArray.SetValue(1,a_vector) ; |
162 | } |
163 | } |
164 | //======================================================================= |
165 | //function : BuildTangents |
166 | //purpose : |
167 | //======================================================================= |
168 | |
169 | static void BuildTangents(const TColgp_Array1OfPnt2d& PointsArray, |
170 | TColgp_Array1OfVec2d& TangentsArray, |
171 | TColStd_Array1OfBoolean& TangentFlags, |
172 | const TColStd_Array1OfReal& ParametersArray) |
173 | { |
174 | Standard_Integer ii, |
175 | degree ; |
176 | Standard_Real *point_array, |
177 | *parameter_array, |
178 | |
179 | eval_result[2][2] ; |
180 | gp_Vec2d a_vector ; |
181 | |
182 | degree = 3 ; |
183 | |
184 | if ( PointsArray.Length() < 3) { |
185 | Standard_ConstructionError::Raise(); |
186 | } |
187 | if (PointsArray.Length() == 3) { |
188 | degree = 2 ; |
189 | } |
190 | if (!TangentFlags.Value(1)) { |
191 | point_array = (Standard_Real *) &PointsArray.Value(PointsArray.Lower()) ; |
192 | parameter_array = |
193 | (Standard_Real *) &ParametersArray.Value(1) ; |
194 | TangentFlags.SetValue(1,Standard_True) ; |
195 | PLib::EvalLagrange(ParametersArray.Value(1), |
196 | 1, |
197 | degree, |
198 | 2, |
199 | point_array[0], |
200 | parameter_array[0], |
201 | eval_result[0][0]) ; |
202 | for (ii = 1 ; ii <= 2 ; ii++) { |
203 | a_vector.SetCoord(ii,eval_result[1][ii-1]) ; |
204 | } |
205 | TangentsArray.SetValue(1,a_vector) ; |
206 | } |
207 | if (! TangentFlags.Value(TangentFlags.Upper())) { |
208 | point_array = |
209 | (Standard_Real *) &PointsArray.Value(PointsArray.Upper() - degree) ; |
210 | TangentFlags.SetValue(TangentFlags.Upper(),Standard_True) ; |
211 | parameter_array = |
212 | (Standard_Real *)&ParametersArray.Value(ParametersArray.Upper() - degree) ; |
213 | PLib::EvalLagrange(ParametersArray.Value(ParametersArray.Upper()), |
214 | 1, |
215 | degree, |
216 | 2, |
217 | point_array[0], |
218 | parameter_array[0], |
219 | eval_result[0][0]) ; |
220 | for (ii = 1 ; ii <= 2 ; ii++) { |
221 | a_vector.SetCoord(ii,eval_result[1][ii-1]) ; |
222 | } |
223 | TangentsArray.SetValue(TangentsArray.Upper(),a_vector) ; |
224 | } |
225 | } |
226 | //======================================================================= |
227 | //function : BuildTangents |
228 | //purpose : scale the given tangent so that they have the length of |
229 | // the size of the derivative of the lagrange interpolation |
230 | // |
231 | //======================================================================= |
232 | static void ScaleTangents(const TColgp_Array1OfPnt2d& PointsArray, |
233 | TColgp_Array1OfVec2d& TangentsArray, |
234 | const TColStd_Array1OfBoolean& TangentFlags, |
235 | const TColStd_Array1OfReal& ParametersArray) |
236 | { |
237 | Standard_Integer ii, |
238 | jj, |
239 | degree=0, |
240 | index, |
241 | num_points ; |
242 | |
243 | Standard_Real *point_array, |
244 | *parameter_array, |
245 | value[2], |
246 | ratio, |
247 | eval_result[2][2] ; |
248 | |
249 | gp_Vec2d a_vector ; |
250 | |
251 | num_points = PointsArray.Length() ; |
252 | if (num_points == 2) { |
253 | degree = 1 ; |
254 | } |
255 | else if (num_points >= 3) { |
256 | degree = 2 ; |
257 | } |
258 | |
259 | index = PointsArray.Lower() ; |
260 | for (ii = TangentFlags.Lower() ; ii <= TangentFlags.Upper() ; ii++) { |
261 | if (TangentFlags.Value(ii)) { |
262 | point_array = |
263 | (Standard_Real *) &PointsArray.Value(index) ; |
264 | parameter_array = |
265 | (Standard_Real *) &ParametersArray.Value(index) ; |
266 | PLib::EvalLagrange(ParametersArray.Value(ii), |
267 | 1, |
268 | degree, |
269 | 2, |
270 | point_array[0], |
271 | parameter_array[0], |
272 | eval_result[0][0]) ; |
273 | value[0] = |
274 | value[1] = 0.0e0 ; |
275 | for (jj = 1 ; jj <= 2 ; jj++) { |
276 | value[0] += Abs(TangentsArray.Value(ii).Coord(jj)) ; |
277 | value[1] += Abs(eval_result[1][jj-1]) ; |
278 | } |
279 | ratio = value[1] / value[0] ; |
280 | for (jj = 1 ; jj <= 2 ; jj++) { |
281 | a_vector.SetCoord(jj, ratio * |
282 | TangentsArray.Value(ii).Coord(jj)) ; |
283 | } |
284 | TangentsArray.SetValue(ii, a_vector) ; |
285 | if (ii != TangentFlags.Lower()) { |
286 | index += 1 ; |
287 | } |
288 | if (index > PointsArray.Upper() - degree) { |
289 | index = PointsArray.Upper() - degree ; |
290 | } |
291 | |
292 | } |
293 | } |
294 | } |
295 | |
296 | //======================================================================= |
297 | //function : Geom2dAPI_Interpolate |
298 | //purpose : |
299 | //======================================================================= |
300 | |
301 | Geom2dAPI_Interpolate::Geom2dAPI_Interpolate |
302 | (const Handle_TColgp_HArray1OfPnt2d& PointsPtr, |
303 | const Standard_Boolean PeriodicFlag, |
304 | const Standard_Real Tolerance) : |
305 | myTolerance(Tolerance), |
306 | myPoints(PointsPtr), |
307 | myIsDone(Standard_False), |
308 | myPeriodic(PeriodicFlag), |
309 | myTangentRequest(Standard_False) |
310 | |
311 | { |
312 | Standard_Integer ii ; |
313 | Standard_Boolean result = |
314 | CheckPoints(PointsPtr->Array1(), |
315 | Tolerance) ; |
316 | myTangents = |
317 | new TColgp_HArray1OfVec2d(myPoints->Lower(), |
318 | myPoints->Upper()) ; |
319 | myTangentFlags = |
320 | new TColStd_HArray1OfBoolean(myPoints->Lower(), |
321 | myPoints->Upper()) ; |
322 | |
323 | if (!result) { |
324 | Standard_ConstructionError::Raise(); |
325 | } |
326 | BuildParameters(PeriodicFlag, |
327 | PointsPtr->Array1(), |
328 | myParameters) ; |
329 | |
330 | for (ii = myPoints->Lower() ; ii <= myPoints->Upper() ; ii++) { |
331 | myTangentFlags->SetValue(ii,Standard_False) ; |
332 | } |
333 | |
334 | |
335 | |
336 | } |
337 | |
338 | //======================================================================= |
339 | //function : Geom2dAPI_Interpolate |
340 | //purpose : |
341 | //======================================================================= |
342 | |
343 | Geom2dAPI_Interpolate::Geom2dAPI_Interpolate |
344 | (const Handle_TColgp_HArray1OfPnt2d& PointsPtr, |
345 | const Handle_TColStd_HArray1OfReal& ParametersPtr, |
346 | const Standard_Boolean PeriodicFlag, |
347 | const Standard_Real Tolerance) : |
348 | myTolerance(Tolerance), |
349 | myPoints(PointsPtr), |
350 | myIsDone(Standard_False), |
351 | myParameters(ParametersPtr), |
352 | myPeriodic(PeriodicFlag), |
353 | myTangentRequest(Standard_False) |
354 | { |
355 | Standard_Integer ii ; |
356 | |
357 | |
358 | Standard_Boolean result = |
359 | CheckPoints(PointsPtr->Array1(), |
360 | Tolerance) ; |
361 | |
362 | if (PeriodicFlag) { |
363 | if ((PointsPtr->Length()) + 1 != ParametersPtr->Length()) { |
364 | Standard_ConstructionError::Raise(); |
365 | } |
366 | } |
367 | myTangents = |
368 | new TColgp_HArray1OfVec2d(myPoints->Lower(), |
369 | myPoints->Upper()) ; |
370 | myTangentFlags = |
371 | new TColStd_HArray1OfBoolean(myPoints->Lower(), |
372 | myPoints->Upper()) ; |
373 | |
374 | if (!result) { |
375 | Standard_ConstructionError::Raise(); |
376 | } |
377 | |
378 | result = |
379 | CheckParameters(ParametersPtr->Array1()) ; |
380 | if (!result) { |
381 | Standard_ConstructionError::Raise(); |
382 | } |
383 | |
384 | for (ii = myPoints->Lower() ; ii <= myPoints->Upper() ; ii++) { |
385 | myTangentFlags->SetValue(ii,Standard_False) ; |
386 | } |
387 | |
388 | } |
389 | //======================================================================= |
390 | //function : Load |
391 | //purpose : |
392 | //======================================================================= |
393 | |
394 | void Geom2dAPI_Interpolate::Load( |
395 | const TColgp_Array1OfVec2d& Tangents, |
396 | const Handle_TColStd_HArray1OfBoolean& TangentFlagsPtr) |
397 | |
398 | { |
399 | Standard_Boolean result ; |
400 | Standard_Integer ii ; |
401 | myTangentRequest = Standard_True ; |
402 | myTangentFlags = TangentFlagsPtr ; |
403 | if (Tangents.Length() != myPoints->Length() || |
404 | TangentFlagsPtr->Length() != myPoints->Length()) { |
405 | Standard_ConstructionError::Raise(); |
406 | } |
407 | result = |
408 | CheckTangents(Tangents, |
409 | TangentFlagsPtr->Array1(), |
410 | myTolerance) ; |
411 | if (result) { |
412 | myTangents = |
413 | new TColgp_HArray1OfVec2d(Tangents.Lower(),Tangents.Upper()) ; |
414 | for (ii = Tangents.Lower() ; ii <= Tangents.Upper() ; ii++ ) { |
415 | myTangents->SetValue(ii,Tangents.Value(ii)) ; |
416 | } |
417 | ScaleTangents(myPoints->Array1(), |
418 | myTangents->ChangeArray1(), |
419 | TangentFlagsPtr->Array1(), |
420 | myParameters->Array1()) ; |
421 | } |
422 | else { |
423 | Standard_ConstructionError::Raise(); |
424 | } |
425 | |
426 | |
427 | } |
428 | |
429 | //======================================================================= |
430 | //function : Load |
431 | //purpose : |
432 | //======================================================================= |
433 | |
434 | void Geom2dAPI_Interpolate::Load(const gp_Vec2d& InitialTangent, |
435 | const gp_Vec2d& FinalTangent) |
436 | { |
437 | Standard_Boolean result ; |
438 | myTangentRequest = Standard_True ; |
439 | myTangentFlags->SetValue(1,Standard_True) ; |
440 | myTangentFlags->SetValue(myPoints->Length(),Standard_True) ; |
441 | myTangents->SetValue(1,InitialTangent) ; |
442 | myTangents->SetValue(myPoints->Length(),FinalTangent); |
443 | result = |
444 | CheckTangents(myTangents->Array1(), |
445 | myTangentFlags->Array1(), |
446 | myTolerance) ; |
447 | if (!result) { |
448 | Standard_ConstructionError::Raise(); |
449 | } |
450 | ScaleTangents(myPoints->Array1(), |
451 | myTangents->ChangeArray1(), |
452 | myTangentFlags->Array1(), |
453 | myParameters->Array1()) ; |
454 | |
455 | } |
456 | //======================================================================= |
457 | //function : Perform |
458 | //purpose : |
459 | //======================================================================= |
460 | |
461 | void Geom2dAPI_Interpolate::Perform() |
462 | { |
463 | if (myPeriodic) { |
464 | PerformPeriodic() ; |
465 | } |
466 | else { |
467 | PerformNonPeriodic() ; |
468 | } |
469 | } |
470 | //======================================================================= |
471 | //function : PerformPeriodic |
472 | //purpose : |
473 | //======================================================================= |
474 | |
475 | void Geom2dAPI_Interpolate::PerformPeriodic() |
476 | { |
477 | Standard_Integer degree, |
478 | ii, |
479 | jj, |
480 | index, |
481 | index1, |
482 | // index2, |
483 | mult_index, |
484 | half_order, |
485 | inversion_problem, |
486 | num_points, |
487 | num_distinct_knots, |
488 | num_poles ; |
489 | |
490 | Standard_Real period ; |
491 | |
492 | gp_Pnt2d a_point ; |
493 | |
494 | num_points = myPoints->Length() ; |
495 | period = myParameters->Value(myParameters->Upper()) - |
496 | myParameters->Value(myParameters->Lower()) ; |
497 | num_poles = num_points + 1 ; |
498 | if (num_points == 2 && !myTangentRequest) { |
499 | // |
500 | // build a periodic curve of degree 1 |
501 | // |
502 | |
503 | degree = 1 ; |
504 | TColStd_Array1OfInteger deg1_mults(1,num_poles) ; |
505 | for (ii = 1 ; ii <= num_poles ; ii++) { |
506 | deg1_mults.SetValue(ii,1) ; |
507 | } |
508 | |
509 | myCurve = |
510 | new Geom2d_BSplineCurve(myPoints->Array1(), |
511 | myParameters->Array1(), |
512 | deg1_mults, |
513 | degree, |
514 | myPeriodic) ; |
515 | myIsDone = Standard_True ; |
516 | |
517 | } |
518 | else { |
519 | num_distinct_knots = num_points + 1 ; |
520 | half_order = 2 ; |
521 | degree = 3 ; |
522 | num_poles += 2 ; |
523 | if (myTangentRequest) |
524 | for (ii = myTangentFlags->Lower() + 1 ; |
525 | ii <= myTangentFlags->Upper() ; ii++) { |
526 | if (myTangentFlags->Value(ii)) { |
527 | num_poles += 1 ; |
528 | } |
529 | } |
530 | |
531 | TColStd_Array1OfReal parameters(1,num_poles) ; |
532 | TColStd_Array1OfReal flatknots(1,num_poles + degree + 1) ; |
533 | TColStd_Array1OfInteger mults(1,num_distinct_knots) ; |
534 | TColStd_Array1OfInteger contact_order_array(1, num_poles) ; |
535 | TColgp_Array1OfPnt2d poles(1,num_poles) ; |
536 | |
537 | for (ii = 1 ; ii <= half_order ; ii++) { |
538 | flatknots.SetValue(ii,myParameters->Value(myParameters->Upper() -1) - |
539 | period) ; |
540 | flatknots.SetValue(ii + half_order,myParameters-> |
541 | Value(myParameters->Lower())) ; |
542 | flatknots.SetValue(num_poles + ii, |
543 | myParameters->Value(myParameters->Upper())) ; |
544 | flatknots.SetValue(num_poles + half_order + ii, |
545 | myParameters->Value(half_order) + period) ; |
546 | } |
547 | for (ii = 1 ; ii <= num_poles ; ii++) { |
548 | contact_order_array.SetValue(ii,0) ; |
549 | } |
550 | for (ii = 2 ; ii < num_distinct_knots ; ii++) { |
551 | mults.SetValue(ii,1) ; |
552 | } |
553 | mults.SetValue(1,half_order) ; |
554 | mults.SetValue(num_distinct_knots ,half_order) ; |
555 | if (num_points >= 3) { |
556 | |
557 | // |
558 | // only enter here if there are more than 3 points otherwise |
559 | // it means we have already the tangent |
560 | // |
561 | BuildPeriodicTangent(myPoints->Array1(), |
562 | myTangents->ChangeArray1(), |
563 | myTangentFlags->ChangeArray1(), |
564 | myParameters->Array1()) ; |
565 | } |
566 | contact_order_array.SetValue(2,1) ; |
567 | parameters.SetValue(1,myParameters->Value(1)) ; |
568 | parameters.SetValue(2,myParameters->Value(1)) ; |
569 | poles.SetValue(1,myPoints->Value(1)) ; |
570 | for (jj = 1 ; jj <= 2 ; jj++) { |
571 | a_point.SetCoord(jj,myTangents->Value(1).Coord(jj)) ; |
572 | } |
573 | poles.SetValue(2,a_point) ; |
574 | |
575 | mult_index = 2 ; |
576 | index = 3 ; |
577 | index1 = degree + 2 ; |
578 | if (myTangentRequest) { |
579 | for (ii = myTangentFlags->Lower() + 1 ; |
580 | ii <= myTangentFlags->Upper() ; ii++) { |
581 | parameters.SetValue(index,myParameters->Value(ii)) ; |
582 | flatknots.SetValue(index1,myParameters->Value(ii)) ; |
583 | poles.SetValue(index,myPoints->Value(ii)) ; |
584 | index += 1 ; |
585 | index1 += 1 ; |
586 | if (myTangentFlags->Value(ii)) { |
587 | mults.SetValue(mult_index,mults.Value(mult_index) + 1) ; |
588 | contact_order_array(index) = 1 ; |
589 | |
590 | parameters.SetValue(index, |
591 | myParameters->Value(ii)) ; |
592 | flatknots.SetValue(index1,myParameters->Value(ii)) ; |
593 | for (jj = 1 ; jj <= 2 ; jj++) { |
594 | a_point.SetCoord(jj,myTangents->Value(ii).Coord(jj)) ; |
595 | } |
596 | poles.SetValue(index,a_point) ; |
597 | index += 1 ; |
598 | index1 += 1 ; |
599 | } |
600 | mult_index += 1 ; |
601 | } |
602 | } |
603 | else { |
604 | index = degree + 1 ; |
605 | index1 = 2 ; |
606 | for(ii = myParameters->Lower() ; ii <= myParameters->Upper() ; ii++) { |
607 | parameters.SetValue(index1, |
608 | myParameters->Value(ii)) ; |
609 | flatknots.SetValue(index, |
610 | myParameters->Value(ii)) ; |
611 | index += 1 ; |
612 | index1 += 1 ; |
613 | } |
614 | index = 3 ; |
615 | for (ii = myPoints->Lower() + 1 ; ii <= myPoints->Upper() ; ii++) { |
616 | // |
617 | // copy all the given points since the last one will be initialized |
618 | // below by the first point in the array myPoints |
619 | // |
620 | poles.SetValue(index, |
621 | myPoints->Value(ii)) ; |
622 | index += 1 ; |
623 | } |
624 | |
625 | } |
626 | contact_order_array.SetValue(num_poles - 1, 1) ; |
627 | parameters.SetValue(num_poles-1, |
628 | myParameters->Value(myParameters->Upper())) ; |
629 | // |
630 | // for the periodic curve ONLY the tangent of the first point |
631 | // will be used since the curve should close itself at the first |
632 | // point See BuildPeriodicTangent |
633 | // |
634 | for (jj = 1 ; jj <= 2 ; jj++) { |
635 | a_point.SetCoord(jj,myTangents->Value(1).Coord(jj)) ; |
636 | } |
637 | poles.SetValue(num_poles-1,a_point) ; |
638 | |
639 | parameters.SetValue(num_poles, |
640 | myParameters->Value(myParameters->Upper())) ; |
641 | |
642 | poles.SetValue(num_poles, |
643 | myPoints->Value(1)) ; |
644 | |
645 | |
646 | BSplCLib::Interpolate(degree, |
647 | flatknots, |
648 | parameters, |
649 | contact_order_array, |
650 | poles, |
651 | inversion_problem) ; |
652 | if (!inversion_problem) { |
653 | TColgp_Array1OfPnt2d newpoles(poles.Value(1), |
654 | 1, |
655 | num_poles - 2) ; |
656 | myCurve = |
657 | new Geom2d_BSplineCurve(newpoles, |
658 | myParameters->Array1(), |
659 | mults, |
660 | degree, |
661 | myPeriodic) ; |
662 | myIsDone = Standard_True ; |
663 | } |
664 | } |
665 | } |
666 | |
667 | |
668 | //======================================================================= |
669 | //function : PerformNonPeriodic |
670 | //purpose : |
671 | //======================================================================= |
672 | |
673 | void Geom2dAPI_Interpolate::PerformNonPeriodic() |
674 | { |
675 | Standard_Integer degree, |
676 | ii, |
677 | jj, |
678 | index, |
679 | index1, |
680 | index2, |
681 | index3, |
682 | mult_index, |
683 | inversion_problem, |
684 | num_points, |
685 | num_distinct_knots, |
686 | num_poles ; |
687 | |
688 | gp_Pnt2d a_point ; |
689 | |
690 | num_points = |
691 | num_distinct_knots = |
692 | num_poles = myPoints->Length() ; |
693 | if (num_poles == 2 && !myTangentRequest) { |
694 | degree = 1 ; |
695 | } |
696 | else if (num_poles == 3 && !myTangentRequest) { |
697 | degree = 2 ; |
698 | num_distinct_knots = 2 ; |
699 | } |
700 | else { |
701 | degree = 3 ; |
702 | num_poles += 2 ; |
703 | if (myTangentRequest) |
704 | for (ii = myTangentFlags->Lower() + 1 ; |
705 | ii < myTangentFlags->Upper() ; ii++) { |
706 | if (myTangentFlags->Value(ii)) { |
707 | num_poles += 1 ; |
708 | } |
709 | } |
710 | } |
711 | |
712 | |
713 | TColStd_Array1OfReal parameters(1,num_poles) ; |
714 | TColStd_Array1OfReal flatknots(1,num_poles + degree + 1) ; |
715 | TColStd_Array1OfInteger mults(1,num_distinct_knots) ; |
716 | TColStd_Array1OfReal knots(1,num_distinct_knots) ; |
717 | TColStd_Array1OfInteger contact_order_array(1, num_poles) ; |
718 | TColgp_Array1OfPnt2d poles(1,num_poles) ; |
719 | |
720 | for (ii = 1 ; ii <= degree + 1 ; ii++) { |
721 | flatknots.SetValue(ii,myParameters->Value(1)) ; |
722 | flatknots.SetValue(ii + num_poles, |
723 | myParameters->Value(num_points)) ; |
724 | } |
725 | for (ii = 1 ; ii <= num_poles ; ii++) { |
726 | contact_order_array.SetValue(ii,0) ; |
727 | } |
728 | for (ii = 2 ; ii < num_distinct_knots ; ii++) { |
729 | mults.SetValue(ii,1) ; |
730 | } |
731 | mults.SetValue(1,degree + 1) ; |
732 | mults.SetValue(num_distinct_knots ,degree + 1) ; |
733 | |
734 | switch (degree) { |
735 | case 1: |
736 | for (ii = 1 ; ii <= num_poles ; ii++) { |
737 | poles.SetValue(ii ,myPoints->Value(ii)) ; |
738 | } |
739 | myCurve = |
740 | new Geom2d_BSplineCurve(poles, |
741 | myParameters->Array1(), |
742 | mults, |
743 | degree) ; |
744 | myIsDone = Standard_True ; |
745 | break ; |
746 | case 2: |
747 | knots.SetValue(1,myParameters->Value(1)) ; |
748 | knots.SetValue(2,myParameters->Value(3)) ; |
749 | for (ii = 1 ; ii <= num_poles ; ii++) { |
750 | poles.SetValue(ii,myPoints->Value(ii)) ; |
751 | |
752 | } |
753 | BSplCLib::Interpolate(degree, |
754 | flatknots, |
755 | myParameters->Array1(), |
756 | contact_order_array, |
757 | poles, |
758 | inversion_problem) ; |
759 | if (!inversion_problem) { |
760 | myCurve = |
761 | new Geom2d_BSplineCurve(poles, |
762 | knots, |
763 | mults, |
764 | degree) ; |
765 | myIsDone = Standard_True ; |
766 | } |
767 | break ; |
768 | case 3: |
769 | // |
770 | // check if the boundary conditions are set |
771 | // |
772 | if (num_points >= 3) { |
773 | // |
774 | // cannot build the tangents with degree 3 with only 2 points |
775 | // if those where not given in advance |
776 | // |
777 | BuildTangents(myPoints->Array1(), |
778 | myTangents->ChangeArray1(), |
779 | myTangentFlags->ChangeArray1(), |
780 | myParameters->Array1()) ; |
781 | } |
782 | contact_order_array.SetValue(2,1) ; |
783 | parameters.SetValue(1,myParameters->Value(1)) ; |
784 | parameters.SetValue(2,myParameters->Value(1)) ; |
785 | poles.SetValue(1,myPoints->Value(1)) ; |
786 | for (jj = 1 ; jj <= 2 ; jj++) { |
787 | a_point.SetCoord(jj,myTangents->Value(1).Coord(jj)) ; |
788 | |
789 | } |
790 | poles.SetValue(2,a_point) ; |
791 | mult_index = 2 ; |
792 | index = 3 ; |
793 | index1 = 2 ; |
794 | index2 = myPoints->Lower() + 1 ; |
795 | index3 = degree + 2 ; |
796 | if (myTangentRequest) { |
797 | for (ii = myParameters->Lower() + 1 ; |
798 | ii < myParameters->Upper() ; ii++) { |
799 | parameters.SetValue(index,myParameters->Value(ii)) ; |
800 | poles.SetValue(index,myPoints->Value(index2)) ; |
801 | flatknots.SetValue(index3,myParameters->Value(ii)) ; |
802 | index += 1 ; |
803 | index3 += 1 ; |
804 | if (myTangentFlags->Value(index1)) { |
805 | // |
806 | // set the multiplicities, the order of the contact, the |
807 | // the flatknots, |
808 | // |
809 | mults.SetValue(mult_index,mults.Value(mult_index) + 1) ; |
810 | contact_order_array(index) = 1 ; |
811 | flatknots.SetValue(index3, myParameters->Value(ii)) ; |
812 | parameters.SetValue(index, |
813 | myParameters->Value(ii)) ; |
814 | for (jj = 1 ; jj <= 2 ; jj++) { |
815 | a_point.SetCoord(jj,myTangents->Value(ii).Coord(jj)) ; |
816 | } |
817 | poles.SetValue(index,a_point) ; |
818 | index += 1 ; |
819 | index3 += 1 ; |
820 | } |
821 | mult_index += 1 ; |
822 | index1 += 1 ; |
823 | index2 += 1 ; |
824 | |
825 | } |
826 | } |
827 | else { |
828 | index1 = 2 ; |
829 | for(ii = myParameters->Lower() ; ii <= myParameters->Upper() ; ii++) { |
830 | parameters.SetValue(index1, |
831 | myParameters->Value(ii)) ; |
832 | index1 += 1 ; |
833 | } |
834 | index = 3 ; |
835 | for (ii = myPoints->Lower() + 1 ; ii <= myPoints->Upper() - 1 ; ii++) { |
836 | poles.SetValue(index, |
837 | myPoints->Value(ii)) ; |
838 | index += 1 ; |
839 | } |
840 | |
841 | |
842 | index = degree + 1 ; |
843 | for(ii = myParameters->Lower() ; ii <= myParameters->Upper() ; ii++) { |
844 | flatknots.SetValue(index, |
845 | myParameters->Value(ii)) ; |
846 | index += 1 ; |
847 | } |
848 | } |
849 | for (jj = 1 ; jj <= 2 ; jj++) { |
850 | a_point.SetCoord(jj, |
851 | myTangents->Value(num_points).Coord(jj)) ; |
852 | } |
853 | poles.SetValue(num_poles-1 ,a_point) ; |
854 | |
855 | contact_order_array.SetValue(num_poles - 1,1) ; |
856 | parameters.SetValue(num_poles, |
857 | myParameters->Value(myParameters->Upper())) ; |
858 | parameters.SetValue(num_poles -1, |
859 | myParameters->Value(myParameters->Upper())) ; |
860 | |
861 | poles.SetValue(num_poles, |
862 | myPoints->Value(num_points)) ; |
863 | |
864 | BSplCLib::Interpolate(degree, |
865 | flatknots, |
866 | parameters, |
867 | contact_order_array, |
868 | poles, |
869 | inversion_problem) ; |
870 | if (!inversion_problem) { |
871 | myCurve = |
872 | new Geom2d_BSplineCurve(poles, |
873 | myParameters->Array1(), |
874 | mults, |
875 | degree) ; |
876 | myIsDone = Standard_True ; |
877 | } |
878 | break ; |
879 | |
880 | } |
881 | } |
882 | //======================================================================= |
883 | //function : Handle_Geom2d_BSplineCurve& |
884 | //purpose : |
885 | //======================================================================= |
886 | |
887 | const Handle(Geom2d_BSplineCurve)& Geom2dAPI_Interpolate::Curve() const |
888 | { |
889 | if ( !myIsDone) |
890 | StdFail_NotDone::Raise(" "); |
891 | return myCurve; |
892 | } |
893 | |
894 | |
895 | |
896 | //======================================================================= |
897 | //function : Geom2d_BSplineCurve |
898 | //purpose : |
899 | //======================================================================= |
900 | |
901 | Geom2dAPI_Interpolate::operator Handle(Geom2d_BSplineCurve)() const |
902 | { |
903 | return myCurve; |
904 | } |
905 | |
906 | |
907 | //======================================================================= |
908 | //function : IsDone |
909 | //purpose : |
910 | //======================================================================= |
911 | |
912 | Standard_Boolean Geom2dAPI_Interpolate::IsDone() const |
913 | { |
914 | return myIsDone; |
915 | } |