1 #ifndef TRACKIO_INCLUDED
2 #define TRACKIO_INCLUDED
3 
4 
5 
6 // ---------------- for param names while tracking -------------------------
7 
8 // temporary candidate for NIML string reading based on ZSS's
9 // int/float-reading definitions in */suma_afni_surface.h
10 #define NI_SETA_STR_tmp(ngr, name, val)  {\
11    char m_stmp[200]; sprintf(m_stmp,"%s", (val));   \
12    NI_set_attribute(ngr, name, m_stmp);  \
13 }
14 
15 
16 typedef struct {
17    int id;     /* some identifier */
18    int N_pts3;  /* total number of values in pts */
19    float *pts; /* vector of coordinates xyz, xyz
20                   N_pts3/3 total number of pts*/
21 } TAYLOR_TRACT; /* KEEP IN SYNC WITH TAYLOR_TRACT_DATUM_DEF */
22 #define TRACT_NPTS(tt) ( (tt)->N_pts3/3 )
23 #define TAYLOR_TRACT_DATUM_NIML_DEF "int,int,float[#2]"
24 
25 
26 typedef struct {
27    int N_tracts;
28    int N_allocated;
29    TAYLOR_TRACT *tracts;
30    int *tract_P0_offset_private; /* Index of 1st point in each tract
31                                     Index of 1st point of 1st tract is 0 */
32    int N_points_private; /* Sum of points in all tracts of bundle */
33    char *bundle_ends; // labels, added Sept 2014
34 } TAYLOR_BUNDLE;
35 
36 typedef struct {
37    THD_3dim_dataset *grid;
38    THD_3dim_dataset *FA;
39    char atlas_space[65];
40    int N_allocated;
41    int N_tbv;
42    TAYLOR_BUNDLE **tbv;
43    int *bundle_tags;
44    int *bundle_alt_tags;
45    int N_points_private; /* Num of points in all tracts of all bundles in net */
46    int N_tracts_private; /* Sum of number of tracts in all bundles */
47    int Longest_tract_length_private; /* Length in points of longest tract */
48    int Longest_tract_index_in_bundle_private; /* longest tract index in bundle */
49    int Longest_tract_bundle_index_in_network_private; /* longest tract bundle */
50 } TAYLOR_NETWORK;
51 
52 typedef struct {
53    THD_3dim_dataset *grid;
54 } INSTA_TRACT_SETUP;
55 
56 int Free_Insta_Tract_Setup(INSTA_TRACT_SETUP *ITS);
57 INSTA_TRACT_SETUP *New_Insta_Tract_Setup(INSTA_TRACT_SETUP *ITS);
58 
59 float Tract_Length(TAYLOR_TRACT *tt);
60 void Show_Taylor_Network(TAYLOR_NETWORK *network, FILE *out, int mx, int mxb);
61 void Show_Taylor_Bundle(TAYLOR_BUNDLE *bundle, FILE *out, int mx);
62 void Show_Taylor_Tract(TAYLOR_TRACT *tract, FILE *out, int mx);
63 TAYLOR_TRACT *Create_Tract_NEW(int ptA, int ptB, float **pts_buff,
64                                int id, THD_3dim_dataset *grid);
65 int Bundle_N_points(TAYLOR_BUNDLE *bun, byte recalc);
66 int Network_N_points(TAYLOR_NETWORK *network, byte recalc);
67 int Network_N_tracts(TAYLOR_NETWORK *network, byte recalc);
68 int Network_N_bundles(TAYLOR_NETWORK *network);
69 int Network_Max_tract_length(TAYLOR_NETWORK *net, byte recalc,
70                              int *t, int *b);
71 int Network_PTB_to_1P(TAYLOR_NETWORK *network, int p, int t, int b);
72 int Network_TB_to_1T(TAYLOR_NETWORK *net, int t, int b);
73 int Network_1P_to_PTB(TAYLOR_NETWORK *network, int P1,
74                       int *p, int *t, int *b, int *l);
75 int Network_1T_to_TB(TAYLOR_NETWORK *net, int TT, int *t, int *b,
76                      int *P0, int *P1);
77 int Network_1B_to_1P(TAYLOR_NETWORK *net, int BB, int *PP1);
78 /*TAYLOR_TRACT *Create_Tract(int N_ptsB, float **pts_buffB,
79                           int N_ptsF, float **pts_buffF,
80                           int id, THD_3dim_dataset *grid);*/
81 TAYLOR_TRACT *Free_Tracts(TAYLOR_TRACT *tt, int N);
82 TAYLOR_BUNDLE *AppCreateBundle(TAYLOR_BUNDLE *tbu, int N_tractsbuf,
83                                TAYLOR_TRACT *tracts_buff);
84 TAYLOR_BUNDLE *Free_Bundle(TAYLOR_BUNDLE *tb);
85 TAYLOR_NETWORK *Free_Network(TAYLOR_NETWORK *net);
86 
87 NI_element *Tract_2_NIel(TAYLOR_TRACT *tt);
88 TAYLOR_TRACT *NIel_2_Tract(NI_element *nel);
89 
90 TAYLOR_NETWORK *AppAddBundleToNetwork(TAYLOR_NETWORK *network,
91                                       TAYLOR_BUNDLE **tb,int tag, int alt_tag,
92                                       THD_3dim_dataset *grid, char *EleName);
93 NI_group *Network_2_NIgr(TAYLOR_NETWORK *network, int mode);
94 NI_group *Network_link(char *filename);
95 TAYLOR_NETWORK *NIgr_2_Network(NI_group *ngr);
96 int Write_NI_Network(NI_group *ngr, char *name, char *mode);
97 int Write_Network(TAYLOR_NETWORK *network, char *name, char *mode);
98 int Write_Bundle(TAYLOR_BUNDLE *tb, char *name, char *mode);
99 TAYLOR_NETWORK * Read_Network(char *name) ;
100 NI_group * Read_NI_Network(char *name);
101 
102 int get_tract_verb(void);
103 void set_tract_verb(int v);
104 int get_NI_tract_type(void);
105 
106 // this currently works for both 3dTrack and 3dProbTrack!
107 int WriteTractAlgOpts(char *fname, NI_element *nel);
108 
109 // new versions for MULTI/HARDI: no M and bvals
110 int NI_getTractAlgOpts_M(NI_element *nel, float *MinFA, float *MaxAngDeg,
111                        float *MinL, int *SeedPerV);
112 NI_element * NI_setTractAlgOpts_M(NI_element *nel, float *MinFA,
113 										  float *MaxAngDeg, float *MinL,
114 										  int *SeedPerV);
115 NI_element *ReadTractAlgOpts_M(char *fname);
116 int NI_getProbTractAlgOpts_M(NI_element *nel, float *MinFA, float *MaxAngDeg,
117 									float *MinL, float *NmNsFr, int *Nseed,
118 									int *Nmonte);
119 NI_element * NI_setProbTractAlgOpts_M(NI_element *nel, float *MinFA,
120 												float *MaxAngDeg, float *MinL,
121 												float *NmNsFr, int *Nseed,
122 												int *Nmonte);
123 NI_element *ReadProbTractAlgOpts_M(char *fname);
124 
125 // TrackVis requirements for *.trk file, defining the header as a struct
126 typedef struct
127 {
128   // 6     ID string for track file. The first 5 characters must be "TRACK".
129   char           id_string[6];
130   // 6   Dimension of the image volume.
131   short int   dim[3];
132   // 12  Voxel size of the image volume.
133   float           voxel_size[3];
134   // 12  Origin of the image volume (Field is not yet being used by
135   //     TrackVis). Origin is always (0, 0, 0).
136   float           origin[3];
137   // 2   Number of scalars saved at each track point (besides x, y and z
138   //     coordinates).
139   short int   n_scalars;
140   // 200 Name of each scalar. Cannot be longer than 20 characters
141   //     each. Can only store up to 10 names.
142   char           scal_n[10][20];
143   // 2   Number of properties saved at each track.
144   short int   n_properties;
145   // 200 Name of each property. Cannot be longer than 20 characters
146   //     each. Can only store up to 10 names.
147   char           prop_n[10][20];
148   // 64  4x4 matrix for voxel to RAS (crs to xyz) transf. If
149   //     vox_to_ras[3][3] is 0, matrix not recorded.
150   float           vox_to_ras[4][4];
151   char           reserved[444];  // 444 Reserved space for future version.
152   // 4     Storing order of the original image data. Explained here.
153   char           voxel_order[4];
154   char           pad2[4];  // 4     Paddings.
155   // 24  Image orientation of the original image. As defined in the
156   //     DICOM header.
157   float           img_orient_p[6];
158   char           pad1[2];  // 2     Paddings.
159   // 1     Inversion/rotation flags used to generate this track file. For
160   // internal use only.
161   unsigned char   invert_x;
162   unsigned char   invert_y;  // 1 As above.
163   unsigned char   invert_z;  // 1 As above.
164   unsigned char   swap_xy;   // 1 As above.
165   unsigned char   swap_yz;   // 1 As above.
166   unsigned char   swap_zx;   // 1 As above.
167   // 4     Number of tracks stored in this track file. 0 means the number
168   //     was NOT stored.
169   int           n_count;  // 4     Version number. Current version is 2.
170   int           version;
171   // 4     Size of the header. Used to determine byte swap. Should be 1000.
172   int           hdr_size;
173 } tv_io_header;
174 
175 // for writing trackvis track info currently
176 int SimpleWriteDetNetTr_M(int N_HAR, FILE *file, int ***idx,
177                            THD_3dim_dataset **PARS,
178                            int PAR_BOT, int PAR_TOP,
179                            float **loc, int **locI, int len,
180                            int *TV, int *Dim, float *Ledge);
181 
182 
183 NI_element * ReadDTI_inputs(char *fname);
184 int NI_getDTI_inputs( NI_element *nel,
185                       char **NameVECT,
186                       char *NameXF,
187                       char **NameSCAL,
188                       char **NamePLUS,
189                       int *extrafile, int *pars_top);
190 
191 char * SUMA_Taylor_Network_Info(TAYLOR_NETWORK *net,
192                                 int show_maxu, int show_maxub);
193 char *SUMA_Taylor_Bundle_Info(TAYLOR_BUNDLE *tb, int show_maxu);
194 char *SUMA_Taylor_Tract_Info(TAYLOR_TRACT *tt, int show_maxu);
195 
196 #endif
197