29 us::ModuleContext* thisContext = us::GetModuleContext();
31 std::vector<us::ServiceReference<USDevice> > services = thisContext->GetServiceReferences<
USDevice>();
32 MITK_INFO <<
"Trying to save " << services.size() <<
" US devices.";
33 int numberOfSavedDevices = 0;
34 for (std::vector<us::ServiceReference<USDevice> >::iterator it = services.begin(); it != services.end(); ++it)
36 mitk::USDevice::Pointer currentDevice = thisContext->GetService(*it);
38 if (currentDevice->GetDeviceClass() ==
"org.mitk.modules.us.USVideoDevice")
40 mitk::USVideoDevice::Pointer currentVideoDevice =
dynamic_cast<mitk::USVideoDevice*
>(currentDevice.GetPointer());
41 QString identifier =
"device" + QString::number(numberOfSavedDevices);
42 m_devices.setValue(identifier, USVideoDeviceToString(currentVideoDevice));
43 numberOfSavedDevices++;
48 MITK_WARN <<
"Saving of US devices of the type " << currentDevice->GetDeviceClass() <<
" is not supported at the moment. Skipping device.";
51 m_devices.setValue(
"numberOfSavedDevices", numberOfSavedDevices);
52 MITK_INFO <<
"Successfully saved " << numberOfSavedDevices <<
" US devices.";
57 std::vector<mitk::USDevice::Pointer> devices;
59 int numberOfSavedDevices = m_devices.value(
"numberOfSavedDevices").toInt();
61 for (
int i = 0; i < numberOfSavedDevices; i++)
66 QString currentString = m_devices.value(
"device" + QString::number(i)).toString();
67 mitk::USDevice::Pointer currentDevice =
dynamic_cast<mitk::USDevice*
>(StringToUSVideoDevice(currentString).GetPointer());
69 devices.push_back(currentDevice.GetPointer());
73 MITK_ERROR <<
"Error occured while loading a USVideoDevice from persistence. Device assumed corrupt, will be deleted.";
78 if (numberOfSavedDevices > 0)
79 MITK_INFO <<
"Restoring " << numberOfSavedDevices <<
" US devices.";
86 QString manufacturer = d->GetManufacturer().c_str();
87 QString model = d->GetName().c_str();
88 QString comment = d->GetComment().c_str();
89 int source = d->GetDeviceID();
90 std::string file = d->GetFilePath();
91 if (!d->GetIsSourceFile()) file =
"none";
93 mitk::USImageVideoSource::Pointer imageSource =
dynamic_cast<mitk::USImageVideoSource*
>(d->GetUSImageSource().GetPointer());
96 MITK_ERROR <<
"There is no USImageVideoSource at the current device.";
97 mitkThrow() <<
"There is no USImageVideoSource at the current device.";
100 int greyscale = imageSource->GetIsGreyscale();
101 int resOverride = imageSource->GetResolutionOverride();
102 int resWidth = imageSource->GetResolutionOverrideWidth();
103 int resHight = imageSource->GetResolutionOverrideHeight();
107 char probesSeperator =
'!';
108 std::vector<mitk::USProbe::Pointer> allProbesOfDevice = d->GetAllProbes();
109 if (allProbesOfDevice.size() > 0)
111 for (std::vector<mitk::USProbe::Pointer>::iterator it = allProbesOfDevice.begin(); it != allProbesOfDevice.end(); it++)
113 if (it == allProbesOfDevice.begin())
115 probes = probes + USProbeToString(*it);
119 probes = probes + probesSeperator + USProbeToString(*it);
124 char seperator =
'|';
126 QString returnValue = manufacturer + seperator
128 + comment + seperator
129 + QString::number(source) + seperator
130 + file.c_str() + seperator
131 + QString::number(greyscale) + seperator
132 + QString::number(resOverride) + seperator
133 + QString::number(resWidth) + seperator
134 + QString::number(resHight) + seperator
138 MITK_INFO <<
"Output String: " << returnValue.toStdString();
144 QString probe = QString::fromStdString(p->GetName());
145 QString croppingSeparator = QString(
",");
146 probe = probe + croppingSeparator + QString::number(p->GetProbeCropping().top)
147 + croppingSeparator + QString::number(p->GetProbeCropping().right)
148 + croppingSeparator + QString::number(p->GetProbeCropping().bottom)
149 + croppingSeparator + QString::number(p->GetProbeCropping().left)
152 char depthSeperator =
'$';
153 char spacingSeperator =
'%';
154 std::map<int, mitk::Vector3D> depthsAndSpacing = p->GetDepthsAndSpacing();
155 if (depthsAndSpacing.size() > 0)
157 for (std::map<int, mitk::Vector3D>::iterator it = depthsAndSpacing.begin(); it != depthsAndSpacing.end(); it++){
158 probe = probe + depthSeperator + QString::number(it->first) + spacingSeperator + QString::number(it->second[0])
159 + spacingSeperator + QString::number(it->second[1]) + spacingSeperator + QString::number(it->second[2]);
167 MITK_INFO <<
"Input String: " << s.toStdString();
168 std::vector<std::string> data;
169 std::string seperators =
"|";
170 std::string text = s.toStdString();
171 split(text, seperators, data);
172 if (data.size() != 10)
174 MITK_ERROR <<
"Cannot parse US device! (Size: " << data.size() <<
")";
175 return mitk::USVideoDevice::New(
"INVALID",
"INVALID",
"INVALID");
178 std::string manufacturer = data.at(0);
179 std::string model = data.at(1);
180 std::string comment = data.at(2);
181 int source = (QString(data.at(3).c_str())).toInt();
182 std::string file = data.at(4);
183 bool greyscale = (QString(data.at(5).c_str())).toInt();
184 bool resOverride = (QString(data.at(6).c_str())).toInt();
185 int resWidth = (QString(data.at(7).c_str())).toInt();
186 int resHight = (QString(data.at(8).c_str())).toInt();
189 mitk::USVideoDevice::Pointer returnValue;
192 returnValue = mitk::USVideoDevice::New(source, manufacturer, model);
193 returnValue->SetComment(comment);
197 returnValue = mitk::USVideoDevice::New(file, manufacturer, model);
198 returnValue->SetComment(comment);
201 mitk::USImageVideoSource::Pointer imageSource =
205 MITK_ERROR <<
"There is no USImageVideoSource at the current device.";
206 mitkThrow() <<
"There is no USImageVideoSource at the current device.";
215 imageSource->OverrideResolution(resWidth, resHight);
216 imageSource->SetResolutionOverride(
true);
219 std::string probes = data.at(9);
220 std::string probesSeperator =
"!";
221 std::vector<std::string> probesVector;
222 split(probes, probesSeperator, probesVector);
223 for (std::vector<std::string>::iterator it = probesVector.begin(); it != probesVector.end(); it++)
225 mitk::USProbe::Pointer probe = StringToUSProbe(*it);
226 returnValue->AddNewProbe(probe);
234 mitk::USProbe::Pointer probe = mitk::USProbe::New();
235 std::string croppingSeparator =
",";
236 std::string spacingSeperator =
"%";
237 std::string depthSeperator =
"$";
238 std::vector<std::string> probeCropping;
239 split(s, croppingSeparator, probeCropping);
241 std::vector<std::string> depthsWithSpacings;
242 split(s, depthSeperator, depthsWithSpacings);
245 std::string probeName = probeCropping.at(0);
246 probe->SetName(probeName);
249 if( probeCropping.size() >= 6 )
251 QString top = QString::fromStdString(probeCropping.at(1));
252 QString right = QString::fromStdString(probeCropping.at(2));
253 QString bottom = QString::fromStdString(probeCropping.at(3));
254 QString left = QString::fromStdString(probeCropping.at(4));
255 probe->SetProbeCropping(top.toUInt(), bottom.toUInt(), left.toUInt(), right.toUInt());
258 for (std::vector<std::string>::iterator it = depthsWithSpacings.begin(); it != depthsWithSpacings.end(); it++)
262 if (it != depthsWithSpacings.begin())
264 std::vector<std::string> spacings;
265 split(*it, spacingSeperator, spacings);
266 mitk::Vector3D spacing;
273 x = spacingToDouble(spacings.at(1));
274 y = spacingToDouble(spacings.at(2));
275 z = spacingToDouble(spacings.at(3));
277 catch (
const mitk::Exception& e)
279 MITK_ERROR << e.GetDescription() <<
"Spacing of " << probe->GetName() <<
" at depth " << spacings.at(0) <<
" will be set to default value 1,1,0.";
290 depth = depthToInt(spacings.at(0));
292 catch (
const mitk::Exception& e)
294 MITK_ERROR << probe->GetName() <<
": " << e.GetDescription();
297 probe->SetDepthAndSpacing(depth, spacing);
305 int n = text.length();
308 start = text.find_first_not_of(separators);
309 while ((start >= 0) && (start < n))
311 stop = text.find_first_of(separators, start);
312 if ((stop < 0) || (stop > n)) stop = n;
313 words.push_back(text.substr(start, stop - start));
314 start = text.find_first_not_of(separators, stop + 1);