RDXTPS_exportPinnGrid4Tomo.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. function RDXTPS_exportPinnGrid4Tomo (Geometry, optResults)
  2. %RDXTPS_EXPORTPINNGRID4TOMO Export CT or dose grid to Pinnacle format for Tomo import
  3. % RDXTPS_exportPinnGrid4Tomo write the *.header and *.img pair in Pinnacle
  4. % format which can be imported into research version of Tomo TPS.
  5. %
  6. % Example:
  7. % RDXTPS_exportPinnGrid4Tomo(Geometry, optResults)
  8. %
  9. % See also N/A
  10. %
  11. % Copyright Nobody
  12. [filename, pathname] = uifile('put', '*', 'Save the export CT image as (without extension)');
  13. ct_filebase = fullfile(pathname, filename);
  14. % Write CT grid
  15. fid = fopen([ct_filebase '.img'], 'w');
  16. fwrite(fid, apply_transformation(Geometry.data), 'short');
  17. fclose(fid);
  18. % Write CT header
  19. fid = fopen([ct_filebase '.header'], 'w');
  20. fprintf(fid, 'read_conversion : \n');
  21. fprintf(fid, 'write_conversion : \n');
  22. fprintf(fid, 'data_type : short\n');
  23. fprintf(fid, 'byte_order = 0\n');
  24. fprintf(fid, 'bytes_pix = 2\n');
  25. fprintf(fid, 'vol_min = \n');
  26. fprintf(fid, 'vol_max = \n');
  27. fprintf(fid, 'x_dim = %d\n', size(Geometry.rhomw, 1));
  28. fprintf(fid, 'y_dim = %d\n', size(Geometry.rhomw, 2));
  29. fprintf(fid, 'z_dim = %d\n', size(Geometry.rhomw, 3));
  30. fprintf(fid, 'dim_units : \n');
  31. fprintf(fid, 'x_pixdim = %f\n', Geometry.voxel_size(1));
  32. fprintf(fid, 'y_pixdim = %f\n', Geometry.voxel_size(2));
  33. fprintf(fid, 'z_pixdim = %f\n', Geometry.voxel_size(3));
  34. fprintf(fid, 'x_start = %f\n', Geometry.start(1));
  35. fprintf(fid, 'y_start = %f\n', Geometry.start(2));
  36. fprintf(fid, 'z_start = %f\n', Geometry.start(3));
  37. fprintf(fid, 'date : \n');
  38. fprintf(fid, 'db_name : \n');
  39. fclose(fid);
  40. % Repeat for dose
  41. [filename, pathname] = uifile('put', '*', 'Save the export dose image as (without extension)');
  42. dose_filebase = fullfile(pathname, filename);
  43. % Write dose grid
  44. fid = fopen([dose_filebase '.img'], 'w');
  45. fwrite(fid, apply_transformation(optResults.dose{end}), 'single');
  46. fclose(fid);
  47. % Write dose header
  48. fid = fopen([dose_filebase '.header'], 'w');
  49. fprintf(fid, 'read_conversion : \n');
  50. fprintf(fid, 'write_conversion : \n');
  51. fprintf(fid, 'data_type : float\n');
  52. fprintf(fid, 'byte_order = 0\n');
  53. fprintf(fid, 'bytes_pix = 4\n');
  54. fprintf(fid, 'vol_min = \n');
  55. fprintf(fid, 'vol_max = \n');
  56. fprintf(fid, 'x_dim = %d\n', size(Geometry.rhomw, 1));
  57. fprintf(fid, 'y_dim = %d\n', size(Geometry.rhomw, 2));
  58. fprintf(fid, 'z_dim = %d\n', size(Geometry.rhomw, 3));
  59. fprintf(fid, 'dim_units : \n');
  60. fprintf(fid, 'x_pixdim = %f\n', Geometry.voxel_size(1));
  61. fprintf(fid, 'y_pixdim = %f\n', Geometry.voxel_size(2));
  62. fprintf(fid, 'z_pixdim = %f\n', Geometry.voxel_size(3));
  63. fprintf(fid, 'x_start = %f\n', Geometry.start(1));
  64. fprintf(fid, 'y_start = %f\n', Geometry.start(2));
  65. fprintf(fid, 'z_start = %f\n', Geometry.start(3));
  66. fprintf(fid, 'date : \n');
  67. fprintf(fid, 'db_name : \n');
  68. fclose(fid);
  69. % Apply appropriate transformation to fit Pinnacle format to input matrix M
  70. function M = apply_transformation(M)
  71. for i = 1:size(M, 3)
  72. M(:,:,i) = rot90(M(:,:,i), 1);
  73. end
  74. M = flipdim(M, 3);
  75. end
  76. end