Home > vbmeg > 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: 2026 $ $Date:: 2021-09-01 11:59:14 +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 ~isempty(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','y','Tag','XLINE');
0757   set(AVWVIEW.handles.axial_yline,'Color','y','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','y','Tag','XLINE');
0785   set(AVWVIEW.handles.coronal_yline,'Color','y','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','y','Tag','XLINE');
0812   set(AVWVIEW.handles.sagittal_yline,'Color','y','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 switch AVWVIEW.view
0907   case 'sag',
0908     currentpoint = get(get(AVWVIEW.handles.sagittal_image,'Parent'),'CurrentPoint');
0909     metric.cor = currentpoint(1,1);
0910     metric.axi = currentpoint(1,2);
0911     metric.sag = get(AVWVIEW.handles.sagittal_slider,'Value') * AVWVIEW.scale2mm(1);
0912   case 'cor',
0913     currentpoint = get(get(AVWVIEW.handles.coronal_image,'Parent'),'CurrentPoint');
0914     metric.sag = currentpoint(2,1);
0915     metric.axi = currentpoint(2,2);
0916     metric.cor = get(AVWVIEW.handles.coronal_slider,'Value') * AVWVIEW.scale2mm(2);
0917   case 'axi',
0918     currentpoint = get(get(AVWVIEW.handles.axial_image,'Parent'),'CurrentPoint');
0919     metric.sag = currentpoint(2,1);
0920     metric.cor = currentpoint(2,2);
0921     metric.axi = get(AVWVIEW.handles.axial_slider,'Value') * AVWVIEW.scale2mm(3);
0922 end
0923 AVWVIEW.metric = metric;
0924 AVWVIEW = metric2slices(AVWVIEW,metric);
0925 AVWVIEW = check_slices(AVWVIEW);
0926 
0927 return
0928 
0929 
0930 
0931 
0932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0933 function AVWVIEW = get_slider_position(AVWVIEW),
0934 
0935 [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi] = deal(0);
0936 
0937 if isfield(AVWVIEW.handles,'sagittal_slider'),
0938   if ishandle(AVWVIEW.handles.sagittal_slider),
0939     AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_slider,'Value'));
0940   end
0941 end
0942 if AVWVIEW.slices.sag == 0,
0943   if isfield(AVWVIEW.handles,'sagittal_sliderN'),
0944     if ishandle(AVWVIEW.handles.sagittal_sliderN),
0945       AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_sliderN,'Value'));
0946     end
0947   end
0948 end
0949 
0950 if isfield(AVWVIEW.handles,'coronal_slider'),
0951   if ishandle(AVWVIEW.handles.coronal_slider),
0952     AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_slider,'Value'));
0953   end
0954 end
0955 if AVWVIEW.slices.cor == 0,
0956   if isfield(AVWVIEW.handles,'coronal_sliderN'),
0957     if ishandle(AVWVIEW.handles.coronal_sliderN),
0958       AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_sliderN,'Value'));
0959     end
0960   end
0961 end
0962 
0963 if isfield(AVWVIEW.handles,'axial_slider'),
0964   if ishandle(AVWVIEW.handles.axial_slider),
0965     AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_slider,'Value'));
0966   end
0967 end
0968 if AVWVIEW.slices.axi == 0,
0969   if isfield(AVWVIEW.handles,'axial_sliderN'),
0970     if ishandle(AVWVIEW.handles.axial_sliderN),
0971       AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_sliderN,'Value'));
0972     end
0973   end
0974 end
0975 
0976 AVWVIEW = check_slices(AVWVIEW);
0977 
0978 return
0979 
0980 
0981 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0982 function AVWVIEW = check_slices(AVWVIEW),
0983 
0984 adjust = 0;
0985 
0986 [ SagSize, CorSize, AxiSize ] = size(AVWVIEW.avw.img);
0987 
0988 if AVWVIEW.slices.sag > SagSize,
0989     AVWVIEW.slices.sag = SagSize;
0990     adjust = 1;
0991 end;
0992 if AVWVIEW.slices.sag < 1,
0993     AVWVIEW.slices.sag = 1;
0994     adjust = 1;
0995 end;
0996 if AVWVIEW.slices.cor > CorSize,
0997     AVWVIEW.slices.cor = CorSize;
0998     adjust = 1;
0999 end;
1000 if AVWVIEW.slices.cor < 1,
1001     AVWVIEW.slices.cor = 1;
1002     adjust = 1;
1003 end;
1004 if AVWVIEW.slices.axi > AxiSize,
1005     AVWVIEW.slices.axi = AxiSize;
1006     adjust = 1;
1007 end;
1008 if AVWVIEW.slices.axi < 1,
1009     AVWVIEW.slices.axi = 1;
1010     adjust = 1;
1011 end;
1012 
1013 if adjust,
1014     AVWVIEW = slices2metric(AVWVIEW);
1015 end
1016 
1017 return
1018 
1019 
1020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1021 function set_display_values(AVWVIEW),
1022 
1023 % get coordinates of selected voxel and the image intensity there
1024 
1025 sag = AVWVIEW.slices.sag;
1026 cor = AVWVIEW.slices.cor;
1027 axi = AVWVIEW.slices.axi;
1028 
1029 imgvalue = AVWVIEW.avw.img(sag,cor,axi);
1030 
1031 set(AVWVIEW.handles.imval,'String',sprintf('%7.2f',imgvalue));
1032 set(AVWVIEW.handles.imval,'Value',imgvalue);
1033 
1034 % Now update the image position text for the selected voxel
1035 
1036 [AVWVIEW, metric] = slices2metric(AVWVIEW);
1037 sag = metric.sag;
1038 cor = metric.cor;
1039 axi = metric.axi;
1040 
1041 string = sprintf('%7.3f %7.3f %7.3f',sag,cor,axi);
1042 
1043 set(AVWVIEW.handles.impos,'String',string);
1044 set(AVWVIEW.handles.impos,'Value',[sag,cor,axi]);
1045 
1046 return
1047 
1048 
1049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1050 function [AVWVIEW,metric] = slices2metric(AVWVIEW),
1051 
1052 AVWVIEW.imgXYZ.voxels = [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi];
1053 AVWVIEW.imgXYZ.meters = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2meters;
1054 AVWVIEW.imgXYZ.mm     = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2mm;
1055 
1056 coord_value = get(AVWVIEW.handles.coord,'value');
1057 
1058 if coord_value == 2,
1059   % using mm
1060   img_mm = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2mm;
1061   metric.axi = img_mm(3);
1062   metric.cor = img_mm(2);
1063   metric.sag = img_mm(1);
1064 elseif coord_value == 3,
1065   % using meters
1066   img_meters = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2meters;
1067   metric.axi = img_meters(3);
1068   metric.cor = img_meters(2);
1069   metric.sag = img_meters(1);
1070 else
1071   % voxels
1072   metric.axi = AVWVIEW.slices.axi;
1073   metric.cor = AVWVIEW.slices.cor;
1074   metric.sag = AVWVIEW.slices.sag;
1075 end;
1076 
1077 return
1078 
1079 
1080 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081 function AVWVIEW = metric2slices(AVWVIEW,metric),
1082 
1083 coord_value = get(AVWVIEW.handles.coord,'value');
1084 
1085 if coord_value == 2,
1086   % using mm
1087   xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2));
1088   ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3));
1089   zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4));
1090   AVWVIEW.slices.axi = round(metric.axi / zpix);
1091   AVWVIEW.slices.cor = round(metric.cor / ypix);
1092   AVWVIEW.slices.sag = round(metric.sag / xpix);
1093 elseif coord_value == 3,
1094   % using meters
1095   xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2)) / 1000;
1096   ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3)) / 1000;
1097   zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4)) / 1000;
1098   AVWVIEW.slices.axi = round(metric.axi / zpix);
1099   AVWVIEW.slices.cor = round(metric.cor / ypix);
1100   AVWVIEW.slices.sag = round(metric.sag / xpix);
1101 else
1102   % voxels
1103   AVWVIEW.slices.axi = round(metric.axi);
1104   AVWVIEW.slices.cor = round(metric.cor);
1105   AVWVIEW.slices.sag = round(metric.sag);
1106 end;
1107 
1108 return
1109 
1110 
1111 
1112 
1113 
1114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1115 function AVWVIEW = init(avw,invarname),
1116 
1117 % try to keep track of the input struct
1118 if exist('invarname','var'),
1119   if ~isempty(invarname),
1120     AVWVIEW.invarname = invarname;
1121   else
1122     AVWVIEW.invarname = '';
1123   end
1124 else
1125   AVWVIEW.invarname = '';
1126 end
1127 
1128 % GUI General Parameters
1129 GUIwidth  = 1;
1130 GUIheight = 1/3;
1131 
1132 version = '[$Revision: 2026 $]';
1133 name = sprintf('Sphere head [v%s]',version(12:16));
1134 
1135 if isfield(avw,'fileprefix'),
1136   if ~isempty(avw.fileprefix),
1137     format = strcat('%+',sprintf('%d',length(avw.fileprefix)+1),'s');
1138     name = strcat(name,' - ',sprintf(format,avw.fileprefix));
1139   end
1140 end
1141 
1142 % The Zbuffer provides smooth slice animations (OpenGL is no good)
1143 GUI = figure('Name',name,'Tag','AVWVIEW','Units','Normalized',...
1144   'BackingStore','off',...
1145   'NumberTitle','off','color',[0 0 0],...
1146   'MenuBar','figure','Position',[0 0.1 1.0 0.8],...
1147   'Renderer','zbuffer');
1148 
1149 movegui(GUI,'center');
1150 
1151 set(GUI,'KeyPressFcn','vb_sphere_head([],[],''keypress'');');
1152 
1153 AVWVIEW.gui = GUI;
1154 
1155 Font.FontName   = 'Helvetica';
1156 Font.FontUnits  = 'Pixels';
1157 Font.FontSize   = 15;
1158 Font.FontWeight = 'normal';
1159 Font.FontAngle  = 'normal';
1160 
1161 
1162 AVWVIEW.shading = 'flat';
1163 shading(AVWVIEW.shading)
1164 
1165 
1166 
1167 %     % determine the datatype of avw.img
1168 %     switch double(avw.hdr.dime.bitpix),
1169 %     case 1,
1170 %         fprintf('...converting avw.img to uint8 for viewing only.\n\n');
1171 %         avw.img = uint8(avw.img);
1172 %     case 8,
1173 %         fprintf('...converting avw.img to uint8 for viewing only.\n\n');
1174 %         avw.img = uint8(avw.img);
1175 %     case 16,
1176 %         fprintf('...converting avw.img to uint16 for viewing only.\n\n');
1177 %         avw.img = uint16(avw.img);
1178 %     case {32,64},
1179 %         % make sure it is double, not single
1180 %         avw.img = double(avw.img);
1181 %     otherwise,
1182 %         % do nothing, leave it as is
1183 %     end
1184 
1185 
1186 % calculate image stats
1187 intensityMean = mean(mean(mean(avw.img)));
1188 intensityMeanRobust = mean(mean(mean(avw.img(find(avw.img)))));
1189 intensityStdev = std(std(std(avw.img)));
1190 
1191 intensityMax = max(max(max(avw.img)));
1192 
1193 % try to adjust for large intensity extremes
1194 if intensityMax > 255,
1195   % got 16 bit data, at least
1196   adjust = 0.5;
1197 else
1198   adjust = 0.9;
1199 end
1200 %AVWVIEW.clim = [0 (intensityMeanRobust + (10 * intensityStdev)) ];
1201 AVWVIEW.clim = [0 (intensityMax * adjust)];
1202 
1203 
1204 
1205 AVWVIEW.xdim = size(avw.img,1);
1206 AVWVIEW.ydim = size(avw.img,2);
1207 AVWVIEW.zdim = size(avw.img,3);
1208 
1209 AVWVIEW.slices.sag = 1;
1210 AVWVIEW.slices.cor = 1;
1211 AVWVIEW.slices.axi = 1;
1212 if AVWVIEW.xdim > 1, AVWVIEW.slices.sag = floor(AVWVIEW.xdim/2); end
1213 if AVWVIEW.ydim > 1, AVWVIEW.slices.cor = floor(AVWVIEW.ydim/2); end
1214 if AVWVIEW.zdim > 1, AVWVIEW.slices.axi = floor(AVWVIEW.zdim/2); end
1215 
1216 % store the volume center for later reference when
1217 % calculating fiducial locations
1218 center = avw_center(avw);
1219 AVWVIEW.center = center.abs.voxels;
1220 
1221 % set the default origin at the center
1222 AVWVIEW.origin  = AVWVIEW.center;
1223 
1224 AVWVIEW.pixdim = double(avw.hdr.dime.pixdim(2:4));
1225 
1226 AVWVIEW.scale2mm     = AVWVIEW.pixdim;          % vol scale in mm
1227 AVWVIEW.scale2meters = AVWVIEW.pixdim ./ 1000;  % vol scale in meters
1228 AVWVIEW.daspect      = AVWVIEW.pixdim ./ min(AVWVIEW.pixdim);
1229 
1230 xPlotSize = 0.38;
1231 yPlotSize = 0.38;
1232 
1233 AVWVIEW.cmapString = 'gray';
1234 
1235 AVWVIEW.cmap = colormap(AVWVIEW.cmapString);
1236 
1237 %
1238 %--- Sphere Model Data
1239 %
1240 
1241 % sphere center and radius;
1242 AVWVIEW.sphere_data = struct;
1243 AVWVIEW.sphere_data.radius = [];
1244 AVWVIEW.sphere_data.center = [];
1245 
1246 % selected point coordinate value and line object handles
1247 AVWVIEW.sphere_data.selected_point = struct;
1248 AVWVIEW.sphere_data.selected_point.axial_point = [];
1249 AVWVIEW.sphere_data.selected_point.axial_component = [];% line object handle
1250 
1251 AVWVIEW.sphere_data.selected_point.coronal_point = [];
1252 AVWVIEW.sphere_data.selected_point.coronal_component = [];% line object handle
1253 
1254 AVWVIEW.sphere_data.selected_point.sagittal_point = [];
1255 AVWVIEW.sphere_data.selected_point.sagittal_component = [];% line object handle
1256 
1257 % line object handles for preview sphere
1258 AVWVIEW.sphere_data.display_component = struct;
1259 AVWVIEW.sphere_data.display_component.axial = [];
1260 AVWVIEW.sphere_data.display_component.coronal = [];
1261 AVWVIEW.sphere_data.display_component.sagittal = [];
1262 
1263 % return sphere data
1264 AVWVIEW.avw.radius = [];
1265 AVWVIEW.avw.center = [];
1266 
1267 % Initial value inputted
1268 if isfield(avw, 'sphere_on_spm_right_m')
1269     Vdim = [AVWVIEW.xdim, AVWVIEW.ydim, AVWVIEW.zdim];
1270     Vsize = AVWVIEW.pixdim;
1271     sphere = avw.sphere_on_spm_right_m;
1272     center = vb_spm_right_to_analyze_right_mm(sphere.center, Vdim, Vsize);
1273     radius = sphere.radius .* 1000;
1274     AVWVIEW.sphere_data.radius = radius;
1275     AVWVIEW.sphere_data.center = center;
1276 end
1277 
1278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279 
1280 % Axial Slice
1281 if AVWVIEW.xdim > 1 & AVWVIEW.ydim > 1,
1282   
1283   handles.axial_subplot = subplot('position',[0.035 0.075 xPlotSize yPlotSize]);
1284   
1285   %avw.img = flipdim(avw.img,1);
1286   % add hayashi change default coordinate left handed to right handed.
1287   
1288   Saxial = squeeze(avw.img(:,:,AVWVIEW.slices.axi));
1289   
1290   %handles.axial_image = pcolor(double(Saxial)); colormap(gray); shading interp
1291   %pcolor(Saxial'); colormap(gray); shading flat
1292   
1293   %surf(avw.img(:,:,20)','edgecolor','none'); view(2); axis tight; colormap(flipdim(gray,1)); colorbar
1294   %surf(avw.img(:,:,20)','edgecolor','none'); view(2); axis tight; colormap(gray)
1295   %image(avw.img(:,:,20)'); axis image; colormap(gray)
1296   %imagesc(avw.img(:,:,20)'); axis image; colormap(gray)
1297   
1298   %handles.axial_image = image('Cdata',Saxial','CDataMapping','scaled',...
1299   %    'XData',[0 xdim],'YData',[0 ydim]);
1300   
1301   handles.axial_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.ydim],Saxial',AVWVIEW.clim);
1302   
1303   handles.axial_axes = gca;
1304   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1305     'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1306   
1307   title('Axial','Color',[1 1 1])
1308   ylabel('Y')
1309   xlabel('left ----- X ----- right')
1310   
1311   
1312 %xlabel('(Right <<) X (>> Left)'); % default radiological orientation for Analyze
1313   %xlabel('(Left <<) X (>> Right)')
1314   
1315   % This callback navigates with mouse button click
1316   set(handles.axial_image,'ButtonDownFcn','vb_sphere_head([],[],''axial_image'');');
1317   
1318   %sample image
1319   RGB = imread('axial.png');
1320   handles.sample_axial_axes = subplot('position', [0.035+xPlotSize, 0.075 0.01 0.01]);
1321   image(RGB);
1322   axis image;
1323 
1324   GUIheight = 0.46;
1325   
1326   if AVWVIEW.zdim > 1,
1327     slider_step(1) = 1/(AVWVIEW.zdim);
1328     slider_step(2) = 1/(AVWVIEW.zdim);
1329     handles.axial_slider = uicontrol('Parent',GUI,'Style','slider',...
1330       'Units','Normalized', Font, ...
1331       'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1332       'BusyAction','queue',...
1333       'TooltipString','Axial slice navigation',...
1334       'Min',1,'Max',AVWVIEW.zdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.axi,...
1335       'Callback','vb_sphere_head([],[],''axial_slider'');');
1336   end
1337   handles.axial_sliderN = uicontrol('Parent',GUI,'Style','text',...
1338     'Units','Normalized', Font, ...
1339     'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1340     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1341     'BusyAction','queue',...
1342     'TooltipString','Axial slice number',...
1343     'String',num2str(AVWVIEW.slices.axi),'Value',AVWVIEW.slices.axi);
1344   handles.axial_sliderT = uicontrol('Parent',GUI,'Style','text',...
1345     'Units','Normalized', Font, ...
1346     'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1347     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1348     'BusyAction','queue',...
1349     'TooltipString','Axial slice navigation',...
1350     'String','Axial');
1351   set(AVWVIEW.gui, 'CurrentAxes', handles.axial_subplot);
1352   handles.axial_xlim = get(handles.axial_axes,'Xlim');
1353   handles.axial_ylim = get(handles.axial_axes,'Ylim');
1354   handles.axial_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],'Ydata',handles.axial_ylim);
1355   handles.axial_yline = line('Ydata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],'Xdata',handles.axial_xlim);
1356   set(handles.axial_xline,'Color','y','Tag','XLINE', 'Visible', 'off');
1357   set(handles.axial_yline,'Color','y','Tag','YLINE', 'Visible', 'off');
1358   
1359 end
1360 
1361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1362 
1363 % Coronal Slice
1364 if AVWVIEW.xdim > 1 & AVWVIEW.zdim > 1,
1365   
1366   handles.coronal_subplot = subplot('position',[0.035 0.575 xPlotSize yPlotSize]);
1367   
1368   Scor = squeeze(avw.img(:,AVWVIEW.slices.cor,:));
1369   handles.coronal_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.zdim],Scor',AVWVIEW.clim);
1370   handles.coronal_axes = gca;
1371   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1372     'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1373   
1374   %xlabel('(Left <<) X (>> Right)')
1375   %xlabel('(Right <<) X (>> Left)')
1376   xlabel('left ----- X ----- right')
1377   ylabel('Z')
1378   title('Coronal','Color',[1 1 1])
1379   
1380   %sample image
1381   RGB = imread('coronal.png');
1382   handles.sample_coronal_axes = subplot('position', [0.035+xPlotSize, 0.575 0.01 0.01]);
1383   image(RGB);
1384   axis image;
1385   
1386   % This callback navigates with left click
1387   set(handles.coronal_image,'ButtonDownFcn','vb_sphere_head([],[],''coronal_image'');');
1388   
1389   GUIheight = GUIheight - 0.04;
1390   
1391   if AVWVIEW.ydim > 1,
1392     slider_step(1) = 1/(AVWVIEW.ydim);
1393     slider_step(2) = 1/(AVWVIEW.ydim);
1394     handles.coronal_slider = uicontrol('Parent',GUI,'Style','slider',...
1395       'Units','Normalized', Font, ...
1396       'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1397       'BusyAction','queue',...
1398       'TooltipString','Coronal slice navigation',...
1399       'Min',1,'Max',AVWVIEW.ydim,'SliderStep',slider_step,'Value',AVWVIEW.slices.cor,...
1400       'Callback','vb_sphere_head([],[],''coronal_slider'');');
1401   end
1402   handles.coronal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1403     'Units','Normalized', Font, ...
1404     'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1405     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1406     'BusyAction','queue',...
1407     'TooltipString','Coronal slice number',...
1408     'String',num2str(AVWVIEW.slices.cor),'Value',AVWVIEW.slices.cor);
1409   handles.coronal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1410     'Units','Normalized', Font, ...
1411     'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1412     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1413     'BusyAction','queue',...
1414     'TooltipString','Coronal slice navigation',...
1415     'String','Coronal');
1416   
1417   set(AVWVIEW.gui, 'CurrentAxes', handles.coronal_subplot);
1418   handles.coronal_xlim = get(handles.coronal_axes,'Xlim');
1419   handles.coronal_ylim = get(handles.coronal_axes,'Ylim');
1420   handles.coronal_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],'Ydata',handles.coronal_ylim);
1421   handles.coronal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],'Xdata',handles.coronal_xlim);
1422   set(handles.coronal_xline,'Color','y','Tag','XLINE', 'Visible', 'off');
1423   set(handles.coronal_yline,'Color','y','Tag','YLINE', 'Visible', 'off');
1424   
1425 end
1426 
1427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1428 
1429 % Sagittal Slice
1430 if AVWVIEW.ydim > 1 & AVWVIEW.zdim > 1,
1431   
1432   handles.sagittal_subplot = subplot('position',[0.50 0.575 xPlotSize yPlotSize]);
1433   
1434   Ssag = squeeze(avw.img(AVWVIEW.slices.sag,:,:));
1435   handles.sagittal_image = imagesc([0,AVWVIEW.ydim],[0,AVWVIEW.zdim],Ssag',AVWVIEW.clim);
1436   
1437   handles.sagittal_axes = gca;
1438   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1439     'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1440   
1441   xlabel('Y')
1442   ylabel('Z')
1443   title('Sagittal','Color',[1 1 1])
1444   
1445   % This callback navigates with mouse click
1446   set(handles.sagittal_image,'ButtonDownFcn','vb_sphere_head([],[],''sagittal_image'');');
1447 
1448   %sample image
1449   RGB = imread('sagittal.png');
1450   handles.sample_sagittal_axes = subplot('position', [0.50+xPlotSize, 0.575 0.01 0.01]);
1451   image(RGB);
1452   axis image;
1453   
1454   GUIheight = GUIheight - 0.04;
1455   
1456   if AVWVIEW.xdim > 1,
1457     slider_step(1) = 1/(AVWVIEW.xdim);
1458     slider_step(2) = 1/(AVWVIEW.xdim);
1459     handles.sagittal_slider = uicontrol('Parent',GUI,'Style','slider',...
1460       'Units','Normalized', Font, ...
1461       'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1462       'BusyAction','queue',...
1463       'TooltipString','Sagittal slice navigation',...
1464       'Min',1,'Max',AVWVIEW.xdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.sag,...
1465       'Callback','vb_sphere_head([],[],''sagittal_slider'');');
1466   end
1467   handles.sagittal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1468     'Units','Normalized', Font, ...
1469     'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1470     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1471     'BusyAction','queue',...
1472     'TooltipString','Sagittal slice number',...
1473     'String',num2str(AVWVIEW.slices.sag),'Value',AVWVIEW.slices.sag);
1474   handles.sagittal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1475     'Units','Normalized', Font, ...
1476     'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1477     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1478     'BusyAction','queue',...
1479     'TooltipString','Sagittal slice navigation',...
1480     'String','Sagittal');
1481   
1482   set(AVWVIEW.gui, 'CurrentAxes', handles.sagittal_subplot);
1483   handles.sagittal_xlim = get(handles.sagittal_axes,'Xlim');
1484   handles.sagittal_ylim = get(handles.sagittal_axes,'Ylim');
1485   handles.sagittal_xline = line('Xdata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],'Ydata',handles.sagittal_ylim);
1486   handles.sagittal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],'Xdata',handles.sagittal_xlim);
1487   set(handles.sagittal_xline,'Color','y','Tag','XLINE', 'Visible', 'off');
1488   set(handles.sagittal_yline,'Color','y','Tag','YLINE', 'Visible', 'off');
1489   
1490 end
1491 
1492 
1493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1495 % Image Contex Menus
1496 
1497 menu=uicontextmenu;
1498 
1499 % enable right click access to ROI tools
1500 roi = uimenu(menu,'Label','ROI');
1501 uimenu(roi,'Label','ROI (9x9x9 block)','Callback','vb_sphere_head([],[],''roi_9'');');
1502 uimenu(roi,'Label','ROI (7x7x7 block)','Callback','vb_sphere_head([],[],''roi_7'');');
1503 uimenu(roi,'Label','ROI (5x5x5 block)','Callback','vb_sphere_head([],[],''roi_5'');');
1504 uimenu(roi,'Label','ROI (3x3x3 block)','Callback','vb_sphere_head([],[],''roi_3'');');
1505 
1506 % save image to graphics file
1507 uimenu(menu,'Label','Save Image','Callback','vb_sphere_head([],[],''save_image'');');
1508 
1509 % zoom image to new figure
1510 uimenu(menu,'Label','Zoom Image','Callback','vb_sphere_head([],[],''zoom'');');
1511 
1512 if isfield(handles,'axial_image'),
1513   if isempty(get(handles.axial_image,'uicontextmenu')),
1514     set(handles.axial_image,'uicontextmenu',menu);
1515   end
1516 end
1517 if isfield(handles,'coronal_image'),
1518   if isempty(get(handles.coronal_image,'uicontextmenu')),
1519     set(handles.coronal_image,'uicontextmenu',menu);
1520   end
1521 end
1522 if isfield(handles,'sagittal_image'),
1523   if isempty(get(handles.sagittal_image,'uicontextmenu')),
1524     set(handles.sagittal_image,'uicontextmenu',menu);
1525   end
1526 end
1527 
1528 
1529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1531 
1532 % Image Intensity at Mouse Click
1533 
1534 GUIheight = GUIheight - 0.04;
1535 
1536 handles.Timval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1537   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1538   'BackgroundColor', [0 0 0],...
1539   'ForegroundColor', [1 1 1],...
1540   'BusyAction','queue',...
1541   'String','Image Intensity');
1542 handles.imval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1543   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1544   'BackgroundColor', [0 0 0],...
1545   'ForegroundColor', [1 1 1],...
1546   'BusyAction','queue',...
1547   'String','x','Value',0);
1548 
1549 % Image Position at Mouse Click
1550 
1551 GUIheight = GUIheight - 0.04;
1552 
1553 handles.Timpos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1554   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1555   'BackgroundColor', [0 0 0],...
1556   'ForegroundColor', [1 1 1],...
1557   'BusyAction','queue',...
1558   'String','Image Position');
1559 handles.impos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1560   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1561   'BackgroundColor', [0 0 0],...
1562   'ForegroundColor', [1 1 1],...
1563   'BusyAction','queue',...
1564   'String','xyz','Value',[0 0 0]);
1565 
1566 
1567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1569 
1570 GUIheight = GUIheight - 0.04;
1571 
1572 %handles.flip = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1573 %  'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1574 %  'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1575 %  'BusyAction','queue',...
1576 %  'TooltipString','Flip Left and Right (viewer only, see also avw_flip).',...
1577 %  'String','Flip L/R',...
1578 %  'Callback','vb_sphere_head([],[],''flip'');');
1579 handles.flipStatus = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1580   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1581   'BackgroundColor', [0 0 0],...
1582   'ForegroundColor', [1 1 1],...
1583   'BusyAction','queue',...
1584   'TooltipString','Flipped Status',...
1585   'String','L>>R (neurological)');
1586 
1587 
1588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1590 
1591 
1592 % Sphere calculation button
1593 GUIheight = GUIheight - 0.04;
1594 
1595 handles.Tsphere_calculation = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1596   'Position',[.55 GUIheight .12 .03], 'HorizontalAlignment', 'left',...
1597   'BackgroundColor', [0.95 0.64 0],...
1598   'ForegroundColor', [0 0 0],...
1599   'BusyAction','queue',...
1600   'TooltipString','Sphere calculation',...
1601   'String','calculate sphere',...
1602   'Callback','vb_sphere_head([],[],''calc_sphere'');');
1603 
1604 %
1605 % Remove point buttons
1606 %
1607 
1608 % remove coronal points
1609 GUIheight = GUIheight - 0.04;
1610 handles.Tremove_coronal_point = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1611   'Position',[.55 GUIheight .12 .03], 'HorizontalAlignment', 'left',...
1612   'BackgroundColor', [0.18 0.54 0.52],...
1613   'ForegroundColor', [0 0 0],...
1614   'BusyAction','queue',...
1615   'TooltipString','remove selected points on coronal slice',...
1616   'String','remove coronal points',...
1617   'Callback','vb_sphere_head([],[],''remove_coronal_point'');');
1618 
1619 % remove axial points
1620 GUIheight = GUIheight - 0.04;
1621 handles.Tremove_axial_point = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1622   'Position',[.55 GUIheight .12 .03], 'HorizontalAlignment', 'left',...
1623   'BackgroundColor', [0.18 0.54 0.52],...
1624   'ForegroundColor', [0 0 0],...
1625   'BusyAction','queue',...
1626   'TooltipString','remove selected points on axial slice',...
1627   'String','remove axial points',...
1628   'Callback','vb_sphere_head([],[],''remove_axial_point'');');
1629 
1630 % remove sagittal points
1631 GUIheight = GUIheight - 0.04;
1632 handles.Tremove_sagittal_point = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1633   'Position',[.55 GUIheight .12 .03], 'HorizontalAlignment', 'left',...
1634   'BackgroundColor', [0.18 0.54 0.52],...
1635   'ForegroundColor', [0 0 0],...
1636   'BusyAction','queue',...
1637   'TooltipString','remove selected points on sagittal slice',...
1638   'String','remove sagittal points',...
1639   'Callback','vb_sphere_head([],[],''remove_sagittal_point'');');
1640 
1641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1643 
1644 %GUIheight = GUIheight - 0.04;
1645 
1646 %handles.contrast = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1647 %  'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1648 %  'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1649 %  'BusyAction','queue',...
1650 %  'TooltipString','Auto contrast with gray colormap',...
1651 %  'String','Auto Contrast',...
1652 %  'Callback','vb_sphere_head([],[],''contrast'');');
1653 
1654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1656 
1657 GUIheight = GUIheight - 0.04;
1658 
1659 handles.dimmer = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1660   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1661   'BackgroundColor', [.75 .75 .75],'ForegroundColor', [0 0 0],...
1662   'BusyAction','queue',...
1663   'TooltipString','Dim by 1%',...
1664   'String','Dimmer',...
1665   'Callback','vb_sphere_head([],[],''dimmer'');');
1666 
1667 handles.brighter = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1668   'Position',[.65 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1669   'BackgroundColor', [.75 .75 .75],'ForegroundColor', [0 0 0],...
1670   'BusyAction','queue',...
1671   'TooltipString','Brighten by 1%',...
1672   'String','Brighter',...
1673   'Callback','vb_sphere_head([],[],''brighter'');');
1674 
1675 handles.clim = uicontrol('Parent',GUI,'Style','edit','Units','Normalized', Font, ...
1676   'Position',[.75 GUIheight .06 .03], 'HorizontalAlignment', 'right',...
1677   'BackgroundColor', [0 0 0],...
1678   'ForegroundColor', [1 1 1],...
1679   'BusyAction','queue',...
1680   'TooltipString','Image intensity Climit (inverse brightness)',...
1681   'String',num2str(AVWVIEW.clim(2)),...
1682   'Callback','vb_sphere_head([],[],''setClimit'');');
1683 
1684 handles.cmap = uicontrol('Parent',GUI,'Style','popup','Units','Normalized', Font, ...
1685   'Position',[.82 GUIheight .06 .03], 'HorizontalAlignment', 'left',...
1686   'BackgroundColor', [0 0 0],...
1687   'ForegroundColor', [1 1 1],...
1688   'BusyAction','queue',...
1689   'TooltipString','Color Map',...
1690   'String',{'gray','bone','copper','hot','cool','spring','summer','autumn','winter','hsv','jet'},...
1691   'Callback','vb_sphere_head([],[],''setCmap'');');
1692 
1693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1695 
1696 GUIheight = 0.46;
1697 
1698 handles.crosshairs = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
1699   'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1700   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1701   'BusyAction','queue',...
1702   'TooltipString','Toggle Crosshairs on/off',...
1703   'String','Crosshairs','Value',0,...
1704   'Callback','vb_sphere_head([],[],''crosshairs'');');
1705 
1706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1708 
1709 GUIheight = GUIheight - 0.04;
1710 
1711 handles.histogram = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1712   'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1713   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1714   'BusyAction','queue',...
1715   'TooltipString','Histogram of Volume Intensity',...
1716   'String','Histogram',...
1717   'Callback','vb_sphere_head([],[],''histogram'');');
1718 
1719 
1720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1721 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1722 
1723 GUIheight = GUIheight - 0.04;
1724 
1725 handles.coord = uicontrol('Parent',GUI,'Style','popupmenu','Units','Normalized', Font, ...
1726   'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1727   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [0 0 0],...
1728   'BusyAction','queue',...
1729   'TooltipString','Voxel or Mensurated Axis Coordinates',...
1730   'String',{'Voxels','mm','meters'},...
1731   'Value', 2,...
1732   'Callback','vb_sphere_head([],[],''coordinates'');');
1733 
1734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1736 
1737 Font.FontWeight = 'bold';
1738 
1739 % View avw.hdr
1740 % handles.Bhdr = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1741 %   'Position',[.90 .09 .09 .03],...
1742 %   'String','HDR','BusyAction','queue',...
1743 %   'TooltipString','View the .hdr parameters.',...
1744 %   'BackgroundColor',[0.0 0.0 0.5],...
1745 %   'ForegroundColor',[0 0 0], 'HorizontalAlignment', 'center',...
1746 %   'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
1747 %   'avw_view_hdr(AVWVIEW.avw,AVWVIEW.gui);',...
1748 %   'clear AVWVIEW;'));
1749 
1750 % Save: Save fiducials
1751 %handles.Bquit =
1752 %uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1753 %  'Position',[.70 .01 .15 .05],...
1754 %  'String','Save fiducials','BusyAction','queue',...
1755 %  'BackgroundColor',[0.0 0.5 0.0],...
1756 %  'ForegroundColor', [0 0 0], 'HorizontalAlignment', 'center',...
1757 %  'Callback','vb_sphere_head([],[],''save'');');
1758 
1759 % Close: application end
1760 handles.Bclose = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1761   'Position',[.88 .01 .10 .05],...
1762   'String','OK','BusyAction','queue',...
1763   'BackgroundColor',[0.0 0.5 0.0],...
1764   'ForegroundColor', [0 0 0], 'HorizontalAlignment', 'center',...
1765   'Callback','vb_sphere_head([],[],''close'');');
1766 
1767 % Update the gui_struct handles for this gui
1768 if exist('parent','var'), AVWVIEW.parent.gui = parent; end
1769 AVWVIEW.avw = avw;
1770 AVWVIEW.handles = handles;
1771 set(AVWVIEW.gui,'Userdata',AVWVIEW);
1772 
1773 % Update sphere
1774 if exist('center', 'var') && exist('radius', 'var')
1775     AVWVIEW = vb_plot_sphere(AVWVIEW, center, radius);
1776 end
1777 
1778 
1779 set(AVWVIEW.gui,'HandleVisibility','callback');
1780 
1781 return
1782 
1783 
1784 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1785 function slice_img(avw),
1786 
1787 figure
1788 xslice = 128;
1789 slice = squeeze( avw.img(xslice,:,:) );
1790 imagesc(slice); axis image; colormap('gray')
1791 figure
1792 yslice = 128;
1793 slice = squeeze( avw.img(:,yslice,:) );
1794 imagesc(slice); axis image; colormap('gray')
1795 figure
1796 zslice = 128;
1797 slice = squeeze( avw.img(:,:,zslice) );
1798 imagesc(slice); axis image; colormap('gray')
1799 
1800 return
1801 
1802 function AVWVIEW = calc_sphere(AVWVIEW)
1803 % This function calculate and displaying sphere circle.
1804 % [IN]
1805 %    AVWVIEW : data store structure of this application.
1806 % [OUT]
1807 %    AVWVIEW : data store structure of this application.
1808 %      .sphere_data
1809 %        .center % sphere center position on coordinate of this application.
1810 %        .radius % sphere radius
1811 %        .display_component
1812 %          .axial    % display component of axial circle line.
1813 %          .coronal  %          -        of coronal  -
1814 %          .sagittal %          -        of sagittal -
1815 
1816 
1817 % remove past caluculation result
1818 AVWVIEW = remove_sphere(AVWVIEW);
1819 
1820 %
1821 % -- calculate sphere
1822 %
1823 point_structure = AVWVIEW.sphere_data.selected_point;
1824 selected_point = [point_structure.axial_point;...
1825                   point_structure.coronal_point;...
1826                   point_structure.sagittal_point];
1827 
1828 [center, r] = vb_center_sphere(selected_point);
1829 if ~isempty(center)
1830     AVWVIEW.sphere_data.center = center;
1831     AVWVIEW.sphere_data.radius = r;
1832     AVWVIEW = vb_plot_sphere(AVWVIEW, center, r);
1833 end
1834 
1835 function AVWVIEW = vb_plot_sphere(AVWVIEW, center, r)
1836 % [IN]
1837 %    AVWVIEW : data store structure of this application.
1838 %    center  : center of sphere.
1839 %          r : radius of sphere.
1840 % [OUT]
1841 %    AVWVIEW.sphere_data
1842 %           ==> .display_component
1843 %                   .axial    % display component of axial circle line.
1844 %                   .coronal  %          -        of coronal  -
1845 %                   .sagittal %          -        of sagittal -
1846 
1847 %
1848 %--- make Circle line component
1849 %
1850 T = 0:pi./100:2.*pi;
1851 point_color = 'yellow';
1852 % coronal line component
1853 X = r*cos(T) + center(1); Y = r*sin(T) + center(3);
1854 set(AVWVIEW.gui, 'CurrentAxes', AVWVIEW.handles.coronal_axes);
1855 h = line(X, Y, 'Color', point_color, 'Visible', 'on');
1856 h = [h; line(center(1), center(3), 'Color', point_color,...
1857          'Marker', '.', 'MarkerSize', 10, 'Visible', 'on')];
1858 AVWVIEW.sphere_data.display_component.axial = h;
1859 % axial line component
1860 X = r*cos(T) + center(1); Y = r*sin(T) + center(2);
1861 set(AVWVIEW.gui, 'CurrentAxes', AVWVIEW.handles.axial_axes);
1862 h = line(X, Y, 'Color', point_color, 'Visible', 'on');
1863 h = [h; line(center(1), center(2), 'Color', point_color,...
1864          'Marker', '.', 'MarkerSize', 10, 'Visible', 'on')];
1865 AVWVIEW.sphere_data.display_component.coronal = h;
1866 % sagittal line component
1867 X = r*cos(T) + center(2); Y = r*sin(T) + center(3);
1868 set(AVWVIEW.gui, 'CurrentAxes', AVWVIEW.handles.sagittal_axes);
1869 h = line(X, Y, 'Color', point_color, 'Visible', 'on');
1870 h = [h; line(center(2), center(3), 'Color', point_color,...
1871          'Marker', '.', 'MarkerSize', 10, 'Visible', 'on')];
1872 AVWVIEW.sphere_data.display_component.sagittal = h;
1873 
1874 function AVWVIEW = remove_sphere(AVWVIEW)
1875 % This function removes sphere circle line on screen.
1876 % [IN]
1877 %    AVWVIEW : data store structure of this application.
1878 % [OUT]
1879 %    AVWVIEW : data store structure of this application.
1880 %              remove data is as below.
1881 %      .sphere_data
1882 %         .display_component
1883 %            .axial    : display component of axial circle line.
1884 %            .coronal  :          -        of coronal  -
1885 %            .sagittal :          -        of sagittal -
1886 
1887 h = AVWVIEW.sphere_data.display_component.axial;
1888 h = [h;AVWVIEW.sphere_data.display_component.coronal];
1889 h = [h;AVWVIEW.sphere_data.display_component.sagittal];
1890 AVWVIEW.sphere_data.display_component.coronal = [];
1891 AVWVIEW.sphere_data.display_component.axial = [];
1892 AVWVIEW.sphere_data.display_component.sagittal = [];
1893 delete(h);
1894 
1895 function AVWVIEW = remove_selected_point(AVWVIEW, face)
1896 % This function removes data and view selected point.
1897 % [IN]
1898 %    AVWVIEW : data store structure of this application.
1899 %    face    : target of remove data.
1900 % [OUT]
1901 %    AVWVIEW : data store structure of this application.
1902 %              remove data is as below.
1903 %      .sphere_data
1904 %         .selected_point
1905 %            .axial_point       % selected coordinate value on axial slice
1906 %            .coronal_point     %              -               coronal  -
1907 %            .sagittal_point    %              -               sagittal -
1908 %            .axial_component   % display component on axial slice
1909 %            .coronal_component %              -       coronal  -
1910 %            .sagittal_component%              -       sagittal -
1911 %
1912 switch(face)
1913     case 'axial'
1914         delete(AVWVIEW.sphere_data.selected_point.axial_component);
1915         AVWVIEW.sphere_data.selected_point.axial_component = [];
1916         AVWVIEW.sphere_data.selected_point.axial_point = [];
1917     case 'coronal'
1918         delete(AVWVIEW.sphere_data.selected_point.coronal_component);
1919         AVWVIEW.sphere_data.selected_point.coronal_component = [];
1920         AVWVIEW.sphere_data.selected_point.coronal_point = [];
1921     case 'sagittal'
1922         delete(AVWVIEW.sphere_data.selected_point.sagittal_component);
1923         AVWVIEW.sphere_data.selected_point.sagittal_component = [];
1924         AVWVIEW.sphere_data.selected_point.sagittal_point = [];
1925     case 'unselected_status_point'
1926         p = AVWVIEW.sphere_data.selected_point;
1927         % sagittal slice
1928         h = findobj(p.sagittal_component, 'Color', 'blue');
1929         if ~isempty(h)
1930             idx = [];
1931             for k=1:length(h)
1932                 idx = [idx; find(p.sagittal_component == h(k))];
1933             end
1934             delete(h);
1935             AVWVIEW.sphere_data.selected_point.sagittal_component(idx, :) = [];
1936             AVWVIEW.sphere_data.selected_point.sagittal_point(idx, :) = [];
1937         end
1938         
1939         % coronal slice
1940         h = findobj(p.coronal_component, 'Color', 'blue');
1941         if ~isempty(h)
1942             idx = [];
1943             for k=1:length(h)
1944                 idx = [idx; find(p.coronal_component == h(k))];
1945             end
1946             delete(h);
1947             AVWVIEW.sphere_data.selected_point.coronal_component(idx, :) = [];
1948             AVWVIEW.sphere_data.selected_point.coronal_point(idx, :) = [];
1949         end
1950         
1951         % axial slice
1952         h = findobj(p.axial_component, 'Color', 'blue');
1953         if ~isempty(h)
1954             idx = [];
1955             for k=1:length(h)
1956                 idx = [idx; find(p.axial_component == h(k))];
1957             end
1958             delete(h);
1959             AVWVIEW.sphere_data.selected_point.axial_component(idx, :) = [];
1960             AVWVIEW.sphere_data.selected_point.axial_point(idx, :) = [];
1961         end
1962 end
1963 AVWVIEW = remove_sphere(AVWVIEW);
1964 
1965 function AVWVIEW = set_selected_point(AVWVIEW)
1966 % This function sets the selected point to AVWVIEW structure.
1967 % [IN]
1968 %    AVWVIEW : data store structure of this application.
1969 % [OUT]
1970 %    AVWVIEW : data store structure of this application.
1971 %      .sphere_data
1972 %         .selected_point
1973 %            .axial_point       % selected coordinate value on axial slice
1974 %            .coronal_point     %              -               coronal  -
1975 %            .sagittal_point    %              -               sagittal -
1976 %            .axial_component   % display component on axial slice
1977 %            .coronal_component %              -       coronal  -
1978 %            .sagittal_component%              -       sagittal -
1979 
1980 marker_size = 15;
1981 line_style = '.';
1982 point_color = 'red';
1983 
1984 X = AVWVIEW.metric.sag;
1985 Y = AVWVIEW.metric.cor;
1986 Z = AVWVIEW.metric.axi;
1987 
1988 point = [X, Y, Z];
1989 
1990 switch AVWVIEW.view
1991     case 'axi'
1992           h = line('Xdata', X, 'Ydata', Y, ...
1993                    'MarkerSize', marker_size, 'Marker', line_style, 'Color', point_color, 'ButtonDownFcn', 'vb_sphere_head([],[],''point_state_reverse'');');
1994           AVWVIEW.sphere_data.selected_point.axial_point = [AVWVIEW.sphere_data.selected_point.axial_point;point];
1995           AVWVIEW.sphere_data.selected_point.axial_component =[AVWVIEW.sphere_data.selected_point.axial_component;h];
1996     case 'cor'
1997           h = line('Xdata', X, 'Ydata', Z, ...
1998                    'MarkerSize', marker_size, 'Marker', line_style, 'Color', point_color, 'ButtonDownFcn', 'vb_sphere_head([],[],''point_state_reverse'');');
1999           AVWVIEW.sphere_data.selected_point.coronal_point = [AVWVIEW.sphere_data.selected_point.coronal_point;point];
2000           AVWVIEW.sphere_data.selected_point.coronal_component = [AVWVIEW.sphere_data.selected_point.coronal_component;h];
2001     case 'sag'
2002           h = line('Xdata', Y, 'Ydata', Z, ...
2003                    'MarkerSize', marker_size, 'Marker', line_style, 'Color', point_color, 'ButtonDownFcn', 'vb_sphere_head([],[],''point_state_reverse'');');
2004           AVWVIEW.sphere_data.selected_point.sagittal_point = [AVWVIEW.sphere_data.selected_point.sagittal_point;point];
2005           AVWVIEW.sphere_data.selected_point.sagittal_component = [AVWVIEW.sphere_data.selected_point.sagittal_component;h];
2006 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005