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

resample.c

Go to the documentation of this file.
00001 #include <volume_io/internal_volume_io.h> 00002 #include <bicpl/vols.h> 00003 00004 public void initialize_resample_volume( 00005 resample_struct *resample, 00006 Volume src_volume, 00007 General_transform *dest_to_src_transform, 00008 Volume dest_volume ) 00009 { 00010 General_transform inverse, tmp; 00011 00012 resample->src_volume = src_volume; 00013 resample->dest_volume = dest_volume; 00014 resample->x = 0; 00015 resample->y = 0; 00016 00017 copy_general_transform( get_voxel_to_world_transform(dest_volume), 00018 &resample->transform ); 00019 00020 if( dest_to_src_transform != (General_transform *) NULL ) 00021 { 00022 create_inverse_general_transform( dest_to_src_transform, &inverse ); 00023 00024 concat_general_transforms( &resample->transform, &inverse, &tmp ); 00025 delete_general_transform( &resample->transform ); 00026 resample->transform = tmp; 00027 } 00028 00029 create_inverse_general_transform( get_voxel_to_world_transform(src_volume), 00030 &inverse ); 00031 00032 concat_general_transforms( &resample->transform, &inverse, &tmp ); 00033 delete_general_transform( &resample->transform ); 00034 resample->transform = tmp; 00035 } 00036 00037 public BOOLEAN do_more_resampling( 00038 resample_struct *resample, 00039 Real max_seconds, 00040 Real *fraction_done ) 00041 { 00042 Real value; 00043 BOOLEAN linear; 00044 Vector z_axis; 00045 int z; 00046 Real xv, yv, zv, voxel[MAX_DIMENSIONS]; 00047 Real end_time; 00048 int dest_sizes[MAX_DIMENSIONS], src_sizes[MAX_DIMENSIONS]; 00049 00050 if( max_seconds >= 0.0 ) 00051 end_time = current_realtime_seconds() + max_seconds; 00052 00053 get_volume_sizes( resample->dest_volume, dest_sizes ); 00054 get_volume_sizes( resample->src_volume, src_sizes ); 00055 00056 linear = get_transform_type( &resample->transform ) == LINEAR; 00057 if( linear ) 00058 { 00059 get_transform_z_axis( get_linear_transform_ptr(&resample->transform), 00060 &z_axis ); 00061 } 00062 00063 while( resample->x < dest_sizes[X] ) 00064 { 00065 for_less( z, 0, dest_sizes[Z] ) 00066 { 00067 if( !linear || z == 0 ) 00068 general_transform_point( &resample->transform, 00069 (Real) resample->x, 00070 (Real) resample->y, 00071 (Real) z, 00072 &xv, &yv, &zv ); 00073 00074 voxel[X] = xv; 00075 voxel[Y] = yv; 00076 voxel[Z] = zv; 00077 evaluate_volume( resample->src_volume, voxel, NULL, 0, FALSE, 00078 get_volume_real_min(resample->src_volume), 00079 &value, NULL, NULL ); 00080 00081 set_volume_real_value( resample->dest_volume, 00082 resample->x, resample->y, z, 0, 0, value ); 00083 00084 if( linear ) 00085 { 00086 xv += (Real) Vector_x(z_axis); 00087 yv += (Real) Vector_y(z_axis); 00088 zv += (Real) Vector_z(z_axis); 00089 } 00090 } 00091 00092 ++resample->y; 00093 if( resample->y >= dest_sizes[Y] ) 00094 { 00095 resample->y = 0; 00096 ++resample->x; 00097 } 00098 00099 if( max_seconds >= 0.0 && current_realtime_seconds() > end_time ) 00100 break; 00101 } 00102 00103 *fraction_done = (Real) (resample->x * dest_sizes[Y] + resample->y) / 00104 (Real) dest_sizes[Y] / (Real) dest_sizes[X]; 00105 00106 return( resample->x < dest_sizes[X] ); 00107 } 00108 00109 public void resample_volume( 00110 Volume src_volume, 00111 General_transform *dest_to_src_transform, 00112 Volume dest_volume ) 00113 { 00114 static const int FACTOR = 1000; 00115 resample_struct resample; 00116 Real amount_done; 00117 progress_struct progress; 00118 00119 initialize_resample_volume( &resample, src_volume, dest_to_src_transform, 00120 dest_volume ); 00121 00122 initialize_progress_report( &progress, FALSE, FACTOR, "Resampling" ); 00123 00124 while( do_more_resampling( &resample, 5.0, &amount_done ) ) 00125 { 00126 update_progress_report( &progress, ROUND(amount_done*(Real)FACTOR) ); 00127 } 00128 00129 terminate_progress_report( &progress ); 00130 }

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