IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6874 for trunk/psLib/src/types


Ignore:
Timestamp:
Apr 17, 2006, 12:00:35 PM (20 years ago)
Author:
magnier
Message:

variety of small changes related to inconsistencies between psModules and psLib

Location:
trunk/psLib/src/types
Files:
3 edited

Legend:

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

    r6548 r6874  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.101 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-03-08 21:09:16 $
     14 *  @version $Revision: 1.102 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-04-17 22:00:03 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    293293    case     PS_DATA_POLYNOMIAL4D:              // psPolynomial4D
    294294    case     PS_DATA_PROJECTION:                // psProjection
     295    case     PS_DATA_REGION:                  // psRegion
    295296    case     PS_DATA_SCALAR:                    // psScalar
    296297    case     PS_DATA_SPHERE:                    // psSphere
     
    341342}
    342343
     344
     345psMetadataItem *psMetadataItemCopy(const psMetadataItem *in
     346                                  )
     347{
     348    PS_ASSERT_PTR_NON_NULL(in,NULL);
     349
     350    psMetadataItem *newItem = NULL;     // New metadata item, to be returned
     351
     352    #define PS_METADATA_ITEM_COPY_CASE(NAME,TYPE) \
     353case PS_DATA_##NAME: \
     354    newItem = psMetadataItemAlloc(in->name, PS_DATA_##NAME, in->comment, in->data.TYPE); \
     355    break; \
     356
     357    switch (in->type) {
     358        // Simple types
     359        PS_METADATA_ITEM_COPY_CASE(BOOL,B);
     360        PS_METADATA_ITEM_COPY_CASE(S8,S8);
     361        PS_METADATA_ITEM_COPY_CASE(S16,S16);
     362        PS_METADATA_ITEM_COPY_CASE(S32,S32);
     363        PS_METADATA_ITEM_COPY_CASE(U8,U8);
     364        PS_METADATA_ITEM_COPY_CASE(U16,U16);
     365        PS_METADATA_ITEM_COPY_CASE(U32,U32);
     366        PS_METADATA_ITEM_COPY_CASE(F32,F32);
     367        PS_METADATA_ITEM_COPY_CASE(F64,F64);
     368        PS_METADATA_ITEM_COPY_CASE(STRING,V); // This will copy the string, not point at it.
     369    case PS_DATA_VECTOR: {
     370            psVector *vecCopy = psVectorCopy(NULL, (psVector*)(in->data.V),
     371                                             ((psVector*)(in->data.V))->type.type);
     372            if (vecCopy == NULL) {
     373                psError(PS_ERR_BAD_PARAMETER_NULL, false,
     374                        "Error copying vector.  Vector skipped.\n");
     375            } else {
     376                newItem = psMetadataItemAlloc(in->name, PS_DATA_VECTOR, in->comment, vecCopy);
     377                psFree(vecCopy);    // Drop reference
     378            }
     379            break;
     380        }
     381    case PS_DATA_TIME: {
     382            psTime *timeCopy = p_psTimeCopy( (psTime*)(in->data.V) );
     383            if (timeCopy == NULL) {
     384                psError(PS_ERR_BAD_PARAMETER_NULL, false,
     385                        "Error copying time.  Time skipped.\n");
     386            } else {
     387                newItem = psMetadataItemAlloc(in->name, PS_DATA_TIME, in->comment, timeCopy);
     388                psFree(timeCopy);   // Drop reference
     389            }
     390            break;
     391        }
     392    case PS_DATA_METADATA: {
     393            // Metadata: copy the next level and stuff that in too
     394            psMetadata *metadata = psMetadataCopy(NULL, in->data.md);
     395            newItem = psMetadataItemAlloc(in->name, PS_DATA_METADATA, in->comment, metadata);
     396            psFree(metadata);       // Drop reference
     397            break;
     398        }
     399    case PS_DATA_REGION: {
     400            psRegion *region = in->data.V; // The region
     401            psRegion *new = psRegionAlloc(region->x0, region->x1, region->y0, region->y1); // Copy of the region
     402            newItem = psMetadataItemAlloc(in->name, PS_DATA_REGION, in->comment, new);
     403            psFree(new);                  // Drop reference
     404            break;
     405        }
     406    default:
     407        // Other kinds of pointers
     408        psLogMsg(__func__, PS_LOG_WARN, "Copying a pointer in the metadata item: %x\n", in->type);
     409        newItem = psMetadataItemAlloc(in->name, in->type, in->comment, in->data.V);
     410        break;
     411    }
     412
     413    return newItem;
     414}
     415
    343416psMetadata *psMetadataCopy(psMetadata *out,
    344417                           const psMetadata *in)
     
    349422        out = psMetadataAlloc();
    350423    }
    351     //    psMetadataItem *item = NULL;
    352     psMetadataIterator *iter = NULL;
    353     iter = psMetadataIteratorAlloc(*(psMetadata**)&in, PS_LIST_HEAD, NULL);
    354     /*
    355         item = psMetadataGetAndIncrement(iter);
    356         while (item != NULL) {
    357             psMetadataAddItem(out, item, PS_LIST_TAIL, 0);
    358             item = psMetadataGetAndIncrement(iter);
    359         }
    360         psFree(item);
    361         psFree(iter);
    362         return out;
    363     */
     424    psMetadataIterator *iter = psMetadataIteratorAlloc(*(psMetadata**)&in, PS_LIST_HEAD, NULL);
    364425    psMetadataItem *inItem = NULL;
    365     unsigned long numPointers = 0;      // Number of pointers we were forced to copy
    366426    while ((inItem = psMetadataGetAndIncrement(iter))) {
    367427        // Need to look for MULTI, which won't be picked up using the iterator.
     
    370430        if (multiCheckItem->type == PS_DATA_METADATA_MULTI) {
    371431            psTrace(__func__, 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment);
    372             flag = PS_DATA_METADATA_MULTI;
     432            flag = PS_META_DUPLICATE_OK;
    373433        }
    374434        psTrace(__func__, 5, "Copying %s (%s)...\n", inItem->name, inItem->comment);
    375435
    376 
    377         //        case PS_TYPE_##NAME:
    378         #define PS_METADATA_COPY_CASE(NAME,TYPE) \
    379     case PS_DATA_##NAME: \
    380         if (! psMetadataAdd(out, PS_LIST_TAIL, inItem->name, \
    381                             PS_DATA_##NAME | flag, inItem->comment, inItem->data.TYPE)) { \
    382             psErrorStackPrint(stderr, "Error copying %s (%s) in the metadata\n", \
    383                               inItem->name, inItem->comment); \
    384         } \
    385         break;
    386 
    387         switch (inItem->type) {
    388             // Numerical types
    389             PS_METADATA_COPY_CASE(BOOL,B);
    390             PS_METADATA_COPY_CASE(S8,S8);
    391             PS_METADATA_COPY_CASE(S16,S16);
    392             PS_METADATA_COPY_CASE(S32,S32);
    393             PS_METADATA_COPY_CASE(U8,U8);
    394             PS_METADATA_COPY_CASE(U16,U16);
    395             PS_METADATA_COPY_CASE(U32,U32);
    396             PS_METADATA_COPY_CASE(F32,F32);
    397             PS_METADATA_COPY_CASE(F64,F64);
    398 
    399         case PS_DATA_VECTOR: {
    400                 psVector *vecCopy = psVectorCopy(NULL, (psVector*)(inItem->data.V),
    401                                                  ((psVector*)(inItem->data.V))->type.type);
    402                 if (vecCopy == NULL) {
    403                     psError(PS_ERR_BAD_PARAMETER_NULL, false,
    404                             "Error copying vector.  Vector skipped.\n");
    405                 } else {
    406                     psMetadataAddVector(out, PS_LIST_TAIL, inItem->name, flag,
    407                                         inItem->comment, vecCopy);
    408                     psFree(vecCopy);
    409                 }
    410                 break;
    411             }
    412         case PS_DATA_TIME: {
    413                 psTime *timeCopy = p_psTimeCopy( (psTime*)(inItem->data.V) );
    414                 if (timeCopy == NULL) {
    415                     psError(PS_ERR_BAD_PARAMETER_NULL, false,
    416                             "Error copying time.  Time skipped.\n");
    417                 } else {
    418                     psMetadataAddTime(out, PS_LIST_TAIL, inItem->name, flag,
    419                                       inItem->comment, timeCopy);
    420                     psFree(timeCopy);
    421                 }
    422                 break;
    423             }
    424             // String: relying on the fact that this will copy the string, not point at it.
    425         case PS_DATA_STRING:
    426             psMetadataAdd(out, PS_LIST_TAIL, inItem->name, PS_DATA_STRING |
    427                           flag, inItem->comment, inItem->data.V);
    428             break;
    429             // Metadata: copy the next level and stuff that in too
    430         case PS_DATA_METADATA: {
    431                 psMetadata *metadata = psMetadataCopy(NULL, inItem->data.md);
    432                 psMetadataAdd(out, PS_LIST_TAIL, inItem->name,
    433                               PS_DATA_METADATA | flag, inItem->comment, metadata);
    434                 psFree(metadata);
    435                 break;
    436             }
    437             // Other kinds of pointers
    438         default:
    439             numPointers++;
    440             psTrace(__func__, 10, "Copying a pointer in the metadata: %x\n", inItem->type);
    441             psMetadataAdd(out, PS_LIST_TAIL, inItem->name, inItem->type | flag,
    442                           inItem->comment, inItem->data.V);
    443             break;
    444         }
     436        // Copy the item and add it on
     437        psMetadataItem *newItem = psMetadataItemCopy(inItem); // Copied item
     438        if (!psMetadataAddItem(out, newItem, PS_LIST_TAIL, flag)) {
     439            psErrorStackPrint(stderr, "Error copying %s (%s) in the metadata\n", inItem->name,
     440                              inItem->comment);
     441        }
     442        psFree(newItem);                // Drop reference
    445443    }
    446444    psFree(iter);
    447 
    448     if (numPointers > 0) {
    449         psLogMsg(__func__, PS_LOG_WARN,
    450                  "Forced to copy %d pointers when copying metadata.  Updating the "
    451                  "copied psMetadata will affect the original!\n", numPointers);
    452     }
    453445
    454446    return out;
     
    528520        } else {
    529521            // default is to error on duplicate entry.
     522            if ((flags & PS_META_NO_REPLACE) != 0) {
     523                return true;
     524            }
    530525            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    531526                    PS_ERRORTEXT_psMetadata_DUPLICATE_NOT_ALLOWED);
     
    554549                   const char *name,
    555550                   int format,
    556                    const char *comment,
    557                    ...)
     551                   const char *comment,...)
    558552{
    559553    PS_ASSERT_PTR_NON_NULL(md,false);
     
    11401134            psMetadataPrint(item->data.V, level + 1);
    11411135            break;
     1136        case PS_DATA_REGION: {
     1137                psString region = psRegionToString(*(psRegion*)item->data.V);
     1138                printf("%s", region);
     1139                psFree(region);
     1140                break;
     1141            }
     1142        case PS_DATA_LIST:
     1143            printf("<a list of unknown contents>");
     1144            break;
     1145        case PS_DATA_TIME: {
     1146                psString time = psTimeToISO(item->data.V);
     1147                printf("%s", time);
     1148                psFree(time);
     1149                break;
     1150            }
    11421151        default:
     1152            printf("\n");
    11431153            psError(PS_ERR_IO, false, "Non-printable metadata type: %x\n", item->type);
    11441154        }
  • trunk/psLib/src/types/psMetadata.h

    r6251 r6874  
    1111*  @author Ross Harman, MHPCC
    1212*
    13 *  @version $Revision: 1.74 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2006-01-30 20:28:33 $
     13*  @version $Revision: 1.75 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2006-04-17 22:00:03 $
    1515*
    1616*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5959    PS_META_DEFAULT = 0,               ///< default behaviour (duplicate entry is an error)
    6060    PS_META_REPLACE = 0x1000000,       ///< allow entry to be replaced
    61     PS_META_DUPLICATE_OK = 0x2000000,  ///< allow duplicate entries
    62     PS_META_NULL = 0x4000000           ///< psMetadataItem.data is a NULL value
     61    PS_META_NO_REPLACE = 0x2000000,    ///< duplicate entry is silently skipped
     62    PS_META_DUPLICATE_OK = 0x4000000,  ///< allow duplicate entries
     63    PS_META_NULL = 0x8000000           ///< psMetadataItem.data is a NULL value
    6364} psMetadataFlags;
    6465
     
    342343);
    343344
     345/** Creates a new copy of a psMetadataItem.
     346 *
     347 * @return psMetadataItem*: the copy of the psMetadataItem
     348 */
     349psMetadataItem *psMetadataItemCopy(const psMetadataItem *in ///< metadata item to be copied
     350                                  );
     351
     352
    344353/** Creates a new copy of all the psMetadataItems in the psMetadata collection, in, and
    345354 *  returns them in out, or creates a new container if out is NULL.
     
    939948
    940949
     950psPolynomial2D *psPolynomial2DfromMD (psMetadata *folder);
     951bool psPolynomial2DtoMD (psMetadata *md, psPolynomial2D *poly, char *format, ...);
     952
     953psPolynomial3D *psPolynomial3DfromMD (psMetadata *folder);
     954bool psPolynomial3DtoMD (psMetadata *md, psPolynomial3D *poly, char *format, ...);
     955
     956psPolynomial4D *psPolynomial4DfromMD (psMetadata *folder);
     957bool psPolynomial4DtoMD (psMetadata *md, psPolynomial4D *poly, char *format, ...);
     958
     959
    941960/// @}
    942961
  • trunk/psLib/src/types/psPixels.h

    r6500 r6874  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-02-28 02:53:03 $
     9 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-04-17 22:00:03 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1717#include "psImage.h"
    1818#include "psVector.h"
     19#include "psRegion.h"
    1920
    2021/// @addtogroup Image
     
    125126 *
    126127 *  psMaskToPixels shall return a psPixels consisting of the coordinates in
    127  *  the mask that match the maskVal. The out pixel list shall be modified if
     128 *  the mask that match the maskVal. The out pixel list shall be modified if
    128129 *  supplied, or allocated and returned if NULL. In hte event that mask is
    129130 *  NULL, the function shall generate an error and return NULL.
Note: See TracChangeset for help on using the changeset viewer.