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