00001
00002
00003
00004
00005
00006
00007 #ifndef _MCW_EDITVOL_
00008 #define _MCW_EDITVOL_
00009
00010 #undef CLUST_DEBUG
00011
00012 #ifdef SPARKY
00013 #undef _POSIX_SOURCE
00014 #endif
00015
00016 #include <sys/types.h>
00017 #include <stddef.h>
00018 #include <X11/Intrinsic.h>
00019 #include <stdarg.h>
00020
00021 #include "mrilib.h"
00022 #include "afni_warp.h"
00023
00024 #ifndef myXtFree
00025 #define myXtFree(xp) (XtFree((char *)(xp)) , (xp)=NULL)
00026 #endif
00027
00028 #ifndef myXtNew
00029 #define myXtNew(type) ((type *) XtCalloc(1,(unsigned) sizeof(type)))
00030 #endif
00031
00032 #define INC_CLUSTER 8
00033
00034
00035
00036
00037
00038 #define IJK_TO_THREE(ijk,i,j,k,nx,nxy) \
00039 ( (k) = (ijk)/(nxy) , (j)=((ijk)%(nxy))/(nx) , (i)=(ijk)%(nx) )
00040
00041
00042
00043 #define THREE_TO_IJK(i,j,k,nx,nxy) ((i)+(j)*(nx)+(k)*(nxy))
00044
00045
00046
00047
00048
00049
00050
00051
00052 typedef struct {
00053 int num_pt ;
00054 int num_all ;
00055 short * i;
00056 short * j;
00057 short * k;
00058 float * mag ;
00059 } MCW_cluster ;
00060
00061
00062
00063 #define INIT_CLUSTER(cc) \
00064 ( (cc) = XtNew(MCW_cluster) , \
00065 (cc)->num_pt = (cc)->num_all = 0 , \
00066 (cc)->i = NULL , (cc)->j = NULL , (cc)->k = NULL ,(cc)->mag = NULL )
00067
00068
00069
00070 #define KILL_CLUSTER(cc) \
00071 do{ if( cc != NULL ){ \
00072 myXtFree((cc)->i) ; \
00073 myXtFree((cc)->j) ; \
00074 myXtFree((cc)->k) ; \
00075 myXtFree((cc)->mag) ; \
00076 myXtFree((cc)) ; \
00077 (cc) = NULL ; \
00078 } break ; } while(0)
00079
00080 #ifdef CLUST_DEBUG
00081 # define DBMALL(n) printf(" -- Realloc-ing cluster: %d\n",(n))
00082 #else
00083 # define DBMALL(n)
00084 #endif
00085
00086
00087
00088 #define ADDTO_CLUSTER(cc,ii,jj,kk,m) \
00089 do{ int nn ; \
00090 if( (cc)->num_pt == (cc)->num_all ){ \
00091 (cc)->num_all = 1.25*(cc)->num_all + INC_CLUSTER ; \
00092 nn = (cc)->num_all ; \
00093 (cc)->i=(short *) XtRealloc((char *)(cc)->i,sizeof(short)*nn );\
00094 (cc)->j=(short *) XtRealloc((char *)(cc)->j,sizeof(short)*nn );\
00095 (cc)->k=(short *) XtRealloc((char *)(cc)->k,sizeof(short)*nn );\
00096 (cc)->mag=(float *) XtRealloc((char *)(cc)->mag,sizeof(float)*nn);\
00097 DBMALL(nn) ; } \
00098 nn = (cc)->num_pt ; ((cc)->num_pt)++ ; \
00099 (cc)->i[nn] = (ii) ; (cc)->j[nn] = (jj) ; (cc)->k[nn] = (kk) ; \
00100 (cc)->mag[nn] = (m) ; break ; } while(0)
00101
00102 #define ISOVALUE_MODE 1
00103 #define ISOMERGE_MODE 2
00104
00105
00106
00107
00108
00109 typedef struct {
00110 int num_clu , num_all ;
00111 MCW_cluster ** clar ;
00112 } MCW_cluster_array ;
00113
00114
00115
00116 #define INIT_CLARR(cl) \
00117 ( (cl) = XtNew(MCW_cluster_array) , \
00118 (cl)->num_clu = (cl)->num_all = 0 , (cl)->clar = NULL )
00119
00120
00121
00122 #define ADDTO_CLARR(cl,cc) \
00123 do{ int nn ; \
00124 if( (cl)->num_clu == (cl)->num_all ){ \
00125 (cl)->num_all += INC_CLUSTER ; nn = (cl)->num_all ; \
00126 (cl)->clar = (MCW_cluster **) XtRealloc( (char *)(cl)->clar , \
00127 sizeof(MCW_cluster *) * nn ) ;\
00128 } \
00129 (cl)->clar[((cl)->num_clu)++] = (cc) ; break ; } while(0)
00130
00131
00132
00133 #define DESTROY_CLARR(cl) \
00134 do{ int ii ; if( cl != NULL ){ \
00135 for( ii=0 ; ii < (cl)->num_clu ; ii++ ) \
00136 KILL_CLUSTER( (cl)->clar[ii] ) ; \
00137 myXtFree((cl)->clar) ; (cl) = NULL ; \
00138 } break ; } while(0)
00139
00140
00141
00142 #define CLUST_ORDERED(c1,c2) ( (c1)->num_pt >= (c2)->num_pt )
00143
00144
00145
00146 #define CLUST_SWAP(c1,c2) (ct=(c1),(c1)=(c2),(c2)=ct,sss=1)
00147
00148
00149
00150 #define SORT_CLARR(name) \
00151 if( (name) != NULL && (name)->num_clu > 1 ){ \
00152 int iic , jjc , sss ; MCW_cluster * ct ; \
00153 for( iic=0 ; iic < (name)->num_clu ; iic++ ){ \
00154 sss = 0 ; \
00155 for( jjc=1 ; jjc < (name)->num_clu ; jjc++ ){ \
00156 if( !CLUST_ORDERED( (name)->clar[jjc-1] , (name)->clar[jjc] ) ) \
00157 CLUST_SWAP( (name)->clar[jjc-1] , (name)->clar[jjc] ) ; \
00158 } if( !sss ) break ; }}
00159
00160
00161
00162 extern MCW_cluster_array * MCW_find_clusters( int,int,int , float,float,float ,
00163 int , void * , float ) ;
00164
00165
00166 extern MCW_cluster_array * NIH_find_clusters( int,int,int , float,float,float ,
00167 int , void * , float , int ) ;
00168
00169 extern void MCW_cluster_to_vol( int,int,int, int,void *, MCW_cluster * ) ;
00170
00171 extern void MCW_scale_to_max( int,int,int, int,void * );
00172
00173 extern float MCW_vol_amax( int,int,int , int,void *) ;
00174
00175
00176 extern MCW_cluster * MCW_build_mask (int, int, int,
00177 float, float, float, float);
00178
00179
00180 extern void MCW_erode_clusters (int, int, int, float, float, float, int,
00181 void *, float, float, int);
00182
00183 extern void MCW_sort_cluster( MCW_cluster * ) ;
00184
00185
00186 #undef ALLOW_SCALE_TO_MAX
00187 char * EDIT_options_help(void) ;
00188
00189
00190
00191
00192
00193
00194
00195 typedef struct EDIT_options {
00196 int thtoin ;
00197 int noneg ;
00198 int abss ;
00199
00200 float clip_bot ;
00201 float clip_top ;
00202 int clip_unscaled ;
00203
00204 float thresh ;
00205 float clust_rmm ;
00206 float clust_vmul ;
00207 float blur ;
00208 float thrblur ;
00209
00210
00211 float erode_pv;
00212 int dilate;
00213
00214
00215 int edit_clust;
00216
00217 float filter_rmm;
00218 int filter_opt;
00219
00220 float thrfilter_rmm;
00221 int thrfilter_opt;
00222
00223 int scale ;
00224
00225 float mult ;
00226
00227 int do_zvol ;
00228 float zv_x1 ;
00229 float zv_x2 ;
00230 float zv_y1 ;
00231 float zv_y2 ;
00232 float zv_z1 ;
00233 float zv_z2 ;
00234
00235 int iv_fim ;
00236 int iv_thr ;
00237
00238 int zscore ;
00239
00240 int verbose ;
00241
00242 int nfmask ;
00243 byte * fmask ;
00244 char * fexpr ;
00245
00246 int fake_dxyz ;
00247
00248 } EDIT_options ;
00249
00250
00251 #define ECFLAG_NONE 0
00252 #define ECFLAG_SAME 1
00253 #define ECFLAG_MEAN 2
00254 #define ECFLAG_MAX 3
00255 #define ECFLAG_AMAX 4
00256 #define ECFLAG_SMAX 5
00257 #define ECFLAG_SIZE 6
00258 #define ECFLAG_ORDER 7
00259
00260
00261 #define FCFLAG_NONE 0
00262 #define FCFLAG_MEAN 1
00263 #define FCFLAG_NZMEAN 2
00264 #define FCFLAG_MAX 3
00265 #define FCFLAG_AMAX 4
00266 #define FCFLAG_SMAX 5
00267
00268 #define FCFLAG_AVER 66
00269 #define FCFLAG_EXPR 77
00270
00271 #define FCFLAG_ONE_STEP 100000
00272 #define FCFLAG_WINSOR (2*FCFLAG_ONE_STEP)
00273
00274
00275
00276 #define INIT_EDOPT(edopt) \
00277 ( (edopt)->thtoin = 0 , \
00278 (edopt)->noneg = 0 , \
00279 (edopt)->abss = 0 , \
00280 (edopt)->clip_bot = 0.0 , \
00281 (edopt)->clip_top = 0.0 , \
00282 (edopt)->thresh = 0.0 , \
00283 (edopt)->clust_rmm = -1.0, \
00284 (edopt)->clust_vmul = 0.0 , \
00285 (edopt)->edit_clust = 0 , \
00286 (edopt)->erode_pv = 0.0 , \
00287 (edopt)->dilate = 0 , \
00288 (edopt)->filter_rmm = 0.0 , \
00289 (edopt)->filter_opt = 0 , \
00290 (edopt)->thrfilter_rmm = 0.0 , \
00291 (edopt)->thrfilter_opt = 0 , \
00292 (edopt)->blur = 0.0 , \
00293 (edopt)->thrblur = 0.0 , \
00294 (edopt)->scale = 0 , \
00295 (edopt)->mult = 0.0 , \
00296 (edopt)->do_zvol = 0 , \
00297 (edopt)->clip_unscaled = 0 , \
00298 (edopt)->iv_fim = -1 , \
00299 (edopt)->iv_thr = -1 , \
00300 (edopt)->zscore = 0 , \
00301 (edopt)->verbose = 0 , \
00302 (edopt)->nfmask = 0 , \
00303 (edopt)->fmask = NULL, \
00304 (edopt)->fexpr = NULL, \
00305 (edopt)->fake_dxyz = 0 , \
00306 0 )
00307
00308 extern void EDIT_one_dataset( THD_3dim_dataset * dset , EDIT_options * edopt ) ;
00309
00310 extern void EDIT_blur_volume( int,int,int , float,float,float , int,void * , float ) ;
00311 extern void EDIT_blur_volume_3d( int,int,int , float,float,float , int,void * , float, float, float ) ;
00312
00313
00314 #define RMS_TO_SIGMA(rms) (0.57735027*(rms))
00315
00316
00317 #define FWHM_TO_SIGMA(fh) (0.42466090*(fh))
00318
00319 extern int EDIT_check_argv( int , char * argv[] , int , EDIT_options * ) ;
00320
00321 extern void EDIT_coerce_type ( int , int,void * , int,void * ) ;
00322 extern void EDIT_coerce_scale_type( int , float , int,void * , int,void * ) ;
00323 extern float EDIT_coerce_autoscale( int , int,void * , int,void * ) ;
00324
00325 extern void EDIT_aver_fvol( int, int, int,
00326 float, float, float, float *, float) ;
00327
00328 extern void EDIT_zscore_vol( int,int,float,void *,int,float * ) ;
00329
00330 extern void EDIT_clip_float( float , int , float * ) ;
00331
00332 extern byte * EDT_calcmask( char * , int * ) ;
00333
00334 extern void * EDIT_volpad( int,int,int,int,int,int ,
00335 int,int,int , int,void * ) ;
00336
00337 #define EDIT_zeropad EDIT_volpad
00338
00339 #define EDIT_volpad_even(px,py,pz,nx,ny,nz,ft,vv) \
00340 EDIT_volpad( (px),(px), (py),(py), (pz),(pz), (nx),(ny),(nz), (ft),(vv) )
00341
00342
00343
00344
00345
00346 extern THD_3dim_dataset * EDIT_empty_copy( THD_3dim_dataset * ) ;
00347 extern THD_3dim_dataset * EDIT_full_copy ( THD_3dim_dataset * , char * ) ;
00348 extern int EDIT_dset_items( THD_3dim_dataset * , ... ) ;
00349 extern THD_3dim_dataset * EDIT_wod_copy( THD_3dim_dataset * ) ;
00350 extern THD_datablock * EDIT_empty_datablock(void) ;
00351
00352 extern void EDIT_add_bricklist( THD_3dim_dataset *,int,int *,float *,void *sbr[] ) ;
00353
00354 extern void EDIT_add_brick( THD_3dim_dataset * , int , float , void * ) ;
00355
00356 extern void EDIT_substitute_brick( THD_3dim_dataset * , int,int , void * ) ;
00357
00358
00359 extern void EDIT_cluster_array (MCW_cluster_array * , int, float, float);
00360
00361
00362 extern void EDIT_filter_volume (int, int, int, float, float, float,
00363 int, void *, int, float , byte * , char * );
00364
00365
00366
00367 #define ADN_none 0
00368
00369
00370
00371 #define ADN_prefix 6001
00372 #define ADN_directory_name 6002
00373
00374
00375
00376 #define ADN_brick_fac 6011
00377 #define ADN_malloc_type 6012
00378 #define ADN_datum_all 6013
00379 #define ADN_datum_array 6014
00380 #define ADN_nvals 6016
00381
00382
00383
00384 #define ADN_nxyz 6020
00385 #define ADN_xyzdel 6021
00386 #define ADN_xyzorg 6022
00387 #define ADN_xyzorient 6023
00388 #define ADN_to_dicomm 6024
00389
00390
00391
00392 #define ADN_ntt 6031
00393 #define ADN_ttorg 6032
00394 #define ADN_ttdel 6033
00395 #define ADN_ttdur 6034
00396
00397 #define ADN_nsl 6035
00398 #define ADN_zorg_sl 6036
00399 #define ADN_dz_sl 6037
00400 #define ADN_toff_sl 6039
00401 #define ADN_tunits 6040
00402
00403
00404
00405 #define ADN_type 6051
00406 #define ADN_view_type 6052
00407 #define ADN_func_type 6053
00408 #define ADN_label1 6054
00409 #define ADN_label2 6055
00410 #define ADN_self_name 6056
00411 #define ADN_keywords_replace 6057
00412 #define ADN_keywords_append 6058
00413
00414 #define ADN_warp_parent 6061
00415 #define ADN_anat_parent 6062
00416 #define ADN_stat_aux 6063
00417 #define ADN_warp 6064
00418 #define ADN_anatpar_idcode 6065
00419
00420
00421 #define ADN_ONE_STEP 100000
00422 #define ADN_brick_label_one (2*ADN_ONE_STEP)
00423 #define ADN_brick_fac_one (3*ADN_ONE_STEP)
00424 #define ADN_brick_stataux_one (4*ADN_ONE_STEP)
00425 #define ADN_brick_keywords_replace_one (5*ADN_ONE_STEP)
00426 #define ADN_brick_keywords_append_one (6*ADN_ONE_STEP)
00427
00428
00429
00430
00431
00432
00433
00434 #define EDIT_COPY_ANATOMY_PARENT_ID(nds,ods) \
00435 do{ if( ISVALID_DSET(nds) && ISVALID_DSET(ods) ) \
00436 (nds)->anat_parent_idcode = (ods)->anat_parent_idcode ; \
00437 } while(0)
00438
00439
00440
00441 #define EDIT_ZERO_ANATOMY_PARENT_ID(nds) \
00442 do{ if( ISVALID_DSET(nds) ) \
00443 ZERO_IDCODE((nds)->anat_parent_idcode); } while(0)
00444
00445
00446
00447
00448
00449
00450
00451 #define EDIT_STATAUX4(ds,iv,ft,a,b,c,d) \
00452 do{ float sqq[6] ; \
00453 if( ISVALID_DSET(ds) && \
00454 (iv) >= 0 && (iv) < DSET_NVALS(ds) && \
00455 (ft) >= 0 && (ft) <= LAST_FUNC_TYPE ){ \
00456 sqq[0] = (ft) ; sqq[1] = FUNC_need_stat_aux[ft] ; \
00457 sqq[2] = (a) ; sqq[3] = (b) ; sqq[4] = (c) ; sqq[5] = (d) ; \
00458 EDIT_dset_items( (ds),ADN_brick_stataux_one+(iv),sqq,ADN_none ) ; \
00459 } } while(0)
00460
00461
00462
00463 #define EDIT_BRICK_TO_NOSTAT(ds,iv) \
00464 EDIT_STATAUX4(ds,iv,FUNC_FIM_TYPE,0,0,0,0)
00465
00466
00467
00468 #define EDIT_BRICK_TO_FICO(ds,iv,nsam,nfit,nort) \
00469 EDIT_STATAUX4(ds,iv,FUNC_COR_TYPE,nsam,nfit,nort,0)
00470
00471
00472
00473 #define EDIT_BRICK_TO_FITT(ds,iv,ndof) \
00474 EDIT_STATAUX4(ds,iv,FUNC_TT_TYPE,ndof,0,0,0)
00475
00476
00477
00478 #define EDIT_BRICK_TO_FIFT(ds,iv,ndof,ddof) \
00479 EDIT_STATAUX4(ds,iv,FUNC_FT_TYPE,ndof,ddof,0,0)
00480
00481
00482
00483 #define EDIT_BRICK_TO_FIZT(ds,iv) \
00484 EDIT_STATAUX4(ds,iv,FUNC_ZT_TYPE,0,0,0,0)
00485
00486
00487
00488 #define EDIT_BRICK_TO_FICT(ds,iv,ndof) \
00489 EDIT_STATAUX4(ds,iv,FUNC_CT_TYPE,ndof,0,0,0)
00490
00491
00492
00493 #define EDIT_BRICK_TO_FIBT(ds,iv,a,b) \
00494 EDIT_STATAUX4(ds,iv,FUNC_BT_TYPE,a,b,0,0)
00495
00496
00497
00498 #define EDIT_BRICK_TO_FIBN(ds,iv,ntrial,prob) \
00499 EDIT_STATAUX4(ds,iv,FUNC_BN_TYPE,ntrial,prob,0,0)
00500
00501
00502
00503 #define EDIT_BRICK_TO_FIGT(ds,iv,shape,scale) \
00504 EDIT_STATAUX4(ds,iv,FUNC_GT_TYPE,shape,scale,0,0)
00505
00506
00507
00508 #define EDIT_BRICK_TO_FIPT(ds,iv,mean) \
00509 EDIT_STATAUX4(ds,iv,FUNC_PT_TYPE,mean,0,0,0)
00510
00511
00512
00513
00514
00515 #define EDIT_BRICK_LABEL(ds,iv,str) \
00516 EDIT_dset_items( (ds), ADN_brick_label_one+(iv), (str), ADN_none )
00517
00518
00519
00520
00521 #define EDIT_BRICK_FACTOR(ds,iv,fac) \
00522 EDIT_dset_items( (ds), ADN_brick_fac_one+(iv), (fac), ADN_none )
00523
00524
00525
00526 #define EDIT_BRICK_ADDKEY(ds,iv,str) \
00527 EDIT_dset_items( (ds), ADN_brick_keywords_append_one+(iv), (str), ADN_none )
00528
00529
00530
00531 #endif