spm_eeg_displayECD.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. function [out] = spm_eeg_displayECD(Pos,Orient,Var,Names,options)
  2. % Plot dipole positions onto the SPM canonical mesh
  3. % FORMAT [out] = spm_eeg_displayECD(Pos,Orient,Var,Names,options)
  4. %
  5. % IN (admissible choices):
  6. % - Pos: a 3xndip matrix containing the positions of the dipoles in
  7. % the canonical frame of reference
  8. % - Orient: the same with dipole orientations
  9. % - Var: the same with position variance
  10. % - Names: the same with dipole names
  11. % - options: an optional structure containing
  12. % .hfig: the handle of the display figure
  13. % .tag: the tag to be associated with the created UI objects
  14. % .add: binary variable ({0}, 1: just add dipole in the figure .hfig)
  15. %
  16. % OUT:
  17. % - out: a structure containing the handles of the object in the figure
  18. % (including the mesh, the dipoles, the transparency slider, etc...)
  19. %__________________________________________________________________________
  20. % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
  21. % Jean Daunizeau
  22. % $Id: spm_eeg_displayECD.m 5737 2013-11-10 20:23:49Z karl $
  23. % checks and defaults
  24. %--------------------------------------------------------------------------
  25. hfig = [];
  26. ParentAxes = [];
  27. query = [];
  28. handles = [];
  29. tag = '';
  30. try, options; catch, options = []; end
  31. try, hfig = options.hfig; end
  32. try, tag = options.tag; end
  33. try, ParentAxes = options.ParentAxes; end
  34. try, query = options.query; end
  35. try, handles = options.handles; end
  36. try
  37. figure(hfig);
  38. catch
  39. hfig = spm_figure('GetWin','Graphics');
  40. spm_figure('Clear',hfig);
  41. ParentAxes = axes('parent',hfig);
  42. end
  43. try
  44. markersize = options.markersize;
  45. catch
  46. markersize = 20;
  47. end
  48. try
  49. meshsurf = options.meshsurf;
  50. catch
  51. meshsurf = fullfile(spm('Dir'),'canonical','cortex_5124.surf.gii');
  52. end
  53. if isscalar(Var), Var = Pos*0 + Var^2; end
  54. try, Pos{1}; catch, Pos = {Pos}; end
  55. try, Orient{1}; catch, Orient = {Orient};end
  56. try, Var{1}; catch, Var = {Var}; end
  57. ndip = size(Pos{1},2);
  58. if ~exist('Names','var') || isempty(Names)
  59. for i=1:ndip
  60. Names{i} = num2str(i);
  61. end
  62. end
  63. col = ['b','g','r','c','m','y','k','w'];
  64. tmp = ceil(ndip./numel(col));
  65. col = repmat(col,1,tmp);
  66. pa = get(ParentAxes,'position');
  67. if ndip > 0
  68. if isempty(query)
  69. opt.hfig = hfig;
  70. opt.ParentAxes = ParentAxes;
  71. opt.visible = 'off';
  72. pos2 = [pa(1),pa(2)+0.25*pa(4),0.03,0.5*pa(4)];
  73. out = spm_eeg_render(meshsurf,opt);
  74. handles.mesh = out.handles.p;
  75. handles.BUTTONS.transp = out.handles.transp;
  76. handles.hfig = out.handles.fi;
  77. handles.ParentAxes = out.handles.ParentAxes;
  78. set(handles.mesh,...
  79. 'facealpha',0.1,...
  80. 'visible','on')
  81. set(handles.BUTTONS.transp,...
  82. 'value',0.1,...
  83. 'position',pos2,...
  84. 'visible','on')
  85. end
  86. set(ParentAxes,'nextplot','add')
  87. for j=1:length(Pos)
  88. for i =1:ndip
  89. try
  90. set(handles.hp(j,i),...
  91. 'xdata',Pos{j}(1,i),...
  92. 'ydata',Pos{j}(2,i),...
  93. 'zdata',Pos{j}(3,i));
  94. catch
  95. handles.hp(j,i) = plot3(handles.ParentAxes,...
  96. Pos{j}(1,i),Pos{j}(2,i),Pos{j}(3,i),...
  97. [col(i),'.'],...
  98. 'markerSize',markersize,...
  99. 'visible','off');
  100. end
  101. try
  102. no = sqrt(sum(Orient{j}(:,i).^2));
  103. if no > 0
  104. Oi = 1e1.*Orient{j}(:,i)./no;
  105. else
  106. Oi = 1e-5*ones(3,1);
  107. end
  108. try
  109. set(handles.hq(j,i),...
  110. 'xdata',Pos{j}(1,i),...
  111. 'ydata',Pos{j}(2,i),...
  112. 'zdata',Pos{j}(3,i),...
  113. 'udata',Oi(1),...
  114. 'vdata',Oi(2),...
  115. 'wdata',Oi(3))
  116. catch
  117. handles.hq(j,i) = quiver3(handles.ParentAxes,...
  118. Pos{j}(1,i),Pos{j}(2,i),Pos{j}(3,i),...
  119. Oi(1),Oi(2),Oi(3),col(i),...
  120. 'lineWidth',2,'visible','off');
  121. end
  122. if isequal(query,'add')
  123. set(handles.hq(j,i),...
  124. 'LineStyle','--',...
  125. 'lineWidth',1)
  126. end
  127. end
  128. [x,y,z]= ellipsoid(Pos{j}(1,i),Pos{j}(2,i),Pos{j}(3,i),...
  129. 1.*sqrt(Var{j}(1,i)),1.*sqrt(Var{j}(2,i)),1.*sqrt(Var{j}(1,i)),20);
  130. try
  131. set(handles.hs(j,i),...
  132. 'xdata',x,...
  133. 'ydata',y,...
  134. 'zdata',z);
  135. catch
  136. handles.hs(j,i) = surf(handles.ParentAxes,...
  137. x,y,z,...
  138. 'edgecolor','none',...
  139. 'facecolor',col(i),...
  140. 'facealpha',0.2,...
  141. 'visible','off');
  142. end
  143. try
  144. set(handles.ht(j,i),...
  145. 'position',Pos{j}(:,i));
  146. catch
  147. handles.ht(j,i) = text(...
  148. Pos{j}(1,i),Pos{j}(2,i),Pos{j}(3,i),...
  149. Names{i},...
  150. 'Parent',handles.ParentAxes,...
  151. 'visible','off');
  152. end
  153. end
  154. end
  155. if length(Pos) > 1
  156. try, set(handles.hp(end,:),'visible','on'); end
  157. try, set(handles.hq(end,:),'visible','on'); end
  158. try, set(handles.hs(end,:),'visible','on'); end
  159. try, set(handles.ht(end,:),'visible','on'); end
  160. handles.uic(1) = uicontrol(handles.fi,...
  161. 'units','normalized',...
  162. 'position',[0.45,0.5,0.2,0.03],...
  163. 'style','radio','string','Show priors',...
  164. 'callback',@doChange1,...
  165. 'BackgroundColor',[1 1 1],...
  166. 'tooltipstring','Display prior locations',...
  167. 'userdata',handles,'value',0,...
  168. 'BusyAction','cancel',...
  169. 'Interruptible','off',...
  170. 'tag','plotEEG');
  171. handles.uic(2) = uicontrol(handles.fi,...
  172. 'units','normalized',...
  173. 'position',[0.45,0.53,0.2,0.03],...
  174. 'style','radio','string','Show posteriors',...
  175. 'callback',@doChange2,...
  176. 'BackgroundColor',[1 1 1],...
  177. 'tooltipstring','Display posterior locations',...
  178. 'userdata',handles,'value',1,...
  179. 'BusyAction','cancel',...
  180. 'Interruptible','off',...
  181. 'tag','plotEEG');
  182. else
  183. try, set(handles.hp(1,:),'visible','on'); end
  184. try, set(handles.hq(1,:),'visible','on'); end
  185. try, set(handles.hs(1,:),'visible','on'); end
  186. try, set(handles.ht(1,:),'visible','on'); end
  187. end
  188. end
  189. try
  190. clear out
  191. out.handles = handles;
  192. catch
  193. out = [];
  194. end
  195. %==========================================================================
  196. function doChange1(i1,i2)
  197. val = get(i1,'value');
  198. handles = get(i1,'userdata');
  199. if ~val
  200. try, set(handles.hp(1,:),'visible','off'); end
  201. try, set(handles.hq(1,:),'visible','off'); end
  202. try, set(handles.hs(1,:),'visible','off'); end
  203. try, set(handles.ht(1,:),'visible','off'); end
  204. else
  205. try, set(handles.hp(1,:),'visible','on'); end
  206. try, set(handles.hq(1,:),'visible','on'); end
  207. try, set(handles.hs(1,:),'visible','on'); end
  208. try, set(handles.ht(1,:),'visible','on'); end
  209. end
  210. %==========================================================================
  211. function doChange2(i1,i2)
  212. val = get(i1,'value');
  213. handles = get(i1,'userdata');
  214. if ~val
  215. try, set(handles.hp(2,:),'visible','off'); end
  216. try, set(handles.hq(2,:),'visible','off'); end
  217. try, set(handles.hs(2,:),'visible','off'); end
  218. try, set(handles.ht(2,:),'visible','off'); end
  219. else
  220. try, set(handles.hp(2,:),'visible','on'); end
  221. try, set(handles.hq(2,:),'visible','on'); end
  222. try, set(handles.hs(2,:),'visible','on'); end
  223. try, set(handles.ht(2,:),'visible','on'); end
  224. end