PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusInfraredTEEV2Cam.cxx
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2 Program: Plus
3 Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4 See License.txt for details.
5 
6 Developed by ULL & IACTEC-IAC group
7 =========================================================Plus=header=end*/
8 
9 // Local includes
10 #include "PlusConfigure.h"
11 #include "vtkPlusChannel.h"
12 #include "vtkPlusDataSource.h"
14 
15 // VTK includes
16 #include <vtkImageData.h>
17 #include <vtkObjectFactory.h>
18 
19 // TEEV2
20 #include "i3system_TE.h"
21 
22 using namespace i3;
23 
24 //----------------------------------------------------------------------------
25 
27 
28 //----------------------------------------------------------------------------
30 {
31  this->RequireImageOrientationInConfiguration = true;
32  this->StartThreadForInternalUpdates = true;
33 }
34 
35 //----------------------------------------------------------------------------
37 {
38 }
39 
40 //----------------------------------------------------------------------------
41 void vtkPlusInfraredTEEV2Cam::PrintSelf(ostream& os, vtkIndent indent)
42 {
43  this->Superclass::PrintSelf(os, indent);
44  os << indent << "InfraredTEEV2Cam: Thermal Expert EV2 Camera" << std::endl;
45 }
46 
47 //-----------------------------------------------------------------------------
48 PlusStatus vtkPlusInfraredTEEV2Cam::ReadConfiguration(vtkXMLDataElement* rootConfigElement)
49 {
50  XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement);
51  LOG_DEBUG("Configure Thermal Expert EV2");
52  return PLUS_SUCCESS;
53 }
54 
55 //-----------------------------------------------------------------------------
56 PlusStatus vtkPlusInfraredTEEV2Cam::WriteConfiguration(vtkXMLDataElement* rootConfigElement)
57 {
58  XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement);
59  return PLUS_SUCCESS;
60 }
61 
62 //----------------------------------------------------------------------------
64 {
65  if (freeze)
66  {
67  this->Disconnect();
68  }
69  else
70  {
71  this->Connect();
72  }
73  return PLUS_SUCCESS;
74 }
75 
76 //----------------------------------------------------------------------------
78 {
79  SCANINFO* pScan = new SCANINFO[MAX_USB_NUM];
80  ScanTE(pScan);
81  this->device = -1;
82  for (int i = 0; i < MAX_USB_NUM; i++)
83  {
84  if (pScan[i].bDevCon)
85  {
86  this->device = i;
87  break;
88  }
89  }
90  delete pScan;
91 
92  if (this->device == -1)
93  {
94  LOG_ERROR("Thermal Expert EV2: camera not detected.");
95  return PLUS_FAIL;
96  }
97  else {
98  LOG_DEBUG("Thermal Expert EV2 Camera handle: " << this->device);
99  }
100 
101  this->pTE = OpenTE_A(this->device);
102 
103  if (!this->pTE)
104  {
105  LOG_ERROR("Thermal Expert EV2: Failed to open.");
106  return PLUS_FAIL;
107  }
108 
109  int width = this->pTE->GetImageWidth();
110  int height = this->pTE->GetImageHeight();
111  this->pImgBuf = new unsigned short[width * height];
112  this->width = width;
113  this->height = height;
114 
115  return PLUS_SUCCESS;
116 }
117 
118 //----------------------------------------------------------------------------
120 {
121  this->pTE->CloseTE();
122  this->pImgBuf = nullptr;
123  return PLUS_SUCCESS;
124 }
125 
126 //----------------------------------------------------------------------------
128 {
129  if (!this->pTE)
130  {
131  LOG_ERROR("vtkPlusInfraredTEEV2Cam::InternalUpdate Unable to read date");
132  return PLUS_SUCCESS;
133  }
134 
135  if (!this->pTE->RecvImage(this->pImgBuf))
136  {
137  LOG_ERROR("vtkPlusInfraredTEEV2Cam::InternalUpdate Unable to receive frame");
138  return PLUS_SUCCESS;
139  }
140 
141  vtkPlusDataSource* aSource(nullptr);
142  if (this->GetFirstActiveOutputVideoSource(aSource) == PLUS_FAIL || aSource == nullptr)
143  {
144  LOG_ERROR("Unable to grab a video source. Skipping frame.");
145  return PLUS_FAIL;
146  }
147 
148  if (aSource->GetNumberOfItems() == 0)
149  {
150  // Init the buffer with the metadata from the first frame
151  aSource->SetImageType(US_IMG_BRIGHTNESS);
152  aSource->SetPixelType(VTK_UNSIGNED_SHORT);
153  aSource->SetNumberOfScalarComponents(1);
154  aSource->SetInputFrameSize(this->width, this->height, 1);
155  }
156 
157  // Add the frame to the stream buffer
158  FrameSizeType frameSize = { static_cast<unsigned int>(this->width), static_cast<unsigned int>(this->height), 1 };
159  if (aSource->AddItem(this->pImgBuf, aSource->GetInputImageOrientation(), frameSize, VTK_UNSIGNED_SHORT, 1, US_IMG_BRIGHTNESS, 0, this->FrameNumber) == PLUS_FAIL)
160  {
161  return PLUS_FAIL;
162  }
163  this->FrameNumber++;
164  return PLUS_SUCCESS;
165 }
166 
167 //----------------------------------------------------------------------------
169 {
170  if (this->OutputChannels.size() > 1)
171  {
172  LOG_WARNING("vtkPlusInfraredTEEV2Cam is expecting one output channel and there are " << this->OutputChannels.size() << " channels. First output channel will be used.");
173  }
174 
175  if (this->OutputChannels.empty())
176  {
177  LOG_ERROR("No output channels defined for vtkPlusInfraredTEEV2Cam. Cannot proceed.");
178  this->CorrectlyConfigured = false;
179  return PLUS_FAIL;
180  }
181  return PLUS_SUCCESS;
182 }
virtual PlusStatus InternalConnect() VTK_OVERRIDE
PlusStatus FreezeDevice(bool freeze)
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
igsioStatus PlusStatus
Definition: PlusCommon.h:40
vtkStandardNewMacro(vtkPlusInfraredTEEV2Cam)
PlusStatus SetInputFrameSize(unsigned int x, unsigned int y, unsigned int z)
virtual PlusStatus AddItem(vtkImageData *frame, US_IMAGE_ORIENTATION usImageOrientation, US_IMAGE_TYPE imageType, long frameNumber, double unfilteredTimestamp=UNDEFINED_TIMESTAMP, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
PlusStatus SetImageType(US_IMAGE_TYPE imageType)
for i
#define PLUS_FAIL
Definition: PlusCommon.h:43
PlusStatus SetPixelType(igsioCommon::VTKScalarPixelType pixelType)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual PlusStatus NotifyConfigured()
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
PhidgetLCD_Font int * width
Definition: phidget22.h:4275
virtual US_IMAGE_ORIENTATION GetInputImageOrientation()
PhidgetLCD_Font int int * height
Definition: phidget22.h:4275
PlusStatus SetNumberOfScalarComponents(unsigned int numberOfScalarComponents)
PlusStatus WriteConfiguration(vtkXMLDataElement *config)
Class for interfacing an Infrared Seek capture device and recording frames into a Plus buffer.
virtual PlusStatus InternalDisconnect() VTK_OVERRIDE
PlusStatus ReadConfiguration(vtkXMLDataElement *config)
virtual int GetNumberOfItems()
Interface to a 3D positioning tool, video source, or generalized data stream.