29 QString filename = mCalibrationFilename;
31 if (!filename.isEmpty() && QFile::exists(filename))
39 filename = mSROMFilename.remove(
".rom", Qt::CaseInsensitive);
40 filename.append(
".cal");
45 file.
write(this->getCalibrationAsSSC());
65 report(
"Replaced calibration in " + filename);
71 QString verificationError(
"Internal verification of tool " + mUid +
" failed! REASON: ");
72 if (!mIsPointer && !mIsReference && !mIsProbe)
77 +
" Tag <tool>::<type> is invalid, must be one one of pointer/probe/reference ");
82 reportError(verificationError +
" Tag <tool>::<uid> is empty. Give tool a unique id.");
85 if (mTrackerType ==
tsNONE)
88 verificationError +
" Tag <sensor>::<type> is invalid ["
90 +
"]. Valid types: [polaris, spectra, vicra, aurora, micron (NOT SUPPORTED YET)]");
93 if ((mTrackerType ==
tsAURORA) && (mPortNumber >= 4))
96 verificationError +
" Tag <sensor>::<portnumber> is invalid ["
98 +
"]. Valid numbers: [0, 1, 2, 3]");
101 if ((mTrackerType ==
tsAURORA) && (mChannelNumber >= 1))
104 verificationError +
" Tag <sensor>::<channelnumber> is invalid ["
105 +
qstring_cast(mChannelNumber) +
"]. Valid numbers: [0, 1]");
109 if (!mSROMFilename.isEmpty() && !dir.exists(mSROMFilename))
112 verificationError +
" Tag <sensor>::<rom_file> is invalid [" + mSROMFilename
113 +
"]. Valid path: relative path to existing rom file.");
116 if (!mCalibrationFilename.isEmpty() && !dir.exists(mCalibrationFilename))
119 verificationError +
" Tag <calibration>::<cal_file> is invalid ["
120 + mCalibrationFilename
121 +
"]. Valid path: relative path to existing calibration file.");
124 if (!mTransformSaveFileName.isEmpty() && !dir.exists(mTransformSaveFileName))
126 reportError(verificationError +
" Logging folder is invalid. Contact programmer! :)");
129 if (!mLoggingFolderName.isEmpty() && !dir.exists(mLoggingFolderName))
131 reportError(verificationError +
" Logging folder is invalid. Contact programmer! :)");
164 QString toolFolderAbsolutePath = QFileInfo(toolFile).dir().absolutePath() +
"/";
168 if (toolNode.isNull())
172 +
", this is not a tool file, skipping.");
176 QDomElement toolTypeElement = toolNode.firstChildElement(
mToolTypeTag);
177 QString toolTypeText = toolTypeElement.text();
179 internalStructure->mIsReference = toolTypeText.contains(
"reference", Qt::CaseInsensitive);
180 internalStructure->mIsPointer = toolTypeText.contains(
"pointer", Qt::CaseInsensitive);
181 internalStructure->mIsProbe = toolTypeText.contains(
"usprobe", Qt::CaseInsensitive);
197 QDomElement toolIdElement = toolNode.firstChildElement(
mToolIdTag);
198 QString toolIdText = toolIdElement.text();
199 internalStructure->mUid = toolIdText;
201 QDomElement toolNameElement = toolNode.firstChildElement(
mToolNameTag);
202 QString toolNameText = toolNameElement.text();
203 internalStructure->mName = toolNameText;
206 QString toolClinicalAppText = toolClinicalAppElement.text();
207 QStringList applicationList = toolClinicalAppText.split(
" ");
208 foreach(QString
string, applicationList)
210 if (
string.isEmpty())
212 string =
string.toLower();
213 internalStructure->mClinicalApplications.push_back(
string);
216 QDomElement toolGeofileElement = toolNode.firstChildElement(
mToolGeoFileTag);
217 QString toolGeofileText = toolGeofileElement.text();
218 if (!toolGeofileText.isEmpty())
219 toolGeofileText = toolFolderAbsolutePath + toolGeofileText;
220 internalStructure->mGraphicsFileName = toolGeofileText;
222 QDomElement toolPicfileElement = toolNode.firstChildElement(
mToolPicFileTag);
223 QString toolPicfileText = toolPicfileElement.text();
224 if (!toolPicfileText.isEmpty())
225 toolPicfileText = toolFolderAbsolutePath + toolPicfileText;
226 internalStructure->mPictureFileName = toolPicfileText;
229 QString toolImageIdfileText = toolImageIdfileElement.text();
230 internalStructure->mOpenigtlinkImageId = toolImageIdfileText;
233 QString toolTransformIdfileText = toolTransformIdfileElement.text();
234 internalStructure->mOpenigtlinkTransformId = toolTransformIdfileText;
237 if (toolInstrumentElement.isNull())
240 "Could not find the <instrument> tag under the <tool> tag. Aborting this tool.");
243 QDomElement toolInstrumentIdElement = toolInstrumentElement.firstChildElement(
mToolInstrumentIdTag);
244 QString toolInstrumentIdText = toolInstrumentIdElement.text();
245 internalStructure->mInstrumentId = toolInstrumentIdText;
248 QString toolInstrumentScannerIdText = toolInstrumentScannerIdElement.text();
249 internalStructure->mInstrumentScannerId = toolInstrumentScannerIdText;
251 QDomElement toolSensorElement = toolNode.firstChildElement(
mToolSensorTag);
252 if (toolSensorElement.isNull())
254 reportError(
"Could not find the <sensor> tag under the <tool> tag. Aborting this tool.");
257 QDomElement toolSensorTypeElement = toolSensorElement.firstChildElement(
mToolSensorTypeTag);
258 QString toolSensorTypeText = toolSensorTypeElement.text();
259 internalStructure->mTrackerType = string2enum<TRACKING_SYSTEM>(toolSensorTypeText);
262 QString toolSensorWirelessText = toolSensorWirelessElement.text();
263 if (toolSensorWirelessText.contains(
"yes", Qt::CaseInsensitive))
264 internalStructure->mWireless =
true;
265 else if (toolSensorWirelessText.contains(
"no", Qt::CaseInsensitive))
266 internalStructure->mWireless =
false;
268 QDomElement toolSensorDOFElement = toolSensorElement.firstChildElement(
mToolSensorDOFTag);
269 QString toolSensorDOFText = toolSensorDOFElement.text();
270 if (toolSensorDOFText.contains(
"5", Qt::CaseInsensitive))
271 internalStructure->m5DOF =
true;
272 else if (toolSensorDOFText.contains(
"6", Qt::CaseInsensitive))
273 internalStructure->m5DOF =
false;
276 QString toolSensorPortnumberText = toolSensorPortnumberElement.text();
277 internalStructure->mPortNumber = toolSensorPortnumberText.toUInt();
280 QString toolSensorChannelnumberText = toolSensorChannelnumberElement.text();
281 internalStructure->mChannelNumber = toolSensorChannelnumberText.toUInt();
284 for (
int j = 0; j < toolSensorReferencePointList.count(); j++)
286 QDomNode node = toolSensorReferencePointList.item(j);
287 if (!node.hasAttributes())
289 reportWarning(
"Found reference point without id attribute. Skipping.");
292 QString
id = node.toElement().attribute(
"id");
293 QString toolSensorReferencePointText = node.toElement().text();
294 Vector3D vector = Vector3D::fromString(toolSensorReferencePointText);
295 internalStructure->mReferencePoints[id] = vector;
299 QString toolSensorRomFileText = toolSensorRomFileElement.text();
300 if (!toolSensorRomFileText.isEmpty())
301 toolSensorRomFileText = toolFolderAbsolutePath + toolSensorRomFileText;
302 internalStructure->mSROMFilename = toolSensorRomFileText;
305 if (toolCalibrationElement.isNull())
308 "Could not find the <calibration> tag under the <tool> tag. Aborting this tool.");
312 QString toolCalibrationFileText = toolCalibrationFileElement.text();
313 if (!toolCalibrationFileText.isEmpty())
314 toolCalibrationFileText = toolFolderAbsolutePath + toolCalibrationFileText;
315 internalStructure->mCalibrationFilename = toolCalibrationFileText;
316 internalStructure->mCalibration = this->
readCalibrationFile(internalStructure->mCalibrationFilename);
320 retval = internalStructure;
328 QFile toolFile(toolAbsoluteFilePath);
329 if (!
mToolDoc.setContent(&toolFile))
331 reportError(
"Could not set the xml content of the tool file " + toolAbsoluteFilePath);