diff options
-rw-r--r-- | tksao/frame/fitsimage.C | 1 | ||||
-rw-r--r-- | tksao/frame/fitsmap.C | 176 | ||||
-rw-r--r-- | tksao/frame/frmap.C | 34 | ||||
-rw-r--r-- | tksao/util/util.C | 2 | ||||
-rw-r--r-- | tksao/util/util.h | 2 | ||||
-rw-r--r-- | tksao/vector/vector.C | 10 | ||||
-rw-r--r-- | tksao/vector/vector.h | 12 |
7 files changed, 180 insertions, 57 deletions
diff --git a/tksao/frame/fitsimage.C b/tksao/frame/fitsimage.C index 78460b7..ae73e0e 100644 --- a/tksao/frame/fitsimage.C +++ b/tksao/frame/fitsimage.C @@ -2951,6 +2951,7 @@ Coord::Orientation FitsImage::getWCSOrientation(Coord::CoordSystem sys, else rr = ang<0 ? Coord::NORMAL : Coord::XX; } + astEnd; // now, clean up memory return rr; } diff --git a/tksao/frame/fitsmap.C b/tksao/frame/fitsmap.C index 7b1a2d1..1dfcb8f 100644 --- a/tksao/frame/fitsmap.C +++ b/tksao/frame/fitsmap.C @@ -107,6 +107,7 @@ void FitsImage::listFromRef(ostream& str, const Vector& vv, // Map Length +#ifndef NEWWCS double FitsImage::mapLenFromRef(double dd, Coord::CoordSystem sys, Coord::DistFormat dist) { @@ -114,7 +115,6 @@ double FitsImage::mapLenFromRef(double dd, Coord::CoordSystem sys, return rr[0]; } -#ifndef NEWWCS Vector FitsImage::mapLenFromRef(const Vector& vv, Coord::CoordSystem sys, Coord::DistFormat dist) { @@ -154,72 +154,77 @@ Vector FitsImage::mapLenFromRef(const Vector& vv, Coord::CoordSystem sys, return Vector(); } #else -Vector FitsImage::mapLenFromRef(const Vector& in, Coord::CoordSystem sys, +double FitsImage::mapLenFromRef(double dd, Coord::CoordSystem sys, Coord::DistFormat dist) { - Vector vv = in; // really from image coords switch (sys) { case Coord::IMAGE: - return mapLen(vv,refToImage); + return dd*refToImage[1].length(); case Coord::PHYSICAL: - return mapLen(vv,refToPhysical); + return dd*refToPhysical[1].length(); case Coord::AMPLIFIER: - return mapLen(vv,refToPhysical * physicalToAmplifier); + return dd*(refToPhysical * physicalToAmplifier)[1].length(); case Coord::DETECTOR: - return mapLen(vv,refToPhysical * physicalToDetector); + return dd*(refToPhysical * physicalToDetector)[1].length(); default: - if (hasWCS(sys)) { + { int ss = sys-Coord::WCS; - Vector out; - Vector cc = center(); - double xx[3], wxx[3]; - xx[0] = cc[0]; - xx[1] = cc[0]+vv[0]; - xx[2] = cc[0]; - double yy[3], wyy[3]; - yy[0] = cc[1]; - yy[1] = cc[1]; - yy[2] = cc[1]+vv[1]; - astTran2(ast_[ss],3,xx,yy,1,wxx,wyy); - - double pt0[2]; - pt0[0] = wxx[0]; - pt0[1] = wyy[0]; - double pt1[2]; - pt1[0] = wxx[1]; - pt1[1] = wyy[1]; - double pt2[2]; - pt2[0] = wxx[2]; - pt2[1] = wyy[2]; - double rr1 = astDistance(ast_[ss],pt0,pt1); - double rr2 = astDistance(ast_[ss],pt0,pt2); - - if (astIsASkyFrame(astGetFrame(ast_[ss], AST__CURRENT))) { - out = Vector(radToDeg(rr1),radToDeg(rr2)); - switch (dist) { - case Coord::DEGREE: - break; - case Coord::ARCMIN: - out *= 60.; - break; - case Coord::ARCSEC: - out *= 60.*60.; - break; + if (sys>=Coord::WCS && ast_ && ast_[ss]) { + astClearStatus; // just to make sure + astBegin; // start memory management + + Vector cc = center(); + double xx[2], wxx[2]; + xx[0] = cc[0]; + xx[1] = cc[0]; + double yy[2], wyy[2]; + yy[0] = cc[1]; + yy[1] = cc[1]+dd; + astTran2(ast_[ss],2,xx,yy,1,wxx,wyy); + + double pt0[2]; + pt0[0] = wxx[0]; + pt0[1] = wyy[0]; + double pt1[2]; + pt1[0] = wxx[1]; + pt1[1] = wyy[1]; + double out = astDistance(ast_[ss],pt0,pt1); + + if (astIsASkyFrame(astGetFrame(ast_[ss], AST__CURRENT))) { + out = radToDeg(out); + switch (dist) { + case Coord::DEGREE: + break; + case Coord::ARCMIN: + out *= 60.; + break; + case Coord::ARCSEC: + out *= 60.*60.; + break; + } } - } - else - out = Vector(rr1,rr2); - return out; + astEnd; // now, clean up memory + return out; + } } } maperr =1; - return Vector(); + return 0; +} + +Vector FitsImage::mapLenFromRef(const Vector& vv, Coord::CoordSystem sys, + Coord::DistFormat dist) +{ + double rx = mapLenFromRef(((Vector)vv)[0],sys,dist); + double ry = mapLenFromRef(((Vector)vv)[1],sys,dist); + return Vector(rx,ry); } #endif +#ifndef NEWWCS double FitsImage::mapLenToRef(double dd, Coord::CoordSystem sys, Coord::DistFormat dist) { @@ -264,6 +269,81 @@ Vector FitsImage::mapLenToRef(const Vector& vv, Coord::CoordSystem sys, maperr =1; return Vector(); } +#else +double FitsImage::mapLenToRef(double dd, Coord::CoordSystem sys, + Coord::DistFormat dist) +{ + switch (sys) { + case Coord::IMAGE: + return dd*imageToRef[1].length(); + case Coord::PHYSICAL: + return dd*physicalToRef[1].length(); + case Coord::AMPLIFIER: + return dd*(amplifierToPhysical * physicalToRef)[1].length(); + case Coord::DETECTOR: + return dd*(detectorToPhysical * physicalToRef)[1].length(); + default: + { + int ss = sys-Coord::WCS; + if (sys>=Coord::WCS && ast_ && ast_[ss]) { + astClearStatus; // just to make sure + astBegin; // start memory management + + if (astIsASkyFrame(astGetFrame(ast_[ss], AST__CURRENT))) { + dd = degToRad(dd); + switch (dist) { + case Coord::DEGREE: + break; + case Coord::ARCMIN: + dd /= 60.; + break; + case Coord::ARCSEC: + dd /= 60.*60.; + break; + } + } + + Vector cc = center(); + Vector wcc; + astTran2(ast_[ss],1,cc.v,cc.v+1,1,wcc.v,wcc.v+1); + + double wxx[2], xx[2]; + wxx[0] = wcc[0]; + wxx[1] = wcc[0]; + double wyy[2], yy[2]; + wyy[0] = wcc[1]; + wyy[1] = wcc[1]+dd; + astTran2(ast_[ss],2,wxx,wyy,0,xx,yy); + + double pt0[2]; + pt0[0] = xx[0]; + pt0[1] = yy[0]; + double pt1[2]; + pt1[0] = xx[1]; + pt1[1] = yy[1]; + + astInvert(ast_[ss]); + double out = astDistance(ast_[ss],pt0,pt1); + astInvert(ast_[ss]); + astEnd; // now, clean up memory + + return out; + } + } + } + + maperr =1; + return 0; +} + +Vector FitsImage::mapLenToRef(const Vector& vv, Coord::CoordSystem sys, + Coord::DistFormat dist) +{ + double rx = mapLenToRef(((Vector)vv)[0],sys,dist); + double ry = mapLenToRef(((Vector)vv)[1],sys,dist); + return Vector(rx,ry); +} +#endif void FitsImage::listLenFromRef(ostream& str, double dd, Coord::CoordSystem sys, Coord::DistFormat dist) diff --git a/tksao/frame/frmap.C b/tksao/frame/frmap.C index 7a8f537..9feec03 100644 --- a/tksao/frame/frmap.C +++ b/tksao/frame/frmap.C @@ -50,6 +50,7 @@ double Base::mapAngleToRef(double angle, Coord::CoordSystem sys, return zeroTWOPI(rr); } +#ifndef NEWWCS double Base::mapLenToRef(double d, Coord::InternalSystem sys) { Vector r = mapLenToRef(Vector(d,0),sys); @@ -67,6 +68,39 @@ Vector Base::mapLenToRef(const Vector& v, Coord::InternalSystem sys) return Vector(); } } +#else +double Base::mapLenToRef(double dd, Coord::InternalSystem sys) +{ + switch (sys) { + case Coord::CANVAS: + return dd*canvasToRef[1].length(); + case Coord::PANNER: + return dd*pannerToRef[1].length(); + default: + return 0; + } +} + +Vector Base::mapLenToRef(const Vector& v, Coord::InternalSystem sys) +{ + switch (sys) { + case Coord::CANVAS: + { + double rx = ((Vector)v)[0]*canvasToRef[0].length(); + double ry = ((Vector)v)[1]*canvasToRef[1].length(); + return Vector(rx,ry); + } + case Coord::PANNER: + { + double rx = ((Vector)v)[0]*pannerToRef[0].length(); + double ry = ((Vector)v)[1]*pannerToRef[1].length(); + return Vector(rx,ry); + } + default: + return Vector(); + } +} +#endif Vector FrameBase::mapFromRef(const Vector& vv, Coord::InternalSystem sys) { diff --git a/tksao/util/util.C b/tksao/util/util.C index 9f4decd..800b9da 100644 --- a/tksao/util/util.C +++ b/tksao/util/util.C @@ -449,6 +449,7 @@ int dCompare(const void* a, const void* b) return 0; } +#ifndef NEWWCS Vector mapLen(const Vector& v, const Matrix& mx) { // remove translation @@ -462,6 +463,7 @@ Vector mapLen(const Vector& v, const Matrix& mx) // all that is left is Scaling return (v*s).abs(); } +#endif #if defined (MAC_OSX_TK) || (_WIN32) diff --git a/tksao/util/util.h b/tksao/util/util.h index 4180bff..7b91e6a 100644 --- a/tksao/util/util.h +++ b/tksao/util/util.h @@ -120,6 +120,8 @@ extern const char* psFontName(const char*, const char*, const char*); extern int fCompare(const void*, const void*); extern int dCompare(const void*, const void*); +#ifndef NEWWCS extern Vector mapLen(const Vector& v, const Matrix& mx); +#endif #endif diff --git a/tksao/vector/vector.C b/tksao/vector/vector.C index 194aca5..65ca1c3 100644 --- a/tksao/vector/vector.C +++ b/tksao/vector/vector.C @@ -44,6 +44,16 @@ Vector& Vector::clip(const BBox& bb) return *this; } +Vector Vector::radToDeg() +{ + return Vector(v[0]*180./M_PI,v[1]*180./M_PI); +} + +Vector Vector::degToRad() +{ + return Vector(v[0]*M_PI/180.,v[1]*M_PI/180.); +} + Vector Vector::TkCanvasPs(void* canvas) { return Vector(v[0], Tk_CanvasPsY((Tk_Canvas)canvas, v[1])); diff --git a/tksao/vector/vector.h b/tksao/vector/vector.h index 77cec3d..2f6a90d 100644 --- a/tksao/vector/vector.h +++ b/tksao/vector/vector.h @@ -75,21 +75,15 @@ class Vector { Vector normalize() {double d = sqrt(v[0]*v[0]+v[1]*v[1]); return d ? Vector(v[0]/d,v[1]/d) : Vector();} + Vector radToDeg(); + Vector degToRad(); + // restrict vector by bbox Vector& clip(const BBox&); Vector TkCanvasPs(void* canvas); }; -// This I/O manipulator flips the number stored in iword between 0 and 1 -/* -inline ios_base& setfoo(ios_base& os) -{ - os.iword(Vector::foo) = !os.iword(Vector::foo); - return os; -} -*/ - // Vector separator(int) struct _Setseparator {int _M_n;}; |