Doxygen Source Code Documentation
AFNI_CoordChange.m
Go to the documentation of this file.00001 function [err,maplocation, mapsign, Mtrans] = AFNI_CoordChange (Orig, Trans, Morig)
00002 %
00003 % [err, maplocation, mapsign, Mtrans] = AFNI_CoordChange (Orig, Trans, [Morig])
00004 %
00005 %Purpose:
00006 % Change the AFNI coordinate system between the 48 different coordinate systems allowed
00007 % Coordinates are as they appear on the top left corner of AFNI's controller
00008 % Coord Order plugin is used to change the coordinate system in AFNI
00009 %
00010 %Input Parameters:
00011 % Orig : the 1x3 letter or number code for the original orientation, like RAI or [1 3 4]
00012 % Trans : the 1x3 letter or number code for the new orientation
00013 % Morig : an (optional) Nx3 matrix containing the XYZ coordinates of N points
00014 %
00015 %Output Parameters:
00016 % err : 0 No Problem
00017 % : 1 Mucho Problems
00018 % maplocation: 1x3 vector containig the map from the old coordinate to the new coordinate system
00019 % This specifies where each dimension in Mtrans is located in Morig
00020 % mapsign: 1x3 vector (of 1 or -1) containing the sign of the map from the old coordinate system to the new one
00021 % This specifies if the dimension has a negative direction (see more Info for an example)
00022 % Mtrans: if Morig is specified, Mtrans is Morig in the new coordinate system
00023 %
00024 %
00025 %Key Terms:
00026 %
00027 %More Info :
00028 %
00029 % maplocation and mapsign are used as such
00030 %
00031 % for (i=1:1:3),
00032 % Mtrans(:,i) = mapsign(i).* Morig(:,maplocation(i));
00033 % end
00034 %
00035 % example:
00036 %[err,maplocation, mapsign, Mtrans] = AFNI_CoordChange ('RAI', 'ALI', [1 2 3; 4 5 6])
00037 %
00038 % Author : Ziad Saad
00039 % Date : Tue Sep 5 18:56:40 PDT 2000
00040 % LBC/NIMH/ National Institutes of Health, Bethesda Maryland
00041
00042
00043 %Define the function name for easy referencing
00044 FuncName = 'AFNI_CoordChange';
00045
00046 %Debug Flag
00047 DBG = 1;
00048
00049 if (nargin == 2),
00050 Morig = [];
00051 end
00052
00053 if (~isempty(Morig) & size(Morig,2) ~= 3),
00054 err = ErrEval(FuncName,'Err_Bad size for Morig');
00055 return;
00056 end
00057
00058
00059 %initailize return variables
00060 err = 1;
00061 Mtrans= [];
00062 maplocation = [0 0 0];
00063 mapsign = [0 0 0];
00064
00065 if (ischar(Orig)),
00066 [err, OrCode] = AFNI_OrientCode (Orig);
00067 else
00068 OrCode = Orig;
00069 end
00070
00071 if (ischar(Trans)),
00072 [err, TrCode] = AFNI_OrientCode (Trans);
00073 else
00074 TrCode = Trans;
00075 end
00076
00077 for (i=1:1:3),
00078 %look for the orientation
00079 itmp = find (OrCode == TrCode(i));
00080 if (~isempty(itmp)), %found, no need for flipping
00081 maplocation(i) = itmp;
00082 mapsign(i) = 1;
00083 else %look for opposite orientation, need flipping
00084 if (rem(TrCode(i),2)),
00085 shft = -1;
00086 else
00087 shft = 1;
00088 end
00089 itmp = find(OrCode == TrCode(i)+shft);
00090 if (isempty(itmp)),
00091 err = ErrEval(FuncName,'Err_Bad code duuude');
00092 end
00093 maplocation(i) = itmp;
00094 mapsign(i) = -1;
00095 end
00096 end %for i
00097
00098 if (~isempty(Morig)),
00099 Mtrans = Morig;
00100 for (i=1:1:3),
00101 Mtrans(:,i) = mapsign(i).* Morig(:,maplocation(i));
00102 end
00103 end
00104
00105 err = 0;
00106 return;
00107