Index: /trunk/psModules/src/pmImageCombine.c
===================================================================
--- /trunk/psModules/src/pmImageCombine.c	(revision 3877)
+++ /trunk/psModules/src/pmImageCombine.c	(revision 3878)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-05-10 23:48:19 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-05-11 00:33:44 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,5 +27,10 @@
 #include "psPixels.h"
 
-
+//
+// The following macros define how big the initial pixel list will be, and
+// how much it should be incremented when realloc'ed.
+//
+#define PS_COMBINE_IMAGE_INITIAL_PIXEL_LIST_LENGTH 100
+#define PS_COMBINE_IMAGE_INITIAL_PIXEL_LIST_LENGTH_INC 100
 /******************************************************************************
 pmCombineImages(combine, questionablePixels, images, errors, masks, maskVal,
@@ -93,5 +98,5 @@
     PS_PTR_CHECK_NULL(stats, combine);
 
-    // Allocate an initialize the combined image, if necessary.
+    // Allocate and initialize the combined image, if necessary.
     if (combine == NULL) {
         combine = psImageAlloc(numCols, numRows, PS_TYPE_F32);
@@ -100,4 +105,23 @@
         }
     }
+
+    //
+    // Allocate the questionablePixels psArray, if necesssary, then create a psPixels
+    // struct for each image.
+    //
+    if (*questionablePixels == NULL) {
+        *questionablePixels = psArrayAlloc(numImages);
+    } else if ((*questionablePixels)->n != numImages) {
+        *questionablePixels = psArrayRealloc(*questionablePixels, numImages);
+    }
+    for (psS32 im = 0 ; im < numImages ; im++) {
+        psFree((*questionablePixels)->data[im]);
+        ((*questionablePixels)->data[im]) = (psPtr *) psPixelsAlloc(PS_COMBINE_IMAGE_INITIAL_PIXEL_LIST_LENGTH);
+    }
+    //
+    // qpPtr is used to maintain a count of the questionable pixels for each image.
+    //
+    psVector *qpPtr = psVectorAlloc(numImages, PS_TYPE_S32);
+    PS_VECTOR_SET_S32(qpPtr, 0);
 
     //
@@ -178,7 +202,15 @@
                         pixelMask->data.F32[im] = maskVal;
                         //
-                        // XXX: Must Code This.
-                        // XXX: Add this to the list of questionable pixels.
+                        // XXX: These data structures indirections are getting complicated.
                         //
+                        psS32 ptr = qpPtr->data.S32[im];
+                        psPixels *pixelListPtr = ((psPixels *) ((*questionablePixels)->data[im]));
+                        if (ptr >= pixelListPtr->n) {
+                            (*questionablePixels)->data[im] = (psPtr *) psPixelsRealloc(((psPixels *) ((*questionablePixels)->data[im])), ((((psPixels *) ((*questionablePixels)->data[im]))->n) + PS_COMBINE_IMAGE_INITIAL_PIXEL_LIST_LENGTH_INC));
+                        }
+                        // XXX: Can the realloc() fail?  Must we check for NULL?
+                        ((psPixels *) ((*questionablePixels)->data[im]))->data[ptr].x = col;
+                        ((psPixels *) ((*questionablePixels)->data[im]))->data[ptr].y = row;
+                        (qpPtr->data.S32[im])++;
                     }
                 }
@@ -229,5 +261,5 @@
     psFree(pixelMask);
     psFree(pixelErrors);
-
+    psFree(qpPtr);
 
     return(combine);
@@ -274,4 +306,10 @@
 }
 
+//
+// The following macros define how big the initial pixel list will be, and
+// how much it should be incremented when realloc'ed.
+//
+#define PS_REJECT_PIXEL_INITIAL_PIXEL_LIST_LENGTH 100
+#define PS_REJECT_PIXEL_INITIAL_PIXEL_LIST_LENGTH_INC 100
 /******************************************************************************
 pmRejectPixels(images, errors, inToOut, outToIn, rejThreshold,
@@ -302,4 +340,18 @@
     // XXX: Loop through all images, ensure their sizes are equal?
 
+    //
+    // Create the psArray of psPixelLists, one for each image, for rejected pixels.
+    //
+    psArray *rejects = psArrayAlloc(numImages);
+    for (psS32 im = 0 ; im < numImages ; im++) {
+        rejects->data[im] = (psPtr *) psPixelsAlloc(PS_REJECT_PIXEL_INITIAL_PIXEL_LIST_LENGTH);
+    }
+    //
+    // rPtr is used to maintain a count of the questionable pixels for each image.
+    //
+    psVector *rPtr = psVectorAlloc(numImages, PS_TYPE_S32);
+    PS_VECTOR_SET_S32(rPtr, 0);
+
+
     psS32 numCols = ((psImage *) images->data[0])->numCols;
     psS32 numRows = ((psImage *) images->data[0])->numRows;
@@ -310,16 +362,16 @@
     psPlane *outCoords = psAlloc(sizeof(psPlane));
 
-    for (psS32 img = 0 ; img < numImages ; img++) {
+    for (psS32 im = 0 ; im < numImages ; im++) {
         //
         // Extract data from psArrays.
         //
-        psPixels *pixelList = (psPixels *) errors->data[img];
-        psImage *currImage = (psImage *) images->data[img];
+        psPixels *pixelList = (psPixels *) errors->data[im];
+        psImage *currImage = (psImage *) images->data[im];
         myRegion->x0 = 0;
         myRegion->x1 = currImage->numCols - 1;
         myRegion->y0 = 0;
         myRegion->y1 = currImage->numRows - 1;
-        psPlaneTransform *myInToOut = (psPlaneTransform *) inToOut->data[img];
-        psPlaneTransform *myOutToIn = (psPlaneTransform *) outToIn->data[img];
+        psPlaneTransform *myInToOut = (psPlaneTransform *) inToOut->data[im];
+        psPlaneTransform *myOutToIn = (psPlaneTransform *) outToIn->data[im];
 
         //
@@ -341,6 +393,6 @@
         //
         for (psS32 p = 0 ; p < pixelList->n ; p++) {
-            inCoords->x = 0.5 + (psF32) (pixelList->data)->x;
-            inCoords->y = 0.5 + (psF32) (pixelList->data)->y;
+            inCoords->x = 0.5 + (psF32) (pixelList->data[p]).x;
+            inCoords->y = 0.5 + (psF32) (pixelList->data[p]).y;
             psPlaneTransformApply(outCoords, myInToOut, inCoords);
 
@@ -358,5 +410,5 @@
                 //
                 for (psS32 otherImg = 0 ; otherImg < numImages ; otherImg++) {
-                    if (img != otherImg) {
+                    if (im != otherImg) {
                         // Map the outCoords to inCoords that for otherImg space.
                         psPlaneTransformApply(inCoords, (psPlaneTransform * )outToIn->data[otherImg], outCoords);
@@ -383,7 +435,17 @@
                 if (meanGrads < gradLimit) {
                     //
-                    // XXX: Add this to the list of questionable pixels.
-                    // XXX: Must Code This.
+                    // Add this to the list of questionable pixels.  We must ensure that the
+                    // pixelList is large enough; if not, we realloc()
                     //
+                    psS32 ptr = rPtr->data.S32[im];
+                    psPixels *pixelListPtr = (psPixels *) rejects->data[im];
+                    if (ptr >= pixelListPtr->n) {
+                        rejects->data[im] = (psPtr *) psPixelsRealloc(((psPixels *) rejects->data[im]),
+                                            ((((psPixels *) rejects->data[im])->n) + PS_REJECT_PIXEL_INITIAL_PIXEL_LIST_LENGTH_INC));
+                    }
+                    // XXX: Can the realloc() fail?  Must we check for NULL?
+                    ((psPixels *) rejects->data[im])->data[ptr].x = (pixelList->data[p]).x;
+                    ((psPixels *) rejects->data[im])->data[ptr].y = (pixelList->data[p]).y;
+                    (rPtr->data.S32[im])++;
                 }
             }
@@ -400,4 +462,3 @@
     return(NULL);
 }
-// This code is
-
+
