Index: trunk/psLib/src/image/psImageStats.c
===================================================================
--- trunk/psLib/src/image/psImageStats.c	(revision 1406)
+++ trunk/psLib/src/image/psImageStats.c	(revision 1407)
@@ -1,2 +1,3 @@
+
 /** @file psImageStats.c
 *  \brief Routines for calculating statistics on images.
@@ -9,6 +10,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-06 22:34:05 $
+*  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-07 00:06:06 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,49 +33,50 @@
 
 /// This routine must determine the various statistics for the image.
+
 /*****************************************************************************
     NOTE: verify that image/mask have the correct types, and sizes.
  *****************************************************************************/
-psStats *psImageStats(psStats *stats,
-                      psImage *in,
-                      psImage *mask,
-                      int maskVal)
-{
-    psVector* junkData=NULL;
-    psVector* junkMask=NULL;
+psStats *psImageStats(psStats * stats, psImage * in, psImage * mask, int maskVal)
+{
+    psVector *junkData = NULL;
+    psVector *junkMask = NULL;
 
     if (stats == NULL) {
-        psError(__func__,"The input psStats struct can not be NULL.");
+        psError(__func__, "The input psStats struct can not be NULL.");
         return NULL;
     }
 
     if (in == NULL) {
-        psError(__func__,"The input image can not be NULL.");
+        psError(__func__, "The input image can not be NULL.");
         return NULL;
     }
 
     if (stats->options == 0) {
-        psError(__func__,"No statistic option/operation was specified.");
+        psError(__func__, "No statistic option/operation was specified.");
         return stats;
     }
-
-    // stuff the image data into a psVector struct.
+    // stuff the image data into a psVector
+    // struct.
     junkData = psAlloc(sizeof(psVector));
     junkData->type = in->type;
-    junkData->nalloc = in->numRows*in->numCols;
+    junkData->nalloc = in->numRows * in->numCols;
     junkData->n = junkData->nalloc;
-    junkData->data.V = in->data.V[0];    // since psImage data is contiguous...
+    junkData->data.V = in->data.V[0];      // since
+    // psImage
+    // data
+    // is
+    // contiguous...
 
     if (mask != NULL) {
         if (mask->type.type != PS_TYPE_MASK) {
-            psError(__func__, "Expected the mask image type not found (type=%x)",
-                    mask->type.type);
+            psError(__func__, "Expected the mask image type not found (type=%x)", mask->type.type);
             psFree(junkData);
             return NULL;
         }
-
-        // stuff the mask data into a psVector struct.
+        // stuff the mask data into a psVector
+        // struct.
         junkMask = psAlloc(sizeof(psVector));
         junkMask->type = mask->type;
-        junkMask->nalloc = mask->numRows*mask->numCols;
+        junkMask->nalloc = mask->numRows * mask->numCols;
         junkMask->n = junkMask->nalloc;
         junkMask->data.V = mask->data.V[0];
@@ -85,5 +87,5 @@
     psFree(junkMask);
     psFree(junkData);
-    return(stats);
+    return (stats);
 }
 
@@ -93,36 +95,35 @@
     NOTE: verify that image/mask have the, correct types and  sizes.
  *****************************************************************************/
-psHistogram *psImageHistogram(psHistogram *out,
-                              psImage *in,
-                              psImage *mask,
-                              unsigned int maskVal)
-{
-    psVector *junkData=NULL;
-    psVector *junkMask=NULL;
+psHistogram *psImageHistogram(psHistogram * out, psImage * in, psImage * mask, unsigned int maskVal)
+{
+    psVector *junkData = NULL;
+    psVector *junkMask = NULL;
 
     // NOTE: Verify this action.
-    if ((out == NULL) ||
-            (in == NULL)) {
-        return(NULL);
+    if ((out == NULL) || (in == NULL)) {
+        return (NULL);
     }
 
     junkData = psAlloc(sizeof(psVector));
     junkData->type = in->type;
-    junkData->nalloc = in->numRows*in->numCols;
+    junkData->nalloc = in->numRows * in->numCols;
     junkData->n = junkData->nalloc;
-    junkData->data.V = in->data.V[0];    // since psImage data is contiguous...
+    junkData->data.V = in->data.V[0];      // since
+    // psImage
+    // data
+    // is
+    // contiguous...
 
     if (mask != NULL) {
         if (mask->type.type != PS_TYPE_MASK) {
-            psError(__func__, "Expected the mask image type not found (type=%x)",
-                    mask->type.type);
+            psError(__func__, "Expected the mask image type not found (type=%x)", mask->type.type);
             psFree(junkData);
             return NULL;
         }
-
-        // stuff the mask data into a psVector struct.
+        // stuff the mask data into a psVector
+        // struct.
         junkMask = psAlloc(sizeof(psVector));
         junkMask->type = mask->type;
-        junkMask->nalloc = mask->numRows*mask->numCols;
+        junkMask->nalloc = mask->numRows * mask->numCols;
         junkMask->n = junkMask->nalloc;
         junkMask->data.V = mask->data.V[0];
@@ -134,5 +135,5 @@
     psFree(junkData);
 
-    return(out);
+    return (out);
 }
 
@@ -141,15 +142,16 @@
     int i = 0;
     float tmp = 0.0;
-    float *scalingFactors = (float *) psAlloc(n * sizeof(float));
-
-    for (i=0;i<n;i++) {
-        //     ((2.0 * (float) i) / ((float) (n-1))) - 1.0;
-        //        tmp = (float) (i + 1);
-        tmp = (float) (n - i);
-        tmp = (M_PI * (tmp - 0.5)) / ((float) n);
+    float *scalingFactors = (float *)psAlloc(n * sizeof(float));
+
+    for (i = 0; i < n; i++) {
+        // ((2.0 * (float) i) / ((float) (n-1)))
+        // - 1.0;
+        // tmp = (float) (i + 1);
+        tmp = (float)(n - i);
+        tmp = (M_PI * (tmp - 0.5)) / ((float)n);
         scalingFactors[i] = cos(tmp);
     }
 
-    return(scalingFactors);
+    return (scalingFactors);
 }
 
@@ -165,15 +167,18 @@
     int i = 0;
     float tmp = 0.0;
+
     return p_psCalcScaleFactorsFit(n);
 
     printf("Should not get here\n");
-    float *scalingFactors = (float *) psAlloc(n * sizeof(float));
-    for (i=0;i<n;i++) {
-        //          scalingFactors[i] = ((2.0 * (float) i) / ((float) (n-1))) - 1.0;
-        tmp = (float) (n - i);
-        tmp = (M_PI * (tmp - 0.5)) / ((float) n);
+    float *scalingFactors = (float *)psAlloc(n * sizeof(float));
+
+    for (i = 0; i < n; i++) {
+        // scalingFactors[i] = ((2.0 * (float) i)
+        // / ((float) (n-1))) - 1.0;
+        tmp = (float)(n - i);
+        tmp = (M_PI * (tmp - 0.5)) / ((float)n);
         scalingFactors[i] = cos(tmp);
     }
-    return(scalingFactors);
+    return (scalingFactors);
 }
 
@@ -184,25 +189,24 @@
     int j = 0;
 
-    chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly *
-                                            sizeof(psPolynomial1D *));
-    for (i=0;i<maxChebyPoly;i++) {
-        chebPolys[i] = psPolynomial1DAlloc(i+1);
-    }
-
-    // Create the Chebyshev polynomials.  Polynomial i has i-th order.
+    chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
+    for (i = 0; i < maxChebyPoly; i++) {
+        chebPolys[i] = psPolynomial1DAlloc(i + 1);
+    }
+
+    // Create the Chebyshev polynomials.
+    // Polynomial i has i-th order.
     chebPolys[0]->coeff[0] = 1;
     chebPolys[1]->coeff[1] = 1;
-    for (i=2;i<maxChebyPoly;i++) {
-        for (j=0;j<chebPolys[i-1]->n;j++) {
-            chebPolys[i]->coeff[j+1] = 2 * chebPolys[i-1]->coeff[j];
-        }
-        for (j=0;j<chebPolys[i-2]->n;j++) {
-            chebPolys[i]->coeff[j]-= chebPolys[i-2]->coeff[j];
-        }
-    }
-
-    return(chebPolys);
-}
-
+    for (i = 2; i < maxChebyPoly; i++) {
+        for (j = 0; j < chebPolys[i - 1]->n; j++) {
+            chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
+        }
+        for (j = 0; j < chebPolys[i - 2]->n; j++) {
+            chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
+        }
+    }
+
+    return (chebPolys);
+}
 
 /*****************************************************************************
@@ -220,7 +224,5 @@
         over all pixels (x,y) in the image.
  *****************************************************************************/
-psPolynomial2D *
-psImageFitPolynomial(const psImage *input,
-                     psPolynomial2D *coeffs)
+psPolynomial2D *psImageFitPolynomial(const psImage * input, psPolynomial2D * coeffs)
 {
     int x = 0;
@@ -235,16 +237,21 @@
     float tmp = 0.0;
 
-    // Create the sums[][] data structure.  This will hold the LHS of equation
-    // 29 in the ADD: sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) }
-    sums = (float **) psAlloc(coeffs->nX * sizeof(float *));
-    for (i=0;i<coeffs->nX;i++) {
-        sums[i] = (float *) psAlloc(coeffs->nY * sizeof(float));
-    }
-
-    // We scale the pixel positions to values between -1.0 and 1.0
+    // Create the sums[][] data structure.  This
+    // will hold the LHS of
+    // equation
+    // 29 in the ADD: sums[k][l] = SUM {
+    // image(x,y) * Tk(x) * Tl(y) }
+    sums = (float **)psAlloc(coeffs->nX * sizeof(float *));
+    for (i = 0; i < coeffs->nX; i++) {
+        sums[i] = (float *)psAlloc(coeffs->nY * sizeof(float));
+    }
+
+    // We scale the pixel positions to values
+    // between -1.0 and 1.0
     rScalingFactors = p_psCalcScaleFactorsFit(input->numRows);
     cScalingFactors = p_psCalcScaleFactorsFit(input->numCols);
 
-    // Determine how many Chebyshev polynomials are needed, then create them.
+    // Determine how many Chebyshev polynomials
+    // are needed, then create them.
     maxChebyPoly = coeffs->nX;
     if (coeffs->nY > coeffs->nX) {
@@ -254,25 +261,29 @@
 
     // Sanity check for the Chebyshevs.
-    for (i=0;i<coeffs->nX;i++) {
-        for (j=0;j<coeffs->nY;j++) {
+    for (i = 0; i < coeffs->nX; i++) {
+        for (j = 0; j < coeffs->nY; j++) {
             tmp = 0.0;
-            for (x=0;x<input->numRows;x++) {
-                tmp+= psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
-                      psPolynomial1DEval(rScalingFactors[x], chebPolys[j]);
+            for (x = 0; x < input->numRows; x++) {
+                tmp +=
+                    psPolynomial1DEval
+                    (rScalingFactors[x], chebPolys[i]) * psPolynomial1DEval(rScalingFactors[x], chebPolys[j]);
 
             }
-            //printf("SUM(Cheby(%d) * Cheby(%d)) is %f\n", i, j, tmp);
+            // printf("SUM(Cheby(%d) * Cheby(%d))
+            // is %f\n", i, j, tmp);
         }
     }
 
     // Compute the sums[][] data structure.
-    for (i=0;i<coeffs->nX;i++) {
-        for (j=0;j<coeffs->nY;j++) {
+    for (i = 0; i < coeffs->nX; i++) {
+        for (j = 0; j < coeffs->nY; j++) {
             sums[i][j] = 0.0;
-            for (x=0;x<input->numRows;x++) {
-                for (y=0;y<input->numCols;y++) {
-                    sums[i][j]+= input->data.F32[x][y] *
-                                 psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
-                                 psPolynomial1DEval(cScalingFactors[y], chebPolys[j]);
+            for (x = 0; x < input->numRows; x++) {
+                for (y = 0; y < input->numCols; y++) {
+                    sums[i][j] +=
+                        input->data.F32[x][y] *
+                        psPolynomial1DEval
+                        (rScalingFactors[x],
+                         chebPolys[i]) * psPolynomial1DEval(cScalingFactors[y], chebPolys[j]);
                 }
             }
@@ -280,22 +291,22 @@
     }
 
-    for (i=0;i<coeffs->nX;i++) {
-        for (j=0;j<coeffs->nY;j++) {
+    for (i = 0; i < coeffs->nX; i++) {
+        for (j = 0; j < coeffs->nY; j++) {
             coeffs->coeff[i][j] = sums[i][j];
-            coeffs->coeff[i][j]/= (float) (input->numRows * input->numCols);
+            coeffs->coeff[i][j] /= (float)(input->numRows * input->numCols);
 
             if ((i != 0) && (j != 0)) {
-                coeffs->coeff[i][j]*= 4.0;
-            } else
-                if ((i == 0) && (j == 0)) {
-                    coeffs->coeff[i][j]*= 1.0;
-                } else {
-                    coeffs->coeff[i][j]*= 2.0;
-                }
-        }
-    }
-
-    // Free the Chebyshev polynomials that were created in this routine.
-    for (i=0;i<maxChebyPoly;i++) {
+                coeffs->coeff[i][j] *= 4.0;
+            } else if ((i == 0) && (j == 0)) {
+                coeffs->coeff[i][j] *= 1.0;
+            } else {
+                coeffs->coeff[i][j] *= 2.0;
+            }
+        }
+    }
+
+    // Free the Chebyshev polynomials that were
+    // created in this routine.
+    for (i = 0; i < maxChebyPoly; i++) {
         psFree(chebPolys[i]);
     }
@@ -303,5 +314,5 @@
 
     // Free some data
-    for (i=0;i<coeffs->nX;i++) {
+    for (i = 0; i < coeffs->nX; i++) {
         psFree(sums[i]);
     }
@@ -310,5 +321,5 @@
     psFree(rScalingFactors);
 
-    return(coeffs);
+    return (coeffs);
 }
 
@@ -316,7 +327,5 @@
  
  *****************************************************************************/
-int
-psImageEvalPolynomial(const psImage *input,
-                      const psPolynomial2D *coeffs)
+int psImageEvalPolynomial(const psImage * input, const psPolynomial2D * coeffs)
 {
     int x = 0;
@@ -331,21 +340,26 @@
     float polySum = 0.0;
 
-    // Create the sums[][] data structure.  This will hold the LHS of equation
-    // 29 in the ADD: sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) }
-    sums = (float **) psAlloc(coeffs->nX * sizeof(float *));
-    for (i=0;i<coeffs->nX;i++) {
-        sums[i] = (float *) psAlloc(coeffs->nY * sizeof(float));
-    }
-    for (i=0;i<coeffs->nX;i++) {
-        for (j=0;j<coeffs->nY;j++) {
+    // Create the sums[][] data structure.  This
+    // will hold the LHS of
+    // equation
+    // 29 in the ADD: sums[k][l] = SUM {
+    // image(x,y) * Tk(x) * Tl(y) }
+    sums = (float **)psAlloc(coeffs->nX * sizeof(float *));
+    for (i = 0; i < coeffs->nX; i++) {
+        sums[i] = (float *)psAlloc(coeffs->nY * sizeof(float));
+    }
+    for (i = 0; i < coeffs->nX; i++) {
+        for (j = 0; j < coeffs->nY; j++) {
             sums[i][j] = 0.0;
         }
     }
 
-    // We scale the pixel positions to values between -1.0 and 1.0
+    // We scale the pixel positions to values
+    // between -1.0 and 1.0
     rScalingFactors = p_psCalcScaleFactorsEval(input->numRows);
     cScalingFactors = p_psCalcScaleFactorsEval(input->numCols);
 
-    // Determine how many Chebyshev polynomials are needed, then create them.
+    // Determine how many Chebyshev polynomials
+    // are needed, then create them.
     maxChebyPoly = coeffs->nX;
     if (coeffs->nY > coeffs->nX) {
@@ -355,12 +369,14 @@
     chebPolys = p_psCreateChebyshevPolys(maxChebyPoly);
 
-    for (x=0;x<input->numRows;x++) {
-        for (y=0;y<input->numCols;y++) {
+    for (x = 0; x < input->numRows; x++) {
+        for (y = 0; y < input->numCols; y++) {
             polySum = 0.0;
-            for (i=0;i<coeffs->nX;i++) {
-                for (j=0;j<coeffs->nY;j++) {
-                    polySum+= psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
-                              psPolynomial1DEval(cScalingFactors[y], chebPolys[j]) *
-                              coeffs->coeff[i][j];
+            for (i = 0; i < coeffs->nX; i++) {
+                for (j = 0; j < coeffs->nY; j++) {
+                    polySum +=
+                        psPolynomial1DEval
+                        (rScalingFactors[x],
+                         chebPolys[i]) *
+                        psPolynomial1DEval(cScalingFactors[y], chebPolys[j]) * coeffs->coeff[i][j];
 
                 }
@@ -370,6 +386,7 @@
     }
 
-    // Free the Chebyshev polynomials that were created in this routine.
-    for (i=0;i<maxChebyPoly;i++) {
+    // Free the Chebyshev polynomials that were
+    // created in this routine.
+    for (i = 0; i < maxChebyPoly; i++) {
         psFree(chebPolys[i]);
     }
@@ -377,5 +394,5 @@
 
     // Free some data
-    for (i=0;i<coeffs->nX;i++) {
+    for (i = 0; i < coeffs->nX; i++) {
         psFree(sums[i]);
     }
@@ -384,4 +401,4 @@
     psFree(rScalingFactors);
 
-    return(0);
-}
+    return (0);
+}
