lsq.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* sim_ann.h contains the structures and definitions for simulated
  2. annealing optimisation */
  3. /* RJ 12 September 2000 */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8. #include <malloc.h>
  9. #include <time.h>
  10. #include <memory.h>
  11. #define SUCCESS 1
  12. #define FAILURE 0
  13. #define Ndvh_bins 1000 // number of bins to use for the calculation of all dvhs
  14. #define SMARTBEAMLETS 1 // if "1", beamlet voxels that are not used in the optimization
  15. // are not loaded, but the full beamlets must be reloaded every
  16. // time the dose distribution is written to file.
  17. typedef struct
  18. {
  19. int x_count;
  20. int y_count;
  21. int z_count;
  22. int Nvox;
  23. float *matrix;
  24. } GRID;
  25. typedef struct
  26. {
  27. int size;
  28. int *indices;
  29. float *data;
  30. } SPARSE_ARRAY;
  31. typedef struct
  32. {
  33. int num_beamlets;
  34. int num_beamlet_batches;
  35. int x_count;
  36. int y_count;
  37. int z_count;
  38. int Nvox; // number of voxels
  39. float *beam_weight;
  40. float *initial_beam_weight;
  41. SPARSE_ARRAY *array;
  42. } GRID_ARRAY;
  43. typedef struct
  44. {
  45. int Nbins; // number of dose bins
  46. float del_d; // spacing between dose bins
  47. float dmax; // maximum dose bin boundary in the dvh
  48. float del_d_plus; // dose between the dVPlus threshold and the actual DVH
  49. float del_d_minus; // dose between the dVMinus threshold and the actual DVH
  50. float dvh[Ndvh_bins]; // dvh itself
  51. } DVH;
  52. typedef struct
  53. {
  54. char name[100];
  55. float alpha; // tissue importance factor
  56. DVH dvh; // dvh structure
  57. // DVH overdose penalty factors
  58. float betaVPlus; // importance of dvh plus penalty term
  59. float dVPlus;
  60. float vPlus;
  61. // DVH underdose penalty factors
  62. float betaVMinus; // importance of dvh minus penalty term
  63. float dVMinus;
  64. float vMinus;
  65. char dosePlusFilename[200]; // name of the file that contains overdose penalty information
  66. char doseMinusFilename[200]; // name of the file that contains underdose penalty information
  67. // mask indices
  68. int Nind; // number of indices in the tissue mask
  69. int *ind; // indices in which there is a non-zero dose prescription
  70. float betaPlus; // overdose penalty weighting factor
  71. float *dPlus; // overdose penalty dose threshold
  72. float betaMinus; // underdose penalty weighting factor
  73. float *dMinus; // underdose penalty weighting factor
  74. } TISSUE;
  75. typedef struct
  76. {
  77. int tissueInd; // index of prescription tissue being represented
  78. float dPlus; // overdose penalty threshold
  79. float dMinus; // underdose penalty threshold
  80. } PRESCNODE;
  81. typedef struct
  82. {
  83. // grid dimensions
  84. int x_count;
  85. int y_count;
  86. int z_count;
  87. int Nvox; // total number of voxels (just x_count*y_count*z_count)
  88. // the two following grids have the above dimensions
  89. PRESCNODE **array; // grid full of prescnode arrays
  90. int *numNodes; // number of prescnodes at each point in grid
  91. } PRESCGRID;
  92. typedef struct
  93. {
  94. int Niterations;
  95. int Nperbatch;
  96. float modFactor;
  97. char prescription_filename[200];
  98. char initial_beam_weights_filename[200];
  99. char beamlet_header_file[200];
  100. char dose_batch_base_name[200];
  101. char dose_batch_extension[200];
  102. char weight_batch_base_name[200];
  103. char weight_batch_extension[200];
  104. char obj_func_name[200];
  105. char bix_dir[200]; // directory containing beamlet batches
  106. char bix_batch_base_filename[200];
  107. char bix_batch_extension[200];
  108. } OPT_PARAM; // optimization parameters
  109. typedef struct
  110. {
  111. int Ntissue; // number of tissue types
  112. int x_count; // dimensions of the tissue grids
  113. int y_count;
  114. int z_count;
  115. int Nvox;
  116. TISSUE *array; // array of tissue prescription structures
  117. } PRESC;
  118. // function prototypes
  119. int read_in_opt_parameters(OPT_PARAM *, char *);
  120. int read_in_beamlets(GRID_ARRAY *, char *, char *, int *, OPT_PARAM *, GRID *);
  121. int read_in_prescription(PRESC *, char *);
  122. int calculate_dose_diff(GRID_ARRAY *, float, int, GRID *);
  123. int calculate_dose(GRID_ARRAY *, GRID *);
  124. int output_dose_weights(GRID_ARRAY *, GRID *, char *, char *);
  125. int calc_update_factor(GRID_ARRAY *, GRID *, PRESC *, int, float *,PRESCGRID *);
  126. int calc_dvh(GRID *, int, int *, DVH *);
  127. float calc_obj_func(GRID_ARRAY *, GRID *, PRESC *);
  128. int compare(void *, void *);
  129. int calcAllDvhs(GRID *, PRESC *);
  130. int find_used_voxels(PRESC *, int *);
  131. int fillPrescriptionGrid(PRESC *, PRESCGRID *);
  132. int loadBeamletsCalcDose(OPT_PARAM *, GRID *, GRID_ARRAY *);
  133. int truncateBeamWeights(float *, int, float);