35 std::vector<us::ServiceReference<USDevice> > services = thisContext->GetServiceReferences<
USDevice>();
36 MITK_INFO <<
"Trying to save " << services.size() <<
" US devices.";
37 int numberOfSavedDevices = 0;
42 if (currentDevice->GetDeviceClass() ==
"org.mitk.modules.us.USVideoDevice")
45 QString identifier =
"device" + QString::number(numberOfSavedDevices);
46 m_devices.setValue(identifier, USVideoDeviceToString(currentVideoDevice));
47 numberOfSavedDevices++;
52 MITK_WARN <<
"Saving of US devices of the type " << currentDevice->GetDeviceClass() <<
" is not supported at the moment. Skipping device.";
55 m_devices.setValue(
"numberOfSavedDevices", numberOfSavedDevices);
56 MITK_INFO <<
"Successfully saved " << numberOfSavedDevices <<
" US devices.";
61 std::vector<mitk::USDevice::Pointer> devices;
63 int numberOfSavedDevices = m_devices.value(
"numberOfSavedDevices").toInt();
65 for (
int i = 0; i < numberOfSavedDevices; i++)
70 QString currentString = m_devices.value(
"device" + QString::number(i)).toString();
73 devices.push_back(currentDevice.GetPointer());
77 MITK_ERROR <<
"Error occured while loading a USVideoDevice from persistence. Device assumed corrupt, will be deleted.";
82 MITK_INFO <<
"Restoring " << numberOfSavedDevices <<
" US devices.";
89 QString manufacturer = d->GetManufacturer().c_str();
90 QString model = d->GetName().c_str();
91 QString comment = d->GetComment().c_str();
92 int source = d->GetDeviceID();
93 std::string file = d->GetFilePath();
94 if (!d->GetIsSourceFile()) file =
"none";
99 MITK_ERROR <<
"There is no USImageVideoSource at the current device.";
100 mitkThrow() <<
"There is no USImageVideoSource at the current device.";
103 int greyscale = imageSource->GetIsGreyscale();
104 int resOverride = imageSource->GetResolutionOverride();
105 int resWidth = imageSource->GetResolutionOverrideWidth();
106 int resHight = imageSource->GetResolutionOverrideHeight();
112 char probesSeperator =
'!';
113 std::vector<mitk::USProbe::Pointer> allProbesOfDevice = d->GetAllProbes();
114 if (allProbesOfDevice.size() > 0)
116 for (std::vector<mitk::USProbe::Pointer>::iterator it = allProbesOfDevice.begin(); it != allProbesOfDevice.end(); it++)
118 if (it == allProbesOfDevice.begin())
120 probes = probes + USProbeToString(*it);
124 probes = probes + probesSeperator + USProbeToString(*it);
129 char seperator =
'|';
131 QString returnValue = manufacturer + seperator
133 + comment + seperator
134 + QString::number(source) + seperator
135 + file.c_str() + seperator
136 + QString::number(greyscale) + seperator
137 + QString::number(resOverride) + seperator
138 + QString::number(resWidth) + seperator
139 + QString::number(resHight) + seperator
140 + QString::number(roi.
topLeftX) + seperator
141 + QString::number(roi.
topLeftY) + seperator
147 MITK_INFO <<
"Output String: " << returnValue.toStdString();
153 QString probe = p->GetName().c_str();
154 char depthSeperator =
'$';
155 char spacingSeperator =
'%';
156 std::map<int, mitk::Vector3D> depthsAndSpacing = p->GetDepthsAndSpacing();
157 if (depthsAndSpacing.size() > 0)
159 for (std::map<int, mitk::Vector3D>::iterator it = depthsAndSpacing.begin(); it != depthsAndSpacing.end(); it++){
160 probe = probe + depthSeperator + QString::number(it->first) + spacingSeperator + QString::number(it->second[0])
161 + spacingSeperator + QString::number(it->second[1]) + spacingSeperator + QString::number(it->second[2]);
169 MITK_INFO <<
"Input String: " << s.toStdString();
170 std::vector<std::string> data;
171 std::string seperators =
"|";
172 std::string text = s.toStdString();
173 split(text, seperators, data);
174 if (data.size() != 14)
176 MITK_ERROR <<
"Cannot parse US device! (Size: " << data.size() <<
")";
180 std::string manufacturer = data.at(0);
181 std::string model = data.at(1);
182 std::string comment = data.at(2);
183 int source = (QString(data.at(3).c_str())).toInt();
184 std::string file = data.at(4);
185 bool greyscale = (QString(data.at(5).c_str())).toInt();
186 bool resOverride = (QString(data.at(6).c_str())).toInt();
187 int resWidth = (QString(data.at(7).c_str())).toInt();
188 int resHight = (QString(data.at(8).c_str())).toInt();
190 cropArea.
topLeftX = (QString(data.at(9).c_str())).toInt();
191 cropArea.
topLeftY = (QString(data.at(10).c_str())).toInt();
192 cropArea.
bottomRightX = (QString(data.at(11).c_str())).toInt();
193 cropArea.
bottomRightY = (QString(data.at(12).c_str())).toInt();
200 returnValue->SetComment(comment);
205 returnValue->SetComment(comment);
212 MITK_ERROR <<
"There is no USImageVideoSource at the current device.";
213 mitkThrow() <<
"There is no USImageVideoSource at the current device.";
217 imageSource->SetColorOutput(!greyscale);
222 imageSource->OverrideResolution(resWidth, resHight);
223 imageSource->SetResolutionOverride(
true);
227 imageSource->SetRegionOfInterest(cropArea);
228 std::string probes = data.at(13);
229 std::string probesSeperator =
"!";
230 std::vector<std::string> probesVector;
231 split(probes, probesSeperator, probesVector);
232 for (std::vector<std::string>::iterator it = probesVector.begin(); it != probesVector.end(); it++)
235 returnValue->AddNewProbe(probe);
244 std::string spacingSeperator =
"%";
245 std::string depthSeperator =
"$";
246 std::vector<std::string> depthsWithSpacings;
247 split(s, depthSeperator, depthsWithSpacings);
249 for (std::vector<std::string>::iterator it = depthsWithSpacings.begin(); it != depthsWithSpacings.end(); it++)
251 if (it == depthsWithSpacings.begin())
257 std::vector<std::string> spacings;
258 split(*it, spacingSeperator, spacings);
266 x = spacingToDouble(spacings.at(1));
267 y = spacingToDouble(spacings.at(2));
268 z = spacingToDouble(spacings.at(3));
272 MITK_ERROR << e.GetDescription() <<
"Spacing of " << probe->GetName() <<
" at depth " << spacings.at(0) <<
" will be set to default value 1,1,0.";
283 depth = depthToInt(spacings.at(0));
287 MITK_ERROR << probe->GetName() <<
": " << e.GetDescription();
290 probe->SetDepthAndSpacing(depth, spacing);
298 int n = text.length();
301 start = text.find_first_not_of(separators);
302 while ((start >= 0) && (start < n))
304 stop = text.find_first_of(separators, start);
305 if ((stop < 0) || (stop > n)) stop = n;
306 words.push_back(text.substr(start, stop - start));
307 start = text.find_first_not_of(separators, stop + 1);
313 std::istringstream i(s);
318 mitkThrow() <<
"An error occured while trying to recover the spacing.";
325 std::istringstream i(s);
330 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()
itk::SmartPointer< Self > Pointer
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)
Defines a region of interest by top left and bottom right corner.
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.
static std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)