51 :
mitk::
USDevice(manufacturer, model), m_UltrasoundDevice(usDevice), m_TrackingDevice(trackingDevice),
53 m_NumberOfSmoothingValues(0), m_DelayCount(0)
59 this->SetNthOutput(0, newOutput);
68 if (m_ServiceRegistration !=
nullptr)
69 m_ServiceRegistration.Unregister();
70 m_ServiceRegistration = 0;
75 return DeviceClassIdentifier;
80 if (m_UltrasoundDevice.IsNull())
82 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
83 mitkThrow() <<
"UltrasoundDevice must not be null.";
86 return m_UltrasoundDevice->GetUSImageSource();
91 if (m_UltrasoundDevice.IsNull())
93 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
94 mitkThrow() <<
"UltrasoundDevice must not be null.";
97 return m_UltrasoundDevice->GetControlInterfaceCustom();
102 if (m_UltrasoundDevice.IsNull())
104 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
105 mitkThrow() <<
"UltrasoundDevice must not be null.";
108 return m_UltrasoundDevice->GetControlInterfaceBMode();
113 if (m_UltrasoundDevice.IsNull())
115 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
116 mitkThrow() <<
"UltrasoundDevice must not be null.";
119 return m_UltrasoundDevice->GetControlInterfaceProbes();
124 if (m_UltrasoundDevice.IsNull())
126 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
127 mitkThrow() <<
"UltrasoundDevice must not be null.";
130 return m_UltrasoundDevice->GetControlInterfaceDoppler();
135 if (m_DeviceState == State_Activated) { this->Deactivate(); }
136 if (m_DeviceState == State_Connected) { this->Disconnect(); }
138 if (m_ServiceRegistration !=
nullptr)
139 m_ServiceRegistration.Unregister();
140 m_ServiceRegistration = 0;
145 return this->GetCalibration(this->GetCurrentDepthValue(), this->GetIdentifierForCurrentProbe());
150 return this->GetCalibration(depth, this->GetIdentifierForCurrentProbe());
162 std::map<std::string, mitk::AffineTransform3D::Pointer>::iterator calibrationIterator
163 = m_Calibrations.find(calibrationKey);
165 if (calibrationIterator == m_Calibrations.end()) {
return 0; }
167 return calibrationIterator->second;
172 if (calibration.IsNull())
174 MITK_WARN <<
"Null pointer passed to SetCalibration of mitk::USDevice. Ignoring call.";
178 std::string calibrationKey = this->GetIdentifierForCurrentCalibration();
179 if (calibrationKey.empty())
181 MITK_WARN <<
"Could not get a key for the calibration -> Calibration cannot be set.";
185 m_Calibrations[calibrationKey] = calibration;
190 return this->RemoveCalibration(this->GetCurrentDepthValue(), this->GetIdentifierForCurrentProbe());
195 return this->RemoveCalibration(depth, this->GetIdentifierForCurrentProbe());
206 return m_Calibrations.erase(calibrationKey) > 0;
211 unsigned int oldNumber = m_NumberOfSmoothingValues;
212 m_NumberOfSmoothingValues = numberOfSmoothingValues;
215 if ((oldNumber == 0 && numberOfSmoothingValues != 0) ||
216 (oldNumber != 0 && numberOfSmoothingValues == 0))
218 this->RebuildFilterPipeline();
220 m_SmoothingFilter->SetNumerOfValues(numberOfSmoothingValues);
225 unsigned int oldCount = m_DelayCount;
226 m_DelayCount = delayCount;
229 if ((oldCount == 0 && delayCount != 0) ||
230 (oldCount != 0 && delayCount == 0))
232 this->RebuildFilterPipeline();
234 m_DelayFilter->SetDelay(delayCount);
239 if (m_UltrasoundDevice.IsNull())
241 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
242 mitkThrow() <<
"UltrasoundDevice must not be null.";
247 return m_UltrasoundDevice->Initialize();
257 if (m_UltrasoundDevice.IsNull())
259 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
260 mitkThrow() <<
"UltrasoundDevice must not be null.";
270 return m_UltrasoundDevice->Connect();
276 if (m_UltrasoundDevice.IsNull())
278 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
279 mitkThrow() <<
"UltrasoundDevice must not be null.";
282 return m_UltrasoundDevice->Disconnect();
287 if (m_UltrasoundDevice.IsNull())
289 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
290 mitkThrow() <<
"UltrasoundDevice must not be null.";
294 if (trackingDeviceSource.IsNull())
296 MITK_WARN(
"USCombinedModality")(
"USDevice") <<
"Cannot start tracking as TrackingDeviceSource is null.";
298 trackingDeviceSource->StartTracking();
307 return m_UltrasoundDevice->Activate();
313 if (m_UltrasoundDevice.IsNull())
315 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
316 mitkThrow() <<
"UltrasoundDevice must not be null.";
320 if (trackingDeviceSource.IsNull())
322 MITK_WARN(
"USCombinedModality")(
"USDevice") <<
"Cannot stop tracking as TrackingDeviceSource is null.";
324 trackingDeviceSource->StopTracking();
326 m_UltrasoundDevice->Deactivate();
328 return m_UltrasoundDevice->GetIsConnected();
334 if (trackingDeviceSource.IsNull())
336 MITK_WARN(
"USCombinedModality")(
"USDevice") <<
"Cannot freeze tracking.";
340 if (freeze) { trackingDeviceSource->Freeze(); }
341 else { trackingDeviceSource->UnFreeze(); }
344 if (m_UltrasoundDevice.IsNull())
346 MITK_ERROR(
"USCombinedModality")(
"USDevice") <<
"UltrasoundDevice must not be null.";
347 mitkThrow() <<
"UltrasoundDevice must not be null.";
349 m_UltrasoundDevice->SetIsFreezed(freeze);
354 return m_LastFilter.GetPointer();
359 return m_Calibrations.find(this->GetIdentifierForCurrentCalibration()) != m_Calibrations.end();
364 return !m_Calibrations.empty();
369 if (m_UltrasoundDevice->GetIsFreezed()) {
return; }
374 if (image.IsNull() || !image->IsInitialized())
376 MITK_WARN <<
"Invalid image in USCombinedModality, aborting!";
382 if (!output->IsInitialized()) { output->Initialize(image); }
386 output->SetSlice(inputReadAccessor.GetData());
387 output->GetGeometry()->SetSpacing(image->GetGeometry()->GetSpacing());
390 std::string calibrationKey = this->GetIdentifierForCurrentCalibration();
391 if (!calibrationKey.empty())
393 std::map<std::string, mitk::AffineTransform3D::Pointer>::iterator calibrationIterator
394 = m_Calibrations.find(calibrationKey);
395 if (calibrationIterator != m_Calibrations.end())
399 this->GetOutput()->GetGeometry()->SetIndexToWorldTransform(calibrationIterator->second);
406 std::stringstream result;
407 result <<
"<calibrations>" << std::endl;
409 for (std::map<std::string, mitk::AffineTransform3D::Pointer>::iterator it = m_Calibrations.begin(); it != m_Calibrations.end(); it++)
411 mitk::AffineTransform3D::MatrixType matrix = it->second->GetMatrix();
412 mitk::AffineTransform3D::TranslationType translation = it->second->GetTranslation();
413 TiXmlElement elem(it->first);
415 elem.SetDoubleAttribute(
"M00", matrix[0][0]);
416 elem.SetDoubleAttribute(
"M01", matrix[0][1]);
417 elem.SetDoubleAttribute(
"M02", matrix[0][2]);
418 elem.SetDoubleAttribute(
"M10", matrix[1][0]);
419 elem.SetDoubleAttribute(
"M11", matrix[1][1]);
420 elem.SetDoubleAttribute(
"M12", matrix[1][2]);
421 elem.SetDoubleAttribute(
"M20", matrix[2][0]);
422 elem.SetDoubleAttribute(
"M21", matrix[2][1]);
423 elem.SetDoubleAttribute(
"M22", matrix[2][2]);
425 elem.SetDoubleAttribute(
"T0", translation[0]);
426 elem.SetDoubleAttribute(
"T1", translation[1]);
427 elem.SetDoubleAttribute(
"T2", translation[2]);
429 result << elem << std::endl;
431 result <<
"</calibrations>" << std::endl;
441 MITK_ERROR <<
"Empty string passed to Deserialize() method of CombinedModality. Aborting...";
442 mitkThrow() <<
"Empty string passed to Deserialize() method of CombinedModality. Aborting...";
446 if (clearPreviousCalibrations) m_Calibrations.clear();
450 if (!doc.Parse(xmlString.c_str()))
452 MITK_ERROR <<
"Unable to deserialize calibrations in CombinedModality. Error was: " << doc.ErrorDesc();
453 mitkThrow() <<
"Unable to deserialize calibrations in CombinedModality. Error was: " << doc.ErrorDesc();
456 TiXmlElement* root = doc.FirstChildElement();
459 MITK_ERROR <<
"Unable to deserialize calibrations in CombinedModality. String contained no root element.";
460 mitkThrow() <<
"Unable to deserialize calibrations in CombinedModality. String contained no root element.";
464 for (TiXmlElement* elem = root->FirstChildElement(); elem != NULL; elem = elem->NextSiblingElement())
466 mitk::AffineTransform3D::MatrixType matrix;
467 mitk::AffineTransform3D::OffsetType translation;
469 std::string calibName = elem->Value();
472 elem->QueryDoubleAttribute(
"M00", &matrix[0][0]);
473 elem->QueryDoubleAttribute(
"M01", &matrix[0][1]);
474 elem->QueryDoubleAttribute(
"M02", &matrix[0][2]);
475 elem->QueryDoubleAttribute(
"M10", &matrix[1][0]);
476 elem->QueryDoubleAttribute(
"M11", &matrix[1][1]);
477 elem->QueryDoubleAttribute(
"M12", &matrix[1][2]);
478 elem->QueryDoubleAttribute(
"M20", &matrix[2][0]);
479 elem->QueryDoubleAttribute(
"M21", &matrix[2][1]);
480 elem->QueryDoubleAttribute(
"M22", &matrix[2][2]);
483 elem->QueryDoubleAttribute(
"T0", &translation[0]);
484 elem->QueryDoubleAttribute(
"T1", &translation[1]);
485 elem->QueryDoubleAttribute(
"T2", &translation[2]);
488 calibration->SetMatrix(matrix);
489 calibration->SetTranslation(translation);
490 m_Calibrations[calibName] = calibration;
496 return this->GetIdentifierForCurrentProbe()
498 + this->GetCurrentDepthValue();
505 us::ServiceProperties::const_iterator probeIt = usdeviceProperties.find(
506 mitk::USCombinedModality::GetPropertyKeys().US_PROPKEY_PROBES_SELECTED);
510 if (probeIt != usdeviceProperties.end())
512 probeName = (probeIt->second).ToString();
516 std::replace(probeName.begin(), probeName.end(),
'/',
'-');
527 us::ServiceProperties::iterator depthIterator = usdeviceProperties.find(
528 mitk::USCombinedModality::GetPropertyKeys().US_PROPKEY_BMODE_DEPTH);
530 if (depthIterator != usdeviceProperties.end())
532 depth = depthIterator->second.ToString();
544 m_LastFilter = m_TrackingDevice;
546 if (m_NumberOfSmoothingValues > 0)
548 for (
unsigned int i = 0; i < m_TrackingDevice->GetNumberOfOutputs(); i++)
550 m_SmoothingFilter->SetInput(i, m_LastFilter->GetOutput(i));
552 m_LastFilter = m_SmoothingFilter;
555 if (m_DelayCount > 0)
557 for (
unsigned int i = 0; i < m_TrackingDevice->GetNumberOfOutputs(); i++)
559 m_DelayFilter->SetInput(i, m_LastFilter->GetOutput(i));
561 m_LastFilter = m_DelayFilter;
574 props[US_PROPKEY_ID] = uidGen.
GetUID();
575 props[US_PROPKEY_DEVICENAME] = this->
GetName();
576 props[US_PROPKEY_CLASS] = this->GetDeviceClass();
578 m_ServiceProperties = props;
580 m_ServiceRegistration = context->RegisterService(
this, props);
A device holds information about it's model, make and the connected probes. It is the common super cl...
static const std::string US_PROPKEY_DEVICENAME
bool RemoveCalibration()
Removes the calibration data of the currently active depth and probe.
virtual bool OnInitialization() override
Initializes UltrasoundDevice.
itk::SmartPointer< Self > Pointer
void DeserializeCalibration(const std::string &xmlString, bool clearPreviousCalibrations=true)
Deserializes a string provided by a prior call to Serialize(). If the bool flag is true...
virtual std::string GetDeviceClass() override
Returns the Class of the Device.
void RebuildFilterPipeline()
virtual bool OnActivation() override
Activates UltrasoundDevice.
void GenerateData() override
Grabs the next frame from the input. This method is called internally, whenever Update() is invoked b...
bool GetIsCalibratedForCurrentStatus()
NavigationDataDelayFilter.
AffineTransform3D::Pointer GetCalibration()
Getter for calibration data of the currently active depth and probe.
USCombinedModality(USDevice::Pointer usDevice, itk::SmartPointer< NavigationDataSource > trackingDevice, std::string manufacturer="", std::string model="")
virtual ~USCombinedModality()
DataCollection - Class to facilitate loading/accessing structured data.
void SetCalibration(AffineTransform3D::Pointer calibration)
Sets a transformation as calibration data. Calibration data is set for the currently activated probe ...
virtual itk::SmartPointer< USControlInterfaceDoppler > GetControlInterfaceDoppler() override
Wrapper for returning doppler control interface of the UltrasoundDevice.
bool GetContainsAtLeastOneCalibration()
virtual USImageSource::Pointer GetUSImageSource() override
Wrapper for returning USImageSource of the UltrasoundDevice.
static const std::string US_PROPKEY_ID
static const std::string US_PROPKEY_CLASS
virtual void SetSpawnAcquireThread(bool _arg)
void SetNumberOfSmoothingValues(unsigned int numberOfSmoothingValues)
void RegisterAsMicroservice()
virtual itk::SmartPointer< mitk::NavigationDataSource > GetNavigationDataSource()
std::string GetCurrentDepthValue()
virtual itk::SmartPointer< USAbstractControlInterface > GetControlInterfaceCustom() override
Wrapper for returning custom control interface of the UltrasoundDevice.
static const char * DefaultProbeIdentifier
void UnregisterOnService()
Remove this device from the micro service. This method is public for mitk::USCombinedModality, because this devices can be completly removed. This is not possible for API devices, which should be available while their sub module is loaded.
This filter smoothes the navigation data by calculating the mean value of the last few input values a...
virtual itk::SmartPointer< USControlInterfaceProbes > GetControlInterfaceProbes() override
Wrapper for returning probes control interface of the UltrasoundDevice.
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
Connects a mitk::TrackingDevice to a MITK-IGT NavigationData-Filterpipeline.
virtual itk::SmartPointer< USControlInterfaceBMode > GetControlInterfaceBMode() override
Wrapper for returning B mode control interface of the UltrasoundDevice.
static const char * ProbeAndDepthSeperator
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
virtual bool OnDeactivation() override
Deactivates UltrasoundDevice.
std::string GetIdentifierForCurrentCalibration()
static std::string GetName(std::string fileName, std::string suffix)
void SetDelayCount(unsigned int delayCount)
ImageReadAccessor class to get locked read access for a particular image part.
std::string GetIdentifierForCurrentProbe()
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
virtual bool OnConnection() override
Connects UltrasoundDevice.
virtual bool OnDisconnection() override
Disconnects UltrasoundDevice.
static const std::string US_INTERFACE_NAME
These Constants are used in conjunction with Microservices.
static const std::string DeviceClassIdentifier
virtual void OnFreeze(bool) override
Freezes or unfreezes UltrasoundDevice.
std::string SerializeCalibration()
Serializes all contained calibrations into an xml fragment.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.