31 std::vector<us::ServiceReference<USDevice> > services = thisContext->GetServiceReferences<
USDevice>();
32 MITK_INFO <<
"Trying to save " << services.size() <<
" US devices.";
33 int numberOfSavedDevices = 0;
38 if (currentDevice->GetDeviceClass() ==
"org.mitk.modules.us.USVideoDevice")
41 QString identifier =
"device" + QString::number(numberOfSavedDevices);
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();
69 devices.push_back(currentDevice.GetPointer());
73 MITK_ERROR <<
"Error occured while loading a USVideoDevice from persistence. Device assumed corrupt, will be deleted.";
78 MITK_INFO <<
"Restoring " << numberOfSavedDevices <<
" US devices.";
85 QString manufacturer = d->GetManufacturer().c_str();
86 QString model = d->GetName().c_str();
87 QString comment = d->GetComment().c_str();
88 int source = d->GetDeviceID();
89 std::string file = d->GetFilePath();
90 if (!d->GetIsSourceFile()) file =
"none";
92 mitk::USImageVideoSource::Pointer imageSource =
dynamic_cast<mitk::USImageVideoSource*
>(d->GetUSImageSource().GetPointer());
95 MITK_ERROR <<
"There is no USImageVideoSource at the current device.";
96 mitkThrow() <<
"There is no USImageVideoSource at the current device.";
99 int greyscale = imageSource->GetIsGreyscale();
100 int resOverride = imageSource->GetResolutionOverride();
101 int resWidth = imageSource->GetResolutionOverrideWidth();
102 int resHight = imageSource->GetResolutionOverrideHeight();
106 char probesSeperator =
'!';
107 std::vector<mitk::USProbe::Pointer> allProbesOfDevice = d->GetAllProbes();
108 if (allProbesOfDevice.size() > 0)
110 for (std::vector<mitk::USProbe::Pointer>::iterator it = allProbesOfDevice.begin(); it != allProbesOfDevice.end(); it++)
112 if (it == allProbesOfDevice.begin())
123 char seperator =
'|';
125 QString returnValue = manufacturer + seperator
127 + comment + seperator
128 + QString::number(source) + seperator
129 + file.c_str() + seperator
130 + QString::number(greyscale) + seperator
131 + QString::number(resOverride) + seperator
132 + QString::number(resWidth) + seperator
133 + QString::number(resHight) + seperator
137 MITK_INFO <<
"Output String: " << returnValue.toStdString();
143 QString probe = QString::fromStdString(p->GetName());
144 QString croppingSeparator = QString(
",");
145 probe = probe + croppingSeparator + QString::number(p->GetProbeCropping().top)
146 + croppingSeparator + QString::number(p->GetProbeCropping().right)
147 + croppingSeparator + QString::number(p->GetProbeCropping().bottom)
148 + croppingSeparator + QString::number(p->GetProbeCropping().left)
151 char depthSeperator =
'$';
152 char spacingSeperator =
'%';
153 std::map<int, mitk::Vector3D> depthsAndSpacing = p->GetDepthsAndSpacing();
154 if (depthsAndSpacing.size() > 0)
156 for (std::map<int, mitk::Vector3D>::iterator it = depthsAndSpacing.begin(); it != depthsAndSpacing.end(); it++){
157 probe = probe + depthSeperator + QString::number(it->first) + spacingSeperator + QString::number(it->second[0])
158 + spacingSeperator + QString::number(it->second[1]) + spacingSeperator + QString::number(it->second[2]);
166 MITK_INFO <<
"Input String: " << s.toStdString();
167 std::vector<std::string> data;
168 std::string seperators =
"|";
169 std::string text = s.toStdString();
170 split(text, seperators, data);
171 if (data.size() != 10)
173 MITK_ERROR <<
"Cannot parse US device! (Size: " << data.size() <<
")";
177 std::string manufacturer = data.at(0);
178 std::string model = data.at(1);
179 std::string comment = data.at(2);
180 int source = (QString(data.at(3).c_str())).toInt();
181 std::string file = data.at(4);
182 bool greyscale = (QString(data.at(5).c_str())).toInt();
183 bool resOverride = (QString(data.at(6).c_str())).toInt();
184 int resWidth = (QString(data.at(7).c_str())).toInt();
185 int resHight = (QString(data.at(8).c_str())).toInt();
192 returnValue->SetComment(comment);
197 returnValue->SetComment(comment);
200 mitk::USImageVideoSource::Pointer imageSource =
204 MITK_ERROR <<
"There is no USImageVideoSource at the current device.";
205 mitkThrow() <<
"There is no USImageVideoSource at the current device.";
209 imageSource->SetColorOutput(!greyscale);
214 imageSource->OverrideResolution(resWidth, resHight);
215 imageSource->SetResolutionOverride(
true);
218 std::string probes = data.at(9);
219 std::string probesSeperator =
"!";
220 std::vector<std::string> probesVector;
221 split(probes, probesSeperator, probesVector);
222 for (std::vector<std::string>::iterator it = probesVector.begin(); it != probesVector.end(); it++)
225 returnValue->AddNewProbe(probe);
234 std::string croppingSeparator =
",";
235 std::string spacingSeperator =
"%";
236 std::string depthSeperator =
"$";
237 std::vector<std::string> probeCropping;
238 split(s, croppingSeparator, probeCropping);
240 std::vector<std::string> depthsWithSpacings;
241 split(s, depthSeperator, depthsWithSpacings);
244 std::string probeName = probeCropping.at(0);
245 probe->SetName(probeName);
248 if( probeCropping.size() >= 6 )
250 QString top = QString::fromStdString(probeCropping.at(1));
251 QString right = QString::fromStdString(probeCropping.at(2));
252 QString bottom = QString::fromStdString(probeCropping.at(3));
253 QString left = QString::fromStdString(probeCropping.at(4));
254 probe->SetProbeCropping(top.toUInt(), bottom.toUInt(), left.toUInt(), right.toUInt());
257 for (std::vector<std::string>::iterator it = depthsWithSpacings.begin(); it != depthsWithSpacings.end(); it++)
261 if (it != depthsWithSpacings.begin())
263 std::vector<std::string> spacings;
264 split(*it, spacingSeperator, spacings);
278 MITK_ERROR << e.GetDescription() <<
"Spacing of " << probe->GetName() <<
" at depth " << spacings.at(0) <<
" will be set to default value 1,1,0.";
293 MITK_ERROR << probe->GetName() <<
": " << e.GetDescription();
296 probe->SetDepthAndSpacing(depth, spacing);
304 int n = text.length();
307 start = text.find_first_not_of(separators);
308 while ((start >= 0) && (start < n))
310 stop = text.find_first_of(separators, start);
311 if ((stop < 0) || (stop > n)) stop = n;
312 words.push_back(text.substr(start, stop - start));
313 start = text.find_first_not_of(separators, stop + 1);
319 std::istringstream i(s);
324 mitkThrow() <<
"An error occured while trying to recover the spacing.";
331 std::istringstream i(s);
336 mitkThrow() <<
"An error occured while trying to recover the scanning depth. " << s <<
" is not a valid scanning depth. ";
int depthToInt(std::string s)
mitk::USProbe::Pointer StringToUSProbe(std::string s)
QString USVideoDeviceToString(mitk::USVideoDevice::Pointer d)
A device holds information about it's model, make and the connected probes. It is the common super cl...
std::vector< mitk::USDevice::Pointer > RestoreLastDevices()
static Pointer New()
Method for creation through the object factory.
This class can be pointed to a video file or a videodevice and delivers USImages. ...
QString USProbeToString(mitk::USProbe::Pointer p)
void split(std::string &text, std::string &separators, std::vector< std::string > &words)
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
void StoreCurrentDevices()
mitk::USVideoDevice::Pointer StringToUSVideoDevice(QString s)
double spacingToDouble(std::string s)
A mitk::USVideoDevice is the common class for video only devices. They capture video input either fro...
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.