IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 23, 2007, 2:06:32 PM (19 years ago)
Author:
Paul Price
Message:

Fixing RINGS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtractionKernels.c

    r14363 r14366  
    517517
    518518    int fibNum = 0;                     // Number of Fibonacci values
    519     int fibLast = 1, fibTotal = 2;      // Fibonacci sequence
    520     while (fibTotal < size - inner) {
    521         int temp = fibTotal;
    522         fibTotal += fibLast;
    523         fibLast = temp;
    524         fibNum++;
     519    {
     520        int fibIndex = 1, fibIndexMinus1 = 0; // Fibonnacci parameters
     521        int radius = inner;
     522        while (radius < size) {
     523            radius++;
     524            int fibNew = fibIndex + fibIndexMinus1;
     525            fibIndexMinus1 = fibIndex;
     526            fibIndex = fibNew;
     527            radius += fibIndex;
     528            fibNum++;
     529            printf("%d ", radius);
     530        }
     531        printf("\n");
    525532    }
    526533
     
    534541    int num = (numRings * numPoly + 1) * numSpatial; // Total number of basis functions
    535542
    536     pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_GUNK,
     543    pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_RINGS,
    537544                                                              size, spatialOrder); // The kernels
    538545
    539     psLogMsg("psModules.imcombine", PS_LOG_INFO, "RINGS kernel: %d,%d,%d --> %d elements",
    540              size, ringsOrder, spatialOrder, num);
     546    psLogMsg("psModules.imcombine", PS_LOG_INFO, "RINGS kernel: %d,%d,%d,%d --> %d elements",
     547             size, inner, ringsOrder, spatialOrder, num);
    541548
    542549    kernels->preCalc = psArrayAlloc(num);
    543550
    544551    // Set the Gaussian kernel parameters
    545     int fibIndex = 1, fibIndexMinus1 = 1; // Fibonnacci parameters
     552    int fibIndex = 1, fibIndexMinus1 = 0; // Fibonnacci parameters
    546553    int radiusLast = 0;                 // Last radius
    547     for (int i = 0, index = 0; i < numRings; i++) {
     554    for (int i = 0, index = 0; i < numRings + 1; i++) {
     555
     556        float lower2;           // Lower limit of radius^2
     557        float upper2;           // Upper limit of radius^2
     558        if (i == 0) {
     559            lower2 = 0;
     560            upper2 = PS_SQR(0.5);
     561        } else if (i <= numInner) {
     562            // A ring every pixel width
     563            float radius = i;
     564            lower2 = PS_SQR(radius - 0.5);
     565            upper2 = PS_SQR(radius + 0.5);
     566            radiusLast = i;
     567        } else {
     568            // Rings Fibonacci distributed (2, 3, 5...)
     569            int fibNew = fibIndex + fibIndexMinus1;
     570            fibIndexMinus1 = fibIndex;
     571            fibIndex = fibNew;
     572
     573            float radiusLower = radiusLast + 1;
     574            radiusLast = radiusLower + fibIndex;
     575            float radiusUpper = radiusLast;
     576
     577            lower2 = PS_SQR(radiusLower - 0.5);
     578            upper2 = PS_SQR(radiusUpper + 0.5);
     579        }
     580
     581        psTrace("psModules.imcombine", 8, "Radius limits: %f --> %f\n", sqrtf(lower2), sqrtf(upper2));
     582
    548583        // Iterate over (u,v) order
    549584        for (int uOrder = 0; uOrder <= (i == 0 ? 0 : ringsOrder); uOrder++) {
     
    558593                    // Central pixel is easy
    559594                    uCoords->data.S32[0] = vCoords->data.S32[0] = 0;
    560                     poly->data.F32[0] = 0;
     595                    poly->data.F32[0] = 1.0;
    561596                    uCoords->n = vCoords->n = poly->n = 1;
    562597                    radiusLast = 0;
    563598                } else {
    564                     float lower2;           // Lower limit of radius^2
    565                     float upper2;           // Upper limit of radius^2
    566 
    567                     if (i < numInner) {
    568                         // A ring every pixel width
    569                         float radius = i;
    570                         lower2 = PS_SQR(radius - 0.5);
    571                         upper2 = PS_SQR(radius + 0.5);
    572                         radiusLast = i;
    573                     } else {
    574                         // Rings Fibonacci distributed (2, 3, 5...)
    575                         int fibNew = fibIndex + fibIndexMinus1;
    576                         fibIndexMinus1 = fibIndex;
    577                         fibIndex = fibNew;
    578 
    579                         float radiusLower = radiusLast + 1;
    580                         radiusLast = radiusLower + fibIndex;
    581                         float radiusUpper = radiusLast;
    582 
    583                         lower2 = PS_SQR(radiusLower - 0.5);
    584                         upper2 = PS_SQR(radiusUpper + 0.5);
    585                     }
    586 
    587599                    int j = 0;          // Index for data
    588                     for (int v = 1; v <= size; v++) {
     600                    for (int v = -size; v <= size; v++) {
    589601                        int v2 = PS_SQR(v);   // Square of v
    590                         float vPolyPlus = power(v, vOrder); // Value of (+v)^vOrder
    591                         float vPolyMinus = power(-v, vOrder); // Value of (-v)^vOrder
    592 
    593                         // u = 0
    594                         uCoords->data.S32[j] = 0;
    595                         vCoords->data.S32[j] = v;
    596                         poly->data.F32[j] = (uOrder == 0 ? vPolyPlus : 0.0);
    597                         j++;
    598 
    599                         uCoords->data.S32[j] = 0;
    600                         vCoords->data.S32[j] = -v;
    601                         poly->data.F32[j] = (uOrder == 0 ? vPolyMinus : 0.0);
    602                         j++;
    603 
    604                         psVectorExtend(uCoords, RINGS_BUFFER, 2);
    605                         psVectorExtend(vCoords, RINGS_BUFFER, 2);
    606                         psVectorExtend(poly, RINGS_BUFFER, 2);
    607 
    608                         for (int u = 1; u <= v; u++) {
     602                        float vPoly = power(v, vOrder); // Value of v^vOrder
     603
     604                        for (int u = -size; u <= size; u++) {
    609605                            int u2 = PS_SQR(u); // Square of u
    610606                            int distance2 = u2 + v2; // Distance from the centre
    611607                            if (distance2 > lower2 && distance2 < upper2) {
    612                                 float uPolyPlus = power(u, uOrder); // Value of (+u)^uOrder
    613                                 float uPolyMinus = power(-u, uOrder); // Value of (-u)^uOrder
     608                                float uPoly = power(u, uOrder); // Value of u^uOrder
    614609
    615610                                uCoords->data.S32[j] = u;
    616611                                vCoords->data.S32[j] = v;
    617                                 poly->data.F32[j] = uPolyPlus * vPolyPlus;
     612                                poly->data.F32[j] = uPoly * vPoly;
     613
     614                                psVectorExtend(uCoords, RINGS_BUFFER, 1);
     615                                psVectorExtend(vCoords, RINGS_BUFFER, 1);
     616                                psVectorExtend(poly, RINGS_BUFFER, 1);
     617
     618                                psTrace("psModules.imcombine", 9, "u = %d, v = %d, poly = %f\n",
     619                                        u, v, poly->data.F32[j]);
     620
    618621                                j++;
    619 
    620                                 uCoords->data.S32[j] = u;
    621                                 vCoords->data.S32[j] = -v;
    622                                 poly->data.F32[j] = uPolyPlus * vPolyMinus;
    623                                 j++;
    624 
    625                                 uCoords->data.S32[j] = -u;
    626                                 vCoords->data.S32[j] = v;
    627                                 poly->data.F32[j] = uPolyMinus * vPolyPlus;
    628                                 j++;
    629 
    630                                 uCoords->data.S32[j] = -u;
    631                                 vCoords->data.S32[j] = -v;
    632                                 poly->data.F32[j] = uPolyMinus * vPolyMinus;
    633                                 j++;
    634 
    635                                 psVectorExtend(uCoords, RINGS_BUFFER, 4);
    636                                 psVectorExtend(vCoords, RINGS_BUFFER, 4);
    637                                 psVectorExtend(poly, RINGS_BUFFER, 4);
    638622                            }
    639623                        }
    640624                    }
    641625                }
     626
     627                psTrace("psModules.imcombine", 8, "%ld pixels in ring\n", uCoords->n);
    642628
    643629                // Iterate over spatial order.  This loop creates the terms for
     
    645631                for (int xOrder = 0; xOrder <= spatialOrder; xOrder++) {
    646632                    for (int yOrder = 0; yOrder <= spatialOrder - xOrder; yOrder++, index++) {
    647                         kernels->preCalc->data[index] = data;
     633                        kernels->preCalc->data[index] = psMemIncrRefCounter(data);
    648634                        kernels->u->data.S32[index] = uOrder;
    649635                        kernels->v->data.S32[index] = vOrder;
     
    655641                    }
    656642                }
     643                psFree(data);
    657644            }
    658645        }
Note: See TracChangeset for help on using the changeset viewer.