<jupyter_start><jupyter_text>------------------------- Author: <NAME> Date: 2019 August 14-------------------------  Import<jupyter_code>from RayCollisionSocket import RayCollisionSocket

import cv2
import numpy as np
import sys<jupyter_output><empty_output><jupyter_text>Built-in methods test<jupyter_code>socket = RayCollisionSocket()

# kind of array to send
vec2 = np.asarray([
    (0.5,0.5),
    (0,0)
])
print("message built :", socket.ToBytes(vec2), "\n")

# kind of received message
vec3 = b"0.5,0.5,0.5;0,0,0;"
print("message converted :", socket.ToArray(vec3))<jupyter_output><empty_output><jupyter_text>Server Define host/port<jupyter_code>_host = "192.168.137.1"
_port = 9999<jupyter_output><empty_output><jupyter_text>Define coordinates to send<jupyter_code>_coords = np.asarray([(0.5,0.5)]) # center<jupyter_output><empty_output><jupyter_text>Start server and wait connection<jupyter_code>socket = RayCollisionSocket().Bind(_host, _port)
connected = socket.WaitConnection()<jupyter_output><empty_output><jupyter_text>Exit if connection failed<jupyter_code>if not connected:
    sys.exit(0)

print("Connected to {}".format(socket.client))<jupyter_output><empty_output><jupyter_text>Loops Manual<jupyter_code>while True:
        
    print("1 => Ask position")
    print("2 => Close connection and quit")
    choice = input()

    if choice == "1":
        positions = socket.AskPositions(_coords)
        if len(positions) > 0: # control that coordinates are valid
            print("received :", positions)

    elif choice == "2": break

socket.Exit()
socket.close()<jupyter_output><empty_output><jupyter_text>Graphical<jupyter_code>while True:

    frame = np.zeros((200, 800)).astype(float)
    
    # ray collision test
    positions = socket.AskPositions(_coords)
    
    # display
    if len(positions) > 0:
        vec = positions[0].astype(str)
        text = "x={} y={} z={}".format(vec[0],vec[1],vec[2])
        cv2.putText(frame, text, (0,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 1, cv2.LINE_AA)
        
    cv2.imshow("frame", frame)
    if cv2.waitKey(1) == ord('q'): break


socket.Exit()
socket.close()

cv2.destroyAllWindows()
socket.Exit()
socket.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1649438202247191, 'fraction_numerical': 0.036853932584269666, 'mean_word_length': 4.363855421686747, 'pattern_counts': {'":': 2, '<': 34, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '388758', 'license': 'Apache-2.0', 'n_tokens_mistral': 837, 'n_tokens_neox': 791, 'n_words': 142, 'path': 'PC/Socket/RayCollisionSocket.ipynb', 'repo_name': 'limvi-licef/NATAssistanceAR', 'size': '2232'}