defs.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* defs.h */
  2. // libraries that will be needed throughout
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <math.h>
  7. #include <malloc.h>
  8. #define MAX_KERNELS 50 //max number of monoenergetic kernels to use for creating polyenergetic kernel
  9. #define N_KERNEL_RADII 24 //number of radial increments in mono kernels
  10. #define N_KERNEL_ANGLES 48 //number of angular increments in mono kernels
  11. #define N_KERNEL_CATEGORIES 5 //number of kernel categories (primary, first scatter...)
  12. #define SOI 17
  13. // upsample factors to determine insideness for voxels on aperture edge:
  14. #define Mus 5
  15. #define Nus 5
  16. #define Qus 5
  17. #define SUCCESS 1
  18. #define FAILURE 0
  19. #define RSAFE 2.0 // safety margin for dose_mask calculation in cm
  20. #define PI 3.14152654
  21. #define Y_DOSE_EXTENT 8.0 //optionally only calculate this many cm in y-direction (commented out in calc_dose)
  22. #define NPHI 12 //number of azimuthal angles for convolution
  23. // #define DELR 0.4 //radial increments for convolution (adaptive to the problem now, in calc_dose)
  24. #define NTHETA 6 //number of polar angles for convolution (must divide evenly into N_KERNEL_ANGLES)
  25. /* #define NPHI 12 //number of azimuthal angles for convolution
  26. #define DELR 0.1 //radial increments for convolution
  27. #define NTHETA 12 //number of polar angles for convolution (must divide evenly into N_KERNEL_ANGLES) */
  28. #define MAXX(x,y) ((x) > (y) ? (x) : (y))
  29. //each kernel file contains 7 entries per voxel, the first five are these categores
  30. typedef enum
  31. {
  32. primary_,
  33. first_scatter_,
  34. second_scatter_,
  35. multiple_scatter_,
  36. brem_annih_
  37. } KERNEL_CATEGORIES;
  38. typedef struct
  39. {
  40. float x;
  41. float y;
  42. float z;
  43. } POINT;
  44. //standard float precision grid structure, with dynamically allocated matrix
  45. //used for density, deff, terma, kerma, dose
  46. typedef struct
  47. {
  48. POINT start;
  49. POINT inc;
  50. int x_count;
  51. int y_count;
  52. int z_count;
  53. float *matrix;
  54. } FLOAT_GRID;
  55. //macro to access grid values
  56. #define GRID_VALUE(GRID_ptr, i, j, k)\
  57. ((GRID_ptr)->matrix[(i) +\
  58. (GRID_ptr)->x_count *\
  59. ((j) + ((k) * (GRID_ptr)->y_count))])
  60. // macro for 3D dot products
  61. #define DOT3D(vec1,vec2) ((vec1[0])*(vec2[0])+(vec1[1])*(vec2[1])+(vec1[2])*(vec2[2]))
  62. //kernel structure for each monoenergetic kernel and the polyenergetic kernel
  63. typedef struct
  64. {
  65. int nradii;
  66. int ntheta;
  67. float *radial_boundary;
  68. float *angular_boundary;
  69. float *matrix[N_KERNEL_CATEGORIES]; //kernel values for each category
  70. float *total_matrix; //sum of all categories (used for current convolution)
  71. } KERNEL;
  72. //macros for accessing kernel values
  73. #define KERNEL_VALUE(kern_ptr,category,i,j) \
  74. (kern_ptr)->matrix[category][(i) + (j)*(kern_ptr)->nradii]
  75. #define KERNEL_TOTAL_VALUE(kern_ptr,i,j) \
  76. (kern_ptr)->total_matrix[(i) + (j)*(kern_ptr)->nradii]
  77. //infor and array of KERNEL structures for monoenergetic kernels
  78. typedef struct
  79. {
  80. int nkernels;
  81. float *energy;
  82. float *fluence;
  83. float *mu;
  84. float *mu_en;
  85. KERNEL kernel[MAX_KERNELS];
  86. } MONO_KERNELS;
  87. //beam description (center and size)
  88. typedef struct
  89. {
  90. float ip[3]; // first aperture center vector
  91. float jp[3]; // second aperture center vector
  92. float kp[3]; // source direction vector
  93. float y_vec[3]; // source location vector
  94. // aperture parameters
  95. float xp;
  96. float yp;
  97. float del_xp; // aperture width in ip direction
  98. float del_yp; // aperture width in jp direction
  99. // source-axis distance (leave here for now because to ubiquitous)
  100. float SAD;
  101. // beam number to avoid ambiguity
  102. int num;
  103. } BEAM;
  104. /* Prototypes of utility functions */
  105. float *fvector(int nl, int nh);
  106. float **fmatrix(int nrl, int nrh, int ncl, int nch);
  107. void free_fvector(float *v, int nl, int nh);
  108. void free_fmatrix(float **m, int nrl, int nrh, int ncl, int nch);
  109. int copy_grid_geometry(FLOAT_GRID *, FLOAT_GRID *);
  110. int binSearch(float *, float, int);
  111. void nrerror(char error_text[]);