Skip to content

Commit

Permalink
Changed: Made many changes for octave compatibility.
Browse files Browse the repository at this point in the history
Fixed:   Corrected wrong arguments in sprintf command in
         cat_main_updateSPM1639.m
Fixed:   Contrasts were sometimes not recognized in cat_spm_results_ui.m because
         we have to go into the analysis folder.
Fixed:   Clipping should be ignored for cat_vol_slice_overlay if lower and upper
         clipping values are equal.
Fixed:   Figure in cat_vol_slice_overlay_ui.m was set to unvisible.

Changed paths:
 M CHANGES.txt
 M cat_io_cprintf.m
 M cat_io_xml.m
 M cat_main_reportfig.m
 M cat_main_reportstr.m
 M cat_main_updateSPM1639.m
 M cat_run.m
 M cat_spm_results_ui.m
 M cat_stat_check_cov_old.m
 M cat_surf_createCS2.m
 M cat_surf_results.m
 M cat_vbdist.c
 M cat_vol_approx.m
 M cat_vol_slice_overlay.m
 M compile.m
 M spm_cat12.m
  • Loading branch information
ChristianGaser committed Jan 22, 2023
1 parent c51598d commit b9aae03
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 69 deletions.
29 changes: 29 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
------------------------------------------------------------------------
r2166 | gaser | 2023-01-22 23:40:08

Changed paths:
M CHANGES.txt
M cat_io_cprintf.m
M cat_io_xml.m
M cat_main_reportfig.m
M cat_main_reportstr.m
M cat_main_updateSPM1639.m
M cat_run.m
M cat_spm_results_ui.m
M cat_stat_check_cov_old.m
M cat_surf_createCS2.m
M cat_surf_results.m
M cat_vbdist.c
M cat_vol_approx.m
M cat_vol_slice_overlay.m
M compile.m
M spm_cat12.m

Changed: Made many changes for octave compatibility.
Fixed: Corrected wrong arguments in sprintf command in
cat_main_updateSPM1639.m
Fixed: Contrasts were sometimes not recognized in cat_spm_results_ui.m because
we have to go into the analysis folder.
Fixed: Clipping should be ignored for cat_vol_slice_overlay if lower and upper
clipping values are equal.
Fixed: Figure in cat_vol_slice_overlay_ui.m was set to unvisible.
------------------------------------------------------------------------
r2164 | gaser | 2023-01-14 21:46:06

Changed paths:
Expand Down
2 changes: 1 addition & 1 deletion cat_io_cprintf.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
end
% The following is for debug use only:
%global docElement el debugData
if ~exist('el','var') || isempty(el), el=handle([]); end %#ok mlint short-circuit error ("used before defined")
if ~strcmpi(spm_check_version,'octave') && (~exist('el','var') || isempty(el)), el=handle([]); end %#ok mlint short-circuit error ("used before defined")
if nargin<1, showDemo(majorVersion,minorVersion); return; end
if isempty(style), return; end
% #### begin extended styles ####
Expand Down
42 changes: 11 additions & 31 deletions cat_io_xml.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,6 @@
% ______________________________________________________________________

onlyxml = 0;
if strcmpi(spm_check_version,'octave')
pkglist = pkg('list');
if isempty(pkglist) || all( strfind( [pkglist{:}.name] , 'io') == 0 )
pkg install -forge io
end
pkg load io
try
% add java files
xmljava{1} = fullfile(fileparts(mfilename('fullpath')),'Octave','xercesImpl.jar');
xmljava{2} = fullfile(fileparts(mfilename('fullpath')),'Octave','xml-apis.jar');
% call them
for xi=1:numel(xmljava), eval(sprintf('javaaddpath("%s");',xmljava{xi})); end
% test function
xmlread;
catch e
if strcmp(e.message,'xmlread: no Java JRE or JDK detected, exiting')
onlyxml = 1;
end
end

end



