Skip to content

Commit 1b62651

Browse files
author
Adam Rankin
committed
re #1010 Adding the ability to define image streams for OpenIGTLink video sources
1 parent 4fe967f commit 1b62651

6 files changed

Lines changed: 253 additions & 222 deletions

File tree

PlusLib/src/PlusCommon/PlusCommon.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class vtkPlusCommonExport PlusTransformName
331331
/*!
332332
Set 'From' and 'To' coordinate frame names from a combined transform name with the following format [FrameFrom]To[FrameTo].
333333
The combined transform name might contain only one 'To' phrase followed by a capital letter (e.g. ImageToToProbe is not allowed)
334-
and the coordiante frame names should be in camel case format starting with capitalized letters.
334+
and the coordinate frame names should be in camel case format starting with capitalized letters.
335335
*/
336336
PlusStatus SetTransformName( const char* aTransformName );
337337

@@ -351,25 +351,30 @@ class vtkPlusCommonExport PlusTransformName
351351
/*! Check if the current transform name is valid */
352352
bool IsValid() const;
353353

354-
bool operator== ( const PlusTransformName& in ) const
354+
inline bool operator== ( const PlusTransformName& in ) const
355355
{
356356
return ( in.m_From == m_From && in.m_To == m_To );
357357
}
358358

359+
inline bool operator!= (const PlusTransformName& in) const
360+
{
361+
return !(in == *this);
362+
}
363+
359364
friend std::ostream& operator<< ( std::ostream& os, const PlusTransformName& transformName )
360365
{
361366
os << transformName.GetTransformName();
362367
return os;
363368
}
364369

365370
private:
366-
367371
/*! Check if the input string is capitalized, if not capitalize it */
368372
void Capitalize( std::string& aString );
369373
std::string m_From; /*! From coordinate frame name */
370374
std::string m_To; /*! To coordinate frame name */
371375
};
372376

377+
373378
#define RETRY_UNTIL_TRUE(command_, numberOfRetryAttempts_, delayBetweenRetryAttemptsSec_) \
374379
{ \
375380
bool success = false; \

PlusLib/src/PlusDataCollection/OpenIGTLink/vtkPlusOpenIGTLinkDevice.cxx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ void vtkPlusOpenIGTLinkDevice::PrintSelf( ostream& os, vtkIndent indent )
5555
{
5656
os << indent << "Message type: " << this->MessageType << "\n";
5757
}
58-
58+
if ( this->ImageStream.IsValid() )
59+
{
60+
os << indent << "Image stream: " << this->ImageStream.GetTransformName() << "\n";
61+
}
5962
}
6063
//----------------------------------------------------------------------------
6164
std::string vtkPlusOpenIGTLinkDevice::GetSdkVersion()
@@ -155,11 +158,22 @@ PlusStatus vtkPlusOpenIGTLinkDevice::SendRequestedMessageTypes()
155158
{
156159
return PLUS_SUCCESS;
157160
}
161+
158162
// Send client info request to the server
159163
PlusIgtlClientInfo clientInfo;
164+
160165
// Set message type
161166
clientInfo.IgtlMessageTypes.push_back( this->MessageType );
162167

