Index: /trunk/psLib/src/image/psPixels.c
===================================================================
--- /trunk/psLib/src/image/psPixels.c	(revision 3759)
+++ /trunk/psLib/src/image/psPixels.c	(revision 3760)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-04-22 00:06:41 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-04-22 23:56:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -19,11 +19,4 @@
 #include "psMemory.h"
 
-typedef struct
-{
-    psS32 x;
-    psS32 y;
-}
-p_psPixelCoord;
-
 typedef int(*qsortCompareFcn)(const void *, const void *);
 
@@ -31,11 +24,10 @@
 {
     if (pixels != NULL) {
-        psFree(pixels->x);
-        psFree(pixels->y);
+        psFree(pixels->data);
     }
 }
 
 // for use by qsort, etc.
-static int comparePixelCoord(p_psPixelCoord* coord1, p_psPixelCoord* coord2)
+static int comparePixelCoord(psPixelCoord* coord1, psPixelCoord* coord2)
 {
     // check row first
@@ -65,10 +57,10 @@
 
     if (size > 0) {
-        out->x = psVectorAlloc(size, PS_TYPE_S32);
-        out->y = psVectorAlloc(size, PS_TYPE_S32);
+        out->data = psAlloc(sizeof(psPixelCoord)*size);
     } else {
-        out->x = NULL;
-        out->y = NULL;
-    }
+        out->data = NULL;
+    }
+    out->n = 0;
+    out->nalloc = size;
 
     psMemSetDeallocator(out, (psFreeFcn)pixelsFree);
@@ -83,8 +75,26 @@
     }
 
-    pixels->x = psVectorRealloc(pixels->x, size);
-    pixels->y = psVectorRealloc(pixels->y, size);
+    pixels->data = psRealloc(pixels->data, sizeof(psPixelCoord)*size);
+
+    pixels->nalloc = size;
+    if (pixels->n > pixels->nalloc) {
+        pixels->n = pixels->nalloc;
+    }
 
     return pixels;
+}
+
+psPixels* psPixelsCopy(psPixels* out, const psPixels* in)
+{
+    if (in == NULL) {
+        return NULL;
+    }
+
+    out = psPixelsRealloc(out, in->n);
+
+    memcpy(in->data,out->data, in->n*sizeof(psPixelCoord));
+    out->n = in->n;
+
+    return out;
 }
 
@@ -97,17 +107,6 @@
         return NULL;
     }
