1 #include "mrilib.h"
2 
3 /*---------------------------------------------------------------------------*/
4 /*! Input is a dataset axes struct and an orientation code.
5     Output is an int saying which dataset axis is this code.
6      -  +1 => dataset +x-axis
7      -  -1 => dataset -x-axis, etc.
8      -   0 => bad inputs
9      - RWCox - 19 Mar 2003
10 -----------------------------------------------------------------------------*/
11 
THD_get_axis_direction(THD_dataxes * daxes,int orient_code)12 int THD_get_axis_direction( THD_dataxes * daxes, int orient_code )
13 {
14    if( daxes == NULL ) return 0;
15 
16    if(                 daxes->xxorient  == orient_code ) return  1 ;
17    if( ORIENT_OPPOSITE(daxes->xxorient) == orient_code ) return -1 ;
18    if(                 daxes->yyorient  == orient_code ) return  2 ;
19    if( ORIENT_OPPOSITE(daxes->yyorient) == orient_code ) return -2 ;
20    if(                 daxes->zzorient  == orient_code ) return  3 ;
21    if( ORIENT_OPPOSITE(daxes->zzorient) == orient_code ) return -3 ;
22    return 0 ;
23 }
24 
25 /* fill ostr with the 3 letter orient code (e.g. LPI) given integer codes
26  *    - null terminate ostr (so there must be space for 4 bytes)
27  *    - return 0 on success, 1 on error
28  * (ostr is just char *, the 4 is a reminder)   23 Jan 2013 [rickr] */
THD_fill_orient_str_3(THD_dataxes * daxes,char ostr[4])29 int THD_fill_orient_str_3( THD_dataxes * daxes, char ostr[4] )
30 {
31    if ( ! daxes || ! ostr ) return 1;
32 
33    ostr[0] = ORIENT_first[daxes->xxorient];
34    ostr[1] = ORIENT_first[daxes->yyorient];
35    ostr[2] = ORIENT_first[daxes->zzorient];
36    ostr[3] = '\0';
37 
38    return 0;
39 }
40 /*
41   Fill oint with 3 int orient code in RLPAIS encoding (e.g., 'LPI'
42   leads to [1, 2, 4]
43 */
THD_fill_orient_int_3_rlpais(THD_dataxes * daxes,int oint[3])44 int THD_fill_orient_int_3_rlpais( THD_dataxes * daxes, int oint[3] )
45 {
46    if ( ! daxes || ! oint ) return 1;
47 
48    oint[0] = daxes->xxorient;
49    oint[1] = daxes->yyorient;
50    oint[2] = daxes->zzorient;
51 
52    return 0;
53 }
54 /* fill ostr with the 6 letter orient code (e.g. LRPAIS) given integer codes
55  *    - null terminate ostr (so there must be space for 7 bytes)
56  *    - the ^1 is to toggle between 0/1, 2/3, 4/5
57  *    - return 0 on success, 1 on error
58  * (ostr is just char *, the 7 is a reminder)   23 Jan 2013 [rickr] */
THD_fill_orient_str_6(THD_dataxes * daxes,char ostr[7])59 int THD_fill_orient_str_6( THD_dataxes * daxes, char ostr[7] )
60 {
61    if ( ! daxes || ! ostr ) return 1;
62 
63    ostr[0] = ORIENT_first[daxes->xxorient];
64    ostr[1] = ORIENT_first[daxes->xxorient^1];
65    ostr[2] = ORIENT_first[daxes->yyorient];
66    ostr[3] = ORIENT_first[daxes->yyorient^1];
67    ostr[4] = ORIENT_first[daxes->zzorient];
68    ostr[5] = ORIENT_first[daxes->zzorient^1];
69    ostr[6] = '\0';
70 
71    return 0;
72 }
73