Changeset 5066 for trunk/psLib/src/math/psSpline.c
- Timestamp:
- Sep 19, 2005, 9:53:13 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psSpline.c (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psSpline.c
r4991 r5066 7 7 * splines. 8 8 * 9 * @version $Revision: 1.12 3$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-09-1 1 22:18:40$9 * @version $Revision: 1.124 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-09-19 19:53:13 $ 11 11 * 12 12 * … … 43 43 /*****************************************************************************/ 44 44 static void spline1DFree(psSpline1D *tmpSpline); 45 static psS32vectorBinDisectF32(psF32 *bins,psS32 numBins,psF32 x);46 static psS32vectorBinDisectS32(psS32 *bins,psS32 numBins,psS32 x);45 static unsigned int vectorBinDisectF32(psF32 *bins,psS32 numBins,psF32 x); 46 static unsigned int vectorBinDisectS32(psS32 *bins,psS32 numBins,psS32 x); 47 47 48 48 /*****************************************************************************/ … … 69 69 static void spline1DFree(psSpline1D *tmpSpline) 70 70 { 71 psS32i;71 unsigned int i; 72 72 73 73 if (tmpSpline == NULL) { … … 101 101 static psF32 fullInterpolate1D##TYPE(ps##TYPE *domain, \ 102 102 ps##TYPE *range, \ 103 psS32n, \103 unsigned int n, \ 104 104 ps##TYPE x) \ 105 105 { \ 106 106 \ 107 psS32i; \108 psS32m; \107 unsigned int i; \ 108 unsigned int m; \ 109 109 static psVector *p = NULL; \ 110 110 p = psVectorRecycle(p, n, PS_TYPE_##TYPE); \ … … 169 169 static psF32 interpolate1DF32(psF32 *domain, 170 170 psF32 *range, 171 psS32n,172 psS32order,171 unsigned int n, 172 unsigned int order, 173 173 psF32 x) 174 174 { … … 178 178 179 179 psS32 binNum; 180 psS32numIntPoints = order+1;180 unsigned int numIntPoints = order+1; 181 181 psS32 origin; 182 182 … … 229 229 "---- calculateSecondDerivs() begin ----\n"); 230 230 231 psS32i;232 psS32k;231 unsigned int i; 232 unsigned int k; 233 233 psF32 sig; 234 234 psF32 p; 235 psS32n = y->n;235 unsigned int n = y->n; 236 236 psF32 *u = (psF32 *) psAlloc(n * sizeof(psF32)); 237 237 psF32 *derivs2 = (psF32 *) psAlloc(n * sizeof(psF32)); … … 253 253 254 254 psTrace(".psLib.dataManip.calculateSecondDerivs", 6, 255 "X[% d] is %f\n", i, X[i]);255 "X[%u] is %f\n", i, X[i]); 256 256 psTrace(".psLib.dataManip.calculateSecondDerivs", 6, 257 "Y[% d] is %f\n", i, Y[i]);257 "Y[%u] is %f\n", i, Y[i]); 258 258 psTrace(".psLib.dataManip.calculateSecondDerivs", 6, 259 "u[% d] is %f\n", i, u[i]);259 "u[%u] is %f\n", i, u[i]); 260 260 } 261 261 … … 268 268 269 269 psTrace(".psLib.dataManip.calculateSecondDerivs", 6, 270 "derivs2[% d] is %f\n", k, derivs2[k]);270 "derivs2[%u] is %f\n", k, derivs2[k]); 271 271 } 272 272 … … 314 314 XXX: Assumes mySpline->knots is psF32. Must add psU32 and psF64. 315 315 *****************************************************************************/ 316 psSpline1D *psVectorFitSpline1D(psSpline1D * mySpline, ///< The spline which will be generated.316 psSpline1D *psVectorFitSpline1D(psSpline1D *spline, ///< The spline which will be generated. 317 317 const psVector* x, ///< Ordinates (or NULL to just use the indices) 318 318 const psVector* y, ///< Coordinates … … 321 321 PS_ASSERT_VECTOR_NON_NULL(y, NULL); 322 322 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(y, NULL); 323 if ( mySpline != NULL) {324 PS_ASSERT_VECTOR_TYPE( mySpline->knots, PS_TYPE_F32, NULL);323 if (spline != NULL) { 324 PS_ASSERT_VECTOR_TYPE(spline->knots, PS_TYPE_F32, NULL); 325 325 } 326 326 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 327 327 "---- psVectorFitSpline1D() begin ----\n"); 328 psS32numSplines = (y->n)-1;328 unsigned int numSplines = (y->n)-1; 329 329 psF32 tmp; 330 330 psF32 H; 331 psS32i;331 unsigned int i; 332 332 psF32 slope; 333 333 psVector *x32 = NULL; … … 364 364 This can not be implemented until SDR states what order spline should be 365 365 created. 366 Should we error if mySpline is not NULL?366 Should we error if spline is not NULL? 367 367 Should we error if mySPline is not NULL? 368 368 */ 369 if ( mySpline == NULL) {370 mySpline = psSpline1DAllocGeneric(x32, 3);371 } 372 PS_ASSERT_PTR_NON_NULL( mySpline, NULL);373 PS_ASSERT_INT_NONNEGATIVE( mySpline->n, NULL);374 375 if (y32->n != (1 + mySpline->n)) {369 if (spline == NULL) { 370 spline = psSpline1DAllocGeneric(x32, 3); 371 } 372 PS_ASSERT_PTR_NON_NULL(spline, NULL); 373 PS_ASSERT_INT_NONNEGATIVE(spline->n, NULL); 374 375 if (y32->n != (1 + spline->n)) { 376 376 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 377 "data size / spline size mismatch (% d %d)\n",378 y32->n, mySpline->n);377 "data size / spline size mismatch (%u %u)\n", 378 y32->n, spline->n); 379 379 return(NULL); 380 380 } … … 382 382 // If these are linear splines, which means their polynomials will have 383 383 // two coefficients, then we do the simple calculation. 384 if (2 == (mySpline->spline[0])->n) { 384 if (2 == (spline->spline[0])->n) { 385 for (i=0;i<spline->n;i++) { 386 slope = (y32->data.F32[i+1] - y32->data.F32[i]) / 387 (spline->knots->data.F32[i+1] - spline->knots->data.F32[i]); 388 (spline->spline[i])->coeff[0] = y32->data.F32[i] - 389 (slope * spline->knots->data.F32[i]); 390 391 (spline->spline[i])->coeff[1] = slope; 392 psTrace(".psLib.dataManip.psMinimize.psVectorFitSpline1D", 4, 393 "---- spline %u coeffs are (%f, %f)\n", i, 394 (spline->spline[i])->coeff[0], 395 (spline->spline[i])->coeff[1]); 396 } 397 psTrace(".psLib.dataManip.psMinimize.psVectorFitSpline1D", 4, 398 "---- Exiting psVectorFitSpline1D()()\n"); 399 return((psSpline1D *) spline); 400 } 401 402 // Check if these are cubic splines (n==4). If not, psError. 403 if (4 != (spline->spline[0])->n) { 404 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 405 "Don't know how to generate %u-order splines.", 406 (spline->spline[0])->n-1); 407 return(NULL); 408 } 409 410 // If we get here, then we know these are cubic splines. We first 411 // generate the second derivatives at each data point. 412 spline->p_psDeriv2 = calculateSecondDerivs(x32, y32); 413 for (i=0;i<y32->n;i++) 414 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 415 "Second deriv[%u] is %f\n", i, spline->p_psDeriv2[i]); 416 417 // We generate the coefficients of the spline polynomials. I can't 418 // concisely explain how this code works. See above function comments 419 // and Numerical Recipes in C. 420 for (i=0;i<numSplines;i++) { 421 H = x32->data.F32[i+1] - x32->data.F32[i]; 422 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 423 "x data (%f - %f) (%f)\n", 424 x32->data.F32[i], 425 x32->data.F32[i+1], H); 426 // 427 // ******** Calculate 0-order term ******** 428 // 429 // From (1) 430 (spline->spline[i])->coeff[0] = (y32->data.F32[i] * x32->data.F32[i+1]/H); 431 // From (2) 432 ((spline->spline[i])->coeff[0])-= ((y32->data.F32[i+1] * x32->data.F32[i])/H); 433 // From (3) 434 tmp = (x32->data.F32[i+1] * x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H); 435 tmp-= (x32->data.F32[i+1] / H); 436 tmp*= (spline->p_psDeriv2)[i] * H * H / 6.0; 437 ((spline->spline[i])->coeff[0])+= tmp; 438 // From (4) 439 tmp = -(x32->data.F32[i] * x32->data.F32[i] * x32->data.F32[i]) / (H * H * H); 440 tmp+= (x32->data.F32[i] / H); 441 tmp*= (spline->p_psDeriv2)[i+1] * H * H / 6.0; 442 ((spline->spline[i])->coeff[0])+= tmp; 443 444 // 445 // ******** Calculate 1-order term ******** 446 // 447 // From (1) 448 (spline->spline[i])->coeff[1] = -(y32->data.F32[i]) / H; 449 // From (2) 450 ((spline->spline[i])->coeff[1])+= (y32->data.F32[i+1] / H); 451 // From (3) 452 tmp = -3.0 * (x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H); 453 tmp+= (1.0 / H); 454 tmp*= ((spline->p_psDeriv2)[i]) * H * H / 6.0; 455 ((spline->spline[i])->coeff[1])+= tmp; 456 // From (4) 457 tmp = 3.0 * (x32->data.F32[i] * x32->data.F32[i]) / (H * H * H); 458 tmp-= (1.0 / H); 459 tmp*= ((spline->p_psDeriv2)[i+1]) * H * H / 6.0; 460 ((spline->spline[i])->coeff[1])+= tmp; 461 462 // 463 // ******** Calculate 2-order term ******** 464 // 465 // From (3) 466 (spline->spline[i])->coeff[2] = ((spline->p_psDeriv2)[i]) * 3.0 * x32->data.F32[i+1] / (6.0 * H); 467 // From (4) 468 ((spline->spline[i])->coeff[2])-= (((spline->p_psDeriv2)[i+1]) * 3.0 * x32->data.F32[i] / (6.0 * H)); 469 470 // 471 // ******** Calculate 3-order term ******** 472 // 473 // From (3) 474 (spline->spline[i])->coeff[3] = -((spline->p_psDeriv2)[i]) / (6.0 * H); 475 // From (4) 476 ((spline->spline[i])->coeff[3])+= ((spline->p_psDeriv2)[i+1]) / (6.0 * H); 477 478 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 479 "(spline->spline[%u])->coeff[0] is %f\n", i, (spline->spline[i])->coeff[0]); 480 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 481 "(spline->spline[%u])->coeff[1] is %f\n", i, (spline->spline[i])->coeff[1]); 482 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 483 "(spline->spline[%u])->coeff[2] is %f\n", i, (spline->spline[i])->coeff[2]); 484 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 485 "(spline->spline[%u])->coeff[3] is %f\n", i, (spline->spline[i])->coeff[3]); 486 487 } 488 489 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 490 "---- psVectorFitSpline1D() end ----\n"); 491 return(spline); 492 } 493 494 495 496 497 498 499 500 501 502 /***************************************************************************** 503 psVectorFitSpline1DNEW(): given a psSpline1D data structure and a set of x/y 504 505 xF32 and yF32 are internal psVectors which are used to hold the psF32 versions 506 of the input data, if necessary. xPtr and yPtr are pointers to either xF32 or 507 the x argument. All computation is done on xPtr and yPtr. xF32 and yF32 will 508 simply be psFree() at the end. 509 510 XXX: nKnots makes no sense. This number is always equal to the size of the x 511 an y vectors. 512 513 XXX: How do we specify the spline order? For now, order=3. 514 *****************************************************************************/ 515 #define PS_XXX_SPLINE_ORDER 3 516 psSpline1D *psVectorFitSpline1DNEW(const psVector* x, ///< Ordinates (or NULL to just use the indices) 517 const psVector* y, ///< Coordinates 518 unsigned int nKnots) 519 { 520 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, "---- psVectorFitSpline1DNEW() begin ----\n"); 521 PS_ASSERT_VECTOR_NON_NULL(y, NULL); 522 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(y, NULL); 523 // PS_ASSERT_INT_EQUAL(y->n, nKnots); 524 525 // 526 // The following code ensures that xPtr points to a psF32 version of the 527 // ordinate data. 528 // 529 psVector *xF32 = NULL; 530 psVector *xPtr = NULL; 531 if (x != NULL) { 532 PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, NULL); 533 if (PS_TYPE_F64 == x->type.type) { 534 xF32 = psVectorAlloc(y->n, PS_TYPE_F32); 535 for (unsigned int i = 0 ; i < x->n ; i++) { 536 xF32->data.F32[i] = (psF32) x->data.F64[i]; 537 } 538 xPtr = xF32; 539 } else if (PS_TYPE_F32 == x->type.type) { 540 xPtr = (psVector *) x; 541 } else { 542 psError(PS_ERR_UNKNOWN, true, "psVector x is wrong type.\n"); 543 return(NULL); 544 } 545 } else { 546 // If x==NULL, create an x32 vector with x values set to (0:n). 547 xF32 = psVectorAlloc(y->n, PS_TYPE_F32); 548 for (unsigned int i = 0 ; i < x->n ; i++) { 549 xF32->data.F32[i] = (psF32) i; 550 } 551 xPtr = xF32; 552 } 553 554 // 555 // If y is of type psF64, then create a new vector yF32 and convert the 556 // y elements. Regardless of y's type, we create a yPtr which will be 557 // used in the remainder of this function. 558 // 559 psVector *yF32 = NULL; 560 psVector *yPtr = NULL; 561 if (PS_TYPE_F64 == y->type.type) { 562 yF32 = psVectorAlloc(y->n, PS_TYPE_F32); 563 for (unsigned int i = 0 ; i < y->n ; i++) { 564 yF32->data.F32[i] = (psF32) y->data.F64[i]; 565 } 566 yPtr = yF32; 567 } else { 568 yPtr = (psVector *) y; 569 } 570 571 psSpline1D *mySpline = psSpline1DAllocGeneric(xPtr, PS_XXX_SPLINE_ORDER); 572 573 unsigned int numSplines = nKnots - 1; 574 psF32 tmp; 575 psF32 H; 576 unsigned int i; 577 psF32 slope; 578 // XXX: get rid of x32 and y32 (this is from old code) 579 psVector *x32 = xPtr; 580 psVector *y32 = yPtr; 581 582 // If these are linear splines, which means their polynomials will have 583 // two coefficients, then we do the simple calculation. 584 if (1 == PS_XXX_SPLINE_ORDER) { 385 585 for (i=0;i<mySpline->n;i++) { 386 586 slope = (y32->data.F32[i+1] - y32->data.F32[i]) / … … 391 591 (mySpline->spline[i])->coeff[1] = slope; 392 592 psTrace(".psLib.dataManip.psMinimize.psVectorFitSpline1D", 4, 393 "---- mySpline % dcoeffs are (%f, %f)\n", i,593 "---- mySpline %u coeffs are (%f, %f)\n", i, 394 594 (mySpline->spline[i])->coeff[0], 395 595 (mySpline->spline[i])->coeff[1]); … … 400 600 } 401 601 602 // 402 603 // Check if these are cubic splines (n==4). If not, psError. 403 if (4 != (mySpline->spline[0])->n) { 604 // 605 if (3 != PS_XXX_SPLINE_ORDER) { 404 606 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 405 "Don't know how to generate %d-order splines.", 406 (mySpline->spline[0])->n-1); 607 "Don't know how to generate %d-order splines.", PS_XXX_SPLINE_ORDER); 407 608 return(NULL); 408 609 } 409 610 611 // 410 612 // If we get here, then we know these are cubic splines. We first 411 613 // generate the second derivatives at each data point. 614 // 412 615 mySpline->p_psDeriv2 = calculateSecondDerivs(x32, y32); 413 616 for (i=0;i<y32->n;i++) 414 617 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 415 "Second deriv[%d] is %f\n", i, mySpline->p_psDeriv2[i]); 416 618 "Second deriv[%u] is %f\n", i, mySpline->p_psDeriv2[i]); 619 620 // 417 621 // We generate the coefficients of the spline polynomials. I can't 418 622 // concisely explain how this code works. See above function comments 419 623 // and Numerical Recipes in C. 624 // 420 625 for (i=0;i<numSplines;i++) { 421 626 H = x32->data.F32[i+1] - x32->data.F32[i]; … … 477 682 478 683 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 479 "(mySpline->spline[% d])->coeff[0] is %f\n", i, (mySpline->spline[i])->coeff[0]);684 "(mySpline->spline[%u])->coeff[0] is %f\n", i, (mySpline->spline[i])->coeff[0]); 480 685 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 481 "(mySpline->spline[% d])->coeff[1] is %f\n", i, (mySpline->spline[i])->coeff[1]);686 "(mySpline->spline[%u])->coeff[1] is %f\n", i, (mySpline->spline[i])->coeff[1]); 482 687 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 483 "(mySpline->spline[% d])->coeff[2] is %f\n", i, (mySpline->spline[i])->coeff[2]);688 "(mySpline->spline[%u])->coeff[2] is %f\n", i, (mySpline->spline[i])->coeff[2]); 484 689 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 485 "(mySpline->spline[%d])->coeff[3] is %f\n", i, (mySpline->spline[i])->coeff[3]); 486 487 } 488 489 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 490 "---- psVectorFitSpline1D() end ----\n"); 491 return(mySpline); 492 } 493 494 495 496 497 498 499 500 501 502 /***************************************************************************** 503 psVectorFitSpline1DNEW(): given a psSpline1D data structure and a set of x/y 504 505 xF32 and yF32 are internal psVectors which are used to hold the psF32 versions 506 of the input data, if necessary. xPtr and yPtr are pointers to either xF32 or 507 the x argument. All computation is done on xPtr and yPtr. xF32 and yF32 will 508 simply be psFree() at the end. 509 510 XXX: nKnots makes no sense. This number is always equal to the size of the x 511 an y vectors. 512 513 XXX: How do we specify the spline order? For now, order=3. 514 *****************************************************************************/ 515 #define PS_XXX_SPLINE_ORDER 3 516 psSpline1D *psVectorFitSpline1DNEW(const psVector* x, ///< Ordinates (or NULL to just use the indices) 517 const psVector* y, ///< Coordinates 518 int nKnots) 519 { 520 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, "---- psVectorFitSpline1DNEW() begin ----\n"); 521 PS_ASSERT_VECTOR_NON_NULL(y, NULL); 522 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(y, NULL); 523 // PS_ASSERT_INT_EQUAL(y->n, nKnots); 524 525 // 526 // The following code ensures that xPtr points to a psF32 version of the 527 // ordinate data. 528 // 529 psVector *xF32 = NULL; 530 psVector *xPtr = NULL; 531 if (x != NULL) { 532 PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, NULL); 533 if (PS_TYPE_F64 == x->type.type) { 534 xF32 = psVectorAlloc(y->n, PS_TYPE_F32); 535 for (psS32 i = 0 ; i < x->n ; i++) { 536 xF32->data.F32[i] = (psF32) x->data.F64[i]; 537 } 538 xPtr = xF32; 539 } else if (PS_TYPE_F32 == x->type.type) { 540 xPtr = (psVector *) x; 541 } else { 542 psError(PS_ERR_UNKNOWN, true, "psVector x is wrong type.\n"); 543 return(NULL); 544 } 545 } else { 546 // If x==NULL, create an x32 vector with x values set to (0:n). 547 xF32 = psVectorAlloc(y->n, PS_TYPE_F32); 548 for (psS32 i = 0 ; i < x->n ; i++) { 549 xF32->data.F32[i] = (psF32) i; 550 } 551 xPtr = xF32; 552 } 553 554 // 555 // If y is of type psF64, then create a new vector yF32 and convert the 556 // y elements. Regardless of y's type, we create a yPtr which will be 557 // used in the remainder of this function. 558 // 559 psVector *yF32 = NULL; 560 psVector *yPtr = NULL; 561 if (PS_TYPE_F64 == y->type.type) { 562 yF32 = psVectorAlloc(y->n, PS_TYPE_F32); 563 for (psS32 i = 0 ; i < y->n ; i++) { 564 yF32->data.F32[i] = (psF32) y->data.F64[i]; 565 } 566 yPtr = yF32; 567 } else { 568 yPtr = (psVector *) y; 569 } 570 571 psSpline1D *mySpline = psSpline1DAllocGeneric(xPtr, PS_XXX_SPLINE_ORDER); 572 573 psS32 numSplines = nKnots - 1; 574 psF32 tmp; 575 psF32 H; 576 psS32 i; 577 psF32 slope; 578 // XXX: get rid of x32 and y32 (this is from old code) 579 psVector *x32 = xPtr; 580 psVector *y32 = yPtr; 581 582 // If these are linear splines, which means their polynomials will have 583 // two coefficients, then we do the simple calculation. 584 if (1 == PS_XXX_SPLINE_ORDER) { 585 for (i=0;i<mySpline->n;i++) { 586 slope = (y32->data.F32[i+1] - y32->data.F32[i]) / 587 (mySpline->knots->data.F32[i+1] - mySpline->knots->data.F32[i]); 588 (mySpline->spline[i])->coeff[0] = y32->data.F32[i] - 589 (slope * mySpline->knots->data.F32[i]); 590 591 (mySpline->spline[i])->coeff[1] = slope; 592 psTrace(".psLib.dataManip.psMinimize.psVectorFitSpline1D", 4, 593 "---- mySpline %d coeffs are (%f, %f)\n", i, 594 (mySpline->spline[i])->coeff[0], 595 (mySpline->spline[i])->coeff[1]); 596 } 597 psTrace(".psLib.dataManip.psMinimize.psVectorFitSpline1D", 4, 598 "---- Exiting psVectorFitSpline1D()()\n"); 599 return((psSpline1D *) mySpline); 600 } 601 602 // 603 // Check if these are cubic splines (n==4). If not, psError. 604 // 605 if (3 != PS_XXX_SPLINE_ORDER) { 606 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 607 "Don't know how to generate %d-order splines.", PS_XXX_SPLINE_ORDER); 608 return(NULL); 609 } 610 611 // 612 // If we get here, then we know these are cubic splines. We first 613 // generate the second derivatives at each data point. 614 // 615 mySpline->p_psDeriv2 = calculateSecondDerivs(x32, y32); 616 for (i=0;i<y32->n;i++) 617 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 618 "Second deriv[%d] is %f\n", i, mySpline->p_psDeriv2[i]); 619 620 // 621 // We generate the coefficients of the spline polynomials. I can't 622 // concisely explain how this code works. See above function comments 623 // and Numerical Recipes in C. 624 // 625 for (i=0;i<numSplines;i++) { 626 H = x32->data.F32[i+1] - x32->data.F32[i]; 627 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 628 "x data (%f - %f) (%f)\n", 629 x32->data.F32[i], 630 x32->data.F32[i+1], H); 631 // 632 // ******** Calculate 0-order term ******** 633 // 634 // From (1) 635 (mySpline->spline[i])->coeff[0] = (y32->data.F32[i] * x32->data.F32[i+1]/H); 636 // From (2) 637 ((mySpline->spline[i])->coeff[0])-= ((y32->data.F32[i+1] * x32->data.F32[i])/H); 638 // From (3) 639 tmp = (x32->data.F32[i+1] * x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H); 640 tmp-= (x32->data.F32[i+1] / H); 641 tmp*= (mySpline->p_psDeriv2)[i] * H * H / 6.0; 642 ((mySpline->spline[i])->coeff[0])+= tmp; 643 // From (4) 644 tmp = -(x32->data.F32[i] * x32->data.F32[i] * x32->data.F32[i]) / (H * H * H); 645 tmp+= (x32->data.F32[i] / H); 646 tmp*= (mySpline->p_psDeriv2)[i+1] * H * H / 6.0; 647 ((mySpline->spline[i])->coeff[0])+= tmp; 648 649 // 650 // ******** Calculate 1-order term ******** 651 // 652 // From (1) 653 (mySpline->spline[i])->coeff[1] = -(y32->data.F32[i]) / H; 654 // From (2) 655 ((mySpline->spline[i])->coeff[1])+= (y32->data.F32[i+1] / H); 656 // From (3) 657 tmp = -3.0 * (x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H); 658 tmp+= (1.0 / H); 659 tmp*= ((mySpline->p_psDeriv2)[i]) * H * H / 6.0; 660 ((mySpline->spline[i])->coeff[1])+= tmp; 661 // From (4) 662 tmp = 3.0 * (x32->data.F32[i] * x32->data.F32[i]) / (H * H * H); 663 tmp-= (1.0 / H); 664 tmp*= ((mySpline->p_psDeriv2)[i+1]) * H * H / 6.0; 665 ((mySpline->spline[i])->coeff[1])+= tmp; 666 667 // 668 // ******** Calculate 2-order term ******** 669 // 670 // From (3) 671 (mySpline->spline[i])->coeff[2] = ((mySpline->p_psDeriv2)[i]) * 3.0 * x32->data.F32[i+1] / (6.0 * H); 672 // From (4) 673 ((mySpline->spline[i])->coeff[2])-= (((mySpline->p_psDeriv2)[i+1]) * 3.0 * x32->data.F32[i] / (6.0 * H)); 674 675 // 676 // ******** Calculate 3-order term ******** 677 // 678 // From (3) 679 (mySpline->spline[i])->coeff[3] = -((mySpline->p_psDeriv2)[i]) / (6.0 * H); 680 // From (4) 681 ((mySpline->spline[i])->coeff[3])+= ((mySpline->p_psDeriv2)[i+1]) / (6.0 * H); 682 683 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 684 "(mySpline->spline[%d])->coeff[0] is %f\n", i, (mySpline->spline[i])->coeff[0]); 685 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 686 "(mySpline->spline[%d])->coeff[1] is %f\n", i, (mySpline->spline[i])->coeff[1]); 687 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 688 "(mySpline->spline[%d])->coeff[2] is %f\n", i, (mySpline->spline[i])->coeff[2]); 689 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 690 "(mySpline->spline[%d])->coeff[3] is %f\n", i, (mySpline->spline[i])->coeff[3]); 690 "(mySpline->spline[%u])->coeff[3] is %f\n", i, (mySpline->spline[i])->coeff[3]); 691 691 692 692 } … … 726 726 XXX: What should be the default type for knots be? psF32 is assumed. 727 727 *****************************************************************************/ 728 psSpline1D *psSpline1DAlloc( int numSplines,729 int order,728 psSpline1D *psSpline1DAlloc(unsigned int numSplines, 729 unsigned int order, 730 730 float min, 731 731 float max) … … 743 743 // 744 744 tmpSpline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *)); 745 for ( psS32i=0;i<numSplines;i++) {745 for (unsigned int i=0;i<numSplines;i++) { 746 746 (tmpSpline->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD); 747 747 } … … 756 756 psF32 width = (max - min) / ((psF32) numSplines); 757 757 tmpSpline->knots->data.F32[0] = min; 758 for ( psS32i=1;i<numSplines;i++) {758 for (unsigned int i=1;i<numSplines;i++) { 759 759 tmpSpline->knots->data.F32[i] = min + (width * (psF32) i); 760 760 } … … 773 773 774 774 if (in->type.type == PS_TYPE_F32) { 775 for ( psS32i = 0 ; i < in->n ; i++) {775 for (unsigned int i = 0 ; i < in->n ; i++) { 776 776 out->data.F32[i] = in->data.F32[i]; 777 777 } 778 778 } else if (in->type.type == PS_TYPE_F64) { 779 for ( psS32i = 0 ; i < in->n ; i++) {779 for (unsigned int i = 0 ; i < in->n ; i++) { 780 780 out->data.F64[i] = in->data.F64[i]; 781 781 } … … 791 791 *****************************************************************************/ 792 792 psSpline1D *psSpline1DAllocGeneric(const psVector *bounds, 793 int order)793 unsigned int order) 794 794 { 795 795 PS_ASSERT_VECTOR_NON_NULL(bounds, NULL); … … 799 799 800 800 psSpline1D *tmpSpline = (psSpline1D *) psAlloc(sizeof(psSpline1D)); 801 psS32numSplines = bounds->n - 1;801 unsigned int numSplines = bounds->n - 1; 802 802 tmpSpline->n = numSplines; 803 803 … … 807 807 // 808 808 tmpSpline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *)); 809 for ( psS32i=0;i<numSplines;i++) {809 for (unsigned int i=0;i<numSplines;i++) { 810 810 (tmpSpline->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD); 811 811 } … … 818 818 // XXX:Ensure that the knots are monotonic. 819 819 // 820 for ( psS32i=0;i<bounds->n-1;i++) {820 for (unsigned int i=0;i<bounds->n-1;i++) { 821 821 if (FLT_EPSILON >= fabs(bounds->data.F32[i+1]-bounds->data.F32[i])) { 822 822 psError(PS_ERR_UNKNOWN, true, "data points must be distinct ([%d] %f %f)\n", i, bounds->data.F32[i], bounds->data.F32[i+1]); … … 839 839 *****************************************************************************/ 840 840 #define FUNC_MACRO_VECTOR_BIN_DISECT(TYPE) \ 841 static psS32vectorBinDisect##TYPE(ps##TYPE *bins, \842 psS32 numBins, \843 ps##TYPE x) \841 static unsigned int vectorBinDisect##TYPE(ps##TYPE *bins, \ 842 psS32 numBins, \ 843 ps##TYPE x) \ 844 844 { \ 845 845 psS32 min; \ … … 906 906 XXX: Assert that the psVector and psScalar have the same type. 907 907 *****************************************************************************/ 908 psS32p_psVectorBinDisect(psVector *bins,909 psScalar *x)908 unsigned int p_psVectorBinDisect(psVector *bins, 909 psScalar *x) 910 910 { 911 911 PS_ASSERT_VECTOR_NON_NULL(bins, -4); … … 972 972 psScalar *p_psVectorInterpolate(psVector *domain, 973 973 psVector *range, 974 int order,974 unsigned int order, 975 975 psScalar *x) 976 976 {
Note:
See TracChangeset
for help on using the changeset viewer.