-    psVector* xVec = pixels->x;
-    psVector* yVec = pixels->y;
-    if (xVec == NULL || yVec == NULL) {
-        // XXX: Error message
-        psFree(out);
-        return NULL;
-    }
-    if (xVec->type.type != PS_TYPE_S32) {
-        // XXX: Error message
-        psFree(out);
-        return NULL;
-    }
-    if (yVec->type.type != PS_TYPE_S32) {
+    psPixelCoord* data = pixels->data;
+    if (data == NULL) {
         // XXX: Error message
         psFree(out);
@@ -151,17 +150,11 @@
 
     // determine the length of the pixel vector
-    int length = pixels->x->n;
-    if (pixels->y->n != length) {
-        // XXX: warning message
-        if (pixels->y->n < length) {
-            length = pixels->y->n;
-        }
-    }
+    int length = pixels->n;
 
     // cycle through the vector of pixels and insert pixels into image
     psMaskType** outData = out->data.PS_TYPE_MASK_DATA;
     for (int p = 0; p < length; p++) {
-        psS32 x = xVec->data.S32[p];
-        psS32 y = yVec->data.S32[p];
+        psS32 x = data[p].x;
+        psS32 y = data[p].y;
         // pixel in region?
         if (x >= x0 && x < x1 && y >= y0 && y < y1) {
@@ -195,24 +188,17 @@
         minPixels = 32;
     }
-    if (out == NULL) {
-        out = psPixelsAlloc(minPixels);
-    }
-    psVector* xVec = out->x;
-    psVector* yVec = out->y;
-
-    // check the x and y vector validity (type/minimum size)
-    if (xVec == NULL || xVec->type.type != PS_TYPE_S32 || xVec->nalloc < minPixels) {
-        xVec = psVectorRecycle(xVec,minPixels,PS_TYPE_S32);
-    }
-    if (yVec == NULL || yVec->type.type != PS_TYPE_S32 || yVec->nalloc < minPixels) {
-        yVec = psVectorRecycle(yVec, minPixels,PS_TYPE_S32);
+
+    // check out's validity (allocated/minimum size)
+    if (out == NULL || out->data == NULL || out->nalloc < minPixels) {
+        out = psPixelsRealloc(out,minPixels);
     }
 
     // start with a blank list of pixels
-    xVec->n = 0;
-    yVec->n = 0;
+    out->n = 0;
 
     // find the mask pixels in the image
     int numPixels = 0;
+    psPixelCoord* data = out->data;
+    int nalloc = out->nalloc;
     for (int row=0; row<numRows; row++) {
         psMaskType* maskRow = mask->data.PS_TYPE_MASK_DATA[row];
@@ -220,13 +206,12 @@
             if ( (maskRow[col] | maskVal) != 0 ) {
                 // check the vector sizes, and expand if necessary
-                if (xVec->nalloc >= numPixels) {
-                    xVec = psVectorRealloc(xVec, 2*xVec->nalloc);
+                if (nalloc >= numPixels) {
+                    out = psPixelsRealloc(out, 2*nalloc);
+                    nalloc = out->nalloc;
+                    data = out->data;
                 }
-                if (yVec->nalloc >= numPixels) {
-                    yVec = psVectorRealloc(yVec, 2*yVec->nalloc);
-                }
-
-                xVec->data.S32[numPixels] = col;
-                yVec->data.S32[numPixels] = row;
+
+                data[numPixels].x = col;
+                data[numPixels].y = row;
                 numPixels++;
             }
@@ -234,10 +219,4 @@
     }
 
-    // return the vectors to the psPixels struct
-    // (n.b., not assuming psVectorRealloc/psVectorRecycle, etc., didn't
-    //  relocate the vectors)
-    out->x = xVec;
-    out->y = yVec;
-
     return out;
 }
@@ -249,95 +228,35 @@
         return NULL;
     }
-    psVector* xPixels = pixels->x;
-    psVector* yPixels = pixels->y;
-
-    // verify that pixels has well formed vectors (type)
-    if (xPixels->type.type != PS_TYPE_S32 ||
-            yPixels->type.type != PS_TYPE_S32) {
-        // XXX: Error message
-        return NULL;
-    }
-
-    // determine the length of the pixel vector
-    int pixelsLen = xPixels->n;
-    if (yPixels->n != pixelsLen) {
-        // XXX: warning message
-        if (yPixels->n < pixelsLen) {
-            pixelsLen = yPixels->n;
+    int pixelsN = pixels->n;
+    psPixelCoord* pixelsData = pixels->data;
+
+    if (out == NULL) {
+        // simple copy pixels
+        out = psPixelsCopy(out,pixels);
+        return out;
+    }
+
+    // make sure the out is large enough to fit the result
+    int outN = out->n;
+    out = psPixelsRealloc(out,outN + pixelsN);
+    psPixelCoord* outData = out->data;
+
+    // sort the OUT array to help in searching for duplicates later
+    qsort(outData, sizeof(psPixelCoord), outN,
+          (qsortCompareFcn)comparePixelCoord);
+
+    // add non-duplicate values in pixels to out
+    psPixelCoord pCoord;
+    int end = outN;
+    for (int n = 0; n < pixelsN; n++) {
+        pCoord = pixelsData[n];
+        if (bsearch(&pCoord, outData, sizeof(psPixelCoord), outN,
+                    (qsortCompareFcn)comparePixelCoord) == NULL) {
+            // no match in OUT array of this value
+            outData[end++] = pCoord;
         }
     }
-
-    if (out == NULL) {
-        // simple copy of pixels
-        out = psPixelsAlloc(0); // let psVectorCopy allocate the vector
-        out->x = psVectorCopy(out->x,pixels->x,PS_TYPE_S32);
-        out->y = psVectorCopy(out->y,pixels->y,PS_TYPE_S32);
-
-        return out;
-    }
-
-    // make sure the out vectors are allocated
-    psVector* xVec = out->x;
-    psVector* yVec = out->y;
-    if (xVec == NULL) {
-        out->x = xVec = psVectorAlloc(pixelsLen,PS_TYPE_S32);
-        xVec->n = 0;
-    }
-    if (yVec == NULL) {
-        out->y = yVec = psVectorAlloc(pixelsLen,PS_TYPE_S32);
-        yVec->n = 0;
-    }
-
-    // verify that out has well formed vectors (type/size)
-    if (xVec->type.type != PS_TYPE_S32 ||
-            yVec->type.type != PS_TYPE_S32) {
-        // XXX: Error message
-        return NULL;
-    }
-    if (xVec->n != yVec->n) {
-        // XXX: Error message
-        return NULL;
-    }
-    int outLen = xVec->n;
-
-
-    // populate an array of psPixelCoord structs with the out values
-    p_psPixelCoord* coordinates = psAlloc(sizeof(p_psPixelCoord)*(pixelsLen+outLen));
-    psS32* outXData = xVec->data.S32;
-    psS32* outYData = yVec->data.S32;
-    for (int n = 0; n < outLen; n++) {
-        coordinates[n].x = outXData[n];
-        coordinates[n].y = outYData[n];
-    }
-
-    // sort the coordinates array
-    qsort(coordinates, sizeof(p_psPixelCoord), outLen,
-          (qsortCompareFcn)comparePixelCoord);
-
-    // search out for coordinates in pixels
-    int end = outLen;
-    psS32* pixelsXData = xPixels->data.S32;
-    psS32* pixelsYData = yPixels->data.S32;
-    p_psPixelCoord pCoord;
-    for (int n = 0; n < pixelsLen; n++) {
-        pCoord.x = pixelsXData[n];
-        pCoord.y = pixelsYData[n];
-        if (bsearch(&pCoord, coordinates, sizeof(p_psPixelCoord), outLen,
-                    (qsortCompareFcn)comparePixelCoord) == NULL) {
-            coordinates[end++] = pCoord;
-        }
-    }
-
-    // transfer the coordinates data back to psPixels
-    out = psPixelsRealloc(out, end);
-    outXData = xVec->data.S32;
-    outYData = yVec->data.S32;
-    for (int n = 0; n < end; n++) {
-        outXData[n] = coordinates[n].x;
-        outYData[n] = coordinates[n].y;
-    }
-
-    psFree(coordinates);
-
-    return out;
-}
+    out->n = end; // set number of elements to reflect added data
+
+    return out;
+}
Index: /trunk/psLib/src/image/psPixels.h
===================================================================
--- /trunk/psLib/src/image/psPixels.h	(revision 3759)
+++ /trunk/psLib/src/image/psPixels.h	(revision 3760)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-04-22 00:06:41 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-04-22 23:56:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -20,4 +20,11 @@
 /// @addtogroup Image
 /// @{
+
+typedef struct
+{
+    psS32 x;
+    psS32 y;
+}
+psPixelCoord;
 
 /** list of pixel coordinates
@@ -33,6 +40,7 @@
 typedef struct
 {
-    psVector *x;                       ///< x coordinate
-    psVector *y;                       ///< y coordinate
+    int n;
+    int nalloc;
+    psPixelCoord* data;
 }
 psPixels;
@@ -54,4 +62,16 @@
     psPixels* pixels,                  ///< psPixels to resize, or NULL to create new psPixels
     int size                           ///< the size of the coordinate vectors
+);
+
+/** Copies a psPixels object
+ *
+ *  Makes a deep copy of the data in a psPixels object.  Any data in the OUT
+ *  parameter will be destroyed and OUT will be resized, if necessary.
+ *
+ *  @return psPixels*   a new psPixels that is a duplicate to IN
+ */
+psPixels* psPixelsCopy(
+    psPixels* out,                     ///< psPixels struct to recycle, or NULL
+    const psPixels* in                 ///< psPixels struct to copy
 );
 
