-
Notifications
You must be signed in to change notification settings - Fork 2
/
PNCDImage.cxx
188 lines (160 loc) · 4.48 KB
/
PNCDImage.cxx
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
#include <Xm/RowColumn.h>
#include <math.h>
#include "PNCDImage.h"
#include "PImageWindow.h"
#include "PNCDHistogram.h"
#include "PResourceManager.h"
#include "PUtils.h"
#include "xsnoed.h"
#include "menu.h"
#include "colours.h"
const float kNcdRadius = 400;
const float kNcdTubeSize = 20;
const int kCursorNear = 8; // pixels that cursor is near NCD tube
#define NCD_MARGIN_BOTTOM (25 * GetScaling())
#define NCD_MARGIN_LEFT (48 * GetScaling())
#define NCD_MARGIN_TOP (14 * GetScaling())
#define NCD_MARGIN_RIGHT (24 * GetScaling())
#define NCD_LABEL_Y (-10 * GetScaling())
// ------------------------------------------------------------
PNCDImage::PNCDImage(PImageWindow *owner, Widget canvas)
: PProjImage(owner,canvas)
{
int n;
Arg wargs[10];
if (!canvas) {
n = 0;
XtSetArg(wargs[n],XmNmarginHeight, 1); ++n;
XtSetArg(wargs[n],XmNleftAttachment, XmATTACH_FORM); ++n;
XtSetArg(wargs[n],XmNtopAttachment, XmATTACH_FORM); ++n;
CreateCanvas("ncdCanvas", kScrollLeftMask);
}
}
PNCDImage::~PNCDImage()
{
}
void PNCDImage::Listen(int message, void *dataPt)
{
switch (message) {
case kMessageNCDSizeChanged:
SetDirty();
break;
default:
PProjImage::Listen(message,dataPt);
break;
}
}
// find ncd nearest current cursor position
int PNCDImage::FindNearestNcd()
{
ImageData *data = mOwner->GetData();
if (data->mLastImage != this) {
TransformHits(); // must transform hits to this projection
}
int num = data->numNcds;
int cur_num = -1;
int curx = data->last_cur_x;
int cury = data->last_cur_y;
int d = 1000000;
float fr = mProj.xscl * kNcdTubeSize / kNcdRadius;
int r = (int)(fr + 0.5) + kCursorNear;
int r2 = r * r;
for (int i=0; i<num; ++i) {
NCDMap *map = data->ncdMap + i;
int x = map->nodes[0].x;
int y = map->nodes[0].y;
int dx = x - curx;
int dy = y - cury;
int t = dx*dx + dy*dy;
if (t <= d) { /* find closest node */
cur_num = i;
d = t;
}
}
/* don't show hit info if too far away from hit (r + kCursorNear pixels) */
if (d > r2) {
cur_num = -1;
}
if (data->cursor_ncd != cur_num) {
data->cursor_ncd = cur_num;
return(1);
}
return(0);
}
/*
** Draw NCD image
*/
void PNCDImage::DrawSelf()
{
ImageData *data = mOwner->GetData();
int i,num;
#ifdef PRINT_DRAWS
Printf("drawNCDImage\n");
#endif
PImageCanvas::DrawSelf(); // let the base class clear the drawing area
if (IsDirty()) {
TransformHits();
}
long bit_mask = HiddenHitMask(); // don't draw hidden tubes
num = data->numNcds;
float fr = mProj.xscl * kNcdTubeSize / kNcdRadius;
int r = (int)(fr + 0.5);
if (r < 1) r = 1;
float first, last;
PNCDHistogram::GetBins(data, &first, &last);
float range = last - first;
long ncols = data->num_cols - 2;
SetFont(PResourceManager::sResource.hist_font);
for (i=0; i<num; ++i) {
NCDMap *map = data->ncdMap + i;
int x = map->nodes[0].x;
int y = map->nodes[0].y;
NCDHit *nh = data->ncdHit + i;
if (!(nh->flags & ~bit_mask)) {
if (nh->flags) {
// use hidden colour for cut NCD hits
SetForeground(HID_COL);
} else {
SetForeground(FRAME_COL);
}
DrawArc(x,y,r,r);
} else {
float val = ncols * (getNcdHitVal(data, nh) - first) / range;
if (val < 0) {
val = -1;
} else if (val >= ncols) {
val = ncols;
}
SetForeground(FIRST_SCALE_COL + (int)val + 1);
FillArc(x,y,r,r);
}
SetForeground(TEXT_COL);
DrawString(x,y+r*4/3,map->label,kTextAlignTopCenter);
}
int y1 = NCD_MARGIN_TOP;
int x2 = mWidth - NCD_MARGIN_RIGHT;
char buff[256];
PNCDHistogram::GetHistogramLabel(data, buff);
SetForeground(TEXT_COL);
DrawString(x2+1,y1+NCD_LABEL_Y,buff,kTextAlignTopRight);
}
void PNCDImage::TransformHits()
{
ImageData *data = mOwner->GetData();
#ifdef PRINT_DRAWS
Printf(":transform NCD\n");
#endif
int num = data->numNcds;
int xscl = mProj.xscl;
int yscl = mProj.yscl;
int xcen = (int)(mProj.xcen - xscl * mProj.pt[0]);
int ycen = (int)(mProj.ycen + yscl * mProj.pt[1]);
for (int i=0; i<num; ++i) {
NCDMap *map = data->ncdMap + i;
int x = (int)(xcen + (map->x / kNcdRadius) * xscl + 0.5);
int y = (int)(ycen - (map->y / kNcdRadius) * yscl + 0.5);
map->nodes[0].x = map->nodes[1].x = x;
map->nodes[0].y = map->nodes[1].y = y;
}
PProjImage::TransformHits();
}