SciCodePile/SciCode-Domain-Code
DATA1: Domain-Specific Code Dataset Dataset Overview DATA1 is a large-scale domain-specific code dataset focusing on code samples from interdisciplinary fields such as biology, chemistry, materials science, and related areas. The dataset is collected and organized from GitHub repositories, covering 178 different domain topics with over 1.1 billion lines of code. Dataset Statistics Total Datasets: 178 CSV files Total Data Size: ~115 GB Total Lines… See the full description on the dataset page: https://huggingface.co/datasets/SciCodePile/SciCode-Domain-Code.
42.4k
1"keyword","repo_name","file_path","file_extension","file_size","line_count","content","language"
2"Neurology","ChristianGaser/cat12","cat_conf_opts.m",".m","24921","381","function opts = cat_conf_opts(expert)3% Configuration file for CAT SPM options4%5% ______________________________________________________________________6%7% Christian Gaser, Robert Dahnke8% Structural Brain Mapping Group (https://neuro-jena.github.io)9% Departments of Neurology and Psychiatry10% Jena University Hospital11% ______________________________________________________________________12% $Id$13%#ok<*AGROW>14 15if ~exist('expert','var')16 expert = 0; % switch to de/activate further GUI options17end18 19 20%------------------------------------------------------------------------21% various options for estimating the segmentations22%------------------------------------------------------------------------23 24 25% tpm:26%------------------------------------------------------------------------27tpm = cfg_files;28tpm.tag = 'tpm';29tpm.name = 'Tissue Probability Map';30tpm.filter = 'image';31tpm.ufilter = '.*';32tpm.def = @(val)cat_get_defaults('opts.tpm', val{1});33tpm.help = {34 'Select the tissue probability image that includes 6 tissue probability classes for (1) grey matter, (2) white matter, (3) cerebrospinal fluid, (4) bone, (5) non-brain soft tissue, and (6) the background. CAT uses the TPM only for the initial SPM segmentation. Hence, it is more independent and allows accurate and robust processing even with the standard TPM in case of strong anatomical differences, e.g. very old/young brains. Nevertheless, for children data we recommend to use customized TPMs created using the Template-O-Matic toolbox. '35 ''36 'The default tissue probability maps are modified versions of the ICBM Tissue Probabilistic Atlases. These tissue probability maps are kindly provided by the International Consortium for Brain Mapping, John C. Mazziotta and Arthur W. Toga. http://www.loni.ucla.edu/ICBM/ICBM_TissueProb.html.'37 ''38 'The original data are derived from 452 T1-weighted scans, which were aligned with an atlas space, corrected for scan inhomogeneities, and classified into grey matter, white matter and cerebrospinal fluid. These data were then affine registered to the MNI space and down-sampled to 1.5 mm resolution. Rather than assuming stationary prior probabilities based upon mixing proportions, additional information is used, based on other subjects'' brain images. Priors are usually generated by registering a large number of subjects together, assigning voxels to different tissue types and averaging tissue classes over subjects. The algorithm used here will employ these priors for the first initial segmentation and normalization. Six tissue classes are used: grey matter, white matter, cerebrospinal fluid, bone, non-brain soft tissue and air outside of the head and in nose, sinus and ears. These maps give the prior probability of any voxel in a registered image being of any of the tissue classes - irrespective of its intensity. The model is refined further by allowing the tissue probability maps to be deformed according to a set of estimated parameters. This allows spatial normalisation and segmentation to be combined into the same model. Selected tissue probability map must be in multi-volume nifti format and contain all six tissue priors. '39 ''40};41tpm.num = [1 1];42tpm.def = @(val)cat_get_defaults('opts.tpm', val{:});43 44 45% ngaus:46%------------------------------------------------------------------------47% The default of SPM12 [GM,WM,CSF,bone,head tissue,BG] was [1,1,2,3,4,2]48% and works very well for most data and the segmentation did not benefit by 49% more classes. There are no systematic effects for interferences or 50% special anatomical properties (e.g. WMHs)!51%------------------------------------------------------------------------52ngaus = cfg_entry;53ngaus.tag = 'ngaus';54ngaus.name = 'Gaussians per class';55ngaus.strtype = 'n';56ngaus.num = [1 6];57ngaus.def = @(val)cat_get_defaults('opts.ngaus', val{:});58ngaus.help = {59 'The number of Gaussians used to represent the intensity distribution for each tissue class can be greater than one. In other words, a tissue probability map may be shared by several clusters. The assumption of a single Gaussian distribution for each class does not hold for a number of reasons. In particular, a voxel may not be purely of one tissue type, and instead contain signal from a number of different tissues (partial volume effects). Some partial volume voxels could fall at the interface between different classes, or they may fall in the middle of structures such as the thalamus, which may be considered as being either grey or white matter. Various other image segmentation approaches use additional clusters to model such partial volume effects. These generally assume that a pure tissue class has a Gaussian intensity distribution, whereas intensity distributions for partial volume voxels are broader, falling between the intensities of the pure classes. Unlike these partial volume segmentation approaches, the model adopted here simply assumes that the intensity distribution of each class may not be Gaussian, and assigns belonging probabilities according to these non-Gaussian distributions. Typical numbers of Gaussians could be one to three for grey and white matter, two for CSF, three for bone, four for other soft tissues and two for air (background).'60 ''61 ...'Note that if any of the Num. Gaussians is set to non-parametric, then a non-parametric approach will be used to model the tissue intensities. This may work for some images (eg CT), but not others - and it has not been optimised for multi-channel data. Note that it is likely to be especially problematic for images with poorly behaved intensity histograms due to aliasing effects that arise from having discrete values on the images.'62 ...''63};64 65 66biasacc = cfg_menu;67biasacc.tag = 'biasacc';68biasacc.name = 'Strength of SPM Inhomogeneity Correction';69biasacc.def = @(val)cat_get_defaults('opts.biasstr', val{:});70biasacc.labels = {'light','medium','strong','heavy'};71biasacc.values = {0.25 0.50 0.75 1.00};72biasacc.help = {73 'Strength of the SPM inhomogeneity (bias) correction that simultaneously controls the SPM biasreg, biasfwhm, samp (resolution), and tol (iteration) parameter. Modify this value only if you experience any problems! Use smaller values for slighter corrections (e.g. in synthetic contrasts without visible bias) and higher values for stronger corrections (e.g. in 3 or 7 Tesla data with strong visible bias). Stronger corrections often improve cortical results but can also cause overcorrection in larger GM structures such as the subcortical structurs, thalamus, or amygdala and will take longer. Bias correction is further controlled by the Affine Preprocessing (APP). '74 ''75};76 77%------------------------------------------------------------------------78% Bias correction79%------------------------------------------------------------------------80biasstr = cfg_menu;81biasstr.tag = 'biasstr';82biasstr.name = 'Strength of SPM Inhomogeneity Correction';83biasstr.def = @(val)cat_get_defaults('opts.biasstr', val{:});84if ~expert85 biasstr.labels = {'light','medium','strong'};86 biasstr.values = {0.25 0.50 0.75};87 %biasstr.labels = {'ultralight','light','medium','strong','heavy'};88 %biasstr.values = {0 0.25 0.50 0.75 1};89 biasstr.help = {90 'Strength of the SPM inhomogeneity (bias) correction that simultaneously controls the SPM biasreg and biasfwhm parameter. Modify this value only if you experience any problems! Use smaller values for slighter corrections (e.g. in synthetic contrasts without visible bias) and higher values for stronger corrections (e.g. in 3 or 7 Tesla data with strong visible bias). Bias correction is further controlled by the Affine Preprocessing (APP). '91 ''92 };93elseif expert>=194 biasstr.labels = {'ultralight (eps)','light (0.25)','medium (0.50)','strong (0.75)','heavy (1.00)'};95 biasstr.values = {eps 0.25 0.50 0.75 1};96 biasstr.help = {97 'Strength of the SPM inhomogeneity (bias) correction that simultaneously controls the SPM biasreg and biasfwhm parameter. Modify this value only if you experience any problems! Use smaller values (>0) for slighter corrections (e.g. in synthetic contrasts without visible bias) and higher values (<=1) for stronger corrections (e.g. in 7 Tesla data). Bias correction is further controlled by the Affine Preprocessing (APP). '98 ''99 ' biasreg = min( 10 , max( 0 , 10^-(biasstr*2 + 2) )) '100 ' biasfwhm = min( inf , max( 30 , 30 + 60*(1-biasstr) )) '101 ''102 ' biasstr biasfwhm biasreg'103 ' ultralight: eps 90 0.0100 '104 ' light: 0.25 75 0.0032 '105 ' medium: 0.50 60 0.0010 '106 ' strong: 0.75 45 0.0003 '107 ' heavy: 1.00 30 0.0001 '108 };109%{110elseif expert==2111 biasstr.labels = {'use SPM bias parameter (0)','ultralight (eps)','light (0.25)','medium (0.50)','strong (0.75)','heavy (1.00)'};112 biasstr.values = {0 eps 0.25 0.50 0.75 1};113 biasstr.help = {114 'Strength of the SPM inhomogeneity (bias) correction that simultaneously controls the SPM biasreg and biasfwhm parameter. Modify this value only if you experience any problems! Use smaller values (>0) for slighter corrections (e.g. in synthetic contrasts without visible bias) and higher values (<=1) for stronger corrections (e.g. in 7 Tesla data). The value 0 will use the original SPM biasreg and biasfwhm parameter of the cat_defaults file. Bias correction is further controlled by the Affine Preprocessing (APP). '115 ''116 ' biasreg = min( 10 , max( 0 , 10^-(biasstr*2 + 2) )) '117 ' biasfwhm = min( inf , max( 30 , 30 + 60*(1-biasstr) )) '118 ''119 ' biasstr biasfwhm biasreg'120 ' SPM parameter: - - - '121 ' ultralight: eps 90 0.0100 '122 ' light: 0.25 75 0.0032 '123 ' medium: 0.50 60 0.0010 '124 ' strong: 0.75 45 0.0003 '125 ' heavy: 1.00 30 0.0001 '126 };127%}128end129 130 131% biasreg: 132%------------------------------------------------------------------------133% Test on the BWP and real data demonstrate that 0.001 mm works best in134% average, whereas some image benefit by more regularisation (0.01) and strong135% bias requires less regularisation (0.0001). There are no special cases136% that benefit by a regularisation >0.01 or <0.0001! Hence, I removed137% these entries (RD 2017-03).138%------------------------------------------------------------------------139biasreg = cfg_menu;140biasreg.tag = 'biasreg';141biasreg.name = 'Bias regularisation';142biasreg.def = @(val)cat_get_defaults('opts.biasreg', val{:});143if 0144 biasreg.labels = {'No regularisation (0)','Extremely light regularisation (0.00001)','Very light regularisation (0.0001)','Light regularisation (0.001)','Medium regularisation (0.01)','Heavy regularisation (0.1)','Very heavy regularisation (1)','Extremely heavy regularisation (10)'};145 biasreg.values = {0, 0.00001, 0.0001, 0.001, 0.01, 0.1, 1.0, 10};146else147 biasreg.labels = {'Very light regularisation (0.0001)','Light regularisation (0.001)','Medium regularisation (0.01)'};148 biasreg.values = {0.0001, 0.001, 0.01};149end150biasreg.help = {151 'Regularisation of the SPM bias field. This parameter is controlled by the biasreg parameter if biasstr>0. Test on the BWP and real data showed that optimal corrections was in range of 0.01 and 0.0001.'152 ''153 'MR images are usually corrupted by a smooth, spatially varying artefact that modulates the intensity of the image (bias). These artefact, although not usually a problem for visual inspection, can impede automated processing of the images. An important issue relates to the distinction between intensity variations that arise because of bias artifact due to the physics of MR scanning, and those that arise due to different tissue properties. The objective is to model the latter by different tissue classes, while modelling the former with a bias field. We know a priori that intensity variations due to MR physics tend to be spatially smooth, whereas those due to different tissue types tend to contain more high frequency information. A more accurate estimate of a bias field can be obtained by including prior knowledge about the distribution of the fields likely to be encountered by the correction algorithm. For example, if it is known that there is little or no intensity non-uniformity, then it would be wise to penalise large values for the intensity non-uniformity parameters. This regularisation can be placed within a Bayesian context, whereby the penalty incurred is the negative logarithm of a prior probability for any particular pattern of non-uniformity. Knowing what works best should be a matter of empirical exploration. For example, if your data has very little intensity non-uniformity artifact, then the bias regularisation should be increased. This effectively tells the algorithm that there is very little bias in your data, so it does not try to model it. '154 ''155};156 157 158% biasfwhm:159%------------------------------------------------------------------------160% Test on the BWP and real data demonstrate that 60 mm works best for most161% datasets. Only 7 Tesla data need further adaptation, larger filter size is162% normaly not required (RD 2017-03)!163% - 30-40 mm: low filter size for very strong fields (e.g. 7 or 3 Tesla data)164% - 50-60 mm: medium filter size works best for >95% of the data, and do not overfit in case of low bias 165% - 70-90 mm: high filter size in case of low bias data166% - >90 mm: better to avoid that, because there is mostly a low bias in the data that is normally not visible 167%------------------------------------------------------------------------168biasfwhm = cfg_menu;169biasfwhm.tag = 'biasfwhm';170biasfwhm.name = 'Bias FWHM';171if 0172 biasfwhm.labels = {'30mm cutoff','40mm cutoff','50mm cutoff','60mm cutoff','70mm cutoff','80mm cutoff','90mm cutoff','100mm cutoff','110mm cutoff','120mm cutoff','130mm cutoff','140mm cutoff','150mm cutoff','No correction'};173 biasfwhm.values = {30,40,50,60,70,80,90,100,110,120,130,140,150,Inf};174else175 biasfwhm.labels = {'30mm cutoff','40mm cutoff','50mm cutoff','60mm cutoff','70mm cutoff','80mm cutoff','90mm cutoff'};176 biasfwhm.values = {30,40,50,60,70,80,90};177end178biasfwhm.def = @(val)cat_get_defaults('opts.biasfwhm', val{:});179biasfwhm.help = {180 'FWHM of Gaussian smoothness of bias. This parameter is controlled by the biasreg parameter if biasstr>0. Test on the BWP and real data showed that 50 to 60 mm works best for nearly all datasets and only some 7 Tesla scans require further adaptation! '181 ' 30-40 mm: low filter size for very strong fields (e.g. 7 or 3 Tesla data) '182 ' 50-60 mm: medium filter size works best for >95% of the data, and do not overfit in case of low bias '183 ' 70-90 mm: high filter size in case of low bias data '184 ''185 'If your intensity non-uniformity is very smooth, then choose a large FWHM. This will prevent the algorithm from trying to model out intensity variation due to different tissue types. The model for intensity non-uniformity is one of i.i.d. Gaussian noise that has been smoothed by some amount, before taking the exponential. Note also that smoother bias fields need fewer parameters to describe them. This means that the algorithm is faster for smoother intensity non-uniformities. '186 ''187};188 189biasspm = cfg_branch;190biasspm.tag = 'spm';191biasspm.name = 'Original SPM bias correction parameter';192biasspm.val = {biasfwhm biasreg};193biasspm.help = {194 'SPM bias correction parameter biasfwhm and biasreg.' 195}; 196 197bias = cfg_choice;198bias.tag = 'bias';199bias.name = 'Biascorrection parameter';200if cat_get_defaults('opts.biasstr')>0201 bias.val = {biasstr};202else203 bias.val = {biasspm};204end205bias.values = {biasstr biasspm};206bias.help = {207 'Bias correction parameters.' 208}; 209 210 211 212 213 214 215 216% warpreg: 217%------------------------------------------------------------------------218% no useful changes in the following testcases:219% [0 0.001 0.5 0.05 0.2] % the default setting220% [0 0.0001 0.001 0.01 0.1] % lower initial regularision with stepwise increasement 221% [0 0.001 0.01 0.1 0.2] % low initial regularision with stepwise increasement 222% [0.5 0.4 0.3 0.2 0.1] % medium initial regularision with stepwise decreasment 223% [1.0 0.8 0.6 0.4 0.2] % 224% [0.0 0.8 0.2 0.8 0.2] % 225%------------------------------------------------------------------------226warpreg = cfg_entry;227warpreg.def = @(val)cat_get_defaults('opts.warpreg', val{:});228warpreg.tag = 'warpreg';229warpreg.name = 'Warping Regularisation';230warpreg.strtype = 'r';231warpreg.num = [1 5];232warpreg.help = {233 'The objective function for registering the tissue probability maps to the image to process, involves minimising the sum of two terms. One term gives a function of how probable the data is given the warping parameters. The other is a function of how probable the parameters are, and provides a penalty for unlikely deformations. Smoother deformations are deemed to be more probable. The amount of regularisation determines the tradeoff between the terms. Pick a value around one. However, if your normalised images appear distorted, then it may be an idea to increase the amount of regularisation (by an order of magnitude). More regularisation gives smoother deformations, where the smoothness measure is determined by the bending energy of the deformations. '234 ''235};236 237 238% affreg239%------------------------------------------------------------------------240% no large differences 241% - mni was most stable242% - rigid did not work in ~20% of the cases (and is of course not meaningful here)243% - subj and none led to identical results 244% - no registration only for animals245%------------------------------------------------------------------------246affreg = cfg_menu;247affreg.tag = 'affreg';248affreg.name = 'Affine Regularisation';249affreg.help = {250 'The procedure is a local optimisation, so it needs reasonable initial starting estimates. Images should be placed in approximate alignment using the Display function of SPM before beginning. A Mutual Information affine registration with the tissue probability maps (D''Agostino et al, 2004) is used to achieve approximate alignment. Note that this step does not include any model for intensity non-uniformity. This means that if the procedure is to be initialised with the affine registration, then the data should not be too corrupted with this artifact. If there is a lot of intensity non-uniformity, then manually position your image in order to achieve closer starting estimates, and turn off the affine registration. Affine registration into a standard space can be made more robust by regularisation (penalising excessive stretching or shrinking). The best solutions can be obtained by knowing the approximate amount of stretching that is needed (e.g. ICBM templates are slightly bigger than typical brains, so greater zooms are likely to be needed). For example, if registering to an image in ICBM/MNI space, then choose this option. If registering to a template that is close in size, then select the appropriate option for this.'251 ''252};253if expert254 affreg.labels = {'ICBM space template - European brains','ICBM space template - East Asian brains','No regularisation','No Affine Registration'};255 affreg.values = {'mni','eastern','none',''};256 affreg.help = [affreg.help {257 'No affine registration was added for processing of animals, where registration may fail!'258 ''259 }];260else261 affreg.labels = {'ICBM space template - European brains','ICBM space template - East Asian brains','No regularisation'};262 affreg.values = {'mni','eastern','none'};263end264affreg.def = @(val)cat_get_defaults('opts.affreg', val{:});265 266 267 268% samp:269%------------------------------------------------------------------------270% Surprisingly, there is no systematical advantage in using higher271% resolution! Only very slightly in single cases, e.g. 7 Tesla. 272%------------------------------------------------------------------------273samp = cfg_entry;274samp.tag = 'samp';275samp.name = 'Sampling distance';276samp.strtype = 'r';277samp.num = [1 1];278samp.def = @(val)cat_get_defaults('opts.samp', val{:});279samp.help = {280 'This encodes the approximate distance between sampled points when estimating the model parameters. Smaller values use more of the data, but the procedure is slower and needs more memory. Determining the ""best"" setting involves a compromise between speed and accuracy.'281 ''282};283 284% SPM processing accuracy285tol = cfg_menu;286tol.tag = 'tol';287tol.name = 'SPM iteration accuracy';288tol.help = { ...289 'Parameter to control the iteration stop criteria of SPM preprocessing functions. In most cases the standard value is good enough for the initialization in CAT. However, some images with servere (local) inhomogeneities or atypical anatomy may benefit by further iterations. '290 };291tol.def = @(val)cat_get_defaults('opts.tol', val{:}); 292tol.labels = {'average (default)' 'high (slow)' 'ultra high (very slow)'};293tol.values = {1e-4 1e-8 1e-16};294if expert>1 % developer295 tol.labels = [{'ultra low (superfast)' 'low (fast)'} tol.labels {'insane'}];296 tol.values = [{1e-1 1e-2} tol.values {1e-32}];297end298 299% single parameter 300accspm = cfg_branch;301accspm.tag = 'spm';302accspm.name = 'Original SPM accuracy parameter';303accspm.val = {samp tol};304accspm.help = {305 'Official SPM resolution parameter ""samp"" and internal SPM iteration parameter ""tol"".' 306}; 307 308% combined SPM processing accuracy parameter309accstr = cfg_menu;310accstr.tag = 'accstr';311accstr.name = 'SPM processing accuracy';312accstr.help = { ...313 'Parameter to control the accuracy of SPM preprocessing functions. In most images the standard accuracy is good enough for the initialization in CAT. However, some images with severe (local) inhomogeneities or atypical anatomy may benefit by additional iterations and higher resolution. '314 };315accstr.labels = {'average (default)' 'high (slow)' 'ulta high (very slow)'};316accstr.values = {0.5 0.75 1.0};317accstr.def = @(val)cat_get_defaults('opts.accstr', val{:}); % no cat_defaults entry318if expert319 %accstr.labels = [{'ultra low (superfast)' 'low (fast)'} accstr.labels];320 %accstr.values = [{0 0.25} accstr.values];321 accstr.help = [accstr.help; 322 {''323 ['Overview of parameters: ' ...324 ' accstr: 0.50 0.75 1.00' ...325 ' samp: 3.00 2.00 1.00 (in mm)' ...326 ' tol: 1e-4 1e-8 1e-16' ...327 '' ...328 'SPM default is samp = 3 mm with tol = 1e-4. ']}];329end330 331% single parameter332acc = cfg_choice;333acc.tag = 'acc';334acc.name = 'SPM preprocessing accuracy parameters';335if cat_get_defaults('opts.accstr')>0336 acc.val = {accstr};337else338 acc.val = {accspm};339end340acc.values = {accstr accspm};341acc.help = {342 'Choose between single or combined SPM preprocessing accuracy parameters.' 343}; 344 345 346redspmres = cfg_entry;347redspmres.tag = 'redspmres';348redspmres.name = 'SPM preprocessing output resolution limit';349redspmres.strtype = 'r';350redspmres.num = [1 1];351redspmres.def = @(val)cat_get_defaults('opts.redspmres', val{:});352redspmres.help = {'Limit SPM preprocessing resolution to improve robustness and performance. Use 0 to process data in the full internal resolution.' ''};353 354 355%------------------------------------------------------------------------356opts = cfg_branch;357opts.tag = 'opts';358opts.name = 'Options for initial SPM12 preprocessing';359opts.help = {360 'CAT uses the Unified Segmentation of SPM12 for initial registration, bias correction, and segmentation. The parameters used here were optimized for a variety of protocols and anatomies. Only in case of strong inhomogeneity of high-field MR scanners we recommend to increase the biasstr parameter. For children data we recommend to use customized TPMs created by the Template-O-Matic toolbox. ' 361 ''362 };363if expert>1364 opts.val = {tpm,affreg,ngaus,warpreg,bias,acc,redspmres};365 opts.help = [opts.help; {366 'Increasing the initial sampling resolution to 1.5 or 1.0 mm may help in some cases of strong inhomogeneity but in general it only increases processing time.'367 ''368 'Strength of the bias correction ""biasstr"" controls the biasreg and biasfwhm parameter if biasstr>0!'369 ''370 }];371elseif expert==1372 opts.val = {tpm,affreg,biasstr,accstr};373 opts.help = [opts.help; {374 'Increasing the initial sampling resolution to 1.5 or 1.0 mm ma help in some cases of strong inhomogeneity but in general it only increases processing time.'375 ''376 }];377else378 opts.val = {tpm,affreg,biasacc};379 380end381 382","MATLAB"
383"Neurology","ChristianGaser/cat12","cat_io_handle_pre.m",".m","1621","38","function FO = cat_io_handle_pre(F,pre,addpre,existfile)384% Remove all known cat prefix types from a filename (and check if this file exist). 385% ______________________________________________________________________386%387% Christian Gaser, Robert Dahnke388% Structural Brain Mapping Group (https://neuro-jena.github.io)389% Departments of Neurology and Psychiatry390% Jena University Hospital391% ______________________________________________________________________392% $Id$393 394 if nargin<4, existfile = 1; end395 if nargin<3, addpre = 0; end396 397 [pp,ff,ee] = fileparts(F); 398 399 if ~addpre400 prefix{1} = {'r','m','e'};401 prefix{2} = {'ma','mb','mc','mv','mn','mi','ml', ... % modifications of T402 'pa','pb','p0','p1','p2','p3','p4','p5','pf','pp' ... % segmentations of T403 'en','eb','ev','ei','ej','em', ... % error maps404 't1','t2','t3','t4'}; % thickness and distaces405 prefix{3} = {'ra0','ra1','rw0','rw1','rwa','rwb','rwj', ...406 'rd0','rd1','rda','rdb','rdj', ...407 'rcs','lcs','bcs','acs','hcs'};408 prefix{4} = {'ercs','elcs','ebcs','eacs','ehcs'};409 410 for pf=1:numel(prefix)411 if numel(ff)>pf+1 && any(strcmp(ff(1:pf),prefix{pf})) && ...412 (~existfile || exist(fullfile(pp,[ff(pf+1:end) ee]),'file'))413 FN = cat_io_handle_pre(fullfile(pp,[ff(pf+1:end) ee]),'',addpre,existfile); 414 if (~existfile || exist(FN,'file')), [ppn,ffn] = fileparts(FN); ff=ffn; end415 end416 end417 end418 419 FO = fullfile(pp,[pre ff ee]);420end","MATLAB"
421"Neurology","ChristianGaser/cat12","cat_io_matlabversion.m",".m","867","33","function year = cat_io_matlabversion(varargin)422% return Matlab version year423% ______________________________________________________________________424%425% Christian Gaser, Robert Dahnke426% Structural Brain Mapping Group (https://neuro-jena.github.io)427% Departments of Neurology and Psychiatry428% Jena University Hospital429% ______________________________________________________________________430% $Id$431 432 433 if strcmpi(spm_check_version,'octave')434 year = 20201;435 return436 end437 438 vers = version;439 [t1,t2,t3,year] = regexp(vers,'\(R.....\)');440 switch year{1}(end-1)441 case 'a', year = [year{1}(3:end-2) '1'];442 case 'b', year = [year{1}(3:end-2) '2'];443 otherwise, year = [year{1}(3:end-2) '0'];444 end445 year = str2double(year);446 447 if nargin==1448 year = varargin{1}==year;449 end450 if nargin==2451 year = varargin{1}<=year && year<=varargin{1};452 end453end","MATLAB"
454"Neurology","ChristianGaser/cat12","optimizer3d.h",".h","682","14","/* $Id$ */455/* (c) John Ashburner (2007) */456extern void fmg3(int n0[], float *a0, float *b0, int rtype, double param[], int c, int nit,457 float *u0, float *scratch);458extern void cgs3(int dm[], float A[], float b[], int rtype, double param[], double tol, int nit,459 float x[], float r[], float p[], float Ap[]);460extern void resize(int na[], float *a, int nc[], float *c, float *b);461extern float norm(int m, float a[]);462extern void LtLf_be(int dm[], float f[], double s[], float g[]);463extern void LtLf_me(int dm[], float f[], double s[], float g[]);464extern void LtLf_le(int dm[], float f[], double s[], float g[]);465extern int fmg3_scratchsize(int n0[]);466 467","Unknown"
468"Neurology","ChristianGaser/cat12","cat_io_json.m",".m","632","34","function S = cat_io_json(varargin)469%cat_io_json. Read json file. 470 471 S = struct();472 473 if nargin == 1474 if isstruct(varargin{1})475 % job case476 files = job.files; 477 else478 % just a file479 files = cellstr(varargin{1});480 end481 end482 483 for fi = 1:numel(files)484 if ~exist(files{fi},'file')485 cat_io_cprintf('err','ERROR: Miss ""%s""\n',files{fi})486 else487 fid = fopen(files{fi}); 488 raw = fread(fid,inf); 489 str = char(raw'); 490 fclose(fid); 491 val = jsondecode(str);492 493 if fi == 1494 S = val; 495 else496 S = cat_io_mergeStruct(S,val); 497 end498 end499 end500end501 ","MATLAB"
502"Neurology","ChristianGaser/cat12","cat_stat_nanmedian.m",".m","2576","89","function out = cat_stat_nanmedian(in, dim)503% ----------------------------------------------------------------------504% Median, not considering NaN values. Similar usage like median() or 505% MATLAB nanmedian of the statistic toolbox. Process input as double506% due to errors in large single arrays and set data class of ""out"" 507% to the data class of ""in"" at the end of the processing,508% Use dim==0 to evaluate in(:) in case of dimension selection 509% (e.g., in(:,:,:,2) ).510%511% out = cat_stat_nanmedian(in,dim)512%513% Example 1:514% a = rand(4,6,3); 515% a(rand(size(a))>0.5)=nan; 516% av = cat_stat_nanmedian(a,3); 517% am = nanmedian(a,3); % of the statistical toolbox ...518% fprintf('%0.4f %0.4f\n',([av(:),am(:)])');519%520% Example 2 - special test call of example 1:521% cat_stat_nanmedian('test')522%523% See also cat_stat_nansum, cat_stat_nanstd, cat_stat_nanmean.524% ______________________________________________________________________525%526% Christian Gaser, Robert Dahnke527% Structural Brain Mapping Group (https://neuro-jena.github.io)528% Departments of Neurology and Psychiatry529% Jena University Hospital530% ______________________________________________________________________531% $Id$532 533 if nargin < 1534 help cat_stat_nanmedian;535 return;536 end;537 538 if ischar(in) && strcmp(in,'test')539 a = rand(4,6,3); 540 a(rand(size(a))>0.5)=nan; 541 av = cat_stat_nanmedian(a,3); 542 am = nanmedian(a,3); % of the statistical toolbox ...543 fprintf('%0.4f %0.4f\n',([av(:),am(:)])');544 out = nanmean(av(:) - am(:)); 545 return; 546 end547 548 if nargin < 2549 if size(in,1) ~= 1550 dim = 1;551 elseif size(in,2) ~= 1552 dim = 2;553 else 554 dim = 3; 555 end;556 end;557 558 if dim == 0 559 in = in(:); 560 dim = 1; 561 end562 563 sz = size(in);564 565 if isempty(in), out = nan; return; end566 tp = class(in);567 in = double(in); % single failed in large arrays568 569 % reduce to 2d matrix570 pm = [dim:max(length(size(in)),dim) 1:dim-1];571 in = reshape(permute(in,pm),size(in,dim),prod(sz)/size(in,dim));572 573 in = sort(in,1);574 s = size(in,1) - sum(isnan(in));575 576 % estimate median in loop577 out = zeros(size(s));578 for i = 1:length(s)579 if s(i)>0, out(i) = cat_stat_nanmean([in(floor((s(i)+1)/2),i),in(ceil((s(i)+1)/2),i)]); else out(i)=nan; end580 end581 582 % estimate median as matrix ... doesn't work :/583 %out = nan(size(s)); si=1:numel(s);584 %out(s>0) = nanmean( [ in(([floor((s(s>0)+1)/2);si(s>0)])'); in(ceil((s(s>0)+1)/2),si(s>0)) ] );585 586 % correct for permutation587 sz(dim) = 1; out = ipermute(reshape(out,sz(pm)),pm);588 589 eval(sprintf('out = %s(out);',tp));590end","MATLAB"
591"Neurology","ChristianGaser/cat12","cat_io_mergeStruct.m",".m","2571","93","function S=cat_io_mergeStruct(S,SN,ri,id)592% _________________________________________________________________________593% Merge to structures 'S' and 'SN'. 594%595% S = cat_io_mergeStruct(S,SN[,[],id])596% 597% where id>0 updates elements S(id) 598% 599% WARNING:600% This function is still in developent! Be careful by using it, due to601% unexpected behaviour. Updating of structures is a complex topic with 602% many subcases and here only a simple alignment is used!603%604% ______________________________________________________________________605%606% Christian Gaser, Robert Dahnke607% Structural Brain Mapping Group (https://neuro-jena.github.io)608% Departments of Neurology and Psychiatry609% Jena University Hospital610% ______________________________________________________________________611% $Id$612 613 % check input614 maxri = 20; 615 if ~exist('id','var') || isempty(id), id=0; end616 if ~exist('ri','var') || isempty(ri), ri=0; end617 618 SFN = fieldnames(S);619 SNFN = fieldnames(SN);620 621 %% add new empty fields in additional element in S622 NSFN = setdiff(SNFN,SFN);623 if ~isempty(NSFN)624 ne = numel(S)+1; 625 for ni = 1:numel(NSFN)626 if isnumeric(SN(1).(NSFN{ni})) 627 S(ne).(NSFN{ni}) = [];628 elseif islogical(SN(1).(NSFN{ni}))629 S(ne).(NSFN{ni}) = false; 630 elseif ischar(SN(1).(NSFN{ni}))631 S(ne).(NSFN{ni}) = '';632 elseif isstruct(SN(1).(NSFN{ni}))633 if ri<maxri634 Stmp = cat_io_mergeStruct(struct(),SN(1).(NSFN{ni})(1),ri+1);635 else636 Stmp = struct(); 637 end638 S(ne).(NSFN{ni}) = Stmp(1);639 elseif iscell(SN(1).(NSFN{ni}))640 S(ne).(NSFN{ni}) = {};641 end642 end643 S(ne) = []; 644 end645 646 %%647 NSSFN = setdiff(SFN,SNFN);648 if ~isempty(NSSFN)649 sne = numel(SN) + 1; 650 for ni = 1:numel(NSSFN)651 if isnumeric(S(1).(NSSFN{ni})) 652 SN(sne).(NSSFN{ni}) = [];653 elseif islogical(S(1).(NSSFN{ni}))654 SN(sne).(NSSFN{ni}) = false(0);655 elseif ischar(S(1).(NSSFN{ni}))656 SN(sne).(NSSFN{ni}) = '';657 elseif isstruct(S(1).(NSSFN{ni}))658 if ri<maxri && ~isempty(fieldnames(S))659 Stmp = cat_io_mergeStruct(struct(),S(1).(NSSFN{ni})(1),ri+1);660 else661 Stmp = struct(); 662 end663 SN(sne).(NSSFN{ni}) = Stmp(1);664 elseif iscell(S(1).(NSSFN{ni}))665 SN(sne).(NSSFN{ni}) = {};666 end667 end668 SN(sne) = [];669 end670 671 %%672 S = orderfields(S);673 SN = orderfields(SN);674 675 ns = numel(S); 676 for sni=1:numel(SN)677 if id==0678 S(ns + sni) = SN(sni);679 else680 S(id + sni - 1) = SN(sni);681 end682 end683end","MATLAB"
684"Neurology","ChristianGaser/cat12","cat_surf_render2.m",".m","130198","3207","function varargout = cat_surf_render2(action,varargin)685% Display a surface mesh & various utilities686% FORMAT H = cat_surf_render2('Disp',M,'PropertyName',propertyvalue)687% M - a GIfTI filename/object or patch structure688% H - structure containing handles of various objects689% Opens a new figure unless a 'parent' Property is provided with an axis690% handle.691%692% FORMAT H = cat_surf_render2(M)693% Shortcut to previous call format.694%695% FORMAT H = cat_surf_render2('view',VIEW)696% FORMAT H = cat_surf_render2('view',H,VIEW)697% Camera line of sight698% VIEW - [az,el] set the azimuth and elevation angles of the camera699% - ['left'|'right'|'top'|'bottom'|'front'|'back'] 700% H - structure containing handles of various objects701%702% FORMAT H = cat_surf_render2('clim',LIMITS)703% FORMAT H = cat_surf_render2('clim',H,LIMITS)704% Set colormap limits.705% H - structure containing handles of various objects706% LIMITS - [cmin cmax] lower and upper limit 707% LIMITS - ['p1'|'p2'|'p5'] settings for 99, 98, and 95 percent 708% 709% FORMAT H = cat_surf_render2('ContextMenu',AX)710% AX - axis handle or structure returned by cat_surf_render2('Disp',...)711%712% FORMAT H = cat_surf_render2('Overlay',AX,P)713% AX - axis handle or structure given by cat_surf_render2('Disp',...)714% P - data to be overlayed on mesh (see spm_mesh_project)715%716% FORMAT H = cat_surf_render2('ColourBar',AX,MODE)717% AX - axis handle or structure returned by cat_surf_render2('Disp',...)718% MODE - {['on'],'off'}719%720% FORMAT H = cat_surf_render2('Clim',AX,[mn mx])721% AX - axis handle or structure given by cat_surf_render2('Disp',...)722% mn mx - min/max of range723%724% FORMAT H = cat_surf_render2('Clip',AX,[mn mx])725% AX - axis handle or structure given by cat_surf_render2('Disp',...)726% mn mx - min/max of clipping range727%728% FORMAT H = cat_surf_render2('ColourMap',AX,MAP)729% AX - axis handle or structure returned by cat_surf_render2('Disp',...)730% MAP - a colour map matrix731%732% FORMAT MAP = cat_surf_render2('ColourMap',AX)733% Retrieves the current colourmap.734%735% FORMAT H = cat_surf_render2('Underlay',AX,P)736% AX - axis handle or structure given by cat_surf_render2('Disp',...)737% P - data (curvature) to be underlayed on mesh (see spm_mesh_project)738%739% FORMAT H = cat_surf_render2('Clim',AX, range)740% range - range of colour scaling741%742% FORMAT H = cat_surf_render2('SaveAs',AX, filename)743% filename - filename744%745% FORMAT cat_surf_render2('Register',AX,hReg)746% AX - axis handle or structure returned by cat_surf_render2('Disp',...)747% hReg - Handle of HandleGraphics object to build registry in.748% See spm_XYZreg for more information.749%__________________________________________________________________________750% Copyright (C) 2010-2011 Wellcome Trust Centre for Neuroimaging751% ______________________________________________________________________752%753% Christian Gaser, Robert Dahnke754% Structural Brain Mapping Group (https://neuro-jena.github.io)755% Departments of Neurology and Psychiatry756% Jena University Hospital757% ______________________________________________________________________758% based on spm_mesh_render.m759% $Id$760 761%#ok<*ASGLU>762%#ok<*INUSL>763%#ok<*INUSD>764%#ok<*TRYNC>765 766 767 768 769% we need to hide some options ...770expert = 2; %cat_get_defaults('extopts.expertgui'); 771try772 cat_get_defaults('print.dpi'); 773catch774 cat_get_defaults('print.dpi',150); 775end776try777 cat_get_defaults('print.type'); 778catch779 cat_get_defaults('print.type','.png'); 780end781 782 783 784%-Input parameters785%--------------------------------------------------------------------------786if ~nargin, action = 'Disp'; end787 788if ~ischar(action)789 varargin = {action varargin{:}};790 action = 'Disp';791end792 793if nargout, varargout = {[]}; end794 795%-Action796%--------------------------------------------------------------------------797switch lower(action)798 799 %-Display800 %======================================================================801 case 'disp'802 if isempty(varargin)803 [M, sts] = spm_select(1,'any','Select surface mesh file');804 if ~sts, return; end805 varargin{1} = cellstr(M);806 else807 M = varargin{1};808 end809 810 811 %%812 %-Figure & Axis813 %------------------------------------------------------------------814 O = getOptions(varargin{2:end});815 if isfield(O,'parent')816 H.issubfigure = 1; 817 H.axis = O.parent;818 H.figure = ancestor(H.axis,'figure');819 % this brings the figure to the foreground :/820 %figure(H.figure); axes(H.axis);821 else822 H.issubfigure = 0;823 H.figure = figure('Color',[1 1 1]);824 H.axis = axes('Parent',H.figure,'Visible','off');825 end826 if isfield(O,'pcdata'), O.pcdata = cellstr(O.pcdata); end827 if isfield(O,'pmesh'), O.pmesh = cellstr(O.pmesh); end828 renderer = get(H.figure,'Renderer');829 830 %{831 try832 % warning to error833 val = feval('set',H.figure,'Renderer','OpenGL');834 if isempty(val)==0 835 error('OpenGLerr')836 end837 catch 838 cat_io_cprintf('err','OpenGL error - cannot display surface\n');839 return840 end841 %}842 if ~isstruct(varargin{1}) && ~isa(varargin{1},'gifti')843 % surface info844 if nargin>=3845 sinfo = cat_surf_info(varargin{3}); 846 elseif nargin>=1847 if ischar(varargin{1})848 %%849 for i=1:size(varargin{1},1)850 [pp,ff,ee] = spm_fileparts(varargin{1}(i,:)); 851 varargin{1}(i,:) = fullfile(pp,[ff strrep(ee,'.dat','.gii')]);852 end853 else854 for i=1:numel(varargin{1})855 [pp,ff,ee] = spm_fileparts(varargin{1}{i}); 856 varargin{1}{i} = fullfile(pp,[ff strrep(ee,'.dat','.gii')]);857 end858 end859 sinfo = cat_surf_info(varargin{1}); 860 else861 sinfo = cat_surf_info(M);862 end863 if ischar(varargin{1})864 sinfo(1).Pmesh = varargin{1};865 end866 867 %%868 labelmap = zeros(0); labelnam = cell(0); labelmapclim = zeros(1,2); labeloid = zeros(0); labelid = zeros(0); nid=1;869 for pi=1:numel(sinfo)870 871 if ~exist(sinfo(pi).fname,'file')872 error('cat_surf_render:nofile','The file ""%s"" does not exist!',sinfo(pi).fname); 873 end874 875 H.filename{pi} = sinfo(pi).fname; 876 877 % load mesh878 [pp,ff,ee] = spm_fileparts(sinfo(pi).Pmesh);879 switch ee880 case '.gii'881 S = gifti(sinfo(pi).Pmesh); 882 otherwise883 S = gifti(cat_io_FreeSurfer('read_surf',sinfo(pi).Pmesh));884 end885 886 887 if ~isfield(S,'cdata') && ~isempty(O) && isfield(O,'pcdata')888 % load texture889 [pp,ff,ee] = spm_fileparts(sinfo(pi).Pdata);890 switch sinfo(pi).ee891 case '.gii'892 cdata = gifti(O.pcdata{pi}); 893 cdatap = export(cdata,'patch');894 if isfield(cdatap,'facevertexcdata')895 cdata = cdatap.facevertexcdata; 896 elseif isfield(cdata,'cdata')897 if isnumeric(cdata.cdata)898 cdata = cdata.cdata; 899 else900 fname = cdata.cdata.fname; 901 fid = fopen(fname, 'r', 'b') ;902 if (fid < 0)903 str = sprintf('could not open curvature file %s', fname) ;904 error(str) ;905 end906 cdata = fread(fid, 'double') ;907 fclose(fid);908 909 end910 end911 if isnumeric(cdata) 912 labelmapclim = [min(cdata) max(cdata)];913 else914 if isfield(cdata,'cdata')915 labelmapclim = [min(cdata.cdata) max(cdata.cdata)];916 elseif isfield(cdata,'vertices')917 labelmapclim = [0 0];918 cdata = zeros(size(cdata.vertices,1),1,'single');919 else920 labelmapclim = [];921 cdata = [];922 end923 end924 case '.annot' 925 %%926 [fsv,cdatao,colortable] = cat_io_FreeSurfer('read_annotation',O.pcdata{pi}); clear fsv;927 cdata = zeros(size(cdatao));928 entries = round(unique(cdatao));929 930 for ei = 1:numel(entries)931 cid = find( labeloid == entries(ei) ,1); % previous imported label?932 if ~isempty(cid) % previous imported label933 cdata( round(cdatao) == entries(ei) ) = labelid(cid); 934 else % new label > new entry935 id = find( colortable.table(:,5)==entries(ei) , 1);936 if ~isempty(id)937 cdata( round(cdatao) == entries(ei) ) = nid; 938 labelmap(nid,:) = colortable.table(id,1:3)/255;939 labelnam(nid) = colortable.struct_names(id);940 labeloid(nid) = entries(ei);941 labelid(nid) = nid;942 labelmapclim(2) = nid;943 nid = nid+1;944 end945 end946 end947 948 otherwise949 St = gifti(struct('cdata',cat_io_FreeSurfer('read_surf_data',sinfo(pi).Pdata)));950 cdata = St.cdata; clear St; 951 labelmapclim = [min(cdata) max(cdata)];952 end953 S.cdata = cdata; clear cdata; 954 S = export(S,'patch');955 elseif isfield(S,'cdata') 956 S = export(S,'patch');957 labelmapclim = [min(S.facevertexcdata) max(S.facevertexcdata)];958 end959 % ignore this warning writing gifti with int32 (eg. cat_surf_createCS:580 > gifti/subsref:45)960 warning off MATLAB:subscripting:noSubscriptsSpecified961 % flip faces in case of defect surfaces962 if mean(max(S.vertices + spm_mesh_normals(S)) - max(S.vertices))>0963 %if strcmp(sinfo(1).texture,'defects'), 964 S.faces = S.faces(:,[2,1,3]); 965 end966 % use original colormap from annot file otherwise use jet967 if ~strcmp(sinfo(pi).ee,'.annot')968 labelmap = jet; 969 end970 971 972 % Patch973 % ----------------------------------------------------------974 P = struct('vertices',S.vertices, 'faces',double(S.faces));975 H.patch(pi) = patch(P,...976 'FaceColor', [0.6 0.6 0.6],...977 'EdgeColor', 'none',...978 'FaceLighting', 'gouraud',...979 'SpecularStrength', 0.0,... 0.7980 'AmbientStrength', 0.4,... 0.1981 'DiffuseStrength', 0.6,... 0.7982 'SpecularExponent', 10,...983 'Clipping', 'off',...984 'DeleteFcn', {@myDeleteFcn, renderer},...985 'Visible', 'off',...986 'Tag', 'CATSurfRender',...987 'Parent', H.axis);988 setappdata(H.patch(pi),'patch',P);989 990 %% -Label connected components of the mesh991 %------------------------------------------------------------------992 C = spm_mesh_label(P);993 setappdata(H.patch(pi),'cclabel',C);994 995 %-Compute mesh curvature996 %------------------------------------------------------------------997 curv = spm_mesh_curvature(P); %$ > 0;998 setappdata(H.patch(pi),'curvature',curv);999 1000 %-Apply texture to mesh1001 %------------------------------------------------------------------1002 if isfield(S,'cdata')1003 T = S.cdata;1004 elseif isfield(S,'facevertexcdata')1005 T = S.facevertexcdata;1006 else1007 T = [];1008 end1009 try1010 updateTexture(H,T,pi);1011 end1012 1013 H.cdata = T; % remove this later ...1014 clear S P; 1015 end1016 H.sinfo = sinfo; 1017 else1018 labelmap = jet; 1019 if 0 %flip1020 S.vertices = [varargin{1}.vertices(:,2) varargin{1}.vertices(:,1) varargin{1}.vertices(:,3)]; 1021 else1022 S.vertices = varargin{1}.vertices;1023 end1024 S.faces = varargin{1}.faces; 1025 if isfield(varargin{1},'facevertexcdata'), S.cdata = varargin{1}.facevertexcdata; end1026 S = gifti(S);1027 S = export(S,'patch'); 1028 warning off;1029 curv = spm_mesh_curvature(S); %$ > 0;1030 warning on; 1031 1032 labelnam = cell(0); %labelmapclim = zeros(1,2); labeloid = zeros(0); labelid = zeros(0); nid=1;1033 P = struct('vertices',S.vertices, 'faces',double(S.faces));1034 H.patch(1) = patch(P,...1035 'FaceColor', [0.6 0.6 0.6],...1036 'EdgeColor', 'none',...1037 'FaceLighting', 'gouraud',...1038 'SpecularStrength', 0.0,... 0.71039 'AmbientStrength', 0.4,... 0.11040 'DiffuseStrength', 0.6,... 0.71041 'SpecularExponent', 10,...1042 'Clipping', 'off',...1043 'DeleteFcn', {@myDeleteFcn, renderer},...1044 'Visible', 'off',...1045 'Tag', 'CATSurfRender',...1046 'Parent', H.axis);1047 setappdata(H.patch(1),'patch',P);1048 C = spm_mesh_label(P);1049 setappdata(H.patch(1),'cclabel',C);1050 setappdata(H.patch(1),'curvature',curv);1051 1052 if isfield(varargin{1},'cdata')1053 try1054 T = gifti(varargin{1}.cdata);1055 catch1056 T = gifti(varargin{1});1057 end1058 T = T.cdata;1059 elseif isfield(varargin{1},'facevertexcdata')1060 try1061 T = gifti(varargin{1}.facevertexcdata);1062 catch1063 T = gifti(varargin{1});1064 end1065 T = T.cdata;1066 else1067 T = [];1068 end1069 try1070 warning off;1071 updateTexture(H,T,1);1072 warning on;1073 catch 1074 warning on; 1075 end1076 labelmapclim = [min(T) max(T)];1077 H.filename{1} = ''; 1078 H.cdata = T; 1079 sinfo = cat_surf_info('');1080 H.sinfo = sinfo; 1081 1082 if mean(max(S.vertices + spm_mesh_normals(S)) - max(S.vertices))>01083 %if strcmp(sinfo(1).texture,'defects'), 1084 S.faces = S.faces(:,[2,1,3]); 1085 end1086 %if strcmp(sinfo(1).texture,'defects'), S.faces = S.faces(:,[2,1,3]); end1087 end1088 1089 1090 %% -Set viewpoint, light and manipulation options1091 %------------------------------------------------------------------1092 axis(H.axis,'image');1093 axis(H.axis,'off');1094 material(H.figure,'dull');1095 1096 % default lighting1097 if 1 && ismac, H.catLighting = 'inner'; else H.catLighting = 'cam'; end1098 1099 1100 [caz,cel] = view;1101 H.light(1) = camlight('headlight','infinite'); 1102 set(H.light(1),'Parent',H.axis,'Tag','camlight'); 1103 switch H.catLighting1104 case 'inner'1105 % switch off local light (camlight)1106 set(H.light(1),'visible','off','parent',H.axis);1107 1108 % set inner light1109 H.light(2) = light('Position',[0 0 0],'parent',H.axis,'Tag','centerlight'); 1110 for pi=1:numel(H.patch)1111 set(H.patch(pi),'BackFaceLighting','unlit');1112 end1113 end1114 1115 1116 if ~H.issubfigure1117 H.rotate3d = rotate3d(H.axis);1118 set(H.rotate3d,'Enable','on');1119 set(H.rotate3d,'ActionPostCallback',{@myPostCallback, H});1120 end1121 1122 1123 %-Store handles1124 %------------------------------------------------------------------1125 setappdata(H.axis,'handles',H);1126 for pi=1:numel(H.patch)1127 set(H.patch(pi),'Visible','on');1128 setappdata(H.patch(pi),'clip',[false NaN NaN]);1129 end1130 1131 1132 for pi=1:numel(H.patch)1133 setappdata(H.patch(pi),'colourmap',labelmap); 1134 end1135 try1136 cat_surf_render2('clim',H.axis,labelmapclim); % RD20221129: Sometimes problems in fast surfaces 1137 end1138 colormap(labelmap); try caxis(labelmapclim); end1139 1140 if numel(labelnam)>01141 %%1142 H = cat_surf_render2('ColorBar',H.axis,'on'); 1143 labelnam2 = [{''} labelnam]; for lni=1:numel(labelnam2),labelnam2{lni} = [' ' labelnam2{lni} ' ']; end1144 1145 labellength = min(100,max(cellfun('length',labelnam2))); 1146 ss = max(1,round(diff(labelmapclim+1)/60)); 1147 ytick = labelmapclim(1):ss:labelmapclim(2);1148 1149 set(H.colourbar,'ytick',ytick,'yticklabel',labelnam2(1:ss:end),...1150 'Position',[max(0.75,0.98-0.008*labellength) 0.05 0.02 0.9]);1151 try, set(H.colourbar,'TickLabelInterpreter','none'); end1152 set(H.axis,'Position',[0.1 0.1 min(0.6,0.98-0.008*labellength - 0.2) 0.8])1153 1154 H.labelmap = struct('colormap',labelmap,'ytick',ytick,'labelnam2',{labelnam2});1155 setappdata(H.axis,'handles',H);1156 end1157 1158 1159 % annotation for colormap ...1160 %if ~H.issubfigure1161 % [pp,ff,ee] = fileparts(H.filename{1}); 1162 % H.text = annotation('textbox','string',[ff ee],'position',[0.0,0.97,0.2,0.03],'LineStyle','none','Interpreter','none');1163 %end1164 1165 1166 %-Add context menu1167 %------------------------------------------------------------------1168 if ~isfield(O,'parent')1169 %try1170 cat_surf_render2('ContextMenu',H);1171 %end1172 end1173 1174 if strcmp(renderer,'painters')1175 1176 end1177 1178 % set default view1179 cat_surf_render2('view',H,[ 0 90]);1180 if numel(H.patch)==11181 if strcmp(H.sinfo(1).side,'lh'); cat_surf_render2('view',H,[ -90 0]); end1182 if strcmp(H.sinfo(1).side,'rh'); cat_surf_render2('view',H,[ 90 0]); end1183 %if strcmp(H.sinfo(1).side,'ch'); cat_surf_render2('view',H,[ 0 90]); end1184 end 1185 1186 % remember this zoom level1187 axis vis3d; %zoom(1.15);1188 zoom reset1189 1190 1191 %-Context Menu1192 %======================================================================1193 case 'contextmenu'1194 1195 if isempty(varargin), varargin{1} = gca; end1196 H = getHandles(varargin{1});1197 sinfo1 = cat_surf_info(H.filename);1198 if ~isempty(get(H.patch(1),'UIContextMenu')), return; end1199 1200 cmenu = uicontextmenu('Callback',{@myMenuCallback, H});