IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5214


Ignore:
Timestamp:
Sep 30, 2005, 2:14:17 PM (21 years ago)
Author:
drobbin
Message:

Changed psPixelCoord to use float's instead of int's

Location:
trunk/psLib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psPixels.c

    r5137 r5214  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-09-26 22:35:53 $
     9 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-10-01 00:14:17 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3232
    3333// for use by qsort, etc.
    34 static int comparePixelCoord(psPixelCoord* coord1, psPixelCoord* coord2)
     34static int comparePixelCoord(psPixelCoord* coord1,
     35                             psPixelCoord* coord2)
    3536{
    3637    // check row first
     
    7980
    8081
    81 psPixels* psPixelsRealloc(psPixels* pixels, long nalloc)
     82psPixels* psPixelsRealloc(psPixels* pixels,
     83                          long nalloc)
    8284{
    8385    if (pixels == NULL) {
     
    101103}
    102104
    103 psPixels* p_psPixelsAppend(psPixels* pixels, long growth, int x, int y)
     105psPixels* p_psPixelsAppend(psPixels* pixels,
     106                           long growth,
     107                           float x,
     108                           float y)
    104109{
    105110    if (growth < 1) {
     
    111116    }
    112117
    113     int n = pixels->n;
     118    long n = pixels->n;
    114119
    115120    pixels->data[n].x = x;
     
    121126}
    122127
    123 psPixels* psPixelsCopy(psPixels* out, const psPixels* pixels)
     128psPixels* psPixelsCopy(psPixels* out,
     129                       const psPixels* pixels)
    124130{
    125131    if (pixels == NULL) {
     
    137143}
    138144
    139 psImage *psPixelsToMask(psImage *out, const psPixels *pixels, psRegion region, psMaskType maskVal)
     145psImage *psPixelsToMask(psImage *out,
     146                        const psPixels *pixels,
     147                        psRegion region,
     148                        psMaskType maskVal)
    140149{
    141150    // check that the input pixel vector is valid
     
    154163    }
    155164
    156     int x0 = region.x0;
    157     int x1 = region.x1;
    158     int y0 = region.y0;
    159     int y1 = region.y1;
     165    float x0 = region.x0;
     166    float x1 = region.x1;
     167    float y0 = region.y0;
     168    float y1 = region.y1;
    160169
    161170    // determine the output image size
     
    165174        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    166175                PS_ERRORTEXT_psPixels_REGION_INVALID,
    167                 y0,y1,x0,x1);
     176                (int)y0,(int)y1,(int)x0,(int)x1);
    168177        psFree(out);
    169178        return NULL;
     
    178187        return NULL;
    179188    }
    180     *(psS32*)&out->row0 = y0;
    181     *(psS32*)&out->col0 = x0;
     189    *(psS32*)&out->row0 = (int)y0;
     190    *(psS32*)&out->col0 = (int)x0;
    182191
    183192    // initialize image to all zeros
     
    188197
    189198    // determine the length of the pixel vector
    190     int length = pixels->n;
     199    long length = pixels->n;
    191200
    192201    // cycle through the vector of pixels and insert pixels into image
    193202    psMaskType** outData = out->data.PS_TYPE_MASK_DATA;
    194203    for (int p = 0; p < length; p++) {
    195         psS32 x = data[p].x;
    196         psS32 y = data[p].y;
     204        float x = data[p].x;
     205        float y = data[p].y;
    197206        // pixel in region?
    198207        if (x >= x0 && x < x1 && y >= y0 && y < y1) {
    199             outData[y-y0][x-x0] |= maskVal;
     208            outData[(int)(y-y0)][(int)(x-x0)] |= maskVal;
    200209        }
    201210    }
     
    204213}
    205214
    206 psPixels* psPixelsFromMask(psPixels* out, const psImage* mask, psMaskType maskVal)
     215psPixels* psPixelsFromMask(psPixels* out,
     216                           const psImage* mask,
     217                           psMaskType maskVal)
    207218{
    208219    if (mask == NULL) {
     
    227238    // total pixels, so it is best to just start with a guess and resize if
    228239    // necessary
    229     int minPixels = numRows*numCols/100; // initial guess, 1% of pixels masked
     240    long minPixels = numRows*numCols/100; // initial guess, 1% of pixels masked
    230241    if (minPixels < 32) { // enforce a minimum size
    231242        minPixels = 32;
     
    241252
    242253    // find the mask pixels in the image
    243     int numPixels = 0;
     254    long numPixels = 0;
    244255    psPixelCoord* data = out->data;
    245256    int nalloc = out->nalloc;
     
    266277}
    267278
    268 psPixels* psPixelsConcatenate(psPixels *out,const psPixels *pixels)
     279psPixels* psPixelsConcatenate(psPixels *out,
     280                              const psPixels *pixels)
    269281{
    270282    if (pixels == NULL) {
     
    274286    }
    275287
    276     int pixelsN = pixels->n;
     288    long pixelsN = pixels->n;
    277289    psPixelCoord* pixelsData = pixels->data;
    278290
     
    284296
    285297    // make sure the out is large enough to fit the result
    286     int outN = out->n;
     298    long outN = out->n;
    287299    out = psPixelsRealloc(out,outN + pixelsN);
    288300    psPixelCoord* outData = out->data;
     
    294306    // add non-duplicate values in pixels to out
    295307    psPixelCoord pCoord;
    296     int end = outN;
    297     for (int n = 0; n < pixelsN; n++) {
     308    long end = outN;
     309    for (long n = 0; n < pixelsN; n++) {
    298310        pCoord = pixelsData[n];
    299311        if (bsearch(&pCoord, outData, outN, sizeof(psPixelCoord),
     
    318330    }
    319331
    320     int n = pixels->n;
     332    long n = pixels->n;
    321333    psPixelCoord* data = pixels->data;
    322334
     
    326338    }
    327339
    328     for (int i = 0; i < n; i++) {
    329         fprintf (fd, "(%d,%d)\n", data[i].x, data[i].y);
     340    for (long i = 0; i < n; i++) {
     341        fprintf (fd, "(%f,%f)\n", data[i].x, data[i].y);
    330342    }
    331343    fprintf (fd, "\n");
  • trunk/psLib/src/types/psPixels.h

    r5137 r5214  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-09-26 22:35:53 $
     9 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-10-01 00:14:17 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2424typedef struct
    2525{
    26     int x;                             ///< x coordinate
    27     int y;                             ///< y coordinate
     26    float x;                             ///< x coordinate
     27    float y;                             ///< y coordinate
    2828}
    2929psPixelCoord;
     
    8686    long growth,
    8787    ///< number of elements to grow the psPixels list, if necessary.  if growth < 1, 10 is used.
    88     int x,                             ///< x coordinate to append
    89     int y                              ///< y coordinate to append
     88    float x,                             ///< x coordinate to append
     89    float y                              ///< y coordinate to append
    9090);
    9191
  • trunk/psLib/test/types/tst_psPixels.c

    r5101 r5214  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.2 $
     7 *  @version $Revision: 1.3 $
    88 *           $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-09-23 00:04:36 $
     9 *  @date $Date: 2005-10-01 00:14:17 $
    1010 *
    1111 *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
     
    8888    if (p1->n != p1->nalloc) {
    8989        psError(PS_ERR_UNKNOWN, true,
    90                 "psPixelsAlloc failed to set n = %d", p1->nalloc);
     90                "psPixelsAlloc failed to set n = %ld", p1->nalloc);
    9191        return 13;
    9292    }
    9393    if (p1->nalloc != 1) {
    9494        psError(PS_ERR_UNKNOWN, true,
    95                 "psPixelsAlloc failed to set nalloc = 1 (%d)",
     95                "psPixelsAlloc failed to set nalloc = 1 (%ld)",
    9696                p1->nalloc);
    9797        return 14;
     
    117117    if (p2->n != p2->nalloc) {
    118118        psError(PS_ERR_UNKNOWN, true,
    119                 "psPixelsAlloc failed to set n = %d", p2->nalloc);
     119                "psPixelsAlloc failed to set n = %ld", p2->nalloc);
    120120        return 13;
    121121    }
    122122    if (p2->nalloc != 10) {
    123123        psError(PS_ERR_UNKNOWN, true,
    124                 "psPixelsAlloc failed to set nalloc = 1 (%d)",
     124                "psPixelsAlloc failed to set nalloc = 1 (%ld)",
    125125                p2->nalloc);
    126126        return 14;
     
    192192        if (p0->data[i].x != i || p0->data[i].y != 100+i) {
    193193            psError(PS_ERR_UNKNOWN, true,
    194                     "The value of pixel %d was not preserved (%d,%d) vs (%d,%d).",
     194                    "The value of pixel %d was not preserved (%f,%f) vs (%d,%d).",
    195195                    i, p0->data[i].x, p0->data[i].y, i, 100+i);
    196196            return 15;
     
    284284        return 3;
    285285    }
    286     for (int i = 0; i < out1->n; i++) {
     286    for (long i = 0; i < out1->n; i++) {
    287287        if (out1->data[i].x != in1->data[i].x || out1->data[i].y != in1->data[i].y) {
    288288            psError(PS_ERR_UNKNOWN, true,
    289                     "failed to copy the values correctly at index %d", i);
     289                    "failed to copy the values correctly at index %ld", i);
    290290            return 4;
    291291        }
     
    402402    if (pixels->n != numRows) {
    403403        psError(PS_ERR_UNKNOWN, false,
    404                 "wrong number of pixels in list.  Got %d, should be %d.",
     404                "wrong number of pixels in list.  Got %ld, should be %d.",
    405405                pixels->n, numRows);
    406406        return 2;
    407407    }
    408408
    409     for (int i = 0; i < pixels->n; i++) {
    410         if (mask->data.PS_TYPE_MASK_DATA[pixels->data[i].y][pixels->data[i].x] != 1) {
     409    for (long i = 0; i < pixels->n; i++) {
     410        if (mask->data.PS_TYPE_MASK_DATA[(int)pixels->data[i].y][(int)pixels->data[i].x] != 1) {
    411411            psError(PS_ERR_UNKNOWN, false,
    412                     "Item in psPixels list (%d,%d) didn't coorespond to a masked value in image",
     412                    "Item in psPixels list (%f,%f) didn't coorespond to a masked value in image",
    413413                    pixels->data[i].x, pixels->data[i].y);
    414414            return 3;
     
    468468        return 3;
    469469    }
    470     for (int i = 0; i < pixels2->n; i++) {
     470    for (long i = 0; i < pixels2->n; i++) {
    471471        if (pixels2->data[i].x != pixels->data[i].x || pixels2->data[i].y != pixels->data[i].y) {
    472472            psError(PS_ERR_UNKNOWN, true,
    473                     "failed to copy the values correctly at index %d", i);
     473                    "failed to copy the values correctly at index %ld", i);
    474474            return 4;
    475475        }
     
    486486    if (pixels3->n != 15) {
    487487        psError(PS_ERR_UNKNOWN, true,
    488                 "pixels3->n != 15, == %d", pixels3->n);
     488                "pixels3->n != 15, == %ld", pixels3->n);
    489489        return 11;
    490490    }
     
    526526    out = psPixelsGet(in, 1);
    527527    if ( out.x != 3 || out.y != 13 ) {
    528         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPixelsGet return incorrect values %d,%d",
     528        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPixelsGet return incorrect values %f,%f",
    529529                out.x, out.y);
    530530        return 4;
     
    538538    out = psPixelsGet(in, 0);
    539539    if (out.x != 1 || out.y != 2) {
    540         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPixelsGet return incorrect values %d,%d",
     540        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPixelsGet return incorrect values %f,%f",
    541541                out.x, out.y);
    542542        return 6;
Note: See TracChangeset for help on using the changeset viewer.