IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 13, 2004, 1:34:58 PM (22 years ago)
Author:
desonia
Message:

added test for psImageRadialCut.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/image/tst_psImageExtraction.c

    r2087 r2093  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2004-10-13 22:04:29 $
     8*  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2004-10-13 23:34:58 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    10101010static int testImageCut(void)
    10111011{
    1012     // XXX - fill in
    10131012    int c = 300;
    10141013    int r = 200;
     
    11741173static int testImageRadialCut(void)
    11751174{
    1176     // XXX - fill in
     1175    int c = 300;
     1176    int r = 200;
     1177    int centerX = c/2;
     1178    int centerY = r/2;
     1179    psErr* err = NULL;
     1180
     1181    psImage* image = psImageAlloc(c,r,PS_TYPE_F32);
     1182    psImage* mask = psImageAlloc(c,r,PS_TYPE_MASK);
     1183    for (int row = 0; row < image->numRows; row++) {
     1184        for (int col = 0; col < image->numCols; col++) {
     1185            image->data.F32[row][col] = sqrtf((col-centerX)*(col-centerX)+(row-centerY)*(row-centerY));
     1186            if ((row & 0x0F) == 0) {
     1187                mask->data.PS_TYPE_MASK_DATA[row][col] = 1;
     1188            } else {
     1189                mask->data.PS_TYPE_MASK_DATA[row][col] = 0;
     1190            }
     1191        }
     1192    }
     1193
     1194    psStats* stat = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
     1195    psVector* radii = psVectorAlloc(10,PS_TYPE_F32);
     1196    for (int i=0; i < 10; i++) {
     1197        radii->data.F32[i] = 10+i*10;
     1198    }
     1199
     1200    psVector* result = NULL;
     1201
     1202    result = psImageRadialCut(result,image,mask,1,centerX,centerY,radii,stat);
     1203
     1204    if (result == NULL) {
     1205        psLogMsg(__func__,PS_LOG_ERROR,
     1206                 "Return value of NULL unexpected.");
     1207        return 1;
     1208    }
     1209
     1210    if (result->type.type != PS_TYPE_F64) {
     1211        psLogMsg(__func__,PS_LOG_ERROR,
     1212                 "Return type not psF64, as expected.");
     1213        return 2;
     1214    }
     1215
     1216    for (int i=0; i < 9; i++) {
     1217        if (fabs(result->data.F64[i] - (15.0+i*10)) > 1) {
     1218            psLogMsg(__func__,PS_LOG_ERROR,
     1219                     "Result was not as expected for radii #%d (%g, expected %d +/- 1)",
     1220                     result->data.F64[i], (15.0+i*10) );
     1221            return 3+i;
     1222        }
     1223    }
     1224
     1225    // again, but without mask
     1226    psVector* orig = result;
     1227    result = psImageRadialCut(result,image,NULL,1,centerX,centerY,radii,stat);
     1228
     1229    if (result == NULL) {
     1230        psLogMsg(__func__,PS_LOG_ERROR,
     1231                 "Return value of NULL unexpected.");
     1232        return 12;
     1233    }
     1234
     1235    if (result != orig) {
     1236        psLogMsg(__func__,PS_LOG_ERROR,
     1237                 "Return value of is not same as input parameter 'out'.");
     1238        return 13;
     1239    }
     1240
     1241    for (int i=0; i < 9; i++) {
     1242        if (fabs(result->data.F64[i] - (15.0+i*10)) > 1) {
     1243            psLogMsg(__func__,PS_LOG_ERROR,
     1244                     "Result was not as expected for radii #%d (%g, expected %d +/- 1)",
     1245                     result->data.F64[i], (15.0+i*10) );
     1246            return 14+i;
     1247        }
     1248    }
     1249
     1250    // NULL input image...
     1251    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1252    result = psImageRadialCut(result,NULL,NULL,1,centerX,centerY,radii,stat);
     1253
     1254    if (result != NULL) {
     1255        psLogMsg(__func__,PS_LOG_ERROR,
     1256                 "Return value not NULL as expected.");
     1257        return 23;
     1258    }
     1259
     1260    err = psErrorLast();
     1261    if (err->code != PS_ERR_BAD_PARAMETER_NULL) {
     1262        psLogMsg(__func__,PS_LOG_ERROR,
     1263                 "psImageRadialCut did not generate proper error message.");
     1264        return 24;
     1265    }
     1266    psFree(err);
     1267
     1268    // NULL input radii...
     1269    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1270    result = psImageRadialCut(result,image,mask,1,centerX,centerY,NULL,stat);
     1271
     1272    if (result != NULL) {
     1273        psLogMsg(__func__,PS_LOG_ERROR,
     1274                 "Return value not NULL as expected.");
     1275        return 23;
     1276    }
     1277
     1278    err = psErrorLast();
     1279    if (err->code != PS_ERR_BAD_PARAMETER_NULL) {
     1280        psLogMsg(__func__,PS_LOG_ERROR,
     1281                 "psImageRadialCut did not generate proper error message.");
     1282        return 24;
     1283    }
     1284    psFree(err);
     1285
     1286    // NULL input stat...
     1287    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1288    result = psImageRadialCut(result,image,mask,1,centerX,centerY,radii,NULL);
     1289
     1290    if (result != NULL) {
     1291        psLogMsg(__func__,PS_LOG_ERROR,
     1292                 "Return value not NULL as expected.");
     1293        return 23;
     1294    }
     1295
     1296    err = psErrorLast();
     1297    if (err->code != PS_ERR_BAD_PARAMETER_NULL) {
     1298        psLogMsg(__func__,PS_LOG_ERROR,
     1299                 "psImageRadialCut did not generate proper error message.");
     1300        return 24;
     1301    }
     1302    psFree(err);
     1303
     1304    // Bad center X
     1305    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1306    result = psImageRadialCut(result,image,mask,1,
     1307                              c+1,centerY,radii,stat);
     1308
     1309    if (result != NULL) {
     1310        psLogMsg(__func__,PS_LOG_ERROR,
     1311                 "Return value not NULL as expected.");
     1312        return 25;
     1313    }
     1314
     1315    err = psErrorLast();
     1316    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     1317        psLogMsg(__func__,PS_LOG_ERROR,
     1318                 "psImageRadialCut did not generate proper error message.");
     1319        return 26;
     1320    }
     1321    psFree(err);
     1322
     1323    // Bad center Y
     1324    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1325    result = psImageRadialCut(result,image,mask,1,
     1326                              centerX,r+1,radii,stat);
     1327
     1328    if (result != NULL) {
     1329        psLogMsg(__func__,PS_LOG_ERROR,
     1330                 "Return value not NULL as expected.");
     1331        return 27;
     1332    }
     1333
     1334    err = psErrorLast();
     1335    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     1336        psLogMsg(__func__,PS_LOG_ERROR,
     1337                 "psImageRadialCut did not generate proper error message.");
     1338        return 28;
     1339    }
     1340    psFree(err);
     1341
     1342    // Bad mask type (N.B., swapped image/mask to do this)
     1343    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1344    result = psImageRadialCut(result,mask,image,1,
     1345                              centerX,r+1,radii,stat);
     1346
     1347    if (result != NULL) {
     1348        psLogMsg(__func__,PS_LOG_ERROR,
     1349                 "Return value not NULL as expected.");
     1350        return 29;
     1351    }
     1352
     1353    err = psErrorLast();
     1354    if (err->code != PS_ERR_BAD_PARAMETER_TYPE) {
     1355        psLogMsg(__func__,PS_LOG_ERROR,
     1356                 "psImageRadialCut did not generate proper error message.");
     1357        return 30;
     1358    }
     1359    psFree(err);
     1360
     1361    // Bad mask size
     1362    psImage* mask2 = psImageAlloc(c/2,r/2,PS_TYPE_MASK);
     1363    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1364    result = psImageRadialCut(result,image, mask2, 1,
     1365                              centerX,centerY,radii,stat);
     1366    psFree(mask2);
     1367    if (result != NULL) {
     1368        psLogMsg(__func__,PS_LOG_ERROR,
     1369                 "Return value not NULL as expected.");
     1370        return 31;
     1371    }
     1372
     1373    err = psErrorLast();
     1374    if (err->code != PS_ERR_BAD_PARAMETER_SIZE) {
     1375        psLogMsg(__func__,PS_LOG_ERROR,
     1376                 "psImageRadialCut did not generate proper error message.");
     1377        return 32;
     1378    }
     1379    psFree(err);
     1380
     1381    // Bad radii size
     1382    psVector* radii2 = psVectorAlloc(1,PS_TYPE_MASK);
     1383    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1384    result = psImageRadialCut(result,image, mask, 1,
     1385                              centerX,centerY,radii2,stat);
     1386    psFree(radii2);
     1387    if (result != NULL) {
     1388        psLogMsg(__func__,PS_LOG_ERROR,
     1389                 "Return value not NULL as expected.");
     1390        return 33;
     1391    }
     1392
     1393    err = psErrorLast();
     1394    if (err->code != PS_ERR_BAD_PARAMETER_SIZE) {
     1395        psLogMsg(__func__,PS_LOG_ERROR,
     1396                 "psImageRadialCut did not generate proper error message.");
     1397        return 34;
     1398    }
     1399    psFree(err);
     1400
     1401    // bad input stat option...
     1402    stat->options = 0;
     1403    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1404    result = psImageRadialCut(result,image,mask,1,centerX,centerY,radii,stat);
     1405    stat->options = PS_STAT_SAMPLE_MEAN;
     1406
     1407    if (result != NULL) {
     1408        psLogMsg(__func__,PS_LOG_ERROR,
     1409                 "Return value not NULL as expected.");
     1410        return 35;
     1411    }
     1412
     1413    err = psErrorLast();
     1414    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     1415        psLogMsg(__func__,PS_LOG_ERROR,
     1416                 "psImageRadialCut did not generate proper error message.");
     1417        return 36;
     1418    }
     1419    psFree(err);
     1420
     1421    psFree(image);
     1422    psFree(mask);
     1423    psFree(radii);
     1424    psFree(stat);
     1425    psFree(result);
    11771426
    11781427    return 0;
Note: See TracChangeset for help on using the changeset viewer.