Changeset 4770 for trunk/psModules/src/pmObjects.c
- Timestamp:
- Aug 15, 2005, 3:10:36 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/pmObjects.c (modified) (49 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/pmObjects.c
r4579 r4770 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1.3 0$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-0 7-19 01:44:48$8 * @version $Revision: 1.31 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-08-16 01:10:34 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 20 20 21 21 /****************************************************************************** 22 pmPeakAlloc(): Allocate the p sPeak data structure and set appropriate members.23 *****************************************************************************/ 24 p sPeak *pmPeakAlloc(psS32 x,22 pmPeakAlloc(): Allocate the pmPeak data structure and set appropriate members. 23 *****************************************************************************/ 24 pmPeak *pmPeakAlloc(psS32 x, 25 25 psS32 y, 26 26 psF32 counts, 27 p sPeakType class)28 { 29 p sPeak *tmp = (psPeak *) psAlloc(sizeof(psPeak));27 pmPeakType class) 28 { 29 pmPeak *tmp = (pmPeak *) psAlloc(sizeof(pmPeak)); 30 30 tmp->x = x; 31 31 tmp->y = y; … … 37 37 38 38 /****************************************************************************** 39 pmMomentsAlloc(): Allocate the p sMoments structure and initialize the members39 pmMomentsAlloc(): Allocate the pmMoments structure and initialize the members 40 40 to zero. 41 41 *****************************************************************************/ 42 p sMoments *pmMomentsAlloc()43 { 44 p sMoments *tmp = (psMoments *) psAlloc(sizeof(psMoments));42 pmMoments *pmMomentsAlloc() 43 { 44 pmMoments *tmp = (pmMoments *) psAlloc(sizeof(pmMoments)); 45 45 tmp->x = 0.0; 46 46 tmp->y = 0.0; … … 56 56 } 57 57 58 static void modelFree(p sModel *tmp)58 static void modelFree(pmModel *tmp) 59 59 { 60 60 psFree(tmp->params); … … 63 63 64 64 /****************************************************************************** 65 pmModelAlloc(): Allocate the p sModel structure, along with its parameters,65 pmModelAlloc(): Allocate the pmModel structure, along with its parameters, 66 66 and initialize the type member. Initialize the params to 0.0. 67 67 XXX EAM: changing params and dparams to psVector 68 68 *****************************************************************************/ 69 p sModel *pmModelAlloc(psModelType type)70 { 71 p sModel *tmp = (psModel *) psAlloc(sizeof(psModel));69 pmModel *pmModelAlloc(pmModelType type) 70 { 71 pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel)); 72 72 73 73 tmp->type = type; … … 99 99 break; 100 100 default: 101 psError(PS_ERR_UNKNOWN, true, "Undefined p sModelType");101 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 102 102 return(NULL); 103 103 } … … 116 116 We might need to increase the reference counter and decrease it here. 117 117 *****************************************************************************/ 118 static void sourceFree(p sSource *tmp)118 static void sourceFree(pmSource *tmp) 119 119 { 120 120 psFree(tmp->peak); … … 122 122 // psFree(tmp->mask); 123 123 psFree(tmp->moments); 124 psFree(tmp->models); 125 } 126 127 /****************************************************************************** 128 pmSourceAlloc(): Allocate the psSource structure and initialize its members 124 psFree(tmp->modelPSF); 125 psFree(tmp->modelFLT); 126 } 127 128 /****************************************************************************** 129 pmSourceAlloc(): Allocate the pmSource structure and initialize its members 129 130 to NULL. 130 131 *****************************************************************************/ 131 p sSource *pmSourceAlloc()132 { 133 p sSource *tmp = (psSource *) psAlloc(sizeof(psSource));132 pmSource *pmSourceAlloc() 133 { 134 pmSource *tmp = (pmSource *) psAlloc(sizeof(pmSource)); 134 135 tmp->peak = NULL; 135 136 tmp->pixels = NULL; 136 137 tmp->mask = NULL; 137 138 tmp->moments = NULL; 138 tmp->models = NULL; 139 tmp->modelPSF = NULL; 140 tmp->modelFLT = NULL; 139 141 tmp->type = 0; 140 142 psMemSetDeallocator(tmp, (psFreeFunc) sourceFree); … … 272 274 psS32 col, 273 275 psF32 counts, 274 p sPeakType type)275 { 276 p sPeak *tmpPeak = pmPeakAlloc(col, row, counts, type);276 pmPeakType type) 277 { 278 pmPeak *tmpPeak = pmPeakAlloc(col, row, counts, type); 277 279 278 280 if (list == NULL) { … … 379 381 // Step through all local peaks in this row. 380 382 for (psU32 i = 0 ; i < row1->n ; i++ ) { 381 p sPeakType myType = PM_PEAK_UNDEF;383 pmPeakType myType = PM_PEAK_UNDEF; 382 384 col = row1->data.U32[i]; 383 385 … … 527 529 // printf("pmCullPeaks(): list size is %d\n", peaks->size); 528 530 while (tmpListElem != NULL) { 529 p sPeak *tmpPeak = (psPeak *) tmpListElem->data;531 pmPeak *tmpPeak = (pmPeak *) tmpListElem->data; 530 532 if ((tmpPeak->counts > maxValue) || 531 533 ((valid != NULL) && … … 553 555 554 556 for (int i = 0; i < peaks->n; i++) { 555 p sPeak *tmpPeak = (psPeak *) peaks->data[i];557 pmPeak *tmpPeak = (pmPeak *) peaks->data[i]; 556 558 if (tmpPeak->counts > maxValue) 557 559 continue; … … 566 568 567 569 /****************************************************************************** 568 p sSource *pmSourceLocalSky(image, peak, innerRadius, outerRadius): this569 routine creates a new p sSource data structure and sets the following members:570 ->p sPeak571 ->p sMoments->sky570 pmSource *pmSourceLocalSky(image, peak, innerRadius, outerRadius): this 571 routine creates a new pmSource data structure and sets the following members: 572 ->pmPeak 573 ->pmMoments->sky 572 574 573 575 The sky value is set from the pixels in the square annulus surrounding the … … 590 592 or they use the image row/column offsets. 591 593 592 XXX: Should we simply set p sSource->peak = peak? If so, should we increase594 XXX: Should we simply set pmSource->peak = peak? If so, should we increase 593 595 the reference counter? Or, should we copy the data structure? 594 596 … … 602 604 members. 603 605 *****************************************************************************/ 604 p sSource *pmSourceLocalSky(const psImage *image,605 const p sPeak *peak,606 pmSource *pmSourceLocalSky(const psImage *image, 607 const pmPeak *peak, 606 608 psStatsOptions statsOptions, 607 609 psF32 innerRadius, … … 723 725 // Create the output mySource, and set appropriate members. 724 726 // 725 p sSource *mySource = pmSourceAlloc();726 mySource->peak = (p sPeak *) peak;727 pmSource *mySource = pmSourceAlloc(); 728 mySource->peak = (pmPeak *) peak; 727 729 mySource->moments = pmMomentsAlloc(); 728 730 psF64 tmpF64; … … 746 748 XXX: macro this for performance. 747 749 *****************************************************************************/ 748 static bool checkRadius(p sPeak *peak,750 static bool checkRadius(pmPeak *peak, 749 751 psF32 radius, 750 752 psS32 x, … … 781 783 /****************************************************************************** 782 784 pmSourceMoments(source, radius): this function takes a subImage defined in the 783 p sSource data structure, along with the peak location, and determines the785 pmSource data structure, along with the peak location, and determines the 784 786 various moments associated with that peak. 785 787 786 788 Requires the following to have been created: 787 p sSource788 p sSource->peak789 p sSource->pixels789 pmSource 790 pmSource->peak 791 pmSource->pixels 790 792 791 793 XXX: The peak calculations are done in image coords, not subImage coords. … … 793 795 XXX: mask values? 794 796 *****************************************************************************/ 795 p sSource *pmSourceMoments(psSource *source,797 pmSource *pmSourceMoments(pmSource *source, 796 798 psF32 radius) 797 799 { … … 925 927 int pmComparePeakAscend (const void **a, const void **b) 926 928 { 927 p sPeak *A = *(psPeak **)a;928 p sPeak *B = *(psPeak **)b;929 pmPeak *A = *(pmPeak **)a; 930 pmPeak *B = *(pmPeak **)b; 929 931 930 932 psF32 diff; … … 940 942 int pmComparePeakDescend (const void **a, const void **b) 941 943 { 942 p sPeak *A = *(psPeak **)a;943 p sPeak *B = *(psPeak **)b;944 pmPeak *A = *(pmPeak **)a; 945 pmPeak *B = *(pmPeak **)b; 944 946 945 947 psF32 diff; … … 992 994 for (psS32 i = 0 ; i < sources->n ; i++) 993 995 { 994 p sSource *tmpSrc = (psSource *) sources->data[i];996 pmSource *tmpSrc = (pmSource *) sources->data[i]; 995 997 PS_ASSERT_PTR_NON_NULL(tmpSrc, false); // just skip this one? 996 998 PS_ASSERT_PTR_NON_NULL(tmpSrc->moments, false); // just skip this one? … … 1027 1029 // measure statistics on Sx, Sy if Sx, Sy within range of clump 1028 1030 { 1029 p sPeak *clump;1031 pmPeak *clump; 1030 1032 psF32 minSx, maxSx; 1031 1033 psF32 minSy, maxSy; … … 1054 1056 for (psS32 i = 0 ; i < sources->n ; i++) 1055 1057 { 1056 p sSource *tmpSrc = (psSource *) sources->data[i];1058 pmSource *tmpSrc = (pmSource *) sources->data[i]; 1057 1059 1058 1060 if (tmpSrc->moments->Sx < minSx) … … 1103 1105 for (psS32 i = 0 ; i < sources->n ; i++) { 1104 1106 1105 p sSource *tmpSrc = (psSource *) sources->data[i];1107 pmSource *tmpSrc = (pmSource *) sources->data[i]; 1106 1108 1107 1109 tmpSrc->peak->class = 0; … … 1197 1199 the pmSourceSetLocal() function. 1198 1200 *****************************************************************************/ 1199 bool pmSourceSetPixelsCircle(p sSource *source,1201 bool pmSourceSetPixelsCircle(pmSource *source, 1200 1202 const psImage *image, 1201 1203 psF32 radius) … … 1293 1295 /****************************************************************************** 1294 1296 pmSourceModelGuess(source, image, model): This function allocates a new 1295 p sModel structure and stores it in the psSource data structure specified in1297 pmModel structure and stores it in the pmSource data structure specified in 1296 1298 the argument list. The model type is specified in the argument list. The 1297 params array in that p sModel structure are allocated, and then set to the1299 params array in that pmModel structure are allocated, and then set to the 1298 1300 appropriate values. This function returns true if everything was successful. 1299 1301 … … 1306 1308 image, not subImage coords. Therefore, the calls to the model evaluation 1307 1309 functions will be in image, not subImage coords. Remember this. 1308 *****************************************************************************/ 1309 bool pmSourceModelGuess(psSource *source, 1310 1311 XXX: The source->models member used to be allocated here. Now I assume 1312 ->modelPSF should be allocated 1313 *****************************************************************************/ 1314 bool pmSourceModelGuess(pmSource *source, 1310 1315 const psImage *image, 1311 p sModelType model)1316 pmModelType model) 1312 1317 { 1313 1318 PS_ASSERT_PTR_NON_NULL(source, false); … … 1316 1321 PS_ASSERT_IMAGE_NON_NULL(image, false); 1317 1322 PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, false); 1318 if (source->model s!= NULL) {1319 psLogMsg(__func__, PS_LOG_WARN, "WARNING: source->model s was non-NULL; calling psFree(source->models).\n");1320 psFree(source->model s);1323 if (source->modelPSF != NULL) { 1324 psLogMsg(__func__, PS_LOG_WARN, "WARNING: source->modelPSF was non-NULL; calling psFree(source->modelPSF).\n"); 1325 psFree(source->modelPSF); 1321 1326 } 1322 1327 if (!((model == PS_MODEL_GAUSS) || … … 1330 1335 } 1331 1336 1332 source->model s= pmModelAlloc(model);1333 1334 psVector *params = source->model s->params;1337 source->modelPSF = pmModelAlloc(model); 1338 1339 psVector *params = source->modelPSF->params; 1335 1340 1336 1341 switch (model) { … … 1364 1369 params->data.F32[6] = source->moments->Sxy; 1365 1370 // XXX: What are these? 1366 // source->model s->params[7] = B2;1367 // source->model s->params[8] = B3;1371 // source->modelPSF->params[7] = B2; 1372 // source->modelPSF->params[8] = B3; 1368 1373 return(true); 1369 1374 … … 1420 1425 /****************************************************************************** 1421 1426 evalModel(source, level, row): a private function which evaluates the 1422 source->model function at the specified coords. The coords are subImage, not1427 source->modelPSF function at the specified coords. The coords are subImage, not 1423 1428 image coords. 1424 1429 … … 1430 1435 the coords is in subImage or image space. 1431 1436 1432 XXX: This should probably be a public p sModules function.1437 XXX: This should probably be a public pmModules function. 1433 1438 1434 1439 XXX: Use static vectors for x. … … 1439 1444 testing. Try to reproduce that and debug. 1440 1445 *****************************************************************************/ 1441 static psF32 evalModel(p sSource *src,1446 static psF32 evalModel(pmSource *src, 1442 1447 psU32 row, 1443 1448 psU32 col) 1444 1449 { 1445 1450 PS_ASSERT_PTR_NON_NULL(src, false); 1446 PS_ASSERT_PTR_NON_NULL(src->model s, false);1447 PS_ASSERT_PTR_NON_NULL(src->model s->params, false);1448 1449 // XXX: The following step will not be necessary if the model s->params1451 PS_ASSERT_PTR_NON_NULL(src->modelPSF, false); 1452 PS_ASSERT_PTR_NON_NULL(src->modelPSF->params, false); 1453 1454 // XXX: The following step will not be necessary if the modelPSF->params 1450 1455 // member is a psVector. Suggest to IfA. 1451 1456 1452 // XXX EAM: done: model s->params is now a vector1453 psVector *params = src->model s->params;1457 // XXX EAM: done: modelPSF->params is now a vector 1458 psVector *params = src->modelPSF->params; 1454 1459 1455 1460 // … … 1461 1466 psF32 tmpF; 1462 1467 1463 switch (src->model s->type) {1468 switch (src->modelPSF->type) { 1464 1469 case PS_MODEL_GAUSS: 1465 1470 tmpF = pmMinLM_Gauss2D(NULL, params, x); … … 1481 1486 break; 1482 1487 default: 1483 psError(PS_ERR_UNKNOWN, true, "Undefined p sModelType");1488 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 1484 1489 return(NAN); 1485 1490 } … … 1500 1505 XXX: The result is returned in image coords. 1501 1506 *****************************************************************************/ 1502 static psF32 findValue(p sSource *source,1507 static psF32 findValue(pmSource *source, 1503 1508 psF32 level, 1504 1509 psU32 row, … … 1575 1580 XXX: The top, bottom of the contour is not correctly determined. 1576 1581 *****************************************************************************/ 1577 psArray *pmSourceContour(p sSource *source,1582 psArray *pmSourceContour(pmSource *source, 1578 1583 const psImage *image, 1579 1584 psF32 level, … … 1585 1590 PS_ASSERT_PTR_NON_NULL(source->peak, false); 1586 1591 PS_ASSERT_PTR_NON_NULL(source->pixels, false); 1587 PS_ASSERT_PTR_NON_NULL(source->model s, false);1592 PS_ASSERT_PTR_NON_NULL(source->modelPSF, false); 1588 1593 1589 1594 // … … 1692 1697 XXX: Probably should remove the "image" argument. 1693 1698 *****************************************************************************/ 1694 bool pmSourceFitModel(p sSource *source,1699 bool pmSourceFitModel(pmSource *source, 1695 1700 const psImage *image) 1696 1701 { … … 1699 1704 PS_ASSERT_PTR_NON_NULL(source->peak, false); 1700 1705 PS_ASSERT_PTR_NON_NULL(source->pixels, false); 1701 PS_ASSERT_PTR_NON_NULL(source->model s, false);1706 PS_ASSERT_PTR_NON_NULL(source->modelPSF, false); 1702 1707 PS_ASSERT_IMAGE_NON_NULL(image, false); 1703 1708 PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, false); … … 1742 1747 PM_SOURCE_FIT_MODEL_TOLERANCE); 1743 1748 1744 psVector *params = source->model s->params;1745 1746 switch (source->model s->type) {1749 psVector *params = source->modelPSF->params; 1750 1751 switch (source->modelPSF->type) { 1747 1752 case PS_MODEL_GAUSS: 1748 1753 rc = psMinimizeLMChi2(myMin, NULL, params, NULL, x, y, yErr, pmMinLM_Gauss2D); … … 1764 1769 break; 1765 1770 default: 1766 psError(PS_ERR_UNKNOWN, true, "Undefined p sModelType");1771 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 1767 1772 rc = false; 1768 1773 } 1769 1774 // XXX EAM: we need to do something (give an error?) if rc is false 1770 1775 // XXX EAM: save the resulting chisq, nDOF, nIter 1771 source->model s->chisq = myMin->value;1772 source->model s->nDOF = y->n - params->n;1773 source->model s->nIter = myMin->iter;1776 source->modelPSF->chisq = myMin->value; 1777 source->modelPSF->nDOF = y->n - params->n; 1778 source->modelPSF->nIter = myMin->iter; 1774 1779 1775 1780 psFree(x); … … 1780 1785 1781 1786 static bool sourceAddOrSubModel(psImage *image, 1782 p sSource *src,1787 pmSource *src, 1783 1788 bool center, 1784 1789 psS32 flag) … … 1788 1793 PS_ASSERT_PTR_NON_NULL(src->peak, false); 1789 1794 PS_ASSERT_PTR_NON_NULL(src->pixels, false); 1790 PS_ASSERT_PTR_NON_NULL(src->model s, false);1795 PS_ASSERT_PTR_NON_NULL(src->modelPSF, false); 1791 1796 PS_ASSERT_IMAGE_NON_NULL(image, false); 1792 1797 PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, false); 1793 1798 1794 1799 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 1795 psVector *params = src->model s->params;1800 psVector *params = src->modelPSF->params; 1796 1801 1797 1802 for (psS32 i = 0; i < src->pixels->numRows; i++) { … … 1808 1813 x->data.F32[0] = (float) imageCol; 1809 1814 x->data.F32[1] = (float) imageRow; 1810 switch (src->model s->type) {1815 switch (src->modelPSF->type) { 1811 1816 case PS_MODEL_GAUSS: 1812 1817 pixelValue = pmMinLM_Gauss2D(NULL, params, x); … … 1828 1833 break; 1829 1834 default: 1830 psError(PS_ERR_UNKNOWN, true, "Undefined p sModelType");1835 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 1831 1836 psFree(x); 1832 1837 return(false); … … 1851 1856 *****************************************************************************/ 1852 1857 bool pmSourceAddModel(psImage *image, 1853 p sSource *src,1858 pmSource *src, 1854 1859 bool center) 1855 1860 { … … 1860 1865 *****************************************************************************/ 1861 1866 bool pmSourceSubModel(psImage *image, 1862 p sSource *src,1867 pmSource *src, 1863 1868 bool center) 1864 1869 {
Note:
See TracChangeset
for help on using the changeset viewer.
