28 #include "WIGTLinkRemote.h"
29 #include "WMOpenIGTLink.h"
30 #include "core/dataHandler/WDataSetScalar.h"
31 #include "core/kernel/WKernel.h"
32 #include "core/kernel/WSelectionManager.h"
34 #define PORT_SLICER_DEFAULT 18944
39 WMOpenIGTLinkSender::WMOpenIGTLinkSender():
44 WMOpenIGTLinkSender::~WMOpenIGTLinkSender()
62 return "OpenIGTLinkSender";
67 return "OpenIGT Link";
82 "Set to true to start the connection or to start the server."
83 "To avoid random connections, an update of the remote IP address"
84 " and the remote or local port is only performed whenever the active flag changes.",
95 m_propCheckCRC =
m_properties->addProperty(
"Check CRC",
"Enable to perform CRC on incoming packets. Disable to ignore the checksum",
98 m_hostname =
m_properties->addProperty(
"Hostname",
"Remote host name to connect to. Enter a host name or an IP address.",
100 m_port =
m_properties->addProperty(
"Port",
"Local port to open or remote port to connect to. The default Slicer3D port is 18944.",
127 debugLog() <<
"Module is now ready.";
129 std::shared_ptr < WIGTLinkRemote > remote;
136 debugLog() <<
"listen on local port";
138 remote->createSocketAndWaitForConnection(
m_port->get() );
143 debugLog() <<
"connect to remote host";
149 catch(
const std::exception& e )
151 infoLog() <<
"Connection failed";
160 debugLog() <<
"no active connection";
192 debugLog() <<
"Shutting down the server.";
193 remote->wait(
true );
197 debugLog() <<
"waiting one second.";
209 debugLog() <<
"listen on local port";
211 remote->createSocketAndWaitForConnection(
m_port->get() );
216 debugLog() <<
"connect to remote host";
222 catch(
const std::exception& e )
224 infoLog() <<
"Connection failed";
234 debugLog() <<
"no active connection";
254 debugLog() <<
"checking receive queue:";
255 remote->receiversMutex.lock();
256 if( !remote->receiveQueue.empty() )
258 debugLog() <<
"something in queue for us";
259 WDataSetScalarSPtr ds = remote->receiveQueue.front();
260 remote->receiveQueue.pop();
268 debugLog() <<
"received empty data set";
275 remote->receiversMutex.unlock();
278 if( remote &&
m_input->updated() )
280 debugLog() <<
"prepare sending new data";
281 WDataSetScalarSPtr dataSet =
m_input->getData();
282 bool dataValid = ( dataSet != NULL );
287 remote->sendImageData( dataSet );
292 if( (
m_xPos->changed(
true ) ||
m_yPos->changed(
true ) ||
m_zPos->changed(
true ) ) && remote )
295 a( 0, 0 ) = 1.0; a( 0, 1 ) = 0.0; a( 0, 2 ) = 0.0; a( 0, 3 ) =
m_xPos->get();
296 a( 1, 0 ) = 0.0; a( 1, 1 ) = 1.0; a( 1, 2 ) = 0.0; a( 1, 3 ) =
m_yPos->get();
297 a( 2, 0 ) = 0.0; a( 2, 1 ) = 0.0; a( 2, 2 ) = 1.0; a( 2, 3 ) =
m_zPos->get();
298 a( 3, 0 ) = 0.0; a( 3, 1 ) = 0.0; a( 3, 2 ) = 0.0; a( 3, 3 ) = 1.0;
300 remote->sendTransform(
"Coordinage System", a );
307 debugLog() <<
"about to shut down: waiting for connection to close.";
308 remote->wait(
true );
309 debugLog() <<
"about to shut down: connection closed";
312 debugLog() <<
"module shutting down.";
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void remove(std::shared_ptr< WCondition > condition)
Removes the specified condition.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
Common base class for a IGT Link connection.
A class containing a list of named items.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
This module provides an interface to OpenIGTLink, a protocol to exchange data remotely over IP networ...
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input
input for data to send
WPropDouble m_xPos
x position of the slice
std::shared_ptr< WItemSelection > m_propServerOrClientSelections
whether we connect to the remote host or just listen
virtual void requirements()
Initialize requirements for this module.
virtual void moduleMain()
Entry point after loading the module.
WPropString m_hostname
hostname to connect to
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
WPropInt m_port
port to listen on or to connect to
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void connectors()
Initialize the connectors this module is using.
WPropDouble m_yPos
y position of the slice
WPropBool m_propCheckCRC
Check CRC.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropSelection m_propServerOrClient
Pick whether to act as an TCPIP server or as an TCPIP client, i.e., whether to listen on a port for i...
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropDouble m_zPos
z position of the slice
WPropBool m_propActive
Activation status of the server.
virtual const std::string getName() const
Gives back the name of this module.
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
output of received data
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
virtual void connectors()
Initialize connectors in this function.
void sleep(const int32_t t) const
Sets thread asleep.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.