Skip to content

Commit

Permalink
Merge branch 'release/3.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
zigaroula committed Feb 2, 2022
2 parents ed9e3bc + 3e76b8a commit 490f157
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 76 deletions.
Binary file modified Assets/Plugins/x86_64/Linux/libhbp_export.so
Binary file not shown.
Binary file not shown.
Binary file modified Assets/Plugins/x86_64/Windows/hbp_export.dll
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions Assets/Scripts/HBP/3D/Scene/Base3DScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,10 @@ public bool IsGeneratorUpToDate
/// </summary>
[HideInInspector] public GenericEvent<IEnumerable<Site>> OnRequestSiteInformation = new GenericEvent<IEnumerable<Site>>();
/// <summary>
/// Event called when requesting a graph from the filtered sites in the siteactions panel
/// </summary>
[HideInInspector] public GenericEvent<IEnumerable<Site>> OnRequestFilteredSitesGraph = new GenericEvent<IEnumerable<Site>>();
/// <summary>
/// Event called when ieeg are outdated or not anymore
/// </summary>
[HideInInspector] public GenericEvent<bool> OnIEEGOutdated = new GenericEvent<bool>();
Expand Down
11 changes: 6 additions & 5 deletions Assets/Scripts/HBP/3D/Scene/Modules/ROIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ public ROI SelectedROI
}
set
{
if (m_SelectedROI != null)
{
m_SelectedROI.SetVisibility(false);
}

if (value == null)
{
m_SelectedROI = null;
}
else
{
if (m_SelectedROI != null)
{
m_SelectedROI.SetVisibility(false);
}

m_SelectedROI = value;
m_SelectedROI.SetVisibility(true);
}

UpdateROIMasks();
}
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/HBP/Data/Dataset/DataInfo/DataInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public virtual string GetErrorsMessage()
{
if (errors[i].Message != "")
{
stringBuilder.AppendLine(string.Format("• {0}({1})", errors[i].Title, errors[i].Message));
stringBuilder.AppendLine(string.Format("• {0} ({1})", errors[i].Title, errors[i].Message));

}
else
Expand All @@ -193,7 +193,7 @@ public virtual string GetErrorsMessage()
}
if (errors.Last().Message != "")
{
stringBuilder.Append(string.Format("• {0}({1})", errors.Last().Title, errors.Last().Message));
stringBuilder.Append(string.Format("• {0} ({1})", errors.Last().Title, errors.Last().Message));

}
else
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/HBP/Data/Dataset/DataInfo/iEEGDataInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ public virtual Error[] GetiEEGErrors(Protocol.Protocol protocol)
List<Tools.CSharp.EEG.Trigger> triggers = file.Triggers;
if (protocol.IsVisualizable && !protocol.Blocs.All(bloc => bloc.MainSubBloc.MainEvent.Codes.Any(code => triggers.Any(t => t.Code == code))))
{
errors.Add(new BlocsCantBeEpochedError());
IEnumerable<string> blocsNotFound = protocol.Blocs.Where(bloc => !bloc.MainSubBloc.MainEvent.Codes.Any(code => triggers.Any(t => t.Code == code))).Select(bloc => bloc.Name);
errors.Add(new BlocsCantBeEpochedError(string.Join(", ", blocsNotFound)));
}
}
m_iEEGErrors = errors.ToArray();
Expand All @@ -199,7 +200,7 @@ public BlocsCantBeEpochedError() : this("")
{

}
public BlocsCantBeEpochedError(string message) : base("One of the blocs of the protocol can't be epoched", message)
public BlocsCantBeEpochedError(string message) : base("At least one of the blocs of the protocol can't be epoched", message)
{

}
Expand Down
16 changes: 15 additions & 1 deletion Assets/Scripts/HBP/Data/Preferences/VisaluzationPreferences.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using UnityEngine;
Expand Down Expand Up @@ -146,6 +147,7 @@ public Color[] Colors
}
}
}
[IgnoreDataMember] private Dictionary<int, Color> m_AdditionalColors = new Dictionary<int, Color>();
#endregion

