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

output_free.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/output_free.c,v 1.22 2000/02/06 15:30:56 stever Exp $"; 00020 #endif 00021 00022 /* ----------------------------- MNI Header ----------------------------------- 00023 @NAME : output_volume_free_format 00024 @INPUT : prefix 00025 volume 00026 axis_ordering 00027 @OUTPUT : 00028 @RETURNS : OR or ERROR 00029 @DESCRIPTION: Outputs a volume in the simple free format. Will probably 00030 become obsolete soon. 00031 @METHOD : 00032 @GLOBALS : 00033 @CALLS : 00034 @CREATED : 1993 David MacDonald 00035 @MODIFIED : 00036 ---------------------------------------------------------------------------- */ 00037 00038 public Status output_volume_free_format( 00039 STRING prefix, 00040 Volume volume, 00041 int axis_ordering[] ) 00042 { 00043 Status status; 00044 Real trans, separations[MAX_DIMENSIONS]; 00045 int sizes[MAX_DIMENSIONS]; 00046 int a1, a2, a3; 00047 int n_bytes_per_voxel, indices[MAX_DIMENSIONS]; 00048 void *ptr; 00049 FILE *file; 00050 STRING header_filename, voxel_filename, abs_voxel_filename; 00051 STRING filename_no_dirs; 00052 int axis; 00053 progress_struct progress; 00054 General_transform *voxel_to_world; 00055 Transform *transform; 00056 00057 header_filename = concat_strings( prefix, ".fre" ); 00058 abs_voxel_filename = alloc_string( string_length(prefix) + 10 ); 00059 abs_voxel_filename = concat_strings( prefix, ".img" ); 00060 00061 filename_no_dirs = remove_directories_from_filename( prefix ); 00062 voxel_filename = concat_strings( filename_no_dirs, ".img" ); 00063 00064 status = open_file( header_filename, WRITE_FILE, ASCII_FORMAT, &file ); 00065 00066 if( get_volume_data_type(volume) == UNSIGNED_BYTE ) 00067 n_bytes_per_voxel = 1; 00068 else 00069 n_bytes_per_voxel = 2; 00070 00071 if( status == OK ) 00072 status = output_int( file, n_bytes_per_voxel ); 00073 00074 if( status == OK ) 00075 status = output_newline( file ); 00076 00077 get_volume_sizes( volume, sizes ); 00078 get_volume_separations( volume, separations ); 00079 00080 voxel_to_world = get_voxel_to_world_transform( volume ); 00081 00082 if( get_transform_type(voxel_to_world) == LINEAR ) 00083 transform = get_linear_transform_ptr( voxel_to_world ); 00084 else 00085 transform = (Transform *) NULL; 00086 00087 for_less( axis, 0, N_DIMENSIONS ) 00088 { 00089 if( status == OK ) 00090 { 00091 if( transform != (Transform *) NULL ) 00092 { 00093 trans = Transform_elem(*transform,axis,3); 00094 if( separations[axis] < 0.0 ) 00095 trans += separations[axis] * (Real) (sizes[axis]-1); 00096 } 00097 else 00098 trans = 0.0; 00099 00100 status = output_float( file, (float) trans ); 00101 } 00102 } 00103 00104 if( status == OK ) 00105 status = output_newline( file ); 00106 00107 for_less( axis, 0, N_DIMENSIONS ) 00108 { 00109 if( status == OK ) 00110 status = output_int( file, sizes[axis_ordering[axis]] ); 00111 00112 if( status == OK ) 00113 status = output_real( file, separations[axis_ordering[axis]]); 00114 00115 if( status == OK ) 00116 status = output_character( file, (char) ' ' ); 00117 00118 if( status == OK ) 00119 status = output_character( file, (char) ('x'+axis_ordering[axis]) ); 00120 00121 if( status == OK ) 00122 status = output_newline( file ); 00123 } 00124 00125 if( status == OK ) 00126 status = output_string( file, voxel_filename ); 00127 00128 if( status == OK ) 00129 status = output_newline( file ); 00130 00131 if( status == OK ) 00132 status = close_file( file ); 00133 00134 if( status == OK ) 00135 status = open_file( abs_voxel_filename, WRITE_FILE, BINARY_FORMAT, 00136 &file ); 00137 00138 if( status == OK ) 00139 { 00140 a1 = axis_ordering[0]; 00141 a2 = axis_ordering[1]; 00142 a3 = axis_ordering[2]; 00143 00144 initialize_progress_report( &progress, FALSE, sizes[a1] * sizes[a2], 00145 "Writing Volume" ); 00146 00147 for_less( indices[a1], 0, sizes[a1] ) 00148 { 00149 for_less( indices[a2], 0, sizes[a2] ) 00150 { 00151 for_less( indices[a3], 0, sizes[a3] ) 00152 { 00153 GET_VOXEL_PTR_3D( ptr, volume, 00154 indices[X],indices[Y],indices[Z] ); 00155 status = io_binary_data( file, WRITE_FILE, 00156 ptr, (size_t) n_bytes_per_voxel,1); 00157 } 00158 00159 update_progress_report( &progress, indices[a1] * sizes[a2] + 00160 indices[a2] + 1 ); 00161 } 00162 } 00163 00164 terminate_progress_report( &progress ); 00165 } 00166 00167 delete_string( header_filename ); 00168 delete_string( voxel_filename ); 00169 delete_string( abs_voxel_filename ); 00170 delete_string( filename_no_dirs ); 00171 00172 return( status ); 00173 }

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