PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkInfraredTEQ1Cam.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 MACBIOIDI-ULPGC & IACTEC-IAC group
7 =========================================================Plus=header=end*/
8 
9 // Local includes
10 #include "PlusConfigure.h"
11 #include "vtkPlusChannel.h"
12 #include "vtkPlusDataSource.h"
13 #include "vtkInfraredTEQ1Cam.h"
14 
15 // VTK includes
16 #include <vtkImageData.h>
17 #include <vtkObjectFactory.h>
18 
19 // TEQ1
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 vtkInfraredTEQ1Cam::PrintSelf(ostream& os, vtkIndent indent)
42 {
43 
44  this->Superclass::PrintSelf(os, indent);
45 
46  os << indent << "InfraredTEQ1Cam: Pro Seek Camera" << std::endl;
47 }
48 
49 //-----------------------------------------------------------------------------
50 PlusStatus vtkInfraredTEQ1Cam::ReadConfiguration(vtkXMLDataElement* rootConfigElement)
51 {
52  XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement);
53  LOG_DEBUG("Configure Thermal Expert Q1");
54 
55  return PLUS_SUCCESS;
56 }
57 
58 //-----------------------------------------------------------------------------
59 PlusStatus vtkInfraredTEQ1Cam::WriteConfiguration(vtkXMLDataElement* rootConfigElement)
60 {
61  XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement);
62  return PLUS_SUCCESS;
63 }
64 
65 //----------------------------------------------------------------------------
67 {
68  if (freeze)
69  {
70  this->Disconnect();
71  }
72  else
73  {
74  this->Connect();
75  }
76  return PLUS_SUCCESS;
77 }
78 
79 //----------------------------------------------------------------------------
81 {
82  SCANINFO* pScan = new SCANINFO[MAX_USB_NUM];
83  ScanTE(nullptr, pScan);
84  this->device = -1;
85  for (int i = 0; i < MAX_USB_NUM; i++)
86  {
87  if (pScan[i].bDevCon)
88  {
89  this->device = i;
90  break;
91  }
92  }
93  delete pScan;
94 
95  if (this->device == -1)
96  {
97  LOG_ERROR("Thermal Expert Q1: camera not detected.");
98  return PLUS_FAIL;
99  }
100 
101  this->pTE = OpenTE_B(nullptr, I3_TE_Q1, this->device);
102  if (! this->pTE)
103  {
104  LOG_ERROR("Thermal Expert Q1: Failed to open.");
105  return PLUS_FAIL;
106  }
107 
108  if (this->pTE->ReadFlashData() == 1)
109  {
110  int width = this->pTE->GetImageWidth();
111  int height = this->pTE->GetImageHeight();
112  this->pImgBuf = new float[width * height];
113  this->width = width;
114  this->height = height;
115  }
116  else
117  {
118  LOG_ERROR("Thermal Expert Q1: Fail to Read Flash Data.");
119  return PLUS_FAIL;
120  }
121  return PLUS_SUCCESS;
122 }
123 
124 //----------------------------------------------------------------------------
126 {
127  this->pTE->CloseTE();
128  this->pImgBuf = nullptr;
129  return PLUS_SUCCESS;
130 }
131 
132 //----------------------------------------------------------------------------
134 {
135  if (!this->pTE)
136  {
137  LOG_ERROR("vtkInfraredTEQ1Cam::InternalUpdate Unable to read date");
138  return PLUS_SUCCESS;
139  }
140 
141  if (!this->pTE->RecvImage(this->pImgBuf))
142  {
143  LOG_ERROR("vtkInfraredTEQ1Cam::InternalUpdate Unable to receive frame");
144  return PLUS_SUCCESS;
145  }
146 
147  pTE->CalcEntireTemp(this->pImgBuf, false);
148 
149  vtkPlusDataSource* aSource(nullptr);
150  if (this->GetFirstActiveOutputVideoSource(aSource) == PLUS_FAIL || aSource == nullptr)
151  {
152  LOG_ERROR("Unable to grab a video source. Skipping frame.");
153  return PLUS_FAIL;
154  }
155 
156  if (aSource->GetNumberOfItems() == 0)
157  {
158  // Init the buffer with the metadata from the first frame
159  aSource->SetImageType(US_IMG_BRIGHTNESS);
160  aSource->SetPixelType(VTK_TYPE_FLOAT32);
161  aSource->SetNumberOfScalarComponents(1);
162  aSource->SetInputFrameSize(this->width, this->height, 1);
163  }
164 
165  // Add the frame to the stream buffer
166  FrameSizeType frameSize = { static_cast<unsigned int>(this->width), static_cast<unsigned int>(this->height), 1 };
167  if (aSource->AddItem(this->pImgBuf, aSource->GetInputImageOrientation(), frameSize, VTK_TYPE_FLOAT32, 1, US_IMG_BRIGHTNESS, 0, this->FrameNumber) == PLUS_FAIL)
168  {
169  return PLUS_FAIL;
170  }
171 
172  this->FrameNumber++;
173 
174  return PLUS_SUCCESS;
175 }
176 
177 //----------------------------------------------------------------------------
179 {
180  if (this->OutputChannels.size() > 1)
181  {
182  LOG_WARNING("vtkInfraredTEQ1Cam is expecting one output channel and there are " << this->OutputChannels.size() << " channels. First output channel will be used.");
183  }
184 
185  if (this->OutputChannels.empty())
186  {
187  LOG_ERROR("No output channels defined for vtkInfraredTEQ1Cam. Cannot proceed.");
188  this->CorrectlyConfigured = false;
189  return PLUS_FAIL;
190  }
191 
192  return PLUS_SUCCESS;
193 }
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
virtual PlusStatus InternalDisconnect() VTK_OVERRIDE
igsioStatus PlusStatus
Definition: PlusCommon.h:40
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
virtual PlusStatus InternalConnect() VTK_OVERRIDE
#define PLUS_FAIL
Definition: PlusCommon.h:43
PlusStatus SetPixelType(igsioCommon::VTKScalarPixelType pixelType)
PlusStatus WriteConfiguration(vtkXMLDataElement *config)
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
PlusStatus FreezeDevice(bool freeze)
vtkStandardNewMacro(vtkInfraredTEQ1Cam)
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
PhidgetLCD_Font int * width
Definition: phidget22.h:4275
Class for interfacing an Infrared Seek capture device and recording frames into a Plus buffer.
virtual US_IMAGE_ORIENTATION GetInputImageOrientation()
PhidgetLCD_Font int int * height
Definition: phidget22.h:4275
PlusStatus SetNumberOfScalarComponents(unsigned int numberOfScalarComponents)
PlusStatus ReadConfiguration(vtkXMLDataElement *config)
virtual PlusStatus NotifyConfigured()
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual int GetNumberOfItems()
Interface to a 3D positioning tool, video source, or generalized data stream.