verbose = 0;
Expand Down Expand Up @@ -188,8 +166,9 @@
try
if usejava('jvm')
xml_write(file,S);
elseif strcmpi(spm_check_version,'octave') && ~onlyxml
xmlwrite(file,S);
elseif strcmpi(spm_check_version,'octave')
warning off all
savexml(file,'S');
end
catch %#ok<*NASGU> % can write xml file??
% This can be a warning as far as we have the mat.
Expand All @@ -211,8 +190,8 @@
try
if usejava('jvm')
S = xml_read(file);
elseif strcmpi(spm_check_version,'octave') && ~onlyxml
S = xmlread(file);
elseif strcmpi(spm_check_version,'octave')
S = loadxml(file);
end
catch
error('MATLAB:cat_io_xml:write+ReadErr','Can''t read XML-file ''%s'' for update!\n',file);
Expand All @@ -223,8 +202,8 @@
try
if usejava('jvm')
S = xml_read(file);
elseif strcmpi(spm_check_version,'octave') && ~onlyxml
S = xmlread(file);
elseif strcmpi(spm_check_version,'octave')
S = loadxml(file);
end
catch
error('MATLAB:cat_io_xml:write+ReadErr','Can''t read XML-file ''%s'' for update!\n',file);
Expand All @@ -248,8 +227,9 @@
try
if usejava('jvm')
xml_write(file,S);
elseif strcmpi(spm_check_version,'octave') && ~onlyxml
xmlwrite(file,S);
elseif strcmpi(spm_check_version,'octave')
warning off all
savexml(file,'S');
end
catch
warning('MATLAB:cat_io_xml:writeErr','Can''t write XML-file ''%s''!\n',file);
Expand All @@ -271,7 +251,7 @@
if usejava('jvm')
S = xml_read(file);
elseif strcmpi(spm_check_version,'octave')
S = xmlread(file);
S = loadxml(file);
end
warning on
catch
Expand Down
2 changes: 1 addition & 1 deletion cat_main_reportfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ function cat_main_reportfig(Ym,Yp0,Yl1,Psurf,job,qa,res,str)
% CAT atlas labeling
LAB = job.extopts.LAB;
NS = @(Ys,s) Ys==s | Ys==s+1;
if job.extopts.report.useoverlay>1
if job.extopts.report.useoverlay>1 && ~strcmpi(spm_check_version,'octave')
try spm_orthviews('window',hhp0,[0 2]); end
V2 = VO;
switch job.extopts.report.useoverlay
Expand Down
4 changes: 2 additions & 2 deletions cat_main_reportstr.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
% red version in case of old version?
% 1 line: Matlab, SPM12, CAT12 version number and GUI and experimental mode
if strcmpi(spm_check_version,'octave')
str{1} = [str{1} struct('name', 'Version: OS / Octave / SPM12 / CAT12:','value',...
sprintf('%s / %s / %s / %s (%s)',qa.software.system,qa.software.version_octave,...
str{1} = [str{1} struct('name', 'Version: OS / SPM12 / CAT12:','value',...
sprintf('%s / %s / %s (%s)',qa.software.system,...
qa.software.version_spm,qa.software.version_cat,catv))];
% native2unicode is working on the command line but not in the figure
cub = '^3';
Expand Down
2 changes: 1 addition & 1 deletion cat_main_updateSPM1639.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
abs(diff(res.spmP0.hsti(1:2:3,:))) ./ max(eps,sum(res.spmP0.hsti(1:2:3,:)));
]));
res.spmP0.help = [res.spmP0.help; {
sprintf('The hsti is the histogram of the T1 image for each class (prob>%0.2%%,%d buckets) ',minprob/255,hbuckets)};
sprintf('The hsti is the histogram of the T1 image for each class (prob>%0.2f,%d buckets) ',minprob/255,hbuckets)};
'that are combined into the average intensity difference between classes histidiff with 1 for the ideal case without overlap and 0 for high overlap. '];
if job.extopts.expertgui>1 && res.spmP0.hstidiff<0.5
cat_io_addwarning('cat_main_updateSPM:highIntOverlapBetweenClasses',...
Expand Down
12 changes: 0 additions & 12 deletions cat_run.m
Original file line number Diff line number Diff line change
Expand Up @@ -1006,18 +1006,6 @@
end


if strcmpi(spm_check_version,'octave') && job.extopts.regstr > 0
warning('cat_run:noShooting','No Shooting registration possible under Octave yet. Switch to Dartel registration.')
job.extopts.regstr = 0;
if isfield(job.extopts,'regmethod')
job.extopts.regmethod = rmfield(job.extopts.regmethod,'shooting');
else
job.extopts = rmfield(job.extopts,'shooting');
end
job.extopts.dartel.darteltpm = cat_get_defaults('extopts.darteltpm');
end


%% set Dartel/Shooting templates
if isfield(job.extopts,'regmethod')
if isfield(job.extopts.regmethod,'dartel')
Expand Down
3 changes: 2 additions & 1 deletion cat_spm_results_ui.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@
if exist(fullfile(fileparts(fileparts(mfilename('fullpath'))),'TFCE'),'dir')
[spmmatfile, sts] = spm_select(1,'^SPM\.mat$','Select SPM.mat');
swd = spm_file(spmmatfile,'fpath');
cd(swd)
warning off
load(fullfile(swd,'SPM.mat'),'SPM','xSPM');
load('SPM.mat','SPM','xSPM');
warning on

[Ic,xCon] = spm_conman(SPM,'T&F',Inf,' Select contrast(s)...','',1);
Expand Down
2 changes: 1 addition & 1 deletion cat_stat_check_cov_old.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function varargout = cat_stat_check_cov(job)
function varargout = cat_stat_check_cov_old(job)
%cat_stat_check_cov. To check covariance across sample.
%
% Images have to be in the same orientation with same voxel size
Expand Down
2 changes: 1 addition & 1 deletion cat_surf_createCS2.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
cstime = clock;

if strcmpi(spm_check_version,'octave')
cat_io_addwarning('cat_surf_createCS:noSRP','Correction of surface collisions is not yet available under Octave.',2,[1 1])
cat_io_addwarning('cat_surf_createCS2:noSRP','Correction of surface collisions is not yet available under Octave.',2,[1 1])
opt.SRP = 0;
end

Expand Down
19 changes: 10 additions & 9 deletions cat_surf_results.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
end

% close old figures
if ishandle(12),close(12);end;if ishandle(21),close(21);end;
if ishandle(12),close(12);end;if ishandle(22),close(22);end;

% remove any existing data
if exist('H','var')
Expand Down Expand Up @@ -205,7 +205,7 @@
'ovmin', [0.050 0.125 0.425 0.100],'ovmax', [0.525 0.125 0.425 0.100],...
'save', [0.050 0.050 0.425 0.050],'close', [0.525 0.050 0.425 0.050]);

