network_gui.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #
  2. # Copyright (C) 2023, Inria
  3. # GRAPHDECO research group, https://team.inria.fr/graphdeco
  4. # All rights reserved.
  5. #
  6. # This software is free for non-commercial, research and evaluation use
  7. # under the terms of the LICENSE.md file.
  8. #
  9. # For inquiries contact george.drettakis@inria.fr
  10. #
  11. import torch
  12. import traceback
  13. import socket
  14. import json
  15. from scene.cameras import MiniCam
  16. host = "127.0.0.1"
  17. port = 6009
  18. conn = None
  19. addr = None
  20. listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  21. def init(wish_host, wish_port):
  22. global host, port, listener
  23. host = wish_host
  24. port = wish_port
  25. listener.bind((host, port))
  26. listener.listen()
  27. listener.settimeout(0)
  28. def try_connect():
  29. global conn, addr, listener
  30. try:
  31. conn, addr = listener.accept()
  32. print(f"\nConnected by {addr}")
  33. conn.settimeout(None)
  34. except Exception as inst:
  35. pass
  36. def read():
  37. global conn
  38. messageLength = conn.recv(4)
  39. messageLength = int.from_bytes(messageLength, 'little')
  40. message = conn.recv(messageLength)
  41. return json.loads(message.decode("utf-8"))
  42. def send(message_bytes, verify):
  43. global conn
  44. if message_bytes != None:
  45. conn.sendall(message_bytes)
  46. conn.sendall(len(verify).to_bytes(4, 'little'))
  47. conn.sendall(bytes(verify, 'ascii'))
  48. def receive():
  49. message = read()
  50. width = message["resolution_x"]
  51. height = message["resolution_y"]
  52. if width != 0 and height != 0:
  53. try:
  54. do_training = bool(message["train"])
  55. fovy = message["fov_y"]
  56. fovx = message["fov_x"]
  57. znear = message["z_near"]
  58. zfar = message["z_far"]
  59. do_shs_python = bool(message["shs_python"])
  60. do_rot_scale_python = bool(message["rot_scale_python"])
  61. keep_alive = bool(message["keep_alive"])
  62. scaling_modifier = message["scaling_modifier"]
  63. world_view_transform = torch.reshape(torch.tensor(message["view_matrix"]), (4, 4)).cuda()
  64. world_view_transform[:,1] = -world_view_transform[:,1]
  65. world_view_transform[:,2] = -world_view_transform[:,2]
  66. full_proj_transform = torch.reshape(torch.tensor(message["view_projection_matrix"]), (4, 4)).cuda()
  67. full_proj_transform[:,1] = -full_proj_transform[:,1]
  68. custom_cam = MiniCam(width, height, fovy, fovx, znear, zfar, world_view_transform, full_proj_transform)
  69. except Exception as e:
  70. print("")
  71. traceback.print_exc()
  72. raise e
  73. return custom_cam, do_training, do_shs_python, do_rot_scale_python, keep_alive, scaling_modifier
  74. else:
  75. return None, None, None, None, None, None