diff options
Diffstat (limited to 'tksao')
-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 | ||||
-rw-r--r-- | tksao/vector/vectorstr.C | 64 | ||||
-rw-r--r-- | tksao/vector/vectorstr.h | 18 |
7 files changed, 185 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); diff --git a/tksao/vector/vectorstr.C b/tksao/vector/vectorstr.C index 145bebc..c77ef16 100644 --- a/tksao/vector/vectorstr.C +++ b/tksao/vector/vectorstr.C @@ -62,3 +62,67 @@ istream& operator>>(istream& ss, VectorStr& vv) ss >> vv.c[0] >> vv.c[1]; return ss; } + +// VectorStr3d + +VectorStr3d::~VectorStr3d() +{ + if (c[0]) + delete [] c[0]; + if (c[1]) + delete [] c[1]; + if (c[2]) + delete [] c[2]; +} + +VectorStr3d::VectorStr3d(const char* aa, const char* bb, const char* cc) +{ + c[0] = dupstr(aa); + c[1] = dupstr(bb); + c[2] = dupstr(cc); +} + +VectorStr3d::VectorStr3d(const VectorStr3d& vv) +{ + c[0] = dupstr(vv.c[0]); + c[1] = dupstr(vv.c[1]); + c[2] = dupstr(vv.c[2]); +} + +VectorStr3d& VectorStr3d::operator=(const VectorStr3d& vv) +{ + if (c[0]) + delete [] c[0]; + c[0]=dupstr(vv.c[0]); + if (c[1]) + delete [] c[1]; + c[1]=dupstr(vv.c[1]); + if (c[2]) + delete [] c[2]; + c[2]=dupstr(vv.c[2]); + return *this; +} + +ostream& operator<<(ostream& os, const VectorStr3d& vv) +{ + unsigned char sep = (unsigned char)os.iword(Vector::separator); + if (!sep) + sep = ' '; + + unsigned char unit = (unsigned char)os.iword(Vector::unit); + if (!unit) + os << vv.c[0] << sep << vv.c[1] << sep << vv.c[2]; + else + os << vv.c[0] << unit << sep << vv.c[1] << unit << sep << vv.c[2] << unit; + + // reset unit + os.iword(Vector::unit) = '\0'; + + return os; +} + +istream& operator>>(istream& ss, VectorStr3d& vv) +{ + ss >> vv.c[0] >> vv.c[1] >> vv.c[2]; + return ss; +} diff --git a/tksao/vector/vectorstr.h b/tksao/vector/vectorstr.h index dbf8d49..36587ad 100644 --- a/tksao/vector/vectorstr.h +++ b/tksao/vector/vectorstr.h @@ -25,6 +25,24 @@ class VectorStr { ostream& operator<<(ostream&, const VectorStr&); istream& operator>>(istream&, VectorStr&); + +class VectorStr3d { + public: + char* c[3]; + + public: + VectorStr3d() {c[0]=NULL; c[1]=NULL; c[2]=NULL;} + ~VectorStr3d(); + VectorStr3d(const char*, const char*, const char*); + VectorStr3d(const VectorStr3d&); + VectorStr3d& operator=(const VectorStr3d&); + + const char* operator[](int i) const {return c[i];} // return element + char** cc() {return c;} // return vector +}; + +ostream& operator<<(ostream&, const VectorStr3d&); +istream& operator>>(istream&, VectorStr3d&); #endif |