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