Skip to content

Commit 8fe96dd

Browse files
committed
fix: fixing a bug that caused searched areas and probes not to re-calculate position when the atlas transform was changed
1 parent fea8060 commit 8fe96dd

File tree

6 files changed

+75
-27
lines changed

6 files changed

+75
-27
lines changed

Assets/Scenes/TrajectoryPlanner.unity

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ PrefabInstance:
604604
objectReference: {fileID: 0}
605605
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
606606
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.size
607-
value: 2
607+
value: 3
608608
objectReference: {fileID: 0}
609609
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
610610
propertyPath: ReferenceCoordChangedEvent.m_PersistentCalls.m_Calls.Array.size
@@ -642,6 +642,10 @@ PrefabInstance:
642642
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[1].m_Mode
643643
value: 1
644644
objectReference: {fileID: 0}
645+
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
646+
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[2].m_Mode
647+
value: 1
648+
objectReference: {fileID: 0}
645649
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
646650
propertyPath: ReferenceCoordChangedEvent.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
647651
value: 1
@@ -654,6 +658,10 @@ PrefabInstance:
654658
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[1].m_Target
655659
value:
656660
objectReference: {fileID: 1452920056}
661+
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
662+
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[2].m_Target
663+
value:
664+
objectReference: {fileID: 2108153968}
657665
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
658666
propertyPath: ReferenceCoordChangedEvent.m_PersistentCalls.m_Calls.Array.data[0].m_Target
659667
value:
@@ -666,6 +674,10 @@ PrefabInstance:
666674
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[1].m_CallState
667675
value: 2
668676
objectReference: {fileID: 0}
677+
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
678+
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[2].m_CallState
679+
value: 2
680+
objectReference: {fileID: 0}
669681
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
670682
propertyPath: ReferenceCoordChangedEvent.m_PersistentCalls.m_Calls.Array.data[0].m_CallState
671683
value: 2
@@ -678,6 +690,10 @@ PrefabInstance:
678690
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[1].m_MethodName
679691
value: UpdateAxisDirections
680692
objectReference: {fileID: 0}
693+
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
694+
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[2].m_MethodName
695+
value: WarpBrain
696+
objectReference: {fileID: 0}
681697
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
682698
propertyPath: ReferenceCoordChangedEvent.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
683699
value: UpdateReferenceCoordinate
@@ -698,6 +714,10 @@ PrefabInstance:
698714
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[1].m_TargetAssemblyTypeName
699715
value: ReferenceCoordBehavior, pinpoint.brain
700716
objectReference: {fileID: 0}
717+
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
718+
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[2].m_TargetAssemblyTypeName
719+
value: PinpointAtlasManager, trajectoryplanner.core
720+
objectReference: {fileID: 0}
701721
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
702722
propertyPath: ReferenceCoordChangedEvent.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
703723
value: ReferenceCoordBehavior, pinpoint.brain
@@ -718,6 +738,10 @@ PrefabInstance:
718738
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[1].m_Arguments.m_ObjectArgumentAssemblyTypeName
719739
value: UnityEngine.Object, UnityEngine
720740
objectReference: {fileID: 0}
741+
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
742+
propertyPath: AtlasTransformChangedEvent.m_PersistentCalls.m_Calls.Array.data[2].m_Arguments.m_ObjectArgumentAssemblyTypeName
743+
value: UnityEngine.Object, UnityEngine
744+
objectReference: {fileID: 0}
721745
- target: {fileID: 1661132737403472946, guid: ee09154d7a7870a419882ff36080d765, type: 3}
722746
propertyPath: ReferenceCoordChangedEvent.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
723747
value: UnityEngine.Object, UnityEngine
@@ -3130,15 +3154,15 @@ PrefabInstance:
31303154
objectReference: {fileID: 1703646459}
31313155
- target: {fileID: 341190943836035196, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
31323156
propertyPath: m_AnchorMax.y
3133-
value: 1
3157+
value: 0
31343158
objectReference: {fileID: 0}
31353159
- target: {fileID: 341190943836035196, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
31363160
propertyPath: m_AnchorMin.y
3137-
value: 1
3161+
value: 0
31383162
objectReference: {fileID: 0}
31393163
- target: {fileID: 341190943836035196, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
31403164
propertyPath: m_AnchoredPosition.x
3141-
value: 169.88
3165+
value: 0
31423166
objectReference: {fileID: 0}
31433167
- target: {fileID: 341190943836276264, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
31443168
propertyPath: m_IsOn
@@ -3274,19 +3298,19 @@ PrefabInstance:
32743298
objectReference: {fileID: 0}
32753299
- target: {fileID: 341190944034978748, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
32763300
propertyPath: m_AnchorMax.y
3277-
value: 1
3301+
value: 0
32783302
objectReference: {fileID: 0}
32793303
- target: {fileID: 341190944034978748, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
32803304
propertyPath: m_AnchorMin.y
3281-
value: 1
3305+
value: 0
32823306
objectReference: {fileID: 0}
32833307
- target: {fileID: 341190944034978748, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
32843308
propertyPath: m_AnchoredPosition.x
3285-
value: 354.84
3309+
value: 0
32863310
objectReference: {fileID: 0}
32873311
- target: {fileID: 341190944034978748, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
32883312
propertyPath: m_AnchoredPosition.y
3289-
value: -15
3313+
value: 0
32903314
objectReference: {fileID: 0}
32913315
- target: {fileID: 341190944071593138, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
32923316
propertyPath: m_AnchorMax.x
@@ -3566,19 +3590,19 @@ PrefabInstance:
35663590
objectReference: {fileID: 0}
35673591
- target: {fileID: 341190944410943211, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
35683592
propertyPath: m_AnchorMax.y
3569-
value: 1
3593+
value: 0
35703594
objectReference: {fileID: 0}
35713595
- target: {fileID: 341190944410943211, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
35723596
propertyPath: m_AnchorMin.y
3573-
value: 1
3597+
value: 0
35743598
objectReference: {fileID: 0}
35753599
- target: {fileID: 341190944410943211, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
35763600
propertyPath: m_AnchoredPosition.x
3577-
value: 384.91998
3601+
value: 0
35783602
objectReference: {fileID: 0}
35793603
- target: {fileID: 341190944410943211, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
35803604
propertyPath: m_AnchoredPosition.y
3581-
value: -15
3605+
value: 0
35823606
objectReference: {fileID: 0}
35833607
- target: {fileID: 341190944411999430, guid: 94cdeca105038d74ea47b57e6b99eb4e, type: 3}
35843608
propertyPath: m_AnchorMax.y

Assets/Scripts/Pinpoint/PinpointAtlasManager.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ public void SetNewTransform(AtlasTransform newTransform)
153153
// Check all probes for mis-matches
154154
foreach (ProbeManager probeManager in ProbeManager.Instances)
155155
probeManager.Update2ActiveTransform();
156-
157-
WarpBrain();
158156
}
159157

160158
private string ConverTransform2UserFriendly(string transformName)
@@ -188,9 +186,12 @@ public void WarpBrain()
188186

189187
foreach (OntologyNode node in DefaultNodes)
190188
WarpNode(node, WorldU2WorldT_Wrapper);
189+
190+
foreach (int areaID in TP_Search.VisibleSearchedAreas)
191+
WarpNode(BrainAtlasManager.ActiveReferenceAtlas.Ontology.ID2Node(areaID), WorldU2WorldT_Wrapper);
191192
}
192193

193-
public void WarpNode(OntologyNode node, Func<Vector3, Vector3> warpFunction)
194+
public static void WarpNode(OntologyNode node, Func<Vector3, Vector3> warpFunction)
194195
{
195196
node.ApplyAtlasTransform(warpFunction);
196197
}
@@ -203,7 +204,7 @@ public void UnwarpBrain()
203204
}
204205
}
205206

206-
private Vector3 WorldU2WorldT_Wrapper(Vector3 input)
207+
public static Vector3 WorldU2WorldT_Wrapper(Vector3 input)
207208
{
208209
return BrainAtlasManager.WorldU2WorldT(input, true);
209210
}

Assets/Scripts/Pinpoint/Probes/Controllers/CartesianProbeController.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ public override void SetProbePosition()
769769
_depth = 0f;
770770
}
771771

772+
SetTipWorldU();
773+
772774
// update surface position
773775
ProbeManager.UpdateSurfacePosition();
774776

@@ -800,20 +802,29 @@ public override void SetProbeAngles(Vector3 angles)
800802

801803
#region Getters
802804

805+
private Vector3 _tipCoordWorldU;
806+
private Vector3 _tipRightWorldU;
807+
private Vector3 _tipUpWorldU;
808+
private Vector3 _tipForwardWorldU;
809+
810+
private void SetTipWorldU()
811+
{
812+
// Note: we need to use the reference coordinates here so that the world positions resolve to (0,0,0) at Bregma,
813+
// otherwise any rotations that get applied will be incorrect
814+
_tipCoordWorldU = BrainAtlasManager.WorldT2WorldU(_probeTipT.position, true);
815+
_tipRightWorldU = (BrainAtlasManager.WorldT2WorldU(_probeTipT.position + _probeTipT.right, true) - _tipCoordWorldU).normalized;
816+
_tipUpWorldU = (BrainAtlasManager.WorldT2WorldU(_probeTipT.position + _probeTipT.up, true) - _tipCoordWorldU).normalized;
817+
_tipForwardWorldU = (BrainAtlasManager.WorldT2WorldU(_probeTipT.position + _probeTipT.forward, true) - _tipCoordWorldU).normalized;
818+
}
819+
803820
/// <summary>
804821
/// Return the tip coordinates and vectors in **un-transformed** world coordinates
805822
/// </summary>
806823
/// <returns></returns>
807824
public override (Vector3 tipCoordWorldU, Vector3 tipRightWorldU, Vector3 tipUpWorldU, Vector3 tipForwardWorldU) GetTipWorldU()
808825
{
809-
// Note: we need to use the reference coordinates here so that the world positions resolve to (0,0,0) at Bregma,
810-
// otherwise any rotations that get applied will be incorrect
811-
Vector3 tipCoordWorldU = BrainAtlasManager.WorldT2WorldU(_probeTipT.position, true);
812-
Vector3 tipRightWorldU = (BrainAtlasManager.WorldT2WorldU(_probeTipT.position + _probeTipT.right, true) - tipCoordWorldU).normalized;
813-
Vector3 tipUpWorldU = (BrainAtlasManager.WorldT2WorldU(_probeTipT.position + _probeTipT.up, true) - tipCoordWorldU).normalized;
814-
Vector3 tipForwardWorldU = (BrainAtlasManager.WorldT2WorldU(_probeTipT.position + _probeTipT.forward, true) - tipCoordWorldU).normalized;
815826

816-
return (tipCoordWorldU, tipRightWorldU, tipUpWorldU, tipForwardWorldU);
827+
return (_tipCoordWorldU, _tipRightWorldU, _tipUpWorldU, _tipForwardWorldU);
817828
}
818829
#endregion
819830

Assets/Scripts/Pinpoint/Probes/ProbeController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ public void Register(ProbeManager probeManager)
5757
/// <param name="transform"></param>
5858
public void SetSpaceTransform(CoordinateSpace atlas, CoordinateTransform transform)
5959
{
60+
Debug.Log($"Setting new transform to: {transform.Name}");
61+
Debug.Log(Insertion.APMLDV);
6062
// Covnert the tip coordinate into the new space
6163
var tipData = GetTipWorldU();
64+
Debug.Log(tipData.tipCoordWorldU);
6265
Vector3 tipCoordNewSpace = transform.U2T(atlas.World2Space(tipData.tipCoordWorldU));
66+
Debug.Log(tipCoordNewSpace);
6367
Insertion.APMLDV = tipCoordNewSpace;
6468
// Set the transforms
6569
Insertion.AtlasName = atlas.Name;

Assets/Scripts/Pinpoint/TP_Search.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class TP_Search : MonoBehaviour
1818
[FormerlySerializedAs("maxAreaPanels")][SerializeField] int _maxAreaPanels = 1;
1919

2020
private List<GameObject> localAreaPanels;
21-
public List<int> VisibleSearchedAreas { get; private set; }
21+
public static List<int> VisibleSearchedAreas { get; private set; }
2222

2323
private const int ACRONYM_FONT_SIZE = 24;
2424
private const int FULL_FONT_SIZE = 14;
@@ -154,6 +154,8 @@ public async void SelectBrainArea(int targetAreaID)
154154
node.SetMaterial(BrainAtlasManager.BrainRegionMaterials["opaque-lit"], OntologyNode.OntologyNodeSide.Left);
155155
node.SetMaterial(BrainAtlasManager.BrainRegionMaterials["opaque-lit"], OntologyNode.OntologyNodeSide.Right);
156156
node.ResetColor();
157+
158+
PinpointAtlasManager.WarpNode(node, PinpointAtlasManager.WorldU2WorldT_Wrapper);
157159
}
158160
VisibleSearchedAreas.Add(targetAreaID);
159161
}

Assets/Scripts/Pinpoint/TrajectoryPlannerManager.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public void SetGhostAreaVisibility()
648648
{
649649
if (Settings.GhostInactiveAreas)
650650
{
651-
List<int> activeAreas = _searchControl.VisibleSearchedAreas;
651+
List<int> activeAreas = TP_Search.VisibleSearchedAreas;
652652
List<OntologyNode> activeNodes = activeAreas.ConvertAll(x => BrainAtlasManager.ActiveReferenceAtlas.Ontology.ID2Node(x));
653653

654654
foreach (OntologyNode node in _pinpointAtlasManager.DefaultNodes)
@@ -956,17 +956,23 @@ public void SetProbeTipPosition2AreaID(int atlasID)
956956
if (ProbeManager.ActiveProbeManager == null) return;
957957
(Vector3 leftCoordU, Vector3 rightCoordU) = BrainAtlasManager.ActiveReferenceAtlas.MeshCenters[atlasID];
958958

959+
Vector3 dims = BrainAtlasManager.ActiveReferenceAtlas.Dimensions;
960+
961+
// coordinates are really broken right now, the right coordinate is the left, and the left is just missing
962+
leftCoordU = rightCoordU;
963+
rightCoordU.y = dims.y/ 2f + dims.y/2f - rightCoordU.y;
959964

960965
// switch to right side if needed
961966
if (atlasID == prevTipID)
962967
prevTipSideLeft = !prevTipSideLeft;
968+
else
969+
prevTipSideLeft = true; // always start on left
963970

964971
// transform the coordinate
965-
972+
966973
Vector3 coordT = BrainAtlasManager.ActiveAtlasTransform.U2T(
967974
(prevTipSideLeft ? leftCoordU : rightCoordU) - BrainAtlasManager.ActiveReferenceAtlas.AtlasSpace.ReferenceCoord);
968975

969-
Debug.Log(coordT);
970976
ProbeManager.ActiveProbeManager.ProbeController.SetProbePosition(coordT);
971977

972978
prevTipID = atlasID;

0 commit comments

Comments
 (0)