Skip to content

Commit 670a583

Browse files
committed
Fixing slice renderer bugs + documenting SliceRenderer
1 parent 339d0f2 commit 670a583

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

Assets/Scripts/TP_SliceRenderer.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@ public class TP_SliceRenderer : MonoBehaviour
2828
// Start is called before the first frame update
2929
void Start()
3030
{
31-
annotationDataset = tpmanager.GetAnnotationDataset();
32-
3331
sagittalTex = new Texture2D(baseSize[0], baseSize[1]);
3432
sagittalTex.filterMode = FilterMode.Point;
3533
mlIdx = Mathf.RoundToInt(baseSize[2] / 2);
36-
3734
sagittalSliceGO.GetComponent<Renderer>().material.mainTexture = sagittalTex;
3835

3936
coronalTex = new Texture2D(baseSize[2], baseSize[1]);
4037
coronalTex.filterMode = FilterMode.Point;
4138
apIdx = Mathf.RoundToInt(baseSize[0] / 2);
42-
4339
coronalSliceGO.GetComponent<Renderer>().material.mainTexture = coronalTex;
4440
}
4541

42+
public void AsyncStart()
43+
{
44+
annotationDataset = tpmanager.GetAnnotationDataset();
45+
}
46+
4647
private void Update()
4748
{
4849
if (localPrefs.GetSlice3D())
@@ -60,7 +61,10 @@ private void Update()
6061
if (needToRender) RenderAnnotationLayer();
6162
}
6263
}
63-
64+
65+
/// <summary>
66+
/// Shift the position of the sagittal and coronal slices to match the tip of the active probe
67+
/// </summary>
6468
private void UpdateSlicePosition()
6569
{
6670
ProbeController activeProbeController = tpmanager.GetActiveProbeController();
@@ -75,6 +79,11 @@ private void UpdateSlicePosition()
7579
apIdx = Mathf.RoundToInt((apPosition + 6.6f) * 40);
7680
}
7781

82+
/// <summary>
83+
/// When the camera swtiches from looking from the "left" or "right" of a slice, flip the direction we are rendering
84+
/// [TODO: this would be better to solve with a two-sided shader, the current approach causes a lot of lag]
85+
/// </summary>
86+
/// <returns></returns>
7887
private bool UpdateCameraPosition()
7988
{
8089
Vector3 camPosition = Camera.main.transform.position;
@@ -118,6 +127,9 @@ private bool UpdateCameraPosition()
118127
return false;
119128
}
120129

130+
/// <summary>
131+
/// Draw onto the sagittal and coronal slices the annotations at the current slice position in the CCF
132+
/// </summary>
121133
private void RenderAnnotationLayer()
122134
{
123135
// Render sagittal slice

Assets/Scripts/TrajectoryPlannerManager.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class TrajectoryPlannerManager : MonoBehaviour
1616
[SerializeField] private TP_RecRegionSlider recRegionSlider;
1717
[SerializeField] private Collider ccfCollider;
1818
[SerializeField] private TP_InPlaneSlice inPlaneSlice;
19+
[SerializeField] private TP_SliceRenderer sliceRenderer;
1920
[SerializeField] private TP_Search searchControl;
2021
[SerializeField] private TMP_InputField searchInput;
2122

@@ -94,6 +95,12 @@ private void Awake()
9495
private uint[] annotationMap_ints;
9596
private int annotationDatasetWait = 0;
9697
private AnnotationDataset annotationDataset;
98+
99+
/// <summary>
100+
/// Loads the annotation dataset files from their Addressable AssetReference objects
101+
///
102+
/// Asynchronous dependencies: inPlaneSlice, localPrefs
103+
/// </summary>
97104
private void LoadAnnotationDataset()
98105
{
99106
dataIndexes.LoadAssetAsync<TextAsset>().Completed += handle =>
@@ -126,6 +133,9 @@ private void LoadAnnotationDataset()
126133
Debug.Log("Annotation dataset loading");
127134
}
128135

136+
/// <summary>
137+
/// Called asynchronously when LoadAnnotationDataset loads all three indexes. Builds the dataset object and calls dependencies.
138+
/// </summary>
129139
private void LoadAnnotationDatasetCompleted()
130140
{
131141
Debug.Log("Annotation dataset loaded");
@@ -136,18 +146,18 @@ private void LoadAnnotationDatasetCompleted()
136146
inPlaneSlice.StartAnnotationDataset();
137147

138148
localPrefs.AsyncStart();
139-
}
140-
141-
142-
private void Start()
143-
{
149+
sliceRenderer.AsyncStart();
144150
}
145151

146152
public void ClickSearchArea(GameObject target)
147153
{
148154
searchControl.ClickArea(target);
149155
}
150156

157+
/// <summary>
158+
///
159+
/// </summary>
160+
/// <param name="value"></param>
151161
public void ToggleBeryl(int value)
152162
{
153163
switch (value)

0 commit comments

Comments
 (0)