@@ -16,11 +16,11 @@ See License.txt for details.
1616#include " vtkPlusDataSource.h"
1717#include " vtkPlusIgtlMessageCommon.h"
1818
19- vtkStandardNewMacro (vtkPlusOpenIGTLinkVideoSource);
19+ vtkStandardNewMacro ( vtkPlusOpenIGTLinkVideoSource );
2020
2121// ----------------------------------------------------------------------------
2222vtkPlusOpenIGTLinkVideoSource::vtkPlusOpenIGTLinkVideoSource ()
23- : IgtlMessageFactory(vtkSmartPointer<vtkPlusIgtlMessageFactory>::New())
23+ : IgtlMessageFactory( vtkSmartPointer<vtkPlusIgtlMessageFactory>::New() )
2424{
2525 this ->RequireImageOrientationInConfiguration = true ;
2626}
@@ -31,118 +31,119 @@ vtkPlusOpenIGTLinkVideoSource::~vtkPlusOpenIGTLinkVideoSource()
3131}
3232
3333// ----------------------------------------------------------------------------
34- void vtkPlusOpenIGTLinkVideoSource::PrintSelf (ostream& os, vtkIndent indent)
34+ void vtkPlusOpenIGTLinkVideoSource::PrintSelf ( ostream& os, vtkIndent indent )
3535{
36- this ->Superclass ::PrintSelf (os,indent);
36+ this ->Superclass ::PrintSelf ( os, indent );
3737}
3838
3939// ----------------------------------------------------------------------------
4040PlusStatus vtkPlusOpenIGTLinkVideoSource::InternalUpdate ()
4141{
4242 LOG_TRACE ( " vtkPlusOpenIGTLinkVideoSource::InternalUpdate" );
43- if (!this ->Recording )
43+ if ( !this ->Recording )
4444 {
4545 // drop the frame, we are not recording data now
4646 return PLUS_SUCCESS;
4747 }
4848
4949 igtl::MessageHeader::Pointer headerMsg;
50- ReceiveMessageHeaderWithErrorHandling (headerMsg);
51-
52- if (headerMsg.IsNull ())
50+ ReceiveMessageHeaderWithErrorHandling ( headerMsg );
51+
52+ if ( headerMsg.IsNull () )
5353 {
5454 OnReceiveTimeout ();
5555 return PLUS_FAIL;
5656 }
5757
5858 // We've received valid header data
59- headerMsg->Unpack (this ->IgtlMessageCrcCheckEnabled );
59+ headerMsg->Unpack ( this ->IgtlMessageCrcCheckEnabled );
6060
6161 // Set unfiltered and filtered timestamp by converting UTC to system timestamp
6262 double unfilteredTimestamp = vtkPlusAccurateTimer::GetSystemTime ();
6363
6464 PlusTrackedFrame trackedFrame;
65- igtl::MessageBase::Pointer bodyMsg = IgtlMessageFactory->CreateReceiveMessage (headerMsg);
65+ vtkSmartPointer<vtkMatrix4x4> embeddedImageTransform;
66+ igtl::MessageBase::Pointer bodyMsg = IgtlMessageFactory->CreateReceiveMessage ( headerMsg );
6667
67- if ( typeid (*bodyMsg) == typeid (igtl::ImageMessage) )
68+ if ( typeid ( *bodyMsg ) == typeid ( igtl::ImageMessage ) )
6869 {
69- if (vtkPlusIgtlMessageCommon::UnpackImageMessage ( bodyMsg, this ->ClientSocket , trackedFrame, this ->ImageMessageEmbeddedTransformName , this ->IgtlMessageCrcCheckEnabled )!= PLUS_SUCCESS)
70+ if ( vtkPlusIgtlMessageCommon::UnpackImageMessage ( bodyMsg, this ->ClientSocket , trackedFrame, this ->ImageMessageEmbeddedTransformName , this ->IgtlMessageCrcCheckEnabled ) != PLUS_SUCCESS )
7071 {
71- LOG_ERROR (" Couldn't get image from OpenIGTLink server!" );
72+ LOG_ERROR ( " Couldn't get image from OpenIGTLink server!" );
7273 return PLUS_FAIL;
7374 }
7475 }
75- else if ( typeid (*bodyMsg) == typeid (igtl::PlusTrackedFrameMessage) )
76+ else if ( typeid ( *bodyMsg ) == typeid ( igtl::PlusTrackedFrameMessage ) )
7677 {
77- if ( vtkPlusIgtlMessageCommon::UnpackTrackedFrameMessage ( bodyMsg, this ->ClientSocket , trackedFrame, this ->IgtlMessageCrcCheckEnabled ) != PLUS_SUCCESS )
78+ if ( vtkPlusIgtlMessageCommon::UnpackTrackedFrameMessage ( bodyMsg, this ->ClientSocket , trackedFrame, embeddedImageTransform, this ->IgtlMessageCrcCheckEnabled ) != PLUS_SUCCESS )
7879 {
79- LOG_ERROR (" Couldn't get tracked frame from OpenIGTLink server!" );
80- return PLUS_FAIL;
80+ LOG_ERROR ( " Couldn't get tracked frame from OpenIGTLink server!" );
81+ return PLUS_FAIL;
8182 }
8283 double unfilteredTimestampUtc = trackedFrame.GetTimestamp ();
83- if (this ->UseReceivedTimestamps )
84+ if ( this ->UseReceivedTimestamps )
8485 {
8586 // Use the timestamp in the OpenIGTLink message
8687 // The received timestamp is in UTC and timestamps in the buffer are in system time, so conversion is needed
87- unfilteredTimestamp = vtkPlusAccurateTimer::GetSystemTimeFromUniversalTime (unfilteredTimestampUtc);
88+ unfilteredTimestamp = vtkPlusAccurateTimer::GetSystemTimeFromUniversalTime ( unfilteredTimestampUtc );
8889 }
8990 }
9091 else
9192 {
92- // if the data type is unknown, skip reading.
93- this ->ClientSocket ->Skip (headerMsg->GetBodySizeToRead (), 0 );
94- return PLUS_SUCCESS;
93+ // if the data type is unknown, skip reading.
94+ this ->ClientSocket ->Skip ( headerMsg->GetBodySizeToRead (), 0 );
95+ return PLUS_SUCCESS;
9596 }
9697
97- // No need to filter already filtered timestamped items received over OpenIGTLink
98+ // No need to filter already filtered timestamped items received over OpenIGTLink
9899 // If the original timestamps are not used it's still safer not to use filtering, as filtering assumes uniform frame rate, which is not guaranteed
99100 double filteredTimestamp = unfilteredTimestamp;
100101
101- // The timestamps are already defined, so we don't need to filter them,
102+ // The timestamps are already defined, so we don't need to filter them,
102103 // for simplicity, we increase frame number always by 1.
103104 this ->FrameNumber ++;
104105
105- vtkPlusDataSource* aSource= NULL ;
106- if ( this ->GetFirstActiveOutputVideoSource (aSource) != PLUS_SUCCESS )
106+ vtkPlusDataSource* aSource = NULL ;
107+ if ( this ->GetFirstActiveOutputVideoSource ( aSource ) != PLUS_SUCCESS )
107108 {
108- LOG_ERROR (" Unable to retrieve the video source in the OpenIGTLinkVideo device." );
109+ LOG_ERROR ( " Unable to retrieve the video source in the OpenIGTLinkVideo device." );
109110 return PLUS_FAIL;
110111 }
111112
112- // If the buffer is empty, set the pixel type and frame size to the first received properties
113+ // If the buffer is empty, set the pixel type and frame size to the first received properties
113114 if ( aSource->GetNumberOfItems () == 0 )
114115 {
115- PlusVideoFrame* videoFrame= trackedFrame.GetImageData ();
116- if (videoFrame== NULL )
116+ PlusVideoFrame* videoFrame = trackedFrame.GetImageData ();
117+ if ( videoFrame == NULL )
117118 {
118- LOG_ERROR (" Invalid video frame received, cannot use it to initialize the video buffer" );
119+ LOG_ERROR ( " Invalid video frame received, cannot use it to initialize the video buffer" );
119120 return PLUS_FAIL;
120121 }
121122 aSource->SetPixelType ( videoFrame->GetVTKScalarPixelType () );
122123 aSource->SetNumberOfScalarComponents ( videoFrame->GetNumberOfScalarComponents () );
123124 aSource->SetImageType ( videoFrame->GetImageType () );
124125 aSource->SetInputFrameSize ( trackedFrame.GetFrameSize () );
125126 }
126- PlusTrackedFrame::FieldMapType customFields= trackedFrame.GetCustomFields ();
127- PlusStatus status = aSource->AddItem ( trackedFrame.GetImageData (), this ->FrameNumber , unfilteredTimestamp, filteredTimestamp, &customFields);
127+ PlusTrackedFrame::FieldMapType customFields = trackedFrame.GetCustomFields ();
128+ PlusStatus status = aSource->AddItem ( trackedFrame.GetImageData (), this ->FrameNumber , unfilteredTimestamp, filteredTimestamp, &customFields );
128129 this ->Modified ();
129130
130131 return status;
131132}
132133
133134// -----------------------------------------------------------------------------
134- PlusStatus vtkPlusOpenIGTLinkVideoSource::ReadConfiguration (vtkXMLDataElement* rootConfigElement)
135+ PlusStatus vtkPlusOpenIGTLinkVideoSource::ReadConfiguration ( vtkXMLDataElement* rootConfigElement )
135136{
136- XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING (deviceConfig, rootConfigElement);
137- XML_READ_STRING_ATTRIBUTE_OPTIONAL (ImageMessageEmbeddedTransformName, deviceConfig);
137+ XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING ( deviceConfig, rootConfigElement );
138+ XML_READ_STRING_ATTRIBUTE_OPTIONAL ( ImageMessageEmbeddedTransformName, deviceConfig );
138139 return PLUS_SUCCESS;
139140}
140141
141142// ----------------------------------------------------------------------------
142- PlusStatus vtkPlusOpenIGTLinkVideoSource::WriteConfiguration (vtkXMLDataElement* rootConfigElement)
143+ PlusStatus vtkPlusOpenIGTLinkVideoSource::WriteConfiguration ( vtkXMLDataElement* rootConfigElement )
143144{
144- XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING (deviceConfig, rootConfigElement);
145- deviceConfig->SetAttribute (" ImageMessageEmbeddedTransformName" , this ->ImageMessageEmbeddedTransformName .GetTransformName ().c_str ());
145+ XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING ( deviceConfig, rootConfigElement );
146+ deviceConfig->SetAttribute ( " ImageMessageEmbeddedTransformName" , this ->ImageMessageEmbeddedTransformName .GetTransformName ().c_str () );
146147 return PLUS_SUCCESS;
147148}
148149
@@ -151,22 +152,22 @@ PlusStatus vtkPlusOpenIGTLinkVideoSource::NotifyConfigured()
151152{
152153 if ( this ->OutputChannels .size () > 1 )
153154 {
154- LOG_WARNING (" vtkPlusOpenIGTLinkVideoSource is expecting one output channel and there are " << this ->OutputChannels .size () << " channels. First output channel will be used." );
155+ LOG_WARNING ( " vtkPlusOpenIGTLinkVideoSource is expecting one output channel and there are " << this ->OutputChannels .size () << " channels. First output channel will be used." );
155156 return PLUS_FAIL;
156157 }
157158
158159 if ( this ->OutputChannels .empty () )
159160 {
160- LOG_ERROR (" No output channels defined for vtkPlusOpenIGTLinkVideoSource. Cannot proceed." );
161- this ->SetCorrectlyConfigured (false );
161+ LOG_ERROR ( " No output channels defined for vtkPlusOpenIGTLinkVideoSource. Cannot proceed." );
162+ this ->SetCorrectlyConfigured ( false );
162163 return PLUS_FAIL;
163164 }
164165
165166 return PLUS_SUCCESS;
166167}
167168
168169// ----------------------------------------------------------------------------
169- PlusStatus vtkPlusOpenIGTLinkVideoSource::SetImageMessageEmbeddedTransformName (const char * nameString)
170+ PlusStatus vtkPlusOpenIGTLinkVideoSource::SetImageMessageEmbeddedTransformName ( const char * nameString )
170171{
171- return this ->ImageMessageEmbeddedTransformName .SetTransformName (nameString);
172+ return this ->ImageMessageEmbeddedTransformName .SetTransformName ( nameString );
172173}
0 commit comments