Skip to content

Commit

Permalink
feat: adding the ability to click on 2D slices and callback the posit…
Browse files Browse the repository at this point in the history
…ion to Python
  • Loading branch information
dbirman committed Nov 25, 2023
1 parent 24e5c3e commit 76fa562
Show file tree
Hide file tree
Showing 13 changed files with 507 additions and 30 deletions.
2 changes: 1 addition & 1 deletion API/oursin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def receive_camera_img(data):

@sio.on('VolumeClick')
def receive_volume_click(data):
volumes.volume_click(data)
volumes._volume_click(data)

# Helper functions
def connected():
Expand Down
45 changes: 43 additions & 2 deletions API/oursin/volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,54 @@
import numpy as np
import zlib
import json
import csv
import ast

counter = 0

CHUNK_LIMIT = 1000000

def volume_click(data):
print(data)
click_list = []
verbose = False

def _volume_click(data):
"""Internal callback function
"""
click_pos = json.loads(data)
if verbose:
print(click_pos)

click_list.append(click_pos)

def clear_clicks():
"""Clear the volumes click list
"""
global click_list
click_list = []

def save_clicks(fpath):
"""Save the current click list to a CSV file.
Use `urchin.volumes.clear_clicks()` before starting your click sequence.
Parameters
----------
fpath : string
Relative filepath
"""
global click_list
# Extract headers and data
headers = ['ap', 'ml', 'dv']
data = [[entry[header] for header in headers] for entry in click_list]

with open(fpath, mode='w', newline='') as file:
writer = csv.writer(file)

# Write headers
writer.writerow(headers)

# Write data
writer.writerows(data)

class Volume:
"""Volumetric dataset represented in a compressed format by using a colormap to translate
Expand Down
4 changes: 3 additions & 1 deletion Server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ ID2Socket = {}; // keeps track of all sockets with the same ID
Socket2ID = {}; // keeps track of the ID of each socket
Socket2Type = {};

reserved_messages = ['connection','disconnect','ID','CameraImgMeta','CameraImg','log','log-warning','log-error']
reserved_messages = ['connection','disconnect','ID','CameraImgMeta','CameraImg',
'log','log-warning','log-error',
'VolumeClick']

io.on("connection", function (socket) {
console.log("Client connected with ID: " + socket.id);
Expand Down
12 changes: 12 additions & 0 deletions UnityClient/Assets/Scenes/UnityMouseRenderer.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,10 @@ PrefabInstance:
propertyPath: ShapeModule.radiusThickness
value: 1
objectReference: {fileID: 0}
- target: {fileID: 756099984625368948, guid: a0c57925ee59dae4ebf1f78ba70837a6, type: 3}
propertyPath: _uiCanvas
value:
objectReference: {fileID: 858013925}
- target: {fileID: 756099984625368948, guid: a0c57925ee59dae4ebf1f78ba70837a6, type: 3}
propertyPath: _cameraUIGOs.Array.size
value: 4
Expand Down Expand Up @@ -10621,6 +10625,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: -256
objectReference: {fileID: 0}
- target: {fileID: 1179077492766071444, guid: 797f30df999d646458e9984856b9b1f7, type: 3}
propertyPath: m_Value
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1179077492766071444, guid: 797f30df999d646458e9984856b9b1f7, type: 3}
propertyPath: m_OnValueChanged.m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
Expand Down Expand Up @@ -11077,6 +11085,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8745640924072365970, guid: 797f30df999d646458e9984856b9b1f7, type: 3}
propertyPath: m_Value
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8745640924072365970, guid: 797f30df999d646458e9984856b9b1f7, type: 3}
propertyPath: m_OnValueChanged.m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Material:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _LeftAxis: {r: 0, g: 1, b: 0, a: 0}
- _LeftAxis: {r: 0, g: -1, b: 0, a: 0}
- _SliceAxis: {r: 1, g: 0, b: 0, a: 0}
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
- _UpAxis: {r: 0, g: 0, b: -1, a: 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Material:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _LeftAxis: {r: -1, g: 0, b: 0, a: 0}
- _LeftAxis: {r: 1, g: 0, b: 0, a: 0}
- _SliceAxis: {r: 0, g: 1, b: 0, a: 0}
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
- _UpAxis: {r: 0, g: 0, b: -1, a: 0}
Expand Down
Loading

0 comments on commit 76fa562

Please sign in to comment.