Mercurial > hg > minc-tools
changeset 998:390e1f4af608
check_in_all
author | david <david> |
---|---|
date | Thu, 11 Apr 1996 19:01:27 +0000 |
parents | 1631ee70f0d3 |
children | a3bece5b4a6b |
files | volume_io/Documentation/volume_io.tex volume_io/Volumes/evaluate.c |
diffstat | 2 files changed, 61 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/volume_io/Documentation/volume_io.tex +++ b/volume_io/Documentation/volume_io.tex @@ -2071,6 +2071,18 @@ derivative arguments are non-null, then the resulting derivatives are placed in the appropriate places.} +{\bf\begin{verbatim} +public void set_volume_interpolation_tolerance( + Real tolerance ) +\end{verbatim}} + +\desc{For speed considerations, if a volume is evaluated at or near a voxel +centre, then no interpolation is performed, and the voxel value is returned. +The tolerance defines how close to the voxel centre this occurs, and defaults +to 0. Note that if derivatives are desired and the degree of continuity +specified is 0 or greater, then interpolation will be performed, even when +within the specified tolerance of the voxel.} + \section{Volume Creation from Scratch} In some circumstances, it is desirable to create volumes in ways
--- a/volume_io/Volumes/evaluate.c +++ b/volume_io/Volumes/evaluate.c @@ -15,7 +15,7 @@ #include <internal_volume_io.h> #ifndef lint -static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/evaluate.c,v 1.28 1996-01-15 17:37:54 david Exp $"; +static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/evaluate.c,v 1.29 1996-04-11 19:01:29 david Exp $"; #endif /* ----------------------------- MNI Header ----------------------------------- @@ -651,6 +651,29 @@ } } +static Real interpolation_tolerance = 0.0; + +/* ----------------------------- MNI Header ----------------------------------- +@NAME : set_volume_interpolation_tolerance +@INPUT : tolerance +@OUTPUT : +@RETURNS : +@DESCRIPTION: Sets the tolerance which defines how close to a voxel centre we + must be in order to just pass back the voxel value, rather than + interpolating. +@METHOD : +@GLOBALS : +@CALLS : +@CREATED : Apr. 11, 1996 David MacDonald +@MODIFIED : +---------------------------------------------------------------------------- */ + +public void set_volume_interpolation_tolerance( + Real tolerance ) +{ + interpolation_tolerance = tolerance; +} + /* ----------------------------- MNI Header ----------------------------------- @NAME : evaluate_volume @INPUT : volume @@ -707,7 +730,7 @@ int n_coefs; Real fraction[MAX_DIMENSIONS], bound, *coefs, pos; Real fixed_size_coefs[MAX_COEF_SPACE]; - BOOLEAN fully_inside, fully_outside; + BOOLEAN fully_inside, fully_outside, on_grid_point; n_dims = get_volume_n_dimensions(volume); @@ -744,6 +767,30 @@ get_volume_sizes( volume, sizes ); + /*--- check if we are near a voxel centre, if so just use nearest neighbour + and avoid the expensive interpolation, unless we need derivatives */ + + if( interpolation_tolerance > 0.0 && + first_deriv == NULL && second_deriv == NULL ) + { + on_grid_point = TRUE; + for_less( d, 0, n_dims ) + { + if( interpolating_dimensions == NULL || interpolating_dimensions[d]) + { + pos = (Real) ROUND( voxel[d] ); + if( voxel[d] < pos - interpolation_tolerance || + voxel[d] > pos + interpolation_tolerance ) + { + on_grid_point = FALSE; + break; + } + } + } + if( on_grid_point ) + degrees_continuity = -1; + } + bound = (Real) degrees_continuity / 2.0; /*--- if we must use linear interpolation near the boundaries, then