- Timestamp:
- Nov 19, 2009, 11:32:06 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091113/psModules/src/astrom/pmAstrometryObjects.c
r26164 r26197 973 973 */ 974 974 975 /*****************************************************************************/ 976 static void pmAstromMatchInfoFree (pmAstromMatchInfo *info) 977 { 978 if (info == NULL) return; 979 return; 980 } 981 982 983 /*****************************************************************************/ 984 pmAstromMatchInfo *pmAstromMatchInfoAlloc() 985 { 986 pmAstromMatchInfo *info = psAlloc (sizeof(pmAstromMatchInfo)); 987 psMemSetDeallocator(info, (psFreeFunc) pmAstromMatchInfoFree); 988 989 info->match = NULL; 990 info->radius = NAN; 991 992 return (info); 993 } 994 995 // generate a unique set of matches (choose closest match) 996 psArray *pmAstromRadiusMatchUniq (psArray *rawstars, psArray *refstars, psArray *matches) { 997 998 // I have the matches between the refstars and the rawstars. 999 // For each refstar, find the single match which has the smallest radius and reject 1000 // all others. 1001 1002 // create an array of refstars->n arrays, each containing all of the matches for the 1003 // given refstar. 1004 1005 psArray *refstarMatches = psArrayAlloc (refstars->n); 1006 1007 for (int i = 0; i < matches->n; i++) { 1008 1009 pmAstromMatch *match = matches->data[i]; 1010 1011 // accumulate this refstar match on the array for this refstar (create if needed) 1012 psArray *refSet = refstarMatches->data[match->ref]; 1013 if (!refSet) { 1014 refstarMatches->data[match->ref] = psArrayAllocEmpty (8); 1015 refSet = refstarMatches->data[match->ref]; 1016 } 1017 1018 pmAstromMatchInfo *matchInfo = pmAstromMatchInfoAlloc(); 1019 1020 pmAstromObj *refStar = refstars->data[match->ref]; 1021 pmAstromObj *rawStar = rawstars->data[match->raw]; 1022 1023 matchInfo->match = match; // reference to the match of interest 1024 matchInfo->radius = hypot (refStar->FP->x - rawStar->FP->x, refStar->FP->y - rawStar->FP->y); 1025 1026 psArrayAdd (refSet, 8, matchInfo); // matchInfo->match is just a reference 1027 psFree (matchInfo); 1028 } 1029 1030 // we now have a set of matches for each refstar and their distances; create a new set 1031 // keeping only the closest entry for each match 1032 1033 psArray *unique = psArrayAllocEmpty (PS_MAX(16, matches->n / 2)); 1034 for (int i = 0; i < refstars->n; i++) { 1035 1036 psArray *refSet = refstarMatches->data[i]; 1037 if (!refSet) continue; 1038 if (refSet->n == 0) continue; // not certain how this can happen... 1039 1040 if (refSet->n == 1) { 1041 pmAstromMatchInfo *matchInfo = refSet->data[0]; 1042 psArrayAdd (unique, 32, matchInfo->match); 1043 continue; 1044 } 1045 1046 pmAstromMatchInfo *matchInfo = refSet->data[0]; 1047 float minRadius = matchInfo->radius; 1048 pmAstromMatch *minMatch = matchInfo->match; 1049 for (int j = 1; j < refSet->n; j++) { 1050 pmAstromMatchInfo *matchInfo = refSet->data[j]; 1051 if (minRadius < matchInfo->radius) continue; 1052 minMatch = matchInfo->match; 1053 minRadius = matchInfo->radius; 1054 } 1055 1056 psArrayAdd (unique, 32, minMatch); // minMatch is just a reference to a match on matches, 1057 } 1058 1059 psLogMsg ("psastro", 3, "generate unique matches to reference stars: %ld matches -> %ld matches\n", matches->n, unique->n); 1060 psFree (refstarMatches); 1061 1062 return unique; 1063 }
Note:
See TracChangeset
for help on using the changeset viewer.
