Skip to content

Commit 028906c

Browse files
committed
feat: re-enabling disabled ephys link code
1 parent 6811050 commit 028906c

File tree

4 files changed

+52
-50
lines changed

4 files changed

+52
-50
lines changed

Assets/Scripts/EphysLink/trajectoryplanner.ephyslink.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"trajectoryplanner.core.utilities",
77
"vbl.brainatlas.runtime",
88
"vbl.brainatlas.atlas",
9-
"vbl.brainatlas.coordsystems"
9+
"vbl.brainatlas.coordsystems",
10+
"vblcore.coordinates"
1011
],
1112
"includePlatforms": [],
1213
"excludePlatforms": [],

Assets/Scripts/Pinpoint/Probes/ManipulatorBehaviorController.cs

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using EphysLink;
77
using UnityEngine;
88
using UnityEngine.Events;
9+
using Urchin.Utils;
910

1011
namespace TrajectoryPlanner.Probes
1112
{
@@ -272,20 +273,19 @@ void StartEchoing()
272273

273274
public void UpdateSpaceAndTransform()
274275
{
275-
throw new NotImplementedException();
276-
//if (ManipulatorType == "sensapex")
277-
//{
278-
// CoordinateSpace = new SensapexSpace();
279-
// Transform = IsRightHanded
280-
// ? new SensapexRightTransform(_probeController.Insertion.Yaw)
281-
// : new SensapexLeftTransform(_probeController.Insertion.Yaw);
282-
//}
283-
//else
284-
//{
285-
// CoordinateSpace = new NewScaleSpace();
286-
// Transform = new NewScaleLeftTransform(_probeController.Insertion.Yaw,
287-
// _probeController.Insertion.Pitch);
288-
//}
276+
if (ManipulatorType == "sensapex")
277+
{
278+
ReferenceAtlas = new SensapexSpace();
279+
AtlasTransform = IsRightHanded
280+
? new SensapexRightTransform(_probeController.Insertion.Yaw)
281+
: new SensapexLeftTransform(_probeController.Insertion.Yaw);
282+
}
283+
else
284+
{
285+
ReferenceAtlas = new NewScaleSpace();
286+
AtlasTransform = new NewScaleLeftTransform(_probeController.Insertion.Yaw,
287+
_probeController.Insertion.Pitch);
288+
}
289289
}
290290

291291
public Vector4 ConvertInsertionToManipulatorPosition(Vector3 insertionAPMLDV)
@@ -317,36 +317,35 @@ public Vector4 ConvertInsertionToManipulatorPosition(Vector3 insertionAPMLDV)
317317
/// </summary>
318318
public void ComputeBrainSurfaceOffset()
319319
{
320-
throw new NotImplementedException();
321-
//if (_probeManager.IsProbeInBrain())
322-
//{
323-
// // Just calculate the distance from the probe tip position to the brain surface
324-
// BrainSurfaceOffset -= _probeManager.GetSurfaceCoordinateT().depthT;
325-
//}
326-
//else
327-
//{
328-
// // We need to calculate the surface coordinate ourselves
329-
// var tipExtensionDirection =
330-
// IsSetToDropToSurfaceWithDepth ? _probeController.GetTipWorldU().tipUpWorldU : Vector3.up;
331-
332-
// var brainSurfaceCoordinate = _annotationDataset.FindSurfaceCoordinate(
333-
// _annotationDataset.CoordinateSpace.World2Space(_probeController.GetTipWorldU().tipCoordWorldU -
334-
// tipExtensionDirection * 5),
335-
// _annotationDataset.CoordinateSpace.World2Space_Vector(tipExtensionDirection));
336-
337-
// if (float.IsNaN(brainSurfaceCoordinate.x))
338-
// {
339-
// Debug.LogWarning("Could not find brain surface! Canceling set brain offset.");
340-
// return;
341-
// }
342-
343-
// var brainSurfaceToTransformed =
344-
// _probeController.Insertion.World2Transformed(
345-
// _annotationDataset.CoordinateSpace.Space2World(brainSurfaceCoordinate));
346-
347-
// BrainSurfaceOffset += Vector3.Distance(brainSurfaceToTransformed,
348-
// _probeController.Insertion.apmldv);
349-
//}
320+
if (_probeManager.IsProbeInBrain())
321+
{
322+
// Just calculate the distance from the probe tip position to the brain surface
323+
BrainSurfaceOffset -= _probeManager.GetSurfaceCoordinateT().depthT;
324+
}
325+
else
326+
{
327+
// We need to calculate the surface coordinate ourselves
328+
var tipExtensionDirection =
329+
IsSetToDropToSurfaceWithDepth ? _probeController.GetTipWorldU().tipUpWorldU : Vector3.up;
330+
331+
var brainSurfaceIdxCoordU = _probeManager.FindSurfaceIdxCoordinate(
332+
BrainAtlasManager.ActiveReferenceAtlas.World2AtlasIdx(_probeController.GetTipWorldU().tipCoordWorldU -
333+
tipExtensionDirection * 5),
334+
BrainAtlasManager.ActiveReferenceAtlas.World2Atlas_Vector(tipExtensionDirection));
335+
336+
if (float.IsNaN(brainSurfaceIdxCoordU.x))
337+
{
338+
Debug.LogWarning("Could not find brain surface! Canceling set brain offset.");
339+
return;
340+
}
341+
342+
var brainSurfaceToTransformed =
343+
_probeController.Insertion.World2T(
344+
BrainAtlasManager.ActiveReferenceAtlas.World2AtlasIdx(brainSurfaceIdxCoordU));
345+
346+
BrainSurfaceOffset += Vector3.Distance(brainSurfaceToTransformed,
347+
_probeController.Insertion.apmldv);
348+
}
350349
}
351350

352351
/// <summary>

Assets/Scripts/Pinpoint/TrajectoryPlannerManager.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ public async void Startup()
180180
}
181181
Settings.ReferenceCoord = referenceAtlas.AtlasSpace.ReferenceCoord;
182182