168+
// Set any requested image streams
169+
if ( this->ImageStream.IsValid() )
170+
{
171+
PlusIgtlClientInfo::ImageStream is;
172+
is.Name = this->ImageStream.From();
173+
is.EmbeddedTransformToFrame = this->ImageStream.To();
174+
clientInfo.ImageStreams.push_back( is );
175+
}
176+
163177
// We need the following tool names from the server
164178
for ( DataSourceContainerConstIterator it = this->GetToolIteratorBegin(); it != this->GetToolIteratorEnd(); ++it )
165179
{

PlusLib/src/PlusDataCollection/OpenIGTLink/vtkPlusOpenIGTLinkDevice.h

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@
1515
#include "igtlMessageBase.h"
1616

1717
/*!
18-
\class vtkPlusOpenIGTLinkDevice
18+
\class vtkPlusOpenIGTLinkDevice
1919
\brief Common base class for OpenIGTLink-based tracking and video devices
2020
2121
\ingroup PlusLibDataCollection
22-
*/
22+
*/
2323
class vtkPlusDataCollectionExport vtkPlusOpenIGTLinkDevice : public vtkPlusDevice
2424
{
2525
public:
26-
27-
//static vtkPlusOpenIGTLinkDevice *New();
28-
vtkTypeMacro(vtkPlusOpenIGTLinkDevice,vtkPlusDevice);
29-
virtual void PrintSelf(ostream& os, vtkIndent indent);
26+
vtkTypeMacro( vtkPlusOpenIGTLinkDevice, vtkPlusDevice );
27+
virtual void PrintSelf( ostream& os, vtkIndent indent );
3028

3129
/*! OpenIGTLink version. */
32-
virtual std::string GetSdkVersion();
30+
virtual std::string GetSdkVersion();
3331

3432
/*! Connect to device */
3533
virtual PlusStatus InternalConnect();
@@ -41,38 +39,44 @@ class vtkPlusDataCollectionExport vtkPlusOpenIGTLinkDevice : public vtkPlusDevic
4139
virtual PlusStatus Probe();
4240

4341
/*! Read configuration from xml data */
44-
virtual PlusStatus ReadConfiguration( vtkXMLDataElement* config );
45-
42+
virtual PlusStatus ReadConfiguration( vtkXMLDataElement* config );
43+
4644
/*! Write configuration to xml data */
47-
virtual PlusStatus WriteConfiguration(vtkXMLDataElement* config);
45+
virtual PlusStatus WriteConfiguration( vtkXMLDataElement* config );
46+
47+
/*! Set OpenIGTLink message type */
48+
vtkSetStringMacro( MessageType );
49+
/*! Get OpenIGTLink message type */
50+
vtkGetStringMacro( MessageType );
4851

49-
/*! Set OpenIGTLink message type */
50-
vtkSetStringMacro(MessageType);
51-
/*! Get OpenIGTLink message type */
52-
vtkGetStringMacro(MessageType);
52+
/*! Set image streams to be sent when message type is a type that sends an image */
53+
vtkSetMacro( ImageStream, PlusTransformName );
5354

54-
/*! Set OpenIGTLink server address */
55-
vtkSetStringMacro(ServerAddress);
56-
/*! Get OpenIGTLink server address */
57-
vtkGetStringMacro(ServerAddress);
55+
/*! Get image streams to be sent when message type is a type that sends an image */
56+
vtkGetMacro( ImageStream, PlusTransformName );
5857

59-
/*! Set OpenIGTLink server port */
60-
vtkSetMacro(ServerPort, int);
61-
/*! Get OpenIGTLink server port */
62-
vtkGetMacro(ServerPort, int);
58+
/*! Set OpenIGTLink server address */
59+
vtkSetStringMacro( ServerAddress );
60+
/*! Get OpenIGTLink server address */
61+
vtkGetStringMacro( ServerAddress );
62+
63+
/*! Set OpenIGTLink server port */
64+
vtkSetMacro( ServerPort, int );
65+
/*! Get OpenIGTLink server port */
66+
vtkGetMacro( ServerPort, int );
6367

6468
/*! Set OpenIGTLink socket timeout */
65-
vtkSetMacro(ReceiveTimeoutSec, double);
69+
vtkSetMacro( ReceiveTimeoutSec, double );
6670
/*! Get OpenIGTLink socket timeout */
67-
vtkGetMacro(ReceiveTimeoutSec, double);
71+
vtkGetMacro( ReceiveTimeoutSec, double );
6872

69-
/*! Set IGTL CRC check flag (0: disabled, 1: enabled) */
70-
vtkSetMacro(IgtlMessageCrcCheckEnabled, int);
71-
/*! Get IGTL CRC check flag (0: disabled, 1: enabled) */
72-
vtkGetMacro(IgtlMessageCrcCheckEnabled, int);
73+
/*! Set IGTL CRC check flag (0: disabled, 1: enabled) */
74+
vtkSetMacro( IgtlMessageCrcCheckEnabled, int );
75+
/*! Get IGTL CRC check flag (0: disabled, 1: enabled) */
76+
vtkGetMacro( IgtlMessageCrcCheckEnabled, int );
7377

7478
/*! Get the ReconnectOnNoData flag */
75-
vtkGetMacro(ReconnectOnReceiveTimeout, bool);
79+
vtkGetMacro( ReconnectOnReceiveTimeout, bool );
7680

7781
protected:
7882
vtkPlusOpenIGTLinkDevice();
@@ -81,53 +85,56 @@ class vtkPlusDataCollectionExport vtkPlusOpenIGTLinkDevice : public vtkPlusDevic
8185
/*! Reconnect the client socket. Used when the connection is established or there is a socket error. */
8286
virtual PlusStatus ClientSocketReconnect();
8387

84-
/*! Sends the requested mesage types when connection is established */
88+
/*! Sends the requested message types when connection is established */
8589
virtual PlusStatus SendRequestedMessageTypes();
86-
90+
8791
/*!
8892
This method is called when receiving a message is timed out.
8993
If ReconnectOnReceiveTimeout is enabled then this method attempts to reconnect to the server.
9094
*/
9195
void OnReceiveTimeout();
92-
96+
9397
/*!
9498
Calls ReceiveMessageHeader and logs the error and/or reconnect as needed.
9599
*/
96-
void ReceiveMessageHeaderWithErrorHandling(igtl::MessageHeader::Pointer &headerMsg);
97-
100+
void ReceiveMessageHeaderWithErrorHandling( igtl::MessageHeader::Pointer& headerMsg );
101+
98102
/*!
99103
Receive an OpenITGLink message header.
100104
Returns PLUS_FAIL if there was a socket error.
101105
The headerMsg is NULL is no data is received.
102106
*/
103-
virtual PlusStatus ReceiveMessageHeader(igtl::MessageHeader::Pointer &headerMsg);
107+
virtual PlusStatus ReceiveMessageHeader( igtl::MessageHeader::Pointer& headerMsg );
104108

105109
/*! Set the ReconnectOnNoData flag */
106-
vtkSetMacro(ReconnectOnReceiveTimeout, bool);
110+
vtkSetMacro( ReconnectOnReceiveTimeout, bool );
107111

108-
vtkSetMacro(UseReceivedTimestamps, bool);
112+
vtkSetMacro( UseReceivedTimestamps, bool );
109113

110114
/*! OpenIGTLink message type */
111-
char* MessageType;
115+
char* MessageType;
116+
117+
/*! Image stream to send when message type wants to send an image */
118+
PlusTransformName ImageStream;
112119

113-
/*! OpenIGTLink server address */
114-
char* ServerAddress;
120+
/*! OpenIGTLink server address */
121+
char* ServerAddress;
115122

116-
/*! OpenIGTLink server port */
117-
int ServerPort;
123+
/*! OpenIGTLink server port */
124+
int ServerPort;
118125

119126
double ReceiveTimeoutSec;
120127

121-
/*! Flag for IGTL CRC check (0: disabled, 1: enabled) */
122-
int IgtlMessageCrcCheckEnabled;
128+
/*! Flag for IGTL CRC check (0: disabled, 1: enabled) */
129+
int IgtlMessageCrcCheckEnabled;
123130

124-
/*! Number of retry attempts for message sending to and receiving from the server */
125-
int NumberOfRetryAttempts;
131+
/*! Number of retry attempts for message sending to and receiving from the server */
132+
int NumberOfRetryAttempts;
126133

127-
/*! Delay between retry attempts */
128-
double DelayBetweenRetryAttemptsSec;
134+
/*! Delay between retry attempts */
135+
double DelayBetweenRetryAttemptsSec;
129136

130-
/*! OpenIGTLink client socket */
137+
/*! OpenIGTLink client socket */
131138
igtl::ClientSocket::Pointer ClientSocket;
132139

133140
/*! Attempt a reconnection if no data is received */
@@ -138,11 +145,10 @@ class vtkPlusDataCollectionExport vtkPlusOpenIGTLinkDevice : public vtkPlusDevic
138145
If it is false then the time of reception is used as timestamp.
139146
*/
140147
bool UseReceivedTimestamps;
141-
142-
private:
143148

144-
vtkPlusOpenIGTLinkDevice(const vtkPlusOpenIGTLinkDevice&); // Not implemented.
145-
void operator=(const vtkPlusOpenIGTLinkDevice&); // Not implemented.
149+
private:
150+
vtkPlusOpenIGTLinkDevice( const vtkPlusOpenIGTLinkDevice& ); // Not implemented.
151+
void operator=( const vtkPlusOpenIGTLinkDevice& ); // Not implemented.
146152
};
147153

148154
#endif

PlusLib/src/PlusDataCollection/OpenIGTLink/vtkPlusOpenIGTLinkTracker.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
#include "vtkPlusIgtlMessageFactory.h"
1414

1515
/*!
16-
\class vtkPlusOpenIGTLinkTracker
17-
\brief OpenIGTLink tracker client
16+
\class vtkPlusOpenIGTLinkTracker
17+
\brief OpenIGTLink tracker client
1818
1919
\ingroup PlusLibDataCollection
2020
*/
2121
class vtkPlusDataCollectionExport vtkPlusOpenIGTLinkTracker : public vtkPlusOpenIGTLinkDevice
2222
{
2323
public:
24-
25-
static vtkPlusOpenIGTLinkTracker *New();
26-
vtkTypeMacro( vtkPlusOpenIGTLinkTracker,vtkPlusOpenIGTLinkDevice );
24+
static vtkPlusOpenIGTLinkTracker* New();
25+
vtkTypeMacro( vtkPlusOpenIGTLinkTracker, vtkPlusOpenIGTLinkDevice );
2726
virtual void PrintSelf( ostream& os, vtkIndent indent );
2827

2928
/*! Disconnect from device */
@@ -33,20 +32,23 @@ class vtkPlusDataCollectionExport vtkPlusOpenIGTLinkTracker : public vtkPlusOpen
3332
PlusStatus InternalUpdate();
3433

3534
/*! Read configuration from xml data */
36-
virtual PlusStatus ReadConfiguration( vtkXMLDataElement* config );
37-
35+
virtual PlusStatus ReadConfiguration( vtkXMLDataElement* config );
36+
3837
/*! Write configuration to xml data */
39-
virtual PlusStatus WriteConfiguration(vtkXMLDataElement* config);
38+
virtual PlusStatus WriteConfiguration( vtkXMLDataElement* config );
4039

41-
virtual bool IsTracker() const { return true; }
40+
virtual bool IsTracker() const
41+
{
42+
return true;
43+
}
4244

43-
/*!
45+
/*!
4446
Set the internal tracker coordinate system name that is send to the tracker
4547
when tracking start is requested using an STT_TDATA message.
46-
*/
47-
vtkSetStringMacro(TrackerInternalCoordinateSystemName);
48-
/*! Get the internal tracker coordinate system name */
49-
vtkGetStringMacro(TrackerInternalCoordinateSystemName);
48+
*/
49+
vtkSetStringMacro( TrackerInternalCoordinateSystemName );
50+
/*! Get the internal tracker coordinate system name */
51+
vtkGetStringMacro( TrackerInternalCoordinateSystemName );
5052

5153
protected:
5254
vtkPlusOpenIGTLinkTracker();
@@ -60,7 +62,7 @@ class vtkPlusDataCollectionExport vtkPlusOpenIGTLinkTracker : public vtkPlusOpen
6062
PlusStatus InternalUpdateGeneral();
6163

6264
/*! Process a single TRANSFORM or POSITION message */
63-
PlusStatus ProcessTransformMessageGeneral(bool &moreMessagesPossible);
65+
PlusStatus ProcessTransformMessageGeneral( bool& moreMessagesPossible );
6466

6567
/*! Process a TDATA message (add all the received transforms to the buffers) */
6668
PlusStatus InternalUpdateTData();
@@ -70,16 +72,16 @@ class vtkPlusDataCollectionExport vtkPlusOpenIGTLinkTracker : public vtkPlusOpen
7072
If no transforms are defined then identity transform will be stored.
7173
If there is a transform defined already with the same timestamp then it will not be overwritten.
7274
*/
73-
PlusStatus StoreMostRecentTransformValues(double unfilteredTimestamp);
75+
PlusStatus StoreMostRecentTransformValues( double unfilteredTimestamp );
7476

7577
/*!
7678
Store the latest transforms again in the buffers with the provided timestamp with invalid status.
7779
If no transforms are defined then identity transform will be stored.
7880
If there is a transform defined already with the same timestamp then it will not be overwritten.
7981
*/
80-
PlusStatus StoreInvalidTransforms(double unfilteredTimestamp);
82+
PlusStatus StoreInvalidTransforms( double unfilteredTimestamp );
8183

82-
vtkSetMacro(UseLastTransformsOnReceiveTimeout, bool);
84+
vtkSetMacro( UseLastTransformsOnReceiveTimeout, bool );
8385

8486
/*!
8587
Internal tracker coordinate system name that is send to the tracker when tracking start is requested
@@ -93,10 +95,9 @@ class vtkPlusDataCollectionExport vtkPlusOpenIGTLinkTracker : public vtkPlusOpen
9395
/*! igtl Factory for message handling */
9496
vtkSmartPointer<vtkPlusIgtlMessageFactory> IgtlMessageFactory;
9597

96-
private:
97-
98+
private:
9899
vtkPlusOpenIGTLinkTracker( const vtkPlusOpenIGTLinkTracker& );
99-
void operator=( const vtkPlusOpenIGTLinkTracker& );
100+
void operator=( const vtkPlusOpenIGTLinkTracker& );
100101
};
101102

102103
#endif

0 commit comments

Comments
 (0)