-
Notifications
You must be signed in to change notification settings - Fork 9
/
RtExternalSenderImageInfo.cpp
150 lines (140 loc) · 5.71 KB
/
RtExternalSenderImageInfo.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
/*=========================================================================
*
* Copyright 2007-2013, the MURFI dev team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include <RtExternalSenderImageInfo.h>
#include <math.h>
RtExternalImageInfo::RtExternalImageInfo() :
headerVersion(EXTERNALSENDER_VERSION),
isLittleEndian(false),
isMosaic(false),
pixelSpacingReadMM(0.0),
pixelSpacingPhaseMM(0.0),
pixelSpacingSliceMM(0.0),
sliceGapMM(0.0),
numPixelsRead(0),
numPixelsPhase(0),
numSlices(0),
repetitionTimeMS(0),
repetitionDelayMS(0),
currentTR(0),
totalTR(0),
isMotionCorrected(false),
mcTranslationXMM(0.0),
mcTranslationYMM(0.0),
mcTranslationZMM(0.0),
mcRotationXRAD(0.0),
mcRotationYRAD(0.0),
mcRotationZRAD(0.0) {
strcpy((char*) magic, EXTERNALSENDER_MAGIC);
seriesUID[0] = '\0';
scanType[0] = '\0';
imageType[0] = '\0';
note[0] = '\0';
dataType[0] = '\0';
// identity
memset(voxelToWorldMatrix, 0, sizeof(voxelToWorldMatrix));
for(int i = 0; i < 4; i++) {
voxelToWorldMatrix[i][i] = 1.;
}
mcOrder[0] = '\0';
}
// Dumps all fields to STDOUT
void RtExternalImageInfo::displayImageInfo() const {
cout << "-----------------------------" << endl;
cout << "Dumping RtExternalImageInfo " << endl;
cout << "Data:" << sizeof (RtExternalImageInfo) << " Bytes used" << endl;
cout << "-----------------------------" << endl;
cout << "Functor Code / Header Version: "
<< magic << " / " << headerVersion << endl
<< "seriesUID: "
<< seriesUID << endl
<< "scanType: "
<< scanType << endl
<< "imageType / isMosaic: "
<< imageType << " / " << isMosaic << endl
<< "dataType / isLittleEndian: "
<< dataType << " / " << isLittleEndian << endl
<< "note: "
<< note << endl
<< "numPixels[Read / Phase / Slice]: "
<< numPixelsRead << " / " << numPixelsPhase << " / " << numSlices << endl
<< "pixelSpacing[Read / Phase]: "
<< pixelSpacingReadMM << " / " << pixelSpacingPhaseMM << endl
<< "Slice [Thickness / Gap]: "
<< pixelSpacingSliceMM << " / " << sliceGapMM << endl
<< "isMotionCorrected / mcOrder: "
<< isMotionCorrected << " / " << mcOrder << endl
<< "mcTranslation[X / Y / Z]: "
<< mcTranslationXMM << " / " << mcTranslationYMM << " / "
<< mcTranslationZMM << endl
<< "mcRotationMM[X / Y / Z]: "
<< mcRotationXRAD << " / " << mcRotationYRAD << " / "
<< mcRotationZRAD << endl
<< "repetitionTimeMS / repetitionDelayMS "
<< repetitionTimeMS << " / " << repetitionDelayMS << endl
<< "currentTR / totalTR "
<< currentTR << " / " << totalTR << endl
<< "voxelToWorldMatrix "
<< voxelToWorldMatrix[0][0] << " " << voxelToWorldMatrix[0][1] << " "
<< voxelToWorldMatrix[0][2] << " " << voxelToWorldMatrix[0][3] << endl
<< " "
<< voxelToWorldMatrix[1][0] << " " << voxelToWorldMatrix[1][1] << " "
<< voxelToWorldMatrix[1][2] << " " << voxelToWorldMatrix[1][3] << endl
<< " "
<< voxelToWorldMatrix[2][0] << " " << voxelToWorldMatrix[2][1] << " "
<< voxelToWorldMatrix[2][2] << " " << voxelToWorldMatrix[2][3] << endl
<< " "
<< voxelToWorldMatrix[3][0] << " " << voxelToWorldMatrix[3][1] << " "
<< voxelToWorldMatrix[3][2] << " " << voxelToWorldMatrix[3][3] << endl;
}
// Returns the size (in bytes) of the header
size_t RtExternalImageInfo::getHeaderSize() {
return sizeof(RtExternalImageInfo);
}
// Returns the size (in bytes) per pixel, specified by dataType
int32_t RtExternalImageInfo::getBytesPerPix() const {
if (!strcmp(dataType, "int16_t")) {
return sizeof(int16_t);
} else {
cout << "WARNING! Header indicates that an unsupported dataType ("
<< dataType << "} was received. Assuming int16_t" << endl;
return sizeof(int16_t);
}
}
// Returns the size (in bytes) of the data blob
int32_t RtExternalImageInfo::getDataSize() const {
return getBytesPerPix()*getNumVoxels();
}
// Returns the size (in voxels) of the data blob
int32_t RtExternalImageInfo::getNumVoxels() const {
if (isMosaic)
// If it's mosaiced then the number of voxels in the data blob
// is potentially larger than the number of voxels in the volume.
// Example: a 72x72x31 volume has 160704 voxels, but creates a 6x6
// (ceil(sqrt(numSlices))) mosaic, and therefore sends 72x72x36 = 186624
// voxels
return (int32_t) numPixelsRead*numPixelsPhase*pow(getMosaicSize(),2);
else
return (int32_t) numPixelsRead*numPixelsPhase*numSlices;
}
// Returns mosaic grid size (in mosaic cells)
int32_t RtExternalImageInfo::getMosaicSize() const {
if (isMosaic)
return (int32_t) ceil(sqrt((double)numSlices));
else
return 1;
}