H.figure = figure(22);
H.figure = figure(23);
clf(H.figure);

set(H.figure, 'MenuBar', 'none', 'Position', H.pos{1}.fig, ...
Expand Down Expand Up @@ -1847,8 +1847,8 @@ function disphist(type)
OV.reference_range = [0.2 1.0];
end

% clipping if defined
if ~isempty(H.clip)
% clipping if (meaningful) defined
if ~isempty(H.clip) && H.clip(2) ~= H.clip(3)
if ~isnan(H.clip(2)) && ~isnan(H.clip(3))
OV.clip = H.clip(2:3);
else
Expand Down Expand Up @@ -1914,7 +1914,8 @@ function disphist(type)
end

% show MIP and keep position if window exists
OV.fig = 21;
OV.fig = 22;

if ishandle(OV.fig)
cat_vol_slice_overlay(OV);
else
Expand Down Expand Up @@ -2805,19 +2806,19 @@ function select_data(obj, event_obj, P)
P0{i} = Pout;
H.isvol(i) = 1;
H.Pvol{i} = Pvol;
H.Pvol_sel = Pvol;
vol = spm_read_vols(spm_vol(Pvol));
H.Pvol_mn{i} = min(vol(:));
H.Pvol_mx{i} = max(vol(:));
H.Pvol_mn{i} = min(vol(vol ~= 0));
H.Pvol_mx{i} = max(vol(vol ~= 0));

% print warning if no SPM.mat file was found
if ~exist(fullfile(pp, 'SPM.mat'), 'file') || ~exist(fullfile(pp, 'vSPM.mat'), 'file')
if ~exist(fullfile(pp, 'SPM.mat'), 'file') && ~exist(fullfile(pp, 'vSPM.mat'), 'file')
fprintf('Warning: Please ensure that %s is spatially registered to the new MNI152NLin2009cAsym template space.\n',[ff ee]);
end
else
P0{i} = deblank(P(i,:));
end
end
H.Pvol_sel = H.Pvol{1};

P0 = char(P0);
info = cat_surf_info(P0,0);
Expand Down
2 changes: 1 addition & 1 deletion cat_vbdist.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
/* such as cat_run_job.APRGs:196 where the old call "Ymx = Ybgd./(Ybd+Ybgd);" was working but
* the new version caused a treshold in an image with INF that lead to an empty brainmask
* Although, this can be solved by "Ymx = min(1,Ybgd./(Ybd+Ybgd));" I do not know other
* problematic call now and this should maybe change later.
* problematic call now and this should maybe changed later.
*/
if (L[i]>=0.5) D[i]=0.0; else D[i]=FLT_MAX;
if (L[i]>255.0)
Expand Down
2 changes: 1 addition & 1 deletion cat_vol_approx.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
PM{1} = (cat_vbdist(PM{1},true(size(PM{1})),[1.5 1 1]) + ...
cat_vol_smooth3X(rand(PTsize)*20,2) + cat_vol_smooth3X(randn(PTsize)*20)) <PTsize(1)/2;

ds('d2','',[1 1 1],PT{1},PT{2},PT{1}.*PM{1},PT{2}.*PM{1},32)
ds('d2','',[1 1 1],PT{1},PT{2},PT{1}.*PM{1},PT{2}.*PM{1},32);


%%
Expand Down
6 changes: 3 additions & 3 deletions cat_vol_slice_overlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
end

% clip colorbar
if isfield(OV,'clip') && all(isfinite(OV.clip))
if isfield(OV,'clip') && all(isfinite(OV.clip)) && OV.clip(2) ~= OV.clip(1)
ncol = length(OV.cmap);
col_step = (OV.range(2) - OV.range(1)) / ncol;
cmin = max([1, ceil((OV.clip(1) - OV.range(1)) / col_step)]);
Expand Down Expand Up @@ -409,7 +409,7 @@
'PaperPositionMode', 'auto', ...
'NumberTitle', 'off', ...
'Name', nm, ...
'Visible', 'off');
'Visible', 'on');

