Home > functions > tool_box > mri_toolbox > sphere_head_dir > vb_sphere_head.m

vb_sphere_head

PURPOSE ^

vb_sphere_head - create and navigate ortho views of Analyze 7.5 volume

SYNOPSIS ^

function [ varargout ] = vb_sphere_head(avw,parent,command),

DESCRIPTION ^

 vb_sphere_head - create and navigate ortho views of Analyze 7.5 volume
 
 Usage : avw = avw_read(analyze_file);
         vb_sphere_head(avw);
 [IN]
    avw : mri data read by avw_read.
 [OUT]
    avw : base workspace struct avw.
          avw.radius  : spherical radius (SPM_Right_m)
             .center  : spherical center (SPM_Right_m)

 avw - a struct, created by avw_read; if omitted, a gui file locator will
 prompt for a .hdr file.
 
 parent  - an optional handle to the gui that calls this gui, useful for
 updating the UserData field of the parent. The avw structure may be
 returned to the parent, if possible.
 
 command - an optional string, such as 'init' or various callback
 commands, 'init' is the default.
 
 The navigation is by sliders, mouse clicks and arrow keys.  Right mouse
 clicks on any ortho-view will show a command menu, for simple block
 region of interest (ROI) calculations, image zoom, and save image.  The
 ROI calculations are returned into avw.stats.
 
 +X is right (R), +Y is anterior (A), +Z is superior (S), the default RAS
 orientation of the Analyze 7.5 format.  The coordinate system is right
 handed.  

 Example of loading and viewing the SPM T1 template:
 avw = sphere_read('T1')
 avw = vb_sphere_head(avw);
 
 Similarly, just 'sphere_head' can be typed at the command prompt and you can
 use the gui file locator to select any .hdr file.

 See also, avw_read, avw_img_read, avw_hdr_read

 This program was created based on avw_view by Darren.Weber_at_flinders.edu.au

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ varargout ] = vb_sphere_head(avw,parent,command),
0002 % vb_sphere_head - create and navigate ortho views of Analyze 7.5 volume
0003 %
0004 % Usage : avw = avw_read(analyze_file);
0005 %         vb_sphere_head(avw);
0006 % [IN]
0007 %    avw : mri data read by avw_read.
0008 % [OUT]
0009 %    avw : base workspace struct avw.
0010 %          avw.radius  : spherical radius (SPM_Right_m)
0011 %             .center  : spherical center (SPM_Right_m)
0012 %
0013 % avw - a struct, created by avw_read; if omitted, a gui file locator will
0014 % prompt for a .hdr file.
0015 %
0016 % parent  - an optional handle to the gui that calls this gui, useful for
0017 % updating the UserData field of the parent. The avw structure may be
0018 % returned to the parent, if possible.
0019 %
0020 % command - an optional string, such as 'init' or various callback
0021 % commands, 'init' is the default.
0022 %
0023 % The navigation is by sliders, mouse clicks and arrow keys.  Right mouse
0024 % clicks on any ortho-view will show a command menu, for simple block
0025 % region of interest (ROI) calculations, image zoom, and save image.  The
0026 % ROI calculations are returned into avw.stats.
0027 %
0028 % +X is right (R), +Y is anterior (A), +Z is superior (S), the default RAS
0029 % orientation of the Analyze 7.5 format.  The coordinate system is right
0030 % handed.
0031 %
0032 % Example of loading and viewing the SPM T1 template:
0033 % avw = sphere_read('T1')
0034 % avw = vb_sphere_head(avw);
0035 %
0036 % Similarly, just 'sphere_head' can be typed at the command prompt and you can
0037 % use the gui file locator to select any .hdr file.
0038 %
0039 % See also, avw_read, avw_img_read, avw_hdr_read
0040 %
0041 % This program was created based on avw_view by Darren.Weber_at_flinders.edu.au
0042 
0043 % $Revision: 1202 $ $Date:: 2010-10-19 10:58:59 +0900#$
0044 
0045 % Licence:  GNU GPL, no express or implied warranties
0046 % History:  change display coordinate from radiological(LAS) to neurological.
0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0048 
0049 if gcbf,
0050     AVWVIEW = get(gcbf,'Userdata');
0051 end
0052 
0053 if ~exist('command','var'), command = 'init'; end
0054 
0055 command = lower(command);
0056 
0057 % Check for specific keys and assign command
0058 if strcmp(command, 'keypress'),
0059   
0060   cc = get(AVWVIEW.gui,'CurrentCharacter');
0061   cc = double(cc);
0062   if cc,
0063     switch cc,
0064       case 26, command = 'del_unselect_status_point'; 
0065 %      case 27, command = 'quit';  % ESC
0066       case 28, command = 'left';  % left
0067       case 29, command = 'right'; % right
0068       case 30, command = 'up';    % up
0069       case 31, command = 'down';  % down
0070       case 127, command = 'left'; 
0071       otherwise, return;  % all other keys
0072     end
0073   end
0074 end
0075 
0076 switch command,
0077     
0078   case 'init',
0079     
0080     if ~exist('avw','var'),
0081       avw = avw_read_ras; % modified by Masa-aki Sato
0082     end
0083     
0084     if nargin == 0,
0085       AVWVIEW = init(avw);
0086     elseif isempty(inputname(1)),
0087       AVWVIEW = init(avw);
0088     else
0089       AVWVIEW = init(avw,inputname(1));
0090     end
0091     
0092     AVWVIEW = set_coordinates(AVWVIEW);
0093     AVWVIEW = set_crosshairs(AVWVIEW);
0094 
0095     
0096     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0097     
0098   case 'coordinates',
0099     
0100     AVWVIEW = set_coordinates(AVWVIEW);
0101     
0102     
0103     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0104     
0105   case 'crosshairs',
0106     
0107     AVWVIEW = set_crosshairs(AVWVIEW);
0108     
0109     
0110   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0111   
0112   case {'axial_image','coronal_image','sagittal_image'},
0113 
0114     
0115     switch command,
0116       case 'axial_image',    AVWVIEW.view = 'axi'; axi_update = 0; cor_update = 1; sag_update = 1;
0117       case 'coronal_image',  AVWVIEW.view = 'cor'; axi_update = 1; cor_update = 0; sag_update = 1;
0118       case 'sagittal_image', AVWVIEW.view = 'sag'; axi_update = 1; cor_update = 1; sag_update = 0;
0119     end
0120     
0121     AVWVIEW = get_current_position(AVWVIEW);
0122     
0123 %     if axi_update,
0124 %         axial_update(AVWVIEW);
0125 %     end
0126 %     if cor_update,
0127 %         coronal_update(AVWVIEW);
0128 %     end;
0129 %     if sag_update,
0130 %         sagittal_update(AVWVIEW);
0131 %     end;
0132     
0133     set_display_values(AVWVIEW);
0134     
0135     % display selected point
0136     AVWVIEW = set_selected_point(AVWVIEW);
0137 
0138 
0139     AVWVIEW = set_crosshairs(AVWVIEW);
0140 
0141     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0142     
0143   case {'axial_slider','coronal_slider','sagittal_slider'},
0144     
0145     switch command,
0146       
0147       case 'axial_slider',
0148         AVWVIEW.view = 'axi';
0149         AVWVIEW = get_slider_position(AVWVIEW);
0150         axial_update(AVWVIEW);
0151         
0152       case 'coronal_slider',
0153         AVWVIEW.view = 'cor';
0154         AVWVIEW = get_slider_position(AVWVIEW);
0155         coronal_update(AVWVIEW);
0156         
0157       case 'sagittal_slider',
0158         AVWVIEW.view = 'sag';
0159         AVWVIEW = get_slider_position(AVWVIEW);
0160         sagittal_update(AVWVIEW);
0161     end
0162     
0163     set_display_values(AVWVIEW);
0164     
0165     AVWVIEW = set_crosshairs(AVWVIEW);
0166     
0167     
0168     
0169     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0170     
0171   case {'left','right','up','down'},
0172     
0173     AVWVIEW = get_slider_position(AVWVIEW);
0174     
0175     % what axes are we in?
0176     if isequal(gca, AVWVIEW.handles.axial_axes),
0177       switch command,
0178         case 'left',
0179           % decrease sagittal slice
0180           if AVWVIEW.slices.sag > 1,
0181             AVWVIEW.slices.sag = AVWVIEW.slices.sag - 1;
0182           end
0183         case 'right',
0184           % increase sagittal slice
0185           if AVWVIEW.slices.sag < AVWVIEW.xdim,
0186             AVWVIEW.slices.sag = AVWVIEW.slices.sag + 1;
0187           end
0188         case 'up',
0189           % increase coronal slice
0190           if AVWVIEW.slices.cor < AVWVIEW.ydim,
0191             AVWVIEW.slices.cor = AVWVIEW.slices.cor + 1;
0192           end
0193         case 'down',
0194           % decrease coronal slice
0195           if AVWVIEW.slices.cor > 1,
0196             AVWVIEW.slices.cor = AVWVIEW.slices.cor - 1;
0197           end
0198       end
0199       switch command,
0200         case {'left','right'}
0201           set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0202           Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0203           set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0204           set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0205           set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0206         case {'up','down'},
0207           set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0208           Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0209           set(AVWVIEW.handles.coronal_image,'CData',Scor');
0210           set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0211           set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0212       end
0213     end
0214     
0215     if isequal(gca, AVWVIEW.handles.coronal_axes),
0216       switch command,
0217         case 'left',
0218           % decrease sagittal slice
0219           if AVWVIEW.slices.sag > 1,
0220             AVWVIEW.slices.sag = AVWVIEW.slices.sag - 1;
0221           end
0222         case 'right',
0223           % increase sagittal slice
0224           if AVWVIEW.slices.sag < AVWVIEW.xdim,
0225             AVWVIEW.slices.sag = AVWVIEW.slices.sag + 1;
0226           end
0227         case 'up',
0228           % increase axial slice
0229           if AVWVIEW.slices.axi < AVWVIEW.zdim,
0230             AVWVIEW.slices.axi = AVWVIEW.slices.axi + 1;
0231           end
0232         case 'down',
0233           % decrease axial slice
0234           if AVWVIEW.slices.axi > 1,
0235             AVWVIEW.slices.axi = AVWVIEW.slices.axi - 1;
0236           end
0237       end
0238       switch command,
0239         case {'left','right'}
0240           set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0241           Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0242           set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0243           set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0244           set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0245         case {'up','down'},
0246           set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0247           Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0248           set(AVWVIEW.handles.axial_image,'CData',Saxi');
0249           set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0250           set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0251       end
0252     end
0253     
0254     if isequal(gca, AVWVIEW.handles.sagittal_axes),
0255       switch command,
0256         case 'left',
0257           % decrease sagittal slice
0258           if AVWVIEW.slices.cor > 1,
0259             AVWVIEW.slices.cor = AVWVIEW.slices.cor - 1;
0260           end
0261         case 'right',
0262           % increase sagittal slice
0263           if AVWVIEW.slices.cor < AVWVIEW.ydim,
0264             AVWVIEW.slices.cor = AVWVIEW.slices.cor + 1;
0265           end
0266         case 'up',
0267           % increase axial slice
0268           if AVWVIEW.slices.axi < AVWVIEW.zdim,
0269             AVWVIEW.slices.axi = AVWVIEW.slices.axi + 1;
0270           end
0271         case 'down',
0272           % decrease axial slice
0273           if AVWVIEW.slices.axi > 1,
0274             AVWVIEW.slices.axi = AVWVIEW.slices.axi - 1;
0275           end
0276       end
0277       switch command,
0278         case {'left','right'}
0279           set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0280           Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0281           set(AVWVIEW.handles.coronal_image,'CData',Scor');
0282           set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0283           set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0284         case {'up','down'},
0285           set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0286           Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0287           set(AVWVIEW.handles.axial_image,'CData',Saxi');
0288           set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0289           set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0290       end
0291     end
0292     
0293     AVWVIEW = set_crosshairs(AVWVIEW);
0294     
0295     
0296     
0297     
0298     
0299     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0300     
0301   case {'roi_9','roi_7','roi_5','roi_3'},
0302     
0303     position = [ AVWVIEW.slices.sag, AVWVIEW.slices.cor, AVWVIEW.slices.axi ];
0304     
0305     shape.type = 'block';
0306     if findstr(command,'9'), shape.size = [9,9,9]; end
0307     if findstr(command,'7'), shape.size = [7,7,7]; end
0308     if findstr(command,'5'), shape.size = [5,5,5]; end
0309     if findstr(command,'3'), shape.size = [3,3,3]; end
0310     
0311     stats.roi = avw_roi(AVWVIEW.avw,position,shape);
0312     
0313     AVWVIEW.avw.stats = avw_stats(stats);
0314     
0315     
0316     
0317     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0318     case 'calc_sphere'
0319         AVWVIEW = calc_sphere(AVWVIEW);
0320     case 'remove_coronal_point'
0321         AVWVIEW = remove_selected_point(AVWVIEW, 'coronal');
0322     case 'remove_axial_point'
0323         AVWVIEW = remove_selected_point(AVWVIEW, 'axial');
0324     case 'remove_sagittal_point'
0325         AVWVIEW = remove_selected_point(AVWVIEW, 'sagittal');
0326     case 'point_state_reverse'
0327         h = gcbo;
0328         col = get(h, 'Color');
0329         if col == [1 0 0] % red
0330             set(h, 'Color', 'blue');
0331         else
0332             set(h, 'Color', 'red');
0333         end
0334     case 'del_unselect_status_point'
0335         AVWVIEW = remove_selected_point(AVWVIEW, 'unselected_status_point');
0336     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0337     
0338   case 'flip',
0339     
0340     % flip X dim here...
0341     AVWVIEW.avw.img = flipdim(AVWVIEW.avw.img,1);
0342     
0343     if isfield(AVWVIEW.handles,'axial_image'),
0344       Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0345       set(AVWVIEW.handles.axial_image,'CData',Saxi');
0346     end;
0347     if isfield(AVWVIEW.handles,'coronal_image'),
0348       Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0349       set(AVWVIEW.handles.coronal_image,'CData',Scor');
0350     end;
0351     if isfield(AVWVIEW.handles,'sagittal_image'),
0352       Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0353       set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0354     end;
0355     
0356     flipStatus = get(AVWVIEW.handles.flipStatus,'string');
0357     if strmatch(flipStatus,'R>>L (radiological)'),
0358       flipStatus = 'L>>R (neurological)';
0359     else,
0360       flipStatus = 'R>>L (radiological)';
0361     end;
0362     set(AVWVIEW.handles.flipStatus,'string',flipStatus);
0363     
0364     
0365     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0366     
0367   case {'brighter','dimmer','setclimit'},
0368     
0369     switch command,
0370       case 'brighter',
0371         AVWVIEW.clim = AVWVIEW.clim .* 0.9;
0372       case 'dimmer',
0373         AVWVIEW.clim = AVWVIEW.clim .* 1.1;
0374       case 'setclimit',
0375         clim = get(AVWVIEW.handles.clim,'string');
0376         AVWVIEW.clim(2) = str2num(clim);
0377     end
0378     climString = sprintf('%05.2f',AVWVIEW.clim(2));
0379     set(AVWVIEW.handles.clim,'string',climString);
0380     
0381     if isfield(AVWVIEW.handles,'axial_image'),
0382       set(AVWVIEW.handles.axial_axes,'Clim',AVWVIEW.clim);
0383     end;
0384     if isfield(AVWVIEW.handles,'coronal_image'),
0385       set(AVWVIEW.handles.coronal_axes,'Clim',AVWVIEW.clim);
0386     end;
0387     if isfield(AVWVIEW.handles,'sagittal_image'),
0388       set(AVWVIEW.handles.sagittal_axes,'Clim',AVWVIEW.clim);
0389     end;
0390     
0391     
0392     
0393     
0394     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0395     
0396   case 'contrast'
0397     
0398     if isfield(AVWVIEW.handles,'axial_image'),
0399       X = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0400       AVWVIEW.cmap = contrast(X);
0401       colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
0402     end;
0403     if isfield(AVWVIEW.handles,'coronal_image'),
0404       X = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0405       AVWVIEW.cmap = contrast(X);
0406       colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
0407     end;
0408     if isfield(AVWVIEW.handles,'sagittal_image'),
0409       X = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0410       AVWVIEW.cmap = contrast(X);
0411       colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
0412     end;
0413     
0414     
0415     
0416     
0417     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0418     
0419   case 'setcmap'
0420     
0421     cmapIndex = get(AVWVIEW.handles.cmap,'value');
0422     cmapString = get(AVWVIEW.handles.cmap,'string');
0423     
0424     AVWVIEW.cmapString = cmapString{cmapIndex};
0425     
0426     if isfield(AVWVIEW.handles,'axial_image'),
0427       AVWVIEW.cmap = colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmapString);
0428     end;
0429     if isfield(AVWVIEW.handles,'coronal_image'),
0430       AVWVIEW.cmap = colormap(AVWVIEW.handles.coronal_axes,AVWVIEW.cmapString);
0431     end;
0432     if isfield(AVWVIEW.handles,'sagittal_image'),
0433       AVWVIEW.cmap = colormap(AVWVIEW.handles.sagittal_axes,AVWVIEW.cmapString);
0434     end;
0435     
0436     
0437     
0438     
0439     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0440     
0441   case 'histogram',
0442     
0443     avw = AVWVIEW.avw;
0444     
0445     % would be nice to use bins that reflect
0446     % the bits per pixel, but it seems to take
0447     % forever for a 16 bit image, otherwise
0448     % use this code:
0449     %     %check the bits per pixel of avw
0450     %     bitpix = avw.hdr.dime.bitpix;
0451     %     % set the bins according to the data type
0452     %     if bitpix <= 8, bins = 0:255; end
0453     %     if bitpix > 8,  bins = 0:65535; end
0454     
0455     %bins = linspace(0,intensity_max,255);
0456     
0457     intensity_min = min(min(min(avw.img)));
0458     intensity_max = max(max(max(avw.img)));
0459     
0460     bins = intensity_min:intensity_max;
0461     
0462     fprintf('...calculating histogram for %d bins.\n',length(bins));
0463     
0464     for i=1:size(avw.img,3),
0465       n = hist(avw.img(:,:,i), bins);
0466       if i == 1,
0467         intensity_volume = sum(n,2);
0468       else
0469         intensity_slice = sum(n,2);
0470         intensity_volume = intensity_volume + intensity_slice;
0471       end
0472     end
0473     figure('name','intensity histogram');
0474     bar(bins,intensity_volume);
0475     
0476     
0477     
0478     
0479     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0480     
0481   case 'zoom'
0482     
0483     x = AVWVIEW.slices.sag;
0484     y = AVWVIEW.slices.cor;
0485     z = AVWVIEW.slices.axi;
0486     
0487     switch AVWVIEW.view,
0488       case 'axi',
0489         slice = rot90(AVWVIEW.avw.img(:,:,z));
0490       case 'cor',
0491         slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
0492       case 'sag',
0493         slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
0494     end
0495     
0496     figure;
0497     imagesc(slice,AVWVIEW.clim); 
0498     colormap(gray); axis off; zoom on;
0499     daspect(AVWVIEW.daspect);
0500     
0501     
0502     
0503     
0504     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0505     
0506   case 'save_image',
0507     
0508     [filename, pathname] = uiputfile(...
0509       { '*.png','PNG Files (*.png)'; ...
0510         '*.jpg','JPG Files (*.jpg)'; ...
0511         '*.ppm;*.pgm;*.pbm','Portable Anymap (*.ppm,*.pgm,*.pbm)'; ...
0512         '*.*',  'All Files (*.*)'}, ...
0513       'IMWrite to file');
0514     
0515     if filename,
0516       
0517       x = AVWVIEW.slices.sag;
0518       y = AVWVIEW.slices.cor;
0519       z = AVWVIEW.slices.axi;
0520       
0521       pixelsPerMM = 1 ./ double(AVWVIEW.avw.hdr.dime.pixdim(2:4));
0522       pixelsPerMeter = pixelsPerMM .* 1000;
0523       
0524       switch AVWVIEW.view,
0525         case 'axi',
0526           slice = rot90(AVWVIEW.avw.img(:,:,z));
0527           xresolution = pixelsPerMeter(1);
0528           yresolution = pixelsPerMeter(2);
0529         case 'cor',
0530           slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
0531           xresolution = pixelsPerMeter(1);
0532           yresolution = pixelsPerMeter(3);
0533         case 'sag',
0534           slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
0535           xresolution = pixelsPerMeter(2);
0536           yresolution = pixelsPerMeter(3);
0537       end
0538       
0539       % scale the image values to between 0-1 for imwrite
0540       % (initially used max of slice, but actually want to
0541       % use the scaled intensity from the gui).
0542       %maxValue = max(max(slice));
0543       %scaledSlice = slice ./ maxValue;
0544       scaledSlice = slice ./ AVWVIEW.clim(2);
0545       
0546       % RGB = ind2rgb(X,map) converts the matrix X and corresponding
0547       % colormap map to RGB (truecolor)
0548       
0549       file = [pathname,filename];
0550       fprintf('saving to:...%s\n',file);
0551       
0552       %Most of the supported image file formats store uint8 data.
0553       %PNG and TIFF formats additionally support uint16 data. For
0554       %grayscale and RGB images, if the data array is double, the
0555       %assumed dynamic range is [0,1]. The data array is automatically
0556       %scaled by 255 before being written as uint8. If the data array
0557       %is uint8 or uint16, it is written without scaling as uint8 or
0558       %uint16, respectively.
0559       
0560       [pathname,filename,ext] = fileparts([pathname,filename]);
0561       
0562       switch ext,
0563       
0564         case '.png',
0565           %imwrite(uint8(image),colormap,file,format);
0566           %imwrite(slice,colormap(gray),file,format,...
0567           
0568           %     'XResolution'  A scalar indicating the number of
0569           %                    pixels/unit in the horizontal direction
0570           %
0571           %     'YResolution'  A scalar indicating the number of
0572           %                    pixels/unit in the vertical direction
0573           %
0574           %     'ResolutionUnit' Either 'unknown' or 'meter'
0575           format = 'png';
0576           imwrite(scaledSlice,file,format,...
0577             'BitDepth',16,'ResolutionUnit','meter',...
0578             'XResolution',xresolution,...
0579             'YResolution',yresolution);
0580           
0581         case '.jpg',
0582           format = 'jpg';
0583           imwrite(scaledSlice,file,format);
0584         case {'.ppm','.pgm','.pbm'},
0585           format = ext(2:end);
0586           imwrite(scaledSlice,file,format);
0587         otherwise
0588           fprintf('...cannot write %s image files\n',ext);
0589       end
0590     end
0591     
0592     
0593     
0594     
0595     
0596   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0597     
0598   case 'save',
0599     % try to assign back into the input struct
0600     if ~isempty(AVWVIEW.invarname),
0601       fprintf('...returning data to base workspace struct ''%s''\n',AVWVIEW.invarname);
0602       assignin('base',AVWVIEW.invarname,AVWVIEW.avw);
0603     elseif evalin('base','exist(''mri'',''var'')'),
0604       fprintf('...returning data to base workspace struct ''mri''\n');
0605       string = ['AVWVIEW = get(', num2str(AVWVIEW.gui),...
0606           ',''Userdata''); mri.data = AVWVIEW.avw; clear AVWVIEW;'];
0607       evalin('base',string);
0608     else
0609       fprintf('...returning data into base workspace struct ''avw''\n');
0610       assignin('base','avw',AVWVIEW.avw);
0611     end
0612 
0613     [filename, pathname] = uiputfile('*.mat','Save fiducials');
0614     if isequal(filename,0) | isequal(pathname,0)
0615        disp('filename not specified.')
0616     else
0617        fiducials = AVWVIEW.avw.fiducials;
0618        vb_fsave([fullfile(pathname, filename)], 'fiducials');
0619     end
0620     %    close gcbf;
0621     
0622 
0623   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0624   
0625   case 'close',
0626       if isempty(AVWVIEW.sphere_data.radius)
0627         res = questdlg(...
0628                 'Sphere calculation is not finished. Do you close this window?', 'confirm', ...
0629                 'Yes', 'No',...
0630                 'Yes');
0631         if strcmp(res, 'No')
0632              return;
0633         end
0634       end
0635           
0636       fprintf('...returning data into base workspace struct ''avw''\n');
0637       if ~isempty(AVWVIEW.sphere_data.center)
0638           Vdim = [AVWVIEW.xdim, AVWVIEW.ydim, AVWVIEW.zdim];
0639           Vsize = AVWVIEW.pixdim;
0640           center = vb_analyze_right_mm_to_spm_right(...
0641                                         AVWVIEW.sphere_data.center, ...
0642                                         Vdim, Vsize);
0643           radius = AVWVIEW.sphere_data.radius .* 0.001;
0644           AVWVIEW.avw.center = center;
0645           AVWVIEW.avw.radius = radius;
0646       end
0647       assignin('base','avw',AVWVIEW.avw);
0648       close gcbf;
0649       
0650   otherwise,
0651 end
0652   
0653 switch command,
0654   case 'save',
0655   case 'close',
0656   otherwise,
0657     set(AVWVIEW.gui,'UserData',AVWVIEW);
0658 end
0659 
0660 if nargout > 0,
0661   varargout{1} = AVWVIEW.avw;
0662 end
0663 
0664 return
0665 
0666 
0667 
0668 
0669 
0670 
0671 
0672 
0673 
0674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0675 % SUBFUNCTIONS
0676 
0677 
0678 
0679 
0680 
0681 
0682 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0683 function axial_update(AVWVIEW)
0684 
0685 if isfield(AVWVIEW.handles,'axial_image'),
0686     Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0687     set(AVWVIEW.handles.axial_image,'CData',Saxi');
0688 end
0689 if isfield(AVWVIEW.handles,'axial_sliderN'),
0690     set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0691     set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0692 end
0693 if isfield(AVWVIEW.handles,'axial_slider'),
0694     set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0695 end;
0696 
0697 return
0698 
0699 
0700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0701 function coronal_update(AVWVIEW)
0702 
0703 if isfield(AVWVIEW.handles,'coronal_image'),
0704     Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0705     set(AVWVIEW.handles.coronal_image,'CData',Scor');
0706 end
0707 if isfield(AVWVIEW.handles,'coronal_sliderN'),
0708     set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0709     set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0710 end
0711 if isfield(AVWVIEW.handles,'coronal_slider'),
0712     set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0713 end;
0714 
0715 return
0716 
0717 
0718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0719 function sagittal_update(AVWVIEW)
0720 
0721 if isfield(AVWVIEW.handles,'sagittal_image'),
0722     Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0723     set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0724 end
0725 if isfield(AVWVIEW.handles,'sagittal_sliderN'),
0726     set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0727     set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0728 end
0729 if isfield(AVWVIEW.handles,'sagittal_slider'),
0730     set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0731 end;
0732 
0733 return
0734 
0735 
0736 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0737 function AVWVIEW = set_crosshairs(AVWVIEW)
0738 
0739 fig = figure(AVWVIEW.gui);
0740 
0741 if isfield(AVWVIEW.handles,'axial_axes'),
0742   set(fig, 'CurrentAxes', AVWVIEW.handles.axial_axes);
0743   
0744   x_value = [AVWVIEW.slices.sag AVWVIEW.slices.sag];
0745   y_value = [AVWVIEW.slices.cor AVWVIEW.slices.cor];
0746   if get(AVWVIEW.handles.coord, 'value') == 3
0747       % mm(or voxel) to m
0748       x_value = x_value / 1000;
0749       y_value = y_value / 1000;
0750   end
0751 
0752   AVWVIEW.handles.axial_xlim = get(AVWVIEW.handles.axial_axes,'Xlim');
0753   AVWVIEW.handles.axial_ylim = get(AVWVIEW.handles.axial_axes,'Ylim');
0754   set(AVWVIEW.handles.axial_xline, 'Xdata', x_value,'Ydata',AVWVIEW.handles.axial_ylim);
0755   set(AVWVIEW.handles.axial_yline, 'Ydata', y_value,'Xdata',AVWVIEW.handles.axial_xlim);
0756   set(AVWVIEW.handles.axial_xline,'Color','b','EraseMode','xor','Tag','XLINE');
0757   set(AVWVIEW.handles.axial_yline,'Color','b','EraseMode','xor','Tag','YLINE');
0758 
0759   if get(AVWVIEW.handles.crosshairs,'value'),
0760     set(AVWVIEW.handles.axial_xline,'visible','on');
0761     set(AVWVIEW.handles.axial_yline,'visible','on');
0762   else
0763     set(AVWVIEW.handles.axial_xline,'visible','off');
0764     set(AVWVIEW.handles.axial_yline,'visible','off');
0765   end
0766   
0767 end
0768 
0769 if isfield(AVWVIEW.handles,'coronal_axes'),
0770   set(fig, 'CurrentAxes', AVWVIEW.handles.coronal_axes);
0771 
0772   x_value = [AVWVIEW.slices.sag AVWVIEW.slices.sag];
0773   y_value = [AVWVIEW.slices.axi AVWVIEW.slices.axi];
0774   if get(AVWVIEW.handles.coord, 'value') == 3
0775       % mm(or voxel) to m
0776       x_value = x_value / 1000;
0777       y_value = y_value / 1000;
0778   end
0779 
0780   AVWVIEW.handles.coronal_xlim = get(AVWVIEW.handles.coronal_axes,'Xlim');
0781   AVWVIEW.handles.coronal_ylim = get(AVWVIEW.handles.coronal_axes,'Ylim');
0782   set(AVWVIEW.handles.coronal_xline, 'Xdata',x_value,'Ydata',AVWVIEW.handles.coronal_ylim);
0783   set(AVWVIEW.handles.coronal_yline, 'Ydata',y_value,'Xdata',AVWVIEW.handles.coronal_xlim);
0784   set(AVWVIEW.handles.coronal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
0785   set(AVWVIEW.handles.coronal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
0786   
0787   
0788   if get(AVWVIEW.handles.crosshairs,'value'),
0789     set(AVWVIEW.handles.coronal_xline,'visible','on');
0790     set(AVWVIEW.handles.coronal_yline,'visible','on');
0791   else
0792     set(AVWVIEW.handles.coronal_xline,'visible','off');
0793     set(AVWVIEW.handles.coronal_yline,'visible','off');
0794   end
0795   
0796 end
0797 
0798 if isfield(AVWVIEW.handles,'sagittal_axes'),
0799   set(fig, 'CurrentAxes', AVWVIEW.handles.sagittal_axes);
0800   x_value = [AVWVIEW.slices.cor AVWVIEW.slices.cor];
0801   y_value = [AVWVIEW.slices.axi AVWVIEW.slices.axi];
0802   if get(AVWVIEW.handles.coord, 'value') == 3
0803       % mm(or voxel) to m
0804       x_value = x_value / 1000;
0805       y_value = y_value / 1000;
0806   end
0807   AVWVIEW.handles.sagittal_xlim = get(AVWVIEW.handles.sagittal_axes,'Xlim');
0808   AVWVIEW.handles.sagittal_ylim = get(AVWVIEW.handles.sagittal_axes,'Ylim');
0809   set(AVWVIEW.handles.sagittal_xline, 'Xdata',x_value,'Ydata',AVWVIEW.handles.sagittal_ylim);
0810   set(AVWVIEW.handles.sagittal_yline, 'Ydata',y_value,'Xdata',AVWVIEW.handles.sagittal_xlim);
0811   set(AVWVIEW.handles.sagittal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
0812   set(AVWVIEW.handles.sagittal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
0813   
0814   if get(AVWVIEW.handles.crosshairs,'value'),
0815     set(AVWVIEW.handles.sagittal_xline,'visible','on');
0816     set(AVWVIEW.handles.sagittal_yline,'visible','on');
0817   else
0818     set(AVWVIEW.handles.sagittal_xline,'visible','off');
0819     set(AVWVIEW.handles.sagittal_yline,'visible','off');
0820   end
0821  
0822 end
0823 
0824 return
0825 
0826 
0827 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0828 function AVWVIEW = set_coordinates(AVWVIEW)
0829 
0830 % set the axis coordinates to voxels, mm or meters
0831 
0832 s = size(AVWVIEW.avw.img);
0833 if length(s) > 0, xdim = s(1); else xdim = 1; end
0834 if length(s) > 1, ydim = s(2); else ydim = 1; end
0835 if length(s) > 2, zdim = s(3); else zdim = 1; end
0836 
0837 % initialise for voxel coordinates
0838 xpixdim = double(AVWVIEW.avw.hdr.dime.pixdim(2));
0839 ypixdim = double(AVWVIEW.avw.hdr.dime.pixdim(3));
0840 zpixdim = double(AVWVIEW.avw.hdr.dime.pixdim(4));
0841 xdata = [0 xdim];
0842 ydata = [0 ydim];
0843 zdata = [0 zdim];
0844 
0845 aspect = 1./AVWVIEW.daspect; %AVWVIEW.avw.hdr.dime.pixdim(2:4);
0846 
0847 
0848 if get(AVWVIEW.handles.coord,'value') == 2,    % mm
0849   xdata = xdata .* xpixdim;
0850   ydata = ydata .* ypixdim;
0851   zdata = zdata .* zpixdim;
0852   aspect = [1 1 1];
0853 end
0854 
0855 if get(AVWVIEW.handles.coord,'value') == 3,    % meters
0856   xpixdim = xpixdim / 1000;
0857   ypixdim = ypixdim / 1000;
0858   zpixdim = zpixdim / 1000;
0859   xdata = xdata .* xpixdim;
0860   ydata = ydata .* ypixdim;
0861   zdata = zdata .* zpixdim;
0862   aspect = [1 1 1];
0863 end
0864 
0865 
0866 if isfield(AVWVIEW.handles,'axial_image'),
0867   set(AVWVIEW.handles.axial_axes,'Xlim',xdata);
0868   set(AVWVIEW.handles.axial_axes,'Ylim',ydata);
0869   set(AVWVIEW.handles.axial_axes,'Zlim',zdata);
0870   set(AVWVIEW.handles.axial_image,'Xdata',xdata);
0871   set(AVWVIEW.handles.axial_image,'Ydata',ydata);
0872   daspect(AVWVIEW.handles.axial_axes,aspect([1 2 3]));
0873 end;
0874 if isfield(AVWVIEW.handles,'coronal_image'),
0875   set(AVWVIEW.handles.coronal_axes,'Xlim',xdata);
0876   set(AVWVIEW.handles.coronal_axes,'Ylim',zdata);
0877   set(AVWVIEW.handles.coronal_axes,'Zlim',ydata);
0878   set(AVWVIEW.handles.coronal_image,'Xdata',xdata);
0879   set(AVWVIEW.handles.coronal_image,'Ydata',zdata);
0880   daspect(AVWVIEW.handles.coronal_axes,aspect([1 3 2]));
0881 end;
0882 if isfield(AVWVIEW.handles,'sagittal_image'),
0883   set(AVWVIEW.handles.sagittal_axes,'Xlim',ydata);
0884   set(AVWVIEW.handles.sagittal_axes,'Ylim',zdata);
0885   set(AVWVIEW.handles.sagittal_axes,'Zlim',xdata);
0886   set(AVWVIEW.handles.sagittal_image,'Xdata',ydata);
0887   set(AVWVIEW.handles.sagittal_image,'Ydata',zdata);
0888   daspect(AVWVIEW.handles.sagittal_axes,aspect([2 3 1]));
0889 end;
0890 
0891 set(AVWVIEW.handles.sample_coronal_axes, 'position', [0.30 0.575 0.20 0.20]);
0892 set(AVWVIEW.handles.sample_axial_axes, 'position',   [0.30 0.075 0.20 0.20]);
0893 set(AVWVIEW.handles.sample_sagittal_axes, 'position',[0.80 0.575 0.20 0.20]);
0894 set_display_values(AVWVIEW);
0895 
0896 return
0897 
0898 
0899 
0900 
0901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0902 function AVWVIEW = get_current_position(AVWVIEW),
0903 
0904 %[AVWVIEW, metric] = slices2metric(AVWVIEW);
0905 
0906 if get(AVWVIEW.handles.coord,'value') == 3
0907     devide = 1000;
0908 else
0909     devide = 1;
0910 end
0911 
0912 switch AVWVIEW.view
0913   case 'sag',
0914     currentpoint = get(get(AVWVIEW.handles.sagittal_image,'Parent'),'CurrentPoint');
0915     metric.cor = currentpoint(1,1);
0916     metric.axi = currentpoint(1,2);
0917     metric.sag = get(AVWVIEW.handles.sagittal_slider,'Value') / devide;
0918   case 'cor',
0919     currentpoint = get(get(AVWVIEW.handles.coronal_image,'Parent'),'CurrentPoint');
0920     metric.sag = currentpoint(2,1);
0921     metric.axi = currentpoint(2,2);
0922     metric.cor = get(AVWVIEW.handles.coronal_slider,'Value') / devide;
0923   case 'axi',
0924     currentpoint = get(get(AVWVIEW.handles.axial_image,'Parent'),'CurrentPoint');
0925     metric.sag = currentpoint(2,1);
0926     metric.cor = currentpoint(2,2);
0927     metric.axi = get(AVWVIEW.handles.axial_slider,'Value') / devide;
0928 end
0929 AVWVIEW.metric = metric;
0930 AVWVIEW = metric2slices(AVWVIEW,metric);
0931 AVWVIEW = check_slices(AVWVIEW);
0932 
0933 return
0934 
0935 
0936 
0937 
0938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0939 function AVWVIEW = get_slider_position(AVWVIEW),
0940 
0941 [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi] = deal(0);
0942 
0943 if isfield(AVWVIEW.handles,'sagittal_slider'),
0944   if ishandle(AVWVIEW.handles.sagittal_slider),
0945     AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_slider,'Value'));
0946   end
0947 end
0948 if AVWVIEW.slices.sag == 0,
0949   if isfield(AVWVIEW.handles,'sagittal_sliderN'),
0950     if ishandle(AVWVIEW.handles.sagittal_sliderN),
0951       AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_sliderN,'Value'));
0952     end
0953   end
0954 end
0955 
0956 if isfield(AVWVIEW.handles,'coronal_slider'),
0957   if ishandle(AVWVIEW.handles.coronal_slider),
0958     AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_slider,'Value'));
0959   end
0960 end
0961 if AVWVIEW.slices.cor == 0,
0962   if isfield(AVWVIEW.handles,'coronal_sliderN'),
0963     if ishandle(AVWVIEW.handles.coronal_sliderN),
0964       AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_sliderN,'Value'));
0965     end
0966   end
0967 end
0968 
0969 if isfield(AVWVIEW.handles,'axial_slider'),
0970   if ishandle(AVWVIEW.handles.axial_slider),
0971     AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_slider,'Value'));
0972   end
0973 end
0974 if AVWVIEW.slices.axi == 0,
0975   if isfield(AVWVIEW.handles,'axial_sliderN'),
0976     if ishandle(AVWVIEW.handles.axial_sliderN),
0977       AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_sliderN,'Value'));
0978     end
0979   end
0980 end
0981 
0982 AVWVIEW = check_slices(AVWVIEW);
0983 
0984 return
0985 
0986 
0987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0988 function AVWVIEW = check_slices(AVWVIEW),
0989 
0990 adjust = 0;
0991 
0992 [ SagSize, CorSize, AxiSize ] = size(AVWVIEW.avw.img);
0993 
0994 if AVWVIEW.slices.sag > SagSize,
0995     AVWVIEW.slices.sag = SagSize;
0996     adjust = 1;
0997 end;
0998 if AVWVIEW.slices.sag < 1,
0999     AVWVIEW.slices.sag = 1;
1000     adjust = 1;
1001 end;
1002 if AVWVIEW.slices.cor > CorSize,
1003     AVWVIEW.slices.cor = CorSize;
1004     adjust = 1;
1005 end;
1006 if AVWVIEW.slices.cor < 1,
1007     AVWVIEW.slices.cor = 1;
1008     adjust = 1;
1009 end;
1010 if AVWVIEW.slices.axi > AxiSize,
1011     AVWVIEW.slices.axi = AxiSize;
1012     adjust = 1;
1013 end;
1014 if AVWVIEW.slices.axi < 1,
1015     AVWVIEW.slices.axi = 1;
1016     adjust = 1;
1017 end;
1018 
1019 if adjust,
1020     AVWVIEW = slices2metric(AVWVIEW);
1021 end
1022 
1023 return
1024 
1025 
1026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1027 function set_display_values(AVWVIEW),
1028 
1029 % get coordinates of selected voxel and the image intensity there
1030 
1031 sag = AVWVIEW.slices.sag;
1032 cor = AVWVIEW.slices.cor;
1033 axi = AVWVIEW.slices.axi;
1034 
1035 imgvalue = AVWVIEW.avw.img(sag,cor,axi);
1036 
1037 set(AVWVIEW.handles.imval,'String',sprintf('%7.2f',imgvalue));
1038 set(AVWVIEW.handles.imval,'Value',imgvalue);
1039 
1040 % Now update the image position text for the selected voxel
1041 
1042 [AVWVIEW, metric] = slices2metric(AVWVIEW);
1043 sag = metric.sag;
1044 cor = metric.cor;
1045 axi = metric.axi;
1046 
1047 string = sprintf('%7.3f %7.3f %7.3f',sag,cor,axi);
1048 
1049 set(AVWVIEW.handles.impos,'String',string);
1050 set(AVWVIEW.handles.impos,'Value',[sag,cor,axi]);
1051 
1052 return
1053 
1054 
1055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1056 function [AVWVIEW,metric] = slices2metric(AVWVIEW),
1057 
1058 AVWVIEW.imgXYZ.voxels = [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi];
1059 AVWVIEW.imgXYZ.meters = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2meters;
1060 AVWVIEW.imgXYZ.mm     = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2mm;
1061 
1062 coord_value = get(AVWVIEW.handles.coord,'value');
1063 
1064 if coord_value == 2,
1065   % using mm
1066   img_mm = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2mm;
1067   metric.axi = img_mm(3);
1068   metric.cor = img_mm(2);
1069   metric.sag = img_mm(1);
1070 elseif coord_value == 3,
1071   % using meters
1072   img_meters = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2meters;
1073   metric.axi = img_meters(3);
1074   metric.cor = img_meters(2);
1075   metric.sag = img_meters(1);
1076 else
1077   % voxels
1078   metric.axi = AVWVIEW.slices.axi;
1079   metric.cor = AVWVIEW.slices.cor;
1080   metric.sag = AVWVIEW.slices.sag;
1081 end;
1082 
1083 return
1084 
1085 
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 function AVWVIEW = metric2slices(AVWVIEW,metric),
1088 
1089 coord_value = get(AVWVIEW.handles.coord,'value');
1090 
1091 if coord_value == 2,
1092   % using mm
1093   xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2));
1094   ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3));
1095   zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4));
1096   AVWVIEW.slices.axi = round(metric.axi / zpix);
1097   AVWVIEW.slices.cor = round(metric.cor / ypix);
1098   AVWVIEW.slices.sag = round(metric.sag / xpix);
1099 elseif coord_value == 3,
1100   % using meters
1101   xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2)) / 1000;
1102   ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3)) / 1000;
1103   zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4)) / 1000;
1104   AVWVIEW.slices.axi = round(metric.axi / zpix);
1105   AVWVIEW.slices.cor = round(metric.cor / ypix);
1106   AVWVIEW.slices.sag = round(metric.sag / xpix);
1107 else
1108   % voxels
1109   AVWVIEW.slices.axi = round(metric.axi);
1110   AVWVIEW.slices.cor = round(metric.cor);
1111   AVWVIEW.slices.sag = round(metric.sag);
1112 end;
1113 
1114 return
1115 
1116 
1117 
1118 
1119 
1120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1121 function AVWVIEW = init(avw,invarname),
1122 
1123 % try to keep track of the input struct
1124 if exist('invarname','var'),
1125   if ~isempty(invarname),
1126     AVWVIEW.invarname = invarname;
1127   else
1128     AVWVIEW.invarname = '';
1129   end
1130 else
1131   AVWVIEW.invarname = '';
1132 end
1133 
1134 % GUI General Parameters
1135 GUIwidth  = 1;
1136 GUIheight = 1/3;
1137 
1138 version = '[$Revision: 1202 $]';
1139 name = sprintf('Sphere head [v%s]',version(12:16));
1140 
1141 if isfield(avw,'fileprefix'),
1142   if ~isempty(avw.fileprefix),
1143     format = strcat('%+',sprintf('%d',length(avw.fileprefix)+1),'s');
1144     name = strcat(name,' - ',sprintf(format,avw.fileprefix));
1145   end
1146 end
1147 
1148 % The Zbuffer provides smooth slice animations (OpenGL is no good)
1149 GUI = figure('Name',name,'Tag','AVWVIEW','Units','Normalized',...
1150   'BackingStore','off',...
1151   'NumberTitle','off','color',[0 0 0],...
1152   'MenuBar','figure','Position',[0 0.1 1.0 0.8],...
1153   'Renderer','zbuffer');
1154 
1155 movegui(GUI,'center');
1156 
1157 set(GUI,'KeyPressFcn','vb_sphere_head([],[],''keypress'');');
1158 
1159 AVWVIEW.gui = GUI;
1160 
1161 Font.FontName   = 'Helvetica';
1162 Font.FontUnits  = 'Pixels';
1163 Font.FontSize   = 15;
1164 Font.FontWeight = 'normal';
1165 Font.FontAngle  = 'normal';
1166 
1167 
1168 AVWVIEW.shading = 'flat';
1169 shading(AVWVIEW.shading)
1170 
1171 
1172 
1173 %     % determine the datatype of avw.img
1174 %     switch double(avw.hdr.dime.bitpix),
1175 %     case 1,
1176 %         fprintf('...converting avw.img to uint8 for viewing only.\n\n');
1177 %         avw.img = uint8(avw.img);
1178 %     case 8,
1179 %         fprintf('...converting avw.img to uint8 for viewing only.\n\n');
1180 %         avw.img = uint8(avw.img);
1181 %     case 16,
1182 %         fprintf('...converting avw.img to uint16 for viewing only.\n\n');
1183 %         avw.img = uint16(avw.img);
1184 %     case {32,64},
1185 %         % make sure it is double, not single
1186 %         avw.img = double(avw.img);
1187 %     otherwise,
1188 %         % do nothing, leave it as is
1189 %     end
1190 
1191 
1192 % calculate image stats
1193 intensityMean = mean(mean(mean(avw.img)));
1194 intensityMeanRobust = mean(mean(mean(avw.img(find(avw.img)))));
1195 intensityStdev = std(std(std(avw.img)));
1196 
1197 intensityMax = max(max(max(avw.img)));
1198 
1199 % try to adjust for large intensity extremes
1200 if intensityMax > 255,
1201   % got 16 bit data, at least
1202   adjust = 0.5;
1203 else
1204   adjust = 0.9;
1205 end
1206 %AVWVIEW.clim = [0 (intensityMeanRobust + (10 * intensityStdev)) ];
1207 AVWVIEW.clim = [0 (intensityMax * adjust)];
1208 
1209 
1210 
1211 AVWVIEW.xdim = size(avw.img,1);
1212 AVWVIEW.ydim = size(avw.img,2);
1213 AVWVIEW.zdim = size(avw.img,3);
1214 
1215 AVWVIEW.slices.sag = 1;
1216 AVWVIEW.slices.cor = 1;
1217 AVWVIEW.slices.axi = 1;
1218 if AVWVIEW.xdim > 1, AVWVIEW.slices.sag = floor(AVWVIEW.xdim/2); end
1219 if AVWVIEW.ydim > 1, AVWVIEW.slices.cor = floor(AVWVIEW.ydim/2); end
1220 if AVWVIEW.zdim > 1, AVWVIEW.slices.axi = floor(AVWVIEW.zdim/2); end
1221 
1222 % store the volume center for later reference when
1223 % calculating fiducial locations
1224 center = avw_center(avw);
1225 AVWVIEW.center = center.abs.voxels;
1226 
1227 % set the default origin at the center
1228 AVWVIEW.origin  = AVWVIEW.center;
1229 
1230 AVWVIEW.pixdim = double(avw.hdr.dime.pixdim(2:4));
1231 
1232 AVWVIEW.scale2mm     = AVWVIEW.pixdim;          % vol scale in mm
1233 AVWVIEW.scale2meters = AVWVIEW.pixdim ./ 1000;  % vol scale in meters
1234 AVWVIEW.daspect      = AVWVIEW.pixdim ./ min(AVWVIEW.pixdim);
1235 
1236 xPlotSize = 0.38;
1237 yPlotSize = 0.38;
1238 
1239 AVWVIEW.cmapString = 'gray';
1240 
1241 AVWVIEW.cmap = colormap(AVWVIEW.cmapString);
1242 
1243 %
1244 %--- Sphere Model Data
1245 %
1246 
1247 % sphere center and radius;
1248 AVWVIEW.sphere_data = struct;
1249 AVWVIEW.sphere_data.radius = [];
1250 AVWVIEW.sphere_data.center = [];
1251 
1252 % selected point coordinate value and line object handles
1253 AVWVIEW.sphere_data.selected_point = struct;
1254 AVWVIEW.sphere_data.selected_point.axial_point = [];
1255 AVWVIEW.sphere_data.selected_point.axial_component = [];% line object handle
1256 
1257 AVWVIEW.sphere_data.selected_point.coronal_point = [];
1258 AVWVIEW.sphere_data.selected_point.coronal_component = [];% line object handle
1259 
1260 AVWVIEW.sphere_data.selected_point.sagittal_point = [];
1261 AVWVIEW.sphere_data.selected_point.sagittal_component = [];% line object handle
1262 
1263 % line object handles for preview sphere
1264 AVWVIEW.sphere_data.display_component = struct;
1265 AVWVIEW.sphere_data.display_component.axial = [];
1266 AVWVIEW.sphere_data.display_component.coronal = [];
1267 AVWVIEW.sphere_data.display_component.sagittal = [];
1268 
1269 % return sphere data
1270 AVWVIEW.avw.radius = [];
1271 AVWVIEW.avw.center = [];
1272 
1273 % Initial value inputted
1274 if isfield(avw, 'sphere_on_spm_right_m')
1275     Vdim = [AVWVIEW.xdim, AVWVIEW.ydim, AVWVIEW.zdim];
1276     Vsize = AVWVIEW.pixdim;
1277     sphere = avw.sphere_on_spm_right_m;
1278     center = vb_spm_right_to_analyze_right_mm(sphere.center, Vdim, Vsize);
1279     radius = sphere.radius .* 1000;
1280     AVWVIEW.sphere_data.radius = radius;
1281     AVWVIEW.sphere_data.center = center;
1282 end
1283 
1284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1285 
1286 % Axial Slice
1287 if AVWVIEW.xdim > 1 & AVWVIEW.ydim > 1,
1288   
1289   handles.axial_subplot = subplot('position',[0.035 0.075 xPlotSize yPlotSize]);
1290   
1291   %avw.img = flipdim(avw.img,1);
1292   % add hayashi change default coordinate left handed to right handed.
1293   
1294   Saxial = squeeze(avw.img(:,:,AVWVIEW.slices.axi));
1295   
1296   %handles.axial_image = pcolor(double(Saxial)); colormap(gray); shading interp
1297   %pcolor(Saxial'); colormap(gray); shading flat
1298   
1299   %surf(avw.img(:,:,20)','edgecolor','none'); view(2); axis tight; colormap(flipdim(gray,1)); colorbar
1300   %surf(avw.img(:,:,20)','edgecolor','none'); view(2); axis tight; colormap(gray)
1301   %image(avw.img(:,:,20)'); axis image; colormap(gray)
1302   %imagesc(avw.img(:,:,20)'); axis image; colormap(gray)
1303   
1304   %handles.axial_image = image('Cdata',Saxial','CDataMapping','scaled',...
1305   %    'XData',[0 xdim],'YData',[0 ydim]);
1306   
1307   handles.axial_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.ydim],Saxial',AVWVIEW.clim);
1308   
1309   handles.axial_axes = gca;
1310   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1311     'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1312   
1313   title('Axial','Color',[1 1 1])
1314   ylabel('Y')
1315   xlabel('left ----- X ----- right')
1316   
1317   
1318 %xlabel('(Right <<) X (>> Left)'); % default radiological orientation for Analyze
1319   %xlabel('(Left <<) X (>> Right)')
1320   
1321   % This callback navigates with mouse button click
1322   set(handles.axial_image,'ButtonDownFcn','vb_sphere_head([],[],''axial_image'');');
1323   
1324   %sample image
1325   RGB = imread('axial.png');
1326   handles.sample_axial_axes = subplot('position', [0.035+xPlotSize, 0.075 0.01 0.01]);
1327   image(RGB);
1328   axis image;
1329 
1330   GUIheight = 0.46;
1331   
1332   if AVWVIEW.zdim > 1,
1333     slider_step(1) = 1/(AVWVIEW.zdim);
1334     slider_step(2) = 1/(AVWVIEW.zdim);
1335     handles.axial_slider = uicontrol('Parent',GUI,'Style','slider',...
1336       'Units','Normalized', Font, ...
1337       'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1338       'BusyAction','queue',...
1339       'TooltipString','Axial slice navigation',...
1340       'Min',1,'Max',AVWVIEW.zdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.axi,...
1341       'Callback','vb_sphere_head([],[],''axial_slider'');');
1342   end
1343   handles.axial_sliderN = uicontrol('Parent',GUI,'Style','text',...
1344     'Units','Normalized', Font, ...
1345     'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1346     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1347     'BusyAction','queue',...
1348     'TooltipString','Axial slice number',...
1349     'String',num2str(AVWVIEW.slices.axi),'Value',AVWVIEW.slices.axi);
1350   handles.axial_sliderT = uicontrol('Parent',GUI,'Style','text',...
1351     'Units','Normalized', Font, ...
1352     'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1353     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1354     'BusyAction','queue',...
1355     'TooltipString','Axial slice navigation',...
1356     'String','Axial');
1357   set(AVWVIEW.gui, 'CurrentAxes', handles.axial_subplot);
1358   handles.axial_xlim = get(handles.axial_axes,'Xlim');
1359   handles.axial_ylim = get(handles.axial_axes,'Ylim');
1360   handles.axial_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],'Ydata',handles.axial_ylim);
1361   handles.axial_yline = line('Ydata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],'Xdata',handles.axial_xlim);
1362   set(handles.axial_xline,'Color','b','EraseMode','xor','Tag','XLINE', 'Visible', 'off');
1363   set(handles.axial_yline,'Color','b','EraseMode','xor','Tag','YLINE', 'Visible', 'off');
1364   
1365 end
1366 
1367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1368 
1369 % Coronal Slice
1370 if AVWVIEW.xdim > 1 & AVWVIEW.zdim > 1,
1371   
1372   handles.coronal_subplot = subplot('position',[0.035 0.575 xPlotSize yPlotSize]);
1373   
1374   Scor = squeeze(avw.img(:,AVWVIEW.slices.cor,:));
1375   handles.coronal_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.zdim],Scor',AVWVIEW.clim);
1376   handles.coronal_axes = gca;
1377   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1378     'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1379   
1380   %xlabel('(Left <<) X (>> Right)')
1381   %xlabel('(Right <<) X (>> Left)')
1382   xlabel('left ----- X ----- right')
1383   ylabel('Z')
1384   title('Coronal','Color',[1 1 1])
1385   
1386   %sample image
1387   RGB = imread('coronal.png');
1388   handles.sample_coronal_axes = subplot('position', [0.035+xPlotSize, 0.575 0.01 0.01]);
1389   image(RGB);
1390   axis image;
1391   
1392   % This callback navigates with left click
1393   set(handles.coronal_image,'ButtonDownFcn','vb_sphere_head([],[],''coronal_image'');');
1394   
1395   GUIheight = GUIheight - 0.04;
1396   
1397   if AVWVIEW.ydim > 1,
1398     slider_step(1) = 1/(AVWVIEW.ydim);
1399     slider_step(2) = 1/(AVWVIEW.ydim);
1400     handles.coronal_slider = uicontrol('Parent',GUI,'Style','slider',...
1401       'Units','Normalized', Font, ...
1402       'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1403       'BusyAction','queue',...
1404       'TooltipString','Coronal slice navigation',...
1405       'Min',1,'Max',AVWVIEW.ydim,'SliderStep',slider_step,'Value',AVWVIEW.slices.cor,...
1406       'Callback','vb_sphere_head([],[],''coronal_slider'');');
1407   end
1408   handles.coronal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1409     'Units','Normalized', Font, ...
1410     'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1411     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1412     'BusyAction','queue',...
1413     'TooltipString','Coronal slice number',...
1414     'String',num2str(AVWVIEW.slices.cor),'Value',AVWVIEW.slices.cor);
1415   handles.coronal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1416     'Units','Normalized', Font, ...
1417     'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1418     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1419     'BusyAction','queue',...
1420     'TooltipString','Coronal slice navigation',...
1421     'String','Coronal');
1422   
1423   set(AVWVIEW.gui, 'CurrentAxes', handles.coronal_subplot);
1424   handles.coronal_xlim = get(handles.coronal_axes,'Xlim');
1425   handles.coronal_ylim = get(handles.coronal_axes,'Ylim');
1426   handles.coronal_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],'Ydata',handles.coronal_ylim);
1427   handles.coronal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],'Xdata',handles.coronal_xlim);
1428   set(handles.coronal_xline,'Color','b','EraseMode','xor','Tag','XLINE', 'Visible', 'off');
1429   set(handles.coronal_yline,'Color','b','EraseMode','xor','Tag','YLINE', 'Visible', 'off');
1430   
1431 end
1432 
1433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1434 
1435 % Sagittal Slice
1436 if AVWVIEW.ydim > 1 & AVWVIEW.zdim > 1,
1437   
1438   handles.sagittal_subplot = subplot('position',[0.50 0.575 xPlotSize yPlotSize]);
1439   
1440   Ssag = squeeze(avw.img(AVWVIEW.slices.sag,:,:));
1441   handles.sagittal_image = imagesc([0,AVWVIEW.ydim],[0,AVWVIEW.zdim],Ssag',AVWVIEW.clim);
1442   
1443   handles.sagittal_axes = gca;
1444   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1445     'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1446   
1447   xlabel('Y')
1448   ylabel('Z')
1449   title('Sagittal','Color',[1 1 1])
1450   
1451   % This callback navigates with mouse click
1452   set(handles.sagittal_image,'ButtonDownFcn','vb_sphere_head([],[],''sagittal_image'');');
1453 
1454   %sample image
1455   RGB = imread('sagittal.png');
1456   handles.sample_sagittal_axes = subplot('position', [0.50+xPlotSize, 0.575 0.01 0.01]);
1457   image(RGB);
1458   axis image;
1459   
1460   GUIheight = GUIheight - 0.04;
1461   
1462   if AVWVIEW.xdim > 1,
1463     slider_step(1) = 1/(AVWVIEW.xdim);
1464     slider_step(2) = 1/(AVWVIEW.xdim);
1465     handles.sagittal_slider = uicontrol('Parent',GUI,'Style','slider',...
1466       'Units','Normalized', Font, ...
1467       'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1468       'BusyAction','queue',...
1469       'TooltipString','Sagittal slice navigation',...
1470       'Min',1,'Max',AVWVIEW.xdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.sag,...
1471       'Callback','vb_sphere_head([],[],''sagittal_slider'');');
1472   end
1473   handles.sagittal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1474     'Units','Normalized', Font, ...
1475     'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1476     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1477     'BusyAction','queue',...
1478     'TooltipString','Sagittal slice number',...
1479     'String',num2str(AVWVIEW.slices.sag),'Value',AVWVIEW.slices.sag);
1480   handles.sagittal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1481     'Units','Normalized', Font, ...
1482     'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1483     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1484     'BusyAction','queue',...
1485     'TooltipString','Sagittal slice navigation',...
1486     'String','Sagittal');
1487   
1488   set(AVWVIEW.gui, 'CurrentAxes', handles.sagittal_subplot);
1489   handles.sagittal_xlim = get(handles.sagittal_axes,'Xlim');
1490   handles.sagittal_ylim = get(handles.sagittal_axes,'Ylim');
1491   handles.sagittal_xline = line('Xdata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],'Ydata',handles.sagittal_ylim);
1492   handles.sagittal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],'Xdata',handles.sagittal_xlim);
1493   set(handles.sagittal_xline,'Color','b','EraseMode','xor','Tag','XLINE', 'Visible', 'off');
1494   set(handles.sagittal_yline,'Color','b','EraseMode','xor','Tag','YLINE', 'Visible', 'off');
1495   
1496 end
1497 
1498 
1499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1501 % Image Contex Menus
1502 
1503 menu=uicontextmenu;
1504 
1505 % enable right click access to ROI tools
1506 roi = uimenu(menu,'Label','ROI');
1507 uimenu(roi,'Label','ROI (9x9x9 block)','Callback','vb_sphere_head([],[],''roi_9'');');
1508 uimenu(roi,'Label','ROI (7x7x7 block)','Callback','vb_sphere_head([],[],''roi_7'');');
1509 uimenu(roi,'Label','ROI (5x5x5 block)','Callback','vb_sphere_head([],[],''roi_5'');');
1510 uimenu(roi,'Label','ROI (3x3x3 block)','Callback','vb_sphere_head([],[],''roi_3'');');
1511 
1512 % save image to graphics file
1513 uimenu(menu,'Label','Save Image','Callback','vb_sphere_head([],[],''save_image'');');
1514 
1515 % zoom image to new figure
1516 uimenu(menu,'Label','Zoom Image','Callback','vb_sphere_head([],[],''zoom'');');
1517 
1518 if isfield(handles,'axial_image'),
1519   if isempty(get(handles.axial_image,'uicontextmenu')),
1520     set(handles.axial_image,'uicontextmenu',menu);
1521   end
1522 end
1523 if isfield(handles,'coronal_image'),
1524   if isempty(get(handles.coronal_image,'uicontextmenu')),
1525     set(handles.coronal_image,'uicontextmenu',menu);
1526   end
1527 end
1528 if isfield(handles,'sagittal_image'),
1529   if isempty(get(handles.sagittal_image,'uicontextmenu')),
1530     set(handles.sagittal_image,'uicontextmenu',menu);
1531   end
1532 end
1533 
1534 
1535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1537 
1538 % Image Intensity at Mouse Click
1539 
1540 GUIheight = GUIheight - 0.04;
1541 
1542 handles.Timval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1543   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1544   'BackgroundColor', [0 0 0],...
1545   'ForegroundColor', [1 1 1],...
1546   'BusyAction','queue',...
1547   'String','Image Intensity');
1548 handles.imval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1549   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1550   'BackgroundColor', [0 0 0],...
1551   'ForegroundColor', [1 1 1],...
1552   'BusyAction','queue',...
1553   'String','x','Value',0);
1554 
1555 % Image Position at Mouse Click
1556 
1557 GUIheight = GUIheight - 0.04;
1558 
1559 handles.Timpos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1560   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1561   'BackgroundColor', [0 0 0],...
1562   'ForegroundColor', [1 1 1],...
1563   'BusyAction','queue',...
1564   'String','Image Position');
1565 handles.impos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1566   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1567   'BackgroundColor', [0 0 0],...
1568   'ForegroundColor', [1 1 1],...
1569   'BusyAction','queue',...
1570   'String','xyz','Value',[0 0 0]);
1571 
1572 
1573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1575 
1576 GUIheight = GUIheight - 0.04;
1577 
1578 %handles.flip = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1579 %  'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1580 %  'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1581 %  'BusyAction','queue',...
1582 %  'TooltipString','Flip Left and Right (viewer only, see also avw_flip).',...
1583 %  'String','Flip L/R',...
1584 %  'Callback','vb_sphere_head([],[],''flip'');');
1585 handles.flipStatus = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1586   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1587   'BackgroundColor', [0 0 0],...
1588   'ForegroundColor', [1 1 1],...
1589   'BusyAction','queue',...
1590   'TooltipString','Flipped Status',...
1591   'String','L>>R (neurological)');
1592 
1593 
1594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1596 
1597 
1598 % Sphere calculation button
1599 GUIheight = GUIheight - 0.04;
1600 
1601 handles.Tsphere_calculation = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1602   'Position',[.55 GUIheight .12 .03], 'HorizontalAlignment', 'left',...
1603   'BackgroundColor', [0.95 0.64 0],...
1604   'ForegroundColor', [0 0 0],...
1605   'BusyAction','queue',...
1606   'TooltipString','Sphere calculation',...
1607   'String','calculate sphere',...
1608   'Callback','vb_sphere_head([],[],''calc_sphere'');');
1609 
1610 %
1611 % Remove point buttons
1612 %
1613 
1614 % remove coronal points
1615 GUIheight = GUIheight - 0.04;
1616 handles.Tremove_coronal_point = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1617   'Position',[.55 GUIheight .12 .03], 'HorizontalAlignment', 'left',...
1618   'BackgroundColor', [0.18 0.54 0.52],...
1619   'ForegroundColor', [0 0 0],...
1620   'BusyAction','queue',...
1621   'TooltipString','remove selected points on coronal slice',...
1622   'String','remove coronal points',...
1623   'Callback','vb_sphere_head([],[],''remove_coronal_point'');');
1624 
1625 % remove axial points
1626 GUIheight = GUIheight - 0.04;
1627 handles.Tremove_axial_point = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1628   'Position',[.55 GUIheight .12 .03], 'HorizontalAlignment', 'left',...
1629   'BackgroundColor', [0.18 0.54 0.52],...
1630   'ForegroundColor', [0 0 0],...
1631   'BusyAction','queue',...
1632   'TooltipString','remove selected points on axial slice',...
1633   'String','remove axial points',...
1634   'Callback','vb_sphere_head([],[],''remove_axial_point'');');
1635 
1636 % remove sagittal points
1637 GUIheight = GUIheight - 0.04;
1638 handles.Tremove_sagittal_point = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1639   'Position',[.55 GUIheight .12 .03], 'HorizontalAlignment', 'left',...
1640   'BackgroundColor', [0.18 0.54 0.52],...
1641   'ForegroundColor', [0 0 0],...
1642   'BusyAction','queue',...
1643   'TooltipString','remove selected points on sagittal slice',...
1644   'String','remove sagittal points',...
1645   'Callback','vb_sphere_head([],[],''remove_sagittal_point'');');
1646 
1647 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1649 
1650 %GUIheight = GUIheight - 0.04;
1651 
1652 %handles.contrast = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1653 %  'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1654 %  'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1655 %  'BusyAction','queue',...
1656 %  'TooltipString','Auto contrast with gray colormap',...
1657 %  'String','Auto Contrast',...
1658 %  'Callback','vb_sphere_head([],[],''contrast'');');
1659 
1660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1662 
1663 GUIheight = GUIheight - 0.04;
1664 
1665 handles.dimmer = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1666   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1667   'BackgroundColor', [.75 .75 .75],'ForegroundColor', [0 0 0],...
1668   'BusyAction','queue',...
1669   'TooltipString','Dim by 1%',...
1670   'String','Dimmer',...
1671   'Callback','vb_sphere_head([],[],''dimmer'');');
1672 
1673 handles.brighter = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1674   'Position',[.65 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1675   'BackgroundColor', [.75 .75 .75],'ForegroundColor', [0 0 0],...
1676   'BusyAction','queue',...
1677   'TooltipString','Brighten by 1%',...
1678   'String','Brighter',...
1679   'Callback','vb_sphere_head([],[],''brighter'');');
1680 
1681 handles.clim = uicontrol('Parent',GUI,'Style','edit','Units','Normalized', Font, ...
1682   'Position',[.75 GUIheight .06 .03], 'HorizontalAlignment', 'right',...
1683   'BackgroundColor', [0 0 0],...
1684   'ForegroundColor', [1 1 1],...
1685   'BusyAction','queue',...
1686   'TooltipString','Image intensity Climit (inverse brightness)',...
1687   'String',num2str(AVWVIEW.clim(2)),...
1688   'Callback','vb_sphere_head([],[],''setClimit'');');
1689 
1690 handles.cmap = uicontrol('Parent',GUI,'Style','popup','Units','Normalized', Font, ...
1691   'Position',[.82 GUIheight .06 .03], 'HorizontalAlignment', 'left',...
1692   'BackgroundColor', [0 0 0],...
1693   'ForegroundColor', [1 1 1],...
1694   'BusyAction','queue',...
1695   'TooltipString','Color Map',...
1696   'String',{'gray','bone','copper','hot','cool','spring','summer','autumn','winter','hsv','jet'},...
1697   'Callback','vb_sphere_head([],[],''setCmap'');');
1698 
1699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1701 
1702 GUIheight = 0.46;
1703 
1704 handles.crosshairs = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
1705   'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1706   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1707   'BusyAction','queue',...
1708   'TooltipString','Toggle Crosshairs on/off',...
1709   'String','Crosshairs','Value',0,...
1710   'Callback','vb_sphere_head([],[],''crosshairs'');');
1711 
1712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1714 
1715 GUIheight = GUIheight - 0.04;
1716 
1717 handles.histogram = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1718   'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1719   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1720   'BusyAction','queue',...
1721   'TooltipString','Histogram of Volume Intensity',...
1722   'String','Histogram',...
1723   'Callback','vb_sphere_head([],[],''histogram'');');
1724 
1725 
1726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1728 
1729 GUIheight = GUIheight - 0.04;
1730 
1731 handles.coord = uicontrol('Parent',GUI,'Style','popupmenu','Units','Normalized', Font, ...
1732   'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1733   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1734   'BusyAction','queue',...
1735   'TooltipString','Voxel or Mensurated Axis Coordinates',...
1736   'String',{'Voxels','mm','meters'},...
1737   'Value', 2,...
1738   'Callback','vb_sphere_head([],[],''coordinates'');');
1739 
1740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1742 
1743 Font.FontWeight = 'bold';
1744 
1745 % View avw.hdr
1746 % handles.Bhdr = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1747 %   'Position',[.90 .09 .09 .03],...
1748 %   'String','HDR','BusyAction','queue',...
1749 %   'TooltipString','View the .hdr parameters.',...
1750 %   'BackgroundColor',[0.0 0.0 0.5],...
1751 %   'ForegroundColor',[0 0 0], 'HorizontalAlignment', 'center',...
1752 %   'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
1753 %   'avw_view_hdr(AVWVIEW.avw,AVWVIEW.gui);',...
1754 %   'clear AVWVIEW;'));
1755 
1756 % Save: Save fiducials
1757 %handles.Bquit =
1758 %uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1759 %  'Position',[.70 .01 .15 .05],...
1760 %  'String','Save fiducials','BusyAction','queue',...
1761 %  'BackgroundColor',[0.0 0.5 0.0],...
1762 %  'ForegroundColor', [0 0 0], 'HorizontalAlignment', 'center',...
1763 %  'Callback','vb_sphere_head([],[],''save'');');
1764 
1765 % Close: application end
1766 handles.Bclose = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1767   'Position',[.88 .01 .10 .05],...
1768   'String','OK','BusyAction','queue',...
1769   'BackgroundColor',[0.0 0.5 0.0],...
1770   'ForegroundColor', [0 0 0], 'HorizontalAlignment', 'center',...
1771   'Callback','vb_sphere_head([],[],''close'');');
1772 
1773 % Update the gui_struct handles for this gui
1774 if exist('parent','var'), AVWVIEW.parent.gui = parent; end
1775 AVWVIEW.avw = avw;
1776 AVWVIEW.handles = handles;
1777 set(AVWVIEW.gui,'Userdata',AVWVIEW);
1778 
1779 % Update sphere
1780 if exist('center', 'var') && exist('radius', 'var')
1781     AVWVIEW = vb_plot_sphere(AVWVIEW, center, radius);
1782 end
1783 
1784 
1785 set(AVWVIEW.gui,'HandleVisibility','callback');
1786 
1787 return
1788 
1789 
1790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1791 function slice_img(avw),
1792 
1793 figure
1794 xslice = 128;
1795 slice = squeeze( avw.img(xslice,:,:) );
1796 imagesc(slice); axis image; colormap('gray')
1797 figure
1798 yslice = 128;
1799 slice = squeeze( avw.img(:,yslice,:) );
1800 imagesc(slice); axis image; colormap('gray')
1801 figure
1802 zslice = 128;
1803 slice = squeeze( avw.img(:,:,zslice) );
1804 imagesc(slice); axis image; colormap('gray')
1805 
1806 return
1807 
1808 function AVWVIEW = calc_sphere(AVWVIEW)
1809 % This function calculate and displaying sphere circle.
1810 % [IN]
1811 %    AVWVIEW : data store structure of this application.
1812 % [OUT]
1813 %    AVWVIEW : data store structure of this application.
1814 %      .sphere_data
1815 %        .center % sphere center position on coordinate of this application.
1816 %        .radius % sphere radius
1817 %        .display_component
1818 %          .axial    % display component of axial circle line.
1819 %          .coronal  %          -        of coronal  -
1820 %          .sagittal %          -        of sagittal -
1821 
1822 
1823 % remove past caluculation result
1824 AVWVIEW = remove_sphere(AVWVIEW);
1825 
1826 %
1827 % -- calculate sphere
1828 %
1829 point_structure = AVWVIEW.sphere_data.selected_point;
1830 selected_point = [point_structure.axial_point;...
1831                   point_structure.coronal_point;...
1832                   point_structure.sagittal_point];
1833 
1834 [center, r] = vb_center_sphere(selected_point);
1835 if ~isempty(center)
1836     AVWVIEW.sphere_data.center = center;
1837     AVWVIEW.sphere_data.radius = r;
1838     AVWVIEW = vb_plot_sphere(AVWVIEW, center, r);
1839 end
1840 
1841 function AVWVIEW = vb_plot_sphere(AVWVIEW, center, r)
1842 % [IN]
1843 %    AVWVIEW : data store structure of this application.
1844 %    center  : center of sphere.
1845 %          r : radius of sphere.
1846 % [OUT]
1847 %    AVWVIEW.sphere_data
1848 %           ==> .display_component
1849 %                   .axial    % display component of axial circle line.
1850 %                   .coronal  %          -        of coronal  -
1851 %                   .sagittal %          -        of sagittal -
1852 
1853 %
1854 %--- make Circle line component
1855 %
1856 T = 0:pi./100:2.*pi;
1857 point_color = 'yellow';
1858 % coronal line component
1859 X = r*cos(T) + center(1); Y = r*sin(T) + center(3);
1860 set(AVWVIEW.gui, 'CurrentAxes', AVWVIEW.handles.coronal_axes);
1861 h = line(X, Y, 'Color', point_color, 'Visible', 'on');
1862 h = [h; line(center(1), center(3), 'Color', point_color,...
1863          'Marker', '.', 'MarkerSize', 10, 'Visible', 'on')];
1864 AVWVIEW.sphere_data.display_component.axial = h;
1865 % axial line component
1866 X = r*cos(T) + center(1); Y = r*sin(T) + center(2);
1867 set(AVWVIEW.gui, 'CurrentAxes', AVWVIEW.handles.axial_axes);
1868 h = line(X, Y, 'Color', point_color, 'Visible', 'on');
1869 h = [h; line(center(1), center(2), 'Color', point_color,...
1870          'Marker', '.', 'MarkerSize', 10, 'Visible', 'on')];
1871 AVWVIEW.sphere_data.display_component.coronal = h;
1872 % sagittal line component
1873 X = r*cos(T) + center(2); Y = r*sin(T) + center(3);
1874 set(AVWVIEW.gui, 'CurrentAxes', AVWVIEW.handles.sagittal_axes);
1875 h = line(X, Y, 'Color', point_color, 'Visible', 'on');
1876 h = [h; line(center(2), center(3), 'Color', point_color,...
1877          'Marker', '.', 'MarkerSize', 10, 'Visible', 'on')];
1878 AVWVIEW.sphere_data.display_component.sagittal = h;
1879 
1880 function AVWVIEW = remove_sphere(AVWVIEW)
1881 % This function removes sphere circle line on screen.
1882 % [IN]
1883 %    AVWVIEW : data store structure of this application.
1884 % [OUT]
1885 %    AVWVIEW : data store structure of this application.
1886 %              remove data is as below.
1887 %      .sphere_data
1888 %         .display_component
1889 %            .axial    : display component of axial circle line.
1890 %            .coronal  :          -        of coronal  -
1891 %            .sagittal :          -        of sagittal -
1892 
1893 h = AVWVIEW.sphere_data.display_component.axial;
1894 h = [h;AVWVIEW.sphere_data.display_component.coronal];
1895 h = [h;AVWVIEW.sphere_data.display_component.sagittal];
1896 AVWVIEW.sphere_data.display_component.coronal = [];
1897 AVWVIEW.sphere_data.display_component.axial = [];
1898 AVWVIEW.sphere_data.display_component.sagittal = [];
1899 delete(h);
1900 
1901 function AVWVIEW = remove_selected_point(AVWVIEW, face)
1902 % This function removes data and view selected point.
1903 % [IN]
1904 %    AVWVIEW : data store structure of this application.
1905 %    face    : target of remove data.
1906 % [OUT]
1907 %    AVWVIEW : data store structure of this application.
1908 %              remove data is as below.
1909 %      .sphere_data
1910 %         .selected_point
1911 %            .axial_point       % selected coordinate value on axial slice
1912 %            .coronal_point     %              -               coronal  -
1913 %            .sagittal_point    %              -               sagittal -
1914 %            .axial_component   % display component on axial slice
1915 %            .coronal_component %              -       coronal  -
1916 %            .sagittal_component%              -       sagittal -
1917 %
1918 switch(face)
1919     case 'axial'
1920         delete(AVWVIEW.sphere_data.selected_point.axial_component);
1921         AVWVIEW.sphere_data.selected_point.axial_component = [];
1922         AVWVIEW.sphere_data.selected_point.axial_point = [];
1923     case 'coronal'
1924         delete(AVWVIEW.sphere_data.selected_point.coronal_component);
1925         AVWVIEW.sphere_data.selected_point.coronal_component = [];
1926         AVWVIEW.sphere_data.selected_point.coronal_point = [];
1927     case 'sagittal'
1928         delete(AVWVIEW.sphere_data.selected_point.sagittal_component);
1929         AVWVIEW.sphere_data.selected_point.sagittal_component = [];
1930         AVWVIEW.sphere_data.selected_point.sagittal_point = [];
1931     case 'unselected_status_point'
1932         p = AVWVIEW.sphere_data.selected_point;
1933         % sagittal slice
1934         h = findobj(p.sagittal_component, 'Color', 'blue');
1935         if ~isempty(h)
1936             idx = [];
1937             for k=1:length(h)
1938                 idx = [idx; find(p.sagittal_component == h(k))];
1939             end
1940             delete(h);
1941             AVWVIEW.sphere_data.selected_point.sagittal_component(idx, :) = [];
1942             AVWVIEW.sphere_data.selected_point.sagittal_point(idx, :) = [];
1943         end
1944         
1945         % coronal slice
1946         h = findobj(p.coronal_component, 'Color', 'blue');
1947         if ~isempty(h)
1948             idx = [];
1949             for k=1:length(h)
1950                 idx = [idx; find(p.coronal_component == h(k))];
1951             end
1952             delete(h);
1953             AVWVIEW.sphere_data.selected_point.coronal_component(idx, :) = [];
1954             AVWVIEW.sphere_data.selected_point.coronal_point(idx, :) = [];
1955         end
1956         
1957         % axial slice
1958         h = findobj(p.axial_component, 'Color', 'blue');
1959         if ~isempty(h)
1960             idx = [];
1961             for k=1:length(h)
1962                 idx = [idx; find(p.axial_component == h(k))];
1963             end
1964             delete(h);
1965             AVWVIEW.sphere_data.selected_point.axial_component(idx, :) = [];
1966             AVWVIEW.sphere_data.selected_point.axial_point(idx, :) = [];
1967         end
1968 end
1969 AVWVIEW = remove_sphere(AVWVIEW);
1970 
1971 function AVWVIEW = set_selected_point(AVWVIEW)
1972 % This function sets the selected point to AVWVIEW structure.
1973 % [IN]
1974 %    AVWVIEW : data store structure of this application.
1975 % [OUT]
1976 %    AVWVIEW : data store structure of this application.
1977 %      .sphere_data
1978 %         .selected_point
1979 %            .axial_point       % selected coordinate value on axial slice
1980 %            .coronal_point     %              -               coronal  -
1981 %            .sagittal_point    %              -               sagittal -
1982 %            .axial_component   % display component on axial slice
1983 %            .coronal_component %              -       coronal  -
1984 %            .sagittal_component%              -       sagittal -
1985 
1986 marker_size = 15;
1987 line_style = '.';
1988 point_color = 'red';
1989 
1990 X = AVWVIEW.metric.sag;
1991 Y = AVWVIEW.metric.cor;
1992 Z = AVWVIEW.metric.axi;
1993 
1994 point = [X, Y, Z];
1995 
1996 switch AVWVIEW.view
1997     case 'axi'
1998           h = line('Xdata', X, 'Ydata', Y, ...
1999                    'MarkerSize', marker_size, 'Marker', line_style, 'Color', point_color, 'ButtonDownFcn', 'vb_sphere_head([],[],''point_state_reverse'');');
2000           AVWVIEW.sphere_data.selected_point.axial_point = [AVWVIEW.sphere_data.selected_point.axial_point;point];
2001           AVWVIEW.sphere_data.selected_point.axial_component =[AVWVIEW.sphere_data.selected_point.axial_component;h];
2002     case 'cor'
2003           h = line('Xdata', X, 'Ydata', Z, ...
2004                    'MarkerSize', marker_size, 'Marker', line_style, 'Color', point_color, 'ButtonDownFcn', 'vb_sphere_head([],[],''point_state_reverse'');');
2005           AVWVIEW.sphere_data.selected_point.coronal_point = [AVWVIEW.sphere_data.selected_point.coronal_point;point];
2006           AVWVIEW.sphere_data.selected_point.coronal_component = [AVWVIEW.sphere_data.selected_point.coronal_component;h];
2007     case 'sag'
2008           h = line('Xdata', Y, 'Ydata', Z, ...
2009                    'MarkerSize', marker_size, 'Marker', line_style, 'Color', point_color, 'ButtonDownFcn', 'vb_sphere_head([],[],''point_state_reverse'');');
2010           AVWVIEW.sphere_data.selected_point.sagittal_point = [AVWVIEW.sphere_data.selected_point.sagittal_point;point];
2011           AVWVIEW.sphere_data.selected_point.sagittal_component = [AVWVIEW.sphere_data.selected_point.sagittal_component;h];
2012 end

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005