Skip to content

Commit

Permalink
Merge branch 'release/4.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
zigaroula committed Nov 7, 2022
2 parents 42d1f08 + 2f3e468 commit 9102d5c
Show file tree
Hide file tree
Showing 48 changed files with 613 additions and 289 deletions.
Binary file modified Assets/Plugins/x86_64/Linux/libEEGFormat.so
Binary file not shown.
Binary file modified Assets/Plugins/x86_64/Linux/libhbp_export.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Assets/Plugins/x86_64/Windows/EEGFormat.dll
Binary file not shown.
Binary file modified Assets/Plugins/x86_64/Windows/hbp_export.dll
Binary file not shown.
Binary file modified Assets/Prefabs/3D/UI/3D Menu.prefab
Binary file not shown.
Binary file modified Assets/Prefabs/CustomUI/Range Slider.prefab
Binary file not shown.
Binary file not shown.
Binary file modified Assets/Prefabs/Informations/Informations.prefab
Binary file not shown.
Binary file modified Assets/Prefabs/Informations/SitesInformations.prefab
Binary file not shown.
Binary file modified Assets/Prefabs/Project/Project item.prefab
Binary file not shown.
13 changes: 11 additions & 2 deletions Assets/Scripts/HBP/Core/Data/Loaded/DynamicData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace HBP.Core.Data
{
Expand Down Expand Up @@ -76,8 +77,16 @@ public DynamicData(DataInfo dataInfo) : this()
List<DLL.EEG.Electrode> channels = file.Electrodes;
foreach (var channel in channels)
{
ValuesByChannel.Add(channel.Label, channel.Data);
UnitByChannel.Add(channel.Label, channel.Unit);
try
{
ValuesByChannel.Add(channel.Label, channel.Data);
UnitByChannel.Add(channel.Label, channel.Unit);
}
catch (ArgumentException e)
{
Debug.LogException(e);
throw new Exception(string.Format("The data file contains multiple {0} channels.", channel.Label));
}
}
Frequency = file.SamplingFrequency;
m_OccurencesByCode = new Dictionary<int, List<EventOccurence>>();
Expand Down
29 changes: 26 additions & 3 deletions Assets/Scripts/HBP/Core/Data/Patient/BaseMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ public static BaseMesh[] LoadFromDirectory(string path)
{
List<BaseMesh> meshes = new List<BaseMesh>();
DirectoryInfo parent = new DirectoryInfo(path);
DirectoryInfo t1mr1 = new DirectoryInfo(Path.Combine(path, "t1mri"));
DirectoryInfo t1mri = new DirectoryInfo(Path.Combine(path, "t1mri"));
DirectoryInfo ct = new DirectoryInfo(Path.Combine(path, "ct"));

DirectoryInfo preimplantationDirectory = null, preTransformationsDirectory = null;
FileInfo preTransformation = null;
preimplantationDirectory = t1mr1.GetDirectories("T1pre_*").FirstOrDefault();
if (t1mri.Exists) preimplantationDirectory = t1mri.GetDirectories("T1pre_*").FirstOrDefault();
if (preimplantationDirectory != null && preimplantationDirectory.Exists)
{
preTransformationsDirectory = new DirectoryInfo(Path.Combine(preimplantationDirectory.FullName, "registration"));
Expand All @@ -165,7 +166,7 @@ public static BaseMesh[] LoadFromDirectory(string path)
// Post
DirectoryInfo postimplantationDirectory = null, postTransformationsDirectory = null;
FileInfo postTransformation = null;
postimplantationDirectory = t1mr1.GetDirectories("T1post_*").FirstOrDefault();
if (t1mri.Exists) postimplantationDirectory = t1mri.GetDirectories("T1post_*").FirstOrDefault();
if (postimplantationDirectory != null && postimplantationDirectory.Exists)
{
postTransformationsDirectory = new DirectoryInfo(Path.Combine(postimplantationDirectory.FullName, "registration"));
Expand All @@ -176,6 +177,20 @@ public static BaseMesh[] LoadFromDirectory(string path)
}
string postTransformationPath = string.Empty;
if (postTransformation != null && postTransformation.Exists) postTransformationPath = postTransformation.FullName;
// CT
DirectoryInfo ctDirectory = null, ctTransformationsDirectory = null;
FileInfo ctTransformation = null;
if (ct.Exists) ctDirectory = ct.GetDirectories("CTpost_*").FirstOrDefault();
if (ctDirectory != null && ctDirectory.Exists)
{
ctTransformationsDirectory = new DirectoryInfo(Path.Combine(ctDirectory.FullName, "registration"));
if (ctTransformationsDirectory != null && ctTransformationsDirectory.Exists)
{
ctTransformation = ctTransformationsDirectory.GetFiles("CT-" + parent.Name + "_" + ctDirectory.Name + "_TO_Scanner_Based.trm").FirstOrDefault();
}
}
string ctTransformationPath = string.Empty;
if (ctTransformation != null && ctTransformation.Exists) ctTransformationPath = ctTransformation.FullName;
// Mesh
DirectoryInfo meshDirectory = new DirectoryInfo(Path.Combine(preimplantationDirectory.FullName, "default_analysis", "segmentation", "mesh"));
if(meshDirectory.Exists)
Expand All @@ -189,6 +204,10 @@ public static BaseMesh[] LoadFromDirectory(string path)
{
meshes.Add(new LeftRightMesh("Grey matter post", postTransformationPath, greyMatterLeftHemisphere.FullName, greyMatterRightHemisphere.FullName, string.Empty, string.Empty));
}
if (!string.IsNullOrEmpty(ctTransformationPath))
{
meshes.Add(new LeftRightMesh("Grey matter CT", ctTransformationPath, greyMatterLeftHemisphere.FullName, greyMatterRightHemisphere.FullName, string.Empty, string.Empty));
}
}

FileInfo whiteMatterLeftHemisphere = new FileInfo(Path.Combine(meshDirectory.FullName, parent.Name + "_Lwhite" + MESH_EXTENSION));
Expand All @@ -205,6 +224,10 @@ public static BaseMesh[] LoadFromDirectory(string path)
{
meshes.Add(new LeftRightMesh("White matter post", postTransformationPath, whiteMatterLeftHemisphere.FullName, whiteMatterRightHemisphere.FullName, marsAtlasLeftHemispherePath, marsAtlasRightHemispherePath));
}
if (!string.IsNullOrEmpty(ctTransformationPath))
{
meshes.Add(new LeftRightMesh("White matter CT", ctTransformationPath, whiteMatterLeftHemisphere.FullName, whiteMatterRightHemisphere.FullName, marsAtlasLeftHemispherePath, marsAtlasRightHemispherePath));
}
}
}
return meshes.ToArray();
Expand Down
15 changes: 15 additions & 0 deletions Assets/Scripts/HBP/Core/Data/Patient/MRI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public static MRI[] LoadFromDirectory(string path)
if (string.IsNullOrEmpty(path) || !Directory.Exists(path)) return MRIs.ToArray();
DirectoryInfo directoryInfo = new DirectoryInfo(path);
DirectoryInfo t1mriDirectoy = directoryInfo.GetDirectories("t1mri", SearchOption.TopDirectoryOnly).FirstOrDefault();
DirectoryInfo ct = directoryInfo.GetDirectories("ct", SearchOption.TopDirectoryOnly).FirstOrDefault();

