diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2018-08-15 19:47:24 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2018-08-15 19:47:24 (GMT) |
commit | d51d3f66c47101fcaaf39f90d77950156fc05648 (patch) | |
tree | 528d26a58b1aa5518c2140a61ab7d5a9a50e6b27 /tksao/frame | |
parent | 9c929fe95cf992440ce00ab90a6abb210d2dab88 (diff) | |
download | blt-d51d3f66c47101fcaaf39f90d77950156fc05648.zip blt-d51d3f66c47101fcaaf39f90d77950156fc05648.tar.gz blt-d51d3f66c47101fcaaf39f90d77950156fc05648.tar.bz2 |
simplify getInfo code
Diffstat (limited to 'tksao/frame')
-rw-r--r-- | tksao/frame/fitsimage.C | 73 | ||||
-rw-r--r-- | tksao/frame/fitsimage.h | 23 | ||||
-rw-r--r-- | tksao/frame/fitsmap.C | 52 | ||||
-rw-r--r-- | tksao/frame/frame3dbase.C | 26 | ||||
-rw-r--r-- | tksao/frame/framebase.C | 20 |
5 files changed, 103 insertions, 91 deletions
diff --git a/tksao/frame/fitsimage.C b/tksao/frame/fitsimage.C index 0a95930..2b2d09f 100644 --- a/tksao/frame/fitsimage.C +++ b/tksao/frame/fitsimage.C @@ -2789,6 +2789,30 @@ Vector FitsImage::pix2wcs(const Vector& in, Coord::CoordSystem sys, return Vector(); } +VectorStr FitsImage::pix2wcs(const Vector& in, Coord::CoordSystem sys, + Coord::SkyFrame sky, Coord::SkyFormat format) +{ + if (!hasWCS(sys)) + return VectorStr(); + + astClearStatus; // just to make sure + astBegin; // start memory management + + setWCSSystem(sys); + setWCSSkyFrame(sky); + + Vector out = wcsTran(ast_, in, 1); + if (!astOK || !checkWCS(out)) + return VectorStr(); + + setWCSFormat(sys,sky,format); + astNorm(ast_, out.v); + astEnd; + + return VectorStr(astFormat(ast_,1,out[0]), astFormat(ast_,2,out[1])); +} + +// waj char* FitsImage::pix2wcs(const Vector& in, Coord::CoordSystem sys, Coord::SkyFrame sky, Coord::SkyFormat format, char* lbuf) @@ -2818,29 +2842,6 @@ char* FitsImage::pix2wcs(const Vector& in, Coord::CoordSystem sys, return lbuf; } -VectorStr FitsImage::pix2wcs(const Vector& in, Coord::CoordSystem sys, - Coord::SkyFrame sky, Coord::SkyFormat format) -{ - if (!hasWCS(sys)) - return VectorStr(); - - astClearStatus; // just to make sure - astBegin; // start memory management - - setWCSSystem(sys); - setWCSSkyFrame(sky); - - Vector out = wcsTran(ast_, in, 1); - if (!astOK || !checkWCS(out)) - return VectorStr(); - - setWCSFormat(sys,sky,format); - astNorm(ast_, out.v); - astEnd; - - return VectorStr(astFormat(ast_,1,out[0]), astFormat(ast_,2,out[1])); -} - Vector3d FitsImage::pix2wcs(const Vector3d& in, Coord::CoordSystem sys, Coord::SkyFrame sky) { @@ -2863,6 +2864,32 @@ Vector3d FitsImage::pix2wcs(const Vector3d& in, Coord::CoordSystem sys, return Vector3d(); } +VectorStr3d FitsImage::pix2wcs(const Vector3d& in, Coord::CoordSystem sys, + Coord::SkyFrame sky, Coord::SkyFormat format) +{ + if (!hasWCS(sys)) + return VectorStr3d(); + + astClearStatus; // just to make sure + astBegin; // start memory management + + setWCSSystem(sys); + setWCSSkyFrame(sky); + + Vector out = wcsTran(ast_, in, 1); + if (!astOK || !checkWCS(out)) + return VectorStr3d(); + + setWCSFormat(sys,sky,format); + astNorm(ast_, out.v); + astEnd; + + return VectorStr3d(astFormat(ast_,1,out[0]), + astFormat(ast_,2,out[1]), + astFormat(ast_,3,out[2])); +} + +// waj char* FitsImage::pix2wcs(const Vector3d& in, Coord::CoordSystem sys, Coord::SkyFrame sky, Coord::SkyFormat format, char* lbuf) diff --git a/tksao/frame/fitsimage.h b/tksao/frame/fitsimage.h index a34f9f0..2d493be 100644 --- a/tksao/frame/fitsimage.h +++ b/tksao/frame/fitsimage.h @@ -377,17 +377,19 @@ class FitsImage { Vector& iisz() {return iisz_;} Vector pix2wcs(const Vector&, Coord::CoordSystem, Coord::SkyFrame); - Vector wcs2pix(const Vector&, Coord::CoordSystem, Coord::SkyFrame); - - char* pix2wcs(const Vector&, Coord::CoordSystem, Coord::SkyFrame, Coord::SkyFormat, char*); VectorStr pix2wcs(const Vector&, Coord::CoordSystem, Coord::SkyFrame, Coord::SkyFormat); - int wcsInv() {return wcsInv_;} Vector3d pix2wcs(const Vector3d&, Coord::CoordSystem, Coord::SkyFrame); - Vector3d wcs2pix(const Vector3d&, Coord::CoordSystem, Coord::SkyFrame); + VectorStr3d pix2wcs(const Vector3d&, Coord::CoordSystem, Coord::SkyFrame, Coord::SkyFormat); + //waj + char* pix2wcs(const Vector&, Coord::CoordSystem, Coord::SkyFrame, Coord::SkyFormat, char*); char* pix2wcs(const Vector3d&, Coord::CoordSystem, Coord::SkyFrame, Coord::SkyFormat, char*); + Vector wcs2pix(const Vector&, Coord::CoordSystem, Coord::SkyFrame); + Vector3d wcs2pix(const Vector3d&, Coord::CoordSystem, Coord::SkyFrame); + int wcsInv() {return wcsInv_;} + void wfpc2WCS(istream&); void appendWCS(istream&); void listWCS(ostream&, Coord::CoordSystem); @@ -432,14 +434,19 @@ class FitsImage { Matrix3d& matrixToData3d(Coord::InternalSystem); Vector mapFromRef(const Vector&, Coord::CoordSystem, Coord::SkyFrame =Coord::FK5); - void mapFromRef(const Vector&, Coord::CoordSystem, Coord::SkyFrame, Coord::SkyFormat, char*); VectorStr mapFromRef(const Vector&, Coord::CoordSystem, Coord::SkyFrame, Coord::SkyFormat); - Vector mapToRef(const Vector&, Coord::CoordSystem, Coord::SkyFrame =Coord::FK5); + // waj + void mapFromRef(const Vector&, Coord::CoordSystem, Coord::SkyFrame, Coord::SkyFormat, char*); + Vector3d mapFromRef(const Vector3d&, Coord::CoordSystem, Coord::SkyFrame =Coord::FK5); - Vector3d mapToRef(const Vector3d&, Coord::CoordSystem, Coord::SkyFrame =Coord::FK5); + VectorStr3d mapFromRef(const Vector3d&, Coord::CoordSystem, Coord::SkyFrame, Coord::SkyFormat); + void listFromRef(ostream&, const Vector&, Coord::CoordSystem, Coord::SkyFrame =Coord::FK5, Coord::SkyFormat =Coord::DEGREES); void listFromRef(ostream&, ostream&, const Vector&, Coord::CoordSystem, Coord::SkyFrame =Coord::FK5, Coord::SkyFormat =Coord::DEGREES); + Vector mapToRef(const Vector&, Coord::CoordSystem, Coord::SkyFrame =Coord::FK5); + Vector3d mapToRef(const Vector3d&, Coord::CoordSystem, Coord::SkyFrame =Coord::FK5); + double mapFromImage3d(double, Coord::CoordSystem); double mapToImage3d(double, Coord::CoordSystem); diff --git a/tksao/frame/fitsmap.C b/tksao/frame/fitsmap.C index ef151f3..5aa1c19 100644 --- a/tksao/frame/fitsmap.C +++ b/tksao/frame/fitsmap.C @@ -27,6 +27,16 @@ Vector FitsImage::mapFromRef(const Vector& vv, Coord::CoordSystem out, return Vector(); } +VectorStr FitsImage::mapFromRef(const Vector& vv, Coord::CoordSystem out, + Coord::SkyFrame sky, Coord::SkyFormat format) +{ + if (hasWCS(out)) + return pix2wcs(vv * refToImage, out, sky, format); + else + return VectorStr(); +} + +// waj void FitsImage::mapFromRef(const Vector& vv, Coord::CoordSystem out, Coord::SkyFrame sky, Coord::SkyFormat format, char* buf) @@ -37,13 +47,30 @@ void FitsImage::mapFromRef(const Vector& vv, Coord::CoordSystem out, strcpy(buf,""); } -VectorStr FitsImage::mapFromRef(const Vector& vv, Coord::CoordSystem out, - Coord::SkyFrame sky, Coord::SkyFormat format) +Vector3d FitsImage::mapFromRef(const Vector3d& vv, Coord::CoordSystem out, + Coord::SkyFrame sky) +{ + switch (out) { + case Coord::IMAGE: + case Coord::PHYSICAL: + case Coord::AMPLIFIER: + case Coord::DETECTOR: + return vv * refToImage3d; + default: + if (hasWCS(out)) + return pix2wcs(vv * refToImage3d, out, sky); + } + + return Vector3d(); +} + +VectorStr3d FitsImage::mapFromRef(const Vector3d& vv, Coord::CoordSystem out, + Coord::SkyFrame sky, Coord::SkyFormat format) { if (hasWCS(out)) - return pix2wcs(vv * refToImage, out, sky, format); + return pix2wcs(vv * refToImage3d, out, sky, format); else - return VectorStr(); + return VectorStr3d(); } Vector FitsImage::mapToRef(const Vector& vv, Coord::CoordSystem in, @@ -68,23 +95,6 @@ Vector FitsImage::mapToRef(const Vector& vv, Coord::CoordSystem in, return Vector(); } -Vector3d FitsImage::mapFromRef(const Vector3d& vv, Coord::CoordSystem out, - Coord::SkyFrame sky) -{ - switch (out) { - case Coord::IMAGE: - case Coord::PHYSICAL: - case Coord::AMPLIFIER: - case Coord::DETECTOR: - return vv * refToImage3d; - default: - if (hasWCS(out)) - return pix2wcs(vv * refToImage3d, out, sky); - } - - return Vector3d(); -} - Vector3d FitsImage::mapToRef(const Vector3d& vv, Coord::CoordSystem in, Coord::SkyFrame sky) { diff --git a/tksao/frame/frame3dbase.C b/tksao/frame/frame3dbase.C index 8b16a3b..eec777a 100644 --- a/tksao/frame/frame3dbase.C +++ b/tksao/frame/frame3dbase.C @@ -162,27 +162,11 @@ void Frame3dBase::getInfoWCS(char* var, Vector3d& rr, FitsImage* sptr) Coord::CoordSystem www = (Coord::CoordSystem)(Coord::WCS+ii); if (hasWCS(www)) { - char buff[128]; - sptr->pix2wcs(img, www, wcsSkyFrame_, wcsSkyFormat_, buff); + VectorStr3d out = sptr->mapFromRef(img, www, wcsSkyFrame_, wcsSkyFormat_); - int argc; - const char** argv; - Tcl_SplitList(interp, buff, &argc, &argv); - - if (argc > 0 && argv && argv[0]) - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",x"),argv[0],0); - else - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",x"),"",0); - - if (argc > 1 && argv && argv[1]) - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",y"),argv[1],0); - else - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",y"),"",0); - - if (argc > 2 && argv && argv[2]) - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",z"),argv[2],0); - else - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",z"),"",0); + Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",x"),out[0],0); + Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",y"),out[1],0); + Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",z"),out[2],0); char* xsym = (char*)sptr->getWCSAxisSymbol(www,0); if (xsym) @@ -208,8 +192,6 @@ void Frame3dBase::getInfoWCS(char* var, Vector3d& rr, FitsImage* sptr) Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",sys"),domain,0); else Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",sys"),coord.coordSystemStr(www),0); - - Tcl_Free((char*)argv); } else { Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",x"),"",0); diff --git a/tksao/frame/framebase.C b/tksao/frame/framebase.C index 6592308..a40c5d6 100644 --- a/tksao/frame/framebase.C +++ b/tksao/frame/framebase.C @@ -144,22 +144,10 @@ void FrameBase::getInfoWCS(char* var, Vector& rr, FitsImage* sptr) Coord::CoordSystem www = (Coord::CoordSystem)(Coord::WCS+ii); if (hasWCS(www)) { - char buff[128]; - sptr->pix2wcs(img, www, wcsSkyFrame_, wcsSkyFormat_, buff); + VectorStr out = sptr->mapFromRef(img, www, wcsSkyFrame_, wcsSkyFormat_); - int argc; - const char** argv; - Tcl_SplitList(interp, buff, &argc, &argv); - - if (argc > 0 && argv && argv[0]) - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",x"),argv[0],0); - else - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",x"),"",0); - - if (argc > 1 && argv && argv[1]) - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",y"),argv[1],0); - else - Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",y"),"",0); + Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",x"),out[0],0); + Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",y"),out[1],0); char* xsym = (char*)sptr->getWCSAxisSymbol(www,0); if (xsym) @@ -180,8 +168,6 @@ void FrameBase::getInfoWCS(char* var, Vector& rr, FitsImage* sptr) Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",sys"),domain,0); else Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",sys"),coord.coordSystemStr(www),0); - - Tcl_Free((char*)argv); } else { Tcl_SetVar2(interp,var,varcat(buf,(char*)"wcs",ww,(char*)",x"),"",0); |