MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSDevice.h
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13#ifndef mitkUSDevice_h
14#define mitkUSDevice_h
15
16// STL
17#include <condition_variable>
18#include <mutex>
19#include <thread>
20#include <vector>
21
22// MitkUS
23#include "mitkUSProbe.h"
24#include <MitkUSExports.h>
25#include "mitkUSImageSource.h"
26
27// MitkIGTL
29#include "mitkIGTLServer.h"
32
33// MITK
34#include <mitkCommon.h>
35#include <mitkMessage.h>
36#include <mitkImageSource.h>
37
38// ITK
39#include <itkObjectFactory.h>
40
41// Microservices
42#include <mitkServiceInterface.h>
43#include <usServiceRegistration.h>
44#include <usServiceProperties.h>
45
46// DEPRECATED
47#include "mitkUSImageMetadata.h"
48
49namespace itk {
50 template<class T> class SmartPointer;
51}
52
53namespace mitk {
54 class USAbstractControlInterface;
55 class USControlInterfaceBMode;
56 class USControlInterfaceProbes;
57 class USControlInterfaceDoppler;
58
75 class MITKUS_EXPORT USDevice : public mitk::ImageSource
76 {
77 public:
78 enum DeviceStates { State_NoState, State_Initialized, State_Connected, State_Activated };
79
80 mitkClassMacro(USDevice, mitk::ImageSource);
81 itkSetMacro(SpawnAcquireThread, bool);
82 itkGetMacro(SpawnAcquireThread, bool);
83
85 {
90 };
91
100 {
101 const std::string US_INTERFACE_NAME; // Common Interface name of all US Devices. Used to refer to this device via Microservices
102 const std::string US_PROPKEY_MANUFACTURER;
103 const std::string US_PROPKEY_NAME;
104 const std::string US_PROPKEY_COMMENT;
105 const std::string US_PROPKEY_LABEL; // Human readable text represntation of this device
106 const std::string US_PROPKEY_ISCONNECTED; // Whether this device is connected or not.
107 const std::string US_PROPKEY_ISACTIVE; // Whether this device is active or not.
108 const std::string US_PROPKEY_CLASS; // Class Name of this Object
109
110 const std::string US_PROPKEY_PROBES_SELECTED;
111
112 const std::string US_PROPKEY_BMODE_FREQUENCY;
113 const std::string US_PROPKEY_BMODE_POWER;
114 const std::string US_PROPKEY_BMODE_DEPTH;
115 const std::string US_PROPKEY_BMODE_GAIN;
116 const std::string US_PROPKEY_BMODE_REJECTION;
118
120 : US_INTERFACE_NAME("org.mitk.services.UltrasoundDevice"),
121 US_PROPKEY_MANUFACTURER(US_INTERFACE_NAME + ".manufacturer"),
122 US_PROPKEY_NAME(US_INTERFACE_NAME + ".name"),
123 US_PROPKEY_COMMENT(US_INTERFACE_NAME + ".comment"),
124 US_PROPKEY_LABEL(US_INTERFACE_NAME + ".label"),
125 US_PROPKEY_ISCONNECTED(US_INTERFACE_NAME + ".isConnected"),
126 US_PROPKEY_ISACTIVE(US_INTERFACE_NAME + ".isActive"),
127 US_PROPKEY_CLASS(US_INTERFACE_NAME + ".class"),
128 US_PROPKEY_PROBES_SELECTED(US_INTERFACE_NAME + ".probes.selected"),
129 US_PROPKEY_BMODE_FREQUENCY(US_INTERFACE_NAME + ".bmode.frequency"),
130 US_PROPKEY_BMODE_POWER(US_INTERFACE_NAME + ".bmode.power"),
131 US_PROPKEY_BMODE_DEPTH(US_INTERFACE_NAME + ".bmode.depth"),
132 US_PROPKEY_BMODE_GAIN(US_INTERFACE_NAME + ".bmode.gain"),
133 US_PROPKEY_BMODE_REJECTION(US_INTERFACE_NAME + ".bmode.rejection"),
134 US_PROPKEY_BMODE_DYNAMIC_RANGE(US_INTERFACE_NAME + ".bmode.dynamicRange")
135 {}
136 };
137
142 mitkNewMessage2Macro(PropertyChanged, const std::string&, const std::string&);
143
147 static mitk::USDevice::PropertyKeys GetPropertyKeys();
148
156 virtual itk::SmartPointer<USAbstractControlInterface> GetControlInterfaceCustom();
157
165 virtual itk::SmartPointer<USControlInterfaceBMode> GetControlInterfaceBMode();
166
174 virtual itk::SmartPointer<USControlInterfaceProbes> GetControlInterfaceProbes();
175
183 virtual itk::SmartPointer<USControlInterfaceDoppler> GetControlInterfaceDoppler();
184
192 bool Initialize();
193
205 bool Connect();
206
207 void ConnectAsynchron();
208
212 bool Disconnect();
213
219 bool Activate();
220
226 void Deactivate();
227
233 virtual void SetIsFreezed(bool freeze);
234
238 virtual bool GetIsFreezed();
239
240 void PushFilter(AbstractOpenCVImageFilter::Pointer filter);
241 void PushFilterIfNotPushedBefore(AbstractOpenCVImageFilter::Pointer filter);
242 bool RemoveFilter(AbstractOpenCVImageFilter::Pointer filter);
243
248 void ProbeChanged(std::string probename);
249
254 void DepthChanged(double depth);
255
262 void UpdateServiceProperty(std::string key, std::string value);
263 void UpdateServiceProperty(std::string key, double value);
264 void UpdateServiceProperty(std::string key, bool value);
265
266 //########### GETTER & SETTER ##################//
267
271 virtual std::string GetDeviceClass() = 0;
272
276 bool GetIsInitialized();
277
281 bool GetIsActive();
282
287 bool GetIsConnected();
288
289 /* @return Returns the area that will be cropped from the US image. Is disabled / [0,0,0,0] by default. */
291
292 /* @return Returns the size of the m_ImageVector of the ultrasound device.*/
293 unsigned int GetSizeOfImageVector();
294
296 virtual USImageSource::Pointer GetUSImageSource() = 0;
297
299 DEPRECATED(std::string GetDeviceManufacturer());
301 DEPRECATED(std::string GetDeviceModel());
303 DEPRECATED(std::string GetDeviceComment());
304
305 itkGetMacro(Manufacturer, std::string);
306 itkGetMacro(Name, std::string);
307 itkGetMacro(Comment, std::string);
308
309 void SetManufacturer(std::string manufacturer);
310 void SetName(std::string name);
311 void SetComment(std::string comment);
312
314
315 itkGetMacro(ServiceProperties, us::ServiceProperties);
316
317 void GrabImage();
318
324 virtual std::vector<mitk::USProbe::Pointer> GetAllProbes() = 0;
325
329 virtual void DeleteAllProbes() {};
330
336 virtual mitk::USProbe::Pointer GetCurrentProbe() = 0;
337
341 virtual void AddNewProbe(mitk::USProbe::Pointer /*probe*/) {};
342
347 virtual mitk::USProbe::Pointer GetProbeByName(std::string name) = 0;
348
352 virtual void RemoveProbeByName(std::string /*name*/) {};
353
359
363 virtual void SetCurrentProbe(std::string /*probename*/) {};
364
365 virtual void SetSpacing(double xSpacing, double ySpacing);
366
367 protected:
368
369 // Threading-Related
370 std::condition_variable m_FreezeBarrier;
371 std::mutex m_FreezeMutex;
372 std::mutex m_ImageMutex;
373 std::thread m_Thread;
374
375 virtual void SetImageVector(std::vector<mitk::Image::Pointer> vec)
376 {
377 if (this->m_ImageVector != vec)
378 {
379 this->m_ImageVector = vec;
380 this->Modified();
381 }
382 }
383
384 void Acquire();
385 void ConnectThread();
386
387 std::vector<mitk::Image::Pointer> m_ImageVector;
388
389 // Variables to determine if spacing was calibrated and needs to be applied to the incoming images
390 mitk::Vector3D m_Spacing;
391
396 void ProvideViaOIGTL();
397
401 void DisableOIGTL();
402
403 mitk::IGTLServer::Pointer m_IGTLServer;
404 mitk::IGTLMessageProvider::Pointer m_IGTLMessageProvider;
405 mitk::ImageToIGTLMessageFilter::Pointer m_ImageToIGTLMsgFilter;
406
408
410
411 /* @brief defines the area that should be cropped from the US image */
413
419 us::ServiceProperties ConstructServiceProperties();
420
424 void UnregisterOnService();
425
434 virtual bool OnInitialization() = 0;
435
444 virtual bool OnConnection() = 0;
445
454 virtual bool OnDisconnection() = 0;
455
464 virtual bool OnActivation() = 0;
465
474 virtual bool OnDeactivation() = 0;
475
481 virtual void OnFreeze(bool) { }
482
486 USDevice(std::string manufacturer, std::string model);
487
492 USDevice(mitk::USImageMetadata::Pointer metadata);
493
494 ~USDevice() override;
495
500 void GenerateData() override;
501
502 std::string GetServicePropertyLabel();
503
504 unsigned int m_NumberOfOutputs;
505
509 us::ServiceProperties m_ServiceProperties;
510
514 us::ServiceRegistration<Self> m_ServiceRegistration;
515
516
517 private:
518
519 std::string m_Manufacturer;
520 std::string m_Name;
521 std::string m_Comment;
522
523 bool m_SpawnAcquireThread;
524
525 bool m_UnregisteringStarted;
526 };
527} // namespace mitk
528
529// This is the microservice declaration. Do not meddle!
530MITK_DECLARE_SERVICE_INTERFACE(mitk::USDevice, "org.mitk.services.UltrasoundDevice")
531
532#endif
A device holds information about it's model, make and the connected probes. It is the common super cl...
virtual void SetCurrentProbe(std::string)
Sets the probe with the given name as current probe if the named probe exists.
std::mutex m_ImageMutex
mutex for images provided by the image source
std::vector< mitk::Image::Pointer > m_ImageVector
virtual mitk::USProbe::Pointer GetCurrentProbe()=0
Return current active probe for this USDevice Returns a pointer to the probe that is currently in use...
std::thread m_Thread
virtual void AddNewProbe(mitk::USProbe::Pointer)
adds a new probe to the device
itkGetMacro(DeviceState, DeviceStates)
DEPRECATED(std::string GetDeviceComment())
Deprecated -> use GetCommend() instead.
itkGetMacro(Manufacturer, std::string)
virtual void RemoveProbeByName(std::string)
Removes the Probe with the given name.
DEPRECATED(std::string GetDeviceModel())
Deprecated -> use GetName() instead.
virtual bool OnDisconnection()=0
Is called during the disconnection process. Override this method in a subclass to handle the actual d...
DeviceStates m_DeviceState
virtual USImageSource::Pointer GetUSImageSource()=0
virtual void DeleteAllProbes()
Cleans the std::vector containing all configured probes.
mitkNewMessage2Macro(PropertyChanged, const std::string &, const std::string &)
Event for being notified about changes of the micro service properties. This event can be used if no ...
USImageCropArea m_CropArea
virtual void SetImageVector(std::vector< mitk::Image::Pointer > vec)
itkGetMacro(ServiceProperties, us::ServiceProperties)
us::ServiceRegistration< Self > m_ServiceRegistration
The device's ServiceRegistration object that allows to modify it's Microservice registraton details.
virtual mitk::USProbe::Pointer GetProbeByName(std::string name)=0
get the probe by its name Returns a pointer to the probe identified by the given name....
us::ServiceProperties m_ServiceProperties
Properties of the device's Microservice.
itkGetMacro(Comment, std::string)
std::condition_variable m_FreezeBarrier
mitkClassMacro(USDevice, mitk::ImageSource)
virtual bool OnConnection()=0
Is called during the connection process. Override this method in a subclass to handle the actual conn...
itkGetMacro(Name, std::string)
mitk::Vector3D m_Spacing
virtual void OnFreeze(bool)
Called when mitk::USDevice::SetIsFreezed() is called. Subclasses can overwrite this method to do addi...
mitk::IGTLMessageProvider::Pointer m_IGTLMessageProvider
itkGetMacro(SpawnAcquireThread, bool)
std::mutex m_FreezeMutex
virtual bool OnInitialization()=0
Is called during the initialization process. Override this method in a subclass to handle the actual ...
mitk::ImageToIGTLMessageFilter::Pointer m_ImageToIGTLMsgFilter
mitk::IGTLServer::Pointer m_IGTLServer
itkSetMacro(SpawnAcquireThread, bool)
virtual std::string GetDeviceClass()=0
Returns the Class of the Device. This Method must be reimplemented by every Inheriting Class.
virtual bool OnActivation()=0
Is called during the activation process. After this method is finished, the device should be generati...
unsigned int m_NumberOfOutputs
virtual bool OnDeactivation()=0
Is called during the deactivation process. After a call to this method the device should still be con...
DEPRECATED(std::string GetDeviceManufacturer())
Deprecated -> use GetManufacturer() instead.
virtual std::vector< mitk::USProbe::Pointer > GetAllProbes()=0
Returns all probes for this device or an empty vector it no probes were set Returns a std::vector of ...
virtual void SetDefaultProbeAsCurrentProbe()
Sets the first existing probe or the default probe of the ultrasound device as the current probe of i...
IGT Exceptions.
These constants are used in conjunction with Microservices. The constants aren't defined as static me...
const std::string US_PROPKEY_CLASS
const std::string US_PROPKEY_ISACTIVE
const std::string US_PROPKEY_BMODE_GAIN
const std::string US_PROPKEY_COMMENT
const std::string US_PROPKEY_BMODE_DEPTH
const std::string US_INTERFACE_NAME
const std::string US_PROPKEY_ISCONNECTED
const std::string US_PROPKEY_BMODE_POWER
const std::string US_PROPKEY_MANUFACTURER
const std::string US_PROPKEY_NAME
const std::string US_PROPKEY_BMODE_DYNAMIC_RANGE
const std::string US_PROPKEY_PROBES_SELECTED
const std::string US_PROPKEY_BMODE_REJECTION
const std::string US_PROPKEY_LABEL
const std::string US_PROPKEY_BMODE_FREQUENCY