%*************** Fonctions Graphique ***************
 
if strcmp(action,'Plus')
  % if(coupe<NbCoupe)
      coupe = coupe+1;
  % end
   
elseif strcmp(action,'Moins'),
 %  if(coupe>1)
      coupe = coupe-1;
 %  end
      
elseif strcmp(action,'go2coupe'),
    coupe = str2num(get(hdl.txt_editcoupe,'string'));
    
   if(coupe>NbCoupe)
	coupe = NbCoupe;
    end
   if(coupe<1)
	coupe = 1;
    end
      
%elseif strcmp(action,'orient'),
%  a = inputdlg({'angle1','angle2','angle3'},'orient (ù)',1,{'90','0','0'});
%  Volume(Num_vol).M_rot  = spm_matrix([0 0 0 ...
%				       pi/180*str2num(a{1}) ...
%				       pi/180*str2num(a{2}) ...
%				       pi/180*str2num(a{3}) ]);
 
elseif strcmp(action,'orient_axial'),
  Volume(Num_vol).M_rot  = [0 1 0 0;1 0 0 0;0 0 1 0;0 0 0 1];
  realy_refresh=1;
elseif strcmp(action,'orient_coronal'),
  Volume(Num_vol).M_rot  = [0 1 0 0;0 0 1 0;1 0 0 0;0 0 0 1];
  realy_refresh=1;
elseif strcmp(action,'orient_sagittal'),
  Volume(Num_vol).M_rot  = [0 0 1 0;0 1 0 0;1 0 0 0;0 0 0 1];
  realy_refresh=1;

%spm_matrix([0 0 0  pi/2 0 -pi/2 -1 1 1]);


elseif strcmp(action,'colorbar');
	mycolorbar;

elseif strcmp(action,'colorlim_init');
  
       slice = get(hdl.Im,'CData');
 	ma = max(max(slice));
 	mi = min(min(slice));
 	set(hdl.edit_min,'string',num2str(mi))
 	set(hdl.edit_max,'string',num2str(ma))

 	maa = ma+(ma+mi)/4;
	mii = mi-(ma+mi)/4;

	Sst = 0.01;
 	set(hdl.slide_max,'value',ma,'Min',mii,'Max',maa,'SliderStep',[Sst Sst*10]);
 	set(hdl.slide_mean,'value',(ma+mi)/2,'Min',mii,'Max',maa,'SliderStep',[Sst Sst*10]);
 	set(hdl.slide_min,'value',mi,'Min',mii,'Max',maa,'SliderStep',[Sst Sst*10]);

   set(get(FigNum,'CurrentAxes'),'visible','on','clim',[mi ma])
 
elseif strcmp(action,'slide');   

 
   ma = get(hdl.slide_max,'value'); 
   mi = get(hdl.slide_min,'value'); 
 	
   set(hdl.slide_mean,'value',(ma+mi)/2);

   set(get(FigNum,'CurrentAxes'),'visible','on','clim',[mi ma])

elseif strcmp(action,'slide_mean');   

   ma = get(hdl.slide_max,'value'); 
   mi = get(hdl.slide_min,'value');
   me = (ma + mi)/2; 
   diff = get(hdl.slide_mean,'value') - me;
   mama = get(hdl.slide_max,'Max');
   mimi = get(hdl.slide_max,'Min');   
   ma = ma + diff;
   mi = mi + diff;   
   if ma > mama
   	ma = mama;
   	mi = 2*me - ma;
   end   
   if mi < mimi
   	mi = mimi;
   	ma = 2*me-mi;
   end

   set(hdl.slide_max,'value',ma);
   set(hdl.slide_min,'value',mi);
   set(get(FigNum,'CurrentAxes'),'visible','on','clim',[mi ma])
   
elseif strcmp(action,'Autolim');   
   set(gca,'clim',[10 30]); %il faut tricher un peu avec matlab mais bon c'est du d‹tail
   set(gca,'CLimMode','auto');
   
   
elseif strcmp(action,'fermer'),
%   Volume(hdl.Num).data = [];
   Volume(hdl.Num).Pos =[];
   Volume(hdl.Num).P64 =[];
   Volume(hdl.Num).Tpos  = [];
   Volume(hdl.Num).Bw  = []; 
   Volume(hdl.Num).Cont = [];

   close(gcf);   
   if isfield(hdl,'color')
      close(hdl.color)
   end
   
   byby =1;
   return
   
elseif strcmp(action,'remember'),
   Volume(Num_vol).stackofmaps = [colormap; Volume(Num_vol).stackofmaps];
   
elseif strcmp(action,'restore'),
   
   stac = Volume(Num_vol).stackofmaps;
   lenm = Volume(Num_vol).lengthofmap;

   colormap(stac(1:lenm,:));
   
   if size(stac,1)>lenm,
      stac(1:lenm,:)=[]; 
   end
   
elseif strcmp(action,'Voyons'),
    keyboard;
    return
    
  
elseif strcmp(action,'invertY'),
   aaa = get(gca,'ydir');
   
   switch lower(aaa)
   case 'reverse'
   	set(gca,'ydir','normal')
   case 'normal'
   	set(gca,'ydir','reverse')
   end
   
   
elseif strcmp(action,'visu_Pos_size'),

   hdlP = hdl.Pos;

   tmp1 = get(hdlP,'MarkerSize');
   tmp2 = get(hdlP,'Marker');
 
   a = inputdlg({'size','type'},'bloups',1,{num2str(tmp1),tmp2});
   set(hdlP,'MarkerSize',str2num(a{1}))
   set(hdlP,'Marker',a{2})
   realy_refresh=1;

elseif strcmp(action,'visu_Pos_color'),
   hdlP = hdl.Pos;

   uisetcolor(hdlP,'sometimes it works ...');
   realy_refresh=1;


end;

