Skip to content

Commit

Permalink
feat: changing Atlas.set_visibilities to use AtlasGroupData
Browse files Browse the repository at this point in the history
Temporary change, the whole class should be re-built to use this class
  • Loading branch information
dbirman committed Mar 14, 2024
1 parent 75a6eef commit 5e97ebf
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 66 deletions.
17 changes: 8 additions & 9 deletions API/oursin/atlas/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

import json
import vbl_aquarium

class CustomAtlas:
def __init__(self, atlas_name, atlas_dimensions, atlas_resolution):
Expand Down Expand Up @@ -113,16 +114,14 @@ def set_visibilities(self, area_list, area_visibility, side = utils.Side.FULL):

# output dictionary should match JSON schema AreaData:
#{"acronym": ["a", "b", "c"], "side": [-1, 0, 1], "visible": [true, true, false]}
data_dict = {}
data_dict['acronym'] = []
data_dict['side'] = []
data_dict['visible'] = []
for i, area in enumerate(area_list):
data_dict['acronym'].append(area.acronym)
data_dict['visible'].append(area_visibility[i])
data_dict['side'].append(side.value)

client.sio.emit('SetAreaVisibility', json.dumps(data_dict))
data = vbl_aquarium.urchin.AreaGroupData(
acronyms = [area.acronym for area in area_list],
visible = area_visibility,
side = [side.value] * len(area_list),
)

client.sio.emit('SetAreaVisibility', data.model_dump_json())

