function spm_roi_view
% function for viewing anatomical location of ROIs
% - was formerly built into spm_tbx_roi.m
% - part of the SPM ROI Toolbox
% - see http://spm-toolbox.sourceforge.net/ for more details
  

Fgraph = spm_figure('FindWin','Graphics');
anat_img   = spm_get(1,'.img','select an anatomical image');
roi_info   = spm_get(1,'roi.mat','select an *con.mat file');
spm_results_ui('Clear',Fgraph);
load(roi_info);

% print cluster list

point=zeros(1,3);
info=sprintf('ROI information for %s',roi_info);
info=sprintf('%s\nCluster #\t\tX\tY\tZ\tMax T\tNumVox',info);
nclust=size(ROI.sphere,2);
for cluster=1:nclust
  point=ROI.sphere(cluster).center;
  info=sprintf('%s\n%d:\t\t%d\t%d\t%d\t%3.2f\t%d',...
       info,cluster,point,max(ROI.sphere(cluster).Z),...
	       size(ROI.sphere(cluster).XYZ,2));
end;
         
info=sprintf('%s\n',info);
	 
ax=axes('Position',[0.05 0.85 0.1 0.1],'Parent',Fgraph,'Visible','off');

set(get(ax,'Title'),'String',info,'FontSize',12,'FontWeight','normal',...
    'Visible','on','HorizontalAlignment','left','VerticalAlignment','top');
         
fprintf('%s',info);

        % render orthviews
        
clust_query=sprintf('Which clusters (1-%d): ',nclust);
cluster=spm_input(clust_query,'+1');
spm_results_ui('Clear',Fgraph);

spm_orthviews('Reset');
global st
st.Space = spm_matrix([0 0 0  0 0 -pi/2])*st.Space;
spm_orthviews('Image',anat_img,[0.05 0.05 0.9 0.45]);
spm_orthviews MaxBB;
	
colstep=1;
        
while colstep<size(cluster,2)+1,
         red=255;
         green=255;
         blue=255;
         for s=1:6
            COL(1:3,colstep)=[red;green;0];
            colstep=colstep+1;
            COL(1:3,colstep)=[red;0;0];
            colstep=colstep+1;
            COL(1:3,colstep)=[0;green;0];
            colstep=colstep+1;
            COL(1:3,colstep)=[0;0;blue];
            colstep=colstep+1;
            COL(1:3,colstep)=[red;0;blue];
            colstep=colstep+1;
            COL(1:3,colstep)=[0;green;blue];
            colstep=colstep+1;
            red=red-255/(size(cluster,2)/5);
            blue=blue-255/(size(cluster,2)/5);
            green=green-255/(size(cluster,2)/5);
         end;
end; % colstep
figure(Fgraph);

for c=1:size(cluster,2)
          point=ROI.sphere(cluster(c)).center;

	  spm_orthviews('addcolouredblobs',1,ROI.sphere(cluster(c)).XYZ,...
			ROI.sphere(cluster(c)).Z,ROI.VOL.M,COL(:,c));
end  
spm_orthviews('Reposition',point);
spm_orthviews('Redraw');

ax=axes('Position',[0.1 0.55 0.8 0.35],'Parent',Fgraph,'Visible','off');
string_title='';
axis([0 1 0 1]);
hold on
for c=1:size(cluster,2)
  point=ROI.sphere(cluster(c)).center;
  string_title=sprintf(['functional ROI: contrast %d, cluster %d, %d' ...
		    ' voxels (%d,%d,%d)\n'],ROI.SPM.Ic(1), ...
		    cluster(c),size(ROI.sphere(cluster(c)).XYZ,2),point);
  boxpos=1 - c/size(cluster,2);
  step=0.05;
  fill([0.1 0.1 0.2 0.2],[boxpos boxpos+step boxpos+step boxpos],...
       [(COL(:,c)/255)']);
  text(0.3,boxpos,string_title);
  axis([0 1 0 1]);
end;
string_title
%set(get(ax,'Title'),'String',string_title,'FontSize',16,'FontWeight','Bold','Visible','on');


return