Skip to content

Commit

Permalink
fix: fixing bug in surface calculation code
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Nov 30, 2023
1 parent 746d00f commit 00421b9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
50 changes: 27 additions & 23 deletions Assets/Scripts/Pinpoint/Probes/ProbeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -770,12 +770,12 @@ public void DropProbeToBrainSurface()
return;
}

Vector3 worldU = BrainAtlasManager.ActiveReferenceAtlas.AtlasIdx2World(entryCoordAtlasIdx);
Vector3 entryCoordAtlasT = BrainAtlasManager.WorldU2WorldT(worldU);
//Vector3 worldU = BrainAtlasManager.ActiveReferenceAtlas.AtlasIdx2World(entryCoordAtlasIdx);
//Vector3 entryCoordAtlasT = BrainAtlasManager.WorldU2WorldT(worldU);

//var entryCoordAtlasT = BrainAtlasManager.ActiveAtlasTransform.U2T(
// BrainAtlasManager.ActiveReferenceAtlas.World2Atlas(
// BrainAtlasManager.ActiveReferenceAtlas.AtlasIdx2World(entryCoordAtlasIdx)));
var entryCoordAtlasT = BrainAtlasManager.ActiveAtlasTransform.U2T(
BrainAtlasManager.ActiveReferenceAtlas.World2Atlas(
BrainAtlasManager.ActiveReferenceAtlas.AtlasIdx2World(entryCoordAtlasIdx)));

_probeController.SetProbePosition(entryCoordAtlasT);
}
Expand Down Expand Up @@ -820,38 +820,42 @@ public void UpdateSurfacePosition()
(Vector3 tipCoordWorldU, _, _, Vector3 tipForwardWorldU) = _probeController.GetTipWorldU();

Vector3 tipAtlasIdxU = BrainAtlasManager.ActiveReferenceAtlas.World2AtlasIdx(tipCoordWorldU);

Vector3 downDir = useDV ? Vector3.down : tipForwardWorldU;
Vector3 downDirAtlas = BrainAtlasManager.ActiveReferenceAtlas.World2Atlas_Vector(downDir);
Debug.Log(downDirAtlas);

// Check if we're in the brain
bool probeInBrain = BrainAtlasManager.ActiveReferenceAtlas.GetAnnotationIdx(tipAtlasIdxU) > 0;

Vector3 tipInBrain = tipAtlasIdxU;

// Adjust the tip coordinate to put it into the brain
// This is kind of a dumb algorithm, we
if (!probeInBrain)
{
// Get which direction we need to go
(int ap, int ml, int dv) = BrainAtlasManager.ActiveReferenceAtlas.DimensionsIdx;
Vector3 center = new Vector3(ap, ml, dv) / 2f;

Vector3 towardBox = downDirAtlas;

// Invert if the vector points the wrong way
if (Vector3.Dot(downDirAtlas, tipAtlasIdxU - center) > 0)
towardBox = -towardBox;

// Step in 1mm increments
float stepSize = 1000f / BrainAtlasManager.ActiveReferenceAtlas.Resolution.z;

bool done = false;
float[] offset = { +1000f, -1000f };
for (int mult = 1; mult <= 16; mult *= 2)
for (int steps = 1; steps < Mathf.RoundToInt(BrainAtlasManager.ActiveReferenceAtlas.Dimensions.z*2f); steps++)
{
for (int i = 0; i < 2; i++)
Vector3 tempTip = tipAtlasIdxU + towardBox * stepSize * steps;
if (BrainAtlasManager.ActiveReferenceAtlas.GetAnnotationIdx(tempTip) > 0)
{
Vector3 temporaryTip = tipAtlasIdxU + downDirAtlas * offset[i] * mult / BrainAtlasManager.ActiveReferenceAtlas.Resolution.z;
Debug.Log(temporaryTip);
if (BrainAtlasManager.ActiveReferenceAtlas.GetAnnotationIdx(temporaryTip) > 0)
{
tipInBrain = temporaryTip;
Debug.Log(tipInBrain);
done = true;
break;
}
}

if (done)
tipInBrain = tempTip;
done = true;
break;
}
}

if (!done)
Expand Down Expand Up @@ -901,7 +905,7 @@ public Vector3 FindEntryIdxCoordinate(Vector3 bottomIdxCoordU, Vector3 downVecto

if (finalPerc > -1f)
{
for (float perc = finalPerc; perc >= 0f; perc -= 0.0001f)
for (float perc = finalPerc; perc >= 0f; perc -= 0.001f)
{
Vector3 point = Vector3.Lerp(topSearchIdxCoordU, bottomIdxCoordU, perc);
if (BrainAtlasManager.ActiveReferenceAtlas.GetAnnotationIdx(point) <= 0)
Expand Down
4 changes: 2 additions & 2 deletions Library/com.unity.addressables/AddressablesBuildTEP.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"Date": "11/29/2023 9:37:56 PM",
"Date": "11/29/2023 10:12:58 PM",
"UnityVersion": "2022.3.12f1",
"com.unity.scriptablebuildpipeline": "1.21.20",
"com.unity.addressables": "1.21.18",
"traceEvents": [
{"name": "Building Use Existing Build (requires built groups)", "ph": "X", "dur": 2142.2, "tid": 1, "ts": 1562, "pid": 1}
{"name": "Building Use Existing Build (requires built groups)", "ph": "X", "dur": 4539.3, "tid": 1, "ts": 1624, "pid": 1}
]
}

0 comments on commit 00421b9

Please sign in to comment.