Skip to content

Commit 1679424

Browse files
committed
Adding slice view features
Slice view now clips off the 3D models from the direction of the camera Suppressed warnings in some code files Fixed various bugs related to the sagittal/coronal slices
1 parent d366c14 commit 1679424

File tree

9 files changed

+97
-38
lines changed

9 files changed

+97
-38
lines changed

Assets/Scenes/TrajectoryPlanner.unity

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3084,7 +3084,7 @@ MonoBehaviour:
30843084
sagittalSliceGO: {fileID: 1490059538}
30853085
coronalSliceGO: {fileID: 175725874}
30863086
tpmanager: {fileID: 2108153954}
3087-
ccfModelControl: {fileID: 2108153952}
3087+
modelControl: {fileID: 2108153952}
30883088
localPrefs: {fileID: 2108153956}
30893089
--- !u!1 &385182333
30903090
GameObject:
@@ -3336,6 +3336,10 @@ PrefabInstance:
33363336
propertyPath: m_CastShadows
33373337
value: 1
33383338
objectReference: {fileID: 0}
3339+
- target: {fileID: 8102641116241020577, guid: 29e154cdc4333644089fccd61fe4987a, type: 3}
3340+
propertyPath: m_Materials.Array.data[0]
3341+
value:
3342+
objectReference: {fileID: 2100000, guid: b8a04b95bf5e0fe4dbdfd3978413393d, type: 2}
33393343
m_RemovedComponents: []
33403344
m_SourcePrefab: {fileID: 100100000, guid: 29e154cdc4333644089fccd61fe4987a, type: 3}
33413345
--- !u!4 &417839206 stripped

Assets/Scripts/BrainCameraController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public class BrainCameraController : MonoBehaviour
2626
// Start is called before the first frame update
2727
void Start()
2828
{
29+
// Artifically limit the framerate
30+
Application.targetFrameRate = 144;
31+
2932
initialCameraRotatorPosition = brainCameraRotator.transform.position;
3033
lastLeftClick = Time.realtimeSinceStartup;
3134
lastRightClick = Time.realtimeSinceStartup;

Assets/Scripts/ProbeController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ public void ManualCoordinateEntry(float ap, float ml, float depth, float phi, fl
340340
SetProbePosition(ap/1000, ml / 1000, depth / 1000, worldPhiTheta.x, worldPhiTheta.y, spin);
341341
UpdateSurfacePosition();
342342

343+
tpmanager.SetMovedThisFrame();
343344
foreach (ProbeUIManager puimanager in probeUIManagers)
344345
puimanager.ProbeMoved();
345346
}

Assets/Scripts/TP_PlayerPrefs.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,27 @@ void Start()
6565
}
6666
public void AsyncStart()
6767
{
68-
int probeCount = PlayerPrefs.GetInt("probecount", 0);
69-
70-
for (int i = 0; i < probeCount; i++)
71-
{
72-
float ap = PlayerPrefs.GetFloat("ap" + i);
73-
float ml = PlayerPrefs.GetFloat("ml" + i);
74-
float depth = PlayerPrefs.GetFloat("depth" + i);
75-
float phi = PlayerPrefs.GetFloat("phi" + i);
76-
float theta = PlayerPrefs.GetFloat("theta" + i);
77-
float spin = PlayerPrefs.GetFloat("spin" + i);
78-
int type = PlayerPrefs.GetInt("type" + i);
79-
80-
Debug.Log(ap);
81-
Debug.Log(ml);
82-
Debug.Log(depth);
83-
Debug.Log(phi);
84-
Debug.Log(theta);
85-
Debug.Log(spin);
86-
87-
tpmanager.AddNewProbe(type, ap, ml, depth, phi, theta, spin);
88-
}
68+
//int probeCount = PlayerPrefs.GetInt("probecount", 0);
69+
70+
//for (int i = 0; i < probeCount; i++)
71+
//{
72+
// float ap = PlayerPrefs.GetFloat("ap" + i);
73+
// float ml = PlayerPrefs.GetFloat("ml" + i);
74+
// float depth = PlayerPrefs.GetFloat("depth" + i);
75+
// float phi = PlayerPrefs.GetFloat("phi" + i);
76+
// float theta = PlayerPrefs.GetFloat("theta" + i);
77+
// float spin = PlayerPrefs.GetFloat("spin" + i);
78+
// int type = PlayerPrefs.GetInt("type" + i);
79+
80+
// Debug.Log(ap);
81+
// Debug.Log(ml);
82+
// Debug.Log(depth);
83+
// Debug.Log(phi);
84+
// Debug.Log(theta);
85+
// Debug.Log(spin);
86+
87+
// tpmanager.AddNewProbe(type, ap, ml, depth, phi, theta, spin);
88+
//}
8989
}
9090

