Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
OphirPyroWrapper.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #using "Interop.OphirLMMeasurementLib.dll"
14 #include <vector>
15 #include <msclr\auto_gcroot.h>
16 #include "OphirPyroWrapper.h"
17 
18 using namespace System::Runtime::InteropServices; // Marshal
19 
20 class OphirPyroWrapperPrivate
21 {
22  public: msclr::auto_gcroot<OphirLMMeasurementLib::CoLMMeasurement^> ophirAPI;
23 };
24 
25 OphirPyroWrapper::OphirPyroWrapper()
26 {
27  _private = new OphirPyroWrapperPrivate();
28  _private->ophirAPI = gcnew OphirLMMeasurementLib::CoLMMeasurement();
29 }
30 
31 OphirPyroWrapper::~OphirPyroWrapper()
32 {
33  delete _private;
34 }
35 
36 char* OphirPyroWrapper::ScanUSB()
37 {
38  char* foo;
39  System::Object^ managedObject;
40  _private->ophirAPI->ScanUSB(managedObject);
41  array<System::String^>^ managedCapi = dynamic_cast<array<System::String^>^>(managedObject);
42  if (managedCapi->Length != 0)
43  return (char*)Marshal::StringToHGlobalAnsi(managedCapi[0]).ToPointer();
44  else
45  return 0;
46 }
47 
48 int OphirPyroWrapper::OpenDevice(char* serialNumber)
49 {
50  int deviceHandle;
51  _private->ophirAPI->OpenUSBDevice(gcnew System::String(serialNumber), deviceHandle);
52 
53  return deviceHandle;
54 }
55 
56 char* OphirPyroWrapper::GetWavelengths(int deviceHandle)
57 {
58  int index;
59  System::Object^ options;
60  // Show wavelengths of channel 0
61  _private->ophirAPI->GetWavelengths(deviceHandle, 0, index, options);
62  array<System::String^>^ managedCapi = dynamic_cast<array<System::String^>^>(options);
63  if (managedCapi->Length != 0)
64  return (char*)Marshal::StringToHGlobalAnsi(managedCapi[index]).ToPointer();
65  else
66  return 0;
67 }
68 
69 char* OphirPyroWrapper::GetRanges(int deviceHandle)
70 {
71  int index;
72  System::Object^ options;
73  // Show ranges of channel 0
74  _private->ophirAPI->GetRanges(deviceHandle, 0, index, options);
75  array<System::String^>^ managedCapi = dynamic_cast<array<System::String^>^>(options);
76  if (managedCapi->Length != 0)
77  return (char*)Marshal::StringToHGlobalAnsi(managedCapi[index]).ToPointer();
78  else
79  return 0;
80 }
81 
82 bool OphirPyroWrapper::StartStream(int deviceHandle)
83 {
84  _private->ophirAPI->StartStream(deviceHandle, 0);
85  return true;
86 }
87 
88 bool OphirPyroWrapper::StopStream(int deviceHandle)
89 {
90  _private->ophirAPI->StopStream(deviceHandle, 0);
91  return true;
92 }
93 
94 bool OphirPyroWrapper::CloseDevice(int deviceHandle)
95 {
96  _private->ophirAPI->Close(deviceHandle);
97  return true;
98 }
99 
100 unsigned int OphirPyroWrapper::GetData(int deviceHandle, std::vector<double>* data, std::vector<double>* timestamp, std::vector<int>* status)
101 {
102  System::Object^ dataArray;
103  System::Object^ timeStampArray;
104  System::Object^ statusArray;
105  array<double>^ managedDataArray;
106  array<double>^ managedTimeStampArray;
107  array<int>^ managedStatusArray;
108  _private->ophirAPI->GetData(deviceHandle, 0, dataArray, timeStampArray, statusArray);
109  managedDataArray = (array<double>^)dataArray;
110  managedTimeStampArray = (array<double>^)timeStampArray;
111  managedStatusArray = (array<int>^)statusArray;
112  if (managedDataArray->Length > 0)
113  {
114  data->resize(managedDataArray->Length);
115  timestamp->resize(managedDataArray->Length);
116  status->resize(managedDataArray->Length);
117  for(int i = 0; i<managedDataArray->Length; i++)
118  {
119  (*data)[i] = managedDataArray[i];
120  (*timestamp)[i] = managedTimeStampArray[i];
121  (*status)[i] = managedStatusArray[i];
122  // DEBUG: std::cout << "managedDataArray " << i << ": " << managedDataArray[i] << " ts: " << managedTimeStampArray[i] << " status: " << managedStatusArray[i] << std::endl;
123  }
124  return managedDataArray->Length;
125  }
126  else
127  {
128  data->resize(1);
129  timestamp->resize(1);
130  status->resize(1);
131  (*data)[0] = -1;
132  (*timestamp)[0] = -1;
133  (*status)[0] = -1;
134  }
135 
136  return 0;
137 }