Medical Imaging Interaction Toolkit  2018.4.99-c0f884b2
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 <vector>
18 
19 // MitkUS
20 #include "mitkUSProbe.h"
21 #include <MitkUSExports.h>
22 #include "mitkUSImageSource.h"
23 
24 // MitkIGTL
26 #include "mitkIGTLServer.h"
27 #include "mitkIGTLDeviceSource.h"
29 
30 // MITK
31 #include <mitkCommon.h>
32 #include <mitkMessage.h>
33 #include <mitkImageSource.h>
34 
35 // ITK
36 #include <itkObjectFactory.h>
37 #include <itkConditionVariable.h>
38 
39 // Microservices
40 #include <mitkServiceInterface.h>
41 #include <usServiceRegistration.h>
42 #include <usServiceProperties.h>
43 
44 // DEPRECATED
45 #include "mitkUSImageMetadata.h"
46 
47 namespace itk {
48  template<class T> class SmartPointer;
49 }
50 
51 namespace mitk {
52  class USAbstractControlInterface;
53  class USControlInterfaceBMode;
54  class USControlInterfaceProbes;
55  class USControlInterfaceDoppler;
56 
74  {
75  public:
76  enum DeviceStates { State_NoState, State_Initialized, State_Connected, State_Activated };
77 
79  itkSetMacro(SpawnAcquireThread, bool);
80  itkGetMacro(SpawnAcquireThread, bool);
81 
83  {
84  int cropLeft;
85  int cropRight;
87  int cropTop;
88  };
89 
97  struct PropertyKeys
98  {
99  const std::string US_INTERFACE_NAME; // Common Interface name of all US Devices. Used to refer to this device via Microservices
100  const std::string US_PROPKEY_MANUFACTURER;
101  const std::string US_PROPKEY_NAME;
102  const std::string US_PROPKEY_COMMENT;
103  const std::string US_PROPKEY_LABEL; // Human readable text represntation of this device
104  const std::string US_PROPKEY_ISCONNECTED; // Whether this device is connected or not.
105  const std::string US_PROPKEY_ISACTIVE; // Whether this device is active or not.
106  const std::string US_PROPKEY_CLASS; // Class Name of this Object
107 
108  const std::string US_PROPKEY_PROBES_SELECTED;
109 
110  const std::string US_PROPKEY_BMODE_FREQUENCY;
111  const std::string US_PROPKEY_BMODE_POWER;
112  const std::string US_PROPKEY_BMODE_DEPTH;
113  const std::string US_PROPKEY_BMODE_GAIN;
114  const std::string US_PROPKEY_BMODE_REJECTION;
116 
118  : US_INTERFACE_NAME("org.mitk.services.UltrasoundDevice"),
119  US_PROPKEY_MANUFACTURER(US_INTERFACE_NAME + ".manufacturer"),
120  US_PROPKEY_NAME(US_INTERFACE_NAME + ".name"),
121  US_PROPKEY_COMMENT(US_INTERFACE_NAME + ".comment"),
122  US_PROPKEY_LABEL(US_INTERFACE_NAME + ".label"),
123  US_PROPKEY_ISCONNECTED(US_INTERFACE_NAME + ".isConnected"),
124  US_PROPKEY_ISACTIVE(US_INTERFACE_NAME + ".isActive"),
125  US_PROPKEY_CLASS(US_INTERFACE_NAME + ".class"),
126  US_PROPKEY_PROBES_SELECTED(US_INTERFACE_NAME + ".probes.selected"),
127  US_PROPKEY_BMODE_FREQUENCY(US_INTERFACE_NAME + ".bmode.frequency"),
128  US_PROPKEY_BMODE_POWER(US_INTERFACE_NAME + ".bmode.power"),
129  US_PROPKEY_BMODE_DEPTH(US_INTERFACE_NAME + ".bmode.depth"),
130  US_PROPKEY_BMODE_GAIN(US_INTERFACE_NAME + ".bmode.gain"),
131  US_PROPKEY_BMODE_REJECTION(US_INTERFACE_NAME + ".bmode.rejection"),
132  US_PROPKEY_BMODE_DYNAMIC_RANGE(US_INTERFACE_NAME + ".bmode.dynamicRange")
133  {}
134  };
135 
140  mitkNewMessage2Macro(PropertyChanged, const std::string&, const std::string&);
141 
145  static mitk::USDevice::PropertyKeys GetPropertyKeys();
146 
154  virtual itk::SmartPointer<USAbstractControlInterface> GetControlInterfaceCustom();
155 
163  virtual itk::SmartPointer<USControlInterfaceBMode> GetControlInterfaceBMode();
164 
172  virtual itk::SmartPointer<USControlInterfaceProbes> GetControlInterfaceProbes();
173 
181  virtual itk::SmartPointer<USControlInterfaceDoppler> GetControlInterfaceDoppler();
182 
190  bool Initialize();
191 
203  bool Connect();
204 
205  void ConnectAsynchron();
206 
210  bool Disconnect();
211 
217  bool Activate();
218 
224  void Deactivate();
225 
231  virtual void SetIsFreezed(bool freeze);
232 
236  virtual bool GetIsFreezed();
237 
238  void PushFilter(AbstractOpenCVImageFilter::Pointer filter);
239  void PushFilterIfNotPushedBefore(AbstractOpenCVImageFilter::Pointer filter);
240  bool RemoveFilter(AbstractOpenCVImageFilter::Pointer filter);
241 
246  void ProbeChanged(std::string probename);
247 
252  void DepthChanged(double depth);
253 
260  void UpdateServiceProperty(std::string key, std::string value);
261  void UpdateServiceProperty(std::string key, double value);
262  void UpdateServiceProperty(std::string key, bool value);
263 
264  //########### GETTER & SETTER ##################//
265 
269  virtual std::string GetDeviceClass() = 0;
270 
274  bool GetIsInitialized();
275 
279  bool GetIsActive();
280 
285  bool GetIsConnected();
286 
287  /* @return Returns the area that will be cropped from the US image. Is disabled / [0,0,0,0] by default. */
288  mitk::USDevice::USImageCropArea GetCropArea();
289 
290  /* @return Returns the size of the m_ImageVector of the ultrasound device.*/
291  unsigned int GetSizeOfImageVector();
292 
294  virtual USImageSource::Pointer GetUSImageSource() = 0;
295 
297  DEPRECATED(std::string GetDeviceManufacturer());
299  DEPRECATED(std::string GetDeviceModel());
301  DEPRECATED(std::string GetDeviceComment());
302 
303  itkGetMacro(Manufacturer, std::string);
304  itkGetMacro(Name, std::string);
305  itkGetMacro(Comment, std::string);
306 
307  void SetManufacturer(std::string manufacturer);
308  void SetName(std::string name);
309  void SetComment(std::string comment);
310 
311  itkGetMacro(DeviceState, DeviceStates);
312 
314 
315  void GrabImage();
316 
322  virtual std::vector<mitk::USProbe::Pointer> GetAllProbes() = 0;
323 
327  virtual void DeleteAllProbes() {};
328 
334  virtual mitk::USProbe::Pointer GetCurrentProbe() = 0;
335 
339  virtual void AddNewProbe(mitk::USProbe::Pointer /*probe*/) {};
340 
345  virtual mitk::USProbe::Pointer GetProbeByName(std::string name) = 0;
346 
350  virtual void RemoveProbeByName(std::string /*name*/) {};
351 
356  virtual void SetDefaultProbeAsCurrentProbe() {};
357 
361  virtual void SetCurrentProbe(std::string /*probename*/) {};
362 
363  virtual void SetSpacing(double xSpacing, double ySpacing);
364 
365  protected:
366 
367  // Threading-Related
368  itk::ConditionVariable::Pointer m_FreezeBarrier;
369  itk::SimpleMutexLock m_FreezeMutex;
370  itk::MultiThreader::Pointer m_MultiThreader;
371  itk::FastMutexLock::Pointer m_ImageMutex;
373 
374  virtual void SetImageVector(std::vector<mitk::Image::Pointer> vec)
375  {
376  if (this->m_ImageVector != vec)
377  {
378  this->m_ImageVector = vec;
379  this->Modified();
380  }
381  }
382 
383  static ITK_THREAD_RETURN_TYPE Acquire(void* pInfoStruct);
384  static ITK_THREAD_RETURN_TYPE ConnectThread(void* pInfoStruct);
385 
386  std::vector<mitk::Image::Pointer> m_ImageVector;
387 
388  // Variables to determine if spacing was calibrated and needs to be applied to the incoming images
390 
395  void ProvideViaOIGTL();
396 
400  void DisableOIGTL();
401 
402  mitk::IGTLServer::Pointer m_IGTLServer;
403  mitk::IGTLMessageProvider::Pointer m_IGTLMessageProvider;
404  mitk::ImageToIGTLMessageFilter::Pointer m_ImageToIGTLMsgFilter;
405 
407 
409 
410  /* @brief defines the area that should be cropped from the US image */
412 
418  us::ServiceProperties ConstructServiceProperties();
419 
423  void UnregisterOnService();
424 
433  virtual bool OnInitialization() = 0;
434 
443  virtual bool OnConnection() = 0;
444 
453  virtual bool OnDisconnection() = 0;
454 
463  virtual bool OnActivation() = 0;
464 
473  virtual bool OnDeactivation() = 0;
474 
480  virtual void OnFreeze(bool) { }
481 
485  USDevice(std::string manufacturer, std::string model);
486 
491  USDevice(mitk::USImageMetadata::Pointer metadata);
492 
493  ~USDevice() override;
494 
499  void GenerateData() override;
500 
501  std::string GetServicePropertyLabel();
502 
503  unsigned int m_NumberOfOutputs;
504 
509 
514 
515 
516  private:
517 
518  std::string m_Manufacturer;
519  std::string m_Name;
520  std::string m_Comment;
521 
522  bool m_SpawnAcquireThread;
523 
524  bool m_UnregisteringStarted;
525  };
526 } // namespace mitk
527 
528 // This is the microservice declaration. Do not meddle!
529 MITK_DECLARE_SERVICE_INTERFACE(mitk::USDevice, "org.mitk.services.UltrasoundDevice")
530 
531 #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:73
mitk::IGTLMessageProvider::Pointer m_IGTLMessageProvider
Definition: mitkUSDevice.h:403
virtual void SetCurrentProbe(std::string)
Sets the probe with the given name as current probe if the named probe exists.
Definition: mitkUSDevice.h:361
virtual void RemoveProbeByName(std::string)
Removes the Probe with the given name.
Definition: mitkUSDevice.h:350
USImageCropArea m_CropArea
Definition: mitkUSDevice.h:411
const std::string US_PROPKEY_LABEL
Definition: mitkUSDevice.h:103
const std::string US_INTERFACE_NAME
Definition: mitkUSDevice.h:99
const std::string US_PROPKEY_BMODE_FREQUENCY
Definition: mitkUSDevice.h:110
DataCollection - Class to facilitate loading/accessing structured data.
const std::string US_PROPKEY_ISCONNECTED
Definition: mitkUSDevice.h:104
virtual void DeleteAllProbes()
Cleans the std::vector containing all configured probes.
Definition: mitkUSDevice.h:327
itk::ConditionVariable::Pointer m_FreezeBarrier
Definition: mitkUSDevice.h:368
mitk::IGTLServer::Pointer m_IGTLServer
Definition: mitkUSDevice.h:402
const std::string US_PROPKEY_BMODE_POWER
Definition: mitkUSDevice.h:111
const std::string US_PROPKEY_BMODE_REJECTION
Definition: mitkUSDevice.h:114
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:356
#define DEPRECATED(func)
Definition: mitkCommon.h:179
const std::string US_PROPKEY_BMODE_GAIN
Definition: mitkUSDevice.h:113
const std::string US_PROPKEY_CLASS
Definition: mitkUSDevice.h:106
mitk::ImageToIGTLMessageFilter::Pointer m_ImageToIGTLMsgFilter
Definition: mitkUSDevice.h:404
const std::string US_PROPKEY_BMODE_DEPTH
Definition: mitkUSDevice.h:112
These constants are used in conjunction with Microservices. The constants aren&#39;t defined as static me...
Definition: mitkUSDevice.h:97
int m_ThreadID
ID of the started thread.
Definition: mitkUSDevice.h:372
mitk::Vector3D m_Spacing
Definition: mitkUSDevice.h:389
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
itk::MultiThreader::Pointer m_MultiThreader
itk::MultiThreader used for thread handling
Definition: mitkUSDevice.h:370
const std::string US_PROPKEY_PROBES_SELECTED
Definition: mitkUSDevice.h:108
us::ServiceRegistration< Self > m_ServiceRegistration
The device&#39;s ServiceRegistration object that allows to modify it&#39;s Microservice registraton details...
Definition: mitkUSDevice.h:513
us::ServiceProperties m_ServiceProperties
Properties of the device&#39;s Microservice.
Definition: mitkUSDevice.h:508
virtual void SetImageVector(std::vector< mitk::Image::Pointer > vec)
Definition: mitkUSDevice.h:374
const std::string US_PROPKEY_MANUFACTURER
Definition: mitkUSDevice.h:100
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
unsigned int m_NumberOfOutputs
Definition: mitkUSDevice.h:503
std::vector< mitk::Image::Pointer > m_ImageVector
Definition: mitkUSDevice.h:386
DeviceStates m_DeviceState
Definition: mitkUSDevice.h:408
itk::SimpleMutexLock m_FreezeMutex
Definition: mitkUSDevice.h:369
#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:480
const std::string US_PROPKEY_ISACTIVE
Definition: mitkUSDevice.h:105
const std::string US_PROPKEY_NAME
Definition: mitkUSDevice.h:101
itk::FastMutexLock::Pointer m_ImageMutex
mutex for images provided by the image source
Definition: mitkUSDevice.h:371
#define mitkNewMessage2Macro(msgHandleObject, type1, type2)
Definition: mitkMessage.h:66
const std::string US_PROPKEY_BMODE_DYNAMIC_RANGE
Definition: mitkUSDevice.h:115
const std::string US_PROPKEY_COMMENT
Definition: mitkUSDevice.h:102
virtual void AddNewProbe(mitk::USProbe::Pointer)
adds a new probe to the device
Definition: mitkUSDevice.h:339