Changeset 4770 for trunk/psModules/src/pmAstrometry.c
- Timestamp:
- Aug 15, 2005, 3:10:36 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/pmAstrometry.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/pmAstrometry.c
r4754 r4770 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-08-1 1 00:03:51$10 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-08-16 01:10:34 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 23 23 #include "pmAstrometry.h" 24 24 25 psDB wow;26 27 25 /***************************************************************************** 28 checkValidImageCoords(): this is a private function which simply 29 determines if the supplied x,y coordinates are in the range for the supplied 30 psImage. 26 checkValidImageCoords(): this is a private function which simply determines if 27 the supplied x,y coordinates are in the range for the supplied psImage. 28 29 XXX: What about col0 and row0 30 XXX: This should return a psBool. 31 31 *****************************************************************************/ 32 /*33 32 static psS32 checkValidImageCoords(double x, 34 33 double y, … … 36 35 { 37 36 PS_ASSERT_IMAGE_NON_NULL(tmpImage, 0); 38 37 39 38 if ((x < 0.0) || (x > (double)tmpImage->numCols) || 40 39 (y < 0.0) || (y > (double)tmpImage->numRows)) { 41 40 return (0); 42 41 } 43 42 44 43 return (1); 45 44 } 46 */ 47 /* 48 static void FPAFree(psFPA* fpa) 45 46 /****************************************************************************** 47 XXX: Is this the correct way to free metadata? 48 XXX: Is this the correct way to free database structs? 49 *****************************************************************************/ 50 51 static void FPAFree(pmFPA *fpa) 49 52 { 50 53 if (fpa != NULL) { 51 psFree(fpa->chips);52 psFree(fpa->grommit);53 psFree(fpa->exposure);54 psFree(fpa->metadata);55 54 psFree(fpa->fromTangentPlane); 56 55 psFree(fpa->toTangentPlane); 57 psFree(fpa->pattern);58 psFree(fpa->colorPlus);59 psFree(fpa->colorMinus);60 56 psFree(fpa->projection); 61 } 62 } 63 */ 64 65 /* 66 static void chipFree(psChip* chip) 57 psFree(fpa->concepts); 58 psFree(fpa->analysis); 59 psFree(fpa->camera); 60 psFree(fpa->chips); 61 psFree(fpa->header); 62 psFree(fpa->db); 63 } 64 } 65 66 static void chipFree(pmChip* chip) 67 67 { 68 68 if (chip != NULL) { 69 psFree(chip->cells);70 psFree(chip->metadata);71 69 psFree(chip->toFPA); 72 70 psFree(chip->fromFPA); 73 } 74 } 75 */ 76 77 /* 78 static void cellFree(psCell* cell) 71 psFree(chip->concepts); 72 psFree(chip->analysis); 73 psFree(chip->cells); 74 psFree(chip->parent); 75 psFree(chip->extname); 76 psFree(chip->pixels); 77 psFree(chip->header); 78 } 79 } 80 81 static void cellFree(pmCell *cell) 79 82 { 80 83 if (cell != NULL) { 84 psFree(cell->toChip); 85 psFree(cell->toFPA); 86 psFree(cell->toSky); 87 psFree(cell->concepts); 88 psFree(cell->analysis); 81 89 psFree(cell->readouts); 82 psFree(cell->metadata); 83 psFree(cell->toChip); 84 psFree(cell->fromChip); 85 psFree(cell->toFPA); 86 psFree(cell->toTP); 87 psFree(cell->toSky); 88 } 89 } 90 */ 91 92 static void readoutFree(psReadout* readout) 90 psFree(cell->parent); 91 psFree(cell->extname); 92 psFree(cell->pixels); 93 psFree(cell->header); 94 } 95 } 96 97 static void readoutFree(pmReadout *readout) 93 98 { 94 99 if (readout != NULL) { 95 100 psFree(readout->image); 96 101 psFree(readout->mask); 97 psFree(readout->objects); 98 psFree(readout->metadata); 99 } 100 } 101 102 /* 103 static void observatoryFree(psObservatory* obs) 104 { 105 if (obs != NULL) { 106 psFree(obs->name); 107 } 108 } 109 */ 110 /* 111 static void exposureFree(psExposure* exp) 112 { 113 if (exp != NULL) { 114 psFree(exp->time); 115 psFree(exp->observatory); 116 psFree(exp->cameraName); 117 psFree(exp->telescopeName); 118 } 119 } 120 */ 121 /* 122 static void fixedPatternFree(psFixedPattern* fp) 123 { 124 if (fp != NULL) { 125 for (psS32 i = 0; i < fp->p_ps_xRows; i++) { 126 psFree(fp->x[i]); 127 } 128 129 for (psS32 j = 0; j < fp->p_ps_yRows; j++) { 130 psFree(fp->y[j]); 131 } 132 133 psFree(fp->x); 134 psFree(fp->y); 135 } 136 } 137 */ 102 psFree(readout->analysis); 103 psFree(readout->concepts); 104 psFree(readout->parent); 105 } 106 } 107 108 109 pmReadout *pmReadoutAlloc(pmCell *cell) 110 { 111 pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout)); 112 113 tmpReadout->col0 = -1; 114 tmpReadout->row0 = -1; 115 tmpReadout->colBins = -1; 116 tmpReadout->rowBins = -1; 117 tmpReadout->image = NULL; 118 tmpReadout->mask = NULL; 119 tmpReadout->analysis = psMetadataAlloc(); 120 tmpReadout->concepts = psMetadataAlloc(); 121 tmpReadout->parent = cell; 122 123 if (cell != NULL) { 124 cell->readouts = psArrayAdd(cell->readouts, 1, (psPtr) tmpReadout); 125 } 126 psMemSetDeallocator(tmpReadout, (psFreeFunc) readoutFree); 127 return(tmpReadout); 128 } 129 130 pmCell *pmCellAlloc(pmChip *chip) 131 { 132 pmCell *tmpCell = (pmCell *) psAlloc(sizeof(pmCell)); 133 134 tmpCell->col0 = -1; 135 tmpCell->row0 = -1; 136 tmpCell->toChip = NULL; 137 tmpCell->toFPA = NULL; 138 tmpCell->toSky = NULL; 139 tmpCell->analysis = psMetadataAlloc(); 140 tmpCell->concepts = psMetadataAlloc(); 141 tmpCell->readouts = psArrayAlloc(0); 142 tmpCell->parent = chip; 143 if (chip != NULL) { 144 chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell); 145 } 146 tmpCell->valid = false; 147 tmpCell->extname = NULL; 148 tmpCell->pixels = NULL; 149 tmpCell->header = NULL; 150 151 psMemSetDeallocator(tmpCell, (psFreeFunc) cellFree); 152 return(tmpCell); 153 } 154 155 pmChip *pmChipAlloc(pmFPA *fpa) 156 { 157 pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip)); 158 159 tmpChip->col0 = -1; 160 tmpChip->row0 = -1; 161 tmpChip->toFPA = NULL; 162 tmpChip->fromFPA = NULL; 163 tmpChip->concepts = psMetadataAlloc(); 164 tmpChip->analysis = psMetadataAlloc(); 165 tmpChip->cells = psArrayAlloc(0); 166 tmpChip->parent = fpa; 167 if (fpa != NULL) { 168 fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip); 169 } 170 tmpChip->valid = false; 171 tmpChip->extname = NULL; 172 tmpChip->pixels = NULL; 173 tmpChip->header = NULL; 174 175 psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree); 176 return(tmpChip); 177 } 178 179 pmFPA *pmFPAAlloc( 180 const psMetadata *camera, 181 psDB *db) 182 { 183 pmFPA *tmpFPA = (pmFPA *) psAlloc(sizeof(pmFPA)); 184 185 tmpFPA->fromTangentPlane = NULL; 186 tmpFPA->toTangentPlane = NULL; 187 tmpFPA->projection = NULL; 188 tmpFPA->concepts = psMetadataAlloc(); 189 tmpFPA->analysis = psMetadataAlloc(); 190 tmpFPA->camera = camera; 191 tmpFPA->chips = psArrayAlloc(0); 192 tmpFPA->header = NULL; 193 tmpFPA->db = db; 194 195 psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree); 196 return(tmpFPA); 197 } 198 199 bool cellCheckParents(pmCell *cell) 200 { 201 if (cell == NULL) { 202 return(true); 203 } 204 psBool flag = true; 205 206 for (psS32 i = 0 ; i < cell->readouts->n ; i++) { 207 pmReadout *tmpReadout = (pmReadout *) cell->readouts->data[i]; 208 PS_ASSERT_PTR_NON_NULL(tmpReadout, false); 209 if (tmpReadout->parent != cell) { 210 tmpReadout->parent = cell; 211 flag = false; 212 } 213 } 214 return(flag); 215 } 216 217 bool chipCheckParents(pmChip *chip) 218 { 219 if (chip == NULL) { 220 return(true); 221 } 222 psBool flag = true; 223 224 for (psS32 i = 0 ; i < chip->cells->n ; i++) { 225 pmCell *tmpCell = (pmCell *) chip->cells->data[i]; 226 PS_ASSERT_PTR_NON_NULL(tmpCell, false); 227 if (tmpCell->parent != chip) { 228 tmpCell->parent = chip; 229 flag = false; 230 } 231 232 flag &= cellCheckParents(tmpCell); 233 } 234 return(flag); 235 } 236 237 bool pmFPACheckParents(pmFPA *fpa) 238 { 239 if (fpa == NULL) { 240 return(true); 241 } 242 psBool flag = true; 243 244 for (psS32 i = 0 ; i < fpa->chips->n ; i++) { 245 pmChip *tmpChip = (pmChip *) fpa->chips->data[i]; 246 PS_ASSERT_PTR_NON_NULL(tmpChip, false); 247 if (tmpChip->parent != fpa) { 248 tmpChip->parent = fpa; 249 flag = false; 250 } 251 252 flag &= chipCheckParents(tmpChip); 253 } 254 return(flag); 255 } 256 257 258 259 // HEY 138 260 /*****************************************************************************/ 139 261 /* FUNCTION IMPLEMENTATION - PUBLIC */ 140 262 /*****************************************************************************/ 141 263 142 /* 143 * XXX: Verify that you interpreted the SDR correctly. 144 * 145 * XXX: This assumes that x,y must be of type F64 146 */ 147 /* 148 psFixedPattern* psFixedPatternAlloc(double x0, 149 double y0, 150 double xScale, 151 double yScale, 152 const psImage *x, 153 const psImage *y) 154 { 155 psFixedPattern *tmp; 156 psS32 i; 157 psS32 j; 158 159 PS_ASSERT_IMAGE_NON_NULL(x, NULL); 160 PS_ASSERT_IMAGE_NON_NULL(y, NULL); 161 PS_ASSERT_IMAGE_TYPE(x, PS_TYPE_F64, NULL); 162 PS_ASSERT_IMAGE_TYPE(y, PS_TYPE_F64, NULL); 163 164 tmp = (psFixedPattern *) psAlloc(sizeof(psFixedPattern)); 165 // XXX: Is this correct? 166 tmp->nX = (x->numCols * x->numRows); 167 tmp->nY = (y->numCols * y->numRows); 168 tmp->x0 = x0; 169 tmp->y0 = y0; 170 tmp->xScale = xScale; 171 tmp->yScale = yScale; 172 tmp->p_ps_xRows = x->numRows; 173 tmp->p_ps_xCols = x->numCols; 174 tmp->p_ps_yRows = y->numRows; 175 tmp->p_ps_yCols = y->numCols; 176 tmp->x = (double **) psAlloc(x->numRows * sizeof(double *)); 177 for (i=0;i<x->numRows;i++) { 178 (tmp->x)[i] = (double *) psAlloc(x->numCols * sizeof(double)); 179 } 180 for (i=0;i<x->numRows;i++) { 181 for (j=0;j<x->numCols;j++) { 182 (tmp->x)[i][j] = x->data.F64[i][j]; 183 } 184 } 185 186 tmp->y = (double **) psAlloc(y->numRows * sizeof(double *)); 187 for (i=0;i<y->numRows;i++) { 188 (tmp->y)[i] = (double *) psAlloc(y->numCols * sizeof(double)); 189 } 190 for (i=0;i<y->numRows;i++) { 191 for (j=0;j<y->numCols;j++) { 192 (tmp->y)[i][j] = y->data.F64[i][j]; 193 } 194 } 195 196 psMemSetDeallocator(tmp,(psFreeFunc)fixedPatternFree); 197 198 return(tmp); 199 } 200 */ 201 /* 202 psExposure* psExposureAlloc(double ra, 203 double dec, 204 double hourAngle, 205 double zenithDistance, 206 double azimuth, 207 const psTime* time, 208 float rotAngle, 209 float temperature, 210 float pressure, 211 float humidity, 212 float exposureTime, 213 float wavelength, 214 const psObservatory* observatory) 215 { 216 PS_ASSERT_PTR_NON_NULL(observatory, NULL); 217 218 psExposure* exp = psAlloc(sizeof(psExposure)); 219 *(double *)&exp->ra = ra; 220 *(double *)&exp->dec = dec; 221 *(double *)&exp->hourAngle = hourAngle; 222 *(double *)&exp->zenithDistance = zenithDistance; 223 *(double *)&exp->azimuth = azimuth; 224 *(float *)&exp->rotAngle = rotAngle; 225 *(float *)&exp->temperature = temperature; 226 *(float *)&exp->pressure = pressure; 227 *(float *)&exp->humidity = humidity; 228 *(float *)&exp->exposureTime = exposureTime; 229 *(float *)&exp->wavelength = wavelength; 230 231 exp->time = psMemIncrRefCounter((psPtr)time); 232 exp->observatory = psMemIncrRefCounter((psPtr)observatory); 233 234 // XXX: how is this value derived? 235 *(double *)&exp->lst = psTimeToLMST((psTime*)time,observatory->longitude); 236 *(float *)&exp->positionAngle = 0.0f; // XXX: need input, see Bug #207 237 *(float *)&exp->parallacticAngle = 0.0f; // XXX: need input, see Bug #207 238 *(float *)&exp->airmass = 0.0f; // XXX: needs calculation! = slaAirmas(zenithDistance); 239 *(float *)&exp->parallacticFactor = 0.0f; 240 exp->cameraName = NULL; 241 exp->telescopeName = NULL; 242 243 psMemSetDeallocator(exp,(psFreeFunc)exposureFree); 244 245 return exp; 246 } 247 */ 248 /* 249 psObservatory* psObservatoryAlloc(const char* name, 250 double latitude, 251 double longitude, 252 double height, 253 double tlr) 254 { 255 psObservatory* obs = psAlloc(sizeof(psObservatory)); 256 257 if (name == NULL) { 258 obs->name = NULL; 259 } else { 260 obs->name = psAlloc(strlen(name)+1); 261 strcpy((char*)obs->name, name); 262 } 263 264 *(double *)&obs->latitude = latitude; 265 *(double *)&obs->longitude = longitude; 266 *(double *)&obs->height = height; 267 *(double *)&obs->tlr = tlr; 268 269 psMemSetDeallocator(obs,(psFreeFunc)observatoryFree); 270 271 return obs; 272 } 273 */ 274 /* 275 psFPA* psFPAAlloc(psS32 nChips, 276 const psExposure* exp) 277 { 278 PS_ASSERT_INT_NONNEGATIVE(nChips, NULL); 279 280 psFPA* newFPA = psAlloc(sizeof(psFPA)); 281 282 // create array of NULL chips of the size nChips 283 newFPA->chips = psArrayAlloc(nChips); 284 psPtr* chips = newFPA->chips->data; 285 for (psS32 i=0;i<nChips;i++) { 286 chips[i] = NULL; 287 } 288 newFPA->chips->n = 0; // per requirement 289 290 newFPA->metadata = NULL; 291 newFPA->fromTangentPlane = NULL; 292 newFPA->toTangentPlane = NULL; 293 newFPA->pattern = NULL; 294 295 if (exp != NULL) { 296 newFPA->exposure = psMemIncrRefCounter((psExposure*)exp); 297 newFPA->grommit = psGrommitAlloc(exp); 298 } else { 299 newFPA->exposure = NULL; 300 newFPA->grommit = NULL; 301 } 302 303 newFPA->colorPlus = NULL; 304 newFPA->colorMinus = NULL; 305 newFPA->projection = NULL; 306 307 newFPA->rmsX = 0.0f; 308 newFPA->rmsY = 0.0f; 309 newFPA->chi2 = 0.0f; 310 311 psMemSetDeallocator(newFPA,(psFreeFunc)FPAFree); 312 313 return newFPA; 314 } 315 */ 316 /* 317 * psChip constructor 318 */ 319 /* 320 psChip* psChipAlloc(psS32 nCells, 321 psFPA *parentFPA) 322 { 323 PS_ASSERT_INT_NONNEGATIVE(nCells, NULL); 324 325 psChip* chip = psAlloc(sizeof(psChip)); 326 327 // create array of NULL psCells 328 int n = (nCells > 0) ? nCells : 1; 329 chip->cells = psArrayAlloc(n); 330 psPtr* cells = chip->cells->data; 331 for (psS32 i=0;i<n;i++) { 332 cells[i] = NULL; 333 } 334 chip->cells->n = 0; // per requirement 335 336 *(int*)&chip->row0 = 0; 337 *(int*)&chip->col0 = 0; 338 339 chip->metadata = NULL; 340 341 chip->toFPA = NULL; 342 chip->fromFPA = NULL; 343 344 chip->parent = parentFPA; 345 346 psMemSetDeallocator(chip,(psFreeFunc)chipFree); 347 348 return chip; 349 350 } 351 */ 352 /* 353 * psCell constructor 354 */ 355 /* 356 psCell* psCellAlloc(psS32 nReadouts, 357 psChip* parentChip) 358 { 359 PS_ASSERT_INT_NONNEGATIVE(nReadouts, NULL); 360 361 psCell* cell = psAlloc(sizeof(psCell)); 362 363 // create array of NULL psReadouts 364 int n = (nReadouts > 0) ? nReadouts : 1; 365 cell->readouts = psArrayAlloc(n); 366 psPtr* readouts = cell->readouts->data; 367 for (psS32 i=0;i<n;i++) { 368 readouts[i] = NULL; 369 } 370 cell->readouts->n = 0; // per requirement 371 372 *(int*)&cell->row0 = 0; 373 *(int*)&cell->col0 = 0; 374 375 cell->metadata = NULL; 376 377 cell->toChip = NULL; 378 cell->fromChip = NULL; 379 cell->toFPA = NULL; 380 cell->toTP = NULL; 381 cell->toSky = NULL; 382 383 cell->parent = parentChip; 384 385 psMemSetDeallocator(cell,(psFreeFunc)cellFree); 386 387 return cell; 388 389 390 } 391 */ 392 393 psReadout *pmReadoutAlloc(pmCell *cell) 394 { 395 psReadout* readout = psAlloc(sizeof(psReadout)); 396 397 *(psU32*)&readout->colBins = 1; 398 *(psU32*)&readout->rowBins = 1; 399 *(psU32*)&readout->rowParity = 0; 400 *(psU32*)&readout->colParity = 0; 401 *(psS32*)&readout->col0 = 0; 402 *(psS32*)&readout->row0 = 0; 403 404 readout->image = NULL; 405 readout->mask = NULL; 406 readout->objects = NULL; 407 readout->metadata = NULL; 408 409 psMemSetDeallocator(readout,(psFreeFunc)readoutFree); 410 411 return readout; 412 } 413 414 /* 415 psGrommit* psGrommitAlloc(const psExposure* exp) 416 { 417 PS_ASSERT_PTR_NON_NULL(exp, NULL); 418 419 psSphere* polarMotion = p_psTimeGetPoleCoords(exp->time); 420 421 psGrommit* grommit = (psGrommit* ) psAlloc(sizeof(psGrommit)); 422 423 *(double*)&grommit->latitude = exp->observatory->latitude; 424 *(double*)&grommit->longitude = exp->observatory->longitude; 425 *(double*)&grommit->height = exp->observatory->height; 426 *(double*)&grommit->abberationMag = 0.0; // XXX: need to figure out what to set here. 427 *(double*)&grommit->temperature = exp->temperature; 428 *(double*)&grommit->pressure = exp->pressure; 429 *(double*)&grommit->humidity = exp->humidity; 430 *(double*)&grommit->wavelength = exp->wavelength; 431 *(double*)&grommit->lapseRate = exp->observatory->tlr; 432 *(double*)&grommit->refractA = polarMotion->r; // XXX: need to figure out what to set here too. 433 *(double*)&grommit->refractB = polarMotion->d; // XXX: need to figure out what to set here too. 434 *(double*)&grommit->siderealTime = psTimeToMJD(exp->time); // XXX: this is probably not correct 435 436 psFree(polarMotion); 437 438 return (grommit); 439 } 440 */ 441 /* 442 psCell* psCellInFPA(const psPlane* fpaCoord, 443 const psFPA* FPA) 264 pmCell* pmCellInFPA(const psPlane* fpaCoord, 265 const pmFPA* FPA) 444 266 { 445 267 PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL); 446 268 PS_ASSERT_PTR_NON_NULL(FPA, NULL); 447 448 p sChip* tmpChip = NULL;269 270 pmChip* tmpChip = NULL; 449 271 psPlane chipCoord; 450 p sCell* outCell = NULL;451 272 pmCell* outCell = NULL; 273 452 274 // Determine which chip contains the fpaCoords. 453 tmpChip = p sChipInFPA(fpaCoord, FPA);275 tmpChip = pmChipInFPA(fpaCoord, FPA); 454 276 if (tmpChip == NULL) { 455 277 return(NULL); 456 278 } 457 279 458 280 // Convert to those chip coordinates. 459 281 psCoordFPAToChip(&chipCoord, fpaCoord, tmpChip); 460 282 461 283 // Determine which cell contains those chip coordinates. 462 outCell = p sCellInChip(&chipCoord, tmpChip);463 284 outCell = pmCellInChip(&chipCoord, tmpChip); 285 464 286 return (outCell); 465 287 } 466 */ 467 /* 468 psChip* psChipInFPA(const psPlane* fpaCoord, 469 const psFPA* FPA) 288 289 pmChip* pmChipInFPA(const psPlane* fpaCoord, 290 const pmFPA* FPA) 470 291 { 471 292 PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL); 472 293 PS_ASSERT_PTR_NON_NULL(FPA, NULL); 473 294 PS_ASSERT_PTR_NON_NULL(FPA->chips, NULL); 474 295 475 296 psArray* chips = FPA->chips; 476 297 psS32 nChips = chips->n; 477 298 psPlane chipCoord; 478 p sCell *tmpCell = NULL;479 299 pmCell *tmpCell = NULL; 300 480 301 // Loop through every chip in this FPA. Convert the original FPA 481 302 // coordinates to chip coordinates for that chip. Then, determine if any 482 303 // cells in that chip contain those chip coordinates. 483 304 484 305 for (psS32 i = 0; i < nChips; i++) { 485 p sChip* tmpChip = chips->data[i];306 pmChip* tmpChip = chips->data[i]; 486 307 PS_ASSERT_PTR_NON_NULL(tmpChip, NULL); 487 308 PS_ASSERT_PTR_NON_NULL(tmpChip->fromFPA, NULL); 488 309 489 310 psPlaneTransformApply(&chipCoord, tmpChip->fromFPA, fpaCoord); 490 491 tmpCell = p sCellInChip(&chipCoord, tmpChip);311 312 tmpCell = pmCellInChip(&chipCoord, tmpChip); 492 313 if (tmpCell != NULL) { 493 314 return(tmpChip); 494 315 } 495 316 } 496 317 497 318 // XXX: Print warning here? 498 319 return (NULL); 499 320 } 500 */ 501 /* 502 p sCell* psCellInChip(const psPlane* chipCoord,503 const p sChip* chip)321 322 323 pmCell* pmCellInChip(const psPlane* chipCoord, 324 const pmChip* chip) 504 325 { 505 326 PS_ASSERT_PTR_NON_NULL(chipCoord, NULL); 506 327 PS_ASSERT_PTR_NON_NULL(chip, NULL); 507 328 508 329 psPlane cellCoord; 509 330 psArray* cells; 510 331 511 332 cells = chip->cells; 512 333 if (cells == NULL) { 513 334 return NULL; 514 335 } 515 336 516 337 // We loop over each cell in the chip. We transform the chipCoord into 517 338 // a cellCoord for that cell and determine if that cellCoord is valid. 518 339 // If so, then we return that cell. 519 340 520 341 for (psS32 i = 0; i < cells->n; i++) { 521 p sCell* tmpCell = (psCell* ) cells->data[i];342 pmCell* tmpCell = (pmCell* ) cells->data[i]; 522 343 PS_ASSERT_PTR_NON_NULL(tmpCell, NULL); 523 PS_ASSERT_PTR_NON_NULL(tmpCell->fromChip, NULL); 344 345 psPlaneTransform *chipToCell = NULL; 346 if (1 != p_psIsProjectionLinear(tmpCell->toChip)) { 347 // XXX: Generate warning message. 348 // XXX: Can we use the following function to derive a transform? 349 // chipToCell = psPlaneTransformInvert(NULL, tmpCell->toChip, NULL, -1); 350 } else { 351 chipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip); 352 } 353 354 PS_ASSERT_PTR_NON_NULL(chipToCell, NULL); 524 355 psArray* readouts = tmpCell->readouts; 525 356 526 357 if (readouts != NULL) { 527 358 for (psS32 j = 0; j < readouts->n; j++) { 528 p sReadout* tmpReadout = readouts->data[j];359 pmReadout* tmpReadout = readouts->data[j]; 529 360 PS_ASSERT_READOUT_NON_NULL(tmpReadout, NULL); 530 361 531 362 psPlaneTransformApply(&cellCoord, 532 tmpCell->fromChip,363 chipToCell, 533 364 chipCoord); 534 365 535 366 if (checkValidImageCoords(cellCoord.x, 536 367 cellCoord.y, … … 540 371 } 541 372 } 542 } 543 373 psFree(chipToCell); 374 } 375 544 376 return (NULL); 545 377 } 546 */ 547 /* 378 379 548 380 psPlane* psCoordCellToChip(psPlane* outCoord, 549 381 const psPlane* inCoord, 550 const p sCell* cell)382 const pmCell* cell) 551 383 { 552 384 PS_ASSERT_PTR_NON_NULL(inCoord, NULL); 553 385 PS_ASSERT_PTR_NON_NULL(cell, NULL); 554 386 555 387 return (psPlaneTransformApply(outCoord, cell->toChip, inCoord)); 556 388 } 557 */ 558 /* 389 390 559 391 psPlane* psCoordChipToFPA(psPlane* outCoord, 560 392 const psPlane* inCoord, 561 const p sChip* chip)393 const pmChip* chip) 562 394 { 563 395 PS_ASSERT_PTR_NON_NULL(inCoord, NULL); 564 396 PS_ASSERT_PTR_NON_NULL(chip, NULL); 565 397 566 398 return (psPlaneTransformApply(outCoord, chip->toFPA, inCoord)); 567 399 } 568 */ 569 /* 400 401 402 570 403 psPlane* psCoordFPAToTP(psPlane* outCoord, 571 404 const psPlane* inCoord, 572 405 double color, 573 406 double magnitude, 574 const p sFPA* fpa)407 const pmFPA* fpa) 575 408 { 576 409 PS_ASSERT_PTR_NON_NULL(inCoord, NULL); 577 410 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 578 411 579 412 return(psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord, 580 413 color, magnitude)); 581 414 } 582 */ 415 583 416 /***************************************************************************** 584 417 XXX: What about units for the (x,y) coords? 585 418 *****************************************************************************/ 586 /*587 419 psSphere* psCoordTPToSky(psSphere* outSphere, 588 420 const psPlane* tpCoord, 589 const psGrommit* grommit) 421 const psProjection *projection 422 ) 590 423 { 591 424 PS_ASSERT_PTR_NON_NULL(tpCoord, NULL); 592 PS_ASSERT_PTR_NON_NULL(grommit, NULL); 593 425 594 426 if (outSphere == NULL) { 595 427 outSphere = (psSphere* ) psAlloc(sizeof(psSphere)); 596 428 } 597 429 598 430 // XXX: this was done by a SLALIB call -- needs to be reimplemented 599 431 psWarning("Warning! psCoordTPToSky functionality is no longer implemented"); 600 432 // slaAopqk(tpCoord->x, tpCoord->y, (double*)grommit, 601 433 // &AOB, &ZOB, &HOB, &outSphere->r, &outSphere->d); 602 434 603 435 return (outSphere); 604 436 } 605 */ 606 /* 437 438 439 607 440 psPlane* psCoordCellToFPA(psPlane* fpaCoord, 608 441 const psPlane* cellCoord, 609 const p sCell* cell)442 const pmCell* cell) 610 443 { 611 444 PS_ASSERT_PTR_NON_NULL(cellCoord, NULL); 612 445 PS_ASSERT_PTR_NON_NULL(cell, NULL); 613 446 614 447 return (psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord)); 615 448 } 616 */ 617 /* 449 450 451 618 452 psSphere* psCoordCellToSky(psSphere* skyCoord, 619 453 const psPlane* cellCoord, 620 454 double color, 621 455 double magnitude, 622 const p sCell* cell)456 const pmCell* cell) 623 457 { 624 458 PS_ASSERT_PTR_NON_NULL(cellCoord, NULL); … … 628 462 PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL); 629 463 PS_ASSERT_PTR_NON_NULL(cell->parent->parent->toTangentPlane, NULL); 630 PS_ASSERT_PTR_NON_NULL(cell->parent->parent->exposure, NULL);631 464 // PS_ASSERT_PTR_NON_NULL(cell->parent->parent->exposure, NULL); 465 632 466 psPlane* fpaCoord = NULL; 633 467 psPlane* tpCoord = NULL; 634 p sFPA* parFPA = (cell->parent)->parent;635 psGrommit* tmpGrommit = NULL;636 468 pmFPA* parFPA = (cell->parent)->parent; 469 // psGrommit* tmpGrommit = NULL; 470 637 471 // Convert the input cell coordinates to FPA coordinates. 638 472 fpaCoord = psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord); 639 473 640 474 // Convert the FPA coordinates to tangent plane Coordinates. 641 475 tpCoord = psPlaneDistortApply(tpCoord, parFPA->toTangentPlane, 642 476 fpaCoord, color, magnitude); 643 477 644 478 // Generate a grommit for this FPA. 645 tmpGrommit = psGrommitAlloc(parFPA->exposure);646 479 // tmpGrommit = psGrommitAlloc(parFPA->exposure); 480 647 481 // Convert the tangent plane Coordinates to sky coordinates. 648 skyCoord = psCoordTPToSky(skyCoord, tpCoord, tmpGrommit);649 482 // skyCoord = psCoordTPToSky(skyCoord, tpCoord, tmpGrommit); 483 650 484 psFree(fpaCoord); 651 485 psFree(tpCoord); 652 psFree(tmpGrommit);653 486 // psFree(tmpGrommit); 487 654 488 return(skyCoord); 655 489 } 656 657 */ 658 /* 490 491 659 492 psSphere* psCoordCellToSkyQuick(psSphere* outSphere, 660 493 const psPlane* cellCoord, 661 const p sCell* cell)494 const pmCell* cell) 662 495 { 663 496 PS_ASSERT_PTR_NON_NULL(cellCoord, NULL); … … 667 500 PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL); 668 501 PS_ASSERT_PTR_NON_NULL(cell->parent->parent->projection, NULL); 669 if (cell->toSky) { 670 // XXX: Should we use toTP or toSky? 671 psLogMsg(__func__, PS_LOG_WARN, 672 "WARNING: psCoordCellToSkyQuick(): The cell->toSky transform is ignored. The cell->toTP transform is being used."); 673 } 674 675 psPlane *tpCoord = NULL; 676 psChip *chip = cell->parent; 677 psFPA *FPA = chip->parent; 678 psProjectionType oldProjectionType; 679 680 if (outSphere == NULL) { 681 outSphere = (psSphere* ) psAlloc(sizeof(psSphere)); 682 } 683 684 // Determine the tangent plane coordinates. 685 tpCoord = psPlaneTransformApply(NULL, cell->toTP, cellCoord); 686 687 // Save the old projection type and set the new projection type to TAN. 688 oldProjectionType = FPA->projection->type; 689 FPA->projection->type = PS_PROJ_TAN; 690 691 // Deproject the tangent plane coordinates a sphere. 692 outSphere = psDeproject(tpCoord, FPA->projection); 693 694 // Restore old projection type. Free memory. 695 FPA->projection->type = oldProjectionType; 696 psFree(tpCoord); 697 698 return (outSphere); 699 } 700 */ 502 503 psLogMsg(__func__, PS_LOG_WARN, 504 "WARNING: psCoordCellToSkyQuick(): This function is not fully specified in the SDRS. Returning NULL.\n"); 505 return(NULL); 506 507 /* 508 if (cell->toSky) { 509 // XXX: Should we use toTP or toSky? 510 psLogMsg(__func__, PS_LOG_WARN, 511 "WARNING: psCoordCellToSkyQuick(): The cell->toSky transform is ignored. The cell->toTP transform is being used."); 512 } 513 514 psPlane *tpCoord = NULL; 515 pmChip *chip = cell->parent; 516 pmFPA *FPA = chip->parent; 517 psProjectionType oldProjectionType; 518 519 if (outSphere == NULL) { 520 outSphere = (psSphere* ) psAlloc(sizeof(psSphere)); 521 } 522 523 // Determine the tangent plane coordinates. 524 tpCoord = psPlaneTransformApply(NULL, cell->toTP, cellCoord); 525 526 // Save the old projection type and set the new projection type to TAN. 527 oldProjectionType = FPA->projection->type; 528 FPA->projection->type = PS_PROJ_TAN; 529 530 // Deproject the tangent plane coordinates a sphere. 531 outSphere = psDeproject(tpCoord, FPA->projection); 532 533 // Restore old projection type. Free memory. 534 FPA->projection->type = oldProjectionType; 535 psFree(tpCoord); 536 537 return (outSphere); 538 */ 539 } 540 701 541 702 542 /***************************************************************************** 703 543 XXX: What about units for the (x,y) coords? 704 544 *****************************************************************************/ 705 /*706 545 psPlane* psCoordSkyToTP(psPlane* tpCoord, 707 546 const psSphere* in, 708 const ps Grommit* grommit)547 const psProjection *projection) 709 548 { 710 549 PS_ASSERT_PTR_NON_NULL(in, NULL); 711 PS_ASSERT_PTR_NON_NULL(grommit, NULL);712 550 // PS_ASSERT_PTR_NON_NULL(grommit, NULL); 551 713 552 // char* type = "RA"; 714 553 715 554 if (tpCoord == NULL) { 716 555 tpCoord = (psPlane* ) psAlloc(sizeof(psPlane)); 717 556 } 718 557 719 558 // XXX: this was done by a SLALIB call -- needs to be reimplemented 720 559 psWarning("Warning! psCoordSkyToTP functionality is no longer implemented"); 721 560 // slaOapqk(type, in->r, in->d, (double*)grommit, &tpCoord->x, &tpCoord->y); 722 561 723 562 return(tpCoord); 724 563 } 725 */ 726 /* 564 565 727 566 psPlane* psCoordTPToFPA(psPlane* fpaCoord, 728 567 const psPlane* tpCoord, 729 568 double color, 730 569 double magnitude, 731 const p sFPA* fpa)570 const pmFPA* fpa) 732 571 { 733 572 PS_ASSERT_PTR_NON_NULL(tpCoord, NULL); 734 573 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 735 574 PS_ASSERT_PTR_NON_NULL(fpa->fromTangentPlane, NULL); 736 575 737 576 return (psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane, 738 577 tpCoord, color, magnitude)); 739 578 } 740 */ 741 /* 579 580 742 581 psPlane* psCoordFPAToChip(psPlane* chipCoord, 743 582 const psPlane* fpaCoord, 744 const p sChip* chip)583 const pmChip* chip) 745 584 { 746 585 PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL); 747 586 PS_ASSERT_PTR_NON_NULL(chip, NULL); 748 587 PS_ASSERT_PTR_NON_NULL(chip->fromFPA, NULL); 749 588 750 589 chipCoord = psPlaneTransformApply(chipCoord, chip->fromFPA, fpaCoord); 751 590 return(chipCoord); 752 591 } 753 */ 754 /* 592 593 755 594 psPlane* psCoordChipToCell(psPlane* cellCoord, 756 595 const psPlane* chipCoord, 757 const p sCell* cell)596 const pmCell* cell) 758 597 { 759 598 PS_ASSERT_PTR_NON_NULL(chipCoord, NULL); 760 599 PS_ASSERT_PTR_NON_NULL(cell, NULL); 761 PS_ASSERT_PTR_NON_NULL(cell->fromChip, NULL); 762 763 cellCoord = psPlaneTransformApply(cellCoord, cell->fromChip, chipCoord); 600 PS_ASSERT_PTR_NON_NULL(cell->parent, NULL); 601 602 pmCell *tmpCell = pmCellInChip(chipCoord, cell->parent); 603 PS_ASSERT_PTR_NON_NULL(tmpCell->toChip, NULL); 604 psPlaneTransform *tmpChipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip); 605 PS_ASSERT_PTR_NON_NULL(tmpChipToCell, NULL); 606 cellCoord = psPlaneTransformApply(cellCoord, tmpChipToCell, chipCoord); 607 psFree(tmpChipToCell); 764 608 return(cellCoord); 765 609 } 766 */ 767 /* 610 611 768 612 psPlane* psCoordSkyToCell(psPlane* cellCoord, 769 613 const psSphere* skyCoord, 770 doublecolor,771 doublemagnitude,772 const p sCell* cell)614 float color, 615 float magnitude, 616 const pmCell* cell) 773 617 { 774 618 PS_ASSERT_PTR_NON_NULL(skyCoord, NULL); … … 776 620 PS_ASSERT_PTR_NON_NULL(cell->parent, NULL); 777 621 PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL); 778 PS_ASSERT_PTR_NON_NULL(cell->parent->parent->grommit, NULL); 779 780 psChip *parChip = cell->parent; 781 psFPA *parFPA = parChip->parent; 782 psGrommit* grommit = parFPA->grommit; 783 622 // PS_ASSERT_PTR_NON_NULL(cell->parent->parent->grommit, NULL); 623 624 pmChip *parChip = cell->parent; 625 pmFPA *parFPA = parChip->parent; 626 784 627 // Convert the skyCoords to tangent plane coords. 785 psPlane *tpCoord = psCoordSkyToTP( tpCoord, skyCoord, grommit);786 628 psPlane *tpCoord = psCoordSkyToTP(NULL, skyCoord, parFPA->projection); 629 787 630 // Convert the tangent plane coords to FPA coords. 788 psPlane *fpaCoord = psCoordTPToFPA(fpaCoord, tpCoord, color, 789 magnitude, parFPA); 790 631 psPlane *fpaCoord = psCoordTPToFPA(NULL, tpCoord, color, magnitude, parFPA); 632 791 633 // Convert the FPA coords to chip coords. 792 psPlane *chipCoord = psCoordFPAToChip( chipCoord, fpaCoord, parChip);793 634 psPlane *chipCoord = psCoordFPAToChip(NULL, fpaCoord, parChip); 635 794 636 // Convert the chip coords to cell coords. 795 637 cellCoord = psCoordChipToCell(cellCoord, chipCoord, cell); 796 638 797 639 psFree(tpCoord); 798 640 psFree(fpaCoord); 799 641 psFree(chipCoord); 800 642 801 643 return (cellCoord); 802 644 } 803 */ 804 /* 645 646 805 647 psPlane* psCoordSkyToCellQuick(psPlane* cellCoord, 806 648 const psSphere* skyCoord, 807 const p sCell* cell)649 const pmCell* cell) 808 650 { 809 651 PS_ASSERT_PTR_NON_NULL(skyCoord, NULL); … … 812 654 PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL); 813 655 PS_ASSERT_PTR_NON_NULL(cell->parent->parent->projection, NULL); 814 PS_ASSERT_PTR_NON_NULL(cell->toTP, NULL); 815 if (cell->toSky) { 816 // XXX: Should we use toTP or toSky? 817 psLogMsg(__func__, PS_LOG_WARN, 818 "WARNING: psCoordSkyToCellQuick(): The cell->toSky transform is ignored. The cell->toTP transform is being used."); 819 } 820 821 psPlane *tpCoord = NULL; 822 psChip *whichChip = cell->parent; 823 psFPA *whichFPA = whichChip->parent; 824 psProjectionType oldProjectionType; 825 psPlaneTransform *TPtoCell = NULL; 826 827 // Save the old projection type and set the new projection type to TAN. 828 oldProjectionType = whichFPA->projection->type; 829 whichFPA->projection->type = PS_PROJ_TAN; 830 831 if (cellCoord == NULL) { 832 cellCoord = (psPlane* ) psAlloc(sizeof(psPlane)); 833 } 834 835 tpCoord = psProject(skyCoord, whichFPA->projection); 836 837 // generate an error if cell->toTP is not linear. 838 if (0 == p_psIsProjectionLinear(cell->toTP)) { 839 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 840 PS_ERRORTEXT_psAstrometry_NONLINEAR_TRANSFORM, 841 "cell to tangent plane"); 842 } 843 844 TPtoCell = p_psPlaneTransformLinearInvert(cell->toTP); 845 cellCoord = psPlaneTransformApply(cellCoord, TPtoCell, tpCoord); 846 847 // Restore old projection type. Free memory. 848 whichFPA->projection->type = oldProjectionType; 849 psFree(tpCoord); 850 return (cellCoord); 851 } 852 */ 853 854 656 657 658 psLogMsg(__func__, PS_LOG_WARN, 659 "WARNING: psCoordSkyToCellQuick(): This function is not fully specified in the SDRS. Returning NULL.\n"); 660 return(NULL); 661 /* 662 663 if (cell->toSky) { 664 // XXX: Should we use toTP or toSky? 665 psLogMsg(__func__, PS_LOG_WARN, 666 "WARNING: psCoordSkyToCellQuick: The cell->toSky transform is ignored. The cell->toTP transform is being used."); 667 } 668 669 psPlane *tpCoord = NULL; 670 pmChip *whichChip = cell->parent; 671 pmFPA *whichFPA = whichChip->parent; 672 psProjectionType oldProjectionType; 673 psPlaneTransform *TPtoCell = NULL; 674 675 // Save the old projection type and set the new projection type to TAN. 676 oldProjectionType = whichFPA->projection->type; 677 whichFPA->projection->type = PS_PROJ_TAN; 678 679 if (cellCoord == NULL) { 680 cellCoord = (psPlane* ) psAlloc(sizeof(psPlane)); 681 } 682 683 tpCoord = psProject(skyCoord, whichFPA->projection); 684 685 // generate an error if cell->toTP is not linear. 686 if (0 == p_psIsProjectionLinear(cell->toTP)) { 687 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 688 PS_ERRORTEXT_psAstrometry_NONLINEAR_TRANSFORM, 689 "cell to tangent plane"); 690 } 691 692 TPtoCell = p_psPlaneTransformLinearInvert(cell->toTP); 693 cellCoord = psPlaneTransformApply(cellCoord, TPtoCell, tpCoord); 694 695 // Restore old projection type. Free memory. 696 whichFPA->projection->type = oldProjectionType; 697 psFree(tpCoord); 698 return (cellCoord); 699 */ 700 } 701 702 703
Note:
See TracChangeset
for help on using the changeset viewer.
