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/data_structures.h>
00017
00018
#ifndef lint
00019
static char rcsid[] =
"$Header: /software/source//libraries/bicpl/Data_structures/bitlist.c,v 1.12 2000/02/06 15:30:10 stever Exp $";
00020
#endif
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 public void create_bitlist(
00036
int n_bits,
00037
bitlist_struct *bitlist )
00038 {
00039 bitlist->
n_words = (n_bits +
BITS_PER_BITLIST_WORD - 1) /
00040 (
BITS_PER_BITLIST_WORD);
00041
00042
if( bitlist->
n_words > 0 )
00043 ALLOC( bitlist->
bits, bitlist->
n_words );
00044
00045
zero_bitlist( bitlist );
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 public void zero_bitlist(
00062
bitlist_struct *bitlist )
00063 {
00064
int i;
00065
00066 for_less( i, 0, bitlist->
n_words )
00067 bitlist->
bits[i] = (
bitlist_type) 0;
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 public void fill_bitlist(
00084
bitlist_struct *bitlist )
00085 {
00086
int i;
00087
00088 for_less( i, 0, bitlist->
n_words )
00089 bitlist->
bits[i] = (
bitlist_type) -1;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 public void set_bitlist_bit(
00108
bitlist_struct *bitlist,
00109
int bit_index,
00110 BOOLEAN value )
00111 {
00112
int word_index, bit_sub_index;
00113
bitlist_type bit;
00114
00115 word_index = bit_index >>
LOG_BITS_PER_BITLIST_WORD;
00116 bit_sub_index = bit_index &
BITS_PER_BITLIST_WORD_MINUS_1;
00117
00118 bit = (
bitlist_type) 1 << (
bitlist_type) bit_sub_index;
00119
00120
if( value )
00121 bitlist->
bits[word_index] |= bit;
00122
else if( bitlist->
bits[word_index] & bit )
00123 bitlist->
bits[word_index] ^= bit;
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 public BOOLEAN
get_bitlist_bit(
00141
bitlist_struct *bitlist,
00142
int bit_index )
00143 {
00144
int word_index, bit_sub_index;
00145
bitlist_type word_bits;
00146 BOOLEAN value;
00147
00148 word_index = bit_index >>
LOG_BITS_PER_BITLIST_WORD;
00149 bit_sub_index = bit_index &
BITS_PER_BITLIST_WORD_MINUS_1;
00150
00151 word_bits = bitlist->
bits[word_index];
00152
00153 value = ((word_bits >> (
bitlist_type) bit_sub_index) & 1) != 0;
00154
00155
return( value );
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 public void delete_bitlist(
00172
bitlist_struct *bitlist )
00173 {
00174
if( bitlist->
n_words > 0 )
00175 {
00176 FREE( bitlist->
bits );
00177 }
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 public void create_bitlist_3d(
00198
int nx,
00199
int ny,
00200
int nz,
00201
bitlist_3d_struct *bitlist )
00202 {
00203 bitlist->
nx =
nx;
00204 bitlist->
ny =
ny;
00205 bitlist->
nz =
nz;
00206 bitlist->
n_z_words = (
nz +
BITS_PER_BITLIST_WORD - 1) /
00207
BITS_PER_BITLIST_WORD;
00208
00209
if(
nx > 0 &&
ny > 0 &&
nz > 0 )
00210 ALLOC3D( bitlist->
bits,
nx,
ny, bitlist->
n_z_words );
00211
00212
zero_bitlist_3d( bitlist );
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 public void zero_bitlist_3d(
00229
bitlist_3d_struct *bitlist )
00230 {
00231
int x,
y, z;
00232
00233 for_less( x, 0, bitlist->
nx )
00234 {
00235 for_less(
y, 0, bitlist->
ny )
00236 {
00237 for_less( z, 0, bitlist->
n_z_words )
00238 {
00239 bitlist->
bits[x][
y][z] = (
bitlist_type) 0;
00240 }
00241 }
00242 }
00243 }
00244
00245 public void get_bitlist_3d_sizes(
00246
bitlist_3d_struct *bitlist,
00247
int *nx,
00248
int *ny,
00249
int *nz )
00250 {
00251 *
nx = bitlist->
nx;
00252 *
ny = bitlist->
ny;
00253 *
nz = bitlist->
nz;
00254 }
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 public void fill_bitlist_3d(
00270
bitlist_3d_struct *bitlist )
00271 {
00272
int x,
y, z;
00273
00274 for_less( x, 0, bitlist->
nx )
00275 {
00276 for_less(
y, 0, bitlist->
ny )
00277 {
00278 for_less( z, 0, bitlist->
n_z_words )
00279 {
00280 bitlist->
bits[x][
y][z] = (
bitlist_type) -1;
00281 }
00282 }
00283 }
00284 }
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 public void set_bitlist_bit_3d(
00304
bitlist_3d_struct *bitlist,
00305
int x,
00306
int y,
00307
int z,
00308 BOOLEAN value )
00309 {
00310
int word_index, bit_sub_index;
00311
bitlist_type bit;
00312
00313 word_index = z >>
LOG_BITS_PER_BITLIST_WORD;
00314 bit_sub_index = z &
BITS_PER_BITLIST_WORD_MINUS_1;
00315
00316 bit = (
bitlist_type) 1 << (
bitlist_type) bit_sub_index;
00317
00318
if( value )
00319 {
00320 bitlist->
bits[x][
y][word_index] |= bit;
00321 }
00322
else
00323 {
00324
if( bitlist->
bits[x][
y][word_index] & bit )
00325 {
00326 bitlist->
bits[x][
y][word_index] ^= bit;
00327 }
00328 }
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 public BOOLEAN
get_bitlist_bit_3d(
00348
bitlist_3d_struct *bitlist,
00349
int x,
00350
int y,
00351
int z )
00352 {
00353
int word_index, bit_sub_index;
00354
bitlist_type word;
00355
00356 bit_sub_index = z &
BITS_PER_BITLIST_WORD_MINUS_1;
00357
00358 word_index = z >>
LOG_BITS_PER_BITLIST_WORD;
00359
00360 word = bitlist->
bits[x][
y][word_index];
00361
00362
if( word == 0 )
00363
return(
FALSE );
00364
else
00365
return( ((word >> (
bitlist_type) bit_sub_index) & 1) != 0 );
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 public void delete_bitlist_3d(
00382
bitlist_3d_struct *bitlist )
00383 {;
00384
if( bitlist->
nx > 0 && bitlist->
ny > 0 && bitlist->
nz > 0 )
00385 {
00386 FREE3D( bitlist->
bits );
00387 }
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 public Status
io_bitlist_3d(
00406 FILE *file,
00407 IO_types io_type,
00408
bitlist_3d_struct *bitlist )
00409 {
00410 Status status;
00411
int x,
y;
00412
00413 status = OK;
00414
00415 for_less( x, 0, bitlist->
nx )
00416 {
00417 for_less(
y, 0, bitlist->
ny )
00418 {
00419 status = io_binary_data( file, io_type,
00420 (
void *) (bitlist->
bits[x][
y]),
00421
sizeof( bitlist->
bits[x][
y] ),
00422 bitlist->
n_z_words );
00423
00424
if( status != OK )
00425
break;
00426 }
00427
if( status != OK )
00428
break;
00429 }
00430
00431
return( status );
00432 }