Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkUSVideoDevice.cpp
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 #include "mitkUSVideoDevice.h"
19 
20 mitk::USVideoDevice::USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model)
21 {
22  Init();
23  m_SourceIsFile = false;
24  m_DeviceID = videoDeviceNumber;
25  m_FilePath = "";
26 }
27 
28 mitk::USVideoDevice::USVideoDevice(std::string videoFilePath, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model)
29 {
30  Init();
31  m_SourceIsFile = true;
32  m_FilePath = videoFilePath;
33 }
34 
36 {
37  Init();
38  m_SourceIsFile = false;
39  m_DeviceID = videoDeviceNumber;
40  m_FilePath = "";
41 }
42 
43 mitk::USVideoDevice::USVideoDevice(std::string videoFilePath, mitk::USImageMetadata::Pointer metadata) : mitk::USDevice(metadata)
44 {
45  Init();
46  m_SourceIsFile = true;
47  m_FilePath = videoFilePath;
48 }
49 
51 {
52  //m_Source->UnRegister();
53  m_Source = 0;
54 }
55 
57 {
58  m_Source = mitk::USImageVideoSource::New();
59  m_ControlInterfaceCustom = mitk::USVideoDeviceCustomControls::New(this);
60  //this->SetNumberOfInputs(1);
61  this->SetNumberOfIndexedOutputs(1);
62 
63  // mitk::USImage::Pointer output = mitk::USImage::New();
64  // output->Initialize();
65  this->SetNthOutput(0, this->MakeOutput(0));
66 }
67 
69 {
71 }
72 
74 {
75  return "org.mitk.modules.us.USVideoDevice";
76 }
77 
79 {
80  return m_ControlInterfaceCustom.GetPointer();
81 }
82 
84 {
85  // nothing to do at initialization of video device
86  return true;
87 }
88 
90 {
91  if (m_SourceIsFile){
92  m_Source->SetVideoFileInput(m_FilePath);
93  }
94  else {
95  m_Source->SetCameraInput(m_DeviceID);
96  }
97  //SetSourceCropArea();
98  return true;
99 }
100 
102 {
103  if (m_DeviceState == State_Activated) this->Deactivate();
104 
105  m_Source->ReleaseInput();
106 
107  return true;
108 }
109 
111 {
112  // make sure that video device is ready before aquiring images
113  if (!m_Source->GetIsReady())
114  {
115  MITK_WARN("mitkUSDevice")("mitkUSVideoDevice") << "Could not activate us video device. Check if video grabber is configured correctly.";
116  return false;
117  }
118 
119  MITK_INFO << "Activated UsVideoDevice!";
120  return true;
121 }
122 
124 {
125  // happens automatically when m_Active is set to false
126  return true;
127 }
128 
130 {
131  if (m_DeviceState == State_Activated) { this->Deactivate(); }
132  if (m_DeviceState == State_Connected) { this->Disconnect(); }
133 
135 }
136 
138 {
139  return m_Source.GetPointer();
140 }
141 
142 std::vector<mitk::USProbe::Pointer> mitk::USVideoDevice::GetAllProbes()
143 {
144  if (m_Probes.empty())
145  {
146  MITK_INFO << "No probes exist for this USVideDevice. Empty vector is returned";
147  }
148  return m_Probes;
149 }
150 
152 {
153  if (m_CurrentProbe.IsNotNull())
154  {
155  return m_CurrentProbe;
156  }
157  else
158  {
159  return 0;
160  }
161 }
162 
164 {
165  for (std::vector<mitk::USProbe::Pointer>::iterator it = m_Probes.begin(); it != m_Probes.end(); it++)
166  {
167  if (name.compare((*it)->GetName()) == 0)
168  return (*it);
169  }
170  MITK_INFO << "No probe with given name " << name << " was found.";
171  return 0; //no matching probe was found so 0 is returned
172 }
173 
175 {
176  for (std::vector<mitk::USProbe::Pointer>::iterator it = m_Probes.begin(); it != m_Probes.end(); it++)
177  {
178  if (name.compare((*it)->GetName()) == 0)
179  {
180  m_Probes.erase(it);
181  return;
182  }
183  }
184  MITK_INFO << "No Probe with given name " << name << " was found";
185 }
186 
188 {
189  m_Probes.push_back(probe);
190 }
191 
193 {
194  return m_SourceIsFile;
195 }
virtual itk::SmartPointer< USAbstractControlInterface > GetControlInterfaceCustom() override
A device holds information about it's model, make and the connected probes. It is the common super cl...
Definition: mitkUSDevice.h:77
itk::SmartPointer< Self > Pointer
bool GetIsSourceFile()
True, if this Device plays back a file, false if it recieves data from a device.
#define MITK_INFO
Definition: mitkLogMacros.h:22
void RemoveProbeByName(std::string name)
Removes the Probe with the given name.
DataCollection - Class to facilitate loading/accessing structured data.
mitk::USProbe::Pointer GetCurrentProbe()
Return current active probe for this USVideoDevice Returns a pointer to the probe that is currently i...
virtual bool OnConnection() override
Is called during the connection process. Returns true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong.
virtual bool OnInitialization() override
Is called during the initialization process. Returns true if successful and false if unsuccessful...
int m_DeviceID
The device id to connect to. Undefined, if m_SourceIsFile == true;.
virtual bool OnDisconnection() override
Is called during the disconnection process. Returns true if successful and false if unsuccessful...
std::vector< mitk::USProbe::Pointer > GetAllProbes()
Return all probes for this USVideoDevice or an empty vector it no probes were set Returns a std::vect...
#define MITK_WARN
Definition: mitkLogMacros.h:23
mitk::USProbe::Pointer GetProbeByName(std::string name)
get the probe by its name Returns a pointer to the probe identified by the given name. If no probe of given name exists for this Device 0 is returned.
bool m_SourceIsFile
True, if this source plays back a file, false if it recieves data from a device.
void UnregisterOnService()
Remove this device from the micro service.
USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model)
Creates a new device that will deliver USImages taken from a video device. under windows, try -1 for device number, which will grab the first available one (Open CV functionality)
void UnregisterOnService()
Remove this device from the micro service. This method is public for mitk::USVideoDevice, because this devices can be completly removed. This is not possible for API devices, which should be available while their sub module is loaded.
virtual USImageSource::Pointer GetUSImageSource() override
virtual bool OnActivation() override
Is called during the activation process. After this method is finsihed, the device should be generati...
std::string m_FilePath
The Filepath id to connect to. Undefined, if m_SourceIsFile == false;.
static Pointer New()
static std::string GetDeviceClassStatic()
virtual std::string GetDeviceClass() override
virtual bool OnDeactivation() override
Is called during the deactivation process. After a call to this method the device should still be con...
void AddNewProbe(mitk::USProbe::Pointer probe)
adds a new probe to the device
void Init()
Initializes common properties for all constructors.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.