/* Cconvolution.cpp */ #include "defs.h" //function prototypes int load_kernels(MONO_KERNELS *, char []); int load_geometry(FLOAT_GRID *, char []); int pop_beam(BEAM *, FILE *); int calc_deff(FLOAT_GRID *,FLOAT_GRID *, FLOAT_GRID *, BEAM *); int terma_kerma(FLOAT_GRID *,FLOAT_GRID *,FLOAT_GRID *,MONO_KERNELS *,FLOAT_GRID *); int make_poly_kernel(MONO_KERNELS *, KERNEL *); int calc_dose(FLOAT_GRID *,FLOAT_GRID *,FLOAT_GRID *,KERNEL *,BEAM *, FLOAT_GRID *); int terma_dose_masks(FLOAT_GRID *, FLOAT_GRID *, BEAM *); int convolution(MONO_KERNELS *, BEAM *, FLOAT_GRID *, FILE *); char errstr[200]; // error string that all routines have access to int main(int argc, char *argv[]) // Expects four input arguments: // 1) kernel_filenames -- contains a list of the kernel files // 2) geometry_filenames -- contains a list of the geometry files // 3) beamspec batch file -- locations of beamspec files in batch // 4) beamlet batch file -- locations of resulting beamlets in batch { int i,j,b,B; char tmpstr[200]; FLOAT_GRID density; MONO_KERNELS mono_kernels; BEAM beam; FILE *beamspec_batch_file; FILE *beamlet_batch_file; /* // print the arguments printf("Input arguments:\n"); for (j=1;jx_count; N = density->y_count; Q = density->z_count; Ntotal = M*N*Q; // Allocate memory for all of the grids and fill them all with zeros if ((terma_mask.matrix = (float *)malloc(sizeof(float)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for terma_mask."); return(FAILURE); } if ((dose_mask.matrix = (float *)malloc(sizeof(float)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for dose_mask."); return(FAILURE); } if ((deff.matrix = (float *)malloc(sizeof(float)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for deff."); return(FAILURE); } if ((terma.matrix = (float *)malloc(sizeof(float)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for terma."); return(FAILURE); } if ((kermac.matrix = (float *)malloc(sizeof(float)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for kermac."); return(FAILURE); } if ((dose.matrix = (float *)malloc(sizeof(float)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for dose."); return(FAILURE); } for (i=0;imatrix,sizeof(float),Ntotal,fid); fclose(fid); */ // find maximum dose doseMax = 0.0; for (i=0;i doseMax) doseMax = dose.matrix[i]; // count the number of non-zero dose values Nind = 0; for (i=0;i= doseMax*doseCutoffThreshold && dose.matrix[i] > 0.0) Nind++; else dose.matrix[i] = 0.0; // turn off doses below threshold // allocate memory for sparse dose data dose_ind = (int *)malloc(sizeof(int)*Nind); dose_data = (float *)malloc(sizeof(float)*Nind); // store the sparse data j = 0; // index just for the sparse data for (i=0;i= doseMax*doseCutoffThreshold && dose.matrix[i] > 0.0) { dose_ind[j] = i; dose_data[j] = dose.matrix[i]; j++; } // save dose to a file // save the total file size first, then the number of non-zero elements fwrite(&beam->num,sizeof(int),1,beamlet_batch_file); fwrite(&M,sizeof(int),1,beamlet_batch_file); fwrite(&N,sizeof(int),1,beamlet_batch_file); fwrite(&Q,sizeof(int),1,beamlet_batch_file); fwrite(&Nind,sizeof(int),1,beamlet_batch_file); fwrite(dose_ind,sizeof(int),Nind,beamlet_batch_file); fwrite(dose_data,sizeof(float),Nind,beamlet_batch_file); free(dose_ind); free(dose_data); // free the calculation grids free(terma_mask.matrix); free(dose_mask.matrix); free(deff.matrix); free(terma.matrix); free(kermac.matrix); free(dose.matrix); free(poly_kernel.angular_boundary); free(poly_kernel.radial_boundary); // free(poly_kernel.total_matrix); for (j=0;j