MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSTelemedProbesControls.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
14#include "mitkUSTelemedDevice.h"
15#include <mitkException.h>
16
18 : mitk::USControlInterfaceProbes(device.GetPointer()),
19 m_IsActive(false), m_TelemedDevice(device),
20 m_ProbesCollection(0), m_Probe(0)
21{
22}
23
28
30{
31 if ( ! m_TelemedDevice )
32 {
33 MITK_WARN("USTelemedProbesControls")("USControlInterfaceProbes")
34 << "Cannot activate probe controls while device is not set.";
35 return;
36 }
37
38 if ( isActive && m_ProbesCollection == 0 )
39 {
40 this->CreateProbesCollection();
41 this->CreateProbesSet();
42 }
43 else
44 {
45 }
46
47 m_IsActive = isActive;
48}
49
51{
52 return m_IsActive;
53}
54
55std::vector<mitk::USProbe::Pointer> mitk::USTelemedProbesControls::GetProbeSet()
56{
57 // create a new vector of base class (USProbe) objects, because
58 // interface wants a vector of this type
59 std::vector<mitk::USProbe::Pointer> usProbes;
60 for (unsigned int n = 0; n < m_ProbesSet.size(); ++n)
61 {
62 usProbes.push_back(m_ProbesSet.at(n).GetPointer());
63 }
64 return usProbes;
65}
66
68{
69 if (index >= m_ProbesSet.size())
70 {
71 MITK_ERROR("USTelemedProbesControls")("USControlInterfaceProbes")
72 << "Cannot select probe with index " << index << ". Maximum possible index is " << m_ProbesSet.size()-1 << ".";
73 mitkThrow() << "Cannot select probe with index " << index <<
74 ". Maximum possible index is " << m_ProbesSet.size()-1 << ".";
75 }
76
77 m_TelemedDevice->SetActiveDataView(m_ProbesSet.at(index)->GetUsgDataView());
78
79 m_SelectedProbeIndex = index;
80}
81
82void mitk::USTelemedProbesControls::OnSelectProbe(mitk::USProbe::Pointer probe)
83{
84}
85
87{
88 if (m_SelectedProbeIndex >= m_ProbesSet.size())
89 {
90 MITK_ERROR("USTelemedProbesControls")("USControlInterfaceProbes")
91 << "Cannot get active probe as the current index is" << m_SelectedProbeIndex <<
92 ". Maximum possible index is " << m_ProbesSet.size()-1 << ".";
93 mitkThrow() << "Cannot get active probe as the current index is" << m_SelectedProbeIndex <<
94 ". Maximum possible index is " << m_ProbesSet.size()-1 << ".";
95 }
96
97 return m_ProbesSet.at(m_SelectedProbeIndex).GetPointer();
98}
99
101{
102 return m_ProbesSet.size();
103}
104
105/*void mitk::USTelemedProbesControls::SetTelemedDevice(itk::SmartPointer<USTelemedDevice> telemedDevice)
106{
107 m_TelemedDevice = telemedDevice;
108}*/
109
111{
112 MITK_INFO << "Probe removed...";
113
114 if ( m_ProbesSet.size() > index )
115 {
116 m_ProbesSet.erase(m_ProbesSet.begin() + index);
117 }
118}
119
121{
122 MITK_INFO << "Probe arrived...";
123
124 this->CreateProbesCollection();
125 this->CreateProbesSet();
126
127 // Activate the added probe, if the added probe is the first probe
128 if (m_ProbesSet.size() == 1)
129 {
130 m_TelemedDevice->SetActiveDataView(m_ProbesSet.at(0)->GetUsgDataView());
131 }
132}
133
135{
136 IUnknown* tmp_obj = nullptr;
137 HRESULT hr;
138
139 // get the main API interface from the Telemed device
140 Usgfw2Lib::IUsgfw2* usgMainInterface = m_TelemedDevice->GetUsgMainInterface();
141 if ( ! usgMainInterface )
142 {
143 MITK_ERROR("USTelemedProbesControls")("USControlInterfaceProbes")
144 << "Main interface of Telemed device must not be null.";
145 mitkThrow() << "Main interface of Telemed device must not be null.";
146 }
147
148 // get probes collection from Telemed API
149 hr = usgMainInterface->get_ProbesCollection(&tmp_obj);
150 if (FAILED(hr) || ! tmp_obj)
151 {
152 MITK_WARN("USTelemedProbesControls")("USControlInterfaceProbes")
153 << "Error on getting probes collection (" << hr << ").";
154 return false;
155 }
156
157 // second step for getting probes collection from Telemed API
158 SAFE_RELEASE(m_ProbesCollection);
159 hr = tmp_obj->QueryInterface(Usgfw2Lib::IID_IUsgCollection,(void**)&m_ProbesCollection);
160 SAFE_RELEASE(tmp_obj);
161 if (FAILED(hr) || ! m_ProbesCollection)
162 {
163 MITK_WARN("USTelemedProbesControls")("USControlInterfaceProbes")
164 << "Error on querying interface for probes collection (" << hr << ").";
165 return false;
166 }
167
168 return true;
169}
170
172{
173 if ( ! m_ProbesCollection)
174 {
175 MITK_ERROR("USTelemedProbesControls")("USControlInterfaceProbes")
176 << "Cannot get probe set without ProbesCollection being initialized before.";
177 mitkThrow() << "Cannot get probe set without ProbesCollection being initialized before.";
178 }
179
180 // get number of available probes
181 LONG probes_count = 0;
182 HRESULT hr = m_ProbesCollection->get_Count(&probes_count);
183 if (FAILED(hr)) { mitkThrow() << "Could not get probes count (" << hr << ")."; }
184
185 if ( ! m_TelemedDevice )
186 {
187 MITK_ERROR("USTelemedProbesControls")("USControlInterfaceProbes")
188 << "Telemed device must not be null when creating probes set.";
189 mitkThrow() << "Telemed device must not be null when creating probes set.";
190 }
191
192 // get the main API interface from the Telemed device
193 Usgfw2Lib::IUsgfw2* usgMainInterface = m_TelemedDevice->GetUsgMainInterface();
194 if ( ! usgMainInterface )
195 {
196 MITK_ERROR("USTelemedProbesControls")("USControlInterfaceProbes")
197 << "Usg main interface must not be null when creating probes set.";
198 mitkThrow() << "Usg main interface must not be null when creating probes set.";
199 }
200
201 // initialize probes set with new vector
202 m_ProbesSet = std::vector<mitk::USTelemedProbe::Pointer>();
203
204 for (LONG n = 0; n < probes_count; ++n)
205 {
206 // get the probe item from the API collection
207 IUnknown* tmp_obj = nullptr;
208 hr = m_ProbesCollection->Item(n,&tmp_obj);
209 if (FAILED(hr))
210 {
211 MITK_ERROR("USTelemedProbesControls")("USControlInterfaceProbes")
212 << "Could not get probe with index " << n << ".";
213 mitkThrow() << "Could not get probe with index " << n << ".";
214 }
215
216 // convert this item to a probe
217 Usgfw2Lib::IProbe* probe;
218 hr = tmp_obj->QueryInterface(Usgfw2Lib::IID_IProbe,(void**)&probe);
219 if (FAILED(hr))
220 {
221 MITK_ERROR("USTelemedProbesControls")("USControlInterfaceProbes")
222 << "Error on querying interface for probe with index "<< n << ".";
223 mitkThrow() << "Error on querying interface for probe with index "<< n << ".";
224 }
225
226 // create main ultrasound scanning object for selected probe
227 Usgfw2Lib::IUsgDataView* usgDataView;
228 Usgfw2Lib::IUsgDataViewPtr usgDataViewTmp;
229 usgDataViewTmp = usgMainInterface->CreateDataView(probe);
230 usgDataViewTmp->QueryInterface(Usgfw2Lib::IID_IUsgDataView, (void**)&usgDataView);
231 if (! usgDataView)
232 {
233 MITK_ERROR("USTelemedProbesControls")("USControlInterfaceProbes")
234 << "Could not create data view for selected probe.";
235 mitkThrow() << "Could not create data view for selected probe.";
236 }
237
238 // probe object can be created now from API data
239 m_ProbesSet.push_back(mitk::USTelemedProbe::New(probe, usgDataView));
240
241 SAFE_RELEASE(tmp_obj);
242 }
243}
Interface defining methods for probe selection of ultrasound devices. It consists of methods for gett...
virtual void OnSelectProbe(unsigned int index)
Virtual method which is called inside mitk::USControlInterfaceProbes::SelectProbe()....
virtual unsigned int GetProbesCount() const
USTelemedProbesControls(itk::SmartPointer< USTelemedDevice > device)
virtual USProbe::Pointer GetSelectedProbe()
virtual std::vector< USProbe::Pointer > GetProbeSet()
#define SAFE_RELEASE(x)
IGT Exceptions.