9191
public void SetStereotaxic(bool state)

Assets/Scripts/TP_Search.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ public void ClickArea(GameObject target)
7878
else
7979
{
8080
if (!targetNode.IsLoaded())
81+
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
8182
targetNode.loadNodeModel(false, handle => {
8283
targetNode.SetNodeModelVisibility(true);
8384
modelControl.ChangeMaterial(targetNode, "lit");
8485
});
86+
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
8587
else
8688
{
8789
targetNode.SetNodeModelVisibility(true);

Assets/Scripts/TP_SliceRenderer.cs

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class TP_SliceRenderer : MonoBehaviour
77
[SerializeField] private GameObject sagittalSliceGO;
88
[SerializeField] private GameObject coronalSliceGO;
99
[SerializeField] private TrajectoryPlannerManager tpmanager;
10-
[SerializeField] private CCFModelControl ccfModelControl;
10+
[SerializeField] private CCFModelControl modelControl;
1111
[SerializeField] private TP_PlayerPrefs localPrefs;
1212

1313
private AnnotationDataset annotationDataset;
@@ -17,8 +17,10 @@ public class TP_SliceRenderer : MonoBehaviour
1717

1818
private Texture2D sagittalTex;
1919
private int mlIdx;
20+
private float trueML;
2021
private Texture2D coronalTex;
21-
private int apIdx = 0;
22+
private int apIdx;
23+
private float trueAP;
2224

2325
bool needToRender = false;
2426
bool loaded = false;
@@ -38,6 +40,8 @@ void Start()
3840
coronalTex.filterMode = FilterMode.Point;
3941
apIdx = Mathf.RoundToInt(baseSize[0] / 2);
4042
coronalSliceGO.GetComponent<Renderer>().material.mainTexture = coronalTex;
43+
44+
needToRender = localPrefs.GetSlice3D();
4145
}
4246

4347
public void AsyncStart()
@@ -49,8 +53,7 @@ public void AsyncStart()
4953

5054
private void Update()
5155
{
52-
53-
if (localPrefs.GetSlice3D())
56+
if (localPrefs.GetSlice3D() && loaded)
5457
{
5558
// Check if the camera moved such that we have to flip the slice quads
5659
needToRender = UpdateCameraPosition();
@@ -62,7 +65,11 @@ private void Update()
6265
needToRender = true;
6366
}
6467

65-
if (needToRender) RenderAnnotationLayer();
68+
if (needToRender)
69+
{
70+
RenderAnnotationLayer();
71+
UpdateNodeModelSlicing();
72+
}
6673
}
6774
}
6875

@@ -77,11 +84,42 @@ private void UpdateSlicePosition()
7784
Vector3 tipPosition = activeProbeTipT.position + activeProbeTipT.up * 0.2f; // add 200 um to get to the start of the recording region
7885

