matlab2amira.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. % creates mask files for plotting in Amira
  2. load GeometryProstate.mat; % geometry file of interest
  3. amira_folder = 'amira2'; % folder for Amira data
  4. amira_file = 'prostateBoost.hx';
  5. curr_dir = pwd; % current directory
  6. mkdir(amira_folder); % create the amira folder
  7. cd(amira_folder); % go to amira folder
  8. Nroi = length(Geometry.ROIS); % get number of ROIS from Geometry structure
  9. % icon position vectors
  10. xIcon = [0:2]*200 + 50;
  11. yIcon = [0:1]*50;
  12. yShift = [0:Nroi]*120 + 400;
  13. % get the names of the rois
  14. roi_names = cell(1,Nroi);
  15. for k=1:Nroi
  16. roi_names{k} = Geometry.ROIS{k}.name;
  17. end
  18. % set up a mask structure
  19. mask.start = Geometry.start;
  20. mask.voxel_size = Geometry.voxel_size;
  21. siz = size(Geometry.data); % mask dimensions
  22. % create the Amira .hx file
  23. fid = fopen(amira_file,'w');
  24. fprintf(fid,'# Amira Script\n');
  25. fprintf(fid,'remove -all\n');
  26. fprintf(fid,['remove physics.icol glow.col dose.am BoundingBox OrthoSlice0 OrthoSlice1 OrthoSlice2 Colorwash0 Colorwash1 Colorwash2 Isolines0 Isolines1 Isolines2 GlobalAxis CastField\n']);
  27. fprintf(fid,'\n');
  28. % viewer parameters
  29. fprintf(fid,'# Create viewers\n');
  30. fprintf(fid,'viewer setVertical 0\n');
  31. fprintf(fid,'\n');
  32. fprintf(fid,'viewer 0 setBackgroundMode 1\n');
  33. fprintf(fid,'viewer 0 setBackgroundColor 0.06 0.13 0.24\n');
  34. fprintf(fid,'viewer 0 setBackgroundColor2 0.72 0.72 0.78\n');
  35. fprintf(fid,'viewer 0 setTransparencyType 5\n');
  36. fprintf(fid,'viewer 0 setAutoRedraw 0\n');
  37. fprintf(fid,'viewer 0 show\n');
  38. fprintf(fid,'mainWindow show\n');
  39. fprintf(fid,'\n');
  40. % create files for each mask region
  41. for k=1:Nroi
  42. mask_filename = [roi_names{k} '.am'];
  43. mask_filename = regexprep(mask_filename,' ',''); % remove spaces
  44. mask.data = zeros(siz,'int8');
  45. mask.data(Geometry.ROIS{k}.ind) = 1; % fill in the mask
  46. geom2am(mask,mask_filename); % save the structure to an Amira file
  47. fprintf(fid,'set hideNewModules 0\n');
  48. fprintf(fid,['[ load ${SCRIPTDIR}/' mask_filename ' ] setLabel ' mask_filename '\n']);
  49. fprintf(fid,[mask_filename ' setIconPosition ' num2str(xIcon(1)) ' ' num2str(yIcon(1)+yShift(k)) '\n']);
  50. fprintf(fid,[mask_filename ' fire\n']);
  51. fprintf(fid,[mask_filename ' fire\n']);
  52. fprintf(fid,[mask_filename ' setViewerMask 65535\n']);
  53. fprintf(fid,'\n');
  54. % set up a CastField module for a LabelField for the mask
  55. fprintf(fid,'set hideNewModules 0\n');
  56. castFieldName = ['CastField' num2str(k)];
  57. fprintf(fid,['create HxCastField {' castFieldName '}\n']);
  58. fprintf(fid,[castFieldName ' setIconPosition ' num2str(xIcon(2)) ' ' num2str(yIcon(1)+yShift(k)) '\n']);
  59. fprintf(fid,[castFieldName ' data connect ' mask_filename '\n']);
  60. fprintf(fid,[castFieldName ' colormap setDefaultColor 1 0.8 0.5\n']);
  61. fprintf(fid,[castFieldName ' colormap setDefaultAlpha 0.500000\n']);
  62. fprintf(fid,[castFieldName ' fire\n']);
  63. fprintf(fid,[castFieldName ' outputType setValue 0 6\n']);
  64. fprintf(fid,[castFieldName ' scaling setMinMax 0 -1.00000001384843e+024 1.00000001384843e+024\n']);
  65. fprintf(fid,[castFieldName ' scaling setValue 0 1\n']);
  66. fprintf(fid,[castFieldName ' scaling setMinMax 1 -1.00000001384843e+024 1.00000001384843e+024\n']);
  67. fprintf(fid,[castFieldName ' scaling setValue 1 0\n']);
  68. fprintf(fid,[castFieldName ' voxelGridOptions setValue 0 1\n']);
  69. fprintf(fid,[castFieldName ' colorFieldOptions setValue 0 0\n']);
  70. fprintf(fid,[castFieldName ' fire\n']);
  71. fprintf(fid,[castFieldName ' setViewerMask 65535\n']);
  72. fprintf(fid,[castFieldName ' deselect\n']);
  73. fprintf(fid,'\n');
  74. % set up mask plotting routines
  75. mask_labelfield_name = regexprep(mask_filename,'am','Labelfield');
  76. fprintf(fid,'set hideNewModules 0\n');
  77. fprintf(fid,['[ {' castFieldName '} create\n']);
  78. fprintf(fid,[' ] setLabel {' mask_labelfield_name '}\n']);
  79. fprintf(fid,[mask_labelfield_name ' setIconPosition ' num2str(xIcon(1)) ' ' num2str(yIcon(2)+yShift(k)) '\n']);
  80. fprintf(fid,[mask_labelfield_name ' master connect ' castFieldName '\n']);
  81. fprintf(fid,[mask_labelfield_name ' fire\n']);
  82. fprintf(fid,[mask_labelfield_name ' primary setValue 0 0\n']);
  83. fprintf(fid,[mask_labelfield_name ' fire\n']);
  84. fprintf(fid,[mask_labelfield_name ' setViewerMask 65535\n']);
  85. fprintf(fid,'\n');
  86. surfaceGenName = ['SurfaceGen' num2str(k)];
  87. fprintf(fid,'set hideNewModules 0\n');
  88. fprintf(fid,['create HxGMC {' surfaceGenName '}\n']);
  89. fprintf(fid,[surfaceGenName ' setIconPosition ' num2str(xIcon(3)) ' ' num2str(yIcon(1)+yShift(k)) '\n']);
  90. fprintf(fid,[surfaceGenName ' data connect ' mask_labelfield_name '\n']);
  91. fprintf(fid,[surfaceGenName ' fire\n']);
  92. fprintf(fid,[surfaceGenName ' smoothing setValue 0 3\n']);
  93. fprintf(fid,[surfaceGenName ' options setValue 0 1\n']);
  94. fprintf(fid,[surfaceGenName ' options setValue 1 0\n']);
  95. fprintf(fid,[surfaceGenName ' border setValue 0 1\n']);
  96. fprintf(fid,[surfaceGenName ' border setValue 1 0\n']);
  97. fprintf(fid,[surfaceGenName ' minEdgeLength setMinMax 0 0 0.800000011920929\n']);
  98. fprintf(fid,[surfaceGenName ' minEdgeLength setValue 0 0\n']);
  99. fprintf(fid,[surfaceGenName ' materialList setValue 0 0\n']);
  100. fprintf(fid,[surfaceGenName ' fire\n']);
  101. fprintf(fid,[surfaceGenName ' setViewerMask 65535\n']);
  102. fprintf(fid,'\n');
  103. mask_surf_name = regexprep(mask_filename,'am','surf');
  104. fprintf(fid,'set hideNewModules 0\n');
  105. fprintf(fid,['[ {' surfaceGenName '} create {' mask_surf_name '}\n']);
  106. fprintf(fid,[' ] setLabel {' mask_surf_name '}\n']);
  107. fprintf(fid,[mask_surf_name ' setIconPosition ' num2str(xIcon(2)) ' ' num2str(yIcon(2)+yShift(k)) '\n']);
  108. fprintf(fid,[mask_surf_name ' master connect ' surfaceGenName '\n']);
  109. fprintf(fid,[mask_surf_name ' fire\n']);
  110. fprintf(fid,[mask_surf_name ' LevelOfDetail setMinMax -1 -1\n']);
  111. fprintf(fid,[mask_surf_name ' LevelOfDetail setButtons 1\n']);
  112. fprintf(fid,[mask_surf_name ' LevelOfDetail setIncrement 1\n']);
  113. fprintf(fid,[mask_surf_name ' LevelOfDetail setValue -1\n']);
  114. fprintf(fid,[mask_surf_name ' LevelOfDetail setSubMinMax -1 -1\n']);
  115. fprintf(fid,[mask_surf_name ' fire\n']);
  116. fprintf(fid,[mask_surf_name ' setViewerMask 65535\n']);
  117. fprintf(fid,[mask_surf_name ' deselect\n']);
  118. fprintf(fid,'\n');
  119. fprintf(fid,'set hideNewModules 0\n');
  120. fprintf(fid,'\n');
  121. surfaceViewName = ['SurfaceView' num2str(k)];
  122. fprintf(fid,'set hideNewModules 0\n');
  123. fprintf(fid,['create HxDisplaySurface {' surfaceViewName '}\n']);
  124. fprintf(fid,[surfaceViewName ' setIconPosition ' num2str(xIcon(3)) ' ' num2str(yIcon(2)+yShift(k)) '\n']);
  125. fprintf(fid,[surfaceViewName ' data connect ' mask_surf_name '\n']);
  126. fprintf(fid,[surfaceViewName ' colormap setDefaultColor 1 0.1 0.1\n']);
  127. fprintf(fid,[surfaceViewName ' colormap setDefaultAlpha 0.500000\n']);
  128. fprintf(fid,[surfaceViewName ' fire\n']);
  129. fprintf(fid,[surfaceViewName ' drawStyle setValue 4\n']);
  130. fprintf(fid,[surfaceViewName ' drawStyle setSpecularLighting 1\n']);
  131. fprintf(fid,[surfaceViewName ' drawStyle setTexture 0\n']);
  132. fprintf(fid,[surfaceViewName ' drawStyle setAlphaMode 3\n']);
  133. fprintf(fid,[surfaceViewName ' drawStyle setNormalBinding 0\n']);
  134. fprintf(fid,[surfaceViewName ' drawStyle setCullingMode 0\n']);
  135. fprintf(fid,[surfaceViewName ' selectionMode setValue 0 0\n']);
  136. fprintf(fid,[surfaceViewName ' Patch setMinMax 0 1\n']);
  137. fprintf(fid,[surfaceViewName ' Patch setButtons 1\n']);
  138. fprintf(fid,[surfaceViewName ' Patch setIncrement 1\n']);
  139. fprintf(fid,[surfaceViewName ' Patch setValue 1\n']);
  140. fprintf(fid,[surfaceViewName ' Patch setSubMinMax 0 1\n']);
  141. fprintf(fid,[surfaceViewName ' BoundaryId setValue 0 -1\n']);
  142. fprintf(fid,[surfaceViewName ' materials setValue 0 1\n']);
  143. fprintf(fid,[surfaceViewName ' materials setValue 1 0\n']);
  144. fprintf(fid,[surfaceViewName ' colorMode setValue 0\n']);
  145. fprintf(fid,[surfaceViewName ' baseTrans setMinMax 0 1\n']);
  146. fprintf(fid,[surfaceViewName ' baseTrans setButtons 0\n']);
  147. fprintf(fid,[surfaceViewName ' baseTrans setIncrement 0.1\n']);
  148. fprintf(fid,[surfaceViewName ' baseTrans setValue 0.53\n']);
  149. fprintf(fid,[surfaceViewName ' baseTrans setSubMinMax 0 1\n']);
  150. fprintf(fid,[surfaceViewName ' VRMode setValue 0 0\n']);
  151. fprintf(fid,[surfaceViewName ' fire\n']);
  152. fprintf(fid,[surfaceViewName ' hideBox 1\n']);
  153. fprintf(fid,['{' surfaceViewName '} selectTriangles zab HIJMPLPPHPGAABDPBAADAACGHIICIN\n']);
  154. fprintf(fid,[surfaceViewName ' fire\n']);
  155. fprintf(fid,[surfaceViewName ' setViewerMask 65535\n']);
  156. fprintf(fid,[surfaceViewName ' deselect\n']);
  157. fprintf(fid,'\n');
  158. end
  159. fclose(fid);