7 #include "PlusConfigure.h" 8 #include "vtkObjectFactory.h" 11 #include "vtkUnsignedCharArray.h" 24 class vtkPlusThorLabsVideoSourceInternal
28 vtkPlusThorLabsVideoSourceInternal()
29 : InstrumentHandle(VI_NULL)
33 virtual ~vtkPlusThorLabsVideoSourceInternal()
38 std::string GetThorLabsErrorString(ViStatus err)
40 ViChar ebuf[TLCCS_ERR_DESCR_BUFFER_SIZE];
41 tlccs_error_message (this->InstrumentHandle, err, ebuf);
45 ViSession InstrumentHandle;
46 ViReal64 WavelengthIntensityDataBuffer[2*TLCCS_NUM_PIXELS];
53 : Internal(new vtkPlusThorLabsVideoSourceInternal)
54 , InstrumentName(NULL)
55 , IntegrationTimeSec(0.050)
79 LOG_TRACE(
"vtkPlusThorLabsVideoSource::ReadConfiguration")
88 LOG_TRACE(
"vtkPlusThorLabsVideoSource::WriteConfiguration");
103 ViStatus err = VI_SUCCESS;
105 std::string selectedInstrumentName;
112 LOG_DEBUG(
"Scanning for CCS instruments...");
113 ViSession resourceManager = VI_NULL;
114 err = viOpenDefaultRM(&resourceManager);
117 LOG_ERROR(
"Error opening ThorLabs resource manager: "<<this->
Internal->GetThorLabsErrorString(err));
120 ViChar instrumentNameBuffer[VI_FIND_BUFLEN]={0};
121 ViUInt32 numberOfInstrumentsFound = 0;
122 err = viFindRsrc(resourceManager, TLCCS_FIND_PATTERN, VI_NULL, &numberOfInstrumentsFound, instrumentNameBuffer);
125 viClose(resourceManager);
126 LOG_ERROR(
"Error finding ThorLabs resource devices: "<<this->
Internal->GetThorLabsErrorString(err));
129 LOG_DEBUG(
"Found "<<numberOfInstrumentsFound<<
" instrument(s). Selected instrument: "<<instrumentNameBuffer);
130 selectedInstrumentName = instrumentNameBuffer;
131 viClose(resourceManager);
134 err = tlccs_init((
char*)selectedInstrumentName.c_str(), VI_OFF, VI_OFF, &this->
Internal->InstrumentHandle);
137 LOG_ERROR(
"Error opening session to ThorLabs device: "<<this->
Internal->GetThorLabsErrorString(err));
141 err = tlccs_setIntegrationTime(this->
Internal->InstrumentHandle, this->IntegrationTimeSec);
144 LOG_ERROR(
"Error setting integration time "<< this->
IntegrationTimeSec <<
"sec in ThorLabs device: "<<this->
Internal->GetThorLabsErrorString(err));
145 tlccs_close(this->
Internal->InstrumentHandle);
149 memset(this->
Internal->WavelengthIntensityDataBuffer, 0,
sizeof(this->Internal->WavelengthIntensityDataBuffer));
150 err = tlccs_getWavelengthData (this->
Internal->InstrumentHandle, TLCCS_CAL_DATA_SET_FACTORY, this->Internal->WavelengthIntensityDataBuffer, NULL, NULL);
153 LOG_ERROR(
"Error getting wavelength values in ThorLabs device: "<<this->
Internal->GetThorLabsErrorString(err));
154 tlccs_close(this->
Internal->InstrumentHandle);
162 LOG_ERROR(
"Unable to access video source in vtkPlusThorLabsVideoSource. Critical failure.");
163 tlccs_close(this->
Internal->InstrumentHandle);
177 tlccs_close(this->
Internal->InstrumentHandle);
186 ViStatus err = tlccs_getDeviceStatus(this->
Internal->InstrumentHandle, &status);
189 LOG_ERROR(
"Error getting device status in ThorLabs device: "<<this->
Internal->GetThorLabsErrorString(err));
194 if(status & TLCCS_STATUS_SCAN_IDLE)
197 err = tlccs_startScan(this->
Internal->InstrumentHandle);
200 LOG_ERROR(
"Error starting scan in ThorLabs device: "<<this->
Internal->GetThorLabsErrorString(err));
206 if(status & TLCCS_STATUS_SCAN_TRANSFER)
208 double* intensityDataBuffer = this->
Internal->WavelengthIntensityDataBuffer+TLCCS_NUM_PIXELS;
209 err = tlccs_getScanData(this->
Internal->InstrumentHandle, intensityDataBuffer);
212 LOG_ERROR(
"Error getting scan data in ThorLabs device: "<<this->
Internal->GetThorLabsErrorString(err));
219 LOG_ERROR(
"Unable to retrieve the video source in the ThorLabs device.");
223 FrameSizeType frameSizeInPx = {TLCCS_NUM_PIXELS, 2, 1};
224 aSource->
AddItem(this->
Internal->WavelengthIntensityDataBuffer, US_IMG_ORIENT_MF, frameSizeInPx, VTK_DOUBLE, 1, US_IMG_BRIGHTNESS, 0, this->FrameIndex);
251 LOG_WARNING(
"ThorLabsVideoSource is expecting one output channel and there are " << this->
OutputChannels.size() <<
" channels. First output channel will be used.");
257 LOG_ERROR(
"No output channels defined for ThorLabs video source. Cannot proceed." );
265 LOG_ERROR(
"Unable to retrieve the video source in the ThorLabs device.");
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual PlusStatus InternalStopRecording()
vtkPlusThorLabsVideoSource()
PlusStatus ReadConfiguration(vtkXMLDataElement *config) override
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
vtkPlusThorLabsVideoSourceInternal * Internal
PlusStatus SetInputFrameSize(unsigned int x, unsigned int y, unsigned int z)
~vtkPlusThorLabsVideoSource()
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)
bool RequireImageOrientationInConfiguration
virtual PlusStatus SetInputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
virtual PlusStatus InternalDisconnect()
PlusStatus SetPixelType(igsioCommon::VTKScalarPixelType pixelType)
PlusStatus GetFirstVideoSource(vtkPlusDataSource *&anImage)
virtual PlusStatus InternalUpdate()
virtual PlusStatus NotifyConfigured()
virtual PlusStatus InternalConnect()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
double IntegrationTimeSec
PlusStatus WriteConfiguration(vtkXMLDataElement *config) override
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual US_IMAGE_ORIENTATION GetInputImageOrientation()
bool StartThreadForInternalUpdates
virtual int GetConnected() const
ChannelContainer OutputChannels
PlusStatus SetNumberOfScalarComponents(unsigned int numberOfScalarComponents)
virtual void SetInstrumentName(const char *)
vtkStandardNewMacro(vtkPlusThorLabsVideoSource)
virtual PlusStatus InternalStartRecording()
ThorLabs compact spectrometer.
Interface to a 3D positioning tool, video source, or generalized data stream.