Changeset 5517 for trunk/psLib/src/math/psSpline.c
- Timestamp:
- Nov 15, 2005, 10:10:32 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psSpline.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psSpline.c
r5180 r5517 7 7 * splines. 8 8 * 9 * @version $Revision: 1.13 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2005- 09-29 20:06:58$9 * @version $Revision: 1.132 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-11-15 20:10:32 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 496 496 PS_ASSERT_VECTOR_NON_NULL(y, NULL); 497 497 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(y, NULL); 498 PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(y->n, 2, NULL); 498 499 psS32 numSplines = (y->n)-1; 499 500 psTrace(__func__, 5, "numSplines is %d\n", numSplines); 501 502 // 503 // Create the psSpline1D struct. 504 // 505 psSpline1D *spline = psSpline1DAlloc(); 506 spline->n = numSplines; 507 spline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *)); 508 for (psS32 i=0;i<numSplines;i++) { 509 spline->spline[i] = psPolynomial1DAlloc(3, PS_POLYNOMIAL_ORD); 510 } 511 500 512 // 501 513 // The following code ensures that xPtr and yPtr points to a psF32 psVector. 502 514 // 503 psVector *xPtr = NULL; 515 // XXX: When you debug, use the vector copy and create routines here: 516 // 517 518 spline->knots = psVectorAlloc(y->n, PS_TYPE_F32); 504 519 if (x != NULL) { 505 520 PS_ASSERT_VECTOR_NON_NULL(x, NULL); 521 PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, NULL); 506 522 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(x, NULL); 507 PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, NULL); 508 // Convert x to F32 if necessary. 509 if (PS_TYPE_F64 == x->type.type) { 510 xPtr = psVectorCopy(NULL, x, PS_TYPE_F32); 511 } else if (PS_TYPE_F32 == x->type.type) { 512 xPtr = (psVector *) x; 523 if (x->type.type == PS_TYPE_F32) { 524 for (psS32 i = 0 ; i < x->n ; i++) { 525 spline->knots->data.F32[i] = x->data.F32[i]; 526 } 527 } else if (x->type.type == PS_TYPE_F64) { 528 for (psS32 i = 0 ; i < x->n ; i++) { 529 spline->knots->data.F32[i] = (psF32) x->data.F64[i]; 530 } 513 531 } 514 532 } else { 515 // Allocate an index vector for x 516 xPtr = psVectorCreate(NULL, 0.0, (psF64) y->n, 1.0, PS_TYPE_F32); 517 } 533 for (psS32 i = 0 ; i < y->n ; i++) { 534 spline->knots->data.F32[i] = (psF32) i; 535 } 536 } 537 psVector *xPtr = spline->knots; 518 538 519 539 psVector *yPtr = NULL; … … 526 546 527 547 // 528 // Create the psSpline1D struct.529 //530 psSpline1D *spline = psSpline1DAlloc();531 spline->n = numSplines;532 spline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));533 for (psS32 i=0;i<numSplines;i++) {534 spline->spline[i] = psPolynomial1DAlloc(3, PS_POLYNOMIAL_ORD);535 }536 spline->knots = psVectorCopy(NULL, xPtr, PS_TYPE_F32);537 //538 548 // Generate the second derivatives at each data point. 539 549 // … … 548 558 psF32 H = xPtr->data.F32[i+1] - xPtr->data.F32[i]; 549 559 if (fabs(H) <= FLT_EPSILON) { 550 psError(PS_ERR_UNKNOWN, false, "x data points are not distinct (%d %d).\n", i, i+1); 560 psError(PS_ERR_UNKNOWN, false, "x data points are not distinct (%d %d) (%f %f).\n", 561 i, i+1, xPtr->data.F32[i], xPtr->data.F32[i+1]); 551 562 } 552 563 psTrace(__func__, 6, "x data (%f - %f) (%f)\n", xPtr->data.F32[i], xPtr->data.F32[i+1], H); … … 609 620 } 610 621 611 if ((x == NULL) || (PS_TYPE_F64 == x->type.type)) {612 psFree(xPtr);613 }614 622 if (PS_TYPE_F64 == y->type.type) { 615 623 psFree(yPtr); … … 618 626 return(spline); 619 627 } 628 629 void PS_POLY1D_PRINT( 630 psPolynomial1D *poly) 631 { 632 printf("-------------- PS_POLY1D_PRINT() --------------\n"); 633 printf("poly->nX is %d\n", poly->nX); 634 for (psS32 i = 0 ; i < (1 + poly->nX) ; i++) { 635 printf("poly->coeff[%d] is %f\n", i, poly->coeff[i]); 636 } 637 } 638 639 void PS_PRINT_SPLINE2(psSpline1D *mySpline) 640 { 641 printf("-------------- PS_PRINT_SPLINE2() --------------\n"); 642 printf("mySpline->n is %d\n", mySpline->n); 643 for (psS32 i = 0 ; i < mySpline->n ; i++) { 644 PS_POLY1D_PRINT(mySpline->spline[i]); 645 } 646 PS_VECTOR_PRINT_F32(mySpline->knots); 647 } 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 620 683 621 684 … … 650 713 // 651 714 psLogMsg(__func__, PS_LOG_WARN, 652 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).", 653 x, spline->knots->data.F32[0], 654 spline->knots->data.F32[n-1]); 715 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).", 716 x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n); 655 717 656 718 if (x < spline->knots->data.F32[0]) {
Note:
See TracChangeset
for help on using the changeset viewer.
