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

landmark_file.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/objects.h> 00017 #include <bicpl/vols.h> 00018 00019 #ifndef lint 00020 static char rcsid[] = "$Header: /software/source//libraries/bicpl/Objects/landmark_file.c,v 1.9 2000/02/06 15:30:43 stever Exp $"; 00021 #endif 00022 00023 /* ----------------------------- MNI Header ----------------------------------- 00024 @NAME : get_default_landmark_file_suffix 00025 @INPUT : 00026 @OUTPUT : 00027 @RETURNS : "lmk" 00028 @DESCRIPTION: Returns the default suffix for landmark files. 00029 @METHOD : 00030 @GLOBALS : 00031 @CALLS : 00032 @CREATED : 1993 David MacDonald 00033 @MODIFIED : 00034 ---------------------------------------------------------------------------- */ 00035 00036 public STRING get_default_landmark_file_suffix( void ) 00037 { 00038 return( "lmk" ); 00039 } 00040 00041 /* ----------------------------- MNI Header ----------------------------------- 00042 @NAME : input_landmark_file 00043 @INPUT : volume 00044 filename 00045 colour 00046 size 00047 type 00048 @OUTPUT : 00049 @RETURNS : OK or ERROR 00050 @DESCRIPTION: Reads a landmark.lmk file and creates an object list consisting 00051 of markers, with the given colour, size, and type. 00052 @METHOD : 00053 @GLOBALS : 00054 @CALLS : 00055 @CREATED : 1993 David MacDonald 00056 @MODIFIED : 00057 ---------------------------------------------------------------------------- */ 00058 00059 public Status input_landmark_file( 00060 Volume volume, 00061 STRING filename, 00062 Colour colour, 00063 Real size, 00064 Marker_types type, 00065 int *n_objects, 00066 object_struct **object_list[] ) 00067 { 00068 Status status; 00069 object_struct *object; 00070 marker_struct marker; 00071 FILE *file; 00072 00073 status = open_file_with_default_suffix( filename, 00074 get_default_landmark_file_suffix(), 00075 READ_FILE, 00076 ASCII_FORMAT, &file ); 00077 00078 *n_objects = 0; 00079 00080 if( status == OK ) 00081 { 00082 while( io_tag_point( file, READ_FILE, volume, size, &marker ) == OK ) 00083 { 00084 marker.colour = colour; 00085 marker.type = type; 00086 object = create_object( MARKER ); 00087 *(get_marker_ptr(object)) = marker; 00088 00089 add_object_to_list( n_objects, object_list, object ); 00090 } 00091 00092 status = close_file( file ); 00093 } 00094 00095 return( status ); 00096 } 00097 00098 /* ----------------------------- MNI Header ----------------------------------- 00099 @NAME : io_tag_point 00100 @INPUT : file 00101 io_direction 00102 volume 00103 size 00104 @OUTPUT : marker 00105 @RETURNS : OK or ERROR 00106 @DESCRIPTION: Inputs one marker in landmark format from the file. 00107 @METHOD : 00108 @GLOBALS : 00109 @CALLS : 00110 @CREATED : 1993 David MacDonald 00111 @MODIFIED : 00112 ---------------------------------------------------------------------------- */ 00113 00114 public Status io_tag_point( 00115 FILE *file, 00116 IO_types io_direction, 00117 Volume volume, 00118 Real size, 00119 marker_struct *marker ) 00120 { 00121 Status status; 00122 STRING line, stripped; 00123 Point position; 00124 int sizes[MAX_DIMENSIONS]; 00125 int len, offset; 00126 Real voxel[MAX_DIMENSIONS]; 00127 Real x, y, z; 00128 Real x_w, y_w, z_w; 00129 00130 status = OK; 00131 00132 if( volume != (Volume) NULL && get_volume_n_dimensions(volume) != 3 ) 00133 { 00134 print_error( "Error: volume must be 3d to use for input landmarks.\n"); 00135 volume = (Volume) NULL; 00136 } 00137 00138 if( io_direction == WRITE_FILE ) 00139 { 00140 if( volume == (Volume) NULL ) 00141 { 00142 position = marker->position; 00143 } 00144 else 00145 { 00146 convert_world_to_voxel( volume, 00147 (Real) Point_x(marker->position), 00148 (Real) Point_y(marker->position), 00149 (Real) Point_z(marker->position), 00150 voxel ); 00151 00152 get_volume_sizes( volume, sizes ); 00153 00154 convert_voxel_to_talairach( voxel[X], voxel[Y], voxel[Z], 00155 sizes[X], sizes[Y], sizes[Z], 00156 &x, &y, &z ); 00157 00158 fill_Point( position, x, y, z ); 00159 } 00160 } 00161 00162 if( status == OK ) 00163 status = io_point( file, io_direction, ASCII_FORMAT, &position ); 00164 00165 if( io_direction == READ_FILE ) 00166 { 00167 marker->colour = WHITE; 00168 marker->type = BOX_MARKER; 00169 00170 if( volume == (Volume) NULL ) 00171 { 00172 marker->position = position; 00173 } 00174 else 00175 { 00176 get_volume_sizes( volume, sizes ); 00177 00178 convert_talairach_to_voxel( (Real) Point_x(position), 00179 (Real) Point_y(position), 00180 (Real) Point_z(position), 00181 sizes[X], sizes[Y], sizes[Z], 00182 &voxel[X], &voxel[Y], &voxel[Z] ); 00183 00184 convert_voxel_to_world( volume, voxel, &x_w, &y_w, &z_w ); 00185 fill_Point( marker->position, x_w, y_w, z_w ); 00186 } 00187 } 00188 00189 #define USE_X_POSITION_FOR_WEIGHT 00190 #ifdef USE_X_POSITION_FOR_WEIGHT 00191 if( status == OK ) 00192 { 00193 if( io_direction == WRITE_FILE ) 00194 status = io_float( file, io_direction, ASCII_FORMAT, 00195 &Point_x(position)); 00196 else 00197 { 00198 status = io_real( file, io_direction, ASCII_FORMAT, &marker->size ); 00199 marker->size = size; 00200 } 00201 } 00202 #else 00203 if( status == OK ) 00204 status = io_real( file, io_direction, ASCII_FORMAT, &marker->size ); 00205 #endif 00206 00207 if( status == OK ) 00208 status = io_int( file, io_direction, ASCII_FORMAT, 00209 &marker->structure_id ); 00210 00211 if( status == OK ) 00212 status = io_int( file, io_direction, ASCII_FORMAT, 00213 &marker->patient_id ); 00214 00215 if( io_direction == WRITE_FILE ) 00216 { 00217 if( status == OK && string_length(marker->label) > 0 ) 00218 status = io_quoted_string( file, io_direction, ASCII_FORMAT, 00219 &marker->label ); 00220 } 00221 else 00222 { 00223 if( status == OK ) 00224 status = input_line( file, &line ); 00225 00226 if( status == OK ) 00227 { 00228 stripped = strip_outer_blanks( line ); 00229 delete_string( line ); 00230 00231 if( stripped[0] == '"' ) 00232 offset = 1; 00233 else 00234 offset = 0; 00235 00236 marker->label = create_string( &stripped[offset] ); 00237 00238 len = string_length( marker->label ); 00239 00240 if( len > 0 && marker->label[len-1] == '"' ) 00241 marker->label[len-1] = END_OF_STRING; 00242 00243 delete_string( stripped ); 00244 } 00245 } 00246 00247 if( status == OK ) 00248 status = io_newline( file, io_direction, ASCII_FORMAT ); 00249 00250 return( status ); 00251 }

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