rri_orient_ui.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. % Return orientation of the current image:
  2. % orient is orientation 1x3 matrix, in that:
  3. % Three elements represent: [x y z]
  4. % Element value: 1 - Left to Right; 2 - Posterior to Anterior;
  5. % 3 - Inferior to Superior; 4 - Right to Left;
  6. % 5 - Anterior to Posterior; 6 - Superior to Inferior;
  7. % e.g.:
  8. % Standard RAS Orientation: [1 2 3]
  9. % Standard RHOS Orientation: [2 4 3]
  10. % Jimmy Shen (jimmy@rotman-baycrest.on.ca), 26-APR-04
  11. %
  12. function orient = rri_orient_ui(varargin)
  13. if nargin == 0
  14. init;
  15. orient_ui_fig = gcf;
  16. uiwait; % wait for user finish
  17. orient = getappdata(gcf, 'orient');
  18. if isempty(orient)
  19. orient = [1 2 3];
  20. end
  21. if ishandle(orient_ui_fig)
  22. close(gcf);
  23. end
  24. return;
  25. end
  26. action = varargin{1};
  27. if strcmp(action, 'done')
  28. click_done;
  29. elseif strcmp(action, 'cancel')
  30. uiresume;
  31. end
  32. return; % rri_orient_ui
  33. %----------------------------------------------------------------------
  34. function init
  35. save_setting_status = 'on';
  36. rri_orient_pos = [];
  37. try
  38. load('pls_profile');
  39. catch
  40. end
  41. try
  42. load('rri_pos_profile');
  43. catch
  44. end
  45. if ~isempty(rri_orient_pos) & strcmp(save_setting_status,'on')
  46. pos = rri_orient_pos;
  47. else
  48. w = 0.35;
  49. h = 0.4;
  50. x = (1-w)/2;
  51. y = (1-h)/2;
  52. pos = [x y w h];
  53. end
  54. handles.figure = figure('Color',[0.8 0.8 0.8], ...
  55. 'Units','normal', ...
  56. 'Name', 'Convert to standard RAS orientation', ...
  57. 'NumberTitle','off', ...
  58. 'MenuBar','none', ...
  59. 'Position',pos, ...
  60. 'WindowStyle', 'normal', ...
  61. 'ToolBar','none');
  62. h0 = handles.figure;
  63. Font.FontUnits = 'point';
  64. Font.FontSize = 12;
  65. margin = .1;
  66. line_num = 6;
  67. line_ht = (1 - margin*2) / line_num;
  68. x = margin;
  69. y = 1 - margin - line_ht;
  70. w = 1 - margin * 2;
  71. h = line_ht * .7;
  72. pos = [x y w h];
  73. handles.Ttit = uicontrol('parent', h0, ...
  74. 'style','text', ...
  75. 'unit', 'normal', ...
  76. Font, ...
  77. 'Position',pos, ...
  78. 'HorizontalAlignment','left',...
  79. 'background', [0.8 0.8 0.8], ...
  80. 'string', 'Please input orientation of the current image:');
  81. y = y - line_ht;
  82. w = .2;
  83. pos = [x y w h];
  84. handles.Tx_orient = uicontrol('parent', h0, ...
  85. 'style','text', ...
  86. 'unit', 'normal', ...
  87. Font, ...
  88. 'Position',pos, ...
  89. 'HorizontalAlignment','left',...
  90. 'background', [0.8 0.8 0.8], ...
  91. 'string', 'X Axes:');
  92. y = y - line_ht;
  93. pos = [x y w h];
  94. handles.Ty_orient = uicontrol('parent', h0, ...
  95. 'style','text', ...
  96. 'unit', 'normal', ...
  97. Font, ...
  98. 'Position',pos, ...
  99. 'HorizontalAlignment','left',...
  100. 'background', [0.8 0.8 0.8], ...
  101. 'string', 'Y Axes:');
  102. y = y - line_ht;
  103. pos = [x y w h];
  104. handles.Tz_orient = uicontrol('parent', h0, ...
  105. 'style','text', ...
  106. 'unit', 'normal', ...
  107. Font, ...
  108. 'Position',pos, ...
  109. 'HorizontalAlignment','left',...
  110. 'background', [0.8 0.8 0.8], ...
  111. 'string', 'Z Axes:');
  112. choice = { 'From Left to Right', 'From Posterior to Anterior', ...
  113. 'From Inferior to Superior', 'From Right to Left', ...
  114. 'From Anterior to Posterior', 'From Superior to Inferior' };
  115. y = 1 - margin - line_ht;
  116. y = y - line_ht;
  117. w = 1 - margin - x - w;
  118. x = 1 - margin - w;
  119. pos = [x y w h];
  120. handles.x_orient = uicontrol('parent', h0, ...
  121. 'style','popupmenu', ...
  122. 'unit', 'normal', ...
  123. Font, ...
  124. 'Position',pos, ...
  125. 'HorizontalAlignment','left',...
  126. 'string', choice, ...
  127. 'value', 1, ...
  128. 'background', [1 1 1]);
  129. y = y - line_ht;
  130. pos = [x y w h];
  131. handles.y_orient = uicontrol('parent', h0, ...
  132. 'style','popupmenu', ...
  133. 'unit', 'normal', ...
  134. Font, ...
  135. 'Position',pos, ...
  136. 'HorizontalAlignment','left',...
  137. 'string', choice, ...
  138. 'value', 2, ...
  139. 'background', [1 1 1]);
  140. y = y - line_ht;
  141. pos = [x y w h];
  142. handles.z_orient = uicontrol('parent', h0, ...
  143. 'style','popupmenu', ...
  144. 'unit', 'normal', ...
  145. Font, ...
  146. 'Position',pos, ...
  147. 'HorizontalAlignment','left',...
  148. 'string', choice, ...
  149. 'value', 3, ...
  150. 'background', [1 1 1]);
  151. x = margin;
  152. y = y - line_ht * 1.5;
  153. w = .3;
  154. pos = [x y w h];
  155. handles.done = uicontrol('parent', h0, ...
  156. 'unit', 'normal', ...
  157. Font, ...
  158. 'Position',pos, ...
  159. 'HorizontalAlignment','center',...
  160. 'callback', 'rri_orient_ui(''done'');', ...
  161. 'string', 'Done');
  162. x = 1 - margin - w;
  163. pos = [x y w h];
  164. handles.cancel = uicontrol('parent', h0, ...
  165. 'unit', 'normal', ...
  166. Font, ...
  167. 'Position',pos, ...
  168. 'HorizontalAlignment','center',...
  169. 'callback', 'rri_orient_ui(''cancel'');', ...
  170. 'string', 'Cancel');
  171. setappdata(h0, 'handles', handles);
  172. setappdata(h0, 'orient', [1 2 3]);
  173. return; % init
  174. %----------------------------------------------------------------------
  175. function click_done
  176. handles = getappdata(gcf, 'handles');
  177. x_orient = get(handles.x_orient, 'value');
  178. y_orient = get(handles.y_orient, 'value');
  179. z_orient = get(handles.z_orient, 'value');
  180. orient = [x_orient y_orient z_orient];
  181. test_orient = [orient, orient + 3];
  182. test_orient = mod(test_orient, 3);
  183. if length(unique(test_orient)) ~= 3
  184. msgbox('Please don''t choose same or opposite direction','Error','modal');
  185. return;
  186. end
  187. setappdata(gcf, 'orient', [x_orient y_orient z_orient]);
  188. uiresume;
  189. return; % click_done