Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


AFNI_IndexChange.m

Go to the documentation of this file.
00001 function [err, Itrans] = AFNI_IndexChange (Info, Iorig, Direction, DispOrient)
00002 %
00003 %   [err, Itrans] = AFNI_IndexChange (Info, Iorig, Direction, [DispOrient])
00004 %
00005 %Purpose:
00006 %   Change the AFNI Index system between the display's and AFNI's coordinate system 
00007 %   
00008 %   
00009 %Input Parameters:
00010 %   Info: The data structure output from BrikInfo 
00011 %   Iorig : anNx3 matrix containing the Ix Iy Iz indices of N points
00012 %   Direction : A string : either 'A2D' or 'D2A' meaning Afni to Display or vice versa
00013 %   DispOrient : The orientation string (or vector) for AFNI's display. This parameter is optional
00014 %    and the defualt is 'RAI", it could be 'LAI' if AFNI's using Left is Left option.
00015 %
00016 %Output Parameters:
00017 %   err : 0 No Problem
00018 %       : 1 Mucho Problems
00019 %   Itrans: if Iorig is specified, Itrans is Iorig in the new coordinate system
00020 %   
00021 %   
00022 %      
00023 %Key Terms:
00024 %   
00025 %More Info :
00026 %   Test_AFNI_IndexChange
00027 %   
00028 %   see also AFNI_CoordChange
00029 %   
00030 %
00031 %     Author : Ziad Saad
00032 %     Date : Fri Sep 8 12:21:01 PDT 2000
00033 %     LBC/NIMH/ National Institutes of Health, Bethesda Maryland
00034 
00035 
00036 %Define the function name for easy referencing
00037 FuncName = 'AFNI_IndexChange';
00038 
00039 %Debug Flag
00040 DBG = 1;
00041 
00042 %initailize return variables
00043 err = 1;
00044 Itrans= [];
00045 maplocation = [0 0 0];
00046 mapsign = [0 0 0];
00047 
00048 
00049 if (nargin == 3),
00050         DispOrient = [0 3 4]; %that's RAI
00051 end
00052 
00053 
00054 %Assume we're going from Display to Afni ('D2A)
00055 if (ischar(DispOrient)),
00056         [err, OrCode] = AFNI_OrientCode (DispOrient);
00057 else
00058         OrCode = DispOrient;
00059 end
00060 
00061         [err, TrCode] = AFNI_OrientCode (Info.Orientation(:,1)');
00062 
00063 %check if that's what is required
00064 if (strmatch(Direction, 'A2D')),
00065         %we're going from Afni to Display coordinates
00066                 tmp = TrCode;
00067                 TrCode = OrCode;
00068                 OrCode = tmp;
00069 else
00070         if (~strmatch(Direction, 'D2A')),
00071                 err = ErrEval(FuncName,'Err_Bad Direction string');
00072                 return;
00073         end
00074 end     
00075         
00076 
00077 %get maplocation and mapsign, automatically from AFNI_CoordChange (no need to rewrite the code here)
00078         [err,maplocation, mapsign] = AFNI_CoordChange (OrCode, TrCode);
00079 
00080 Itrans = Iorig;
00081 if (strmatch(Direction, 'A2D')),
00082                 fprintf ('Doing A2D\n');
00083                 %(1-mapsign(i))./2 is 0 when mapsign(i) = 1 and 1 when mapsign(i) = -1;  This way, the if condition for mapsign(i) can be done away with
00084                 %I left the simple method for the second loop for clarity. i don't think there's much efficiency difference between the two.
00085         for (i=1:1:3),
00086                 Itrans(:,i) = ( (1-mapsign(i))./2 .* (Info.DATASET_DIMENSIONS(maplocation(i)) - 1) ) + ( mapsign(i) .* Iorig(:,maplocation(i)) );
00087         end
00088 else
00089                 fprintf ('Doing D2A: \n');
00090         for (i=1:1:3),
00091                 Itrans(:,i) = Iorig(:,maplocation(i));
00092                 if (mapsign(i) < 0),
00093                         Itrans(:,i) = Info.DATASET_DIMENSIONS((i)) -1 - Itrans(:,i);
00094                 end
00095         end     
00096 end
00097 
00098 
00099 err = 0;
00100 return;
00101 
 

Powered by Plone

This site conforms to the following standards: