Skip to content

Commit bf6b0b1

Browse files
committed
fix: changing Ephys Link references back to CoordinateSpace/CoordinateTransform
1 parent f19d16d commit bf6b0b1

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

Assets/Scripts/Pinpoint/Probes/ManipulatorBehaviorController.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Linq;
44
using BrainAtlas;
55
using BrainAtlas.CoordinateSystems;
6+
using CoordinateSpaces;
7+
using CoordinateTransforms;
68
using EphysLink;
79
using UnityEngine;
810
using UnityEngine.Events;
@@ -47,21 +49,21 @@ private void EchoPosition(Vector4 pos)
4749

4850
// Convert to coordinate space
4951
var manipulatorSpacePosition =
50-
AtlasTransform.T2U(zeroCoordinateAdjustedManipulatorPosition);
52+
CoordinateTransform.T2U(zeroCoordinateAdjustedManipulatorPosition);
5153

5254
// Brain surface adjustment
5355
// FIXME: Dependent on CoordinateSpace direction. Should be standardized by Ephys Link.
5456
var brainSurfaceAdjustment = float.IsNaN(BrainSurfaceOffset) ? 0 : BrainSurfaceOffset;
5557
if (IsSetToDropToSurfaceWithDepth)
5658
zeroCoordinateAdjustedManipulatorPosition.w +=
57-
ReferenceAtlas.World2Atlas_Vector(Vector3.down).z * brainSurfaceAdjustment;
59+
CoordinateSpace.World2Space_Vector(Vector3.down).z * brainSurfaceAdjustment;
5860
else
5961
manipulatorSpacePosition.z +=
60-
ReferenceAtlas.World2Atlas_Vector(Vector3.down).z * brainSurfaceAdjustment;
62+
CoordinateSpace.World2Space_Vector(Vector3.down).z * brainSurfaceAdjustment;
6163

6264
// Convert to world space
6365
var zeroCoordinateAdjustedWorldPosition =
64-
ReferenceAtlas.Atlas2World(manipulatorSpacePosition);
66+
CoordinateSpace.Space2World(manipulatorSpacePosition);
6567

6668
// Set probe position (change axes to match probe)
6769
var transformedApmldv =
@@ -189,8 +191,8 @@ public bool IsSetToDropToSurfaceWithDepth
189191
}
190192
}
191193

192-
public ReferenceAtlas ReferenceAtlas { get; private set; }
193-
private AtlasTransform AtlasTransform { get; set; }
194+
public CoordinateSpace CoordinateSpace { get; private set; }
195+
private CoordinateTransform CoordinateTransform { get; set; }
194196

