@@ -109,7 +109,7 @@ public class TrajectoryPlannerManager : MonoBehaviour
109109 // Local tracking variables
110110 private bool _movedThisFrame ;
111111
112- private const string SCENE_RESET_KEY = "scene-rest " ;
112+ private const string SCENE_NOT_RESET = "scene-not-reset " ;
113113 private bool _sceneWasReset ;
114114
115115 // Track who got clicked on, probe, camera, or brain
@@ -151,31 +151,39 @@ private void Awake()
151151
152152 public async void Startup ( )
153153 {
154- // Clear the "Reset" PlayerPrefs flag
155- _sceneWasReset = PlayerPrefs . GetInt ( SCENE_RESET_KEY , 0 ) == 1 ;
154+ // Determine startup flags, we check two things:
155+ // (1) Are the PlayerPrefs cleared? If they are, we will load the null transform and bregma reference coordinate
156+ // (2) If set, check if this is an atlas reset, if it is, load the null transform and bregma reference coordinate
157+ // Otherwise, load all the previous settings
158+ bool _firstTime = ! PlayerPrefs . HasKey ( "scene-atlas-reset" ) ;
159+ bool _atlasReset = PlayerPrefs . GetInt ( "scene-atlas-reset" , 0 ) == 1 ;
156160
157161 // STARTUP SEQUENCE
158162 StartupEvent_MetaLoaded . Invoke ( ) ;
159163
160- // Startup CCF
164+ // Load Atlas
165+ // Settings.AtlasName returns CCF if PlayerPrefs is cleared, otherwise returns the previous atlas setting
161166 await BrainAtlasManager . LoadAtlas ( Settings . AtlasName ) ;
162167 ReferenceAtlas referenceAtlas = BrainAtlasManager . ActiveReferenceAtlas ;
163168
164169 // Set the reference coordinate before anything else happen
165- // if the scene was reset we should use the default coordinates
166- if ( _sceneWasReset )
170+ // if this is the first time, load bregma
171+ Debug . Log ( ( _firstTime , _atlasReset ) ) ;
172+ if ( _firstTime || _atlasReset )
167173 {
168174 if ( Utils . BregmaDefaults . ContainsKey ( Settings . AtlasName ) )
169175 referenceAtlas . AtlasSpace . ReferenceCoord = Utils . BregmaDefaults [ Settings . AtlasName ] ;
170- else
171- referenceAtlas . AtlasSpace . ReferenceCoord = Vector3 . zero ;
172- Settings . ReferenceCoord = referenceAtlas . AtlasSpace . ReferenceCoord ;
173176 }
174177 else
175178 {
176179 referenceAtlas . AtlasSpace . ReferenceCoord = Settings . ReferenceCoord ;
177180 }
181+ Settings . ReferenceCoord = referenceAtlas . AtlasSpace . ReferenceCoord ;
182+
183+ // Now that the scene is loaded we can also set the BLDistance values
184+ SetBLUI ( ) ;
178185
186+ // there is only one default set right now, tbd if we want to add others (beryl/cosmos/etc)
179187 var nodeTask = _atlasManager . LoadDefaultAreas ( "" ) ;
180188
181189 referenceAtlas . LoadAnnotations ( ) ;
@@ -207,7 +215,7 @@ public async void Startup()
207215 ProbeManager . ActiveProbeUIUpdateEvent . AddListener ( ( ) => SetSurfaceDebugColor ( ProbeManager . ActiveProbeManager . Color ) ) ;
208216
209217 // Complete
210- PlayerPrefs . SetInt ( SCENE_RESET_KEY , 0 ) ;
218+ PlayerPrefs . SetInt ( "scene-atlas-reset" , 0 ) ;
211219 StartupEvent_Complete . Invoke ( ) ;
212220
213221 // After annotation loads, check if the user wants to load previously used probes
@@ -446,8 +454,6 @@ public ProbeManager AddNewProbe(ProbeProperties.ProbeType probeType, ProbeInsert
446454
447455 probeManager . ProbeController . SetProbePosition ( insertion . apmldv ) ;
448456 probeManager . ProbeController . SetProbeAngles ( insertion . angles ) ;
449- // [TODO]
450- //probeManager.ProbeController.SetSpaceTransform(insertion.ReferenceAtlas, insertion.AtlasTransform);
451457
452458 return probeManager ;
453459 }
@@ -459,8 +465,6 @@ public ProbeManager AddNewProbe(ProbeProperties.ProbeType probeType, ProbeInsert
459465
460466 probeManager . ProbeController . SetProbePosition ( insertion . apmldv ) ;
461467 probeManager . ProbeController . SetProbeAngles ( insertion . angles ) ;
462- // [TODO]
463- //probeManager.ProbeController.SetSpaceTransform(insertion.ReferenceAtlas, insertion.AtlasTransform);
464468
465469 // Return data if there is no current Ephys Link data
466470 if ( Settings . IsEphysLinkDataExpired ( ) ) return probeManager ;
@@ -471,8 +475,7 @@ public ProbeManager AddNewProbe(ProbeProperties.ProbeType probeType, ProbeInsert
471475 probeManager . ManipulatorBehaviorController . BrainSurfaceOffset = brainSurfaceOffset ;
472476 probeManager . ManipulatorBehaviorController . IsSetToDropToSurfaceWithDepth = dropToSurfaceWithDepth ;
473477 probeManager . ManipulatorBehaviorController . IsSetToDropToSurfaceWithDepth = dropToSurfaceWithDepth ;
474- // [TODO]
475- //probeManager.ManipulatorBehaviorController.IsRightHanded = isRightHanded;
478+ probeManager . ManipulatorBehaviorController . IsRightHanded = isRightHanded ;
476479 var communicationManager = GameObject . Find ( "EphysLink" ) . GetComponent < CommunicationManager > ( ) ;
477480
478481 if ( communicationManager . IsConnected && ! string . IsNullOrEmpty ( manipulatorId ) )
@@ -1007,54 +1010,68 @@ private void AccountsNewProbeHelper((Vector3 apmldv, Vector3 angles, int type, s
10071010
10081011 #region BLDistance
10091012
1013+ public void SetBLUI ( )
1014+ {
1015+ string atlasName = BrainAtlasManager . ActiveReferenceAtlas . Name ;
1016+ float defaultBLDistance = Utils . LambdaDefaults [ atlasName ] . x - Utils . BregmaDefaults [ atlasName ] . x ;
1017+ float min = Mathf . Max ( 0f , Mathf . FloorToInt ( defaultBLDistance / 2f ) ) ;
1018+ float max = Mathf . CeilToInt ( defaultBLDistance * 1.5f ) ;
1019+
1020+ _blDistance . SetBLRange ( min , max , defaultBLDistance ) ;
1021+ }
1022+
1023+ private CoordinateTransform _originalTransform ;
1024+
10101025 /// <summary>
10111026 /// Change the bregma-lamba distance. By default this is 4.15f, so if it isn't that value, then we need to add an isometric scaling to the current transform
10121027 /// </summary>
1013- /// <param name="blDistance "></param>
1014- public void ChangeBLDistance ( float blDistance )
1028+ /// <param name="newBLDistance "></param>
1029+ public void ChangeBLDistance ( float newBLDistance )
10151030 {
1016- // [TODO]
1031+ if ( BrainAtlasManager . ActiveReferenceAtlas == null )
1032+ return ;
10171033
1018- // float blRatio = blDistance / 4.15f;
1019- //#if UNITY_EDITOR
1020- // Debug.Log($"(BL Distance) Re-scaling to {blRatio}");
1021- //#endif
1034+ float blRatio = newBLDistance / _blDistance . DefaultBLDistance ;
10221035
1023- // if (CoordinateSpaceManager.ActiveCoordinateTransform.Name != "Custom")
1024- // CoordinateSpaceManager.OriginalTransform = CoordinateSpaceManager.ActiveCoordinateTransform;
1036+ #if UNITY_EDITOR
1037+ Debug . Log ( $ "(BL Distance) Re-scaling to { blRatio } ") ;
1038+ #endif
10251039
1026- // // There's no easy way to implement this without a refactor of the CoordinateTransform code, because you can't pull out the transform matrix.
1040+ if ( BrainAtlasManager . ActiveAtlasTransform . Name != "Custom" )
1041+ _originalTransform = BrainAtlasManager . ActiveAtlasTransform ;
10271042
1028- // // For now what we'll do is switch through the current transform, and replace it with a new version that's been scaled
1043+ // There's no easy way to implement this without a refactor of the CoordinateTransform code, because you can't pull out the transform matrix.
10291044
1030- // CoordinateTransform newTransform;
1045+ // For now what we'll do is switch through the current transform, and replace it with a new version that's been scaled
10311046
1032- // switch (CoordinateSpaceManager.OriginalTransform.Prefix)
1033- // {
1034- // case "ccf":
1035- // // the ccf transform is the unity transform, so just build a new affine transform that scales
1036- // newTransform = new CustomAffineTransform(blRatio * Vector3.one, Vector3.zero);
1037- // break;
1047+ AtlasTransform newTransform ;
10381048
1039- // case "q18":
1040- // newTransform = new CustomAffineTransform(blRatio * new Vector3(-1.031f, 0.952f, -0.885f), new Vector3(0f, -5f, 0f));
1041- // break;
1049+ switch ( _originalTransform . Prefix )
1050+ {
1051+ case "" :
1052+ // the null transform is the unity transform, so just build a new affine transform that scales
1053+ newTransform = new CustomAffineTransform ( blRatio * Vector3 . one , Vector3 . zero ) ;
1054+ break ;
10421055
1043- // case "d08 ":
1044- // newTransform = new CustomAffineTransform(blRatio * new Vector3(-1.087f, 1f , -0.952f ), new Vector3(0f, -5f, 0f));
1045- // break;
1056+ case "q18 " :
1057+ newTransform = new CustomAffineTransform ( blRatio * new Vector3 ( - 1.031f , 0.952f , - 0.885f ) , new Vector3 ( 0f , - 5f , 0f ) ) ;
1058+ break ;
10461059
1047- // case "i- d08":
1048- // newTransform = new CustomAffineTransform(blRatio * new Vector3(-1.087f, 1f, -0.952f), new Vector3(0f, 0f , 0f));
1049- // break;
1060+ case "d08" :
1061+ newTransform = new CustomAffineTransform ( blRatio * new Vector3 ( - 1.087f , 1f , - 0.952f ) , new Vector3 ( 0f , - 5f , 0f ) ) ;
1062+ break ;
10501063
1051- // default:
1052- // Debug.LogError("Previous transform is not scalable");
1053- // return;
1054- // }
1064+ case "i-d08" :
1065+ newTransform = new CustomAffineTransform ( blRatio * new Vector3 ( - 1.087f , 1f , - 0.952f ) , new Vector3 ( 0f , 0f , 0f ) ) ;
1066+ break ;
1067+
1068+ default :
1069+ Debug . LogError ( "Previous transform is not scalable" ) ;
1070+ return ;
1071+ }
10551072
1056- // // Apply the new transform
1057- // SetNewTransform(newTransform);
1073+ // Apply the new transform
1074+ _pinpointAtlasManager . SetNewTransform ( newTransform ) ;
10581075 }
10591076
10601077 #endregion
0 commit comments