#region Constructors
Expand Down Expand Up @@ -203,7 +205,19 @@ public Color GetColor(int position)
{
return m_Colors[position].ToColor();
}
return new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f));
else
{
if (m_AdditionalColors.TryGetValue(position, out Color color))
{
return color;
}
else
{
color = new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f));
m_AdditionalColors.Add(position, color);
return color;
}
}
}
public Color GetColor(int row, int column)
{
Expand Down
20 changes: 10 additions & 10 deletions Assets/Scripts/HBP/Data/TrialMatrix/Grid/ChannelStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public bool Equals(MEGData other)
}

[Serializable]
public class ROI : IEquatable<ROI>
public class ChannelStructsGroup : IEquatable<ChannelStructsGroup>
{
#region Properties
[SerializeField] string m_Name;
Expand Down Expand Up @@ -308,7 +308,7 @@ public List<ChannelStruct> Channels
#endregion

#region Constructors
public ROI(string name, IEnumerable<ChannelStruct> channels)
public ChannelStructsGroup(string name, IEnumerable<ChannelStruct> channels)
{
Name = name;
Channels = new List<ChannelStruct>(channels);
Expand All @@ -318,9 +318,9 @@ public ROI(string name, IEnumerable<ChannelStruct> channels)
#region Public Methods
public override bool Equals(object obj)
{
return Equals(obj as ROI);
return Equals(obj as ChannelStructsGroup);
}
public bool Equals(ROI other)
public bool Equals(ChannelStructsGroup other)
{
bool notNull = other != null;
if (notNull)
Expand All @@ -339,11 +339,11 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + EqualityComparer<List<ChannelStruct>>.Default.GetHashCode(Channels);
return hashCode;
}
public static bool operator ==(ROI struct1, ROI struct2)
public static bool operator ==(ChannelStructsGroup struct1, ChannelStructsGroup struct2)
{
return EqualityComparer<ROI>.Default.Equals(struct1, struct2);
return EqualityComparer<ChannelStructsGroup>.Default.Equals(struct1, struct2);
}
public static bool operator !=(ROI struct1, ROI struct2)
public static bool operator !=(ChannelStructsGroup struct1, ChannelStructsGroup struct2)
{
return !(struct1 == struct2);
}
Expand Down Expand Up @@ -406,13 +406,13 @@ public class Column : IEquatable<Column>
{
public string Name;
public Data Data;
public ROI ROI;
public List<ChannelStructsGroup> ChannelGroups;

public Column(string name, Data data, ROI roi)
public Column(string name, Data data, List<ChannelStructsGroup> channelGroups)
{
Name = name;
Data = data;
ROI = roi;
ChannelGroups = new List<ChannelStructsGroup>(channelGroups);
}

#region Public Methods
Expand Down
70 changes: 46 additions & 24 deletions Assets/Scripts/HBP/UI/Module3D/SiteInformations/SiteActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ public class SiteActions : MonoBehaviour
/// </summary>
[SerializeField] private GameObject m_ActionsPanel;

/// <summary>
/// Toggle to specify that the action to be apply is an export to a csv file
/// </summary>
[SerializeField] private Toggle m_ExportSitesToggle;
/// <summary>
/// Object containing all the UI used to export the sites to a csv file
/// </summary>
[SerializeField] private GameObject m_ExportSitesPanel;
/// <summary>
/// Toggle to specify that the action to be apply is a change in the states of the sites
/// </summary>
Expand All @@ -56,13 +48,13 @@ public class SiteActions : MonoBehaviour
/// </summary>
[SerializeField] private GameObject m_ChangeStatePanel;
/// <summary>
/// Toggle to specify that the action to be apply is a group creation
/// Toggle to specify that the action to be apply is a misc action
/// </summary>
[SerializeField] private Toggle m_CreateGroupToggle;
[SerializeField] private Toggle m_OtherToggle;
/// <summary>
/// Object containing all the UI used to create a group
/// Object containing all the UI used for misc actions
/// </summary>
[SerializeField] private GameObject m_CreateGroupPanel;
[SerializeField] private GameObject m_OtherPanel;

/// <summary>
/// Used to highlight the filtered sites
Expand Down Expand Up @@ -113,7 +105,22 @@ public class SiteActions : MonoBehaviour
/// </summary>
[SerializeField] private Toggle m_AllColumnsToggle;

/// <summary>
/// Toggle to specify that the action to be apply is an export to a csv file
/// </summary>
[SerializeField] private Toggle m_ExportSitesToggle;
/// <summary>
/// Toggle to specify that the action to be apply is a group creation
/// </summary>
[SerializeField] private Toggle m_CreateGroupToggle;
/// <summary>
/// Inputfield to specify the name of the newly created group
/// </summary>
[SerializeField] private InputField m_GroupNameInputField;
/// <summary>
/// Toggle to specify that the action to be apply is a graph display
/// </summary>
[SerializeField] private Toggle m_DisplayGraphsToggle;

/// <summary>
/// Button to trigger the application of the action
Expand Down Expand Up @@ -153,22 +160,29 @@ public void ApplyAction()
{
ChangeSitesStates();
}
else if (m_ExportSitesToggle.isOn)
else if (m_OtherToggle.isOn)
{
if (m_Coroutine != null)
if (m_ExportSitesToggle.isOn)
{
if (m_Coroutine != null)
{
StopCoroutine(m_Coroutine);
StopExport();
}
else
{
ExportSites();
}
}
else if (m_CreateGroupToggle.isOn)
{
StopCoroutine(m_Coroutine);
StopExport();
CreateGroup();
}
else
else if (m_DisplayGraphsToggle.isOn)
{
ExportSites();
DisplayGraphs();
}
}
else if (m_CreateGroupToggle.isOn)
{
CreateGroup();
}
}
catch (Exception e)
{
Expand All @@ -182,14 +196,18 @@ public void ApplyAction()
private void Awake()
{
m_OnOffToggle.onValueChanged.AddListener(m_ActionsPanel.gameObject.SetActive);
m_ExportSitesToggle.onValueChanged.AddListener(m_ExportSitesPanel.SetActive);
m_ChangeStateToggle.onValueChanged.AddListener(m_ChangeStatePanel.SetActive);
m_CreateGroupToggle.onValueChanged.AddListener(m_CreateGroupPanel.SetActive);
m_OtherToggle.onValueChanged.AddListener(m_OtherPanel.SetActive);
m_ApplyButton.onClick.AddListener(ApplyAction);

m_ColorPickerButton.onClick.AddListener(() =>
{
ApplicationState.ColorPicker.Open(m_ColorPickedImage.color, (c) => m_ColorPickedImage.color = c);
});
m_AddLabelToggle.onValueChanged.AddListener(isOn => m_LabelInputField.interactable = m_AddLabelToggle.isOn || m_RemoveLabelToggle.isOn);
m_RemoveLabelToggle.onValueChanged.AddListener(isOn => m_LabelInputField.interactable = m_AddLabelToggle.isOn || m_RemoveLabelToggle.isOn);
m_ColorToggle.onValueChanged.AddListener(isOn => m_ColorPickerButton.interactable = isOn);
m_CreateGroupToggle.onValueChanged.AddListener(isOn => m_GroupNameInputField.interactable = isOn);
}
private void Update()
{
Expand Down Expand Up @@ -281,6 +299,10 @@ private void StopExport()
m_Coroutine = null;
m_ProgressBar.End();
}
private void DisplayGraphs()
{
m_Scene.OnRequestFilteredSitesGraph.Invoke(m_Scene.SelectedColumn.Sites.Where(s => s.State.IsFiltered));
}
#endregion

#region Coroutines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ Graph.Curve GenerateColumnCurve(Column column, ChannelStruct[] channels, SubBloc
List<Graph.Curve> subcurves = new List<Graph.Curve>();

// Add ROI Curve.
if (column.ROI != null)
for (int i = 0; i < column.ChannelGroups.Count; i++)
{
subcurves.Add(GenerateROICurve(column, subBloc, ID));
subcurves.Add(GenerateGroupsCurve(column, i, subBloc, ID));
}

// Generate Channels By Patient.
Expand All @@ -294,12 +294,12 @@ Graph.Curve GenerateColumnCurve(Column column, ChannelStruct[] channels, SubBloc
Graph.Curve curve = new Graph.Curve(column.Name, null, true, ID, subcurves.ToArray(), m_DefaultColor);
return curve;
}
Graph.Curve GenerateROICurve(Column column, SubBloc subBloc, string ID)
Graph.Curve GenerateGroupsCurve(Column column, int index, SubBloc subBloc, string ID)
{
ID += "_" + column.ROI.Name;
ID += "_" + column.ChannelGroups[index].Name;
CurveData curveData = null;
Dictionary<Patient, List<string>> ChannelsByPatient = new Dictionary<Patient, List<string>>();
foreach (var channel in column.ROI.Channels)
foreach (var channel in column.ChannelGroups[index].Channels)
{
ChannelsByPatient.AddIfAbsent(channel.Patient, new List<string>());
ChannelsByPatient[channel.Patient].Add(channel.Channel);
Expand All @@ -322,15 +322,15 @@ Graph.Curve GenerateROICurve(Column column, SubBloc subBloc, string ID)
}
}

Color color = ApplicationState.UserPreferences.Visualization.Graph.GetColor(2, Array.IndexOf(m_Columns, column));
if (column.ROI.Channels.Count > 1)
Color color = ApplicationState.UserPreferences.Visualization.Graph.GetColor(index + 2, Array.IndexOf(m_Columns, column));
if (column.ChannelGroups[index].Channels.Count > 1)
{
int channelCount = column.ROI.Channels.Count;
int channelCount = column.ChannelGroups[index].Channels.Count;
// Get the statistics for all channels in the ROI
BlocChannelStatistics[] statistics = new BlocChannelStatistics[channelCount];
for (int c = 0; c < channelCount; ++c)
{
statistics[c] = DataManager.GetStatistics(dataInfoByPatient[column.ROI.Channels[c].Patient], column.Data.Bloc, column.ROI.Channels[c].Channel);
statistics[c] = DataManager.GetStatistics(dataInfoByPatient[column.ChannelGroups[index].Channels[c].Patient], column.Data.Bloc, column.ChannelGroups[index].Channels[c].Channel);
}
// Create all the required variables
int length = statistics[0].Trial.ChannelSubTrialBySubBloc[subBloc].Values.Length;
Expand Down Expand Up @@ -369,9 +369,9 @@ Graph.Curve GenerateROICurve(Column column, SubBloc subBloc, string ID)
}
curveData = ShapedCurveData.CreateInstance(points, standardDeviations, color);
}
else if (column.ROI.Channels.Count == 1)
else if (column.ChannelGroups[index].Channels.Count == 1)
{
ChannelStruct channel = column.ROI.Channels[0];
ChannelStruct channel = column.ChannelGroups[index].Channels[0];
ChannelSubTrialStat stat = DataManager.GetStatistics(dataInfoByPatient[channel.Patient], column.Data.Bloc, channel.Channel).Trial.ChannelSubTrialBySubBloc[subBloc];
float[] values = stat.Values;

Expand All @@ -388,7 +388,7 @@ Graph.Curve GenerateROICurve(Column column, SubBloc subBloc, string ID)
curveData = CurveData.CreateInstance(points, color);
}

Graph.Curve result = new Graph.Curve(column.ROI.Name, curveData, true, ID, new Graph.Curve[0], m_DefaultColor);
Graph.Curve result = new Graph.Curve(column.ChannelGroups[index].Name, curveData, true, ID, new Graph.Curve[0], m_DefaultColor);
return result;
}
Graph.Curve GeneratePatientCurve(Column column, ChannelStruct[] channels, SubBloc subBloc, string ID)
Expand Down
Loading

0 comments on commit 490f157

Please sign in to comment.