00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 public STRING
get_default_landmark_file_suffix(
void )
00037 {
00038
return(
"lmk" );
00039 }
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
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
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
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 }