39 MITK_INFO <<
"Return Crop Area L:" << m_CropArea.cropLeft
40 <<
" R:" << m_CropArea.cropRight <<
" T:" << m_CropArea.cropTop
41 <<
" B:" << m_CropArea.cropBottom;
48 m_DeviceState(State_NoState),
49 m_Manufacturer(manufacturer),
51 m_SpawnAcquireThread(true),
52 m_MultiThreader(
itk::MultiThreader::
New()),
53 m_ImageMutex(
itk::FastMutexLock::
New()),
55 m_UnregisteringStarted(false)
65 this->SetNumberOfIndexedOutputs(1);
69 this->SetNthOutput(0, newOutput);
75 m_DeviceState(State_NoState),
76 m_SpawnAcquireThread(true),
77 m_MultiThreader(
itk::MultiThreader::
New()),
78 m_ImageMutex(
itk::FastMutexLock::
New()),
80 m_UnregisteringStarted(false)
82 m_Manufacturer = metadata->GetDeviceManufacturer();
83 m_Name = metadata->GetDeviceModel();
84 m_Comment = metadata->GetDeviceComment();
94 this->SetNumberOfIndexedOutputs(1);
98 this->SetNthOutput(0, newOutput);
105 m_MultiThreader->TerminateThread(m_ThreadID);
110 this->UnregisterOnService();
116 MITK_INFO <<
"Custom control interface does not exist for this object.";
123 MITK_INFO <<
"Control interface BMode does not exist for this object.";
130 MITK_INFO <<
"Control interface Probes does not exist for this object.";
137 MITK_INFO <<
"Control interface Doppler does not exist for this object.";
143 m_Manufacturer = manufacturer;
144 if (m_DeviceState >= State_Initialized)
146 this->UpdateServiceProperty(
147 mitk::USDevice::GetPropertyKeys().US_PROPKEY_MANUFACTURER,
155 if (m_DeviceState >= State_Initialized)
157 this->UpdateServiceProperty(
158 mitk::USDevice::GetPropertyKeys().US_PROPKEY_NAME, name);
165 if (m_DeviceState >= State_Initialized)
167 this->UpdateServiceProperty(
168 mitk::USDevice::GetPropertyKeys().US_PROPKEY_COMMENT, comment);
179 this->GetIsConnected() ?
"true" :
"false";
181 this->GetIsActive() ?
"true" :
"false";
187 this->GetControlInterfaceProbes();
188 if (probesControls.IsNotNull() && probesControls->GetIsActive())
191 if (probe.IsNotNull())
202 m_ServiceProperties = props;
210 if (m_ServiceRegistration && !m_UnregisteringStarted)
214 m_UnregisteringStarted =
true;
215 m_ServiceRegistration.Unregister();
216 m_ServiceRegistration = 0;
222 if (!this->OnInitialization())
227 m_DeviceState = State_Initialized;
233 m_ServiceRegistration = context->RegisterService(
this, props);
240 MITK_DEBUG <<
"mitk::USDevice::Connect() called";
242 if (this->GetIsConnected())
244 MITK_INFO(
"mitkUSDevice") <<
"Tried to connect an ultrasound device that "
245 "was already connected. Ignoring call...";
249 if (!this->GetIsInitialized())
252 <<
"Cannot connect device if it is not in initialized state.";
257 if (!this->OnConnection())
263 m_DeviceState = State_Connected;
265 this->UpdateServiceProperty(
266 mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISCONNECTED,
true);
272 this->m_MultiThreader->SpawnThread(this->ConnectThread,
this);
277 if (!GetIsConnected())
279 MITK_WARN <<
"Tried to disconnect an ultrasound device that was not "
280 "connected. Ignoring call...";
284 if (!this->OnDisconnection())
288 m_DeviceState = State_Initialized;
290 this->UpdateServiceProperty(
291 mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISCONNECTED,
false);
298 if (!this->GetIsConnected())
301 <<
"Cannot activate device if it is not in connected state.";
307 m_DeviceState = State_Activated;
312 if (m_SpawnAcquireThread)
315 this->m_MultiThreader->SpawnThread(this->Acquire,
this);
318 this->UpdateServiceProperty(
319 mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISACTIVE,
true);
320 this->UpdateServiceProperty(
321 mitk::USDevice::GetPropertyKeys().US_PROPKEY_LABEL,
322 this->GetServicePropertyLabel());
325 this->GetControlInterfaceBMode();
326 if (bmodeControls.IsNotNull())
328 bmodeControls->Initialize();
332 this->ProvideViaOIGTL();
334 return m_DeviceState == State_Activated;
340 if (m_IGTLServer.IsNull())
343 m_IGTLServer->SetName(this->
GetName());
346 if (m_IGTLMessageProvider.IsNull())
350 m_IGTLMessageProvider->SetIGTLDevice(m_IGTLServer);
354 m_IGTLMessageProvider->RegisterAsMicroservice();
357 m_ImageToIGTLMsgFilter->ConnectTo(
this);
360 m_ImageToIGTLMsgFilter->SetName(this->
GetName());
366 m_ImageToIGTLMsgFilter->RegisterAsMicroservice();
371 if (!this->GetIsActive())
374 <<
"Cannot deactivate a device which is not activae.";
378 if (!OnDeactivation())
384 m_DeviceState = State_Connected;
386 this->UpdateServiceProperty(
387 mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISACTIVE,
false);
388 this->UpdateServiceProperty(
389 mitk::USDevice::GetPropertyKeys().US_PROPKEY_LABEL,
390 this->GetServicePropertyLabel());
397 m_IGTLServer->CloseConnection();
398 m_IGTLMessageProvider->UnRegisterMicroservice();
399 m_ImageToIGTLMsgFilter->UnRegisterMicroservice();
404 if (!this->GetIsActive())
407 <<
"Cannot freeze or unfreeze if device is not active.";
411 this->OnFreeze(freeze);
422 m_FreezeBarrier->Signal();
428 if (!this->GetIsActive())
430 MITK_WARN(
"mitkUSDevice")(
"mitkUSTelemedDevice")
431 <<
"Cannot get freeze state if the hardware interface is not ready. "
432 "Returning false...";
442 if (imageSource.IsNull())
444 MITK_ERROR <<
"ImageSource must not be null when pushing a filter.";
445 mitkThrow() <<
"ImageSource must not be null when pushing a filter.";
448 imageSource->PushFilter(filter);
455 if (imageSource.IsNull())
457 MITK_ERROR <<
"ImageSource must not be null when pushing a filter.";
458 mitkThrow() <<
"ImageSource must not be null when pushing a filter.";
461 if (!imageSource->GetIsFilterInThePipeline(filter))
463 imageSource->PushFilter(filter);
470 if (imageSource.IsNull())
472 MITK_ERROR <<
"ImageSource must not be null when pushing a filter.";
473 mitkThrow() <<
"ImageSource must not be null when removing a filter.";
476 return imageSource->RemoveFilter(filter);
481 m_ServiceProperties[key] = value;
482 m_ServiceRegistration.SetProperties(m_ServiceProperties);
485 m_PropertyChangedMessage(key, value);
490 std::stringstream stream;
492 this->UpdateServiceProperty(key, stream.str());
497 this->UpdateServiceProperty(
498 key, value ? std::string(
"true") : std::string(
"false"));
549 m_ImageMutex->Lock();
550 this->SetImage(image);
551 m_ImageMutex->Unlock();
560 return m_DeviceState == State_Initialized;
567 return m_DeviceState == State_Connected;
578 m_ImageMutex->Lock();
580 if (m_Image.IsNull() || !m_Image->IsInitialized())
582 m_ImageMutex->Unlock();
588 if (!output->IsInitialized() ||
589 output->GetDimension(0) != m_Image->GetDimension(0) ||
590 output->GetDimension(1) != m_Image->GetDimension(1))
592 output->Initialize(m_Image->GetPixelType(), m_Image->GetDimension(),
593 m_Image->GetDimensions());
597 m_Image->GetSliceData(0, 0, 0));
598 output->SetSlice(inputReadAccessor.GetData());
599 output->SetGeometry(m_Image->GetGeometry());
600 m_ImageMutex->Unlock();
605 std::string isActive;
606 if (this->GetIsActive())
608 isActive =
" (Active)";
612 isActive =
" (Inactive)";
615 return m_Manufacturer +
" " + m_Name + isActive;
621 struct itk::MultiThreader::ThreadInfoStruct* pInfo =
622 (
struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct;
629 itk::SimpleMutexLock* mutex = &(device->m_FreezeMutex);
632 if (device->m_FreezeBarrier.IsNotNull())
634 device->m_FreezeBarrier->Wait(mutex);
640 return ITK_THREAD_RETURN_VALUE;
646 struct itk::MultiThreader::ThreadInfoStruct* pInfo =
647 (
struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct;
652 return ITK_THREAD_RETURN_VALUE;
658 this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_PROBES_SELECTED, probename);
663 this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_BMODE_DEPTH, depth);
virtual itk::SmartPointer< USControlInterfaceBMode > GetControlInterfaceBMode()
Default getter for the b mode control interface. Has to be implemented in a subclass if a b mode cont...
Superclass of all classes generating Images (instances of class Image) as output. ...
bool Activate()
Activates this device. After the activation process, the device will start to produce images...
A device holds information about it's model, make and the connected probes. It is the common super cl...
void UpdateServiceProperty(std::string key, std::string value)
Given property is updated in the device micro service. This method is mainly for being used by the co...
static ITK_THREAD_RETURN_TYPE Acquire(void *pInfoStruct)
itk::SmartPointer< Self > Pointer
std::string GetDeviceComment()
Deprecated -> use GetCommend() instead.
void PushFilterIfNotPushedBefore(AbstractOpenCVImageFilter::Pointer filter)
USImageCropArea m_CropArea
const std::string US_PROPKEY_LABEL
us::ServiceProperties ConstructServiceProperties()
This Method constructs the service properties which can later be used to register the object with the...
DataCollection - Class to facilitate loading/accessing structured data.
const std::string US_PROPKEY_ISCONNECTED
void DisableOIGTL()
Deregisters the microservices for OpenIGTLink.
bool Connect()
Connects this device. A connected device is ready to deliver images (i.e. be Activated). A Connected Device can be active. A disconnected Device cannot be active. Internally calls onConnect and then registers the device with the service. A device usually should override the OnConnection() method, but never the Connect() method, since this will possibly exclude the device from normal service management. The exact flow of events is: 0. Check if the device is already connected. If yes, return true anyway, but don't do anything.
bool GetIsConnected()
True, if the device is currently ready to start transmitting image data or is already transmitting im...
std::string GetDeviceManufacturer()
Deprecated -> use GetManufacturer() instead.
mitk::USDevice::USImageCropArea GetCropArea()
void ProbeChanged(std::string probename)
To be called when the used probe changed. Will update the service properties.
virtual itk::SmartPointer< USControlInterfaceDoppler > GetControlInterfaceDoppler()
Default getter for the doppler control interface. Has to be implemented in a subclass if a doppler co...
void DepthChanged(double depth)
To be called when the scanning depth of the probe changed. Will update the service properties...
const std::string US_PROPKEY_CLASS
void SetComment(std::string comment)
std::string GetDeviceModel()
Deprecated -> use GetName() instead.
These constants are used in conjunction with Microservices. The constants aren't defined as static me...
void SetManufacturer(std::string manufacturer)
virtual void SetIsFreezed(bool freeze)
Can toggle if ultrasound image is currently updated or freezed.
const std::string US_PROPKEY_PROBES_SELECTED
USDevice(std::string manufacturer, std::string model)
Enforces minimal Metadata to be set.
bool Initialize()
Changes device state to mitk::USDevice::State_Initialized. During initialization the virtual method m...
void UnregisterOnService()
Remove this device from the micro service.
const std::string US_PROPKEY_MANUFACTURER
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
void SetName(std::string name)
virtual bool GetIsFreezed()
void Deactivate()
Deactivates this device. After the deactivation process, the device will no longer produce images...
static std::string GetName(std::string fileName, std::string suffix)
virtual void GenerateData() override
Grabs the next frame from the Video input. This method is called internally, whenever Update() is inv...
const std::string US_PROPKEY_ISACTIVE
bool GetIsInitialized()
True, if the device object is created and initialized, false otherwise.
const std::string US_PROPKEY_NAME
static ITK_THREAD_RETURN_TYPE ConnectThread(void *pInfoStruct)
ImageReadAccessor class to get locked read access for a particular image part.
void PushFilter(AbstractOpenCVImageFilter::Pointer filter)
bool GetIsActive()
True, if the device is currently generating image data, false otherwise.
void ProvideViaOIGTL()
Registers an OpenIGTLink device as a microservice so that we can send the images of this device via t...
virtual mitkNewMessage2Macro(PropertyChanged, const std::string &, const std::string &) static mitk itk::SmartPointer< USAbstractControlInterface > GetControlInterfaceCustom()
Event for being notified about changes of the micro service properties. This event can be used if no ...
bool Disconnect()
Works analogously to mitk::USDevice::Connect(). Don't override this Method, but onDisconnection inste...
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
const std::string US_PROPKEY_COMMENT
bool RemoveFilter(AbstractOpenCVImageFilter::Pointer filter)
std::string GetServicePropertyLabel()
virtual itk::SmartPointer< USControlInterfaceProbes > GetControlInterfaceProbes()
Default getter for the probes control interface. Has to be implemented in a subclass if a probes cont...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.