IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 6, 2005, 5:33:01 PM (21 years ago)
Author:
eugene
Message:

psphot reorganization: merged in pmObjects code from psModule, modified to work with psLib 0.7.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psLibUtils.c

    r4946 r4954  
    1 # include "psphot.h"
     1# include <strings.h>  // for strncasecmp
     2# include <pslib.h>
     3
     4// XXX EAM : this is NOT included in the C99 headers ??
     5FILE *fdopen(int fildes, const char *mode);
    26
    37// XXX EAM : these utility functions should be added back into PSLib
     
    2933    if (timers == NULL) timers = psHashAlloc (16);
    3034
    31     start = psTimeGetTime (PS_TIME_UTC);
     35    start = psTimeGetNow (PS_TIME_UTC);
    3236    psHashAdd (timers, name, start);
    3337    psFree (start);
     
    4751    if (start == NULL) return (0);
    4852
    49     mark = psTimeGetTime (PS_TIME_UTC);
     53    mark = psTimeGetNow (PS_TIME_UTC);
    5054    delta = psTimeDelta (mark, start);
    5155    psFree (mark);
     
    5357
    5458    return (delta);
     59}
     60
     61// find the location of the specified argument
     62int psArgumentGet (int argc, char **argv, char *arg) {
     63
     64    int i;
     65
     66    for (i = 0; i < argc; i++) {
     67        if (!strcmp(argv[i], arg))
     68            return (i);
     69    }
     70 
     71    return ((int)NULL);
     72}
     73
     74// remove the specified argument (by location)
     75int psArgumentRemove (int N, int *argc, char **argv) {
     76
     77    int i;
     78
     79    if ((N != (int)NULL) && (N != 0)) {
     80        (*argc)--;
     81        for (i = N; i < *argc; i++) {
     82            argv[i] = argv[i+1];
     83        }
     84    }
     85
     86    return (N);
    5587}
    5688
     
    114146}
    115147
    116 // find the location of the specified argument
    117 int psArgumentGet (int argc, char **argv, char *arg) {
    118 
    119     int i;
    120 
    121     for (i = 0; i < argc; i++) {
    122         if (!strcmp(argv[i], arg))
    123             return (i);
    124     }
    125  
    126     return ((int)NULL);
    127 }
    128 
    129 // remove the specified argument (by location)
    130 int psArgumentRemove (int N, int *argc, char **argv) {
    131 
    132     int i;
    133 
    134     if ((N != (int)NULL) && (N != 0)) {
    135         (*argc)--;
    136         for (i = N; i < *argc; i++) {
    137             argv[i] = argv[i+1];
    138         }
    139     }
    140 
    141     return (N);
    142 }
    143 
    144148// alternate implementation of this function from pmObjects.c
     149// XXX EAM : move this to pmObjects_EAM.c
    145150psVector *psGetRowVectorFromImage(psImage *image,
    146151                                  psU32 row)
    147152{
    148     PS_IMAGE_CHECK_NULL(image, NULL);
    149     PS_IMAGE_CHECK_TYPE(image, PS_TYPE_F32, NULL);
     153    PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     154    PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL);
    150155
    151156    psVector *tmpVector = psVectorAlloc(image->numCols, PS_TYPE_F32);
     
    201206}
    202207
    203 void psImageSmooth (psImage *image, float sigma, float Nsigma) {
     208// XXX EAM : this is now in psLib
     209void psImageSmooth_EAM (psImage *image, float sigma, float Nsigma) {
    204210
    205211    int Nx, Ny, Npixel, Nrange;
     
    314320}           
    315321
     322// count number of pixels with given mask value
     323int psImageCountPixelMask (psImage *mask, psU8 value)
     324{
     325    int Npixels = 0;
     326 
     327    for (int i = 0; i < mask->numRows; i++) {
     328        for (int j = 0; j < mask->numCols; j++) {
     329            if (mask->data.U8[i][j] & value) {
     330                Npixels ++;
     331            }
     332        }
     333    }
     334    return (Npixels);
     335}
     336
    316337// define a square region centered on the given coordinate
     338// XXX EAM : this is now in psLib
     339# if (0)
    317340psRegion *psRegionSquare (psF32 x, psF32 y, psF32 radius) {
    318341    psRegion *region;
     
    321344    return (region);
    322345}
     346# endif
    323347
    324348// set actual region based on image parameters:
     
    327351//     frame, which means the negative values should subtract from Nx,Ny of
    328352//     the parent, not the child.  but, we don't carry the dimensions of the
    329 //     parent in the psImage container.  for now, us the child Nx,Ny
    330 // force range to be on this subimage
    331 // XXX EAM : this needs to be changes to use psRegion rather than psRegion*
     353//     parent in the psImage container.  for now, use the child Nx,Ny
     354//     force range to be on this subimage
     355// XXX EAM : this needs to be changed to use psRegion rather than psRegion*
     356// XXX EAM : this is now in psLib
     357# if (0)
    332358psRegion *psRegionForImage (psRegion *out, psImage *image, psRegion *in) {
    333359   
     
    356382    return (out);
    357383}
     384# endif
    358385
    359386// mask the area contained by the region
    360387// the region is defined wrt the parent image
     388// XXX EAM : this is now in psLib
     389# if (0)
    361390void psImageMaskRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) {
    362391
     
    375404    }
    376405}
     406# endif
    377407
    378408// mask the area not contained by the region
    379409// the region is defined wrt the parent image
     410// XXX EAM : this is now in psLib
     411# if (0)
    380412void psImageKeepRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) {
    381413
     
    396428    }
    397429}
     430# endif
    398431
    399432// mask the area contained by the region
    400433// the region is defined wrt the parent image
     434// XXX EAM : this is now in psLib
     435# if (0)
    401436void psImageMaskCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) {
    402437
     
    419454    }
    420455}
     456# endif
    421457
    422458// mask the area contained by the region
    423459// the region is defined wrt the parent image
     460// XXX EAM : this is now in psLib
     461# if (0)
    424462void psImageKeepCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) {
    425463
     
    442480    }
    443481}
     482# endif
    444483
    445484psVector *psVectorCreate (double lower, double upper, double delta, psElemType type) {
     
    455494  return (out);
    456495}
     496
     497// XXX EAM a utility function
     498bool p_psVectorPrintRow (int fd, psVector *a, char *name)
     499{
     500
     501    FILE *f;
     502    f = fdopen(fd, "a+");
     503    fprintf (f, "vector: %s\n", name);
     504
     505    for (int i = 0; i < a[0].n; i++) {
     506        fprintf (f, "%f  ", p_psVectorGetElementF64(a, i));
     507    }
     508    fprintf (f, "\n");
     509    fclose(f);
     510    return (true);
     511}
     512// XXX EAM is the use of fdopen here a good way to do this?
Note: See TracChangeset for help on using the changeset viewer.