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

texture_values.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 #ifndef lint 00016 static char rcsid[] = "$Header: /software/source//libraries/bicpl/Objects/texture_values.c,v 1.6 2001/04/21 17:06:53 stever Exp $"; 00017 #endif 00018 00019 #include <netcdf.h> 00020 #include <volume_io/internal_volume_io.h> 00021 #include <bicpl/objects.h> 00022 00023 private Status output_texture_values_ascii( 00024 STRING filename, 00025 int n_values, 00026 Real values[] ) 00027 { 00028 int v; 00029 Status status; 00030 FILE *file; 00031 00032 status = open_file( filename, WRITE_FILE, ASCII_FORMAT, &file ); 00033 00034 if( status != OK ) 00035 return( status ); 00036 00037 for_less( v, 0, n_values ) 00038 { 00039 if( output_real( file, values[v] ) != OK || 00040 output_newline( file ) != OK ) 00041 { 00042 print_error( "Error outputting %d'th value out of %d to file %s\n", 00043 v+1, n_values, filename ); 00044 return( ERROR ); 00045 } 00046 } 00047 00048 (void) close_file( file ); 00049 00050 return( OK ); 00051 } 00052 00053 private Status input_texture_values_ascii( 00054 STRING filename, 00055 int *n_values, 00056 Real *values[] ) 00057 { 00058 Status status; 00059 FILE *file; 00060 Real value; 00061 00062 status = open_file( filename, READ_FILE, ASCII_FORMAT, &file ); 00063 00064 if( status != OK ) 00065 return( status ); 00066 00067 *n_values = 0; 00068 *values = NULL; 00069 00070 while( input_real( file, &value ) == OK ) 00071 { 00072 ADD_ELEMENT_TO_ARRAY( *values, *n_values, value, DEFAULT_CHUNK_SIZE ); 00073 } 00074 00075 (void) close_file( file ); 00076 00077 return( OK ); 00078 } 00079 00080 private Status output_texture_values_binary( 00081 STRING filename, 00082 int n_values, 00083 Real values[] ) 00084 { 00085 int v, sizes[2]; 00086 Status status; 00087 Volume volume; 00088 STRING dim_names[] = { MIxspace, MIyspace }; 00089 00090 volume = create_volume( 2, dim_names, NC_FLOAT, FALSE, 0.0, 0.0 ); 00091 sizes[0] = 1; 00092 sizes[1] = n_values; 00093 set_volume_sizes( volume, sizes ); 00094 alloc_volume_data( volume ); 00095 00096 for_less( v, 0, n_values ) 00097 set_volume_real_value( volume, 0, v, 0, 0, 0, values[v] ); 00098 00099 status = output_volume( filename, NC_UNSPECIFIED, FALSE, 0.0, 0.0, 00100 volume, "Texture values.\n", NULL ); 00101 00102 delete_volume( volume ); 00103 00104 return( status ); 00105 } 00106 00107 private Status input_texture_values_binary( 00108 STRING filename, 00109 int *n_values, 00110 Real *values[] ) 00111 { 00112 int v, sizes[2]; 00113 Status status; 00114 Volume volume; 00115 STRING dim_names[] = { MIxspace, MIyspace }; 00116 00117 status = input_volume( filename, 2, dim_names, 00118 NC_UNSPECIFIED, FALSE, 0.0, 0.0, 00119 TRUE, &volume, NULL ); 00120 00121 if( status != OK ) 00122 return( status ); 00123 00124 get_volume_sizes( volume, sizes ); 00125 00126 *n_values = sizes[1]; 00127 00128 ALLOC( *values, *n_values ); 00129 00130 for_less( v, 0, *n_values ) 00131 (*values)[v] = get_volume_real_value( volume, 0, v, 0, 0, 0 ); 00132 00133 delete_volume( volume ); 00134 00135 return( OK ); 00136 } 00137 00144 public Status output_texture_values( 00145 STRING filename, 00146 File_formats format, 00147 int n_values, 00148 Real values[] ) 00149 { 00150 Status status; 00151 00152 if( format == ASCII_FORMAT ) 00153 status = output_texture_values_ascii( filename, n_values, values ); 00154 else 00155 status = output_texture_values_binary( filename, n_values, values ); 00156 00157 return( status ); 00158 } 00159 00166 public Status input_texture_values( 00167 STRING filename, 00168 int *n_values, 00169 Real *values[] ) 00170 { 00171 Status status; 00172 00173 if( filename_extension_matches( filename, MNC_ENDING ) ) 00174 status = input_texture_values_binary( filename, n_values, values ); 00175 else 00176 status = input_texture_values_ascii( filename, n_values, values ); 00177 00178 return( status ); 00179 }

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