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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
// Copyright (C) 1999-2016
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
#include <tk.h>
#include "boxannulus.h"
#include "fitsimage.h"
BoxAnnulus::BoxAnnulus(Base* p, const Vector& ctr,
const Vector& s,
double ang,
const char* clr, int* dsh,
int wth, const char* fnt, const char* txt,
unsigned short prop, const char* cmt,
const List<Tag>& tg, const List<CallBack>& cb)
: BaseBox(p, ctr, ang, clr, dsh, wth, fnt, txt, prop, cmt, tg, cb)
{
numAnnuli_ = 1;
annuli_ = new Vector[1];
annuli_[0] = s;
strcpy(type_,"boxannulus");
numHandle = 4;
updateBBox();
}
BoxAnnulus::BoxAnnulus(Base* p, const Vector& ctr,
const Vector& inner, const Vector& outer, int num,
double ang)
: BaseBox(p, ctr, ang)
{
numAnnuli_ = num+1;
annuli_ = new Vector[numAnnuli_];
for (int i=0; i<numAnnuli_; i++)
annuli_[i] = ((outer-inner)/num)*i+inner;
strcpy(type_,"boxannulus");
numHandle = 4 + numAnnuli_;
updateBBox();
}
BoxAnnulus::BoxAnnulus(Base* p, const Vector& ctr,
const Vector& inner, const Vector& outer, int num,
double ang,
const char* clr, int* dsh,
int wth, const char* fnt, const char* txt,
unsigned short prop, const char* cmt,
const List<Tag>& tg, const List<CallBack>& cb)
: BaseBox(p, ctr, ang, clr, dsh, wth, fnt, txt, prop, cmt, tg, cb)
{
numAnnuli_ = num+1;
annuli_ = new Vector[numAnnuli_];
for (int i=0; i<numAnnuli_; i++)
annuli_[i] = ((outer-inner)/num)*i+inner;
strcpy(type_,"boxannulus");
numHandle = 4 + numAnnuli_;
updateBBox();
}
BoxAnnulus::BoxAnnulus(Base* p, const Vector& ctr,
int an, Vector* s,
double ang,
const char* clr, int* dsh,
int wth, const char* fnt, const char* txt,
unsigned short prop, const char* cmt,
const List<Tag>& tg, const List<CallBack>& cb)
: BaseBox(p, ctr, ang, clr, dsh, wth, fnt, txt, prop, cmt, tg, cb)
{
numAnnuli_ = an;
annuli_ = new Vector[numAnnuli_];
for (int i=0; i<numAnnuli_; i++)
annuli_[i] = s[i];
sortAnnuli();
strcpy(type_, "boxannulus");
numHandle = 4 + numAnnuli_;
updateBBox();
doCallBack(CallBack::EDITCB);
}
BoxAnnulus::BoxAnnulus(const BoxAnnulus& a) : BaseBox(a) {}
void BoxAnnulus::editBegin(int h)
{
if (h<5) {
switch (h) {
case 1:
return;
case 2:
annuli_[numAnnuli_-1] = Vector(-annuli_[numAnnuli_-1][0],annuli_[numAnnuli_-1][1]);
return;
case 3:
annuli_[numAnnuli_-1] = -annuli_[numAnnuli_-1];
return;
case 4:
annuli_[numAnnuli_-1] = Vector(annuli_[numAnnuli_-1][0],-annuli_[numAnnuli_-1][1]);
return;
}
}
doCallBack(CallBack::EDITBEGINCB);
}
void BoxAnnulus::edit(const Vector& v, int h)
{
Matrix mm = bckMatrix();
Matrix nn = mm.invert();
// This sizes about the opposite node
if (h<5) {
Vector o = annuli_[numAnnuli_-1];
Vector n = (annuli_[numAnnuli_-1]/2) - (v*mm);
// don't go thru opposite node
if (n[0]!=0 && n[1]!=0) {
Vector ov = annuli_[numAnnuli_-1]/2 * nn;
annuli_[numAnnuli_-1] = n;
Vector nv = annuli_[numAnnuli_-1]/2 * nn;
center -= nv-ov;
for (int i=0; i<numAnnuli_-1; i++) {
annuli_[i][0] *= fabs(n[0]/o[0]);
annuli_[i][1] *= fabs(n[1]/o[1]);
}
}
}
else {
// we must have some length
double l = (v * mm * 2).length();
annuli_[h-5] = annuli_[numAnnuli_-1] * l/annuli_[numAnnuli_-1][0];
}
updateBBox();
doCallBack(CallBack::EDITCB);
doCallBack(CallBack::MOVECB);
}
void BoxAnnulus::editEnd()
{
for (int i=1; i<numAnnuli_; i++)
annuli_[i] = annuli_[i].abs();
sortAnnuli();
updateBBox();
doCallBack(CallBack::EDITENDCB);
}
int BoxAnnulus::addAnnuli(const Vector& v)
{
Matrix mm = bckMatrix();
double l = (v * mm * 2).length();
Vector rr = annuli_[numAnnuli_-1] * l/annuli_[numAnnuli_-1][0];
return insertAnnuli(rr);
}
void BoxAnnulus::analysis(AnalysisTask mm, int which)
{
switch (mm) {
case RADIAL:
if (!analysisRadial_ && which) {
addCallBack(CallBack::MOVECB, analysisRadialCB_[0],
parent->options->cmdName);
addCallBack(CallBack::EDITCB, analysisRadialCB_[0],
parent->options->cmdName);
addCallBack(CallBack::EDITENDCB, analysisRadialCB_[0],
parent->options->cmdName);
addCallBack(CallBack::ROTATECB, analysisRadialCB_[0],
parent->options->cmdName);
addCallBack(CallBack::UPDATECB, analysisRadialCB_[0],
parent->options->cmdName);
addCallBack(CallBack::DELETECB, analysisRadialCB_[1],
parent->options->cmdName);
}
if (analysisRadial_ && !which) {
deleteCallBack(CallBack::MOVECB, analysisRadialCB_[0]);
deleteCallBack(CallBack::EDITCB, analysisRadialCB_[0]);
deleteCallBack(CallBack::EDITENDCB, analysisRadialCB_[0]);
deleteCallBack(CallBack::ROTATECB, analysisRadialCB_[0]);
deleteCallBack(CallBack::UPDATECB, analysisRadialCB_[0]);
deleteCallBack(CallBack::DELETECB, analysisRadialCB_[1]);
}
analysisRadial_ = which;
break;
case STATS:
if (!analysisStats_ && which) {
addCallBack(CallBack::MOVECB, analysisStatsCB_[0],
parent->options->cmdName);
addCallBack(CallBack::EDITCB, analysisStatsCB_[0],
parent->options->cmdName);
addCallBack(CallBack::EDITENDCB, analysisStatsCB_[0],
parent->options->cmdName);
addCallBack(CallBack::ROTATECB, analysisStatsCB_[0],
parent->options->cmdName);
addCallBack(CallBack::UPDATECB, analysisStatsCB_[0],
parent->options->cmdName);
addCallBack(CallBack::DELETECB, analysisStatsCB_[1],
parent->options->cmdName);
}
if (analysisStats_ && !which) {
deleteCallBack(CallBack::MOVECB, analysisStatsCB_[0]);
deleteCallBack(CallBack::EDITCB, analysisStatsCB_[0]);
deleteCallBack(CallBack::EDITENDCB, analysisStatsCB_[0]);
deleteCallBack(CallBack::ROTATECB, analysisStatsCB_[0]);
deleteCallBack(CallBack::UPDATECB, analysisStatsCB_[0]);
deleteCallBack(CallBack::DELETECB, analysisStatsCB_[1]);
}
analysisStats_ = which;
break;
default:
// na
break;
}
}
void BoxAnnulus::analysisRadial(char* xname, char* yname, char* ename,
Coord::CoordSystem sys)
{
double* xx;
double* yy;
double* ee;
BBox* bb = new BBox[numAnnuli_];
Matrix mm = Rotate(angle) * Translate(center);
for (int ii=0; ii<numAnnuli_; ii++) {
// during resize, annuli_ can be negative
Vector vv = annuli_[ii].abs();
bb[ii] = BBox(-vv * mm);
bb[ii].bound( vv * mm);
bb[ii].bound(Vector( vv[0],-vv[1]) * mm);
bb[ii].bound(Vector(-vv[0], vv[1]) * mm);
}
int num = parent->markerAnalysisRadial(this, &xx, &yy, &ee,
numAnnuli_-1, annuli_,
bb, sys);
analysisXYEResult(xname, yname, ename, xx, yy, ee, num);
}
void BoxAnnulus::analysisStats(Coord::CoordSystem sys, Coord::SkyFrame sky)
{
ostringstream str;
BBox* bb = new BBox[numAnnuli_];
Matrix mm = Rotate(angle) * Translate(center);
for (int ii=0; ii<numAnnuli_; ii++) {
// during resize, annuli_ can be negative
Vector vv = annuli_[ii].abs();
bb[ii] = BBox(-vv * mm);
bb[ii].bound( vv * mm);
bb[ii].bound(Vector( vv[0],-vv[1]) * mm);
bb[ii].bound(Vector(-vv[0], vv[1]) * mm);
}
parent->markerAnalysisStats(this, str, numAnnuli_-1, bb, sys, sky);
str << ends;
Tcl_AppendResult(parent->interp, str.str().c_str(), NULL);
}
// list
void BoxAnnulus::list(ostream& str, Coord::CoordSystem sys, Coord::SkyFrame sky,
Coord::SkyFormat format, int conj, int strip)
{
FitsImage* ptr = parent->findFits(sys,center);
listPre(str, sys, sky, ptr, strip, 0);
switch (sys) {
case Coord::IMAGE:
case Coord::PHYSICAL:
case Coord::DETECTOR:
case Coord::AMPLIFIER:
listNonCel(ptr, str, sys);
break;
default:
if (ptr->hasWCSCel(sys)) {
double aa = parent->mapAngleFromRef(angle,sys,sky);
switch (format) {
case Coord::DEGREES:
{
Vector vv = ptr->mapFromRef(center,sys,sky);
str << "box(" << setprecision(8) << vv
<< setprecision(3) << fixed;
for (int ii=0; ii<numAnnuli_; ii++) {
Vector rr = ptr->mapLenFromRef(annuli_[ii],sys,Coord::ARCSEC);
str << ',' << setunit('"') << rr;
}
str.unsetf(ios_base::floatfield);
str << setprecision(8) << ',' << radToDeg(aa) << ')';
}
break;
case Coord::SEXAGESIMAL:
listRADEC(ptr,center,sys,sky,format);
str << "box(" << ra << ',' << dec
<< setprecision(3) << fixed;
for (int ii=0; ii<numAnnuli_; ii++) {
Vector rr = ptr->mapLenFromRef(annuli_[ii],sys,Coord::ARCSEC);
str << ',' << setunit('"') << rr;
}
str.unsetf(ios_base::floatfield);
str << setprecision(8) << ',' << radToDeg(aa) << ')';
break;
}
}
else
listNonCel(ptr, str, sys);
}
listPost(str, conj, strip);
}
void BoxAnnulus::listNonCel(FitsImage* ptr, ostream& str,
Coord::CoordSystem sys)
{
Vector vv = ptr->mapFromRef(center,sys);
double aa = parent->mapAngleFromRef(angle,sys);
str << "box(" << setprecision(8) << vv;
for (int ii=0; ii<numAnnuli_; ii++) {
Vector rr = ptr->mapLenFromRef(annuli_[ii],sys);
str << ',' << rr;
}
str << ',' << radToDeg(aa) << ')';
}
void BoxAnnulus::listXML(ostream& str, Coord::CoordSystem sys,
Coord::SkyFrame sky, Coord::SkyFormat format)
{
FitsImage* ptr = parent->findFits(sys,center);
XMLRowInit();
XMLRow(XMLSHAPE,type_);
XMLRowCenter(ptr,sys,sky,format);
XMLRowRadius(ptr,sys,annuli_,numAnnuli_);
XMLRowAng(sys,sky);
XMLRowProps(ptr,sys);
XMLRowEnd(str);
}
void BoxAnnulus::listPros(ostream& str, Coord::CoordSystem sys,
Coord::SkyFrame sky, Coord::SkyFormat format,
int strip)
{
FitsImage* ptr = parent->findFits();
switch (sys) {
case Coord::IMAGE:
case Coord::DETECTOR:
case Coord::AMPLIFIER:
sys = Coord::IMAGE;
case Coord::PHYSICAL:
{
Vector vv = ptr->mapFromRef(center,sys);
for (int ii=0; ii<numAnnuli_; ii++) {
coord.listProsCoordSystem(str,sys,sky);
str << "; ";
Vector rr = ptr->mapLenFromRef(annuli_[ii],Coord::IMAGE);
str << "box " << setprecision(8) << vv << ' ' << rr << ' '
<< radToDeg(angle);
if (ii!=0) {
Vector r1 = ptr->mapLenFromRef(annuli_[ii-1],Coord::IMAGE);
str << " & !box " << setprecision(8) << vv << ' ' << r1 << ' '
<< radToDeg(angle);
}
listProsPost(str, strip);
}
}
break;
default:
if (ptr->hasWCSCel(sys)) {
switch (format) {
case Coord::DEGREES:
{
Vector vv = ptr->mapFromRef(center,sys,sky);
for (int ii=0; ii<numAnnuli_; ii++) {
coord.listProsCoordSystem(str,sys,sky);
str << "; ";
Vector rr = ptr->mapLenFromRef(annuli_[ii],sys,Coord::ARCSEC);
str << "box "
<< setprecision(10) << setunit('d') << vv << ' '
<< setprecision(3) << setunit('"') << fixed << rr << ' ';
str.unsetf(ios_base::floatfield);
str << setprecision(8) << radToDeg(angle);
if (ii!=0) {
Vector r1 = ptr->mapLenFromRef(annuli_[ii-1],sys,Coord::ARCSEC);
str << " & !box "
<< setprecision(8) << setunit('d') << vv << ' '
<< setprecision(3) << setunit('"') << fixed << r1 << ' ';
str.unsetf(ios_base::floatfield);
str << setprecision(8) << radToDeg(angle);
}
listProsPost(str, strip);
}
}
break;
case Coord::SEXAGESIMAL:
listRADECPros(ptr,center,sys,sky,format);
for (int ii=0; ii<numAnnuli_; ii++) {
coord.listProsCoordSystem(str,sys,sky);
str << "; ";
Vector rr = ptr->mapLenFromRef(annuli_[ii],sys,Coord::ARCSEC);
str << "box " << ra << ' ' << dec << ' '
<< setprecision(3) << setunit('"') << fixed << rr << ' ';
str.unsetf(ios_base::floatfield);
str << setprecision(8) << radToDeg(angle);
if (ii!=0) {
Vector r1 = ptr->mapLenFromRef(annuli_[ii-1],sys,Coord::ARCSEC);
str << " & !box " << ra << ' ' << dec << ' '
<< setprecision(3) << setunit('"') << fixed << r1 << ' ';
str.unsetf(ios_base::floatfield);
str << setprecision(8) << radToDeg(angle);
}
listProsPost(str, strip);
}
break;
}
}
}
}
void BoxAnnulus::listSAOimage(ostream& str, int strip)
{
FitsImage* ptr = parent->findFits();
listSAOimagePre(str);
for (int ii=0; ii<numAnnuli_; ii++) {
Vector vv = ptr->mapFromRef(center,Coord::IMAGE);
str << "box(" << setprecision(8) << vv << ','
<< annuli_[ii] << ',' << radToDeg(angle) << ')';
if (ii!=0)
str << " & !box(" << setprecision(8) << vv << ','
<< annuli_[ii-1] << ',' << radToDeg(angle) << ')';
listSAOimagePost(str, strip);
}
}
|