From 04731b65a3518fac20f7c4b64f90b4adaacf6c18 Mon Sep 17 00:00:00 2001 From: William Joye Date: Thu, 12 Jul 2018 14:53:43 -0400 Subject: simplify wcs code --- tksao/frame/coord.h | 7 +++ tksao/frame/fitsimage.C | 144 ++++++++++++++++++++++++++++++------------------ tksao/frame/fitsimage.h | 1 + 3 files changed, 98 insertions(+), 54 deletions(-) diff --git a/tksao/frame/coord.h b/tksao/frame/coord.h index 3d34e88..6176d23 100644 --- a/tksao/frame/coord.h +++ b/tksao/frame/coord.h @@ -19,10 +19,17 @@ class Coord { enum InternalSystem {WINDOW, CANVAS, WIDGET, USER, REF, PANNER, MAGNIFIER, PS}; +#ifndef NEWWCS enum CoordSystem {DATA, IMAGE, PHYSICAL, AMPLIFIER, DETECTOR, WCS, WCSA, WCSB, WCSC, WCSD, WCSE, WCSF, WCSG, WCSH, WCSI, WCSJ, WCSK, WCSL, WCSM, WCSN, WCSO, WCSP, WCSQ, WCSR, WCSS, WCST, WCSU, WCSV, WCSW, WCSX, WCSY, WCSZ, WCS0}; +#else + enum CoordSystem {DATA, IMAGE, PHYSICAL, AMPLIFIER, DETECTOR, WCS=8, + WCSA, WCSB, WCSC, WCSD, WCSE, WCSF, WCSG, WCSH, WCSI, + WCSJ, WCSK, WCSL, WCSM, WCSN, WCSO, WCSP, WCSQ, WCSR, + WCSS, WCST, WCSU, WCSV, WCSW, WCSX, WCSY, WCSZ, WCS0=8}; +#endif enum SkyFrame {FK4, FK4_NO_E, FK5, ICRS, GALACTIC, SUPERGALACTIC, ECLIPTIC, HELIOECLIPTIC}; diff --git a/tksao/frame/fitsimage.C b/tksao/frame/fitsimage.C index 229801a..b047ca2 100644 --- a/tksao/frame/fitsimage.C +++ b/tksao/frame/fitsimage.C @@ -1070,9 +1070,9 @@ void FitsImage::iisSetFileName(const char* fn) iisFileName = dupstr(fn); } +#ifndef NEWWCS void FitsImage::initWCS() { -#ifndef NEWWCS if (wcs_) { for (int ii=0; iinextSlice(); while (sptr) { if (sptr == this) { -#ifndef NEWWCS for (int ii=0; iiwcs_[ii]; for (int ii=0; iiast_[ii]; for (int ii=0; iiwcsx_[ii]; -#else - ast_ = ptr->ast_; - astInv_ = ptr->astInv_; - wcs_ = ptr->wcs_; - wcsEqu_ = ptr->wcsEqu_; - wcsCel_ = ptr->wcsCel_; - wcs3D_ = ptr->wcs3D_; - wcsHPX_ = ptr->wcsHPX_; -#endif -#ifndef NEWWCS initWCSPhysical(); -#endif manageWCS_ =0; return; } @@ -1178,7 +1143,6 @@ void FitsImage::initWCS() prim = image_->primary() && image_->inherit() ? image_->primary() : NULL; } -#ifndef NEWWCS // wcsinit is sloooowwww! so try to figure it out first // look first for default WCS. Let wcsinit figure it out since there can // be many different non-standard wcs's present @@ -1225,19 +1189,7 @@ void FitsImage::initWCS() astShow(ast_[ii]); } } -#else - astInit(hd, prim); - wcsInit(); - wcsEquInit(); - wcsCelInit(); - wcs3DInit(); - wcsHPXInit(); - - if (DebugAST && ast_) - astShow(ast_); -#endif -#ifndef NEWWCS // WCSDEP if (hd->find("WCSDEP")) { char* str = hd->getString("WCSDEP"); @@ -1319,9 +1271,85 @@ void FitsImage::initWCS() } } } -#endif } +#else + +void FitsImage::initWCS() +{ + if (manageWCS_) { + if (ast_) + astAnnul(ast_); + ast_ = NULL; + if (wcs_) + delete [] wcs_; + wcs_ = NULL; + if (wcs_) + delete [] wcs_; + wcs_ = NULL; + if (wcsEqu_) + delete [] wcsEqu_; + wcsEqu_ = NULL; + if (wcsCel_) + delete [] wcsCel_; + wcsCel_ = NULL; + if (wcs3D_) + delete [] wcs3D_; + wcs3D_ = NULL; + wcsHPX_ = 0; + } + + // shareWCS? + manageWCS_ =1; + if (context_->shareWCS()) { + FitsImage* ptr = context_->fits; + while (ptr) { + if (ptr == this) + break; + + FitsImage* sptr = ptr->nextSlice(); + while (sptr) { + if (sptr == this) { + ast_ = ptr->ast_; + astInv_ = ptr->astInv_; + wcs_ = ptr->wcs_; + wcsEqu_ = ptr->wcsEqu_; + wcsCel_ = ptr->wcsCel_; + wcs3D_ = ptr->wcs3D_; + wcsHPX_ = ptr->wcsHPX_; + + manageWCS_ =0; + return; + } + sptr = sptr->nextSlice(); + } + ptr = ptr->nextMosaic(); + } + } + + FitsHead* hd =NULL; + FitsHead* prim =NULL; + if (wcsHeader_) + hd = wcsHeader_; + else if (altHeader_) + hd = altHeader_; + else { + hd = image_->head(); + prim = image_->primary() && image_->inherit() ? image_->primary() : NULL; + } + + astInit(hd, prim); + wcsInit(); + wcsEquInit(); + wcsCelInit(); + wcs3DInit(); + wcsHPXInit(); + + if (DebugAST && ast_) + astShow(ast_); +} +#endif + #ifndef NEWWCS void FitsImage::initWCSPhysical() { @@ -1350,6 +1378,7 @@ void FitsImage::initWCSPhysical() } #endif +#ifndef NEWWCS void FitsImage::initWCS0(const Vector& pix) { FitsHead* hd =NULL; @@ -1363,7 +1392,6 @@ void FitsImage::initWCS0(const Vector& pix) prim = image_->primary() && image_->inherit() ? image_->primary() : NULL; } -#ifndef NEWWCS int ii = Coord::WCS0-Coord::WCS; if (wcs_[ii]) wcsfree(wcs_[ii]); @@ -1392,8 +1420,12 @@ void FitsImage::initWCS0(const Vector& pix) if (DebugAST) astShow(ast_[ii]); } -#endif } +#else +void FitsImage::initWCS0(const Vector& pix) +{ +} +#endif void FitsImage::load() { @@ -2353,9 +2385,9 @@ void FitsImage::resetWCS() initWCS(); } +#ifndef NEWWCS void FitsImage::resetWCS0() { -#ifndef NEWWCS int ii = Coord::WCS0-Coord::WCS; if (wcs_[ii]) wcsfree(wcs_[ii]); @@ -2364,8 +2396,12 @@ void FitsImage::resetWCS0() if (ast_[ii]) astAnnul(ast_[ii]); ast_[ii] = NULL; -#endif } +#else +void FitsImage::resetWCS0() +{ +} +#endif char* FitsImage::root(const char* fn) { diff --git a/tksao/frame/fitsimage.h b/tksao/frame/fitsimage.h index b5f63a9..9451e81 100644 --- a/tksao/frame/fitsimage.h +++ b/tksao/frame/fitsimage.h @@ -132,6 +132,7 @@ class FitsImage { AstFrameSet** ast_; // ast frameset; #else AstFrameSet* ast_; // ast frameset; + AstFrameSet* astAlt_; // ast frameset; #endif private: -- cgit v0.12