-
Notifications
You must be signed in to change notification settings - Fork 1
/
IntensityDlg.cpp
executable file
·451 lines (395 loc) · 14.6 KB
/
IntensityDlg.cpp
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
#include "stdafx.h"
#include "OCT.h"
#include "IntensityDlg.h"
#include "OCTDlg.h"
#include "ImageWnd.h"
#include "Defines.h"
#include "niimaq.h"
#include <iostream>
#include <fstream>
#include <tiffio.h>
#include "ExternVariables.h"
#include "intensitydlg.h"
#include ".\intensitydlg.h"
using namespace std;
//extern UINT DisplayIntensityThreadProc(LPVOID);
IMPLEMENT_DYNAMIC(CIntensityDlg, CDialog)
CIntensityDlg::CIntensityDlg()
{
//initialize all the data
m_pIntensityImgWnd = NULL;
bDisplayIntensity = FALSE;
}
CIntensityDlg::~CIntensityDlg()
{
delete m_pIntensityImgWnd;
m_pIntensityImgWnd = NULL;
}
BEGIN_MESSAGE_MAP(CIntensityDlg, CDialog)
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_START_INTENSITY, OnBnClickedStartIntensity)
ON_BN_CLICKED(IDC_PAUSE_INTENSITY, OnBnClickedPauseIntensity)
ON_BN_CLICKED(IDC_SAVE_INTENSITY, OnBnClickedSaveIntensity)
ON_BN_CLICKED(IDC_AOI, OnBnClickedCheckBox)
ON_BN_CLICKED(IDC_ZOOM, OnBnClickedZoom)
ON_BN_CLICKED(IDC_LOAD_INTENSITY, OnBnClickedLoadIntensity)
ON_BN_CLICKED(IDC_LOG, OnBnClickedCheckBox)
ON_BN_CLICKED(IDC_HOT_COLOR, OnBnClickedHotColor)
ON_BN_CLICKED(IDC_AUTOSAVE, OnBnClickedCheckBox)
ON_NOTIFY(UDN_DELTAPOS, IDC_FILE_SPIN, OnDeltaposFileSpin)
ON_BN_CLICKED(IDC_RECON_INTENSITY, OnBnClickedReconIntensity)
ON_BN_CLICKED(IDC_EXPAND, OnBnClickedCheckBox)
ON_BN_CLICKED(IDC_REPLAY, OnBnClickedReplay)
ON_BN_CLICKED(IDC_SNAP, OnBnClickedSnap)
END_MESSAGE_MAP()
void CIntensityDlg::DoDataExchange(CDataExchange* pDX)
{
DDX_Text(pDX, IDC_INTENSITY, intensity);
DDX_Text(pDX, IDC_VOLTAGEX, voltageX);
DDX_Text(pDX, IDC_VOLTAGEY, voltageY);
DDX_Text(pDX, IDC_DEPTH, depth);
DDX_Check(pDX, IDC_AOI, bAOIEn);
DDX_Check(pDX,IDC_LOG, bLog);
DDX_Check(pDX, IDC_ZOOM, bZoom);
DDX_Check(pDX, IDC_EXPAND, bExpand);
DDX_Check(pDX, IDC_AUTOSAVE, bAutosave);
DDX_Slider(pDX, IDC_INTENSITY_GAIN, m_iIntensityGain);
DDX_Slider(pDX, IDC_INTENSITY_OFFSET, OffSet);
DDX_Text(pDX, IDC_FILE_INDEX, nIndex);
DDX_Check(pDX, IDC_HOT_COLOR, bHotColor);
DDX_Control(pDX, IDC_FILE_SPIN, m_FileSpin);
CDialog::DoDataExchange(pDX);
}
void CIntensityDlg::OnCancel()
{
COCTDlg::bIntensityDlgEn = FALSE;
theApp.TerminateDisplayIntensityThread();
delete m_pIntensityImgWnd;
m_pIntensityImgWnd=NULL;
DestroyWindow();
}
void CIntensityDlg::OnOK()
{
UpdateData();
nIndex=nIndex>strPathNameArray.GetSize() ? strPathNameArray.GetSize(): nIndex;
m_FileSpin.SetPos(nIndex);
UpdateData(FALSE);
OnDeltaposFileSpin(NULL, NULL);
}
BOOL CIntensityDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if (bZoom)
SetWindowPos(&wndTop,INTENSITY_DLG_POS_BIG,NULL);
else
SetWindowPos(&wndTop,INTENSITY_DLG_POS_SMALL,NULL);
//reset the position of the dialog and initialize Controllers
RECT rect;
rect.left=100;
rect.right=613+512*bZoom;
rect.top = 2;
rect.bottom=505+500*bZoom;
m_pIntensityImgWnd = new CImageWnd;
m_pIntensityImgWnd->Create(NULL,"Intensity Image",WS_BORDER | WS_VISIBLE | CS_HREDRAW | CS_VREDRAW,
rect,this,ID_INTENSITY_IMAGE_WINDOW,NULL) ;
m_iIntensityGain = 50;
UpdateData(FALSE);
IntensityGain = (float) m_iIntensityGain*GAINFACTOR/SPECTRUMWIDTH/IterationNum;
return TRUE;
}
void CIntensityDlg::OnBnClickedStartIntensity()
{
theApp.StartDisplayIntensityThread();
GetDlgItem(IDC_START_INTENSITY)->EnableWindow(FALSE);
GetDlgItem(IDC_START_INTENSITY)->ShowWindow(FALSE);
GetDlgItem(IDC_PAUSE_INTENSITY)->ShowWindow(TRUE);
GetDlgItem(IDC_PAUSE_INTENSITY)->EnableWindow(TRUE);
GetDlgItem(IDC_FILE_SPIN)->EnableWindow(FALSE);
GetDlgItem(IDC_FILE_INDEX)->EnableWindow(FALSE);
//GetDlgItem(IDC_AOI)->EnableWindow();
}
void CIntensityDlg::OnBnClickedPauseIntensity()
{
theApp.PauseDisplayIntensityThread();
GetDlgItem(IDC_PAUSE_INTENSITY)->EnableWindow(FALSE);
GetDlgItem(IDC_PAUSE_INTENSITY)->ShowWindow(FALSE);
GetDlgItem(IDC_START_INTENSITY)->ShowWindow(TRUE);
GetDlgItem(IDC_START_INTENSITY)->EnableWindow(TRUE);
}
void CIntensityDlg::OnBnClickedSaveIntensity()
{
//save the status of threads for resuming.
BOOL bDisplayIntensityWasRunning=bDisplayIntensity;
OnBnClickedPauseIntensity();
TIFF *image;
char szFilter[] = " RAW Data (*.RAW)|*.RAW| TIFF Image (*.TIF)|*.TIF||";
CFileDialog fileDlg(FALSE, "TIF.RAW", NULL, OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT , szFilter, NULL);
int nResponse = fileDlg.DoModal();
if(nResponse == IDOK)
{
//save Raw Data or reconstructed Image data Depend on the File extension name.
CString strPathName = fileDlg.GetPathName();
if (strPathName.Right(3)== "TIF") {
image = TIFFOpen(strPathName, "w");
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, IMAGEWIDTH );
TIFFSetField(image, TIFFTAG_IMAGELENGTH, IMAGEHEIGHT);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, IMAGEHEIGHT);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(image, TIFFTAG_COMPRESSION, 1);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFWriteEncodedStrip(image, 0, IntensityImage, IMAGESIZE);
TIFFClose(image);
}
//save the raw data
else {
BOOL bCaliWasRunning=bCali;
theApp.PauseCaliThread();
image = TIFFOpen(strPathName, "w");
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, SPECTRUMWIDTH );
TIFFSetField(image, TIFFTAG_IMAGELENGTH, ALineNum*IterationNum);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 16);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, IterationNum);
TIFFSetField(image, TIFFTAG_COMPRESSION, 1);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
//write the images
int imageOffset = 0;
int stripSize = IterationNum * SPECTRUMWIDTH*2;
for ( int stripCount = 0; stripCount < ALineNum; stripCount++ )
imageOffset+=TIFFWriteEncodedStrip(image, stripCount,CaliBuff + imageOffset, stripSize)/2;
// '/2' is because bits per sample is 16 = 2 bytes.
TIFFClose(image);
if (bCaliWasRunning)
theApp.StartCaliThread();
}
}
if (bDisplayIntensityWasRunning)
OnBnClickedStartIntensity();
}
void CIntensityDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
UpdateData(TRUE);
IntensityGain = (float)m_iIntensityGain*GAINFACTOR/SPECTRUMWIDTH/IterationNum;
SetEvent(IntensityBuffNew);
if (!bDisplayIntensity)
theApp.StartDisplayIntensityThread();
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CIntensityDlg::OnBnClickedCheckBox()
{
UpdateData(TRUE);
}
void CIntensityDlg::OnBnClickedHotColor()
{
UpdateData(TRUE);
if (bHotColor)
imgPlot ((GUIHNDL)(m_pIntensityImgWnd->GetSafeHwnd()), IntensityImageRGB, 0 , 0, IMAGEWIDTH,IMAGEHEIGHT, 0,0, IMGPLOT_COLOR_RGB32);
else
imgPlot ((GUIHNDL)(m_pIntensityImgWnd->GetSafeHwnd()), IntensityImage, 0 , 0, IMAGEWIDTH,IMAGEHEIGHT, 0,0, IMGPLOT_MONO_8);
}
void CIntensityDlg::OnBnClickedLoadIntensity()
{
OnBnClickedPauseIntensity();
char szFilter[] = " TIFF Image (*.TIF)|*.TIF||";
CFileDialog fileDlg(TRUE, "TIF", NULL, OFN_EXPLORER | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilter, NULL);
char FileNameBuff[2000];
memset(FileNameBuff,0,2000);
fileDlg.m_ofn.lpstrFile=FileNameBuff;
fileDlg.m_ofn.nMaxFile=2000;
int nResponse = fileDlg.DoModal();
POSITION pos =fileDlg.GetStartPosition();
if (NULL==pos) return;
if(nResponse == IDOK) {
strPathNameArray.RemoveAll();
while (pos)
strPathNameArray.Add(fileDlg.GetNextPathName(pos));
if (strPathNameArray.IsEmpty()) return;
//set the range of spin controller;
m_FileSpin.SetRange(1, strPathNameArray.GetSize());
GetDlgItem(IDC_FILE_SPIN)->EnableWindow();
GetDlgItem(IDC_FILE_INDEX)->EnableWindow();
nIndex=1;
m_FileSpin.SetPos(nIndex);
UpdateData(FALSE);
pMainDlg->OnBnClickedPauseImaq();
theApp.TerminateDisplayIntensityThread();
GetDlgItem(IDC_START_INTENSITY)->EnableWindow();
LoadTiffImage();
}
}
void CIntensityDlg::OnBnClickedReconIntensity()
{
OnBnClickedPauseIntensity();
char szFilter[] = " RAW Data (*.RAW)|*.RAW||";
CFileDialog fileDlg(TRUE, "RAW", NULL, OFN_EXPLORER | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilter, NULL);
char FileNameBuff[2000];
memset(FileNameBuff,0,2000);
fileDlg.m_ofn.lpstrFile=FileNameBuff;
fileDlg.m_ofn.nMaxFile=2000;
int nResponse = fileDlg.DoModal();
POSITION pos =fileDlg.GetStartPosition();
if (NULL==pos) return;
if(nResponse == IDOK) {
strPathNameArray.RemoveAll();
while (pos)
strPathNameArray.Add(fileDlg.GetNextPathName(pos));
if (strPathNameArray.IsEmpty()) return;
//set the range of spin controller;
m_FileSpin.SetRange(1, strPathNameArray.GetSize());
GetDlgItem(IDC_FILE_SPIN)->EnableWindow();
GetDlgItem(IDC_FILE_INDEX)->EnableWindow();
nIndex=1;
m_FileSpin.SetPos(nIndex);
//theApp.TerminateSDOCTThreads();
pMainDlg->OnBnClickedPauseImaq();
//bReconstruction = TRUE;
theApp.StartCaliThread();
theApp.StartFFTThread();
theApp.StartDisplayIntensityThread();
}
}
void CIntensityDlg::OnDeltaposFileSpin(NMHDR *pNMHDR, LRESULT *pResult)
{
if (pNMHDR) {
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
m_FileSpin.SetPos(pNMUpDown->iPos);
nIndex=pNMUpDown->iPos;
UpdateData(FALSE);
}
if ((strPathNameArray[nIndex-1]).Right(3)== "TIF")
LoadTiffImage();
else
LoadRawImage();
}
void CIntensityDlg::OnBnClickedReplay()
{
int nIndexMax=strPathNameArray.GetSize();
char FileIndex[4];
for ( nIndex=0; nIndex<nIndexMax; ) {
nIndex++;
m_FileSpin.SetPos(nIndex);
UpdateData(FALSE);
if ((strPathNameArray[nIndex-1]).Right(3)== "TIF")
LoadTiffImage();
else
LoadRawImage();
}
}
void CIntensityDlg::LoadTiffImage()
{
TIFF *image;
image = TIFFOpen(strPathNameArray[nIndex-1], "r");
int stripSize = TIFFStripSize (image);
int stripMax = TIFFNumberOfStrips (image);
int imageOffset = 0;
for (int stripCount = 0; stripCount < stripMax; stripCount++)
imageOffset+=TIFFReadEncodedStrip (image, stripCount,IntensityImage + imageOffset ,stripSize);
TIFFClose(image);
//HotColor display .
for (int i = 0; i<ALineNum;i++){
for (int j = UpDepthIndex; j<= DownDepthIndex; j++){
*(IntensityImageRGB+(i + LeftLateralIndex)*IMAGEWIDTH+j) = HotColorTable[*(IntensityImage+(i + LeftLateralIndex)*IMAGEWIDTH+j)];
}
}
if (!bZoom) {
for (int i = 0; i<ALineNum ;i=i+2){
for (int j = UpDepthIndex; j<= DownDepthIndex; j=j+2){
*(IntensitySmallImage+(i + LeftLateralIndex)/2*IMAGEHALFWIDTH+j/2) = *(IntensityImage+(i + LeftLateralIndex)*IMAGEWIDTH+j);
//if hot color enabled, get the image array for hot color
if (bHotColor)
*(IntensitySmallImageRGB+(i + LeftLateralIndex)/2*IMAGEHALFWIDTH+j/2) = *(IntensityImageRGB+(i + LeftLateralIndex)*IMAGEWIDTH+j);
}
}
}
//if DrawCurve thread is running and IntensityCurveData is needed for display intensity Curve along ALine
if (bDrawCurve || bAxialIntensity)
memcpy(IntensityCurveData, IntensityImage+(AxialLine_i+LeftLateralIndex)*IMAGEWIDTH, IMAGEWIDTH);
if ( bHotColor ){
if (bZoom)
imgPlot((GUIHNDL)(m_pIntensityImgWnd->GetSafeHwnd()), IntensityImageRGB, 0 , 0, IMAGEWIDTH,IMAGEHEIGHT, 0,0, IMGPLOT_COLOR_RGB32);
else
imgPlot((GUIHNDL)(m_pIntensityImgWnd->GetSafeHwnd()), IntensitySmallImageRGB, 0 , 0, IMAGEHALFWIDTH,IMAGEHALFHEIGHT , 0,0, IMGPLOT_COLOR_RGB32);
}
else {
if (bZoom)
imgPlot((GUIHNDL)(m_pIntensityImgWnd->GetSafeHwnd()), IntensityImage, 0 , 0, IMAGEWIDTH,IMAGEHEIGHT, 0,0, IMGPLOT_MONO_8);
else
imgPlot((GUIHNDL)(m_pIntensityImgWnd->GetSafeHwnd()), IntensitySmallImage, 0 , 0, IMAGEHALFWIDTH,IMAGEHALFHEIGHT, 0,0, IMGPLOT_MONO_8);
}
}
void CIntensityDlg::LoadRawImage()
{
TIFF *image;
image = TIFFOpen(strPathNameArray[nIndex-1], "r");
//read scan and acquisition information from the images
int stripSize = TIFFStripSize(image);
int stripMax = TIFFNumberOfStrips(image);
pMainDlg->m_ALineNum=stripMax;
pMainDlg->m_IterationNum=stripSize/SPECTRUMWIDTH/2;
pMainDlg->UpdateData(FALSE);
if (ALineNum!= pMainDlg->m_ALineNum || IterationNum!= pMainDlg->m_IterationNum)
pMainDlg->ReconfigureScan();
if (bCali){
WaitForSingleObject(CaliBuffEmpty,INFINITE);
int imageOffset = 0;
for ( int stripCount = 0; stripCount < stripMax; stripCount++ )
imageOffset+=TIFFReadEncodedStrip(image, stripCount,CaliBuff+imageOffset ,stripSize)/2;
// '/2' is because bits per sample is 16 = 2 bytes.
TIFFClose(image);
SetEvent(CaliBuffNew);
}
}
void CIntensityDlg::OnBnClickedZoom()
{
UpdateData(TRUE);
if (pMainDlg->bPhaseDlgEn)
pMainDlg->m_pPhaseDlg->ResizeWindow();
ResizeWindow();
}
void CIntensityDlg::ResizeWindow()
{
if (bZoom) {
SetWindowPos(&wndTop,INTENSITY_DLG_POS_BIG,NULL);
m_pIntensityImgWnd->SetWindowPos(&wndTop,IMAGE_WND_POS_BIG,NULL);
}
else {
SetWindowPos(&wndTop,INTENSITY_DLG_POS_SMALL,NULL);
m_pIntensityImgWnd->SetWindowPos(&wndTop,IMAGE_WND_POS_SMALL,NULL);
}
}
void CIntensityDlg::OnBnClickedSnap()
{
//save the status of threads for resuming.
BOOL bDisplayIntensityWasRunning=bDisplayIntensity;
OnBnClickedPauseIntensity();
BOOL bCaliWasRunning=bCali;
theApp.PauseCaliThread();
//save Raw Data or reconstructed Image data Depend on the File extension name.
CTime currentTime=CTime::GetCurrentTime();
CString strTime=currentTime.Format("%H_%M_%S");
//save the Calibrated data
TIFF *image;
image = TIFFOpen(DefaultFilePath+strTime+".RAW", "w");//what is the path name???
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, SPECTRUMWIDTH );
TIFFSetField(image, TIFFTAG_IMAGELENGTH, ALineNum*IterationNum);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 16);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, IterationNum);
TIFFSetField(image, TIFFTAG_COMPRESSION, 1);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
//write the images
int imageOffset = 0;
int32 stripSize = IterationNum * SPECTRUMWIDTH*2;
for ( int stripCount = 0; stripCount < ALineNum; stripCount++ )
imageOffset+=TIFFWriteEncodedStrip(image, stripCount, CaliBuff + imageOffset, stripSize)/2;
// '/2' is because bits per sample is 16 = 2 bytes.
TIFFClose(image);
if (bCaliWasRunning)
theApp.StartCaliThread();
if (bDisplayIntensityWasRunning)
OnBnClickedStartIntensity();
}