-
Notifications
You must be signed in to change notification settings - Fork 7
/
eeglab_dipplot.m
1730 lines (1611 loc) · 69.7 KB
/
eeglab_dipplot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% dipplot() - Visualize EEG equivalent-dipole locations and orientations
% in the MNI average MRI head or in the BESA spherical head model.
% Usage:
% >> dipplot( sources, 'key', 'val', ...);
% >> [sources X Y Z XE YE ZE] = dipplot( sources, 'key', 'val', ...);
%
% Inputs:
% sources - structure array of dipole information: can contain
% either BESA or DIPFIT dipole information. BESA dipole
% information are still supported but may disapear in the
% future. For DIPFIT
% sources.posxyz: contains 3-D location of dipole in each
% column. 2 rows indicate 2 dipoles.
% sources.momxyz: contains 3-D moments for dipoles above.
% sources.rv : residual variance from 0 to 1.
% other fields : used for graphic interface.
%
% Optional input:
% 'rvrange' - [min max] or [max] Only plot dipoles with residual variace
% within the given range. Default: plot all dipoles.
% 'summary' - ['on'|'off'|'3d'] Build a summary plot with three views (top,
% back, side). {default: 'off'}
% 'mri' - Matlab file containing an MRI volume and a 4-D transformation
% matrix to go from voxel space to electrode space:
% mri.anatomy contains a 3-D anatomical data array
% mri.transfrom contains a 4-D homogenous transformation matrix.
% 'coordformat' - ['MNI'|'spherical'] Consider that dipole coordinates are in
% MNI or spherical coordinates (for spherical, the radius of the
% head is assumed to be 85 (mm)). See also function sph2spm().
% 'transform' - [real array] traditional transformation matrix to convert
% dipole coordinates to MNI space. Default is assumed from
% 'coordformat' input above. Type help traditional for more
% information.
% 'image' - ['besa'|'mri'] Background image.
% 'mri' (or 'fullmri') uses mean-MRI brain images from the Montreal
% Neurological Institute. This option can also contain a 3-D MRI
% volume (dim 1: left to right; dim 2: anterior-posterior; dim 3:
% superior-inferior). Use 'coregist' to coregister electrodes
% with the MRI. {default: 'mri'}
% 'verbose' - ['on'|'off'] comment on operations on command line {default:
% 'on'}.
% 'plot' - ['on'|'off'] only return outputs {default: 'off'}.
%
% Plotting options:
% 'color' - [cell array of color strings or (1,3) color arrays]. For
% exemple { 'b' 'g' [1 0 0] } gives blue, green and red.
% Dipole colors will rotate through the given colors if
% the number given is less than the number of dipoles to plot.
% A single number will be used as color index in the jet colormap.
% 'view' - 3-D viewing angle in cartesian coords.,
% [0 0 1] gives a sagittal view, [0 -1 0] a view from the rear;
% [1 0 0] gives a view from the side of the head.
% 'mesh' - ['on'|'off'] Display spherical mesh. {Default is 'on'}
% 'meshdata' - [cell array|'file_name'] Mesh data in a cell array { 'vertices'
% data 'faces' data } or a boundary element model filename (the
% function will plot the 3rd mesh in the 'bnd' sub-structure).
% 'axistight' - ['on'|'off'] For MRI only, display the closest MRI
% slide. {Default is 'off'}
% 'gui' - ['on'|'off'] Display controls. {Default is 'on'} If gui 'off',
% a new figure is not created. Useful for incomporating a dipplot
% into a complex figure.
% 'num' - ['on'|'off'] Display component number. Take into account
% dipole size. {Default: 'off'}
% 'cornermri' - ['on'|'off'] force MRI images to the corner of the MRI volume
% (usefull when background is not black). Default: 'off'.
% 'drawedges' - ['on'|'off'] draw edges of the 3-D MRI (black in axistight,
% white otherwise.) Default is 'off'.
% 'projimg' - ['on'|'off'] Project dipole(s) onto the 2-D images, for use
% in making 3-D plots {Default 'off'}
% 'projlines' - ['on'|'off'] Plot lines connecting dipole with 2-D projection.
% Color is dashed black for BESA head and dashed black for the
% MNI brain {Default 'off'}
% 'projcol' - [color] color for the projected line {Default is same as dipole}
% 'dipolesize' - Size of the dipole sphere(s). This option may also contain one
% value per dipole {Default: 30}
% 'dipolelength' - Length of the dipole bar(s) {Default: 1}
% 'pointout' - ['on'|'off'] Point the dipoles outward. {Default: 'off'}
% 'sphere' - [float] radius of sphere corresponding to the skin. Default is 1.
% 'spheres' - ['on'|'off'] {default: 'off'} plot dipole markers as 3-D spheres.
% Does not yet interact with gui buttons, produces non-gui mode.
% 'spheresize' - [real>0] size of spheres (if 'on'). {default: 5}
% 'normlen' - ['on'|'off'] Normalize length of all dipoles. {Default: 'off'}
% 'dipnames' - [cell array] cell array of string with a name for each dipole (or
% pair of dipole).
% 'holdon' - ['on'|'off'] create a new dipplot figure or plot dipoles within an
% an existing figure. Default is 'off'.
%
% Outputs:
% sources - EEG.source structure with two extra fiels 'mnicoord' and 'talcoord'
% containing the MNI and talairach coordinates of the dipoles. Note
% that for the BEM model, dipoles are already in MNI coordinates.
% X,Y,Z - Locations of dipole heads (Cartesian coordinates in MNI space).
% If there is more than one dipole per components, the last dipole
% is returned.
% XE,YE,ZE - Locations of dipole ends (Cartesian coordinates). The same
% remark as above applies.
%
% Author: Arnaud Delorme, CNL / Salk Institute, 1st July 2002
%
% Notes: See DIPFIT web tutorial at sccn.ucsd.edu/eeglab/dipfittut/dipfit.html
% for more details about MRI co-registration etc...
%
% Example:
% % define dipoles
% sources(1).posxyz = [-59 48 -28]; % position for the first dipole
% sources(1).momxyz = [ 0 58 -69]; % orientation for the first dipole
% sources(1).rv = 0.036; % residual variance for the first dipole
% sources(2).posxyz = [74 -4 -38]; % position for the second dipole
% sources(2).momxyz = [43 -38 -16]; % orientation for the second dipole
% sources(2).rv = 0.027; % residual variance for the second dipole
%
% % plot of the two dipoles (first in green, second in blue)
% dipplot( sources, 'color', { 'g' 'b' });
%
% % To make a stereographic plot
% figure( 'position', [153 553 1067 421];
% subplot(1,3,1); dipplot( sources, 'view', [43 10], 'gui', 'off');
% subplot(1,3,3); dipplot( sources, 'view', [37 10], 'gui', 'off');
%
% % To make a summary plot
% dipplot( sources, 'summary', 'on', 'num', 'on');
%
% See also: eeglab(), dipfit()
%123456789012345678901234567890123456789012345678901234567890123456789012
% old options
% -----------
% 'std' - [cell array] plot standard deviation of dipoles. i.e.
% { [1:6] [7:12] } plot two elipsoids that best fit all the dipoles
% from 1 to 6 and 7 to 12 with radius 1 standard deviation.
% { { [1:6] 2 'linewidth' 2 } [7:12] } do the same but now the
% first elipsoid is 2 standard-dev and the lines are thicker.
% Copyright (C) 2002 Arnaud Delorme
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% README -- Plotting strategy:
% - All buttons have a tag 'tmp' so they can be removed
% - The component-number buttons have 'userdata' equal to 'editor' and
% can be found easily by other buttons find('userdata', 'editor')
% - All dipoles have a tag 'dipoleX' (X=their number) and can be made
% visible/invisible
% - The gcf object 'userdat' field stores the handle of the dipole that
% is currently being modified
% - Gca 'userdata' stores imqge names and position
%$Log: dipplot.m,v $
%Revision 1.161 2009/11/10 22:43:52 dev
%fixed the 'point out' option
%
%Revision 1.160 2009/08/04 04:44:22 arno
%All functions necessary for compiling EEGLAB code
%
%Revision 1.159 2009/05/16 00:11:42 arno
%adding tag to axis
%
%Revision 1.158 2009/05/15 23:33:19 arno
%3d mode
%
%Revision 1.157 2009/05/12 18:23:51 arno
%summary mode 3d
%
%Revision 1.156 2009/05/12 02:37:49 arno
%fix hold on option
%
%Revision 1.155 2009/05/08 01:48:18 arno
%invisible figure
%
%Revision 1.154 2009/01/03 00:06:44 arno
%fixed typo
%
%Revision 1.153 2008/12/23 02:17:13 arno
%fix help message
%
%Revision 1.152 2008/12/23 02:16:26 arno
%adding custom dipole size
%
%Revision 1.151 2008/05/15 23:19:39 arno
%hold on option
%
%Revision 1.150 2008/02/04 23:01:16 arno
%cap for cylinder
%
%Revision 1.149 2008/02/01 23:12:44 arno
%cylinder dipoles
%
%Revision 1.148 2007/11/21 18:47:52 arno
%fixed CTF error
%
%Revision 1.147 2007/08/28 17:15:32 arno
%fix traditional
%
%Revision 1.146 2007/02/02 09:25:48 arno
%change x axis
%
%Revision 1.144 2006/11/20 21:22:12 arno
%call 2 mni2tal compatible with mni2tal in bioelectromagnetism
%
%Revision 1.143 2006/11/10 02:47:00 arno
%remove transformation
%
%Revision 1.142 2006/11/10 02:22:28 arno
%problem with BEM
%
%Revision 1.141 2006/11/10 02:13:03 arno
%transform to MNI model
%
%Revision 1.140 2006/10/26 17:33:24 arno
%propagate axis tight option to summary mode
%
%Revision 1.139 2006/10/25 23:29:47 arno
%custom summary mode
%
%Revision 1.138 2006/01/23 22:24:24 arno
%set multfactor to 1
%
%Revision 1.137 2006/01/23 22:23:18 arno
%factor -> multfactor
%
%Revision 1.136 2006/01/23 22:19:16 arno
%same
%
%Revision 1.135 2006/01/23 22:17:32 arno
%fixing coordinate error
%
%Revision 1.134 2006/01/19 23:54:27 arno
%adding meshdata to summary mode
%
%Revision 1.133 2006/01/19 23:38:57 arno
%using field talcoord
%
%Revision 1.132 2006/01/19 23:35:17 arno
%spherical to talairach changed
%
%Revision 1.131 2006/01/19 21:45:56 arno
%typo
%
%Revision 1.130 2006/01/19 21:45:01 arno
%coordformat and mri for summary mode
%
%Revision 1.129 2005/10/26 21:49:41 arno
%returning electrode coordinates
%
%Revision 1.128 2005/10/26 18:03:34 arno
%remove dual 0 dipoles
%
%Revision 1.127 2005/08/19 04:41:26 arno
%mesh for BEM
%
%Revision 1.126 2005/04/19 23:38:58 arno
%allow plotting LORETA images
%
%Revision 1.125 2005/04/07 18:48:08 hilit
%adding a 'verbose' option
%
%Revision 1.124 2005/04/01 22:12:14 arno
%3-D sphere projection
%
%Revision 1.123 2005/04/01 20:02:07 arno
%sagital -> sagittal
%
%Revision 1.122 2005/04/01 16:05:39 arno
%fixing summary
%
%Revision 1.121 2005/03/31 18:44:24 arno
%debug summary
%
%Revision 1.120 2005/03/31 18:39:21 arno
%same
%
%Revision 1.119 2005/03/31 18:38:17 arno
%fixing dipole name for summary mode
%
%Revision 1.118 2005/03/31 18:32:57 arno
%test for strings
%.,
%
%Revision 1.117 2005/03/22 19:03:35 arno
%rvrange
%
%Revision 1.116 2005/03/18 17:57:12 arno
%disable mesh for MNI coordinate with no mesh data
%
%Revision 1.115 2005/03/18 17:52:05 arno
%fixing summary mode
%
%Revision 1.114 2005/03/18 17:14:26 arno
%fixing besa coordinates
%.,
%
%Revision 1.113 2005/03/17 17:14:18 arno
%re-implemented normlen, autodetect MRI etc...
%
%Revision 1.112 2005/03/17 16:16:03 arno
%reading anatomical image
%
%Revision 1.111 2005/03/14 18:28:56 arno
%implementing tailarach coordinate display
%
%Revision 1.110 2005/03/11 16:31:14 arno
%new option meshdata
%
%Revision 1.109 2005/03/11 16:22:38 arno
%mesh for boundary element model
%
%Revision 1.108 2005/03/04 23:18:55 arno
%use MNI coordinates, completelly remodeled function
%
%Revision 1.104 2004/11/20 02:32:43 scott
%help msg edits: carthesian -> Cartesian
%
%Revision 1.103 2004/11/11 02:34:15 arno
%fixing dipnames
%
%Revision 1.102 2004/11/11 02:11:16 arno
%dipname -> dipnames
%
%Revision 1.101 2004/11/11 01:40:39 arno
%new dipnames option
%
%Revision 1.100 2004/06/15 17:57:06 arno
%do not know
%
%Revision 1.99 2004/06/11 00:16:12 arno
%change light
%
%Revision 1.98 2004/06/09 21:15:01 arno
%debug projcol
%
%Revision 1.97 2004/06/09 21:12:34 arno
%fixing projcolor
%
%Revision 1.96 2004/06/09 16:27:11 arno
%color debug
%
%Revision 1.95 2004/06/02 22:47:38 arno
%debug color
%
%Revision 1.94 2004/06/02 22:44:03 arno
%projection color decoding
%
%Revision 1.93 2004/06/02 22:15:42 arno
%debug color problem
%
%Revision 1.92 2004/06/01 20:37:01 arno
%fixing projection color
%
%Revision 1.91 2004/06/01 18:48:31 arno
%fixing spheres
%
%Revision 1.90 2004/06/01 16:53:35 scott
%spherecolor now works (undocumented) but gives weird color palette ??
%
%Revision 1.89 2004/06/01 15:48:50 scott
%sphere colors
%
%Revision 1.88 2004/06/01 05:03:41 scott
%sphere color
%
%Revision 1.87 2004/06/01 01:06:28 scott
%still puzzling about spheres colors ...
%
%Revision 1.86 2004/05/13 18:57:48 arno
%plot middle of two dipoles
%
%Revision 1.85 2004/05/10 14:37:59 arno
%image type
%
%Revision 1.84 2004/05/05 15:25:41 scott
%typo
%
%Revision 1.83 2004/05/05 15:24:50 scott
%typo
%,
%
%Revision 1.82 2004/05/05 15:24:00 scott
%working on sphere coloring -> ????????
%
%Revision 1.81 2004/05/05 01:17:27 scott
%added spheresize
%
%Revision 1.80 2004/05/05 00:52:11 scott
%dipole length 0 + 'spheres' again...
%
%Revision 1.79 2004/05/04 17:04:22 scott
%test for s1, p1 if spheres on
%
%Revision 1.78 2004/05/04 05:37:26 scott
%turn off 'spheres' cylinder plotting if g.dipolelenth == 0
%
%Revision 1.77 2004/04/30 18:48:53 scott
%made default image 'mri' - debugged spheres/cylinders
%
%Revision 1.76 2004/04/29 15:35:32 scott
%adding cylinders for spheres pointers
%
%Revision 1.75 2004/04/14 01:40:32 scott
%hid 'spheres' option
%
%Revision 1.74 2004/04/13 18:24:58 scott
%nothing
%
%Revision 1.73 2004/04/12 23:40:50 arno
%nothing
%
%Revision 1.72 2004/03/26 01:39:04 arno
%only plotting active dipoles
%
%Revision 1.71 2004/03/26 01:22:20 arno
%mricorner with tightview
%
%Revision 1.70 2004/03/26 00:57:17 arno
%read custom mri
%
%Revision 1.69 2004/02/27 19:13:25 arno
%nothing
%
%Revision 1.68 2004/02/23 19:17:00 arno
%remove debug msg
%
%Revision 1.67 2004/02/23 19:16:16 arno
%fixing 2 dipole problem
%
%Revision 1.66 2004/02/23 19:09:05 arno
%*** empty log message ***
%
%Revision 1.65 2004/01/28 15:26:14 arno
%detecting empty dipoles
%
%Revision 1.64 2003/11/05 20:30:51 arno
%nothing
%
%Revision 1.63 2003/11/05 18:50:28 arno
%nothing
%
%Revision 1.62 2003/10/31 23:29:29 arno
%dicreases dipole size for summary mode
%
%Revision 1.61 2003/10/31 19:50:38 arno
%reordering 2 dipoles, delete old edges
%
%Revision 1.60 2003/10/31 18:59:41 arno
%divide rvrange by 100
%
%Revision 1.59 2003/10/30 03:25:17 arno
%adding projection lines
%
%Revision 1.58 2003/10/29 23:44:38 arno
%don't know
%
%Revision 1.57 2003/10/27 18:50:06 arno
%adding edges
%
%Revision 1.56 2003/10/09 01:02:12 arno
%nothing
%
%Revision 1.55 2003/09/11 00:53:04 arno
%same
%
%Revision 1.54 2003/09/11 00:52:38 arno
%documenting new arg cornermri\
%
%Revision 1.53 2003/09/11 00:51:19 arno
%adding new param cornermri
%
%Revision 1.52 2003/08/13 00:46:07 arno
%*** empty log message ***
%
%Revision 1.51 2003/08/04 21:29:06 arno
%scale besa for summary plot
%
%Revision 1.50 2003/08/04 21:15:54 arno
%num color on MRI
%
%Revision 1.49 2003/08/04 19:08:09 arno
%[Afixing normlen in summarize mode
%
%Revision 1.48 2003/07/31 23:37:07 arno
%adding property to structure attatched to dipole
%
%Revision 1.47 2003/07/31 23:30:05 arno
%*** empty log message ***
%
%Revision 1.46 2003/07/24 17:08:03 arno
%making component number for dipfit
%
%Revision 1.45 2003/07/22 01:10:06 arno
%*** empty log message ***
%
%Revision 1.44 2003/07/21 22:04:09 arno
%debug for Matlab 5.3
%
%Revision 1.43 2003/07/21 21:55:14 arno
%fixing MNI brain for distribution
%
%Revision 1.42 2003/07/16 18:39:14 arno
%nothing
%
%Revision 1.41 2003/07/03 00:02:43 arno
%undo last change
%
%Revision 1.40 2003/07/02 23:48:56 arno
%changing outputs
%
%Revision 1.39 2003/07/02 23:38:58 arno
%debuging projections and summary
%
%Revision 1.38 2003/07/01 23:52:50 arno
%test for sphere 1 before renormalizing
%
%Revision 1.37 2003/07/01 23:49:21 arno
%try to implement contextual menu: does not work in 3-D
%
%Revision 1.36 2003/07/01 22:10:14 arno
%debuging for 2 dipoles/component
%
%Revision 1.35 2003/07/01 19:04:13 arno
%fixing view problem
%
%Revision 1.34 2003/07/01 00:21:18 arno
%implementing 3-D MNI volume
%
%Revision 1.33 2003/06/12 23:49:56 arno
%dipplot normalization
%
%Revision 1.32 2003/06/10 19:04:11 arno
%nothing
%
%Revision 1.31 2003/06/03 16:37:16 arno
%tag images
%
%Revision 1.30 2003/05/30 17:16:22 arno
%nothing
%
%Revision 1.29 2003/05/30 17:09:00 arno
%for index = 1:size(x, 2);
% dipstruct(index).posxyz = [x(index) y(index) z(index)];
% %dipstruct(index).posxyz = tmp(index).posxyz;
% dipstruct(index).momxyz = [1 1 1];
% dipstruct(index).component = index;
% dipstruct(index).rv = 0.1;
%end;
%dipplot(dipstruct);
%making xyz output compatible
%
%Revision 1.28 2003/05/30 16:06:27 arno
%nothing
%
%Revision 1.27 2003/05/14 21:36:36 arno
%nothing
%
%Revision 1.26 2003/04/30 18:42:07 arno
%calibrating roughtly the slice selection
%
%Revision 1.25 2003/04/30 16:19:28 arno
%calibrating infants
%
%Revision 1.24 2003/04/30 02:05:24 arno
%changing axis properties for images
%
%Revision 1.23 2003/04/30 01:31:53 arno
%infant option
%
%Revision 1.22 2003/04/23 18:35:11 arno
%allow to plot elipses
%
%Revision 1.21 2003/04/22 21:18:44 arno
%standard dev
%
%Revision 1.20 2003/04/19 01:15:07 arno
%debugging 2 besa dipoles
%
%Revision 1.19 2003/04/19 00:55:53 arno
%correct normalized dipole length
%
%Revision 1.18 2003/04/19 00:46:41 arno
%correcting projection
%
%Revision 1.17 2003/04/19 00:37:43 arno
%changing dipole size for BESA
%
%Revision 1.16 2003/04/11 17:26:45 arno
%accurate plotting in fullMRI
%
%Revision 1.15 2003/04/10 17:37:18 arno
%multi layer MRI plot
%
%Revision 1.14 2003/03/14 17:06:42 arno
%adding error message if plotting non-BESA dipoles on the BESA head model
%
%Revision 1.13 2003/03/14 02:11:33 arno
%automatic scaling for dipfit
%
%Revision 1.12 2003/03/11 23:33:27 arno
%typo
%
%Revision 1.11 2003/03/11 23:27:09 arno
%adding normlen parameter
%
%Revision 1.10 2003/03/11 01:20:32 arno
%updating default besaextori, debuging summary
%
%Revision 1.9 2003/03/07 00:32:53 arno
%debugging textforgui
%
%Revision 1.8 2003/03/06 17:01:10 arno
%textgui -> textforgui
%
%Revision 1.7 2003/03/06 16:50:08 arno
%adding log message
%
function [outsources, XX, YY, ZZ, XO, YO, ZO] = eeglab_dipplot( sourcesori, varargin )
DEFAULTVIEW = [0 0 1];
if nargin < 1
help eeglab_dipplot;
return;
end;
% reading and testing arguments
% -----------------------------
sources = sourcesori;
if ~isstruct(sources)
updatedipplot(sources(1));
% sources countain the figure handler
return
end;
% key type range default
g = finputcheck( varargin, { 'color' '' [] [];
'axistight' 'string' { 'on' 'off' } 'off';
'coordformat' 'string' { 'MNI' 'spherical' 'CTF' 'auto' } 'auto';
'drawedges' 'string' { 'on' 'off' } 'off';
'mesh' 'string' { 'on' 'off' } 'off';
'gui' 'string' { 'on' 'off' } 'on';
'summary' 'string' { 'on2' 'on' 'off' '3d' } 'off';
'verbose' 'string' { 'on' 'off' } 'on';
'view' 'real' [] [0 0 1];
'rvrange' 'real' [0 Inf] [];
'transform' 'real' [0 Inf] [];
'normlen' 'string' { 'on' 'off' } 'off';
'num' 'string' { 'on' 'off' } 'off';
'cornermri' 'string' { 'on' 'off' } 'off';
'mri' { 'string' 'struct' } [] '';
'dipnames' 'cell' [] {};
'projimg' 'string' { 'on' 'off' } 'off';
'projcol' '' [] [];
'projlines' 'string' { 'on' 'off' } 'off';
'pointout' 'string' { 'on' 'off' } 'off';
'holdon' 'string' { 'on' 'off' } 'off';
'dipolesize' 'real' [0 Inf] 30;
'dipolelength' 'real' [0 Inf] 1;
'sphere' 'real' [0 Inf] 1;
'spheres' 'string' {'on' 'off'} 'off';
'links' 'real' [] [];
'image' { 'string' 'real' } [] 'mri';
'plot' 'string' { 'on' 'off' } 'on';
'meshdata' { 'string' 'cell' } [] '' }, 'dipplot');
% 'std' 'cell' [] {};
% 'coreg' 'real' [] [];
if isstr(g), error(g); end;
if strcmpi(g.holdon, 'on'), g.gui = 'off'; end;
if length(g.dipolesize) == 1, g.dipolesize = repmat(g.dipolesize, [1 length(sourcesori)]); end;
g.zoom = 1500;
if strcmpi(g.image, 'besa')
error('BESA image not supported any more. Use EEGLAB version 4.512 or earlier. (BESA dipoles can still be plotted in MNI brain.)');
end;
% trying to determine coordformat
% -------------------------------
if ~isfield(sources, 'momxyz')
g.coordformat = 'spherical';
end;
if strcmpi(g.coordformat, 'auto')
if ~isempty(g.meshdata)
g.coordformat = 'MNI';
if strcmpi(g.verbose, 'on'),
disp('Coordinate format unknown: using ''MNI'' since mesh data was provided as input');
end
else
maxdiplen = 0;
for ind = 1:length(sourcesori)
maxdiplen = max(maxdiplen, max(sourcesori(ind).momxyz(:)));
end;
if maxdiplen>2000
if strcmpi(g.verbose, 'on'),
disp('Coordinate format unknown: using ''MNI'' because of large dipole moments');
end
else
g.coordformat = 'spherical';
if strcmpi(g.verbose, 'on'),
disp('Coordinate format unknown: using ''spherical'' since no mesh data was provided as input');
end
end;
end;
end;
% axis image and limits
% ---------------------
dat.axistight = strcmpi(g.axistight, 'on');
dat.drawedges = g.drawedges;
dat.cornermri = strcmpi(g.cornermri, 'on');
radius = 85;
% look up an MRI file if necessary
% --------------------------------
if isempty(g.mri)
if strcmpi(g.verbose, 'on'),
disp('No MRI file given as input. Looking up one.');
end
dipfitdefs;
g.mri = template_models(1).mrifile;
end;
% read anatomical MRI using Fieldtrip and SPM2 functons
% -----------------------------------------------------
if isstr(g.mri);
try,
g.mri = load('-mat', g.mri);
g.mri = g.mri.mri;
catch,
disp('Failed to read Matlab file. Attempt to read MRI file using function read_fcdc_mri');
try,
warning off;
g.mri = read_fcdc_mri(g.mri);
%g.mri.anatomy(find(g.mri.anatomy > 255)) = 255;
%g.mri.anatomy = uint8(g.mri.anatomy);
g.mri.anatomy = round(gammacorrection( g.mri.anatomy, 0.8));
g.mri.anatomy = uint8(round(g.mri.anatomy/max(reshape(g.mri.anatomy, prod(g.mri.dim),1))*255));
% WARNING: if using double instead of int8, the scaling is different
% [-128 to 128 and 0 is not good]
% WARNING: the transform matrix is not 1, 1, 1 on the diagonal, some slices may be
% misplaced
warning on;
catch,
error('Cannot load file using read_fcdc_mri');
end;
end;
end;
if strcmpi(g.coordformat, 'spherical')
dat.sph2spm = sph2spm;
elseif strcmpi(g.coordformat, 'CTF')
dat.sph2spm = traditionaldipfit([0 0 0 0 0 0 10 -10 10]);
else
dat.sph2spm = []; %traditional([0 0 0 0 0 pi 1 1 1]);
end;
dat.sph2spm=eye(4); % zeynep
if ~isempty(g.transform), dat.sph2spm = traditionaldipfit(g.transform);
end;
if isfield(g.mri, 'anatomycol')
dat.imgs = g.mri.anatomycol;
else
dat.imgs = g.mri.anatomy;
end;
dat.transform = g.mri.transform;
% MRI coordinates for slices
% --------------------------
if ~isfield(g.mri, 'xgrid')
g.mri.xgrid = [1:size(dat.imgs,1)];
g.mri.ygrid = [1:size(dat.imgs,2)];
g.mri.zgrid = [1:size(dat.imgs,3)];
end;
if strcmpi(g.coordformat, 'CTF')
g.mri.zgrid = g.mri.zgrid(end:-1:1);
end;
dat.imgcoords = { g.mri.xgrid g.mri.ygrid g.mri.zgrid };
dat.maxcoord = [max(dat.imgcoords{1}) max(dat.imgcoords{2}) max(dat.imgcoords{3})];
COLORMESH = 'w';
BACKCOLOR = 'k';
% point 0
% -------
[xx yy zz] = transform(0, 0, 0, dat.sph2spm); % nothing happens for BEM since dat.sph2spm is empty
dat.zeroloc = [ xx yy zz ];
% conversion
% ----------
if strcmpi(g.normlen, 'on')
if isfield(sources, 'besaextori')
sources = rmfield(sources, 'besaextori');
end;
end;
if ~isfield(sources, 'besathloc') & strcmpi(g.image, 'besa') & ~is_sccn
error(['For copyright reasons, it is not possible to use the BESA ' ...
'head model to plot non-BESA dipoles']);
end;
if isfield(sources, 'besathloc')
sources = convertbesaoldformat(sources);
end;
if ~isfield(sources, 'posxyz')
sources = computexyzforbesa(sources);
end;
if ~isfield(sources, 'component')
if strcmpi(g.verbose, 'on'),
disp('No component indices, making incremental ones...');
end
for index = 1:length(sources)
sources(index).component = index;
end;
end;
% find non-empty sources
% ----------------------
noempt = cellfun('isempty', { sources.posxyz } );
sources = sources( find(~noempt) );
% transform coordinates
% ---------------------
outsources = sources;
for index = 1:length(sources)
sources(index).momxyz = sources(index).momxyz/1000;
end;
% remove 0 second dipoles if any
% ------------------------------
for index = 1:length(sources)
if size(sources(index).momxyz,1) == 2
if all(sources(index).momxyz(2,:) == 0)
sources(index).momxyz = sources(index).momxyz(1,:);
sources(index).posxyz = sources(index).posxyz(1,:);
end;
end;
end;
% remove sources with out of bound Residual variance
% --------------------------------------------------
if isfield(sources, 'rv') & ~isempty(g.rvrange)
if length(g.rvrange) == 1, g.rvrange = [ 0 g.rvrange ]; end;
for index = length(sources):-1:1
if sources(index).rv < g.rvrange(1)/100 | sources(index).rv > g.rvrange(2)/100
sources(index) = [];
end;
end;
end;
% color array
% -----------
if isempty(g.color)
g.color = { 'g' 'b' 'r' 'm' 'c' 'y' };
if strcmp(BACKCOLOR, 'w'), g.color = { g.color{:} 'k' }; end;
end;
g.color = g.color(mod(0:length(sources)-1, length(g.color)) +1);
if ~isempty(g.color)
g.color = strcol2real( g.color, jet(64) );
end;
if ~isempty(g.projcol)
g.projcol = strcol2real( g.projcol, jet(64) );
g.projcol = g.projcol(mod(0:length(sources)-1, length(g.projcol)) +1);
else
g.projcol = g.color;
for index = 1:length(g.color)
g.projcol{index} = g.projcol{index}/2;
end;
end;
% build summarized figure
% -----------------------
if strcmpi(g.summary, 'on') | strcmpi(g.summary, 'on2')
figure;
options = { 'gui', 'off', 'dipolesize', g.dipolesize/1.5,'dipolelength', g.dipolelength, 'sphere', g.sphere ...
'color', g.color, 'mesh', g.mesh, 'num', g.num, 'image', g.image 'normlen' g.normlen ...
'coordformat' g.coordformat 'mri' g.mri 'meshdata' g.meshdata 'axistight' g.axistight };
pos1 = [0 0 0.5 0.5];
pos2 = [0 0.5 0.5 .5];
pos3 = [.5 .5 0.5 .5]; if strcmp(g.summary, 'on2'), tmp = pos1; pos1 =pos3; pos3 = tmp; end;
axes('position', pos1); newsources = eeglab_dipplot(sourcesori, 'view', [1 0 0] , options{:}); axis off;
axes('position', pos2); newsources = eeglab_dipplot(sourcesori, 'view', [0 0 1] , options{:}); axis off;
axes('position', pos3); newsources = eeglab_dipplot(sourcesori, 'view', [0 -1 0], options{:}); axis off;
axes('position', [0.5 0 0.5 0.5]);
colorcount = 1;
if isfield(newsources, 'component')
for index = 1:length(newsources)
if isempty(g.dipnames), tmpname = sprintf( 'Comp. %d', newsources(index).component);
else tmpname = char(g.dipnames{index});
end;
talpos = newsources(index).talcoord;
if strcmpi(g.coordformat, 'CTF')
textforgui(colorcount) = { sprintf( [ tmpname ' (RV:%3.2f%%)' ], 100*newsources(index).rv) };
elseif size(talpos,1) == 1
textforgui(colorcount) = { sprintf( [ tmpname ' (RV:%3.2f%%; Tal:%d,%d,%d)' ], ...
100*newsources(index).rv, ...
round(talpos(1,1)), round(talpos(1,2)), round(talpos(1,3))) };
else
textforgui(colorcount) = { sprintf( [ tmpname ' (RV:%3.2f%%; Tal:%d,%d,%d & %d,%d,%d)' ], ...
100*newsources(index).rv, ...
round(talpos(1,1)), round(talpos(1,2)), round(talpos(1,3)), ...
round(talpos(2,1)), round(talpos(2,2)), round(talpos(2,3))) };
end;
colorcount = colorcount+1;
end;
colorcount = colorcount-1;
allstr = strvcat(textforgui{:});
h = text(0,0.45, allstr);
if colorcount >= 15, set(h, 'fontsize', 8);end;
if colorcount >= 20, set(h, 'fontsize', 6);end;
if strcmp(BACKCOLOR, 'k'), set(h, 'color', 'w'); end;
end;
axis off;
return;
elseif strcmpi(g.summary, '3d')
options = { 'gui', 'off', 'dipolesize', g.dipolesize/1.5,'dipolelength', g.dipolelength, 'sphere', g.sphere, 'spheres', g.spheres ...
'color', g.color, 'mesh', g.mesh, 'num', g.num, 'image', g.image 'normlen' g.normlen ...
'coordformat' g.coordformat 'mri' g.mri 'meshdata' g.meshdata 'axistight' g.axistight };
figure('position', [ 100 600 600 200 ]);
axes('position', [-0.1 -0.1 1.2 1.2], 'color', 'k'); axis off; blackimg = zeros(10,10,3); image(blackimg);
axes('position', [0 0 1/3 1], 'tag', 'rear'); eeglab_dipplot(sourcesori, options{:}, 'holdon', 'on'); view([0 -1 0]);
axes('position', [1/3 0 1/3 1], 'tag', 'top' ); eeglab_dipplot(sourcesori, options{:}, 'holdon', 'on'); view([0 0 1]);
axes('position', [2/3 0 1/3 1], 'tag', 'side'); eeglab_dipplot(sourcesori, options{:}, 'holdon', 'on'); view([1 -0.01 0]);
set(gcf, 'paperpositionmode', 'auto');
return;
end;
% plot head graph in 3D
% ---------------------
if strcmp(g.gui, 'on')
fig = figure('visible', g.plot);
pos = get(gca, 'position');
set(gca, 'position', [pos(1)+0.05 pos(2:end)]);
end;
indx = ceil(dat.imgcoords{1}(end)/2);
indy = ceil(dat.imgcoords{2}(end)/2);
indz = ceil(dat.imgcoords{3}(end)/2); indz=34;
if strcmpi(g.holdon, 'off')
plotimgs( dat, [indx indy indz], dat.transform);
set(gca, 'color', BACKCOLOR);
%warning off; a = imread('besaside.pcx'); warning on;
% BECAUSE OF A BUG IN THE WARP FUNCTION, THIS DOES NOT WORK (11/02)
%hold on; warp([], wy, wz, a);
% set camera target
% -----------------
% format axis (BESA or MRI)
axis equal;
set(gca, 'cameraviewanglemode', 'manual'); % disable change size
camzoom(1.2^2);
if strcmpi(g.coordformat, 'CTF'), g.view(2:3) = -g.view(2:3); end;
view(g.view);
%set(gca, 'cameratarget', dat.zeroloc); % disable change size
%set(gca, 'cameraposition', dat.zeroloc+g.view*g.zoom); % disable change size
axis off;
end;
% plot sphere mesh and nose
% -------------------------
if strcmpi(g.holdon, 'off')
if isempty(g.meshdata)
SPHEREGRAIN = 20; % 20 is also Matlab default
[x y z] = sphere(SPHEREGRAIN);
hold on;
[xx yy zz] = transform(x*0.085, y*0.085, z*0.085, dat.sph2spm);
[xx yy zz] = transform(x*85 , y*85 , z*85 , dat.sph2spm);
%xx = x*100;
%yy = y*100;
%zz = z*100;
if strcmpi(COLORMESH, 'w')
hh = mesh(xx, yy, zz, 'cdata', ones(21,21,3), 'tag', 'mesh'); hidden off;
else
hh = mesh(xx, yy, zz, 'cdata', zeros(21,21,3), 'tag', 'mesh'); hidden off;
end;
else
try,
if isstr(g.meshdata)
tmp = load('-mat', g.meshdata);
g.meshdata = { 'vertices' tmp.vol.bnd(1).pnt 'faces' tmp.vol.bnd(1).tri };
end;
%hh = patch(g.meshdata{:}, 'facecolor', 'none', 'edgecolor', COLORMESH, 'tag', 'mesh');
hh = patch(g.meshdata{:},'facecolor',[1,0.75,0.65],'EdgeColor','none','FaceAlpha',0.2)
lightangle(45,30);
lightangle(45+180,30);
set(hh, 'specularcolorreflectance', 0, 'specularexponent',50);
set(hh,'DiffuseStrength',.6,'SpecularStrength',0,...
'AmbientStrength',.4,'SpecularExponent',5);