1 #ifndef _TTATLAS_QUERY_HEADER_
2 #define _TTATLAS_QUERY_HEADER_
3 
4 /* for putting strings into strings with #defines */
5 #define STRINGIFY2( x) #x
6 #define STRINGIFY(x) STRINGIFY2(x)
7 
8 /*-----------------------------------------------------------*/
9 /*----------------- data for Talairach To -------------------*/
10 /*----------------- Some of that stuff used -----------------*/
11 /*----------------- be in afni.h. ZSS Feb. 06----------------*/
12 #define TTO_LMAX    (ATLAS_CMAX+16)
13 #define TTO_FORMAT  "%." STRINGIFY(ATLAS_CMAX) "s [%3.0f,%3.0f,%3.0f]"
14 #define IS_BLANK(c) ( ( (c) == ' '  || (c) == '\t' || \
15                         (c) == '\n' || (c) == '\v' || \
16                         (c) == '\f' || (c) == '\r') ? 1 : 0 )
17 
18 #define IS_PUNCT(m) (   m=='[' || m==']' || \
19                         m=='<' || m=='>' || \
20                         m==':' || m==';' || \
21                         m=='(' || m==')' || \
22                         m=='*' || m==',' || \
23                         m=='?')
24 
25 #define IS_QUOTE(m) (   m=='"' || m=='\'' )
26 
27 #define IS_PERIOD(m) (   m=='.' )
28 
29 #ifdef MAIN
30    /* Table moved to thd_ttatlas_query.c, access is no longer
31    restricted to when MAIN is defined */
32 #else
33 #endif
34 extern int atlas_current_structure ;
35 /*-------------------------------------*/
36 
37 
38 /*! CA_EZ atlas material is now automatically prepared
39 from a downloaded SPM toolbox. See the matlab function
40 CA_EZ_Prep.m */
41 #include "thd_ttatlas_CA_EZ.h"
42 
43 /* global web browser, unless we find somewhere better to put it          */
44 extern char *GLOBAL_browser ;   /* moved from afni.h  22 Feb 2012 [rickr] */
45 
46 
47 /* generic atlas functions and definitions - 03/13/2009 */
48 /* #include "thd_atlas.h" */
49 
50 /*-------- End Atlas Tables ------------*/
51 
52 #define IS_LETTER(c) ( ( ((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z') ) ? 1 : 0 )
53 #define IS_NUMBER(c) ( ( ((c) >= '0' && (c) <= '9') ) ? 1 : 0 )
54 #define TO_LOWER(c) ( ((c) >= 'A' && (c) <= 'Z') ? (c + 'a' - 'A') : (c) )
55 #define TO_UPPER(c) ( ((c) >= 'a' && (c) <= 'z') ? (c + 'A' - 'a') : (c) )
56 
57 #define STR_PRINT(s) ( ((s)) ? (s) : ("NULL") )
58 #define MIN_PAIR(a,b) ( ((a)<(b)) ? (a) : (b) )
59 #define COUNTER_SUFFIX(ic)  ( ((ic) == 1) ? "st" : ((ic) == 2) ? "nd" : ((ic) == 3) ? "rd" : "th" )
60 #define SIDE_MATCH(squery,satlas) ( (squery == satlas || TO_LOWER(satlas) == 'u' || TO_LOWER(squery) == 'u') ? 1:0 )
61 
62 #define WAMI_HEAD "+++++++ nearby Atlas structures +++++++\n"
63 #define WAMI_TAIL "\n******** Please use results with caution! ********"  \
64                   "\n******** Brain anatomy is quite variable! ********"  \
65                   "\n******** The database may contain errors! ********"
66 
67 
68 typedef struct {
69    char side; /*!< u, b, l, or r for: Unknown/Left/Right/Bi */
70    char *orig_label;  /*!< label string as provided by atlas */
71    char *longname; /*!<  possible long name for region */
72    int id; /*!< integer identifier in atlas */
73    int N_chnks; /*!< Number of chunks in label, as interpreted by afni */
74    char **chnks; /*!< label chunks, as interpreted by afni*/
75    char *atlas_name; /*!< Redundant with AFNI_ATLAS's content, but kept
76                           in cases where AFNI_ATLAS_REGION are used
77                           separately, such as with ROI_String_Decode.  */
78 } AFNI_ATLAS_REGION;
79 
80 typedef struct {
81    char *atlas_name;
82    int N_regions;
83    AFNI_ATLAS_REGION **reg;
84 } AFNI_ATLAS;
85 
86 typedef enum { CLASSIC_WAMI_ATLAS_SORT = 1,  TAB1_WAMI_ATLAS_SORT = 2,     TAB2_WAMI_ATLAS_SORT = 3,
87                CLASSIC_WAMI_ZONE_SORT,       TAB1_WAMI_ZONE_SORT,          TAB2_WAMI_ZONE_SORT } WAMI_SORT_MODES;
88 
89 
90 typedef enum { UNKNOWN_ATLAS=0, /*!< Dunno */
91                AFNI_TLRC_ATLAS, /*!< The Classic */
92                CA_EZ_N27_MPM_ATLAS,  /*!< Eickhoff, Zilles MPM atlas*/
93                CA_EZ_N27_ML_ATLAS,  /*!< Eickhoff, Zilles MacroLabels atlas*/
94                CA_EZ_N27_PMAPS_ATLAS, /*!< Eickhoff, Zilles Probability maps atlas*/
95                CA_EZ_N27_LR_ATLAS,  /*!< Eickhoff, Zilles Left/Right Anatomy atlas*/
96                CUSTOM_ATLAS,       /* user specified */
97                NUMBER_OF_ATLASES  /*!< A flag for the number of atlases, leave for last */
98                } AFNI_ATLAS_CODES;
99 
100 
101 typedef struct {
102    int *iloc;
103    float *score;
104    int N;
105    int nmatch;
106 }  ATLAS_SEARCH;
107 
108 typedef struct {
109    float x, y, z; /*!< coordinates */
110    char space_name[65]; /*!< Name of coordinate space, will supersede space */
111    char orcode[4]; /*!< The signs and labels of x y z axis (4th for nil char)*/
112 } ATLAS_COORD;
113 
114 typedef struct {
115    int N_label; /*!< number of label types available in a particular atlas.
116                      For example the "Anterior Cingulate" can coincide with "Brodmann area 25" in TT_Daemon atlas.
117                      In this case, N_label = 2 */
118    int level; /*!< a number used to group zones together. This can be equal to the 'within' radius ... */
119    char **label;  /*!< labels of the zone. label[0] = "Anterior Cingulate", label[1] = "Brodmann area 25" */
120    int   *code;  /*!< Integer code of zone in atlas */
121    char  **atname; /*!< Integer code of atlas */
122    float *prob; /*!< probability, if applicable, of being of a particular label */
123    float *radius;   /*!< distance, search distance for reported label.*/
124    char **longname; /*!< long name for label/atlas region */
125    char **webpage; /*!< webpages for a web-atlas for whereami location */
126    char **connpage; /*!< connection info webpages for a web-atlas for whereami location */
127 } ATLAS_ZONE;
128 
129 typedef struct {
130    int N_zone;      /*!< number of zones found */
131    ATLAS_ZONE **zone; /*!< the zones */
132 } ATLAS_QUERY;
133 
134 typedef struct {
135    int n_points;
136    ATLAS_POINT *at_point;
137 } ATLAS_POINT_LIST;
138 
139 #define MAX_ELM(apl2) ((apl2) ? (apl2)->n_points:0)
140 
141 typedef struct {
142    THD_3dim_dataset *adset;
143    int mxlablen;
144    int probkey;
145    byte *lrmask;            /* Do not free this one either */
146    int maxkeyval;        /* Highest integral value in dset */
147    int minkeyval;        /* Lowest integral value in dset */
148    ATLAS_POINT_LIST *apl2;  /* use new list structure for segmentation
149                               At the moment, apl2 is also filled for
150                               probabilistic atlases because it is needed
151                               to go from sub-brick label to area name. */
152    byte duplicateLRentries; /* Are LR labels listed in adh.apl and
153                                under the same code?
154                                (only case I know of is in TTO_list) */
155    byte build_lr;
156    int params_set;
157 } ATLAS_DSET_HOLDER;
158 
159 typedef struct {
160    char *xform_type, *xform_name, *source, *dest, *coord_order;
161    float dist;   /* distance (cost) of xform between two spaces */
162    int inverse;  /* inverse transformation from dest to src */
163    int post;  /* for 2/12 part, evaluate coords pre/post xformation */
164    int nelts;    /* number of data elements */
165    void *xform;  /* data for xformation */
166 } ATLAS_XFORM;
167 
168 typedef struct {
169    char *dset_name;
170    char *space;
171    char *name;
172    char *description;
173    char *comment;
174    char *atlas_type;  /* web or NULL for now, for web type, dset is http webpage address */
175    char *orient;  /* string to specify xyz order requests - Elsevier's web version uses "RSA"*/
176    char *supp_web_info; /* string specifying base webpage for supplemental structure info */
177    char *supp_web_type; /* extension suffix for webpages - pdf, html,... */
178    char *supp_conn_info; /* string specifying base webpage for supplemental connection info */
179    char *supp_conn_type; /* extension suffix for webpages - pdf, html,... */
180    int atlas_found;
181    ATLAS_DSET_HOLDER *adh;
182 } ATLAS; /*!< All char * should be initialized when .niml file is loaded,
183                or when ATLAS_LIST * is formed in the old syle.
184               *adh is initialized to zero, then populated if needed
185               by the function Atlas_With_Trimming. The latter should
186               be used almost exclusively to get an atlas */
187 
188 /* macro accessors for the atlas fields - first version is to pointer location,
189    second _S version is for default string if NULL string in structure */
190 #define ATL_COMMENT(xa) ( ( (xa) && (xa)->comment) ?   \
191                            (xa)->comment : NULL )
192 #define ATL_COMMENT_S(xa) ( (ATL_COMMENT(xa)) ? \
193                               (ATL_COMMENT(xa)) : "None" )
194 
195 #define ATL_DESCRIPTION(xa) ( ( (xa) && (xa)->description ) ?   \
196                            (xa)->description : NULL )
197 #define ATL_DESCRIPTION_S(xa) ( (ATL_DESCRIPTION(xa)) ? \
198                                  (ATL_DESCRIPTION(xa)) : "None" )
199 
200 #define ATL_NAME(xa) ( ( (xa) && (xa)->name) ?   \
201                            (xa)->name : NULL )
202 #define ATL_NAME_S(xa) ( (ATL_NAME(xa)) ? \
203                                  (ATL_NAME(xa)) : "None" )
204 
205 #define ATL_DSET(xa) ( ( (xa) && (xa)->adh ) ? \
206                         (xa)->adh->adset : NULL )
207 
208 #define ATL_ADH_SET(xa) ( ( (xa) && (xa)->adh ) ? \
209                            (xa)->adh->params_set : 0 )
210 
211 #define ATL_ORIENT(xa) ( ( (xa) && (xa)->orient) ?   \
212                            (xa)->orient : NULL )
213 #define ATL_ORIENT_S(xa) ( (ATL_ORIENT(xa)) ? \
214                               (ATL_ORIENT(xa)) : "RAI" )
215 
216 #define ATL_TYPE(xa) ( ( (xa) && (xa)->atlas_type) ?   \
217                            (xa)->atlas_type : NULL )
218 #define ATL_TYPE_S(xa) ( (ATL_TYPE(xa)) ? \
219                               (xa)->atlas_type : "None" )
220 /* is the atlas a web type */
221 #define ATL_WEB_TYPE(xa) (strcasecmp((ATL_TYPE_S(xa)),"web")== 0)
222 
223 /* is there supplemental information on Internet */
224 #define ATL_SUPP_WEB_INFO(xa) ((xa) && (xa)->supp_web_info ? 1: 0)
225 #define ATL_SUPP_WEB_INFO_S(xa) ( (ATL_SUPP_WEB_INFO(xa)) ? \
226           ((xa)->supp_web_info)   : "No supplemental info " )
227 #define ATL_SUPP_WEB_TYPE(xa) ((xa)->supp_web_type ? 1: 0)
228 #define ATL_SUPP_WEB_TYPE_S(xa) ( (ATL_SUPP_WEB_TYPE(xa)) ? \
229           ((xa)->supp_web_type)   : ".html" )
230 
231 #define ATL_SUPP_CONN_INFO(xa) ((xa) && (xa)->supp_conn_info ? 1: 0)
232 #define ATL_SUPP_CONN_INFO_S(xa) ( (ATL_SUPP_CONN_INFO(xa)) ? \
233           ((xa)->supp_conn_info)   : "No supplemental info " )
234 #define ATL_SUPP_CONN_TYPE(xa) ((xa)->supp_conn_type ? 1: 0)
235 #define ATL_SUPP_CONN_TYPE_S(xa) ( (ATL_SUPP_CONN_TYPE(xa)) ? \
236           ((xa)->supp_conn_type)   : ".html" )
237 
238 #define ATL_FOUND(xa) ( (xa)  ? \
239                            ((xa)->atlas_found) : 0 )
240 
241 
242 /* number of atlases in an atlas list */
243 #define NUM_ATLASES(atl) ( (atl) ? \
244                            (atl)->natlases : 0)
245 
246 #define ATLAS_IN_LIST(atl, i) ( (atl) ? \
247                            (atl)->atlas+i : 0)
248 
249 typedef struct {
250    char *atlas_space;
251    char *generic_space;
252 } ATLAS_SPACE;
253 
254 typedef struct {
255    char *template;
256    char *space;
257    char *description;
258    char *comment;
259 } ATLAS_TEMPLATE;
260 
261 typedef struct {
262    int nxforms;
263    ATLAS_XFORM *xform;
264 } ATLAS_XFORM_LIST;
265 
266 typedef struct {
267    int natlases;
268    ATLAS *atlas;
269 } ATLAS_LIST;
270 
271 typedef struct {
272    int nspaces;
273    ATLAS_SPACE *space;
274 } ATLAS_SPACE_LIST;
275 
276 typedef struct {
277    int ntemplates;
278    ATLAS_TEMPLATE *atlas_template;
279 } ATLAS_TEMPLATE_LIST;
280 
281 typedef struct {
282    int nelts;
283    void *rgblist;
284 } ATLAS_LUT;
285 
286 typedef enum { LEV=0, /* Levenshtein distance */
287                FLD, /* Length Difference */
288                FCD, /* Number of characters from s2 found in s1*/
289                PMD, /* partial match depth */
290                MWI, /* Matching word index (in line of words) */
291                MWL, /* Line in multi-line text of matching word */
292                IWD, /* Intra Words Distance */
293                N_APPROX_STR_DIMS /* leave the last */ } APPROX_STR_DIMS;
294 
295 #define SRCFILE_MAX 32
296 
297 typedef struct {
298    int d[N_APPROX_STR_DIMS];
299    char srcfile[SRCFILE_MAX+1];
300 } APPROX_STR_DIFF;
301 
302 typedef struct {
303    float w[N_APPROX_STR_DIMS];
304 } APPROX_STR_DIFF_WEIGHTS;
305 
306 
307 #define WAMI_WEB_PRINT_XML    1
308 #define WAMI_WEB_BROWSER      2
309 #define WAMI_WEB_STRUCT       3
310 
311 #define MAX_URL 2048
312 
313 const char *Atlas_Val_Key_to_Val_Name(ATLAS *atlas, int tdval);
314 int Init_Whereami_Max_Find(void);
315 void Set_Whereami_Max_Find(int n);
316 float Init_Whereami_Max_Rad(void);
317 void Set_Whereami_Max_Rad(float n);
318 THD_3dim_dataset * get_atlas(char *epath, char *aname) ;
319 char * get_atlas_dirname(void) ; /* 31 Jan 2008 -- RWCox */
320 char Is_Side_Label(char *str, char *opt);
321 int qmode_int(int *iv, int ni);
322 int *z_rand_order(int bot, int top, long int seed);
323 int *z_iqsort (float *x , int nx );
324 int *z_idoubleqsort (double *x , int nx );
325 int *z_idqsort (int *x , int nx );
326 int *z_dqsort (int *x , int nx );
327 int *z_istrqsort (char **x , int nx );
328 void Show_Atlas_Region (AFNI_ATLAS_REGION *aar);
329 AFNI_ATLAS_REGION * Free_Atlas_Region (AFNI_ATLAS_REGION *aar);
330 AFNI_ATLAS_REGION * Atlas_Chunk_Label(char *lbli, int id, char *aname, char *longname);
331 AFNI_ATLAS *Build_Atlas (char *aname, ATLAS_LIST *atlas_list) ;
332 void Show_Atlas (AFNI_ATLAS *aa);
333 AFNI_ATLAS *Free_Atlas(AFNI_ATLAS *aa) ;
334 AFNI_ATLAS_REGION *ROI_String_Decode(char *str, ATLAS_LIST *atlas_list);
335 char * deblank_name(char *name);
336 char *deslash_allname(char *name, char fill);
337 char *deblank_allname(char *name, char fill);
338 char *cdeblank_allname(char *name, char fill);
339 char * depunct_name(char *name);
340 char * dequote_name(char *name, char qo);
341 int begins_with(char *name, char *quote, int debl);
342 int ends_with(char *name, char *quote, int debl);
343 APPROX_STR_DIFF_WEIGHTS *init_str_diff_weights(APPROX_STR_DIFF_WEIGHTS *Dwi);
344 float best_approx_str_match(char **words, int N_words, char *str, byte ci,
345                            APPROX_STR_DIFF_WEIGHTS *Dwi);
346 void test_approx_str_match(void);
347 char **approx_str_sort(char **words, int N_words, char *str, byte ci,
348                        float **sorted_score, byte word_split,
349                        APPROX_STR_DIFF_WEIGHTS *Dwi,
350                        APPROX_STR_DIFF **Dout);
351 char **approx_str_sort_text(char *text, int *N_ws, char *str,
352                             byte ci, float **sorted_score,
353                             APPROX_STR_DIFF_WEIGHTS *Dwi,
354                             APPROX_STR_DIFF **Dout, char join_breaks);
355 char **approx_str_sort_tfile(char *fname, int textinname, int *N_ws, char *str,
356                             byte ci, float **sorted_score,
357                             APPROX_STR_DIFF_WEIGHTS *Dwi,
358                             APPROX_STR_DIFF **Dout, int verb, char join_breaks);
359 THD_string_array *approx_str_sort_Ntfile(
360                       char **fnames, int N_names, char *str,
361                       byte ci, float **sorted_score,
362                       APPROX_STR_DIFF_WEIGHTS *Dwi,
363                       APPROX_STR_DIFF **Doutp, int verb, char join_breaks);
364 #define APSEARCH_TMP_PREF "__apsearch"
365 char **approx_str_sort_phelp(char *prog, int textinname, int *N_ws, char *str,
366                             byte ci, float **sorted_score,
367                             APPROX_STR_DIFF_WEIGHTS *Dwi,
368                             APPROX_STR_DIFF **Dout, int verb, char join_breaks);
369 char **approx_str_sort_all_popts(char *prog, int textinname, int *N_ws,
370                             byte ci, float **sorted_score,
371                             APPROX_STR_DIFF_WEIGHTS *Dwi,
372                             APPROX_STR_DIFF **Dout,
373                             int uopts, int verb, char join_breaks);
374 char *get_updated_help_file(int force_recreate, byte verb, char *progname,
375                             int shtp);
376 char **approx_str_sort_readmes(char *str, int *N_r);
377 char **unique_str(char **words, int N_words, byte ci,
378                   byte noae, int *N_unq, int **isort_out);
379 char *approx_string_diff_info(APPROX_STR_DIFF *D,APPROX_STR_DIFF_WEIGHTS *Dwi);
380 ATLAS_SEARCH *Find_Atlas_Regions(AFNI_ATLAS *aa, AFNI_ATLAS_REGION *ur ,
381                                  ATLAS_SEARCH *usethissearch);
382 ATLAS_SEARCH *Free_Atlas_Search(ATLAS_SEARCH *as);
383 char *Report_Found_Regions(AFNI_ATLAS *aa, AFNI_ATLAS_REGION *ur , ATLAS_SEARCH *as, int *nexact);
384 char * Clean_Atlas_Label( char *lb);
385 char * Clean_Atlas_Label_to_Prefix( char *lb);
386 ATLAS_ZONE *Get_Atlas_Zone(ATLAS_QUERY *aq, int level);
387 ATLAS_ZONE *Atlas_Zone(ATLAS_ZONE *zn, int level, char *label, int code,
388                        float prob, float within, char *aname, char *webpage, char *connpage) ;
389 ATLAS_ZONE *Free_Atlas_Zone(ATLAS_ZONE *zn);
390 void Set_Show_Atlas_Mode(int md);
391 void Show_Atlas_Zone(ATLAS_ZONE *zn, ATLAS_LIST *atlas_list);
392 void Show_Atlas_Query(ATLAS_QUERY *aq, ATLAS_LIST *atlas_list);
393 ATLAS_QUERY *Add_To_Atlas_Query(ATLAS_QUERY *aq, ATLAS_ZONE *zn);
394 ATLAS_QUERY *Free_Atlas_Query(ATLAS_QUERY *aq);
395 int CA_EZ_LR_load_atlas_old(void);
396 int CA_EZ_ML_load_atlas_old(void);
397 int CA_EZ_MPM_load_atlas_old(void);
398 int CA_EZ_PMaps_load_atlas_old(void);
399 THD_3dim_dataset *load_atlas_dset(char *dsetname);
400 void CA_EZ_MPM_purge_atlas(void);
401 void CA_EZ_PMaps_purge_atlas(void);
402 void CA_EZ_ML_purge_atlas(void);
403 char * Atlas_Query_to_String (ATLAS_QUERY *wami, ATLAS_COORD ac,
404                               WAMI_SORT_MODES Mode, ATLAS_LIST *atlas_list);
405 char * genx_Atlas_Query_to_String (ATLAS_QUERY *wami,
406                               ATLAS_COORD ac, WAMI_SORT_MODES mode,
407                               ATLAS_LIST *atlas_list);
408 char MNI_Anatomical_Side(ATLAS_COORD ac, ATLAS_LIST *atlas_list);
409 void TT_whereami_set_outmode(WAMI_SORT_MODES md);
410 void set_TT_whereami_version(int atlas_list_version, int whereami_version);
411 char * Atlas_Prob_String(float p);
412 char * Atlas_Code_String(int c);
413 byte Same_Chunks(AFNI_ATLAS_REGION *aar1, AFNI_ATLAS_REGION *aar2);
414 THD_3dim_dataset *Atlas_Region_Mask(AFNI_ATLAS_REGION *aar,
415                                     int *codes, int n_codes,
416                                     ATLAS_LIST *atlas_list);
417 char Atlas_Voxel_Side( THD_3dim_dataset *dset, int k1d, byte *lrmask);
418 void TT_whereami_remove_atlas(AFNI_ATLAS_CODES ac);
419 void TT_whereami_add_atlas(AFNI_ATLAS_CODES ac);
420 THD_3dim_dataset *THD_3dim_G_from_ROIstring(char *shar);
421 THD_3dim_dataset *THD_3dim_from_ROIstring(char *shar, ATLAS_LIST *atlas_list);
422 void Set_ROI_String_Decode_Verbosity(byte lvl);
423 int * UniqueInt (int *y, int ysz, int *kunq, int Sorted );
424 short * UniqueShort (short *y, int ysz, int *kunq, int Sorted );
425 byte * UniqueByte (byte *y, int ysz, int *kunq, int Sorted );
426 
427 ATLAS *Atlas_With_Trimming(char *atname, int LoadLRMask,
428                                        ATLAS_LIST *atlas_list);
429 int whereami_in_atlas(  char *aname,
430                         ATLAS_COORD ac,
431                         ATLAS_QUERY **wamip);
432 char *atlas_key_label(ATLAS *atlas, int key, ATLAS_COORD *ac);
433 char *Atlas_name_choice(ATLAS_POINT *atp);
434 char *prob_atlas_sb_to_label(ATLAS *atlas, int sb, int *key);
435 byte is_probabilistic_atlas(ATLAS *atlas);
436 byte is_integral_atlas(ATLAS *atlas);
437 byte is_atlas_key_labeled(ATLAS *atlas, int key);
438 int whereami_3rdBase( ATLAS_COORD aci, ATLAS_QUERY **wamip,
439                       ATLAS_SPACE_LIST *asli, ATLAS_LIST *aali);
440 int XYZ_to_AtlasCoord(float x, float y, float z, char *orcode,
441                               char *spacename, ATLAS_COORD*ac);
442 /* change these to stop using the term code */
443 char *Atlas_Code_to_Atlas_Description(AFNI_ATLAS_CODES icod);
444 char *Atlas_Code_to_Atlas_Name (AFNI_ATLAS_CODES cod);
445 int init_global_atlas_list (void);
446 ATLAS *get_Atlas_Named(char *atname, ATLAS_LIST *atlas_list);
447 char *suggest_Atlas_Named(char *atname, ATLAS_LIST *atlas_list);
448 ATLAS *get_Atlas_ByDsetID(char *dsetid, ATLAS_LIST *atlas_list);
449 ATLAS_LIST *Atlas_Names_to_List(char **atnames, int natlases);
450 char **free_names_list(char **nl, int N_nl);
451 int find_in_names_list(char **nl, int N_nl, char *name);
452 char **add_to_names_list(char **nl, int *N_nl, char *name);
453 int set_adh_old_way(ATLAS_DSET_HOLDER *adh, char *aname);
454 int find_coords_in_space(ATLAS_COORD *acl, int N_acl, char *space_name);
455 int transform_atlas_coords(ATLAS_COORD ac, char **out_spaces,
456                            int N_out_spaces, ATLAS_COORD *acl, char *orcodeout);
457 int wami_xform_xyz(float xi,float yi,float zi,
458    float *xout, float *yout, float *zout,
459    char *srcspace, char *destspace);
460 int wami_xform_coords_print(float *coords, int ncoords,
461    char *srcspace, char *destspace, char *outfile);
462 void set_atlas_name_code(int code);
463 
464 void set_wami_verb(int lev);
465 int wami_verb(void);
466 int wami_lh(void);
467 int Init_Atlas_Dset_Holder(ATLAS *atlas) ;
468 ATLAS_DSET_HOLDER *Free_Atlas_Dset_Holder(ATLAS_DSET_HOLDER *adh);
469 int is_small_TT(ATLAS *atlas);
470 int is_big_TT(ATLAS *atlas);
471 char * TT_whereami_default_spc_name (void);
472 int is_Dset_Space_Named(THD_3dim_dataset *dset, char *name);
473 int is_Dset_Atlasy(THD_3dim_dataset *dset, ATLAS_LIST *atlas_alist);
474 char *gen_space_str(char *space_str);
475 int equivalent_space(char *inspace_str);
476 char *get_out_space(void);
477 void set_out_space(char *space_str);
478 
479 char **atlas_reference_string_list(char *atname, int *N_refs);
480 char *atlas_version_string(char *atname);
481 ATLAS_POINT_LIST *atlas_point_list(char *atname);
482 ATLAS_POINT_LIST *atlas_point_list_old_way(char *atname);
483 int genx_load_atlas_dset(ATLAS *atlas);
484 int purge_atlas(char *atname);
485 THD_string_array *get_working_atlas_name_list(void);
486 THD_string_array *recreate_working_atlas_name_list(void);
487 ATLAS_SPACE_LIST *get_G_space_list(void);
488 ATLAS_XFORM_LIST *get_G_xform_list(void);
489 ATLAS_LIST* get_G_atlas_list(void);
490 ATLAS_TEMPLATE_LIST *get_G_templates_list(void);
491 char *find_atlas_niml_file(char * nimlname, int nini);
492 char * get_env_atlas_path(void);
493 ATLAS_LIST *env_atlas_list(void);
494 char **env_space_list(int *);
495 int env_dec_places(void);
496 char * search_quotes(char *in_str);
497 
498 char *Current_Atlas_Default_Name(void);
499 char **Atlas_Names_List(ATLAS_LIST *atl);
500 int AFNI_get_dset_val_label(THD_3dim_dataset *dset, double val, char *str);  /* 26 Feb 2010 ZSS */
501 int AFNI_get_dset_val_label_maybeCR(THD_3dim_dataset *dset, double val, char *str);  /* 16 Aug 2021 DRG */
502 int AFNI_get_dset_label_val(THD_3dim_dataset *dset, double *val, char *str); /* 02 Nov 2010 ZSS */
503 int AFNI_get_dset_label_ival(THD_3dim_dataset *dset, int *val, char *str);   /* 30 Nov 2016 [rickr] */
504 int thd_LT_label_to_int_list(THD_3dim_dataset *dset,int_list *ilist,char *str); /* 22 Nov 2016 [rickr] */
505 int known_atlas_label_to_int_list(int_list * ilist, char * str);
506 
507 
508 char *elsevier_query(float xx, float yy, float zz, ATLAS *atlas);
509 char *elsevier_query_request(float xx, float yy, float zz, ATLAS *atlas, int el_req_type);
510 void wami_query_web(ATLAS *atlas, ATLAS_COORD ac, ATLAS_QUERY *wami);
511 
512 char * whereami_XML_get(char *data, char *name, char **next);
513 int whereami_browser(char *url);
514 char *cleanup_url(char *url);
515 void set_wami_web_found(int found);
516 int get_wami_web_found(void);
517 void set_wami_web_reqtype(int reqtype);
518 int get_wami_web_reqtype(void);
519 void set_wami_webpage(char *url);
520 char * get_wami_webpage(void);
521 void open_wami_webpage(void);
522 int AFNI_wami_output_mode(void);
523 void set_AFNI_wami_output_mode(int webflag);
524 char * atlas_suppinfo_webpage(ATLAS *atlas, char *blab);
525 char * atlas_suppinfo_connpage(ATLAS *atlas, char *blab);
526 
527 size_t CURL_read_URL_http ( char *url, char **data);
528 void set_wami_minprob(float val);
529 float get_wami_minprob(void);
530 float Get_PMap_Factor(void);
531 int show_neurosynth_link();
532 int show_linkrbrain_link();
533 int show_sumsdb_link();
534 char * neurosynth_coords_link(float x, float y, float z);
535 char * sumsdb_coords_link(float x, float y, float z);
536 int make_linkrbrain_xml(float *coords, int ncoords,
537     char *src_space, char *dest_space, char *linkrbrain_xml, int linkr_corr_type);
538 int send_linkrbrain_xml(char *linkrbrain_xml, char *linkrbrain_results);
539 
540 /* Transforms for going from one space to another */
541 #if 0
542 static char MNI_N27_to_AFNI_TLRC_HEAD[256] = {"TT_N27+tlrc"}; /*!<  TT_N27+tlrc was obtained by transforming N27 from MNI
543                                                     space to AFNI's Talairach space (manual transformation, 12 piece-wise-linear xforms)
544                                                     N27 was taken from Zilles' v12 database (colin_seg.hdr) before it got changed
545                                                     to MNI anatomical (by simple shift) in v13 database*/
546 #endif
547 static char TT_DAEMON_TT_PREFIX[256] = {"TTatlas"}; /*!< Good old tlrc daemon */
548 static char CA_EZ_N27_MPM_TT_PREFIX[256] = {"TT_N27_CA_EZ_MPM"};   /*!< Prefix of the Zilles Eickhoff Maximum Probability Maps in TT space */
549 static char CA_EZ_N27_PMaps_TT_PREFIX[256] = {"TT_N27_CA_EZ_PMaps"};    /*!< Prefix of the Zilles Eickhoff Probability Maps in TT space */
550 static char CA_EZ_N27_ML_TT_PREFIX[256] = {"TT_N27_EZ_ML"};  /*!< Prefix of the Zilles Eickhoff Macro Labels in TT space */
551 static char CA_EZ_N27_LR_TT_PREFIX[256] = {"TT_N27_EZ_LR"};   /*!< Prefix of the Zilles Eickhoff Left/Right mask dset */
552 static char CUSTOM_ATLAS_PREFIX[256] = {"?CUSTOM?"}; /* default prefix of additional custom atlas */
553 /* static char CUSTOM_ATLAS_PREFIX[256] = {"TTatlas_2010_master"};*/ /* default prefix of additional custom atlas */
554 
555 
556 static float MNI_N27_to_AFNI_TLRC_WRP_VEC[360] = {
557       0.9444444,              0,              0,              0,      0.9976303,
558      0.06880209,              0,    -0.05989829,      0.8685252,       1.058824,
559              -0,              0,             -0,      0.9976304,    -0.07902943,
560              -0,      0.0688021,       1.145927,              0,      -3.405704,
561       -4.103033,             -0,       3.073373,       4.936095,          -9999,
562           -9999,              0,              0,              0,         9999.9,
563       0.9315069,              0,              0,              0,      0.9976303,
564      0.06880209,              0,    -0.05989829,      0.8685252,       1.073529,
565              -0,              0,             -0,      0.9976304,    -0.07902943,
566              -0,      0.0688021,       1.145927,              0,      -3.405704,
567       -4.103033,             -0,       3.073373,       4.936095,              0,
568           -9999,              0,         9999.9,              0,         9999.9,
569       0.9444444,              0,              0,              0,      0.8154033,
570      0.05623471,              0,    -0.05989829,      0.8685252,       1.058824,
571              -0,              0,             -0,       1.220581,    -0.07902943,
572              -0,     0.08417804,       1.145927,              0,      -2.783618,
573       -4.103033,             -0,       3.073372,       4.936095,          -9999,
574               0,              0,              0,             23,         9999.9,
575       0.9315069,              0,              0,              0,      0.8154033,
576      0.05623471,              0,    -0.05989829,      0.8685252,       1.073529,
577              -0,              0,             -0,       1.220582,    -0.07902943,
578              -0,     0.08417805,       1.145927,              0,      -2.783618,
579       -4.103033,             -0,       3.073373,       4.936095,              0,
580               0,              0,         9999.9,             23,         9999.9,
581       0.9444444,              0,              0,              0,      0.9511568,
582      0.06559702,              0,    -0.05989829,      0.8685252,       1.058824,
583              -0,              0,             -0,       1.046375,    -0.07902944,
584              -0,     0.07216377,       1.145927,              0,      0.5821307,
585       -4.103033,             -0,     -0.9333872,       4.659767,          -9999,
586              23,              0,              0,           9999,         9999.9,
587       0.9315069,              0,              0,              0,      0.9511568,
588      0.06559702,              0,    -0.05989829,      0.8685252,       1.073529,
589              -0,              0,             -0,       1.046375,    -0.07902943,
590              -0,     0.07216376,       1.145927,              0,      0.5821307,
591       -4.103033,             -0,     -0.9333871,       4.659767,              0,
592              23,              0,         9999.9,           9999,         9999.9,
593       0.9444444,              0,              0,              0,      0.9976303,
594      0.06880209,              0,    -0.06148272,      0.8914994,       1.058824,
595              -0,              0,             -0,      0.9976304,    -0.07699282,
596              -0,      0.0688021,       1.116396,              0,      -3.405704,
597       -4.211566,             -0,       3.073373,       4.936095,          -9999,
598           -9999,          -9999,              0,              0,              0,
599       0.9315069,              0,              0,              0,      0.9976303,
600      0.06880209,              0,    -0.06148272,      0.8914994,       1.073529,
601              -0,              0,             -0,      0.9976304,    -0.07699282,
602              -0,      0.0688021,       1.116396,              0,      -3.405704,
603       -4.211566,             -0,       3.073373,       4.936095,              0,
604           -9999,          -9999,         9999.9,              0,              0,
605       0.9444444,              0,              0,              0,      0.8154033,
606      0.05623471,              0,    -0.06148272,      0.8914994,       1.058823,
607              -0,              0,             -0,       1.220582,    -0.07699282,
608              -0,     0.08417804,       1.116396,              0,      -2.783618,
609       -4.211566,             -0,       3.073373,       4.936095,          -9999,
610               0,          -9999,              0,             23,              0,
611       0.9315069,              0,              0,              0,      0.8154033,
612      0.05623471,              0,    -0.06148272,      0.8914994,       1.073529,
613              -0,              0,             -0,       1.220582,    -0.07699282,
614              -0,     0.08417805,       1.116396,              0,      -2.783618,
615       -4.211566,             -0,       3.073373,       4.936095,              0,
616               0,          -9999,         9999.9,             23,              0,
617       0.9444444,              0,              0,              0,      0.9511568,
618      0.06559702,              0,    -0.06148272,      0.8914994,       1.058824,
619              -0,              0,             -0,       1.046375,    -0.07699282,
620              -0,     0.07216378,       1.116396,              0,      0.5821307,
621       -4.211566,             -0,     -0.9333872,       4.659767,          -9999,
622              23,          -9999,              0,           9999,              0,
623       0.9315069,              0,              0,              0,      0.9511568,
624      0.06559702,              0,    -0.06148272,      0.8914994,       1.073529,
625              -0,              0,             -0,       1.046375,    -0.07699282,
626              -0,     0.07216377,       1.116396,              0,      0.5821307,
627       -4.211566,             -0,     -0.9333872,       4.659767,              0,
628              23,          -9999,         9999.9,           9999,              0 }; /*!< Taken from TT_N27+tlrc which was obtained by transforming
629                                                                                     N27 from MNI space to AFNI's Talairach space (manual transformation,
630                                                                                     12 piece-wise-linear xforms) */
631 
632 THD_fvec3 THD_mni_to_tta_N27( THD_fvec3 mv );
633 THD_fvec3 THD_tta_to_mni_N27( THD_fvec3 mv );
634 THD_fvec3 THD_mnia_to_tta_N27( THD_fvec3 mv );
635 THD_fvec3 THD_tta_to_mnia_N27( THD_fvec3 mv );
636 
637 #endif
638