-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathResidualsImagesDrawing.cpp
More file actions
423 lines (344 loc) · 11.1 KB
/
Copy pathResidualsImagesDrawing.cpp
File metadata and controls
423 lines (344 loc) · 11.1 KB
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
/*
This file is part of RMAExpress.
RMAExpress is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
RMAExpress is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RMAExpress; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**************************************************************************
**
** File: ResidualsImagesDrawing.cpp
**
** Copyright (C) B. M. Bolstad 2004-2008
**
** Aim: Separates out the drawing components from the dialog componenets.
**
** Code in this file was originally in residualsimages.cpp
**
** History
** Sep 30, 2005 - created as individual file
** Oct 1, 2005 - added functionality for drawing to an wxImage for the console application
** - change some preprocessor directives
**
** History of residualsimages.cpp - Created Jan 20, 2004
** Feb 28, 2004 - added radiobox for selecting, both, positive or negative residuals
** and altered drawing routine to draw them.
**
** Feb 29, 2004 - fixed save buttons.
**
** Jul 11, 2005 - added sign of residuals, fixed colors which were around wrong way (why no one noticed until now is somewhat of a mystery).m
**
** Oct 29, 2005 - make sure that empty regions on signs images are white now.
**
** Jan 30, 2006 - Add additional functionality for only redrawing part of the image
** Sep 16, 2006 - fix compile problems on unicode builds of wxWidgets
** Feb 28, 2008 - BufferedMatrix indexing is now via() operator rather than []
**
***************************************************************************/
#include "ResidualsImagesDrawing.h"
#include "ResidualsDataGroup.h"
#include <wx/image.h>
unsigned char getBlue(double x){
if (x > 2.0){
return 0;
} else if (x <= 0.05){
return 255;
} else {
return (unsigned char)(255 - x/2.5*255);
}
}
unsigned char getRed(double x){
if (x < -2.0){
return 0;
} else if (x >= -0.05){
return 255;
} else {
return (unsigned char)(255 - x/-2.5*255);
}
}
unsigned char getGreen(double x){
if (x > 0){
return getBlue(x);
} else {
return getRed(x);
}
}
#if RMA_GUI_APP
void drawPseudoChipImage(wxDC *dc,wxString name, wxString type, ResidualsDataGroup *resids){
#ifndef BUFFERED
Matrix *thedata;
#else
BufferedMatrix *thedata;
#endif
unsigned char red,green,blue;
int whichchip;
if (name.Cmp(_T(""))==0){
return;
}
dc->DrawText( name, 20, 5);
dc->SetPen( *wxBLACK_PEN );
dc->DrawRectangle(19,19,resids->ncols()+2,resids->nrows()+2);
thedata = resids->GetIntensities();
whichchip = (resids->GetArrayNames()).Index(name);
// Note the flip for orientation purposes
if (type.Cmp(_T("Positive")) == 0){
for (int i =0; i < resids->nrows(); i++){
for (int j=0; j < resids->ncols(); j++){
if ((*thedata)(i*resids->ncols() + j,whichchip) > 0){
red = getRed((*thedata)(i*resids->ncols() + j,whichchip));
blue = getBlue((*thedata)(i*resids->ncols() + j,whichchip));
green =getGreen((*thedata)(i*resids->ncols() + j,whichchip));
} else {
red = 255;
blue = 255;
green = 255;
}
dc->SetPen(wxPen(wxColor(red,green,blue) ,1,wxSOLID));
dc->DrawPoint(20+j,20+i);
}
}
} else if (type.Cmp(_T("Negative")) ==0){
for (int i =0; i < resids->nrows(); i++){
for (int j=0; j < resids->ncols(); j++){
if ((*thedata)(i*resids->ncols() + j,whichchip) < 0){
red = getRed((*thedata)(i*resids->ncols() + j,whichchip));
blue = getBlue((*thedata)(i*resids->ncols() + j,whichchip));
green = getGreen((*thedata)(i*resids->ncols() + j,whichchip));
} else {
red = 255;
blue = 255;
green = 255;
}
dc->SetPen(wxPen(wxColor(red,green,blue) ,1,wxSOLID));
dc->DrawPoint(20+j,20+i);
}
}
} else if (type.Cmp(_T("Sign")) ==0){
for (int i =0; i < resids->nrows(); i++){
for (int j=0; j < resids->ncols(); j++){
if ((*thedata)(i*resids->ncols() + j,whichchip) > 0){
red = 255;
blue = 0;
green = 0;
} else if ((*thedata)(i*resids->ncols() + j,whichchip) < 0) {
red = 0;
blue = 255;
green = 0;
} else {
red = 255;
blue = 255;
green = 255;
}
dc->SetPen(wxPen(wxColor(red,green,blue) ,1,wxSOLID));
dc->DrawPoint(20+j,20+i);
}
}
} else {
for (int i =0; i < resids->nrows(); i++){
for (int j=0; j < resids->ncols(); j++){
red = getRed((*thedata)(i*resids->ncols() + j,whichchip));
blue = getBlue((*thedata)(i*resids->ncols() + j,whichchip));
green = getGreen((*thedata)(i*resids->ncols() + j,whichchip));
dc->SetPen(wxPen(wxColor(red,green,blue) ,1,wxSOLID));
dc->DrawPoint(20+j,20+i);
}
}
}
}
// Draws only a partial region (for redrawing only what should be visible)
void drawPseudoChipImage(wxDC *dc,wxString name, wxString type, ResidualsDataGroup *resids,int startx, int starty, int width, int height){
#ifndef BUFFERED
Matrix *thedata;
#else
BufferedMatrix *thedata;
#endif
unsigned char red,green,blue;
int whichchip;
int wherestartx, wherestarty;
int wherestopx, wherestopy;
if (name.Cmp(_T(""))==0){
return;
}
// will title and rebox every time (even if not visible)
dc->DrawText( name, 20, 5);
dc->SetPen( *wxBLACK_PEN );
dc->DrawRectangle(19,19,resids->ncols()+2,resids->nrows()+2);
thedata = resids->GetIntensities();
// Check which chip we are drawing residuals image for
whichchip = (resids->GetArrayNames()).Index(name);
if (startx < 20){
wherestartx = 0;
} else {
wherestartx = startx-20;
}
if (starty < 20){
wherestarty = 0;
} else {
wherestarty = starty-20;
}
if (startx+height > resids->nrows()){
wherestopx = resids->nrows();
} else {
wherestopx = startx+height-20;
}
if (starty+width > resids->ncols()){
wherestopy = resids->ncols();
} else {
wherestopy = starty+width-20;
}
// Note the flip for orientation purposes
for (int i =(wherestartx); i < wherestopx; i++){
for (int j=(wherestarty); j < wherestopy; j++){
if (type.Cmp(_T("Positive")) == 0){
if ((*thedata)(i*resids->ncols() + j,whichchip) > 0){
red = getRed((*thedata)(i*resids->ncols() + j,whichchip));
blue = getBlue((*thedata)(i*resids->ncols() + j,whichchip));
green =getGreen((*thedata)(i*resids->ncols() + j,whichchip));
} else {
red = 255;
blue = 255;
green = 255;
}
} else if (type.Cmp(_T("Negative")) ==0){
if ((*thedata)(i*resids->ncols() + j,whichchip) < 0){
red = getRed((*thedata)(i*resids->ncols() + j,whichchip));
blue = getBlue((*thedata)(i*resids->ncols() + j,whichchip));
green = getGreen((*thedata)(i*resids->ncols() + j,whichchip));
} else {
red = 255;
blue = 255;
green = 255;
}
} else if (type.Cmp(_T("Sign")) ==0){
if ((*thedata)(i*resids->ncols() + j,whichchip) > 0){
red = 255;
blue = 0;
green = 0;
} else if ((*thedata)(i*resids->ncols() + j,whichchip) < 0){
red = 0;
blue = 255;
green = 0;
} else {
red = 255;
blue = 255;
green = 255;
}
} else {
red = getRed((*thedata)(i*resids->ncols() + j,whichchip));
blue = getBlue((*thedata)(i*resids->ncols() + j,whichchip));
green = getGreen((*thedata)(i*resids->ncols() + j,whichchip));
}
dc->SetPen(wxPen(wxColor(red,green,blue) ,1,wxSOLID));
dc->DrawPoint(20+j,20+i);
}
}
}
void annotatePseudoChipImage(wxDC *dc,wxString name, ResidualsDataGroup *resids){
if (name.Cmp(_T(""))==0){
return;
}
dc->DrawText( name, 20, 5);
dc->SetPen( *wxBLACK_PEN );
dc->SetBrush( *wxTRANSPARENT_BRUSH);
dc->DrawRectangle(19,19,resids->ncols()+2,resids->nrows()+2);
}
#endif
#include <wx/image.h>
void drawPseudoChipImage( wxImage *Image, wxString name, wxString type, ResidualsDataGroup *resids){
#ifndef BUFFERED
Matrix *thedata;
#else
BufferedMatrix *thedata;
#endif
int whichchip;
unsigned char red,green,blue;
int offset = 20; // note the 20/40 in here is a hard coded constant
if (name.Cmp(_T(""))==0){
return;
}
wxImage subimage;
unsigned char *imagedata;
whichchip = (resids->GetArrayNames()).Index(name);
// whichchip = whichchip*(resids->ncols()*resids->nrows());
thedata = resids->GetIntensities();
imagedata = Image->GetData();
// Initial band of white
for (int i =0; i < 3*20 + (20-1)*3*((resids->ncols())+40) - 3; i++){
imagedata[i] = 255;
}
// short strip after top line but before text
offset=3*20 + 20*3*(resids->ncols()+40);
for (int i =offset-4; i >= offset-3*39; i--){
imagedata[i] = 255;
}
// Note the flip for orientation purposes
for (int i =0; i < resids->nrows(); i++){
for (int j=0; j < resids->ncols(); j++){
if (type.Cmp(_T("Positive")) == 0){
if ((*thedata)(i*resids->ncols() + j,whichchip) > 0){
red = getRed((*thedata)(i*resids->ncols() + j,whichchip));
blue = getBlue((*thedata)(i*resids->ncols() + j,whichchip));
green =getGreen((*thedata)(i*resids->ncols() + j,whichchip));
} else {
red = 255;
blue = 255;
green = 255;
}
} else if (type.Cmp(_T("Negative")) ==0){
if ((*thedata)(i*resids->ncols() + j,whichchip) < 0){
red = getRed((*thedata)(i*resids->ncols() + j,whichchip));
blue = getBlue((*thedata)(i*resids->ncols() + j,whichchip));
green = getGreen((*thedata)(i*resids->ncols() + j,whichchip));
} else {
red = 255;
blue = 255;
green = 255;
}
} else if (type.Cmp(_T("Sign")) ==0){
if ((*thedata)(i*resids->ncols() + j,whichchip) > 0){
red = 255;
blue = 0;
green = 0;
} else if ((*thedata)(i*resids->ncols() + j,whichchip) < 0){
red = 0;
blue = 255;
green = 0;
} else {
red = 255;
blue = 255;
green = 255;
}
} else {
red = getRed((*thedata)(i*resids->ncols() + j,whichchip));
blue = getBlue((*thedata)(i*resids->ncols() + j,whichchip));
green = getGreen((*thedata)(i*resids->ncols() + j,whichchip));
}
// dc->SetPen(wxPen(wxColor(red,green,blue) ,1,wxSOLID));
//dc->DrawPoint(20+j,20+i);
imagedata[offset] = red;
imagedata[offset + 1] = green;
imagedata[offset + 2] = blue;
/* imagedata[i*(3*resids->ncols()) + 3*j ] = red;
imagedata[i*(3*resids->ncols()) + 3*j + 1 ] = green;
imagedata[i*(3*resids->ncols()) + 3*j + 2 ] = blue; */
offset+=3;
}
// leave jsut enough room for borders
for (int k=offset+3; k < offset+ 3*40-3;k++){
imagedata[k] = 255;
}
offset+= 3*40;
}
// Empty white area at end of image
offset+=3*((resids->ncols()));
for (int i =offset+3; i < offset+3*20 + (20-1)*3*((resids->ncols())+40); i++){
imagedata[i] = 255;
}
}