183-
// Now that the scene is loaded we can also set the BLDistance values
184-
SetBLUI();
185-
186183
// there is only one default set right now, tbd if we want to add others (beryl/cosmos/etc)
187184
var nodeTask = _atlasManager.LoadDefaultAreas("");
188185

@@ -202,6 +199,11 @@ public async void Startup()
202199
_pinpointAtlasManager.DefaultNodes.Add(node);
203200
}
204201

202+
// Now that the areas are loaded we can also set the BLDistance values
203+
SetBLUI();
204+
if (Settings.BregmaLambdaDistance > 0f)
205+
ChangeBLDistance(Settings.BregmaLambdaDistance);
206+
205207
StartupEvent_RefAtlasLoaded.Invoke();
206208
StartupEvent_AnnotationTextureLoaded.Invoke(BrainAtlasManager.ActiveReferenceAtlas.AnnotationTexture);
207209

@@ -1028,7 +1030,7 @@ public void SetBLUI()
10281030
/// <param name="newBLDistance"></param>
10291031
public void ChangeBLDistance(float newBLDistance)
10301032
{
1031-
if (BrainAtlasManager.ActiveReferenceAtlas == null)
1033+
if (BrainAtlasManager.ActiveReferenceAtlas == null || newBLDistance == _blDistance.DefaultBLDistance)
10321034
return;
10331035

10341036
float blRatio = newBLDistance / _blDistance.DefaultBLDistance;

Assets/Scripts/Pinpoint/Utilities/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public static string AtlasTransformName
341341
}
342342
}
343343

344-
private const float BREGMALAMBDA_DEFAULT = 4.15f;
344+
private const float BREGMALAMBDA_DEFAULT = -1f;
345345
[SerializeField] private Slider _blSlider;
346346
public UnityEvent<float> BregmaLambdaChangedEvent;
347347

0 commit comments

Comments
 (0)