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 ==
"PT")
42 else if(modalityString.contains(enum2string<IMAGE_MODALITY>(
imSC), Qt::CaseInsensitive))
45 CX_LOG_WARNING() <<
"convertToModality - Cannot convert the string \"" << modalityString <<
"\" to a known image modality";
55 if (imageTypeSubString.isEmpty() || imageTypeSubString ==
" ")
57 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istUNKNOWN), Qt::CaseInsensitive))
59 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istMRT1), Qt::CaseInsensitive))
61 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istMRT2), Qt::CaseInsensitive))
63 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istMRFLAIR), Qt::CaseInsensitive))
65 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istANGIO), Qt::CaseInsensitive))
67 else if(imageTypeSubString.contains(enum2string<IMAGE_SUBTYPE>(
istUSBMODE), Qt::CaseInsensitive))
69 else if(imageTypeSubString.contains(
"bmode", Qt::CaseInsensitive))
71 else if(imageTypeSubString.contains(
"b_mode", Qt::CaseInsensitive))
73 else if(imageTypeSubString.contains(
"b mode", Qt::CaseInsensitive))
75 else if(imageTypeSubString.contains(
"seg", Qt::CaseInsensitive))
77 else if(imageTypeSubString.contains(
"label", Qt::CaseInsensitive))
80 CX_LOG_WARNING() <<
"convertToImageSubType - Cannot convert the string \"" << imageTypeSubString <<
"\" to a known image subtype";
92 QFile file(mFilename);
95 if (file.open(QIODevice::ReadOnly))
103 if (line.startsWith(key, Qt::CaseInsensitive))
105 QStringList list = line.split(
"=", QString::SkipEmptyParts);
106 if (list.size() >= 2)
109 return list.join(
"=");
121 QString modalityString = this->
readKey(
"Modality");
127 QString imageTypeString = this->
readKey(
"ImageType3");
134 void CustomMetaImage::remove(QStringList* data, QStringList keys)
136 QRegExp regexp(QString(
"(^%1)").arg(keys.join(
"|^")));
137 QStringList removeThese = data->filter(regexp);
138 for (
int i=0; i<removeThese.size(); ++i)
139 data->removeAll(removeThese[i]);
147 void CustomMetaImage::append(QStringList* data, QString key, QString value)
150 int last = data->lastIndexOf(QRegExp(
"^ElementDataFile.*"));
151 data->insert(last, QString(
"%1 = %2").arg(key).arg(value));
156 QFile file(mFilename);
158 if (!file.open(QIODevice::ReadWrite))
160 reportError(
"Failed to open file " + mFilename +
".");
164 QStringList data = QTextStream(&file).readAll().split(
"\n");
166 this->
remove(&data, QStringList()<<key);
167 this->append(&data, key, value);
170 file.write(data.join(
"\n").toLatin1());
192 QFile file(mFilename);
195 if (file.open(QIODevice::ReadOnly))
197 QTextStream t(&file);
203 if (line.startsWith(
"Position", Qt::CaseInsensitive) || line.startsWith(
"Offset", Qt::CaseInsensitive))
205 QStringList list = line.split(
" ", QString::SkipEmptyParts);
207 p_r =
Vector3D(list[2].toDouble(), list[3].toDouble(), list[4].toDouble());
209 else if (line.startsWith(
"TransformMatrix", Qt::CaseInsensitive) || line.startsWith(
"Orientation",
210 Qt::CaseInsensitive))
212 QStringList list = line.split(
" ", QString::SkipEmptyParts);
216 e_x =
Vector3D(list[2].toDouble(), list[3].toDouble(), list[4].toDouble());
217 e_y =
Vector3D(list[5].toDouble(), list[6].toDouble(), list[7].toDouble());
218 e_z =
cross(e_x, e_y);
228 for (
unsigned i = 0; i < 3; ++i)
245 QFile file(mFilename);
247 if (!file.open(QIODevice::ReadWrite))
249 reportWarning(
"Could not save transform because: Failed to open file " + mFilename);
253 QStringList data = QTextStream(&file).readAll().split(
"\n");
255 this->
remove(&data, QStringList()<<
"TransformMatrix"<<
"Offset"<<
"Position"<<
"Orientation");
258 std::stringstream tmList;
259 for (
int c=0; c<dim; ++c)
260 for (
int r=0; r<dim; ++r)
261 tmList <<
" " << M(r,c);
262 this->append(&data,
"TransformMatrix",
qstring_cast(tmList.str()));
264 std::stringstream posList;
265 for (
int r=0; r<dim; ++r)
266 posList <<
" " << M(r,3);
267 this->append(&data,
"Offset",
qstring_cast(posList.str()));
270 file.write(data.join(
"\n").toLatin1());
QString qstring_cast(const T &val)
void reportError(QString msg)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
IMAGE_MODALITY convertToModality(QString modalityString)
Vector3D cross(const Vector3D &a, const Vector3D &b)
compute cross product of a and b.
void reportWarning(QString msg)
IMAGE_SUBTYPE convertToImageSubType(QString imageTypeSubString)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
QString enum2string(const ENUM &val)
Namespace for all CustusX production code.