MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSTelemedDevice.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 "mitkUSTelemedDevice.h"
14#include "mitkImageReadAccessor.h"
16
17mitk::USTelemedDevice::USTelemedDevice(std::string manufacturer, std::string model)
18: mitk::USDevice(manufacturer, model),
19m_ControlsProbes(mitk::USTelemedProbesControls::New(this)),
20m_ControlsBMode(mitk::USTelemedBModeControls::New(this)),
21m_ControlsDoppler(mitk::USTelemedDopplerControls::New(this)),
22m_ImageSource(mitk::USTelemedImageSource::New()), m_UsgMainInterface(0),
23m_Probe(0), m_UsgDataView(0), m_ProbesCollection(0)
24{
25 SetNumberOfIndexedOutputs(1);
26 SetNthOutput(0, this->MakeOutput(0));
27}
28
32
34{
35 return "org.mitk.modules.us.USTelemedDevice";
36}
37
38mitk::USControlInterfaceBMode::Pointer mitk::USTelemedDevice::GetControlInterfaceBMode()
39{
40 return m_ControlsBMode.GetPointer();
41}
42
43mitk::USControlInterfaceProbes::Pointer mitk::USTelemedDevice::GetControlInterfaceProbes()
44{
45 return m_ControlsProbes.GetPointer();
46};
47
48mitk::USControlInterfaceDoppler::Pointer mitk::USTelemedDevice::GetControlInterfaceDoppler()
49{
50 return m_ControlsDoppler.GetPointer();
51};
52
54{
55 CoInitialize(nullptr); // initialize COM library
56
57 return true;
58}
59
61{
62 // create main Telemed API COM library object
63 HRESULT hr;
64
65 hr = CoCreateInstance(Usgfw2Lib::CLSID_Usgfw2, nullptr, CLSCTX_INPROC_SERVER, Usgfw2Lib::IID_IUsgfw2,(LPVOID*) &m_UsgMainInterface);
66 if (FAILED(hr))
67 {
68 SAFE_RELEASE(m_UsgMainInterface);
69 MITK_ERROR("USDevice")("USTelemedDevice") << "Error at connecting to ultrasound device (" << hr << ").";
70 return false;
71 }
72
73 this->ConnectDeviceChangeSink();
74
75 return true;
76}
77
79{
80 // control objects cannot be active anymore
81 m_ControlsBMode->SetIsActive(false);
82 m_ControlsDoppler->SetIsActive(false);
83 m_ControlsProbes->SetIsActive(false);
84
85 ReleaseUsgControls();
86
87 return true;
88}
89
91{
92 // probe controls are available now
93 m_ControlsProbes->SetIsActive(true);
94
95 if ( m_ControlsProbes->GetProbesCount() < 1 )
96 {
97 MITK_WARN("USDevice")("USTelemedDevice") << "No probe found.";
98 return false;
99 }
100
101 // select first probe as a default
102 m_ControlsProbes->SelectProbe(0);
103
104 // set scan mode b as default for activation -
105 // control interfaces can override this later
106 HRESULT hr = m_UsgDataView->put_ScanMode(Usgfw2Lib::SCAN_MODE_B);
107 if (FAILED(hr))
108 {
109 MITK_ERROR("USDevice")("USTelemedDevice") << "Could not set scan mode b (" << hr << ").";
110 return false;
111 }
112
113 // start ultrasound scanning with selected scan mode
114 hr = m_UsgDataView->put_ScanState(Usgfw2Lib::SCAN_STATE_RUN);
115 if (FAILED(hr))
116 {
117 MITK_ERROR("USDevice")("USTelemedDevice") << "Start scanning failed (" << hr << ").";
118 return false;
119 }
120
121 m_ControlsBMode->ReinitializeControls();
122
123 return true;
124}
125
127{
128 this->StopScanning();
129 return true;
130}
131
133{
134 if ( freeze )
135 {
136 m_UsgDataView->put_ScanState(Usgfw2Lib::SCAN_STATE_FREEZE);
137 }
138 else
139 {
140 m_UsgDataView->put_ScanState(Usgfw2Lib::SCAN_STATE_RUN);
141 }
142}
143
145{
146 mitk::USTelemedImageSource::Pointer s = dynamic_cast<mitk::USTelemedImageSource*>(GetUSImageSource().GetPointer());
147 s->GetNextRawImage(m_ImageVector);
148 Superclass::GenerateData();
149}
150
151mitk::USImageSource::Pointer mitk::USTelemedDevice::GetUSImageSource()
152{
153 return m_ImageSource.GetPointer();
154}
155
157{
158 if (m_UsgDataView) { this->StopScanning(); };
159
160 SAFE_RELEASE(m_UsgMainInterface);
161 SAFE_RELEASE(m_Probe);
162 SAFE_RELEASE(m_UsgDataView);
163 SAFE_RELEASE(m_ProbesCollection);
164}
165
167{
168 if ( ! m_UsgDataView )
169 {
170 MITK_WARN("USDevice")("USTelemedDevice") << "Cannot stop scanning as Telemed Data View is null.";
171 return;
172 }
173
174 HRESULT hr;
175 hr = m_UsgDataView->put_ScanState(Usgfw2Lib::SCAN_STATE_STOP);
176
177 if (FAILED(hr))
178 {
179 MITK_ERROR("USDevice")("USTelemedDevice") << "Stop scanning failed (" << hr << ").";
180 mitkThrow() << "Stop scanning failed (" << hr << ").";
181 }
182}
183
184std::vector<mitk::USProbe::Pointer> mitk::USTelemedDevice::GetAllProbes(){
185 return m_ControlsProbes->GetProbeSet();
186}
187
189 return m_ControlsProbes->GetSelectedProbe();
190}
191
192mitk::USProbe::Pointer mitk::USTelemedDevice::GetProbeByName(std::string name){
193 for (mitk::USProbe::Pointer p : m_ControlsProbes->GetProbeSet()){
194 if (p->GetName().compare(name)==0) {return p;}
195 }
196 return nullptr;
197}
198
200{
201 return m_UsgMainInterface;
202}
203
204void mitk::USTelemedDevice::SetActiveDataView(Usgfw2Lib::IUsgDataView* usgDataView)
205{
206 // do nothing if the usg data view hasn't changed
207 if ( m_UsgDataView != usgDataView )
208 {
209 // scan converter plugin is connected to IUsgDataView -> a new plugin
210 // must be created when changing IUsgDataView
211 m_UsgDataView = usgDataView;
212 if ( ! m_ImageSource->CreateAndConnectConverterPlugin(m_UsgDataView, Usgfw2Lib::SCAN_MODE_B)) { return; }
213
214 // b mode control object must know about active data view
215 m_ControlsBMode->SetUsgDataView(m_UsgDataView);
216 }
217}
218
220{
221 IConnectionPointContainer* cpc = nullptr;
222 HRESULT hr = m_UsgMainInterface->QueryInterface(IID_IConnectionPointContainer, (void**)&cpc);
223 if (hr != S_OK)
224 cpc = nullptr;
225
226 if (cpc != nullptr)
227 hr = cpc->FindConnectionPoint(Usgfw2Lib::IID_IUsgDeviceChangeSink, &m_UsgDeviceChangeCpnt);
228
229 if (hr != S_OK)
230 {
231 m_UsgDeviceChangeCpnt = nullptr;
232 m_UsgDeviceChangeCpntCookie = 0;
233 }
234 SAFE_RELEASE(cpc);
235
236 if (m_UsgDeviceChangeCpnt != nullptr)
237 hr = m_UsgDeviceChangeCpnt->Advise((IUnknown*)((Usgfw2Lib::IUsgDeviceChangeSink*)this), &m_UsgDeviceChangeCpntCookie);
238}
239
240// --- Methods for Telemed API Interfaces
241
242HRESULT __stdcall mitk::USTelemedDevice::raw_OnBeamformerArrive(IUnknown *pUsgBeamformer, ULONG *reserved)
243{
244 this->Connect();
245
246 return S_OK;
247}
248
249HRESULT __stdcall mitk::USTelemedDevice::raw_OnBeamformerRemove(IUnknown *pUsgBeamformer, ULONG *reserved)
250{
251 if ( this->GetIsActive() ) { this->Deactivate(); }
252
253 this->Disconnect();
254
255 return S_OK;
256}
257
258HRESULT __stdcall mitk::USTelemedDevice::raw_OnProbeArrive(IUnknown*, ULONG* probeIndex)
259{
260 m_ControlsProbes->ProbeAdded(static_cast<unsigned int>(*probeIndex));
261
262 this->Activate();
263
264 return S_OK;
265};
266
267HRESULT __stdcall mitk::USTelemedDevice::raw_OnProbeRemove(IUnknown*, ULONG* probeIndex)
268{
269 m_ControlsProbes->ProbeRemoved(static_cast<unsigned int>(*probeIndex));
270
271 if ( this->GetIsActive() ) { this->Deactivate(); }
272
273 return S_OK;
274};
275
276STDMETHODIMP_(ULONG) mitk::USTelemedDevice::AddRef()
277{
278 ++m_RefCount;
279 return m_RefCount;
280}
281
282STDMETHODIMP_(ULONG) mitk::USTelemedDevice::Release()
283{
284 --m_RefCount;
285 return m_RefCount;
286}
287
288STDMETHODIMP mitk::USTelemedDevice::QueryInterface(REFIID riid, void** ppv)
289{
290 if (riid == IID_IUnknown || riid == Usgfw2Lib::IID_IUsgDeviceChangeSink)
291 {
292 *ppv = (IUsgDeviceChangeSink*)this;
293 return S_OK;
294 }
295 if (riid == IID_IDispatch)
296 {
297 *ppv = (IDispatch*)this;
298 return S_OK;
299 }
300 return E_NOINTERFACE;
301}
302
304{
305 if (pctinfo == nullptr) return E_INVALIDARG;
306 *pctinfo = 0;
307 return S_OK;
308}
309
310HRESULT mitk::USTelemedDevice::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
311{
312 if (pptinfo == nullptr) return E_INVALIDARG;
313 *pptinfo = nullptr;
314 if(itinfo != 0) return DISP_E_BADINDEX;
315 return S_OK;
316}
317
318HRESULT mitk::USTelemedDevice::GetIDsOfNames(const IID &riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid)
319{
320 // this is not used - must use the same fixed dispid's from Usgfw2 idl file
321 return S_OK;
322}
323
324HRESULT mitk::USTelemedDevice::Invoke(DISPID dispIdMember, const IID &riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
325{
326 if ( (dispIdMember >= 1) && (dispIdMember <= 6) )
327 {
328 if (pDispParams->cArgs != 2) // we need 2 arguments
329 return S_OK;
330
331 IUnknown *unkn = nullptr;
332 ULONG *res = nullptr;
333
334 VARIANTARG* p1;
335 VARIANTARG* p;
336 p1 = pDispParams->rgvarg;
337
338 p = p1;
339 if (p->vt == (VT_BYREF|VT_UI4))
340 res = p->pulVal;
341 p1++;
342
343 p = p1;
344 if (p->vt == VT_UNKNOWN)
345 unkn = (IUnknown*)(p->punkVal);
346
347 if (dispIdMember == 1)
348 OnProbeArrive(unkn, res);
349 else if (dispIdMember == 2)
350 OnBeamformerArrive(unkn, res);
351 else if (dispIdMember == 3)
352 OnProbeRemove(unkn, res);
353 else if (dispIdMember == 4)
354 OnBeamformerRemove(unkn, res);
355 else if (dispIdMember == 5)
356 OnProbeStateChanged(unkn, res);
357 else if (dispIdMember == 6)
358 OnBeamformerStateChanged(unkn, res);
359 }
360
361 return S_OK;
362}
A device holds information about it's model, make and the connected probes. It is the common super cl...
Implementation of mitk::USControlInterfaceBMode for Telemed ultrasound devices. See documentation of ...
void GenerateData() override
Grabs the next frame from the Video input. This method is called internally, whenever Update() is inv...
STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
virtual HRESULT __stdcall raw_OnProbeArrive(IUnknown *pUsgProbe, ULONG *reserved)
virtual HRESULT __stdcall raw_OnProbeRemove(IUnknown *pUsgProbe, ULONG *reserved)
USTelemedDevice(std::string manufacturer, std::string model)
USImageSource::Pointer GetUSImageSource()
virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT *pctinfo)
Usgfw2Lib::IUsgfw2 * GetUsgMainInterface()
Getter for main Telemed API object. This method is for being called by Telemed control interfaces.
virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
virtual bool OnActivation()
Is called during the activation process. After this method is finished, the device is generating imag...
virtual HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, const IID &riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
void StopScanning()
Stop ultrasound scanning by Telemed API call.
void SetActiveDataView(Usgfw2Lib::IUsgDataView *)
Changes active IUsgDataView of the device. This method is for being called by Telemed control interfa...
virtual bool OnInitialization()
Is called during the initialization process. There is nothing done on the initialization of a mik::US...
mitk::USProbe::Pointer GetProbeByName(std::string name)
get the probe by its name Returns a pointer to the probe identified by the given name....
mitk::USProbe::Pointer GetCurrentProbe()
Return current active probe for this USDevice Returns a pointer to the probe that is currently in use...
virtual void OnFreeze(bool freeze)
Changes scan state of the device if freeze is toggeled in mitk::USDevice.
virtual USControlInterfaceBMode::Pointer GetControlInterfaceBMode()
Default getter for the b mode control interface. Has to be implemented in a subclass if a b mode cont...
virtual HRESULT __stdcall raw_OnBeamformerRemove(IUnknown *pUsgBeamformer, ULONG *reserved)
virtual std::string GetDeviceClass()
Returns the class of the device.
virtual bool OnDisconnection()
Is called during the disconnection process. Deactivate and remove all Telemed API controls....
std::vector< mitk::USProbe::Pointer > GetAllProbes()
Returns all probes for this device or an empty vector it no probes were set Returns a std::vector of ...
virtual USControlInterfaceProbes::Pointer GetControlInterfaceProbes()
Default getter for the probes control interface. Has to be implemented in a subclass if a probes cont...
virtual USControlInterfaceDoppler::Pointer GetControlInterfaceDoppler()
Default getter for the doppler control interface. Has to be implemented in a subclass if a doppler co...
virtual HRESULT __stdcall raw_OnBeamformerArrive(IUnknown *pUsgBeamformer, ULONG *reserved)
virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(const IID &riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgdispid)
virtual bool OnConnection()
Is called during the connection process. Connect to the Telemed API and try to get available probes f...
virtual bool OnDeactivation()
Is called during the deactivation process. After a call to this method the device is connected,...
Implementation of mitk::USControlInterfaceDoppler for Telemed ultrasound devices. See documentation o...
Implementation of mitk::USImageSource for Telemed API devices. The method mitk::USImageSource::GetNex...
virtual void GetNextRawImage(std::vector< mitk::Image::Pointer > &)
Implementation of mitk::USControlInterfaceProbes for Telemed ultrasound devices. See documentation of...
STDMETHODIMP_(ULONG) mitk
#define SAFE_RELEASE(x)
IGT Exceptions.