Hello again, @lassoan
I created a small IGTL server-client pair based on the examples of pyigtl.
Server side code:
import pyigtl
from time import sleep
import numpy as np
server = pyigtl.OpenIGTLinkServer(port=18944, local_server=False)
print(f"Starting server at: {server.host}:{server.port}")
timestep = 0
while True:
if not server.is_connected():
# Wait for client to connect
sleep(0.1)
continue
print("Server connected")
# Generate transform
timestep += 1
# Send transform
transform = np.random.rand(4, 4) @ np.eye(4)
print(f"time: {timestep} transform: ({transform.ravel()})")
transform_message = pyigtl.TransformMessage(transform, device_name="MyTransform")
server.send_message(transform_message, wait=True)
sleep(1)
# Since we wait until the message is actually sent, the message queue will not be flooded
And client-side code:
import pyigtl # pylint: disable=import-error
import socket
client = pyigtl.OpenIGTLinkClient(host=socket.gethostbyname(socket.gethostname()), port=18944)
# Get transform
input_message = client.wait_for_message("MyTransform", timeout=-1)
print(input_message)
My intention was to construct the communication like so, as we previously discussed:
After starting the server and client pair, each in a different Python process, on the client side, the execution gets halted in the line that defines
input_message. If I adjust the timeout to a value other than -1, the client receives the message once, and the execution finishes. In 3DSlicer, I want to update the transform every time I get the message, and I do not wish the module to hang in the line that defines input_message.In addition, I do not want to use 3DSlicer’s IGTLinkF module, I would like to manage the connection entirely from the code of my module. Can IGTLinkF’s logic be replicated using
pyigtl?
Thank you,
Marm
