1
0

calc_deff.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* calc_deff.cpp */
  2. /* Calculates the effective depth of each voxel in the tumor mask. */
  3. #include "defs.h"
  4. extern char errstr[200]; // error string that all routines have access to
  5. //prototype for Siddon raytrace routine (point to point)
  6. int raytrace(FLOAT_GRID *,FLOAT_GRID *,POINT,POINT);
  7. int calc_deff(FLOAT_GRID *dens, FLOAT_GRID *deff, FLOAT_GRID *terma_mask, BEAM *bm)
  8. {
  9. int i, j, k;
  10. // points that will be used for raytrace operation
  11. POINT p1;
  12. POINT p2;
  13. // Raytracing is only done for voxels that non-zero in the terma_mask.
  14. //initialize deff, with -1 signifying voxels of interest in the raytrace
  15. for (k=0;k<deff->z_count;k++)
  16. for (j=0;j<deff->y_count;j++)
  17. for (i=0;i<deff->x_count;i++)
  18. // we only care about voxels for which the terma_mask is positive
  19. if (GRID_VALUE(terma_mask,i,j,k) > 0)
  20. GRID_VALUE(deff,i,j,k) = -1.0;
  21. // Set the x-ray origin to the the source location
  22. p1.x = bm->y_vec[0];
  23. p1.y = bm->y_vec[1];
  24. p1.z = bm->y_vec[2];
  25. // calculate the radiological depth for all voxels in the terma_mask
  26. for (k=0;k<deff->z_count;k++)
  27. for (j=0;j<deff->y_count;j++)
  28. for (i=0;i<deff->x_count;i++)
  29. if (GRID_VALUE(deff,i,j,k) == -1.0)
  30. {
  31. // The start location is the center of the voxel at (i,j,k).
  32. // Since raytrace works with voxel sides rather than centers,
  33. // need to shift the input by half a voxel in the negative
  34. // direction for each voxel dimension.
  35. p2.x = deff->start.x + ((float) i)*deff->inc.x;
  36. p2.y = deff->start.y + ((float) j)*deff->inc.y;
  37. p2.z = deff->start.z + ((float) k)*deff->inc.z;
  38. // extend the ray by a factor of 10 to include more voxels in the raytrace
  39. p2.x = p1.x + (p2.x-p1.x)*(float)10.0;
  40. p2.y = p1.y + (p2.y-p1.y)*(float)10.0;
  41. p2.z = p1.z + (p2.z-p1.z)*(float)10.0;
  42. // do the raytrace, filling in voxels that are passed on the way
  43. raytrace(dens,deff,p1,p2);
  44. }
  45. return(SUCCESS);
  46. }