195197
public bool IsRightHanded
196198
{
@@ -275,15 +277,15 @@ public void UpdateSpaceAndTransform()
275277
{
276278
if (ManipulatorType == "sensapex")
277279
{
278-
ReferenceAtlas = new SensapexSpace();
279-
AtlasTransform = IsRightHanded
280+
CoordinateSpace = new SensapexSpace();
281+
CoordinateTransform = IsRightHanded
280282
? new SensapexRightTransform(_probeController.Insertion.Yaw)
281283
: new SensapexLeftTransform(_probeController.Insertion.Yaw);
282284
}
283285
else
284286
{
285-
ReferenceAtlas = new NewScaleSpace();
286-
AtlasTransform = new NewScaleLeftTransform(_probeController.Insertion.Yaw,
287+
CoordinateSpace = new NewScaleSpace();
288+
CoordinateTransform = new NewScaleLeftTransform(_probeController.Insertion.Yaw,
287289
_probeController.Insertion.Pitch);
288290
}
289291
}
@@ -295,9 +297,9 @@ public Vector4 ConvertInsertionToManipulatorPosition(Vector3 insertionAPMLDV)
295297

296298
// Convert to Sensapex space
297299
var posInManipulatorSpace =
298-
_probeManager.ManipulatorBehaviorController.ReferenceAtlas.World2Atlas(convertToWorld);
300+
_probeManager.ManipulatorBehaviorController.CoordinateSpace.World2Space(convertToWorld);
299301
Vector4 posInManipulatorTransform =
300-
_probeManager.ManipulatorBehaviorController.AtlasTransform.U2T(posInManipulatorSpace);
302+
_probeManager.ManipulatorBehaviorController.CoordinateTransform.U2T(posInManipulatorSpace);
301303

302304
// Apply brain surface offset
303305
var brainSurfaceAdjustment = float.IsNaN(_probeManager.ManipulatorBehaviorController.BrainSurfaceOffset)
@@ -367,10 +369,10 @@ public void MoveByWorldSpaceDelta(Vector4 worldSpaceDelta, Action<bool> onSucces
367369
Action<string> onErrorCallback = null)
368370
{
369371
// Convert to manipulator axes (world -> space -> transform)
370-
var manipulatorSpaceDelta = ReferenceAtlas.World2Atlas_Vector(worldSpaceDelta);
371-
var manipulatorTransformDelta = AtlasTransform.U2T(manipulatorSpaceDelta);
372-
var manipulatorSpaceDepth = ReferenceAtlas
373-
.World2Atlas_Vector(Vector3.down).z * worldSpaceDelta.w;
372+
var manipulatorSpaceDelta = CoordinateSpace.World2Space_Vector(worldSpaceDelta);
373+
var manipulatorTransformDelta = CoordinateTransform.U2T(manipulatorSpaceDelta);
374+
var manipulatorSpaceDepth = CoordinateSpace
375+
.World2Space_Vector(Vector3.down).z * worldSpaceDelta.w;
374376

375377
// Get manipulator position
376378
CommunicationManager.Instance.GetPos(ManipulatorID, pos =>

Assets/Scripts/Pinpoint/UI/EphysCopilot/DrivePanelHandler.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ public void Drive()
195195
var driveDepth = _duraDepth;
196196
if (Mathf.Abs(_duraDepth - _targetDepth) > NEAR_TARGET_DISTANCE)
197197
driveDepth = _targetDepth - ProbeManager.ManipulatorBehaviorController
198-
.ReferenceAtlas
199-
.World2Atlas_Vector(Vector3.down).z *
198+
.CoordinateSpace
199+
.World2Space_Vector(Vector3.down).z *
200200
NEAR_TARGET_DISTANCE;
201201

202202
// Drive until within near target distance
@@ -209,8 +209,8 @@ public void Drive()
209209
CommunicationManager.Instance.DriveToDepth(
210210
ProbeManager.ManipulatorBehaviorController.ManipulatorID,
211211
_targetDepth +
212-
ProbeManager.ManipulatorBehaviorController.ReferenceAtlas
213-
.World2Atlas_Vector(Vector3.down).z * _drivePastTargetDistance,
212+
ProbeManager.ManipulatorBehaviorController.CoordinateSpace
213+
.World2Space_Vector(Vector3.down).z * _drivePastTargetDistance,
214214
_targetDriveSpeed * NEAR_TARGET_SPEED_MULTIPLIER,
215215
_ =>
216216
{
@@ -249,8 +249,8 @@ public void DriveBackToSurface()
249249
if (Mathf.Abs(_duraDepth - _targetDepth) > NEAR_TARGET_DISTANCE)
250250
driveDepth = _targetDepth -
251251
ProbeManager.ManipulatorBehaviorController
252-
.ReferenceAtlas
253-
.World2Atlas_Vector(Vector3.down).z *
252+
.CoordinateSpace
253+
.World2Space_Vector(Vector3.down).z *
254254
NEAR_TARGET_DISTANCE;
255255

256256
// Drive back to dura by near target distance (as much as possible)
@@ -266,8 +266,8 @@ public void DriveBackToSurface()
266266
// FIXME: Dependent on CoordinateSpace direction. Should be standardized by Ephys Link.
267267
CommunicationManager.Instance.DriveToDepth(
268268
ProbeManager.ManipulatorBehaviorController.ManipulatorID,
269-
_duraDepth - ProbeManager.ManipulatorBehaviorController.ReferenceAtlas
270-
.World2Atlas_Vector(Vector3.up).z * DURA_MARGIN_DISTANCE,
269+
_duraDepth - ProbeManager.ManipulatorBehaviorController.CoordinateSpace
270+
.World2Space_Vector(Vector3.up).z * DURA_MARGIN_DISTANCE,
271271
_exitDriveSpeed, _ =>
272272
{
273273
// Drive the rest of the way to the surface
@@ -379,15 +379,15 @@ private void ComputeAndSetDriveTime(float driveSpeed, Action callback = null)
379379

380380
// Set target and exit depths
381381
_targetDepth = position.w +
382-
ProbeManager.ManipulatorBehaviorController.ReferenceAtlas
383-
.World2Atlas_Vector(Vector3.down).z * targetDriveDistance;
382+
ProbeManager.ManipulatorBehaviorController.CoordinateSpace
383+
.World2Space_Vector(Vector3.down).z * targetDriveDistance;
384384
_exitDepth = position.w +
385-
ProbeManager.ManipulatorBehaviorController.ReferenceAtlas
386-
.World2Atlas_Vector(Vector3.up).z * surfaceDriveDistance;
385+
ProbeManager.ManipulatorBehaviorController.CoordinateSpace
386+
.World2Space_Vector(Vector3.up).z * surfaceDriveDistance;
387387

388388
// Warn if target depth is out of bounds
389389
if (!_acknowledgeOutOfBounds &&
390-
(_targetDepth > ProbeManager.ManipulatorBehaviorController.ReferenceAtlas.Dimensions.z ||
390+
(_targetDepth > ProbeManager.ManipulatorBehaviorController.CoordinateSpace.Dimensions.z ||
391391
_targetDepth < 0))
392392
{
393393
QuestionDialogue.Instance.NewQuestion(

0 commit comments

Comments
 (0)