Medical Imaging Interaction Toolkit  2022.04.99-b2814023
Medical Imaging Interaction Toolkit
mitkUSDevice.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef MITKUSDevice_H_HEADER_INCLUDED_
14 #define MITKUSDevice_H_HEADER_INCLUDED_
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"
30 #include "mitkIGTLDeviceSource.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 
49 namespace itk {
50  template<class T> class SmartPointer;
51 }
52 
53 namespace mitk {
54  class USAbstractControlInterface;
55  class USControlInterfaceBMode;
56  class USControlInterfaceProbes;
57  class USControlInterfaceDoppler;
58 
76  {
77  public:
78  enum DeviceStates { State_NoState, State_Initialized, State_Connected, State_Activated };
79 
81  itkSetMacro(SpawnAcquireThread, bool);
82  itkGetMacro(SpawnAcquireThread, bool);
83 
85  {
86  int cropLeft;
87  int cropRight;
89  int cropTop;
90  };
91 
99  struct PropertyKeys
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. */
290  mitk::USDevice::USImageCropArea GetCropArea();
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 
313  itkGetMacro(DeviceState, DeviceStates);
314 
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 
358  virtual void SetDefaultProbeAsCurrentProbe() {};
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
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 
510 
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!
530 MITK_DECLARE_SERVICE_INTERFACE(mitk::USDevice, "org.mitk.services.UltrasoundDevice")
531 
532 #endif // MITKUSDevice_H_HEADER_INCLUDED_
Superclass of all classes generating Images (instances of class Image) as output. ...
#define MITK_DECLARE_SERVICE_INTERFACE(IFace, IId)
A device holds information about it&#39;s model, make and the connected probes. It is the common super cl...
Definition: mitkUSDevice.h:75
std::condition_variable m_FreezeBarrier
Definition: mitkUSDevice.h:370
mitk::IGTLMessageProvider::Pointer m_IGTLMessageProvider
Definition: mitkUSDevice.h:404
virtual void SetCurrentProbe(std::string)
Sets the probe with the given name as current probe if the named probe exists.
Definition: mitkUSDevice.h:363
virtual void RemoveProbeByName(std::string)
Removes the Probe with the given name.
Definition: mitkUSDevice.h:352
USImageCropArea m_CropArea
Definition: mitkUSDevice.h:412
const std::string US_PROPKEY_LABEL
Definition: mitkUSDevice.h:105
const std::string US_INTERFACE_NAME
Definition: mitkUSDevice.h:101
const std::string US_PROPKEY_BMODE_FREQUENCY
Definition: mitkUSDevice.h:112
DataCollection - Class to facilitate loading/accessing structured data.
const std::string US_PROPKEY_ISCONNECTED
Definition: mitkUSDevice.h:106
virtual void DeleteAllProbes()
Cleans the std::vector containing all configured probes.
Definition: mitkUSDevice.h:329
std::thread m_Thread
Definition: mitkUSDevice.h:373
mitk::IGTLServer::Pointer m_IGTLServer
Definition: mitkUSDevice.h:403
std::mutex m_FreezeMutex
Definition: mitkUSDevice.h:371
const std::string US_PROPKEY_BMODE_POWER
Definition: mitkUSDevice.h:113
const std::string US_PROPKEY_BMODE_REJECTION
Definition: mitkUSDevice.h:116
virtual void SetDefaultProbeAsCurrentProbe()
Sets the first existing probe or the default probe of the ultrasound device as the current probe of i...
Definition: mitkUSDevice.h:358
#define DEPRECATED(func)
Definition: mitkCommon.h:175
const std::string US_PROPKEY_BMODE_GAIN
Definition: mitkUSDevice.h:115
const std::string US_PROPKEY_CLASS
Definition: mitkUSDevice.h:108
mitk::ImageToIGTLMessageFilter::Pointer m_ImageToIGTLMsgFilter
Definition: mitkUSDevice.h:405
const std::string US_PROPKEY_BMODE_DEPTH
Definition: mitkUSDevice.h:114
These constants are used in conjunction with Microservices. The constants aren&#39;t defined as static me...
Definition: mitkUSDevice.h:99
mitk::Vector3D m_Spacing
Definition: mitkUSDevice.h:390
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
const std::string US_PROPKEY_PROBES_SELECTED
Definition: mitkUSDevice.h:110
us::ServiceRegistration< Self > m_ServiceRegistration
The device&#39;s ServiceRegistration object that allows to modify it&#39;s Microservice registraton details...
Definition: mitkUSDevice.h:514
us::ServiceProperties m_ServiceProperties
Properties of the device&#39;s Microservice.
Definition: mitkUSDevice.h:509
virtual void SetImageVector(std::vector< mitk::Image::Pointer > vec)
Definition: mitkUSDevice.h:375
const std::string US_PROPKEY_MANUFACTURER
Definition: mitkUSDevice.h:102
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
unsigned int m_NumberOfOutputs
Definition: mitkUSDevice.h:504
std::vector< mitk::Image::Pointer > m_ImageVector
Definition: mitkUSDevice.h:387
std::mutex m_ImageMutex
mutex for images provided by the image source
Definition: mitkUSDevice.h:372
DeviceStates m_DeviceState
Definition: mitkUSDevice.h:409
#define MITKUS_EXPORT
Definition: MitkUSExports.h:15
virtual void OnFreeze(bool)
Called when mitk::USDevice::SetIsFreezed() is called. Subclasses can overwrite this method to do addi...
Definition: mitkUSDevice.h:481
const std::string US_PROPKEY_ISACTIVE
Definition: mitkUSDevice.h:107
const std::string US_PROPKEY_NAME
Definition: mitkUSDevice.h:103
#define mitkNewMessage2Macro(msgHandleObject, type1, type2)
Definition: mitkMessage.h:66
const std::string US_PROPKEY_BMODE_DYNAMIC_RANGE
Definition: mitkUSDevice.h:117
const std::string US_PROPKEY_COMMENT
Definition: mitkUSDevice.h:104
virtual void AddNewProbe(mitk::USProbe::Pointer)
adds a new probe to the device
Definition: mitkUSDevice.h:341