@@ -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}
0 commit comments