7986
float mlPosition = tipPosition.x;
87+
trueML = -(mlPosition - 5.7f);
8088
sagittalSliceGO.transform.position = new Vector3(mlPosition, 0f, 0f);
81-
mlIdx = Mathf.RoundToInt(-(mlPosition - 5.7f) * 40);
89+
mlIdx = Mathf.RoundToInt(trueML * 40);
8290
float apPosition = tipPosition.z;
91+
trueAP = apPosition + 6.6f;
8392
coronalSliceGO.transform.position = new Vector3(0f, 0f, apPosition);
84-
apIdx = Mathf.RoundToInt((apPosition + 6.6f) * 40);
93+
apIdx = Mathf.RoundToInt(trueAP * 40);
94+
}
95+
96+
private void UpdateNodeModelSlicing()
97+
{
98+
// Update the renderers on the node objects
99+
foreach (CCFTreeNode node in modelControl.DefaultLoadedNodes())
100+
{
101+
if (camYBack)
102+
// clip from apPosition forward
103+
node.SetShaderProperty("_APClip", new Vector2(0f, trueAP));
104+
else
105+
node.SetShaderProperty("_APClip", new Vector2(trueAP, 13.2f));
106+
107+
if (camXLeft)
108+
// clip from mlPosition forward
109+
node.SetShaderProperty("_MLClip", new Vector2(trueML, 11.4f));
110+
else
111+
node.SetShaderProperty("_MLClip", new Vector2(0f, trueML));
112+
}
113+
}
114+
115+
private void ClearNodeModelSlicing()
116+
{
117+
// Update the renderers on the node objects
118+
foreach (CCFTreeNode node in modelControl.DefaultLoadedNodes())
119+
{
120+
node.SetShaderProperty("_APClip", new Vector2(0f, 13.2f));
121+
node.SetShaderProperty("_MLClip", new Vector2(0f, 11.4f));
122+
}
85123
}
86124

87125
/// <summary>
@@ -116,7 +154,7 @@ private bool UpdateCameraPosition()
116154

117155
if (changed)
118156
{
119-
// Something changed, rotate and re-render the
157+
// Something changed, rotate and re-render the slices
120158
if (camXLeft)
121159
sagittalSliceGO.transform.localRotation = Quaternion.Euler(new Vector3(0f, -90f, 0f));
122160
else
@@ -145,7 +183,7 @@ private void RenderAnnotationLayer()
145183
{
146184
for (int y = 0; y < baseSize[1]; y++)
147185
{
148-
sagittalTex.SetPixel(camXLeft ? x : baseSize[0] - x, baseSize[1]-y, ccfModelControl.GetCCFAreaColor(annotationDataset.ValueAtIndex(x, y, mlIdx)));
186+
sagittalTex.SetPixel(camXLeft ? x : baseSize[0] - x, baseSize[1]-y, modelControl.GetCCFAreaColor(annotationDataset.ValueAtIndex(x, y, mlIdx)));
149187
}
150188
}
151189
sagittalTex.Apply();
@@ -154,7 +192,7 @@ private void RenderAnnotationLayer()
154192
{
155193
for (int y = 0; y < baseSize[1]; y++)
156194
{
157-
coronalTex.SetPixel(camYBack ? x : baseSize[2] - x, baseSize[1]-y, ccfModelControl.GetCCFAreaColor(annotationDataset.ValueAtIndex(apIdx, y, x)));
195+
coronalTex.SetPixel(camYBack ? x : baseSize[2] - x, baseSize[1]-y, modelControl.GetCCFAreaColor(annotationDataset.ValueAtIndex(apIdx, y, x)));
158196
}
159197
}
160198
coronalTex.Apply();
@@ -173,6 +211,11 @@ public void ToggleSliceVisibility(bool visible)
173211
UpdateCameraPosition();
174212
UpdateSlicePosition();
175213
RenderAnnotationLayer();
214+
UpdateNodeModelSlicing();
215+
}
216+
else
217+
{
218+
ClearNodeModelSlicing();
176219
}
177220
}
178221
}

Assets/Scripts/TrajectoryPlannerManager.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public class TrajectoryPlannerManager : MonoBehaviour
5454
private List<int> targetedBrainAreas;
5555

5656
private bool movedThisFrame;
57-
private bool movedThisFrameDirty;
5857
private bool spawnedThisFrame = false;
5958

6059
private int visibleProbePanels;
@@ -145,8 +144,10 @@ private void LoadAnnotationDatasetCompleted()
145144
datasetIndexes_bytes = null;
146145
inPlaneSlice.StartAnnotationDataset();
147146

