Index: trunk/psModules/src/pmObjects.c
===================================================================
--- trunk/psModules/src/pmObjects.c	(revision 3698)
+++ trunk/psModules/src/pmObjects.c	(revision 3699)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-04-14 02:07:10 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-04-14 02:42:41 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -313,14 +313,8 @@
 of all peaks.
  
-XXX: I'm not convinced the peak type definition in the SDRS is mutually
-exclusive.  Some peaks can have multiple types.  Edges for sure.  Also, a
-digonal line with the same value at each point will have a peak for every
-point on that line.
+XXX: For multiple type peaks, ensure that each is set.
  
 XXX: This does not work if image has either a single row, or a single column.
- 
-XXX: In the output psList elements, should we use the image row/column offsets?
-     Currently, we do not.
- *****************************************************************************/
+  *****************************************************************************/
 psList *pmFindImagePeaks(const psImage *image,
                          psF32 threshold)
@@ -391,5 +385,5 @@
     //
     for (row = 1 ; row < (image->numRows - 1) ; row++) {
-        tmpRow = p_psGetRowVectorFromImage((psImage *) image, 0);
+        tmpRow = p_psGetRowVectorFromImage((psImage *) image, row);
         row1 = pmFindVectorPeaks(tmpRow, threshold);
 
@@ -507,4 +501,8 @@
 
 
+/******************************************************************************
+PS_REGION_CHECK(VALID, X, Y): this macro evaluates to TRUE if the coordinate
+(X, Y) is within REGION, otherwise it evaluates to FALSE.
+ *****************************************************************************/
 #define PS_REGION_CHECK(VALID, X, Y) \
 (((X) >= (VALID)->x0) && \
@@ -513,29 +511,9 @@
  ((Y) <= (VALID)->y1))
 
-// XXX: Macro this.
-bool IsItInThisRegion(const psRegion *valid,
-                      psS32 x,
-                      psS32 y)
-{
-
-    if ((x >= valid->x0) &&
-            (x <= valid->x1) &&
-            (y >= valid->y0) &&
-            (y <= valid->y1)) {
-        return(true);
-    }
-
-    return(false);
-}
-
 
 /******************************************************************************
 psCullPeaks(peaks, maxValue, valid): eliminate peaks from the psList that have
 a peak value above the given maximum, or fall outside the valid region.
- 
-XXX: Should the sky value be used when comparing the maximum?
- 
-XXX: warning message if valid is NULL?
- *****************************************************************************/
+  *****************************************************************************/
 psList *pmCullPeaks(psList *peaks,
                     psF32 maxValue,
@@ -543,15 +521,15 @@
 {
     PS_PTR_CHECK_NULL(peaks, NULL);
-    //    PS_PTR_CHECK_NULL(valid, NULL);
+    if (valid == NULL) {
+        psLogMsg(__func__, PS_LOG_WARN, "WARNING: psRegion valid is NULL.  Ignoring ...\n");
+    }
 
     psListElem *tmpListElem = (psListElem *) peaks->head;
     psS32 indexNum = 0;
 
-    //    printf("pmCullPeaks(): list size is %d\n", peaks->size);
     while (tmpListElem != NULL) {
         psPeak *tmpPeak = (psPeak *) tmpListElem->data;
         if ((tmpPeak->counts > maxValue) ||
                 ((valid != NULL) &&
-                 //                 (true == IsItInThisRegion(valid, tmpPeak->x, tmpPeak->y)))) {
                  (true == PS_REGION_CHECK(valid, tmpPeak->x, tmpPeak->y)))) {
             psListRemoveData(peaks, (psPtr) tmpPeak);
@@ -576,6 +554,4 @@
 We simply create a subSet image and mask the inner pixels, then call
 psImageStats on that subImage+mask.
- 
-XXX: The subImage has width of 1+2*outerRadius.  Verify with IfA.
  
 XXX: Use static data structures for:
@@ -726,39 +702,19 @@
 
 /******************************************************************************
-bool CheckRadius(*peak, radius, x, y): private function which simply
-determines if the (x, y) point is within the radius of the specified peak.
- 
-XXX: macro this for performance.
+bool PS_RADIUS_CHECK(): a macro which evaluates to TRUE if the (x, y) point is
+within the radius of the specified peak.
   *****************************************************************************/
-bool CheckRadius(psPeak *peak,
-                 psF32 radius,
-                 psS32 x,
-                 psS32 y)
-{
-    if (PS_SQR(radius) >= (psF32) (PS_SQR(x - peak->x) + PS_SQR(y - peak->y))) {
-        return(true);
-    }
-
-    return(false);
-}
-
-/******************************************************************************
-bool CheckRadius2(): private function which simply determines if the (x, y)
-point is within the radius of the specified peak.
- 
-XXX: macro this for performance.
+#define PS_RADIUS_CHECK(PEAK, RADIUS, X, Y) \
+(PS_SQR((RADIUS)) >= ((psF32) (PS_SQR((X) - (PEAK)->x) + PS_SQR((Y) - (PEAK)->y))))
+
+
+/******************************************************************************
+bool PS_RADIUS_CHECK22(): a macro which evaluates to TRUE if the (x, y) point
+is within the radius of the specified point.
   *****************************************************************************/
-bool CheckRadius2(psF32 xCenter,
-                  psF32 yCenter,
-                  psF32 radius,
-                  psF32 x,
-                  psF32 y)
-{
-    if ((PS_SQR(x - xCenter) + PS_SQR(y - yCenter)) < PS_SQR(radius)) {
-        return(true);
-    }
-
-    return(false);
-}
+#define PS_RADIUS_CHECK2(X_CENTER, Y_CENTER, RADIUS, X, Y) \
+(PS_SQR((RADIUS)) >= ((psF32) (PS_SQR((X) - (X_CENTER)) + PS_SQR((Y) - (Y_CENTER)))))
+
+
 
 /******************************************************************************
@@ -772,6 +728,4 @@
     psSource->pixels
  
-XXX: The peak calculations are done in image coords, not subImage coords.
- 
 XXX: mask values?
  *****************************************************************************/
@@ -784,10 +738,9 @@
     PS_FLOAT_COMPARE(0.0, radius, NULL);
 
-    //
-    // XXX: Verify the setting for sky if source->moments == NULL.
-    //
     psF32 sky = 0.0;
     if (source->moments == NULL) {
-        source->moments = pmMomentsAlloc();
+        psError(PS_ERR_UNKNOWN, true, "Undefined source->psMoments is NULL");
+        psFree(source);
+        return(NULL);
     } else {
         sky = source->moments->Sky;
@@ -818,8 +771,8 @@
                 psS32 imgColCoord = col + source->pixels->col0;
                 psS32 imgRowCoord = row + source->pixels->row0;
-                if (CheckRadius(source->peak,
-                                radius,
-                                imgColCoord,
-                                imgRowCoord)) {
+                if (PS_RADIUS_CHECK(source->peak,
+                                    radius,
+                                    imgColCoord,
+                                    imgRowCoord)) {
                     psF32 xDiff = (psF32) (imgColCoord - source->peak->x);
                     psF32 yDiff = (psF32) (imgRowCoord - source->peak->y);
@@ -866,6 +819,4 @@
  
 XXX: The sigX and sigY stuff in the SDRS is unclear.
- 
-XXX: How can this function ever return FALSE?
  *****************************************************************************/
 #define SATURATE 0.0
@@ -941,11 +892,6 @@
 pmSourceSetPixelCircle(source, image, radius)
  
-XXX: Why boolean output?
- 
-XXX: Why are we checking source->moments for NULL?  Should the circle be
-     centered on the centroid or the peak?
- 
-XXX: The circle will have a diameter of (1+radius).  This is different from
-     the pmSourceSetLocal() function.
+XXX: Checking source->moments for NULL.  Circle must be centered on the
+     centroid, not peak (from IfA 2005-04-06).
  *****************************************************************************/
 bool pmSourceSetPixelCircle(psSource *source,
@@ -1021,9 +967,9 @@
         for (psS32 col = 0 ; col < source->mask->numCols; col++) {
 
-            if (CheckRadius2((psF32) radiusS32,
-                             (psF32) radiusS32,
-                             radius,
-                             (psF32) col,
-                             (psF32) row)) {
+            if (PS_RADIUS_CHECK2((psF32) radiusS32,
+                                 (psF32) radiusS32,
+                                 radius,
+                                 (psF32) col,
+                                 (psF32) row)) {
                 source->mask->data.U8[row][col] = 1;
             } else {
@@ -1151,5 +1097,5 @@
 
 /******************************************************************************
-evalModel(source, level, row): a private function which evaluates the
+evalModel(src, col, row): a private function which evaluates the
 source->model function at the specified coords.  The coords are subImage, not
 image coords.
@@ -1157,6 +1103,4 @@
 NOTE: The coords are in subImage source->pixel coords, not image coords.
  
-XXX: reverse order of row,col args?
- 
 XXX: rename all coords in this file such that their name defines whether
 the coords is in subImage or image space.
@@ -1172,6 +1116,6 @@
  *****************************************************************************/
 psF32 evalModel(psSource *src,
-                psU32 row,
-                psU32 col)
+                psU32 col,
+                psU32 row)
 {
     PS_PTR_CHECK_NULL(src, false);
@@ -1224,11 +1168,9 @@
 
 /******************************************************************************
-findValue(source, level, row, col, dir): a private function which determines
+findValue(source, level, col, row, dir): a private function which determines
 the column coordinate of the model function which has the value "level".  If
 dir equals 0, then you loop leftwards from the peak pixel, otherwise,
 rightwards.
  
-XXX: reverse order of row,col args?
- 
 XXX: Input row/col are in image coords.
  
@@ -1237,6 +1179,6 @@
 psF32 findValue(psSource *source,
                 psF32 level,
+                psU32 col,
                 psU32 row,
-                psU32 col,
                 psU32 dir)
 {
@@ -1257,5 +1199,5 @@
     }
 
-    psF32 oldValue = evalModel(source, subRow, subCol);
+    psF32 oldValue = evalModel(source, subCol, subRow);
     if (oldValue == level) {
         return(((psF32) (subCol + source->pixels->col0)));
@@ -1278,5 +1220,5 @@
 
     while (subCol != lastColumn) {
-        psF32 newValue = evalModel(source, subRow, subCol);
+        psF32 newValue = evalModel(source, subCol, subRow);
         if (oldValue == level) {
             return((psF32) (subCol + source->pixels->col0));
@@ -1338,5 +1280,5 @@
 
         // Starting at peak pixel, search leftwards for the column intercept.
-        psF32 leftIntercept = findValue(source, level, row, col, 0);
+        psF32 leftIntercept = findValue(source, level, col, row, 0);
         if (isnan(leftIntercept)) {
             psError(PS_ERR_UNKNOWN, true, "Could not find contour edge (NAN)");
@@ -1349,5 +1291,5 @@
         // Starting at peak pixel, search rightwards for the column intercept.
 
-        psF32 rightIntercept = findValue(source, level, row, col, 1);
+        psF32 rightIntercept = findValue(source, level, col, row, 1);
         if (isnan(rightIntercept)) {
             psError(PS_ERR_UNKNOWN, true, "Could not find contour edge (NAN)");
@@ -1372,5 +1314,5 @@
 
         // Starting at peak pixel, search leftwards for the column intercept.
-        psF32 leftIntercept = findValue(source, level, row, col, 0);
+        psF32 leftIntercept = findValue(source, level, col, row, 0);
         if (isnan(leftIntercept)) {
             psError(PS_ERR_UNKNOWN, true, "Could not find contour edge (NAN)");
@@ -1382,5 +1324,5 @@
 
         // Starting at peak pixel, search rightwards for the column intercept.
-        psF32 rightIntercept = findValue(source, level, row, col, 1);
+        psF32 rightIntercept = findValue(source, level, col, row, 1);
         if (isnan(rightIntercept)) {
             psError(PS_ERR_UNKNOWN, true, "Could not find contour edge (NAN)");
