1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
25
#ifndef WIGTLINKREMOTE_H
26
#define WIGTLINKREMOTE_H
32
#include "core/common/WCondition.h"
34
#include "core/common/WThreadedRunner.h"
36
#include "core/common/math/WMatrix.h"
38
#include "igtlMessageHeader.h"
39
#include "igtlImageMessage.h"
40
#include "igtlClientSocket.h"
41
#include "core/dataHandler/WDataSetScalar.h"
47
// there is no WDataSetScalar::SPtr definition, yet
48
// so I use this workaround here for better readability
49
typedef boost::shared_ptr<WDataSetScalar> WDataSetScalarSPtr;
52
* Common base class for a IGT Link connection.
53
* Provides some helper functions to handle and convert OW data.
55
class WIGTLinkRemote : public WThreadedRunner
60
virtual ~WIGTLinkRemote();
63
* Use this as a server that waits for client connections.
65
* \param port Port number for the connection
67
void createSocketAndWaitForConnection( uint32_t port );
70
* Use this as a client that connects to a remote server
72
* \param server Name of the remote server.
73
* \param port Port number for the connection.
75
void createSocketAndConnect( std::string server, uint32_t port );
78
* main loop for reading
85
* \param headerMsg The message conatining the transform.
87
void receiveTransform( igtl::MessageHeader::Pointer headerMsg );
92
* \param headerMsg The image in this message is used to create a dataset
93
* \return Dataset created from message.
95
WDataSetScalarSPtr receiveImage( igtl::MessageHeader::Pointer headerMsg );
98
* TODO: inject a message in the send queue
100
void injectMessage();
103
* Send metadata of a list of data sets
105
* \param dataSets A vector containing pointer to the datasets whose metadata we want to send.
107
void sendImageMetaData( const std::vector<WDataSetScalarSPtr>& dataSets );
110
* Send image data of a single data set
112
* \param dataSetScalar Pointer to the dataset we want to send
114
void sendImageData( WDataSetScalarSPtr dataSetScalar );
117
* send a matrix as an igtl transform
118
* \param name: the name to use for the transform
119
* \param matrix: the matrix that will be send
120
* \pre: socket is valid. If not, nothing will be sent and no error will be reported.
122
void sendTransform( const std::string& name, const WMatrix <double> & matrix );
125
* Internal helper to create a value set from a message
127
* \param imgMsg The image behind this pointer is used to create the dataset
128
* \return Created value set.
130
boost::shared_ptr < WValueSetBase > createValueSet( const igtl::ImageMessage::Pointer& imgMsg );
133
* Set whether we check the CRC. Otherwise, we just ignore it while unpacking the data.
134
* The default for checkCRC is false, so there is no CRC checking when this function
135
* has not been called.
137
* \param doCheckCRC Should CRC of the data be checked?
139
void setCheckCRC( bool doCheckCRC = true )
141
checkCRC = doCheckCRC;
145
* setup listening socket and listen
150
* Send a message containing the metadata of the data sets
152
* \param dataSets A vector containing pointers to the datasets whose metadata we want to send.
154
void sendImageMetaData( std::vector < WDataSetScalarSPtr > dataSets );
157
* mutex has to be locked during access to receiveQueue
159
boost::mutex receiversMutex;
162
* condition to notify receivers that new data is waiting
164
boost::shared_ptr < WCondition > receiversCondition;
167
* condition to notify a status change
169
boost::shared_ptr < WCondition > statusCondition;
172
* queue of received data sets that should be read by the module
174
std::queue < WDataSetScalarSPtr > receiveQueue;
178
* the main thread doing passive connections or receiving data
180
virtual void threadMain();
182
/** true if we check CRC sums in incoming packets */
185
/** the port for listening connections */
189
* Points to the socket used by this connection.
191
igtl::ClientSocket::Pointer socket;
194
#endif // WIGTLINKREMOTE_H