-
Notifications
You must be signed in to change notification settings - Fork 0
/
DTImage.cpp
96 lines (85 loc) · 1.62 KB
/
DTImage.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
#include "DTImage.h"
#include <ifstream>
DTImage::DTImage(void)
{
_rawImage = NULL;
_bTable = NULL;
_sizeX = _sizeY = _sizeZ = 0;
}
DTImage::~DTImage(void)
{
}
DTImage::DTImage(QString rawFileName)
{
_rawImage = NULL;
_bTable = NULL;
_sizeX = _sizeY = _sizeZ = 0;
if (!readRawImage(rawFileName) || !readBTable(rawFileName))
{
delete _rawImage;
delete _bTable;
_rawImage = NULL;
_bTable = NULL;
_sizeX = _sizeY = _sizeZ = 0;
_bInitialized = false;
}
_bInitialized = true;
}
int DTImage::readRawImage(QString fileName)
{
_rawImage = nifti_image_read(fileName.toStdString().c_str(), 1);
if (!_rawImage)
{
QMessageBox msg;
msg.setText("Cannot open selected file!");
msg.exec();
return 0;
}
_sizeX = _rawImage->dim[1];
_sizeY = _rawImage->dim[2];
_sizeZ = _rawImage->dim[3];
return 1;
}
int DTImage::readBTable(QString fileName)
{
if (!_rawImage)
{
return 0;
}
int acqCount = _rawImage->dim[3];
_bTable = new float [4*acqCount];
float val;
fileName.replace(QRegExp("\.nii$"), ".bvec");
ifstream bvecFile;
bvecFile.open(fileName.toStdString().c_str());
if (!bvecFile)
{
QMessageBox msg;
msg.setText("Cannot open b-vec file!");
msg.exec();
return 0;
}
for (int i=0; i<3*acqCount;++i)
{
bvecFile >>val;
_bTable[(i/3)*4+i%3] = val;
}
bvecFile.close();
fileName.replace(QRegExp("\.bvec$"), ".bval");
ifstream bvalFile;
bvalFile.open(fileName.toStdString().c_str());
if (!bvalFile)
{
QMessageBox msg;
msg.setText("Cannot open b-val file!");
msg.exec();
return 0;
}
for (int i=0; i<acqCount;++i)
{
bvalFile >>val;
_bTable[i*4] = val;
}
bvalFile.close();
return 1;
}