if (t1mriDirectoy != null && t1mriDirectoy.Exists)
{
Expand All @@ -165,6 +166,20 @@ public static MRI[] LoadFromDirectory(string path)
MRIs.Add(new MRI("Postimplantation", postimplantationMRIFile.FullName));
}
}

// CT
if (ct != null && ct.Exists)
{
DirectoryInfo ctDirectory = ct.GetDirectories("CTpost_*", SearchOption.TopDirectoryOnly).FirstOrDefault();
if (ctDirectory != null && ctDirectory.Exists)
{
FileInfo ctMRIFile = ctDirectory.GetFiles(directoryInfo.Name + "-CTPost_*" + EXTENSION).FirstOrDefault();
if (ctMRIFile != null && ctMRIFile.Exists)
{
MRIs.Add(new MRI("CT", ctMRIFile.FullName));
}
}
}
}
return MRIs.ToArray();
}
Expand Down
24 changes: 14 additions & 10 deletions Assets/Scripts/HBP/Core/Data/Patient/Site.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public static List<Site> LoadFromIntranatDirectory(string path)
{
referenceSystem = "Post";
}
else if (referenceSystem.Contains("CTPost"))
{
referenceSystem = "CT";
}
var ptsSites = LoadSitesFromPTSFile(referenceSystem, file.FullName);
foreach (var site in ptsSites)
{
Expand Down Expand Up @@ -175,11 +179,11 @@ public static List<Site> LoadImplantationFromBIDSFile(string referenceSystem, st
int marsAtlasIndex = splittedLines[0].IndexOf("MarsAtlas");
if (marsAtlasIndex != -1)
{
splittedLines[0].Insert(marsAtlasIndex + 1, "Hemisphere (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 2, "Lobe (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 3, "Name_FS (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 4, "Full name (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 5, "Brodmann Area (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 1, "Hemisphere-MarsAtlas");
splittedLines[0].Insert(marsAtlasIndex + 2, "Lobe-MarsAtlas");
splittedLines[0].Insert(marsAtlasIndex + 3, "NameFS-MarsAtlas");
splittedLines[0].Insert(marsAtlasIndex + 4, "Fullname-MarsAtlas");
splittedLines[0].Insert(marsAtlasIndex + 5, "BrodmannArea-MarsAtlas");
for (int i = 1; i < splittedLines.Count; ++i)
{
int marsAtlasLabel = Object3DManager.MarsAtlas.Label(splittedLines[i][marsAtlasIndex]);
Expand Down Expand Up @@ -410,11 +414,11 @@ public static List<Site> LoadSitesFromCSVFile(string csvFile)
int marsAtlasIndex = splittedLines[0].IndexOf("MarsAtlas");
if (marsAtlasIndex != -1)
{
splittedLines[0].Insert(marsAtlasIndex + 1, "Hemisphere (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 2, "Lobe (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 3, "Name_FS (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 4, "Full name (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 5, "Brodmann Area (MarsAtlas)");
splittedLines[0].Insert(marsAtlasIndex + 1, "Hemisphere-MarsAtlas");
splittedLines[0].Insert(marsAtlasIndex + 2, "Lobe-MarsAtlas");
splittedLines[0].Insert(marsAtlasIndex + 3, "NameFS-MarsAtlas");
splittedLines[0].Insert(marsAtlasIndex + 4, "Fullname-MarsAtlas");
splittedLines[0].Insert(marsAtlasIndex + 5, "Brodmann-MarsAtlas");
for (int i = 1; i < splittedLines.Count; ++i)
{
int marsAtlasLabel = Object3DManager.MarsAtlas.Label(splittedLines[i][marsAtlasIndex]);
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/HBP/Core/Data/Project/Alias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public Alias(string key, string value) : base()
#region Public Methods
public void ConvertKeyToValue(ref string s)
{
if (string.IsNullOrEmpty(Value)) return;
s = s.Replace(Key, Value);
}
public void ConvertValueToKey(ref string s)
{
if (string.IsNullOrEmpty(Value)) return;
s = s.Replace(Value, Key);
}
#endregion
Expand Down
84 changes: 84 additions & 0 deletions Assets/Scripts/HBP/Core/Data/Project/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using UnityEngine;
using HBP.Core.Exceptions;
using HBP.Core.Tools;
using HBP.Core.Interfaces;

namespace HBP.Core.Data
{
Expand Down Expand Up @@ -404,6 +405,89 @@ public string GetProject(string path, string ID)
}
return projectsDirectories.FirstOrDefault((project) => new ProjectInfo(project).Settings.ID == ID);
}
public Dictionary<string, List<Tuple<BaseData, string>>> CheckProjectIDs()
{
Dictionary<string, List<Tuple<BaseData, string>>> dataByID = new Dictionary<string, List<Tuple<BaseData, string>>>();
void addToDict(BaseData data, string name)
{
if (dataByID.ContainsKey(data.ID)) dataByID[data.ID].Add(new Tuple<BaseData, string>(data, name));
else dataByID.Add(data.ID, new List<Tuple<BaseData, string>>(new Tuple<BaseData, string>[] { new Tuple<BaseData, string>(data, name) }));
}
string getName(INameable data)
{
return string.Format("{0} ({1})", data.Name, getType(data as BaseData));
}
string getType(BaseData data)
{
return data.GetType().ToString().Split('.').Last();
}
// Settings
addToDict(Preferences, getType(Preferences));
foreach (var alias in Preferences.Aliases) addToDict(alias, string.Format("{0} ({1})", alias.Key, getType(alias)));
foreach (var tag in Preferences.Tags) addToDict(tag, getName(tag));
// Patients
foreach (var patient in m_Patients)
{
addToDict(patient, getName(patient));
foreach (var mesh in patient.Meshes) addToDict(mesh, string.Format("{0} / {1}", getName(patient), getName(mesh)));
foreach (var mri in patient.MRIs) addToDict(mri, string.Format("{0} / {1}", getName(patient), getName(mri)));
foreach (var site in patient.Sites)
{
addToDict(site, string.Format("{0} / {1}", getName(patient), getName(site)));
foreach (var coordinate in site.Coordinates) addToDict(coordinate, string.Format("{0} / {1} / {2}", getName(patient), getName(site), string.Format("{0} ({1})", coordinate.ReferenceSystem, getType(coordinate))));
foreach (var tagValue in site.Tags) addToDict(tagValue, string.Format("{0} / {1} / {2}", getName(patient), getName(site), string.Format("{0} ({1})", tagValue.Tag.Name, getType(tagValue))));
}
foreach (var tagValue in patient.Tags) addToDict(tagValue, string.Format("{0} / {1}", getName(patient), string.Format("{0} ({1})", tagValue.Tag.Name, getType(tagValue))));
}
// Groups
foreach (var group in m_Groups) addToDict(group, getName(group));
// Protocols
foreach (var protocol in m_Protocols)
{
addToDict(protocol, getName(protocol));
foreach (var bloc in protocol.Blocs)
{
addToDict(bloc, string.Format("{0} / {1}", getName(protocol), getName(bloc)));
foreach (var subBloc in bloc.SubBlocs)
{
addToDict(subBloc, string.Format("{0} / {1} / {2}", getName(protocol), getName(bloc), getName(subBloc)));
foreach (var ev in subBloc.Events) addToDict(ev, string.Format("{0} / {1} / {2} / {3}", getName(protocol), getName(bloc), getName(subBloc), getName(ev)));
foreach (var icon in subBloc.Icons) addToDict(icon, string.Format("{0} / {1} / {2} / {3}", getName(protocol), getName(bloc), getName(subBloc), getName(icon)));
foreach (var treatment in subBloc.Treatments) addToDict(treatment, string.Format("{0} / {1} / {2} / {3}", getName(protocol), getName(bloc), getName(subBloc), getType(treatment)));
}
}
}
// Datasets
foreach (var dataset in m_Datasets)
{
addToDict(dataset, getName(dataset));
foreach (var data in dataset.Data)
{
addToDict(data, string.Format("{0} / {1}", getName(dataset), getName(data)));
addToDict(data.DataContainer, string.Format("{0} / {1} / {2}", getName(dataset), getName(data), getType(data.DataContainer)));
}
}
// Visualizations
foreach (var visualization in m_Visualizations)
{
addToDict(visualization, getName(visualization));
foreach (var column in visualization.Columns)
{
addToDict(column, string.Format("{0} / {1}", getName(visualization), getName(column)));
addToDict(column.BaseConfiguration, string.Format("{0} / {1} / {2}", getName(visualization), getName(column), getType(column.BaseConfiguration)));
foreach (var siteConfig in column.BaseConfiguration.ConfigurationBySite) addToDict(siteConfig.Value, string.Format("{0} / {1} / {2})", getName(visualization), getName(column), string.Format("{0} ({1})", siteConfig.Key, getType(siteConfig.Value))));
}
foreach (var anatomicColumn in visualization.AnatomicColumns) addToDict(anatomicColumn.AnatomicConfiguration, string.Format("{0} / {1} / {2}", getName(visualization), getName(anatomicColumn), getType(anatomicColumn.AnatomicConfiguration)));
foreach (var ieegColumn in visualization.IEEGColumns) addToDict(ieegColumn.DynamicConfiguration, string.Format("{0} / {1} / {2}", getName(visualization), getName(ieegColumn), getType(ieegColumn.DynamicConfiguration)));
foreach (var ccepColumn in visualization.CCEPColumns) addToDict(ccepColumn.DynamicConfiguration, string.Format("{0} / {1} / {2}", getName(visualization), getName(ccepColumn), getType(ccepColumn.DynamicConfiguration)));
foreach (var fmriColumn in visualization.FMRIColumns) addToDict(fmriColumn.FMRIConfiguration, string.Format("{0} / {1} / {2}", getName(visualization), getName(fmriColumn), getType(fmriColumn.FMRIConfiguration)));
foreach (var megColumn in visualization.MEGColumns) addToDict(megColumn.MEGConfiguration, string.Format("{0} / {1} / {2}", getName(visualization), getName(megColumn), getType(megColumn.MEGConfiguration)));
}
// Check unicity and return error string
Dictionary<string, List<Tuple<BaseData, string>>> problematicData = new Dictionary<string, List<Tuple<BaseData, string>>>();
foreach (var kv in dataByID) if (kv.Value.Count > 1) problematicData.Add(kv.Key, kv.Value);
return problematicData;
}

public IEnumerator c_Load(ProjectInfo projectInfo, Action<float, float, LoadingText> onChangeProgress)
{
Expand Down
12 changes: 11 additions & 1 deletion Assets/Scripts/HBP/Core/Data/Project/ProjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Ionic.Zip;
using HBP.Core.Exceptions;
using HBP.Core.Tools;
using UnityEngine;

namespace HBP.Core.Data
{
Expand Down Expand Up @@ -64,7 +65,16 @@ public ProjectInfo(string path) : base()
FileInfo settingsFile = new FileInfo(System.IO.Path.Combine(ApplicationState.TMPFolder, entry.FileName));
if (settingsFile.Exists) settingsFile.Delete();
entry.Extract(ApplicationState.TMPFolder);
Settings = ClassLoaderSaver.LoadFromJson<ProjectPreferences>(settingsFile.FullName);
try
{
Settings = ClassLoaderSaver.LoadFromJson<ProjectPreferences>(settingsFile.FullName);
}
catch (System.Exception e)
{
Debug.LogException(e);
Settings = new ProjectPreferences(System.IO.Path.GetFileNameWithoutExtension(path));
Settings.CanLoadProject = false;
}
settingsFile.Directory.Delete(true);
}
}
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/HBP/Core/Data/Project/ProjectPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ReadOnlyCollection<BaseTag> Tags
[IgnoreDataMember] public static string DefaultName = "New Project";
[IgnoreDataMember] public static string DefaultPatientDatabase = "";
[IgnoreDataMember] public static string DefaultLocalizerDatabase = "";
[IgnoreDataMember] public bool CanLoadProject = true;
#endregion

#region Constructors
Expand Down
Loading

0 comments on commit 9102d5c

Please sign in to comment.