@@ -19,7 +19,7 @@ function allen_ccf_npx(tv,av,st)
1919
2020% If not already loaded in, load in atlas
2121if nargin < 3
22- allen_atlas_path = ' C:\Users\Andrew\OneDrive for Business\ Documents\Atlases \AllenCCF' ;
22+ allen_atlas_path = ' C:\Users\Andy\ Documents\AllenCCF' ;
2323 if isempty(allen_atlas_path )
2424 error(' Enter path where Allen CCF is stored at Line 23' );
2525 end
@@ -148,11 +148,8 @@ function key_press(probe_atlas_gui,eventdata)
148148 set(gui_data .handles .probe_line ,' XData' ,get(gui_data .handles .probe_line ,' XData' ) + ap_offset );
149149 elseif any(strcmp(eventdata .Modifier ,' shift' ))
150150 % Ctrl-up: increase DV angle
151- angle_change = [0 ;-1 ];
152- new_angle = gui_data .probe_angle + angle_change ;
153- gui_data.probe_angle = new_angle ;
154- guidata(probe_atlas_gui , gui_data );
155- update_probe_angle(probe_atlas_gui );
151+ angle_change = [-10 ;0];
152+ gui_data = update_probe_angle(probe_atlas_gui ,angle_change );
156153 elseif any(strcmp(eventdata .Modifier ,' alt' ))
157154 % Alt-up: raise probe
158155 probe_offset = - 10 ;
@@ -175,11 +172,8 @@ function key_press(probe_atlas_gui,eventdata)
175172 set(gui_data .handles .probe_line ,' XData' ,get(gui_data .handles .probe_line ,' XData' ) + ap_offset );
176173 elseif any(strcmp(eventdata .Modifier ,' shift' ))
177174 % Ctrl-down: decrease DV angle
178- angle_change = [0 ;1];
179- new_angle = gui_data .probe_angle + angle_change ;
180- gui_data.probe_angle = new_angle ;
181- guidata(probe_atlas_gui , gui_data );
182- update_probe_angle(probe_atlas_gui );
175+ angle_change = [10 ;0];
176+ gui_data = update_probe_angle(probe_atlas_gui ,angle_change );
183177 elseif any(strcmp(eventdata .Modifier ,' alt' ))
184178 % Alt-down: lower probe
185179 probe_offset = 10 ;
@@ -202,11 +196,8 @@ function key_press(probe_atlas_gui,eventdata)
202196 set(gui_data .handles .probe_line ,' YData' ,get(gui_data .handles .probe_line ,' YData' ) + ml_offset );
203197 elseif any(strcmp(eventdata .Modifier ,' shift' ))
204198 % Ctrl-right: increase vertical angle
205- angle_change = [1 ;0];
206- new_angle = gui_data .probe_angle + angle_change ;
207- gui_data.probe_angle = new_angle ;
208- guidata(probe_atlas_gui , gui_data );
209- update_probe_angle(probe_atlas_gui );
199+ angle_change = [0 ;10];
200+ gui_data = update_probe_angle(probe_atlas_gui ,angle_change );
210201 end
211202
212203 case ' leftarrow'
@@ -217,11 +208,8 @@ function key_press(probe_atlas_gui,eventdata)
217208 set(gui_data .handles .probe_line ,' YData' ,get(gui_data .handles .probe_line ,' YData' ) + ml_offset );
218209 elseif any(strcmp(eventdata .Modifier ,' shift' ))
219210 % Ctrl-right: increase vertical angle
220- angle_change = [-1 ;0];
221- new_angle = gui_data .probe_angle + angle_change ;
222- gui_data.probe_angle = new_angle ;
223- guidata(probe_atlas_gui , gui_data );
224- update_probe_angle(probe_atlas_gui );
211+ angle_change = [0 ;-10 ];
212+ gui_data = update_probe_angle(probe_atlas_gui ,angle_change );
225213 end
226214
227215 case ' c'
@@ -567,26 +555,42 @@ function set_probe_position(probe_atlas_gui,varargin)
567555end
568556
569557
570- function update_probe_angle(probe_atlas_gui ,varargin )
558+ function gui_data = update_probe_angle(probe_atlas_gui ,angle_change )
571559
572560% Get guidata
573561gui_data = guidata(probe_atlas_gui );
574562
563+ % Set new angle
564+ new_angle = gui_data .probe_angle + angle_change ;
565+ gui_data.probe_angle = new_angle ;
566+
575567% Get the positions of the probe and trajectory reference
576568probe_ref_vector = cell2mat(get(gui_data .handles .probe_ref_line ,{' XData' ,' YData' ,' ZData' })' );
577569probe_vector = cell2mat(get(gui_data .handles .probe_line ,{' XData' ,' YData' ,' ZData' })' );
578570
579- % Update the probe trajectory reference (rotate about trajectory top)
580- [ap_max ,dv_max ,ml_max ] = size(gui_data .tv );
581-
582- max_ref_length = sqrt(sum(([ap_max ,dv_max ,ml_max ].^2 )));
583-
584- probe_angle_rad = (gui_data .probe_angle ./ 360 )*2 * pi ;
585- [x ,y ,z ] = sph2cart(pi - probe_angle_rad(1 ),probe_angle_rad(2 ),max_ref_length );
586-
587- new_probe_ref_top = [probe_ref_vector(1 ,1 ),probe_ref_vector(2 ,1 ),0 ];
588- new_probe_ref_bottom = new_probe_ref_top + [x ,y ,z ];
589- new_probe_ref_vector = [new_probe_ref_top ;new_probe_ref_bottom ]' ;
571+ % Update the probe trajectory reference angle
572+
573+ % % (Old, unused: spherical/manipulator coordinates)
574+ % [ap_max,dv_max,ml_max] = size(gui_data.tv);
575+ %
576+ % max_ref_length = sqrt(sum(([ap_max,dv_max,ml_max].^2)));
577+ %
578+ % probe_angle_rad = (gui_data.probe_angle./360)*2*pi;
579+ % [x,y,z] = sph2cart(pi-probe_angle_rad(1),probe_angle_rad(2),max_ref_length);
580+ %
581+ % new_probe_ref_top = [probe_ref_vector(1,1),probe_ref_vector(2,1),0];
582+ % new_probe_ref_bottom = new_probe_ref_top + [x,y,z];
583+ % new_probe_ref_vector = [new_probe_ref_top;new_probe_ref_bottom]';
584+
585+ % (New: cartesian coordinates of the trajectory bottom)
586+ new_probe_ref_vector = [probe_ref_vector(: ,1 ), ...
587+ probe_ref_vector(: ,2 ) + [angle_change ;0]];
588+
589+ [probe_azimuth ,probe_elevation ] = cart2sph( ...
590+ diff(fliplr(new_probe_ref_vector(1 ,: ))), ...
591+ diff(fliplr(new_probe_ref_vector(2 ,: ))), ...
592+ diff(fliplr(new_probe_ref_vector(3 ,: ))));
593+ gui_data.probe_angle = [probe_azimuth ,probe_elevation ]*(360 /(2 * pi ));
590594
591595set(gui_data .handles .probe_ref_line ,' XData' ,new_probe_ref_vector(1 ,: ), ...
592596 ' YData' ,new_probe_ref_vector(2 ,: ), ...
@@ -638,6 +642,11 @@ function update_probe_coordinates(probe_atlas_gui,varargin)
638642trajectory_brain_intersect = ...
639643 [trajectory_xcoords(trajectory_brain_idx ),trajectory_ycoords(trajectory_brain_idx ),trajectory_zcoords(trajectory_brain_idx )]' ;
640644
645+ % (if the probe doesn't intersect the brain, don't update)
646+ if isempty(trajectory_brain_intersect )
647+ return
648+ end
649+
641650probe_areas = interp3(single(gui_data .av(1 : pixel_space : end ,1 : pixel_space : end ,1 : pixel_space : end )), ...
642651 round(probe_zcoords / pixel_space ),round(probe_xcoords / pixel_space ),round(probe_ycoords / pixel_space ),' nearest' )' ;
643652probe_area_boundaries = intersect(unique([find(~isnan(probe_areas ),1 ,' first' ); ...
@@ -657,8 +666,8 @@ function update_probe_coordinates(probe_atlas_gui,varargin)
657666 num2str(probe_bregma_coordinate(1 )) ' AP, ' , ...
658667 num2str(-probe_bregma_coordinate(2 )) ' ML, ' , ...
659668 num2str(probe_depth ) ' Probe-axis, ' ...
660- num2str(gui_data .probe_angle(1 )) char(176 ) ' from midline, ' ...
661- num2str(gui_data .probe_angle(2 )) char(176 ) ' from horizontal' ];
669+ num2str(round( gui_data .probe_angle(1 ) )) char(176 ) ' from midline, ' ...
670+ num2str(round( gui_data .probe_angle(2 ) )) char(176 ) ' from horizontal' ];
662671set(gui_data .probe_coordinates_text ,' String' ,probe_text );
663672
664673% Update the probe areas
@@ -743,7 +752,7 @@ function probe_histology(probe_atlas_gui)
743752 ' \b f Probe: \r m' ...
744753 ' Arrow keys : translate probe' ...
745754 ' Alt/Option up/down : raise/lower probe' ...
746- ' Shift arrow keys : rotate probe (around top) ' ...
755+ ' Shift arrow keys : change probe angle ' ...
747756 ' m : set probe location manually' , ...
748757 ' \b f 3D brain areas: \r m' ...
749758 ' =/+ : add (list selector)' ...
0 commit comments