From c0b3a0c82c8f3b288fb155f76a3c85a505b38314 Mon Sep 17 00:00:00 2001 From: William Joye Date: Mon, 11 Feb 2019 14:40:18 -0500 Subject: add support for 1D wcs --- tksao/frame/fitsimage.C | 38 ++++++++++++++--- tksao/frame/grid25d.C | 20 +++++++-- tksao/frame/grid2d.C | 21 ++++++++-- tksao/frame/grid3d.C | 17 ++++++++ tksao/frame/wcsast.C | 108 +++++++++++++++++++++++++++++++++++++----------- 5 files changed, 168 insertions(+), 36 deletions(-) diff --git a/tksao/frame/fitsimage.C b/tksao/frame/fitsimage.C index 2668ef0..bfd0cbf 100644 --- a/tksao/frame/fitsimage.C +++ b/tksao/frame/fitsimage.C @@ -2884,7 +2884,21 @@ VectorStr FitsImage::pix2wcs(const Vector& in, Coord::CoordSystem sys, astNorm(ast_, out.v); astEnd; - return VectorStr(astFormat(ast_,1,out[0]), astFormat(ast_,2,out[1])); + int naxes = astGetI(ast_,"Naxes"); + switch (naxes) { + case 1: + { + ostringstream str; + str << setprecision(context_->parent_->precLinear_) << in[1] << ends; + return VectorStr(astFormat(ast_,1,out[0]), str.str().c_str()); + } + case 2: + case 3: + case 4: + return VectorStr(astFormat(ast_,1,out[0]), astFormat(ast_,2,out[1])); + } + + return VectorStr(); } Vector3d FitsImage::pix2wcs(const Vector3d& in, Coord::CoordSystem sys, @@ -2929,12 +2943,24 @@ VectorStr3d FitsImage::pix2wcs(const Vector3d& in, Coord::CoordSystem sys, int naxes = astGetI(ast_,"Naxes"); switch (naxes) { case 1: - // error - break; + { + ostringstream str1; + str1 << setprecision(context_->parent_->precLinear_) << in[1] << ends; + ostringstream str2; + str2 << setprecision(context_->parent_->precLinear_) << in[2] << ends; + return VectorStr3d(astFormat(ast_,1,out[0]), + str1.str().c_str(), + str2.str().c_str()); + } case 2: - return VectorStr3d(astFormat(ast_,1,out[0]), - astFormat(ast_,2,out[1]), - "1"); + { + ostringstream str; + str << setprecision(context_->parent_->precLinear_) << in[1] << ends; + return VectorStr3d(astFormat(ast_,1,out[0]), + astFormat(ast_,2,out[1]), + str.str().c_str()); + + } case 3: case 4: return VectorStr3d(astFormat(ast_,1,out[0]), diff --git a/tksao/frame/grid25d.C b/tksao/frame/grid25d.C index 7d4d039..2433ad7 100644 --- a/tksao/frame/grid25d.C +++ b/tksao/frame/grid25d.C @@ -75,9 +75,23 @@ void Grid25d::doit(RenderMode rm) int naxes = astGetI(ast,"Naxes"); switch (naxes) { case 1: - // error - astEnd; // now, clean up memory - return; + { + AstFrame* zbase = astFrame(1,""); + AstFrame* zcurr = astFrame(1,""); + AstMapping* zmap = (AstMapping*)astUnitMap(1,""); + + AstFrame* wcsbase = (AstFrame*)astGetFrame(ast,AST__BASE); + AstFrame* wcscurr = (AstFrame*)astGetFrame(ast,AST__CURRENT); + AstMapping* wcsmap = (AstMapping*)astGetMapping(ast,AST__BASE,AST__CURRENT); + + AstCmpFrame* cmpwcsbase = astCmpFrame(wcsbase,zbase,""); + AstCmpFrame* cmpwcscurr = astCmpFrame(wcscurr,zcurr,""); + AstCmpMap* cmpwcsmap = astCmpMap(wcsmap,zmap,0,""); + + ast = astFrameSet(cmpwcsbase,""); + astAddFrame(ast, AST__CURRENT, cmpwcsmap, cmpwcscurr); + } + break; case 2: break; case 3: diff --git a/tksao/frame/grid2d.C b/tksao/frame/grid2d.C index cafd702..1e1c6dc 100644 --- a/tksao/frame/grid2d.C +++ b/tksao/frame/grid2d.C @@ -75,9 +75,23 @@ void Grid2d::doit(RenderMode rm) int naxes = astGetI(ast,"Naxes"); switch (naxes) { case 1: - // error - astEnd; // now, clean up memory - return; + { + AstFrame* zbase = astFrame(1,""); + AstFrame* zcurr = astFrame(1,""); + AstMapping* zmap = (AstMapping*)astUnitMap(1,""); + + AstFrame* wcsbase = (AstFrame*)astGetFrame(ast,AST__BASE); + AstFrame* wcscurr = (AstFrame*)astGetFrame(ast,AST__CURRENT); + AstMapping* wcsmap = (AstMapping*)astGetMapping(ast,AST__BASE,AST__CURRENT); + + AstCmpFrame* cmpwcsbase = astCmpFrame(wcsbase,zbase,""); + AstCmpFrame* cmpwcscurr = astCmpFrame(wcscurr,zcurr,""); + AstCmpMap* cmpwcsmap = astCmpMap(wcsmap,zmap,0,""); + + ast = astFrameSet(cmpwcsbase,""); + astAddFrame(ast, AST__CURRENT, cmpwcsmap, cmpwcscurr); + } + break; case 2: break; case 3: @@ -97,6 +111,7 @@ void Grid2d::doit(RenderMode rm) } break; } + // add wcs to frameset // this will link frameset to wcs with unitMap int id = astGetI(ast,"Current"); diff --git a/tksao/frame/grid3d.C b/tksao/frame/grid3d.C index 877a457..681f68d 100644 --- a/tksao/frame/grid3d.C +++ b/tksao/frame/grid3d.C @@ -76,6 +76,23 @@ void Grid3d::doit(RenderMode rm) int naxes = astGetI(ast,"Naxes"); switch (naxes) { case 1: + { + AstFrame* zbase = astFrame(2,""); + AstFrame* zcurr = astFrame(2,""); + AstMapping* zmap = (AstMapping*)astUnitMap(2,""); + + AstFrame* wcsbase = (AstFrame*)astGetFrame(ast,AST__BASE); + AstFrame* wcscurr = (AstFrame*)astGetFrame(ast,AST__CURRENT); + AstMapping* wcsmap = (AstMapping*)astGetMapping(ast,AST__BASE,AST__CURRENT); + + AstCmpFrame* cmpwcsbase = astCmpFrame(wcsbase,zbase,""); + AstCmpFrame* cmpwcscurr = astCmpFrame(wcscurr,zcurr,""); + AstCmpMap* cmpwcsmap = astCmpMap(wcsmap,zmap,0,""); + + ast = astFrameSet(cmpwcsbase,""); + astAddFrame(ast, AST__CURRENT, cmpwcsmap, cmpwcscurr); + } + break; case 2: { AstFrame* zbase = astFrame(1,""); diff --git a/tksao/frame/wcsast.C b/tksao/frame/wcsast.C index d1b75a6..fe41962 100644 --- a/tksao/frame/wcsast.C +++ b/tksao/frame/wcsast.C @@ -71,12 +71,19 @@ Vector wcsTran(AstFrameSet* ast, const Vector& in, int forward) int naxes = astGetI(ast,"Naxes"); switch (naxes) { case 1: - // error - break; + { + double pin[1]; + double pout[1]; + pin[0] = in[0]; + astTran1(ast, 1, pin, forward, pout); + return Vector(pout[0],forward ? 1 : 0); + } case 2: - double xout, yout; - astTran2(ast, 1, in.v, in.v+1, forward, &xout, &yout); - return Vector(xout, yout); + { + double xout, yout; + astTran2(ast, 1, in.v, in.v+1, forward, &xout, &yout); + return Vector(xout, yout); + } case 3: { double pin[3]; @@ -87,7 +94,6 @@ Vector wcsTran(AstFrameSet* ast, const Vector& in, int forward) astTranN(ast, 1, 3, 1, pin, forward, 3, 1, pout); return Vector(pout[0],pout[1]); } - break; case 4: { double pin[4]; @@ -99,7 +105,6 @@ Vector wcsTran(AstFrameSet* ast, const Vector& in, int forward) astTranN(ast, 1, 4, 1, pin, forward, 4, 1, pout); return Vector(pout[0],pout[1]); } - break; } return Vector(); } @@ -109,7 +114,21 @@ void wcsTran(AstFrameSet* ast, int npoint, Vector* in, int forward, Vector* out) int naxes = astGetI(ast,"Naxes"); switch (naxes) { case 1: - // error + { + double* xin = new double[npoint]; + double* xout = new double[npoint]; + + for (int ii=0; ii