IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13741


Ignore:
Timestamp:
Jun 10, 2007, 7:54:05 AM (19 years ago)
Author:
magnier
Message:

adding psRegionAndParityFromString

Location:
trunk/psLib/src/math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psRegion.c

    r10999 r13741  
    88#include "psError.h"
    99#include "psAssert.h"
     10#include "psConstants.h"
    1011#include "psRegion.h"
    1112
     
    8384}
    8485
     86psRegion psRegionAndParityFromString(int *xParity, int *yParity, const char* region)
     87{
     88    PS_ASSERT_PTR_NON_NULL (xParity, psRegionSet(NAN,NAN,NAN,NAN));
     89    PS_ASSERT_PTR_NON_NULL (yParity, psRegionSet(NAN,NAN,NAN,NAN));
     90
     91    psS32 col0;
     92    psS32 col1;
     93    psS32 row0;
     94    psS32 row1;
     95
     96    // unless otherwise detected
     97    *xParity = +1;
     98    *yParity = +1;
     99
     100    // section should be of the form '[col0:col1,row0:row1]'
     101    if (region == NULL) {
     102        return psRegionSet(0,0,0,0);
     103    }
     104
     105    if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
     106        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     107                _("Specified subsection string, '%s', can not be parsed.  Must be in the form '[x1:x2,y1:y2]'."),
     108                region);
     109        return psRegionSet(NAN,NAN,NAN,NAN);
     110    }
     111
     112    // [0:0,0:0] is complete image region
     113    if ((col0 == 0) && (col1 == 0) && (row0 == 0) && (row1 == 0)) {
     114        return psRegionSet(0,0,0,0);
     115    }
     116
     117    if ((col1 > 0) && (col0 > col1)) {
     118        *xParity = -1;
     119        PS_SWAP (col0, col1);
     120    }
     121
     122    if ((row1 > 0) && (row0 > row1)) {
     123        *yParity = -1;
     124        PS_SWAP (row0, row1);
     125    }
     126
     127    return psRegionSet(col0-1,col1,row0-1,row1);
     128}
     129
    85130psString psRegionToString(const psRegion region)
    86131{
  • trunk/psLib/src/math/psRegion.h

    r11248 r13741  
    22 * @brief image regions and related functions
    33 *
    4  * $Revision: 1.8 $ $Name: not supported by cvs2svn $
    5  * $Date: 2007-01-23 22:47:23 $
     4 * $Revision: 1.9 $ $Name: not supported by cvs2svn $
     5 * $Date: 2007-06-10 17:54:05 $
    66 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    77 */
     
    7272);
    7373
     74/** Create a psRegion from a string in IRAF form '[x0:x1,y0:y1]', returning range parities
     75 *
     76 *  Create a psRegion using the range defined by a string in the standard IRAF form
     77 *  '[x0:x1,y0:y1]'.  Unlike psRegionFromString, the ranges may have x0 > x1 or y0 > y1, in
     78 *  which case the xParity or yParity terms will be set to -1 (instead of the default +1).
     79 *
     80 *  @return psRegion:       A new psRegion struct, or NULL is not successful.
     81 */
     82psRegion psRegionAndParityFromString(
     83    int *xParity,                     ///< +1 if x0 <= x1, -1 otherwise
     84    int *yParity,                     ///< +1 if y0 <= y1, -1 otherwise
     85    const char* region                ///< image rectangular region in the form '[x0:x1,y0:y1]'
     86);
     87
    7488/** Create a string of the standard IRAF form '[x0:x1,y0:y1]' from a psRegion.
    7589 *
Note: See TracChangeset for help on using the changeset viewer.