summaryrefslogtreecommitdiffstats
path: root/tksao/frame/frmap.C
blob: feb267a74a0bc0308f72d9abb4ce265f70fc4ebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (C) 1999-2016
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#include "context.h"
#include "framebase.h"
#include "fitsimage.h"

double Base::mapAngleFromRef(double angle, Coord::CoordSystem sys, Coord::SkyFrame sky)
{
  double rr = angle;
  FitsImage* ptr = currentContext->cfits;
  if (!ptr)
    return 0;

  switch (sys) {
  case Coord::IMAGE: 
  case Coord::PHYSICAL:
  case Coord::DETECTOR:
  case Coord::AMPLIFIER:
    break;
  default:
    switch (ptr->getWCSOrientation(sys,sky)) {
    case Coord::NORMAL:
      rr += ptr->getWCSRotation(sys,sky);
      break;
    case Coord::XX:
      rr = -(angle + ptr->getWCSRotation(sys,sky) + M_PI);
      break;
    case Coord::YY:
    case Coord::XY:
      break;
    }
  }

  return zeroTWOPI(rr);
}

double Base::mapAngleToRef(double angle, Coord::CoordSystem sys, Coord::SkyFrame sky)
{
  double rr = angle;
  FitsImage* ptr = currentContext->cfits;
  if (!ptr)
    return 0;

  switch (sys) {
  case Coord::IMAGE: 
  case Coord::PHYSICAL:
  case Coord::DETECTOR:
  case Coord::AMPLIFIER:
    break;
  default:
    switch (ptr->getWCSOrientation(sys,sky)) {
    case Coord::NORMAL:
      rr -= ptr->getWCSRotation(sys,sky);
      break;
    case Coord::XX:
      rr = -(angle + ptr->getWCSRotation(sys,sky) + M_PI);
      break;
    case Coord::YY:
    case Coord::XY:
      break;
    }
  }

  return zeroTWOPI(rr);
}

double Base::mapDistFromRef(const Vector& v1, const Vector& v2, 
			    Coord::InternalSystem sys)
{
  switch (sys) {
  case Coord::CANVAS:
    return (v2*refToCanvas - v1*refToCanvas).length();
  case Coord::PANNER:
    return (v2*refToPanner - v1*refToPanner).length();
  default:
    // na
    return 0;
  }
}

double Base::mapLenFromRef(double d, Coord::InternalSystem sys)
{
  Vector r = mapLenFromRef(Vector(d,0),sys);
  return r[0];
}

Vector Base::mapLenFromRef(const Vector& v, Coord::InternalSystem sys)
{
  switch (sys) {
  case Coord::CANVAS:
    return mapLen(v,refToCanvas);
  case Coord::PANNER:
    return mapLen(v,refToPanner);
  default:
    return Vector();
  }
}

double Base::mapLenToRef(double d, Coord::InternalSystem sys)
{
  Vector r = mapLenToRef(Vector(d,0),sys);
  return r[0];
}

Vector Base::mapLenToRef(const Vector& v, Coord::InternalSystem sys)
{
  switch (sys) {
  case Coord::CANVAS:
    return mapLen(v,canvasToRef);
  case Coord::PANNER:
    return mapLen(v,pannerToRef);
  default:
    return Vector();
  }
}

Vector FrameBase::mapFromRef(const Vector& vv, Coord::InternalSystem sys)
{
  switch (sys) {
  case Coord::REF:
    return vv;
  case Coord::USER:
    return vv * refToUser;
  case Coord::WIDGET:
    return vv * refToWidget;
  case Coord::CANVAS:
    return vv * refToCanvas;
  case Coord::WINDOW:
    return vv * refToWindow;
  case Coord::PANNER:
    return vv * refToPanner;
  case Coord::MAGNIFIER:
    return vv * refToMagnifier;
  default:
    return Vector();
  }
}

Vector FrameBase::mapToRef(const Vector& vv, Coord::InternalSystem sys)
{
  switch (sys) {
  case Coord::REF:
    return vv;
  case Coord::USER:
    return vv * userToRef;
  case Coord::WIDGET:
    return vv * widgetToRef;
  case Coord::CANVAS:
    return vv * canvasToRef;
  case Coord::WINDOW:
    return vv * windowToRef;
  case Coord::PANNER:
    return vv * pannerToRef;
  case Coord::MAGNIFIER:
    return vv * magnifierToRef;
  default:
    return Vector();
  }
}