def set_colors(self, area_list, area_colors, sided="full"):
"""Set color of multiple areas at once.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void Start()
public static Action<string> AtlasLoad;
//public static Action<CustomAtlasData> AtlasCreateCustom;
//public static Action<Vector3Data> AtlasSetReferenceCoord;
//public static Action<AreaData> AtlasSetAreaVisibility;
public static Action<AreaGroupData> AtlasSetAreaVisibility;
public static Action<Dictionary<string, string>> AtlasSetAreaColors;
public static Action<Dictionary<string, float>> AtlasSetAreaIntensities;
public static Action<string> AtlasSetColormap;
Expand All @@ -97,7 +97,7 @@ private void Start_Atlas()
manager.Socket.On<string>("LoadAtlas", x => AtlasLoad.Invoke(x));
//manager.Socket.On<string>("CustomAtlas", x => AtlasCreateCustom.Invoke(JsonUtility.FromJson<CustomAtlasData>(x)));
//manager.Socket.On<string>("AtlasSetReferenceCoord", x => AtlasSetReferenceCoord.Invoke(JsonUtility.FromJson<Vector3Data>(x)));
//manager.Socket.On<string>("SetAreaVisibility", x => AtlasSetAreaVisibility.Invoke(JsonUtility.FromJson<AreaData>(x)));
manager.Socket.On<string>("SetAreaVisibility", x => AtlasSetAreaVisibility.Invoke(JsonUtility.FromJson<AreaGroupData>(x)));
manager.Socket.On<Dictionary<string, string>>("SetAreaColors", x => AtlasSetAreaColors.Invoke(x));
manager.Socket.On<Dictionary<string, float>>("SetAreaIntensity", x => AtlasSetAreaIntensities.Invoke(x));
manager.Socket.On<string>("SetAreaColormap", x => AtlasSetColormap.Invoke(x));
Expand Down
106 changes: 53 additions & 53 deletions UnityClient/Packages/vbl.urchin/Scripts/Managers/AtlasManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void Start()
Client_SocketIO.AtlasLoad += LoadAtlas;
//Client_SocketIO.AtlasCreateCustom += CustomAtlas;

//Client_SocketIO.AtlasSetAreaVisibility += SetAreaVisibility;
Client_SocketIO.AtlasSetAreaVisibility += SetAreaVisibility;
Client_SocketIO.AtlasSetAreaColors += SetAreaColors;
Client_SocketIO.AtlasSetAreaIntensities += SetAreaIntensity;
Client_SocketIO.AtlasSetColormap += SetAreaColormap;
Expand Down Expand Up @@ -104,58 +104,58 @@ public async void LoadAtlas(string atlasName)
// BrainAtlasManager.CustomAtlas(data.name, dims, res);
//}

// public void SetAreaVisibility(AreaData data)
// {
// for (int i = 0; i < data.acronym.Length; i++)
// {
// int areaID = BrainAtlasManager.ActiveReferenceAtlas.Ontology.Acronym2ID(data.acronym[i]);

// OntologyNode node = BrainAtlasManager.ActiveReferenceAtlas.Ontology.ID2Node(areaID);
// OntologyNode.OntologyNodeSide side = (OntologyNode.OntologyNodeSide)data.side[i];

// if (node == null)
// return;

// bool set = false;

// bool full = side == OntologyNode.OntologyNodeSide.Full;
// bool leftSide = side == OntologyNode.OntologyNodeSide.Left;
// bool rightSide = side == OntologyNode.OntologyNodeSide.Right;

// if (full && node.FullLoaded.IsCompleted)
// {
// node.SetVisibility(data.visible[i], OntologyNode.OntologyNodeSide.Full);
// VisibleNodes.Add(node);
// set = true;
//#if UNITY_EDITOR
// Debug.Log("Setting full model visibility to true");
//#endif
// }
// if (leftSide && node.SideLoaded.IsCompleted)
// {
// node.SetVisibility(data.visible[i], OntologyNode.OntologyNodeSide.Left);
// VisibleNodes.Add(node);
// set = true;
//#if UNITY_EDITOR
// Debug.Log("Setting left model visibility to true");
//#endif
// }
// if (rightSide && node.SideLoaded.IsCompleted)
// {
// node.SetVisibility(data.visible[i], OntologyNode.OntologyNodeSide.Right);
// VisibleNodes.Add(node);
// set = true;
//#if UNITY_EDITOR
// Debug.Log("Setting right model visibility to true");
//#endif
// }

// if (set)
// NodeVisibleEvent.Invoke(node);
// else
// LoadIndividualArea(node, full, leftSide, rightSide, data.visible[i]);
// }
// }
public void SetAreaVisibility(AreaGroupData data)
{
for (int i = 0; i < data.acronyms.Length; i++)
{
int areaID = BrainAtlasManager.ActiveReferenceAtlas.Ontology.Acronym2ID(data.acronyms[i]);

OntologyNode node = BrainAtlasManager.ActiveReferenceAtlas.Ontology.ID2Node(areaID);
OntologyNode.OntologyNodeSide side = (OntologyNode.OntologyNodeSide)data.side[i];

if (node == null)
return;

bool set = false;

bool full = side == OntologyNode.OntologyNodeSide.Full;
bool leftSide = side == OntologyNode.OntologyNodeSide.Left;
bool rightSide = side == OntologyNode.OntologyNodeSide.Right;

if (full && node.FullLoaded.IsCompleted)
{
node.SetVisibility(data.visible[i], OntologyNode.OntologyNodeSide.Full);
VisibleNodes.Add(node);
set = true;
#if UNITY_EDITOR
Debug.Log("Setting full model visibility to true");
#endif
}
if (leftSide && node.SideLoaded.IsCompleted)
{
node.SetVisibility(data.visible[i], OntologyNode.OntologyNodeSide.Left);
VisibleNodes.Add(node);
set = true;
#if UNITY_EDITOR
Debug.Log("Setting left model visibility to true");
#endif
}
if (rightSide && node.SideLoaded.IsCompleted)
{
node.SetVisibility(data.visible[i], OntologyNode.OntologyNodeSide.Right);
VisibleNodes.Add(node);
set = true;
#if UNITY_EDITOR
Debug.Log("Setting right model visibility to true");
#endif
}

if (set)
NodeVisibleEvent.Invoke(node);
else
LoadIndividualArea(node, full, leftSide, rightSide, data.visible[i]);
}
}

public async void SetAreaColors(Dictionary<string, string> areaColor)
{
Expand Down
6 changes: 4 additions & 2 deletions UnityClient/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ PlayerSettings:
androidMinimumWindowWidth: 400
androidMinimumWindowHeight: 300
androidFullscreenMode: 1
androidAutoRotationBehavior: 1
defaultIsNativeResolution: 1
macRetinaSupport: 1
runInBackground: 1
Expand Down Expand Up @@ -136,7 +137,9 @@ PlayerSettings:
vulkanEnableLateAcquireNextImage: 0
vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0
bundleVersion: 0.5.3
visionOSBundleVersion: 1.0
tvOSBundleVersion: 1.0
bundleVersion: 0.5.4
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down Expand Up @@ -437,7 +440,6 @@ PlayerSettings:
switchScreenResolutionBehavior: 2
switchUseCPUProfiler: 0
switchEnableFileSystemTrace: 0
switchUseGOLDLinker: 0
switchLTOSetting: 0
switchApplicationID: 0x01004b9000490000
switchNSODependencies:
Expand Down

0 comments on commit 5e97ebf

Please sign in to comment.