MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSVideoDevice.cpp
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#include "mitkUSVideoDevice.h"
15
16mitk::USVideoDevice::USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model)
17{
18 Init();
19 m_SourceIsFile = false;
20 m_DeviceID = videoDeviceNumber;
21 m_FilePath = "";
22}
23
24mitk::USVideoDevice::USVideoDevice(std::string videoFilePath, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model)
25{
26 Init();
27 m_SourceIsFile = true;
28 m_FilePath = videoFilePath;
29}
30
31mitk::USVideoDevice::USVideoDevice(int videoDeviceNumber, mitk::USImageMetadata::Pointer metadata) : mitk::USDevice(metadata)
32{
33 Init();
34 m_SourceIsFile = false;
35 m_DeviceID = videoDeviceNumber;
36 m_FilePath = "";
37}
38
39mitk::USVideoDevice::USVideoDevice(std::string videoFilePath, mitk::USImageMetadata::Pointer metadata) : mitk::USDevice(metadata)
40{
41 Init();
42 m_SourceIsFile = true;
43 m_FilePath = videoFilePath;
44}
45
47{
48 //m_Source->UnRegister();
49 m_Source = nullptr;
50}
51
53{
54 m_Source = mitk::USImageVideoSource::New();
55 m_ControlInterfaceCustom = mitk::USVideoDeviceCustomControls::New(this);
56 //this->SetNumberOfInputs(1);
57 this->SetNumberOfIndexedOutputs(1);
58
59 // mitk::USImage::Pointer output = mitk::USImage::New();
60 // output->Initialize();
61 this->SetNthOutput(0, this->MakeOutput(0));
62}
63
68
70{
71 return "org.mitk.modules.us.USVideoDevice";
72}
73
74mitk::USAbstractControlInterface::Pointer mitk::USVideoDevice::GetControlInterfaceCustom()
75{
76 return m_ControlInterfaceCustom.GetPointer();
77}
78
80{
81 // nothing to do at initialization of video device
82 return true;
83}
84
86{
87 if (m_SourceIsFile){
88 m_Source->SetVideoFileInput(m_FilePath);
89 }
90 else {
91 m_Source->SetCameraInput(m_DeviceID);
92 }
93 //SetSourceCropArea();
94 return true;
95}
96
98{
99 if (m_DeviceState == State_Activated) this->Deactivate();
100
101 m_Source->ReleaseInput();
102
103 return true;
104}
105
107{
108 // make sure that video device is ready before aquiring images
109 if (!m_Source->GetIsReady())
110 {
111 MITK_WARN("mitkUSDevice")("mitkUSVideoDevice") << "Could not activate us video device. Check if video grabber is configured correctly.";
112 return false;
113 }
114
115 MITK_INFO << "Activated UsVideoDevice!";
116 return true;
117}
118
120{
121 // happens automatically when m_Active is set to false
122 return true;
123}
124
126{
127 Superclass::GenerateData();
128
129 if( m_ImageVector.size() == 0 || this->GetNumberOfIndexedOutputs() == 0 )
130 {
131 return;
132 }
133
134 m_ImageMutex.lock();
135 auto& image = m_ImageVector[0];
136 if( image.IsNotNull() && image->IsInitialized() && m_CurrentProbe.IsNotNull() )
137 {
138 //MITK_INFO << "Spacing CurrentProbe: " << m_CurrentProbe->GetSpacingForGivenDepth(m_CurrentProbe->GetCurrentDepth());
139 image->GetGeometry()->SetSpacing(m_CurrentProbe->GetSpacingForGivenDepth(m_CurrentProbe->GetCurrentDepth()));
140 this->GetOutput(0)->SetGeometry(image->GetGeometry());
141 }
142 m_ImageMutex.unlock();
143}
144
146{
147 if (m_DeviceState == State_Activated) { this->Deactivate(); }
148 if (m_DeviceState == State_Connected) { this->Disconnect(); }
149
151}
152
153mitk::USImageSource::Pointer mitk::USVideoDevice::GetUSImageSource()
154{
155 return m_Source.GetPointer();
156}
157
158std::vector<mitk::USProbe::Pointer> mitk::USVideoDevice::GetAllProbes()
159{
160 if (m_Probes.empty())
161 {
162 MITK_INFO << "No probes exist for this USVideDevice. Empty vector is returned";
163 }
164 return m_Probes;
165}
166
168{
169 m_Probes.clear();
170}
171
173{
174 if (m_CurrentProbe.IsNotNull())
175 {
176 return m_CurrentProbe;
177 }
178 else
179 {
180 return nullptr;
181 }
182}
183
184mitk::USProbe::Pointer mitk::USVideoDevice::GetProbeByName(std::string name)
185{
186 for (std::vector<mitk::USProbe::Pointer>::iterator it = m_Probes.begin(); it != m_Probes.end(); it++)
187 {
188 if (name.compare((*it)->GetName()) == 0)
189 return (*it);
190 }
191 MITK_INFO << "No probe with given name " << name << " was found.";
192 return nullptr; //no matching probe was found so 0 is returned
193}
194
196{
197 for (std::vector<mitk::USProbe::Pointer>::iterator it = m_Probes.begin(); it != m_Probes.end(); it++)
198 {
199 if (name.compare((*it)->GetName()) == 0)
200 {
201 m_Probes.erase(it);
202 return;
203 }
204 }
205 MITK_INFO << "No Probe with given name " << name << " was found";
206}
207
208void mitk::USVideoDevice::AddNewProbe(mitk::USProbe::Pointer probe)
209{
210 m_Probes.push_back(probe);
211}
212
214{
215 return m_SourceIsFile;
216}
217
219{
220 if( m_Probes.size() == 0 )
221 {
222 std::string name = "default";
223 mitk::USProbe::Pointer defaultProbe = mitk::USProbe::New( name );
224 m_Probes.push_back( defaultProbe );
225 }
226
227 m_CurrentProbe = m_Probes.at(0);
228 MITK_INFO << "SetDefaultProbeAsCurrentProbe()";
229 this->ProbeChanged( m_CurrentProbe->GetName() );
230}
231
232void mitk::USVideoDevice::SetCurrentProbe(std::string probename)
233{
234 m_CurrentProbe = this->GetProbeByName( probename );
235 MITK_INFO << "SetCurrentProbe() " << probename;
236}
237
238void mitk::USVideoDevice::SetSpacing(double xSpacing, double ySpacing)
239{
240 mitk::Vector3D spacing;
241 spacing[0] = xSpacing;
242 spacing[1] = ySpacing;
243 spacing[2] = 1;
244 MITK_INFO << "Spacing: " << spacing;
245
246 if( m_CurrentProbe.IsNotNull() )
247 {
248 m_CurrentProbe->SetSpacingForGivenDepth(m_CurrentProbe->GetCurrentDepth(), spacing);
249 }
250 else
251 {
252 MITK_WARN << "Cannot set spacing. Current ultrasound probe not set.";
253 }
254}
A device holds information about it's model, make and the connected probes. It is the common super cl...
void UnregisterOnService()
Remove this device from the micro service.
bool OnDisconnection() override
Is called during the disconnection process. Returns true if successful and false if unsuccessful....
itk::SmartPointer< USAbstractControlInterface > GetControlInterfaceCustom() override
bool OnDeactivation() override
Is called during the deactivation process. After a call to this method the device should still be con...
void DeleteAllProbes() override
Cleans the std::vector containing all configured probes.
mitk::USProbe::Pointer GetProbeByName(std::string name) override
get the probe by its name Returns a pointer to the probe identified by the given name....
bool m_SourceIsFile
True, if this source plays back a file, false if it recieves data from a device.
std::vector< mitk::USProbe::Pointer > GetAllProbes() override
Return all probes for this USVideoDevice or an empty vector it no probes were set Returns a std::vect...
void GenerateData() override
Grabs the next frame from the Video input. This method is called internally, whenever Update() is inv...
void SetSpacing(double xSpacing, double ySpacing) override
Sets the given spacing of the current depth of the current probe.
void UnregisterOnService()
Remove this device from the micro service. This method is public for mitk::USVideoDevice,...
void RemoveProbeByName(std::string name) override
Removes the Probe with the given name.
bool OnInitialization() override
Is called during the initialization process. Returns true if successful and false if unsuccessful....
mitk::USProbe::Pointer GetCurrentProbe() override
Return current active probe for this USVideoDevice Returns a pointer to the probe that is currently i...
int m_DeviceID
The device id to connect to. Undefined, if m_SourceIsFile == true;.
bool OnConnection() override
Is called during the connection process. Returns true if successful and false if unsuccessful....
std::string GetDeviceClass() override
void AddNewProbe(mitk::USProbe::Pointer probe) override
adds a new probe to the device
void Init()
Initializes common properties for all constructors.
USImageSource::Pointer GetUSImageSource() override
USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model)
Creates a new device that will deliver USImages taken from a video device. under windows,...
static std::string GetDeviceClassStatic()
void SetCurrentProbe(std::string probename) override
Sets the probe with the given name as current probe if the named probe exists.
std::string m_FilePath
The Filepath id to connect to. Undefined, if m_SourceIsFile == false;.
bool OnActivation() override
Is called during the activation process. After this method is finsihed, the device should be generati...
bool GetIsSourceFile()
True, if this Device plays back a file, false if it recieves data from a device.
void SetDefaultProbeAsCurrentProbe() override
Sets the first existing probe or the default probe of the video device as the current probe of it.
IGT Exceptions.