Mercurial > hg > minc-tools
changeset 990:0aaa3866a1c3
*** empty log message ***
author | david <david> |
---|---|
date | Tue, 27 Feb 1996 15:11:23 +0000 |
parents | 1b6121baee84 |
children | 8d4af6eaf901 |
files | volume_io/Volumes/input_mnc.c volume_io/Volumes/volume_cache.c volume_io/Volumes/volumes.c |
diffstat | 3 files changed, 184 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/volume_io/Volumes/input_mnc.c +++ b/volume_io/Volumes/input_mnc.c @@ -16,7 +16,7 @@ #include <minc.h> #ifndef lint -static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/input_mnc.c,v 1.51 1996-02-14 16:03:34 david Exp $"; +static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/input_mnc.c,v 1.52 1996-02-27 15:11:23 david Exp $"; #endif #define INVALID_AXIS -1 @@ -169,19 +169,22 @@ MIvector_dimension ) ) { if( options->convert_vector_to_colour_flag && - options->dimension_size_for_colour_data == - file->sizes_in_file[file->n_file_dimensions-1] ) + file->sizes_in_file[file->n_file_dimensions-1] >= + options->dimension_size_for_colour_data && + file->sizes_in_file[file->n_file_dimensions-1] <= + options->max_dimension_size_for_colour_data ) { for_less( i, 0, 4 ) { + file->rgba_indices[i] = options->rgba_indices[i]; + if( options->rgba_indices[i] >= - options->dimension_size_for_colour_data ) + file->sizes_in_file[file->n_file_dimensions-1] ) { - print_error( "Error: rgba indices out of range.\n" ); - FREE( file ); - return( (Minc_file) NULL ); + file->rgba_indices[i] = -1; + if( i != 3 ) + print_error( "Warning: rgba indices out of range.\n" ); } - file->rgba_indices[i] = options->rgba_indices[i]; } set_volume_type( volume, NC_LONG, FALSE, 0.0, 0.0 ); @@ -1293,12 +1296,13 @@ public void set_default_minc_input_options( minc_input_options *options ) { - static int default_rgba_indices[4] = { 0, 1, 2, -1 }; + static int default_rgba_indices[4] = { 0, 1, 2, 3 }; set_minc_input_promote_invalid_to_min_flag( options, TRUE ); set_minc_input_vector_to_scalar_flag( options, TRUE ); set_minc_input_vector_to_colour_flag( options, FALSE ); set_minc_input_colour_dimension_size( options, 3 ); + set_minc_input_colour_max_dimension_size( options, 4 ); set_minc_input_colour_indices( options, default_rgba_indices ); } @@ -1392,6 +1396,33 @@ } /* ----------------------------- MNI Header ----------------------------------- +@NAME : set_minc_input_colour_max_dimension_size +@INPUT : size +@OUTPUT : options +@RETURNS : +@DESCRIPTION: Sets the maximum number of vector components in a file that + contains colour data. +@METHOD : +@GLOBALS : +@CALLS : +@CREATED : 1993 David MacDonald +@MODIFIED : +---------------------------------------------------------------------------- */ + +public void set_minc_input_colour_max_dimension_size( + minc_input_options *options, + int size ) +{ + if( size > 0 ) + options->max_dimension_size_for_colour_data = size; + else + { + print_error( "Warning: set_minc_input_colour_max_dimension_size:\n" ); + print_error( " illegal size: %d\n", size ); + } +} + +/* ----------------------------- MNI Header ----------------------------------- @NAME : set_minc_input_colour_indices @INPUT : indices @OUTPUT : options
--- a/volume_io/Volumes/volume_cache.c +++ b/volume_io/Volumes/volume_cache.c @@ -13,7 +13,7 @@ ---------------------------------------------------------------------------- */ #ifndef lint -static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/volume_cache.c,v 1.20 1996-01-15 17:38:53 david Exp $"; +static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/volume_cache.c,v 1.21 1996-02-27 15:11:23 david Exp $"; #endif #include <internal_volume_io.h> @@ -45,6 +45,20 @@ volume_cache_struct *cache, Volume volume ); +#ifdef CACHE_DEBUGGING +private void initialize_cache_debug( + volume_cache_struct *cache ); + +private void record_cache_hit( + volume_cache_struct *cache ); + +private void record_cache_prev_hit( + volume_cache_struct *cache ); + +private void record_cache_no_hit( + volume_cache_struct *cache ); +#endif + /* ----------------------------- MNI Header ----------------------------------- @NAME : set_n_bytes_cache_threshold @INPUT : threshold @@ -302,6 +316,10 @@ cache->max_cache_bytes = get_default_max_bytes_in_cache(); alloc_volume_cache( cache, volume ); + +#ifdef CACHE_DEBUGGING + initialize_cache_debug( cache ); +#endif } /* ----------------------------- MNI Header ----------------------------------- @@ -378,6 +396,12 @@ cache->n_blocks = 0; } +public BOOLEAN volume_cache_is_alloced( + volume_cache_struct *cache ) +{ + return( cache->hash_table != NULL ); +} + /* ----------------------------- MNI Header ----------------------------------- @NAME : get_block_start @INPUT : cache @@ -607,6 +631,7 @@ delete_cache_blocks( cache, volume, TRUE ); FREE( cache->hash_table ); + cache->hash_table = NULL; n_dims = cache->n_dimensions; for_less( dim, 0, n_dims ) @@ -1246,7 +1271,12 @@ block accessed */ if( block_index == cache->previous_block_index ) + { +#ifdef CACHE_DEBUGGING + record_cache_prev_hit( cache ); +#endif return( cache->previous_block ); + } /*--- search the hash table for the block index */ @@ -1263,6 +1293,10 @@ if( block == NULL ) { +#ifdef CACHE_DEBUGGING + record_cache_no_hit( cache ); +#endif + /*--- find a block to use */ block = appropriate_a_cache_block( cache, volume ); @@ -1298,6 +1332,10 @@ } else /*--- block was found in hash table */ { +#ifdef CACHE_DEBUGGING + record_cache_hit( cache ); +#endif + /*--- move block to head of used list */ if( block != cache->head ) @@ -1445,3 +1483,104 @@ { return( cache->minc_file != NULL ); } + +public BOOLEAN volume_is_cached( + Volume volume ) +{ + return( volume->is_cached_volume ); +} + +#ifndef CACHE_DEBUGGING +/* ARGSUSED */ +#endif + +public void set_volume_cache_debugging( + Volume volume, + int output_every ) +{ +#ifdef CACHE_DEBUGGING + if( output_every >= 1 ) + { + volume->cache.debugging_on = TRUE; + volume->cache.output_every = output_every; + } + else + { + volume->cache.debugging_on = FALSE; + } +#endif +} + +#ifdef CACHE_DEBUGGING + +private void initialize_cache_debug( + volume_cache_struct *cache ) +{ + int output_every; + STRING debug; + + debug = getenv( "VOLUME_CACHE_DEBUG" ); + + cache->debugging_on = (debug != NULL); + + if( debug == NULL || sscanf( debug, "%d", &output_every ) != 1 || + output_every < 1 ) + { + output_every = 1000; + } + + cache->output_every = output_every; + cache->n_accesses = 0; + cache->n_hits = 0; + cache->n_prev_hits = 0; +} + +private void increment_n_accesses( + volume_cache_struct *cache ) +{ + ++cache->n_accesses; + + if( cache->n_accesses >= cache->output_every ) + { + print( "Volume cache: Hit ratio: %g Prev ratio: %g\n", + (Real) (cache->n_hits + cache->n_prev_hits) / + (Real) cache->n_accesses, + (Real) cache->n_prev_hits / + (Real) cache->n_accesses ); + + cache->n_accesses = 0; + cache->n_hits = 0; + cache->n_prev_hits = 0; + } +} + +private void record_cache_hit( + volume_cache_struct *cache ) +{ + if( cache->debugging_on ) + { + ++cache->n_hits; + increment_n_accesses( cache ); + } +} + +private void record_cache_prev_hit( + volume_cache_struct *cache ) +{ + if( cache->debugging_on ) + { + ++cache->n_prev_hits; + increment_n_accesses( cache ); + } +} + +private void record_cache_no_hit( + volume_cache_struct *cache ) +{ + if( cache->debugging_on ) + { + increment_n_accesses( cache ); + } +} + +#endif
--- a/volume_io/Volumes/volumes.c +++ b/volume_io/Volumes/volumes.c @@ -17,7 +17,7 @@ #include <float.h> #ifndef lint -static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/volumes.c,v 1.59 1996-02-08 17:40:14 david Exp $"; +static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/volumes.c,v 1.60 1996-02-27 15:11:23 david Exp $"; #endif STRING XYZ_dimension_names[] = { MIxspace, MIyspace, MIzspace }; @@ -711,9 +711,9 @@ { axis = N_DIMENSIONS - axis_list[0] - axis_list[1]; - create_orthogonal_vector( &directions[(axis+1) % N_DIMENSIONS], - &directions[(axis+2) % N_DIMENSIONS], - &directions[axis] ); + CROSS_VECTORS( directions[axis], + directions[(axis+1) % N_DIMENSIONS], + directions[(axis+2) % N_DIMENSIONS] ); } if( EQUAL_VECTORS( directions[0], directions[1] ) ||