Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

talairach.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- 00002 @COPYRIGHT : 00003 Copyright 1993,1994,1995 David MacDonald, 00004 McConnell Brain Imaging Centre, 00005 Montreal Neurological Institute, McGill University. 00006 Permission to use, copy, modify, and distribute this 00007 software and its documentation for any purpose and without 00008 fee is hereby granted, provided that the above copyright 00009 notice appear in all copies. The author and McGill University 00010 make no representations about the suitability of this 00011 software for any purpose. It is provided "as is" without 00012 express or implied warranty. 00013 ---------------------------------------------------------------------------- */ 00014 00015 #include <volume_io/internal_volume_io.h> 00016 #include <bicpl/vols.h> 00017 00018 #ifndef lint 00019 static char rcsid[] = "$Header: /software/source//libraries/bicpl/Volumes/talairach.c,v 1.14 2000/02/06 15:30:57 stever Exp $"; 00020 #endif 00021 00022 #define TALAIRACH_OFFSET 16.0 00023 00024 #define FALSE 0 00025 #define TRUE 1 00026 00027 private int nx = 128; 00028 private int ny = 128; 00029 private int nz = 80; 00030 00031 private Real x_low = -1.28; 00032 private Real x_high = 1.28; 00033 private Real y_low = -1.28; 00034 private Real y_high = 1.28; 00035 private Real z_low = -0.50; 00036 private Real z_high = 1.10; 00037 00038 private Real x_dist_minus_1 = -67.0; 00039 private Real x_dist_1 = 67.0; 00040 private Real y_dist_minus_1 = -86.0; 00041 private Real y_dist_1 = 86.0; 00042 private Real z_dist_0 = 0.0; 00043 private Real z_dist_1 = 75.0; 00044 00045 private BOOLEAN initialized = FALSE; 00046 00047 private void read_talairach_coordinate_system( void ); 00048 00049 /* ----------------------------- MNI Header ----------------------------------- 00050 @NAME : check_initialized 00051 @INPUT : 00052 @OUTPUT : 00053 @RETURNS : 00054 @DESCRIPTION: Checks if the Talairach system has been read from the standard 00055 place. 00056 @METHOD : 00057 @GLOBALS : 00058 @CALLS : 00059 @CREATED : 1993 David MacDonald 00060 @MODIFIED : 00061 ---------------------------------------------------------------------------- */ 00062 00063 private void check_initialized( void ) 00064 { 00065 if( !initialized ) 00066 { 00067 read_talairach_coordinate_system(); 00068 initialized = TRUE; 00069 } 00070 } 00071 00072 /* ----------------------------- MNI Header ----------------------------------- 00073 @NAME : read_talairach_coordinate_system 00074 @INPUT : 00075 @OUTPUT : 00076 @RETURNS : 00077 @DESCRIPTION: Reads the Talairach system coordinates from the standard 00078 place. 00079 @METHOD : 00080 @GLOBALS : 00081 @CALLS : 00082 @CREATED : 1993 David MacDonald 00083 @MODIFIED : 00084 ---------------------------------------------------------------------------- */ 00085 00086 private void read_talairach_coordinate_system( void ) 00087 { 00088 int i, n_lines, ch; 00089 FILE *file; 00090 STRING name = "brain_size.dat"; 00091 STRING filename; 00092 int okay; 00093 int tmp_nx, tmp_ny, tmp_nz; 00094 Real tmp_x_low, tmp_x_high, tmp_y_low, tmp_y_high, tmp_z_low; 00095 Real tmp_z_high, tmp_x_dist_minus_1, tmp_x_dist_1, tmp_y_dist_minus_1; 00096 Real tmp_y_dist_1, tmp_z_dist_0, tmp_z_dist_1; 00097 00098 okay = TRUE; 00099 00100 if( file_exists(name) ) 00101 { 00102 filename = create_string( name ); 00103 } 00104 else 00105 { 00106 if( getenv( "PET_ROI" ) == NULL ) 00107 { 00108 print_error( "You have to setenv PET_ROI.\n" ); 00109 filename = NULL; 00110 okay = FALSE; 00111 } 00112 else 00113 { 00114 filename = get_absolute_filename( name, getenv("PET_ROI") ); 00115 } 00116 } 00117 00118 if( okay ) 00119 { 00120 file = fopen( filename, "r" ); 00121 00122 if( file == (FILE *) 0 ) 00123 { 00124 print_error( "Cannot open %s\n", filename ); 00125 okay = FALSE; 00126 } 00127 } 00128 00129 if( okay ) 00130 { 00131 (void) input_int( file, &n_lines ); 00132 00133 for( i = 0; i < n_lines+1; ++i ) 00134 { 00135 while( (ch = fgetc(file)) != EOF && ch != '\n' ) 00136 {} 00137 } 00138 00139 if( input_int( file, &tmp_nx ) != OK || 00140 input_int( file, &tmp_ny ) != OK || 00141 input_int( file, &tmp_nz ) != OK || 00142 input_real( file, &tmp_x_low ) != OK || 00143 input_real( file, &tmp_x_high ) != OK || 00144 input_real( file, &tmp_y_low ) != OK || 00145 input_real( file, &tmp_y_high ) != OK || 00146 input_real( file, &tmp_z_low ) != OK || 00147 input_real( file, &tmp_z_high ) != OK || 00148 input_real( file, &tmp_x_dist_minus_1 ) != OK || 00149 input_real( file, &tmp_x_dist_1 ) != OK || 00150 input_real( file, &tmp_y_dist_minus_1 ) != OK || 00151 input_real( file, &tmp_y_dist_1 ) != OK || 00152 input_real( file, &tmp_z_dist_0 ) != OK || 00153 input_real( file, &tmp_z_dist_1 ) != OK ) 00154 { 00155 print_error( "Error reading info from %s\n", filename ); 00156 okay = FALSE; 00157 } 00158 } 00159 00160 if( okay ) 00161 { 00162 nx = tmp_nx; 00163 ny = tmp_ny; 00164 nz = tmp_nz; 00165 00166 x_low = tmp_x_low; 00167 x_high = tmp_x_high; 00168 y_low = tmp_y_low; 00169 y_high = tmp_y_high; 00170 z_low = tmp_z_low; 00171 z_high = tmp_z_high; 00172 00173 x_dist_minus_1 = tmp_x_dist_minus_1; 00174 x_dist_1 = tmp_x_dist_1; 00175 y_dist_minus_1 = tmp_y_dist_minus_1; 00176 y_dist_1 = tmp_y_dist_1; 00177 z_dist_0 = tmp_z_dist_0; 00178 z_dist_1 = tmp_z_dist_1; 00179 00180 (void) fclose( file ); 00181 } 00182 00183 delete_string( filename ); 00184 } 00185 00186 /* ----------------------------- MNI Header ----------------------------------- 00187 @NAME : convert_voxel_to_talairach 00188 @INPUT : x_voxel 00189 y_voxel 00190 z_voxel 00191 nx_voxels 00192 ny_voxels 00193 nz_voxels 00194 @OUTPUT : x_tal 00195 y_tal 00196 z_tal 00197 @RETURNS : 00198 @DESCRIPTION: Converts a voxel to a Talairach voxel. 00199 @METHOD : 00200 @GLOBALS : 00201 @CALLS : 00202 @CREATED : 1993 David MacDonald 00203 @MODIFIED : 00204 ---------------------------------------------------------------------------- */ 00205 00206 public void convert_voxel_to_talairach( 00207 Real x_voxel, 00208 Real y_voxel, 00209 Real z_voxel, 00210 int nx_voxels, 00211 int ny_voxels, 00212 int nz_voxels, 00213 Real *x_tal, 00214 Real *y_tal, 00215 Real *z_tal ) 00216 { 00217 check_initialized(); 00218 00219 *x_tal = x_voxel / (Real) nx_voxels * (Real) nx; 00220 *y_tal = y_voxel / (Real) ny_voxels * (Real) ny; 00221 *z_tal = z_voxel / (Real) nz_voxels * (Real) nz; 00222 } 00223 00224 /* ----------------------------- MNI Header ----------------------------------- 00225 @NAME : convert_talairach_to_voxel 00226 @INPUT : x_tal 00227 y_tal 00228 z_tal 00229 nx_voxels 00230 ny_voxels 00231 nz_voxels 00232 @OUTPUT : x_voxel 00233 y_voxel 00234 z_voxel 00235 @RETURNS : 00236 @DESCRIPTION: Converts a Talairach voxel to a volume voxel. 00237 @METHOD : 00238 @GLOBALS : 00239 @CALLS : 00240 @CREATED : 1993 David MacDonald 00241 @MODIFIED : 00242 ---------------------------------------------------------------------------- */ 00243 00244 public void convert_talairach_to_voxel( 00245 Real x_tal, 00246 Real y_tal, 00247 Real z_tal, 00248 int nx_voxels, 00249 int ny_voxels, 00250 int nz_voxels, 00251 Real *x_voxel, 00252 Real *y_voxel, 00253 Real *z_voxel ) 00254 { 00255 check_initialized(); 00256 00257 *x_voxel = x_tal / (Real) nx * (Real) nx_voxels; 00258 *y_voxel = y_tal / (Real) ny * (Real) ny_voxels; 00259 *z_voxel = z_tal / (Real) nz * (Real) nz_voxels; 00260 } 00261 00262 /* ----------------------------- MNI Header ----------------------------------- 00263 @NAME : convert_to_mm 00264 @INPUT : tal 00265 n_planes 00266 limit_low 00267 limit_high 00268 brain_dist_low 00269 brain_dist_high 00270 brain_limit_low 00271 brain_limit_high 00272 @OUTPUT : 00273 @RETURNS : mm distance 00274 @DESCRIPTION: Converts to Talairach mm in one axis. 00275 @METHOD : 00276 @GLOBALS : 00277 @CALLS : 00278 @CREATED : 1993 David MacDonald 00279 @MODIFIED : 00280 ---------------------------------------------------------------------------- */ 00281 00282 private Real convert_to_mm( 00283 Real tal, 00284 int n_planes, 00285 Real limit_low, 00286 Real limit_high, 00287 Real brain_dist_low, 00288 Real brain_dist_high, 00289 Real brain_limit_low, 00290 Real brain_limit_high ) 00291 { 00292 Real mm; 00293 Real stereotactic; 00294 00295 stereotactic = limit_low + (limit_high - limit_low) * tal / (Real) n_planes; 00296 00297 mm = brain_dist_low + (brain_dist_high - brain_dist_low) * 00298 (stereotactic - brain_limit_low) / (brain_limit_high - brain_limit_low); 00299 00300 return( mm ); 00301 } 00302 00303 /* ----------------------------- MNI Header ----------------------------------- 00304 @NAME : convert_talairach_to_mm 00305 @INPUT : x_tal 00306 y_tal 00307 z_tal 00308 @OUTPUT : x_mm 00309 y_mm 00310 z_mm 00311 @RETURNS : 00312 @DESCRIPTION: Converts a Talairach voxel to a Talairach mm coordinate. 00313 @METHOD : 00314 @GLOBALS : 00315 @CALLS : 00316 @CREATED : 1993 David MacDonald 00317 @MODIFIED : 00318 ---------------------------------------------------------------------------- */ 00319 00320 public void convert_talairach_to_mm( 00321 Real x_tal, 00322 Real y_tal, 00323 Real z_tal, 00324 Real *x_mm, 00325 Real *y_mm, 00326 Real *z_mm ) 00327 { 00328 check_initialized(); 00329 00330 *x_mm = convert_to_mm( x_tal, nx, x_low, x_high, x_dist_minus_1, x_dist_1, 00331 -1.0, 1.0 ); 00332 *y_mm = convert_to_mm( y_tal, ny, y_low, y_high, y_dist_minus_1, y_dist_1, 00333 -1.0, 1.0 ); 00334 *y_mm -= TALAIRACH_OFFSET; 00335 *z_mm = convert_to_mm( z_tal, nz, z_low, z_high, z_dist_0, z_dist_1, 00336 0.0, 1.0 ); 00337 } 00338 00339 /* ----------------------------- MNI Header ----------------------------------- 00340 @NAME : convert_from_mm 00341 @INPUT : mm 00342 n_planes 00343 limit_low 00344 limit_high 00345 brain_dist_low 00346 brain_dist_high 00347 brain_limit_low 00348 brain_limit_high 00349 @OUTPUT : 00350 @RETURNS : Talairach voxel 00351 @DESCRIPTION: Converts from Talairach mm space to Talairach voxel space, 00352 along one axis. 00353 @METHOD : 00354 @GLOBALS : 00355 @CALLS : 00356 @CREATED : 1993 David MacDonald 00357 @MODIFIED : 00358 ---------------------------------------------------------------------------- */ 00359 00360 private Real convert_from_mm( 00361 Real mm, 00362 int n_planes, 00363 Real limit_low, 00364 Real limit_high, 00365 Real brain_dist_low, 00366 Real brain_dist_high, 00367 Real brain_limit_low, 00368 Real brain_limit_high ) 00369 { 00370 Real stereotactic; 00371 00372 stereotactic = brain_limit_low + 00373 (mm - brain_dist_low) * (brain_limit_high - brain_limit_low) 00374 / (brain_dist_high - brain_dist_low); 00375 00376 return( (stereotactic - limit_low) * (Real) n_planes / 00377 (limit_high - limit_low) ); 00378 } 00379 00380 /* ----------------------------- MNI Header ----------------------------------- 00381 @NAME : convert_mm_to_talairach 00382 @INPUT : x_mm 00383 y_mm 00384 z_mm 00385 @OUTPUT : x_tal 00386 y_tal 00387 z_tal 00388 @RETURNS : 00389 @DESCRIPTION: Converts Talairach mm to Talairach voxels. 00390 @METHOD : 00391 @GLOBALS : 00392 @CALLS : 00393 @CREATED : 1993 David MacDonald 00394 @MODIFIED : 00395 ---------------------------------------------------------------------------- */ 00396 00397 public void convert_mm_to_talairach( 00398 Real x_mm, 00399 Real y_mm, 00400 Real z_mm, 00401 Real *x_tal, 00402 Real *y_tal, 00403 Real *z_tal ) 00404 { 00405 check_initialized(); 00406 00407 *x_tal = convert_from_mm( x_mm, nx, x_low, x_high, x_dist_minus_1, x_dist_1, 00408 -1.0, 1.0 ); 00409 *y_tal = convert_from_mm( y_mm + TALAIRACH_OFFSET, ny, y_low, y_high, 00410 y_dist_minus_1, y_dist_1, -1.0, 1.0 ); 00411 *z_tal = convert_from_mm( z_mm, nz, z_low, z_high, z_dist_0, z_dist_1, 00412 0.0, 1.0 ); 00413 }

Generated on Wed Jul 28 09:10:58 2004 for BICPL by doxygen 1.3.7