148-
//localPrefs.AsyncStart();
149147
sliceRenderer.AsyncStart();
148+
149+
// Re-spawn previously active probes as the *final* step in loading
150+
localPrefs.AsyncStart();
150151
}
151152

152153
public void ClickSearchArea(GameObject target)
@@ -275,6 +276,7 @@ IEnumerator DelayedIBLProbeAdd(float phi, float theta, float delay)
275276
IEnumerator DelayedMoveAllProbes()
276277
{
277278
yield return new WaitForSeconds(0.05f);
279+
movedThisFrame = true;
278280
MoveAllProbes();
279281
}
280282

@@ -296,7 +298,7 @@ public ProbeController AddNewProbe(int probeType)
296298
RecalculateProbePanels();
297299

298300
spawnedThisFrame = true;
299-
DelayedMoveAllProbes();
301+
StartCoroutine(DelayedMoveAllProbes());
300302

301303
return newProbe.GetComponent<ProbeController>();
302304
}
@@ -366,7 +368,6 @@ public void SetActiveProbe(ProbeController newActiveProbeController)
366368
if (!activeProbeColliders.Contains(collider))
367369
inactiveProbeColliders.Add(collider);
368370
UpdateNonActiveColliders();
369-
movedThisFrame = true;
370371

371372
// Also update the recording region size slider
372373
recRegionSlider.SliderValueChanged(activeProbeController.GetRecordingRegionSize());
@@ -392,6 +393,11 @@ public bool MovedThisFrame()
392393
return movedThisFrame;
393394
}
394395

396+
public void SetMovedThisFrame()
397+
{
398+
movedThisFrame = true;
399+
}
400+
395401
public void UpdateInPlaneView()
396402
{
397403
inPlaneSlice.UpdateInPlaneSlice();

Assets/vbl-core

UserSettings/EditorUserSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ EditorUserSettings:
3636
value: 22424703114646680e0b0227036c6b02171d1d29382734291d251c3dece52676f7e93ffdfe
3737
flags: 0
3838
UnityEditor.ShaderGraph.Blackboard:
39-
value: 18135939215a0a5004000b0e15254b524c030a3f2964643d120d1230e9e93a3fd6e826abbd3c3e302a07a37e0901373ae01e0008f707250d171df81a53a5405d419548954b994b489f49459f9a4487bb828398a8d5d4cfd7ccd6bafdfae4eff4daf7a3e8afbcbe9afbffb0e2f69b9e9d989ce69c99959995ed869d91b3ece1dac3d3c78cc2c5c09983dcf9d4ecc1fefdcaf8f2cfc1fdcbffcfccd0f079f1f534363626efe5e1efd7e8ec35d62b23d3dd6f6a
39+
value: 18135939215a0a5004000b0e15254b524c030a3f2964643d120d1230e9e93a3fd6e826abbd2e2d293c4ead313b08042de6030a0afa240c0d020be94c4baf5e435d8715fa32c70d15d11612dacc11fee5d3c5d1fe9ab1b688908cf9abada9b7aea4a9f0a8fafaab94e6edf38e9ccbddc18390ac86d4849396e38b9f82e78a8b8a8f8fd18e8bd38a8995cfb9cff8c4f7f5ddf7f4c6c5f5cffacdcdc9e335e5b27d
4040
flags: 0
4141
UnityEditor.ShaderGraph.FloatingWindowsLayout2:
4242
value: 181344140043005e1a220d3b1f364b524c0c5a27130c293326201334cee5322ca0bd30e8eb293a707b0fd0180b3d0a36fc0d3d04e649500d1002ee0b5dbd1d2c27c00ad113cb1e10e41f1addc80993b98d9884a69ae6d8f0d1cda9e8fbfefaf9f9dea3fdb9ade882f0f7b0e1e380cafbf2c3adc18e9cd285a2908b82ec8b9c8395949c9483d68a8c97dcf9d4fbc8f6f2cbf8f0c3c6f4cab68083

0 commit comments

Comments
 (0)