Skip to content

Commit 678a02f

Browse files
committed
feat: added sagittal/coronal angles, no from allowed for now
from is so complicated daaaamn
1 parent 562a846 commit 678a02f

File tree

11 files changed

+147
-20
lines changed

11 files changed

+147
-20
lines changed

Assets/Prefabs/UI/SettingsMenu/Menus/ProbeMenu.prefab

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4259,6 +4259,8 @@ MonoBehaviour:
42594259
m_Image: {fileID: 0}
42604260
- m_Text: 'Angle convention: New Scale MIS'
42614261
m_Image: {fileID: 0}
4262+
- m_Text: 'Angle convention: Coronal/Sagittal'
4263+
m_Image: {fileID: 0}
42624264
m_OnValueChanged:
42634265
m_PersistentCalls:
42644266
m_Calls:

Assets/Scenes/TrajectoryPlanner.unity

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,6 @@ MonoBehaviour:
512512
m_Script: {fileID: 11500000, guid: 67bac97c0532be84b862331a0bfec212, type: 3}
513513
m_Name:
514514
m_EditorClassIdentifier:
515-
--- !u!114 &499537228 stripped
516-
MonoBehaviour:
517-
m_CorrespondingSourceObject: {fileID: 341190943836276264, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
518-
m_PrefabInstance: {fileID: 341190943874437988}
519-
m_PrefabAsset: {fileID: 0}
520-
m_GameObject: {fileID: 0}
521-
m_Enabled: 1
522-
m_EditorHideFlags: 0
523-
m_Script: {fileID: 11500000, guid: 9085046f02f69544eb97fd06b6048fe2, type: 3}
524-
m_Name:
525-
m_EditorClassIdentifier:
526515
--- !u!114 &514262552 stripped
527516
MonoBehaviour:
528517
m_CorrespondingSourceObject: {fileID: 2252271064940867327, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
@@ -9144,7 +9133,7 @@ PrefabInstance:
91449133
- target: {fileID: 8016510558008620337, guid: 482bfae3ba88b424e96d7fcd669f7b73, type: 3}
91459134
propertyPath: iblAngleToggle
91469135
value:
9147-
objectReference: {fileID: 499537228}
9136+
objectReference: {fileID: 0}
91489137
- target: {fileID: 8016510558008620337, guid: 482bfae3ba88b424e96d7fcd669f7b73, type: 3}
91499138
propertyPath: invivoDropdown
91509139
value:
@@ -9156,7 +9145,7 @@ PrefabInstance:
91569145
- target: {fileID: 8016510558008620337, guid: 482bfae3ba88b424e96d7fcd669f7b73, type: 3}
91579146
propertyPath: _iblAngleToggle
91589147
value:
9159-
objectReference: {fileID: 499537228}
9148+
objectReference: {fileID: 0}
91609149
- target: {fileID: 8016510558008620337, guid: 482bfae3ba88b424e96d7fcd669f7b73, type: 3}
91619150
propertyPath: _invivoDropdown
91629151
value:

Assets/Scripts/Pinpoint/AngleConventions/AngleConvention.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,49 @@ public abstract class AngleConvention
88
public abstract string YName { get; }
99
public abstract string ZName { get; }
1010

11+
public abstract bool AllowFrom { get; }
12+
1113
public abstract Vector3 ToConvention(Vector3 pinpointAngles);
1214

1315
public abstract Vector3 FromConvention(Vector3 conventionAngles);
16+
17+
/// <summary>
18+
/// Convert Pinpoint angles to Cartesian coordinates in a unit sphere
19+
/// </summary>
20+
/// <param name="pinpointAngles"></param>
21+
/// <returns></returns>
22+
public static Vector3 ToCartesian(Vector3 pinpointAngles)
23+
{
24+
pinpointAngles.y = 90f - pinpointAngles.y; // invert the pitch
25+
Vector3 radAngles = pinpointAngles * Mathf.Deg2Rad;
26+
float x = Mathf.Sin(radAngles.y) * Mathf.Cos(radAngles.x);
27+
float y = Mathf.Sin(radAngles.y) * Mathf.Sin(radAngles.x);
28+
float z = Mathf.Cos(radAngles.y);
29+
30+
return new Vector3(x, y, z);
31+
}
32+
33+
/// <summary>
34+
/// Convert Cartesian coordiantes back to Pinpoint angles
35+
/// </summary>
36+
/// <param name="cartesianCoords">normalized vector of cartesian coordinates</param>
37+
/// <returns></returns>
38+
public static Vector3 FromCartesian(Vector3 cartesianCoords)
39+
{
40+
float yaw;
41+
42+
// Handle near-vertical vectors by checking if x and y are small
43+
if (Mathf.Abs(cartesianCoords.x) < 1e-6f && Mathf.Abs(cartesianCoords.y) < 1e-6f)
44+
{
45+
return new Vector3(0f, 90f, 0f);
46+
}
47+
48+
yaw = Mathf.Atan2(cartesianCoords.y, cartesianCoords.x) * Mathf.Rad2Deg;
49+
50+
// Calculate the pitch (angle from the z-axis)
51+
float pitch = Mathf.Acos(cartesianCoords.z) * Mathf.Rad2Deg;
52+
53+
// Return the pinpoint angles
54+
return new Vector3(yaw, 90f - pitch, 0f);
55+
}
1456
}

Assets/Scripts/Pinpoint/AngleConventions/IBLAngleConvention.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class IBLAngleConvention : AngleConvention
1010

1111
public override string ZName => "Roll";
1212

13+
public override bool AllowFrom => true;
14+
1315
/// <summary>
1416
/// Convert Pinpoint angles to IBL format
1517
/// </summary>

Assets/Scripts/Pinpoint/AngleConventions/MISAngleConvention.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ public class MISAngleConvention : AngleConvention
66

77
public override string DisplayName => "New Scale MIS";
88

9-
public override string XName => "AP";
9+
public override string XName => "Arc angle";
1010

11-
public override string YName => "ML";
11+
public override string YName => "Arc tilt";
1212

1313
public override string ZName => "Spin";
1414

15+
public override bool AllowFrom => false;
16+
1517
/// <summary>
1618
/// Convert MIS angles to IBL format
1719
/// </summary>
@@ -20,6 +22,9 @@ public class MISAngleConvention : AngleConvention
2022
public override Vector3 ToConvention(Vector3 pinpointAngles)
2123
{
2224
// todo
25+
Vector3 cartesianCoords = ToCartesian(pinpointAngles);
26+
//float arc_tilt = Mathf.Asin(pinpointAngles)
27+
//float arc_angle =
2328
return new Vector3();
2429
}
2530

Assets/Scripts/Pinpoint/AngleConventions/PinpointAngleConvention.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class PinpointAngleConvention : AngleConvention
1010

1111
public override string ZName => "Roll";
1212

13+
public override bool AllowFrom => true;
14+
1315
public override Vector3 FromConvention(Vector3 conventionAngles)
1416
{
1517
return conventionAngles;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using UnityEngine;
2+
3+
public class SagittalCoronalAngleConvention : AngleConvention
4+
{
5+
public override string DisplayName => "Coronal/Sagittal";
6+
7+
public override string XName => "Coronal";
8+
9+
public override string YName => "Sagittal";
10+
11+
public override string ZName => "Roll";
12+
13+
public override bool AllowFrom => false;
14+
15+
public override Vector3 FromConvention(Vector3 conventionAngles)
16+
{
17+
18+
//conventionAngles = conventionAngles.normalized;
19+
20+
//// Extract the sagittal (XZ) and coronal (YZ) angles from the convention angles
21+
//float XZAngle = conventionAngles.x;
22+
//float YZAngle = -conventionAngles.y; // Undo the sign change from ToConvention
23+
//float combinedRoll = conventionAngles.z;
24+
25+
//Debug.Log(conventionAngles);
26+
27+
////Convert the angles back to Cartesian coordinates
28+
//float z = 1f; // We assume unit length for simplicity (same as in ToConvention)
29+
//float x = Mathf.Tan((90f - XZAngle) * Mathf.Deg2Rad) * z;
30+
//float y = Mathf.Tan((90f - YZAngle) * Mathf.Deg2Rad) * z;
31+
32+
//Debug.Log((x, y, z));
33+
34+
//Vector3 pinpointAngles = FromCartesian(new Vector3(x, y, z));
35+
36+
//Debug.Log(pinpointAngles);
37+
38+
//pinpointAngles.z = combinedRoll - pinpointAngles.x;
39+
40+
41+
//Debug.Log(pinpointAngles);
42+
43+
return conventionAngles;
44+
}
45+
46+
public override Vector3 ToConvention(Vector3 pinpointAngles)
47+
{
48+
Vector3 cartesianCoords = ToCartesian(pinpointAngles);
49+
50+
Debug.Log(cartesianCoords);
51+
52+
// Get the XZ angle, which is the sagittal angle
53+
float XZAngle = 90f - Mathf.Atan2(cartesianCoords.z, cartesianCoords.x) * Mathf.Rad2Deg;
54+
// Get the YZ angle, which is the coronal plane
55+
float YZAngle = 90f - Mathf.Atan2(cartesianCoords.z, cartesianCoords.y) * Mathf.Rad2Deg;
56+
57+
Vector3 angles = new Vector3(XZAngle, -YZAngle, pinpointAngles.x + pinpointAngles.z);
58+
Vector3 back = FromConvention(angles);
59+
60+
Debug.Log((pinpointAngles, back));
61+
return new Vector3(XZAngle, -YZAngle, pinpointAngles.x + pinpointAngles.z);
62+
}
63+
}

Assets/Scripts/Pinpoint/AngleConventions/SagittalCoronalAngleConvention.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Pinpoint/CoordinateEntryPanel.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,18 @@ public void UpdateInteractable(Vector4 pos, Vector3 ang)
6868
_dvField.interactable = pos.z != 0f;
6969
_depthField.interactable = pos.w != 0f;
7070

71-
_yawField.interactable = ang.x != 0f;
72-
_pitchField.interactable = ang.y != 0f;
73-
_rollField.interactable = ang.z != 0f;
71+
if (Settings.AngleConvention.AllowFrom)
72+
{
73+
_yawField.interactable = ang.x != 0f;
74+
_pitchField.interactable = ang.y != 0f;
75+
_rollField.interactable = ang.z != 0f;
76+
}
77+
else
78+
{
79+
_yawField.interactable = false;
80+
_pitchField.interactable = false;
81+
_rollField.interactable = false;
82+
}
7483
}
7584

7685
public void UpdateText()

Assets/Scripts/Pinpoint/TrajectoryPlannerManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ public ProbeManager AddNewProbe(ProbeProperties.ProbeType probeType, string UUID
450450

451451
UpdateQuickSettingsProbeIdText();
452452

453-
newProbeManager.UIUpdateEvent.AddListener(() => UpdateQuickSettings(newProbeManager));
453+
// This listener seems to be redundant with LateUpdate call
454+
//newProbeManager.UIUpdateEvent.AddListener(() => UpdateQuickSettings(newProbeManager));
454455
newProbeManager.ProbeController.MovedThisFrameEvent.AddListener(SetMovedThisFrame);
455456

456457
// Add listener for SetActiveProbe

0 commit comments

Comments
 (0)