Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKUSDevice_H_HEADER_INCLUDED_
18 #define MITKUSDevice_H_HEADER_INCLUDED_
19 
20 // STL
21 #include <vector>
22 
23 // MitkUS
24 #include "mitkUSProbe.h"
25 #include <MitkUSExports.h>
26 #include "mitkUSImageSource.h"
27 
28 // MitkIGTL
30 #include "mitkIGTLServer.h"
31 #include "mitkIGTLDeviceSource.h"
33 
34 // MITK
35 #include <mitkCommon.h>
36 #include <mitkMessage.h>
37 #include <mitkImageSource.h>
38 
39 // ITK
40 #include <itkObjectFactory.h>
41 #include <itkConditionVariable.h>
42 
43 // Microservices
44 #include <mitkServiceInterface.h>
45 #include <usServiceRegistration.h>
46 #include <usServiceProperties.h>
47 
48 // DEPRECATED
49 #include "mitkUSImageMetadata.h"
50 
51 namespace itk {
52  template<class T> class SmartPointer;
53 }
54 
55 namespace mitk {
56  class USAbstractControlInterface;
57  class USControlInterfaceBMode;
58  class USControlInterfaceProbes;
59  class USControlInterfaceDoppler;
60 
77  class MITKUS_EXPORT USDevice : public mitk::ImageSource
78  {
79  public:
80  enum DeviceStates { State_NoState, State_Initialized, State_Connected, State_Activated };
81 
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 
144 
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 
293  virtual USImageSource::Pointer GetUSImageSource() = 0;
294 
296  DEPRECATED(std::string GetDeviceManufacturer());
298  DEPRECATED(std::string GetDeviceModel());
300  DEPRECATED(std::string GetDeviceComment());
301 
302  itkGetMacro(Manufacturer, std::string);
303  itkGetMacro(Name, std::string);
304  itkGetMacro(Comment, std::string);
305 
306  void SetManufacturer(std::string manufacturer);
307  void SetName(std::string name);
308  void SetComment(std::string comment);
309 
310  itkGetMacro(DeviceState, DeviceStates)
311  itkGetMacro(ServiceProperties, us::ServiceProperties)
312 
313  void GrabImage();
314 
315  protected:
316  itkSetMacro(Image, mitk::Image::Pointer);
317  itkSetMacro(SpawnAcquireThread, bool);
318  itkGetMacro(SpawnAcquireThread, bool);
319 
320  static ITK_THREAD_RETURN_TYPE Acquire(void* pInfoStruct);
321  static ITK_THREAD_RETURN_TYPE ConnectThread(void* pInfoStruct);
322 
323  mitk::Image::Pointer m_Image;
324  mitk::Image::Pointer m_OutputImage;
325 
330  void ProvideViaOIGTL();
331 
335  void DisableOIGTL();
336 
337  mitk::IGTLServer::Pointer m_IGTLServer;
338  mitk::IGTLMessageProvider::Pointer m_IGTLMessageProvider;
339  mitk::ImageToIGTLMessageFilter::Pointer m_ImageToIGTLMsgFilter;
340 
341  bool m_IsFreezed;
342 
343  DeviceStates m_DeviceState;
344 
345  /* @brief defines the area that should be cropped from the US image */
346  USImageCropArea m_CropArea;
347 
353  us::ServiceProperties ConstructServiceProperties();
354 
358  void UnregisterOnService();
359 
368  virtual bool OnInitialization() = 0;
369 
378  virtual bool OnConnection() = 0;
379 
388  virtual bool OnDisconnection() = 0;
389 
398  virtual bool OnActivation() = 0;
399 
408  virtual bool OnDeactivation() = 0;
409 
415  virtual void OnFreeze(bool) { }
416 
420  USDevice(std::string manufacturer, std::string model);
421 
427 
428  virtual ~USDevice();
429 
434  virtual void GenerateData() override;
435 
436  std::string GetServicePropertyLabel();
437 
438  private:
439 
440  std::string m_Manufacturer;
441  std::string m_Name;
442  std::string m_Comment;
443 
444  bool m_SpawnAcquireThread;
445 
449  us::ServiceRegistration<Self> m_ServiceRegistration;
450 
454  us::ServiceProperties m_ServiceProperties;
455 
456  // Threading-Related
457  itk::ConditionVariable::Pointer m_FreezeBarrier;
458  itk::SimpleMutexLock m_FreezeMutex;
459  itk::MultiThreader::Pointer m_MultiThreader;
460  itk::FastMutexLock::Pointer m_ImageMutex;
461  int m_ThreadID;
462 
463  bool m_UnregisteringStarted;
464  };
465 } // namespace mitk
466 
467 // This is the microservice declaration. Do not meddle!
468 MITK_DECLARE_SERVICE_INTERFACE(mitk::USDevice, "org.mitk.services.UltrasoundDevice")
469 
470 #endif // MITKUSDevice_H_HEADER_INCLUDED_
Superclass for all ultrasound device control interfaces. Defines an interface for activating and deac...
Superclass of all classes generating Images (instances of class Image) as output. ...
A device holds information about it's model, make and the connected probes. It is the common super cl...
Definition: mitkUSDevice.h:77
Superclass for OpenIGTLink server.
itk::SmartPointer< Self > Pointer
Interface defining methods for probe selection of ultrasound devices. It consists of methods for gett...
const std::string US_PROPKEY_LABEL
Definition: mitkUSDevice.h:105
STL namespace.
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.
Interface defining methods for scanning mode doppler of ultrasound devices. There are no methods defi...
const std::string US_PROPKEY_ISCONNECTED
Definition: mitkUSDevice.h:106
This is an abstract superclass for delivering USImages. Each subclass must implement the method mitk:...
const std::string US_PROPKEY_BMODE_POWER
Definition: mitkUSDevice.h:113
const std::string US_PROPKEY_BMODE_REJECTION
Definition: mitkUSDevice.h:116
#define DEPRECATED(func)
Definition: mitkCommon.h:183
const std::string US_PROPKEY_BMODE_GAIN
Definition: mitkUSDevice.h:115
const std::string US_PROPKEY_CLASS
Definition: mitkUSDevice.h:108
const std::string US_PROPKEY_BMODE_DEPTH
Definition: mitkUSDevice.h:114
These constants are used in conjunction with Microservices. The constants aren't defined as static me...
Definition: mitkUSDevice.h:99
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Image class for storing images.
Definition: mitkImage.h:76
const std::string US_PROPKEY_PROBES_SELECTED
Definition: mitkUSDevice.h:110
Provides information/objects from a MITK-Pipeline to other OpenIGTLink devices.
This filter creates IGTL messages from mitk::Image objects.
Interface for image filters on OpenCV images.
Interface defining methods for scanning mode b of ultrasound devices. It consists of methods for scan...
const std::string US_PROPKEY_MANUFACTURER
Definition: mitkUSDevice.h:102
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
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:70
MITK_DECLARE_SERVICE_INTERFACE(mitk::ISimulationService,"org.mitk.ISimulationService")
const std::string US_PROPKEY_BMODE_DYNAMIC_RANGE
Definition: mitkUSDevice.h:117
const std::string US_PROPKEY_COMMENT
Definition: mitkUSDevice.h:104