IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 18, 2005, 11:44:40 AM (21 years ago)
Author:
drobbin
Message:

folded in code from bug 481. Tests still to be written.

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

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/mathtypes/psImage.c

    r4545 r4815  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.74 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-07-12 19:35:15 $
     11 *  @version $Revision: 1.75 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-08-18 21:44:40 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    147147    return psStringCopy(tmpText);
    148148}
     149
     150
     151// set actual region based on image parameters:
     152// compensate for negative upper limits
     153// XXX this is inconsistent: the coordindates should always be in the parent
     154//     frame, which means the negative values should subtract from Nx,Ny of
     155//     the parent, not the child.  but, we don't carry the dimensions of the
     156//     parent in the psImage container.  for now, us the child Nx,Ny
     157// force range to be on this subimage
     158// XXX EAM : this needs to be changes to use psRegion rather than psRegion*
     159psRegion psRegionForImage(psImage *image,
     160                          psRegion *in)
     161{
     162
     163    // x0,y0, x1,y1 are in *parent* units
     164    //    PS_ASSERT_PTR_NON_NULL(in, NULL);
     165    if( in == NULL ) {
     166        psError(PS_ERR_BAD_PARAMETER_NULL, true, "Unallowable operation.  psRegion *in is NULL.");
     167        return *in;
     168    }
     169    /*    if (out == NULL) {
     170    //    out = psRegionAlloc(in->x0, in->x1, in->y0, in->y1);
     171        *out = psRegionSet(in->x0, in->x1, in->y0, in->y1);
     172        } else {
     173        *out = *in;
     174        }
     175    */    // XXX these are probably wrong (see above)
     176    if (in->x1 <= 0) {
     177        in->x1 = image->col0 + image->numCols + in->x1;
     178    }
     179    if (in->y1 <= 0) {
     180        in->y1 = image->row0 + image->numRows + in->y1;
     181    }
     182
     183    // force the lower-limits to be on the child
     184    in->x0 = PS_MAX(image->col0, in->x0);
     185    in->y0 = PS_MAX(image->row0, in->y0);
     186
     187    // force the upper-limits to be on the child
     188    in->x1 = PS_MIN(image->col0 + image->numCols, in->x1);
     189    in->y1 = PS_MIN(image->row0 + image->numRows, in->y1);
     190    return (*in);
     191}
     192
     193// define a square region centered on the given coordinate
     194psRegion psRegionForSquare(float x,
     195                           float y,
     196                           float radius)
     197{
     198    psRegion region;
     199    region = psRegionSet (x - radius, x + radius + 1,
     200                          y - radius, y + radius + 1);
     201    return (region);
     202}
     203
     204bool psImageInit (psImage *image,...)
     205{
     206
     207    va_list argp;
     208    psU8  vU8;
     209    psF32 vF32;
     210    psF64 vF64;
     211
     212    if (image == NULL)
     213        return (false);
     214
     215    va_start (argp, image);
     216
     217    switch (image->type.type) {
     218    case PS_TYPE_U8:
     219        vU8 = va_arg (argp, psU32);
     220
     221        for (int iy = 0; iy < image->numRows; iy++) {
     222            for (int ix = 0; ix < image->numCols; ix++) {
     223                image->data.U8[iy][ix] = vU8;
     224            }
     225        }
     226        break;
     227
     228    case PS_TYPE_F32:
     229        vF32 = va_arg (argp, psF64);
     230
     231        for (int iy = 0; iy < image->numRows; iy++) {
     232            for (int ix = 0; ix < image->numCols; ix++) {
     233                image->data.F32[iy][ix] = vF32;
     234            }
     235        }
     236        return (true);
     237
     238    case PS_TYPE_F64:
     239        vF64 = va_arg (argp, psF64);
     240
     241        for (int iy = 0; iy < image->numRows; iy++) {
     242            for (int ix = 0; ix < image->numCols; ix++) {
     243                image->data.F64[iy][ix] = vF64;
     244            }
     245        }
     246        return (true);
     247
     248    default:
     249        psError (PS_ERR_BAD_PARAMETER_TYPE, true, "datatype %d not defined in psImageInit\n", image->type);
     250        return (false);
     251    }
     252    return (false);
     253}
     254
    149255
    150256psImage* psImageRecycle(psImage* old,
  • trunk/psLib/src/mathtypes/psImage.h

    r4590 r4815  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.61 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2005-07-21 02:39:57 $
     13 *  @version $Revision: 1.62 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2005-08-18 21:44:40 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "psType.h"
    2424#include "psArray.h"
     25#include "psConstants.h"
    2526
    2627/// @addtogroup Image
     
    112113/** Create a psRegion with the specified attributes.
    113114 *
    114  * @return psRegion : a cooresponding psRegion.
     115 *  @return psRegion : a cooresponding psRegion.
    115116 */
    116117psRegion psRegionSet(
     
    141142);
    142143
     144/** Sets an actual region based on image parameters.
     145 *
     146 *  An image region defined with negative upper limits may be rationalized for the bounds of a
     147 *  specific image with psRegionForImage.  The output of this function is a region with negative
     148 *  upper limits replaced by their corrected value appropriate to the given image.  In addition,
     149 *  the lower and upper limits are foced to lie within the bounds of the image.  If the lower-
     150 *  limit coordinates are lewss than the lower bound of the image, they are limited to the lower
     151 *  bound of the image.  Conversely, if the upper-limit coordinates are greater than the upper
     152 *  bound of the image, they are truncated to define only valid pixels.  If the lower-limit
     153 *  coordinates are greater than the upper bounds of the image, or the upper-limit coordinates
     154 *  are less than the lower bounds of the image, the coordinates should saturate on those limits.
     155 *
     156 *  @return psRegion:       A region with negative upper limits replaced by the corrected
     157 */
     158psRegion psRegionForImage(
     159    psImage *image,                    ///< the image for which the region is to be set
     160    psRegion *in                       ///< the image region limits
     161);
     162
     163/** Defines a region corresponding to the square with center at coordinate x,y
     164 *  and with coderadius.  The width of the square is 2radius + 1.
     165 *
     166 *  @return psRegion:       the newly defined psRegion.
     167 */
     168psRegion psRegionForSquare(
     169    float x,                           ///< x coordinate at square-center
     170    float y,                           ///< y coordinate at square-center
     171    float radius                       ///< radius of square
     172);
     173
     174/** Initializes the image with the given value.
     175 *
     176 *  The input data is cast to match the image datatype.
     177 *
     178 *  @return bool:       True on success, otherwise false.
     179 */
     180bool psImageInit(
     181    psImage *image,                    ///< the image to be initialized
     182    ...                                ///< Variable argument list for initialization
     183);
     184
    143185/** Resize a given image to the given size/type.
    144186 *
    145187 *  @return psImage* Resized psImage.
    146  *
    147188 */
    148189psImage* psImageRecycle(
     
    166207 *
    167208 *  @return int      Number of children freed.
    168  *
    169209 */
    170210int psImageFreeChildren(
Note: See TracChangeset for help on using the changeset viewer.