8 #include "PlusConfigure.h" 15 #include <igtlImageMessage.h> 18 #include <vtkImageData.h> 19 #include <vtkObjectFactory.h> 43 LOG_TRACE(
"vtkPlusOpenIGTLinkVideoSource::InternalUpdate");
50 igtl::MessageHeader::Pointer headerMsg;
62 if (headerMsg ==
nullptr)
72 double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
74 igsioTrackedFrame trackedFrame;
75 igtl::MessageBase::Pointer bodyMsg = this->
MessageFactory->CreateReceiveMessage(headerMsg);
77 if (
typeid(*bodyMsg) ==
typeid(igtl::ImageMessage))
81 LOG_ERROR(
"Couldn't get image from OpenIGTLink server!");
89 LOG_ERROR(
"Couldn't get tracked frame from OpenIGTLink server!");
92 double unfilteredTimestampUtc = trackedFrame.GetTimestamp();
97 unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTimeFromUniversalTime(unfilteredTimestampUtc);
103 igsioLockGuard<vtkIGSIORecursiveCriticalSection> socketGuard(this->
SocketMutex);
104 this->
ClientSocket->Skip(headerMsg->GetBodySizeToRead(), 0);
110 double filteredTimestamp = unfilteredTimestamp;
119 LOG_ERROR(
"Unable to retrieve the video source in the OpenIGTLinkVideo device.");
126 igsioVideoFrame* videoFrame = trackedFrame.GetImageData();
127 if (videoFrame == NULL)
129 LOG_ERROR(
"Invalid video frame received, cannot use it to initialize the video buffer");
132 aSource->
SetPixelType(videoFrame->GetVTKScalarPixelType());
133 unsigned int numberOfScalarComponents(1);
134 if (videoFrame->GetNumberOfScalarComponents(numberOfScalarComponents) !=
PLUS_SUCCESS)
136 LOG_ERROR(
"Unable to retrieve number of scalar components.");
143 igsioFieldMapType customFields = trackedFrame.GetCustomFields();
144 PlusStatus status = aSource->
AddItem(trackedFrame.GetImageData(), this->
FrameNumber, unfilteredTimestamp, filteredTimestamp, &customFields);
171 LOG_WARNING(
"vtkPlusOpenIGTLinkVideoSource is expecting one output channel and there are " << this->
OutputChannels.size() <<
" channels. First output channel will be used.");
177 LOG_ERROR(
"No output channels defined for vtkPlusOpenIGTLinkVideoSource. Cannot proceed.");
vtkPlusOpenIGTLinkVideoSource()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
virtual ~vtkPlusOpenIGTLinkVideoSource()
vtkSmartPointer< vtkPlusIgtlMessageFactory > MessageFactory
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)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *config)
vtkSmartPointer< vtkIGSIORecursiveCriticalSection > SocketMutex
bool RequireImageOrientationInConfiguration
PlusStatus SetImageType(US_IMAGE_TYPE imageType)
igsioTransformName ImageMessageEmbeddedTransformName
IGTL message helper class for tracked frame messages.
PlusStatus SetPixelType(igsioCommon::VTKScalarPixelType pixelType)
static PlusStatus UnpackTrackedFrameMessage(igtl::MessageHeader::Pointer headerMsg, igtl::Socket *socket, igsioTrackedFrame &trackedFrame, const igsioTransformName &embeddedTransformName, int crccheck)
virtual PlusStatus NotifyConfigured()
PlusStatus GetFirstActiveOutputVideoSource(vtkPlusDataSource *&aVideoSource)
virtual void SetCorrectlyConfigured(bool)
unsigned long FrameNumber
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual PlusStatus ReceiveMessageHeader(igtl::MessageHeader::Pointer &headerMsg)
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
bool UseReceivedTimestamps
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
static PlusStatus UnpackImageMessage(igtl::MessageHeader::Pointer headerMsg, igtl::Socket *socket, igsioTrackedFrame &trackedFrame, const igsioTransformName &embeddedTransformName, int crccheck)
virtual bool IsRecording() const
igtl::ClientSocket::Pointer ClientSocket
VTK interface for video input from OpenIGTLink image message.
virtual int GetConnected() const
ChannelContainer OutputChannels
PlusStatus SetNumberOfScalarComponents(unsigned int numberOfScalarComponents)
vtkStandardNewMacro(vtkPlusOpenIGTLinkVideoSource)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *config)
PlusStatus InternalUpdate()
virtual int GetNumberOfItems()
int IgtlMessageCrcCheckEnabled
Interface to a 3D positioning tool, video source, or generalized data stream.