SO.figure = h;
SO.area.units = 'pixels';
Expand Down Expand Up @@ -938,7 +938,7 @@
corners = T * [vcorners; ones(1, 8)];

SO.slices = spm_input('Slices to display (mm)', '+1', 'e', XYZ_unique{orientn});
SO.figure = figure(21);
SO.figure = figure(22);

% and do the display
if dispf, slice_overlay; end
Expand Down
9 changes: 6 additions & 3 deletions compile.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@
'cat_sanlm.c sanlm_float.c'
};
% internal c-functions
nc{2} = {
'cat_vol_cMRegularizarNLM3D.c'
};
% does not yet work for octave
if ~strcmpi(spm_check_version,'octave')
nc{2} = {
'cat_vol_cMRegularizarNLM3D.c'
};
end
rc = cell(1,2); % results of c-function comiling
rcc = cell(1,2); % results of c-function comiling
nce = cell(1,2); % number of errors
Expand Down
6 changes: 5 additions & 1 deletion spm_cat12.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ function spm_cat12(varargin)
try
feval(@cat_sanlm,single(rand(6,6,6)),1,3);
catch
if ismac
if strcmpi(spm_check_version,'octave')
cd(pth)
compile
feval(@cat_sanlm,single(rand(6,6,6)),1,3);
elseif ismac
CATDir = fullfile(catdir);
web('https://en.wikibooks.org/wiki/SPM/Installation_on_64bit_Mac_OS_(Intel)#Troubleshooting');
cat_io_cmd(sprintf('\nThe following commands will be executed as administrator to allow execution of CAT12 binaries and mex-files.\n Please now type admin password to call sudo\n'),'warning');
Expand Down

0 comments on commit b9aae03

Please sign in to comment.