14 #include <QTextStream>
15 #include <QStringList>
30 if(modalityString.contains(enum2string<IMAGE_MODALITY>(
imUNKNOWN), Qt::CaseInsensitive))
32 else if(modalityString.contains(enum2string<IMAGE_MODALITY>(
imCT), Qt::CaseInsensitive))
34 else if(modalityString.contains(enum2string<IMAGE_MODALITY>(
imMR), Qt::CaseInsensitive))
36 else if(modalityString.contains(enum2string<IMAGE_MODALITY>(
imUS), Qt::CaseInsensitive))
38 else if(modalityString.contains(enum2string<IMAGE_MODALITY>(
imPET), Qt::CaseInsensitive))
40 else if(modalityString.contains(enum2string<IMAGE_MODALITY>(
imSC), Qt::CaseInsensitive))
43 CX_LOG_WARNING() <<
"convertToModality - Cannot convert the string \"" << modalityString <<
"\" to a known image modality";
53 if (imageTypeSubString.isEmpty() || imageTypeSubString ==
" ")
55 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istUNKNOWN), Qt::CaseInsensitive))
57 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istMRT1), Qt::CaseInsensitive))
59 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istMRT2), Qt::CaseInsensitive))
61 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istMRFLAIR), Qt::CaseInsensitive))
63 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istANGIO), Qt::CaseInsensitive))
65 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istUSBMODE), Qt::CaseInsensitive))
67 else if(imageTypeSubString.contains(
"bmode", Qt::CaseInsensitive))
69 else if(imageTypeSubString.contains(
"b_mode", Qt::CaseInsensitive))
71 else if(imageTypeSubString.contains(
"b mode", Qt::CaseInsensitive))
73 else if(imageTypeSubString.contains(
"seg", Qt::CaseInsensitive))
75 else if(imageTypeSubString.contains(
"label", Qt::CaseInsensitive))
78 CX_LOG_WARNING() <<
"convertToImageSubType - Cannot convert the string \"" << imageTypeSubString <<
"\" to a known image subtype";
90 QFile file(mFilename);
93 if (file.open(QIODevice::ReadOnly))
101 if (line.startsWith(key, Qt::CaseInsensitive))
103 QStringList list = line.split(
"=", QString::SkipEmptyParts);
104 if (list.size() >= 2)
107 return list.join(
"=");
119 QString modalityString = this->
readKey(
"Modality");
125 QString imageTypeString = this->
readKey(
"ImageType3");
132 void CustomMetaImage::remove(QStringList* data, QStringList keys)
134 QRegExp regexp(QString(
"(^%1)").arg(keys.join(
"|^")));
135 QStringList removeThese = data->filter(regexp);
136 for (
int i=0; i<removeThese.size(); ++i)
137 data->removeAll(removeThese[i]);
145 void CustomMetaImage::append(QStringList* data, QString key, QString value)
148 int last = data->lastIndexOf(QRegExp(
"^ElementDataFile.*"));
149 data->insert(last, QString(
"%1 = %2").arg(key).arg(value));
154 QFile file(mFilename);
156 if (!file.open(QIODevice::ReadWrite))
158 reportError(
"Failed to open file " + mFilename +
".");
162 QStringList data = QTextStream(&file).readAll().split(
"\n");
164 this->remove(&data, QStringList()<<key);
165 this->append(&data, key, value);
168 file.write(data.join(
"\n").toLatin1());
190 QFile file(mFilename);
193 if (file.open(QIODevice::ReadOnly))
195 QTextStream t(&file);
201 if (line.startsWith(
"Position", Qt::CaseInsensitive) || line.startsWith(
"Offset", Qt::CaseInsensitive))
203 QStringList list = line.split(
" ", QString::SkipEmptyParts);
205 p_r =
Vector3D(list[2].toDouble(), list[3].toDouble(), list[4].toDouble());
207 else if (line.startsWith(
"TransformMatrix", Qt::CaseInsensitive) || line.startsWith(
"Orientation",
208 Qt::CaseInsensitive))
210 QStringList list = line.split(
" ", QString::SkipEmptyParts);
214 e_x =
Vector3D(list[2].toDouble(), list[3].toDouble(), list[4].toDouble());
215 e_y =
Vector3D(list[5].toDouble(), list[6].toDouble(), list[7].toDouble());
216 e_z =
cross(e_x, e_y);
226 for (
unsigned i = 0; i < 3; ++i)
243 QFile file(mFilename);
245 if (!file.open(QIODevice::ReadWrite))
247 reportWarning(
"Could not save transform because: Failed to open file " + mFilename);
251 QStringList data = QTextStream(&file).readAll().split(
"\n");
253 this->remove(&data, QStringList()<<
"TransformMatrix"<<
"Offset"<<
"Position"<<
"Orientation");
256 std::stringstream tmList;
257 for (
int c=0; c<dim; ++c)
258 for (
int r=0; r<dim; ++r)
259 tmList <<
" " << M(r,c);
260 this->append(&data,
"TransformMatrix",
qstring_cast(tmList.str()));
262 std::stringstream posList;
263 for (
int r=0; r<dim; ++r)
264 posList <<
" " << M(r,3);
265 this->append(&data,
"Offset",
qstring_cast(posList.str()));
268 file.write(data.join(
"\n").toLatin1());