This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Raith_element.m
1534 lines (1289 loc) · 168 KB
/
Raith_element.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
classdef Raith_element < handle
%
% obj=Raith_element('polygon',layer,uv,DF)
% obj=Raith_element('path',layer,uv,w,DF)
% obj=Raith_element('dot',layer,uv,DF)
% obj=Raith_element('arc',layer,uv_c,r,theta,angle,w,N,DF)
% obj=Raith_element('circle',layer,uv_c,r,w,N,DF)
% obj=Raith_element('ellipse',layer,uv_c,r,w,angle,N,DF)
% obj=Raith_element('text',layer,uv_0,h,angle,uv_align,textlabel,DF)
% obj=Raith_element('fbmspath',layer,uv,cvtr,w,DF)
% obj=Raith_element('fbmscircle',layer,uv_c,r,w,DF)
% obj=Raith_element('sref',name,uv_0,[mag,angle,reflect])
% obj=Raith_element('aref',name,uv_0,n_colrow,a_colrow,[mag,angle,reflect])
%
% Raith_element objects define low-level elements used to generate
% GDSII hierarchies for Raith beamwriting tools.
%
%
% Arguments:
%
% type - type of element: must be either 'polygon', 'path', 'dot', 'arc',
% 'circle', 'ellipse', 'text', 'fbmspath', 'fbmscircle', 'sref', or
% 'aref'
%
% The number and identity of the remaining arguments depends on type:
%
% 'polygon' (closed, filled polygon)
% layer - GDSII layer for element (0-63)
% uv - polygon vertices; 2 x n matrix [u;v] (um)
% DF - dose factor for polygon
%
% 'path' (path of line segments)
% layer - GDSII layer for element (0-63)
% uv - path vertices; 2 x n matrix [u;v] (um)
% w - width of path (um); value of zero yields single-pixel line; a
% negative value denotes an absolute width (not affected by
% magnification of any parent structure)
% DF - dose factor for path
%
% 'dot' (single-pixel dot(s))
% layer - GDSII layer for element (0-63)
% uv - dot position(s); 2 x n matrix [u;v] (um)
% DF - dose factor(s) for dot(s); if scalar, DF is applied to all
% dots specified by uv; if vector, must be of same length as uv
%
% 'arc' (segment of circular or elliptical path; Raith curved element)
% layer - GDSII layer for element (0-63)
% uv_c - arc centre; 1 x 2 vector [u_c v_c] (um)
% r - radius of arc; may be scalar for a circular arc, or a 1 x 2
% vector, [semi-major semi-minor] axes of an elliptical arc (um)
% theta - starting and ending angles of arc w.r.t. axis defined by
% angle argument; 1 x 2 vector [theta_1 theta_2] (degrees)
% angle - angle of rotation between positive u-axis and theta = 0
% axis (degrees)
% w - width of arc (um); if empty, arc is a filled elliptical disk
% segment; if zero, arc is a single-pixel line; if non-zero, arc
% has a width; a negative value denotes an absolute width (not
% affected by magnification of any parent structure)
% N - number of vertices
% DF - dose factor for arc
%
% 'circle' (circular Raith curved element)
% layer - GDSII layer for element (0-63)
% uv_c - circle centre; 1 x 2 vector [u_c v_c] (um)
% r - radius of circle (um)
% w - width of circle (um); if empty, circle is filled (disk); if
% zero, circle is a single-pixel line; if greater than zero,
% circle has a width; a negative value denotes an absolute width
% (not affected by magnification of any parent structure)
% N - number of vertices
% DF - dose factor for circle
%
% 'ellipse' (elliptical Raith curved element)
% layer - GDSII layer for element (0-63)
% uv_c - ellipse centre; 1 x 2 vector [u_c v_c] (um)
% r - 1 x 2 vector, [semi-major semi-minor] axes of ellipse (um)
% w - width of ellipse (um); if empty, ellipse is filled (elliptical
% disk); if zero, ellipse is a single-pixel line; if greater than
% zero, ellipse has a width; a negative value denotes an absolute
% width (not affected by magnification of any parent structure)
% angle - angle between semi-major axis and u axis (degrees)
% N - number of vertices
% DF - dose factor for ellipse
%
% 'text' (text rendered as simply-connected polygons)
% layer - GDSII layer for element (0-63)
% uv_0 - text anchor point [u_0 v_0] (um)
% h - height of capital letters (um)
% angle - angle of rotation of text w.r.t. positive u-axis (degrees)
% uv_align - alignment w.r.t. anchor point; 1 x 2 vector
% [u_align v_align]; allowed values are 0 (left/top), 1 (centre),
% 2 (right/bottom)
% textlabel - the text to be written (string); allowed characters are
% `1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./~
% !@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?µ and [space]
% DF - dose factor for text
%
% 'fbmspath' (fixed beam moving stage path of line or arc segments)
% layer - GDSII layer for element (0-63)
% uv - path vertices; 2 x n matrix [u;v] (um)
% cvtr - curvature of path segments (um); if scalar and zero, the path
% comprises line segments (no curvature); if a 1 x n vector,
% cvtr(k) yields a circular arc with chord endpoints of uv(:,k-1)
% and uv(:,k) such that the radial distance between the arc and
% the chord centre is cvtr(k); a positive (negative) value of
% cvtr(k) corresponds to an arc to the left (right) of the chord;
% the value of cvtr(1) is ignored if cvtr is 1 x n
% w - width of path (um); if zero, path is a single-pixel line (no
% beam raster); if greater than zero, circle has a width (beam
% rastered during stage motion)
% DF - dose factor for path
%
% 'fbmscircle' (fixed beam moving stage circle)
% layer - GDSII layer for element (0-63)
% uv_c - circle centre; 1 x 2 vector [u_c v_c] (um)
% r - radius of circle (um)
% w - width of circle (um); if zero, circle is a single-pixel line
% (no beam raster); if greater than zero, circle has a width
% (beam rastered during stage motion)
% DF - dose factor for circle
%
% 'sref' (structure reference)
% N.B.! Transformations are applied in the following order: 1. scaling,
% mirroring; 2. rotation; 3. insertion.
% name - name of structure being referenced (string)
% uv_0 - structure origin; 1 x 2 vector [u_0 v_0] (um)
% mag - magnification factor [optional]; default is no magnification
% (mag = 1)
% angle - angle of rotation, counter-clockwise positive (degrees)
% [optional]; default is no rotation (angle = 0)
% reflect - Boolean flag for reflecting about u axis before other
% transformations [optional]; default is no reflection
% (reflect = 0)
%
% 'aref' (array reference)
% N.B.! Raith interprets aref objects differently than the GDSII
% specification (e.g., as displayed using KLayout). Given the number and
% spacing of rows and columns, a lattice of instance origins is
% generated, then rotation is applied to this lattice (if specified). At
% each of these lattice points, a structure is placed, after first being
% scaled and/or rotated.
% name - name of structure being referenced (string)
% uv_0 - structure origin; 1 x 2 vector [u_0 v_0] (um)
% n_colrow - 1 x 2 vector indicating number of columns and rows,
% respectively
% a_colrow - 1 x 2 vector indicating lattice spacing in rows and
% columns, respectively (um)
% mag - magnification factor [optional]; default is no magnification
% (mag = 1)
% angle - angle of rotation, counter-clockwise positive (degrees)
% [optional]; default is no rotation (angle = 0)
% reflect - Boolean flag for reflecting about u axis before other
% transformations [optional]; default is no reflection
% (reflect = 0)
%
%
% Properties:
%
% type - type of element: 'polygon', 'path', 'dot', 'arc', 'circle',
% 'ellipse', 'text', 'fbmspath', 'fbmscircle', 'sref', or 'aref'
% data - remaining record data for element (depends on element type)
%
%
% Methods:
%
% plot([M,scDF]) - plot element with Raith dose factor colouring (filled
% polygons where applicable)
% M - augmented transformation matrix for plot [optional]
% scDF - overall multiplicative scaling factor for DF specified
% in obj.data.DF (e.g., passed from a positionlist entry)
% [optional]
%
% plotedges([M,scDF]) - plot element with Raith dose factor colouring
% (edges of polygons where applicable)
% M - augmented transformation matrix for plot [optional]
% scDF - overall multiplicative scaling factor for DF specified
% in obj.data.DF (e.g., passed from a positionlist entry)
% [optional]
%
%
% Aaron Hryciw
% 2013-03-07
%
% Version 1.2
% 2014-10-07
%
%
% The Raith_GDSII MATLAB toolbox was developed at the National Institute
% for Nanotechnology (NINT), a joint initiative between the Government of
% Canada, the Government of Alberta, the National Research Council (NRC),
% and the University of Alberta. If is currently maintained by the
% University of Alberta nanoFAB facility.
%
% This Source Code Form is subject to the terms of the Mozilla Public
% License, v. 2.0. If a copy of the MPL was not distributed with this
% file, you can obtain one at http://mozilla.org/MPL/2.0/.
%
properties
type
data
end
methods
function obj=Raith_element(Type,varargin)
if nargin>0
switch lower(Type)
case {'polygon','dot'} % Arguments: layer, uv, DF
if nargin~=4 % Check for correct number of arguments
error(['Construct a Raith_element ' Type ' as: Raith_element(''' Type ''',layer,uv,DF).'])
else
Data.layer=varargin{1};
Data.uv=varargin{2}; % Round uv to nearest nm (1 nm data grid for Raith)
Data.DF=varargin{3}; % Round DF to nearest thousandth (precision expected by Raith GDSII)
end % polygon
case 'path' % Arguments: layer, uv, w, DF
if nargin~=5
error('Construct a Raith_element path as: Raith_element(''path'',layer,uv,w,DF).')
else
Data.layer=varargin{1};
Data.uv=varargin{2};
Data.w=varargin{3};
Data.DF=varargin{4};
end % path
case 'arc' % Arguments: layer, uv_c, r, theta, angle, w, N, DF
if nargin~=9
error('Construct a Raith_element arc as: Raith_element(''arc'',layer,uv_c,r,theta,angle,w,N,DF).')
else
Data.layer=varargin{1};
Data.uv_c=varargin{2};
Data.r=varargin{3};
Data.theta=varargin{4};
Data.angle=varargin{5};
Data.w=varargin{6};
Data.N=varargin{7};
Data.DF=varargin{8};
end % arc
case 'circle' % Arguments: layer, uv_c, r, w, N, DF
if nargin~=7
error('Construct a Raith_element circle as: Raith_element(''circle'',layer,uv_c,r,w,N,DF).')
else
Data.layer=varargin{1};
Data.uv_c=varargin{2};
Data.r=varargin{3};
Data.w=varargin{4};
Data.N=varargin{5};
Data.DF=varargin{6};
end % circle
case 'ellipse' % Arguments: layer, uv_c, r, w, angle, N, DF
if nargin~=8
error('Construct a Raith_element ellipse as: Raith_element(''ellipse'',layer,uv_c,r,w,angle,N,DF).')
else
Data.layer=varargin{1};
Data.uv_c=varargin{2};
Data.r=varargin{3};
Data.w=varargin{4};
Data.angle=varargin{5};
Data.N=varargin{6};
Data.DF=varargin{7};
end % ellipse
case 'text' % Arguments: layer, uv_0, h, angle, uv_align, textlabel, DF
if nargin~=8
error('Construct a Raith_element text as: Raith_element(''text'',layer,uv_0,h,angle,uv_align,textlabel,DF).')
else
Data.layer=varargin{1};
Data.uv_0=varargin{2};
Data.h=varargin{3};
Data.angle=varargin{4};
Data.uv_align=varargin{5};
Data.textlabel=varargin{6};
Data.DF=varargin{7};
end % text
case 'fbmspath' % Arguments: layer, uv, cvtr, w, DF
if nargin~=6
error('Construct a Raith_element fbmspath as: Raith_element(''fbmspath'',layer,uv,cvtr,w,DF).')
else
Data.layer=varargin{1};
Data.uv=varargin{2};
Data.cvtr=varargin{3};
Data.w=varargin{4};
Data.DF=varargin{5};
end % fbmspath
case 'fbmscircle' % Arguments: layer, uv_c, r, w, DF
if nargin~=6
error('Construct a Raith_element fbmscircle as: Raith_element(''fbmscircle'',layer,uv_c,r,w,DF).')
else
Data.layer=varargin{1};
Data.uv_c=varargin{2};
Data.r=varargin{3};
Data.w=varargin{4};
Data.DF=varargin{5};
end % fbmscircle
case 'sref' % Arguments: name, uv_0, [mag, angle, reflect]
if nargin<3 || nargin>6
error('Construct a Raith_element structure reference as: Raith_element(''sref'',name,uv_0,[mag,angle,reflect]).')
else
Data.name=varargin{1};
Data.uv_0=varargin{2};
% Defaults for transformations
Data.mag=1;
Data.angle=0;
Data.reflect=0;
if nargin>3 % Mag specified
if ~isempty(varargin{3})
Data.mag=varargin{3};
end
end
if nargin>4 % Mag and angle specified
if ~isempty(varargin{4})
Data.angle=varargin{4};
end
end
if nargin>5 % Mag, angle, and reflect specified
if ~isempty(varargin{5})
Data.reflect=varargin{5};
end
end
end % sref
case 'aref' % Arguments: name, uv_0, n_colrow, a_colrow, [mag, angle, reflect]
if nargin<5 && nargin>8
error('Construct a Raith_element array reference as: Raith_element(''aref'',name,uv_0,n_colrow,a_colrow,[mag,angle,reflect]).')
else
Data.name=varargin{1};
Data.uv_0=varargin{2};
Data.n_colrow=varargin{3};
Data.a_colrow=varargin{4};
% Defaults for transformations
Data.mag=1;
Data.angle=0;
Data.reflect=0;
if nargin>5 % Mag specified
if ~isempty(varargin{5})
Data.mag=varargin{5};
end
end
if nargin>6 % Mag and angle specified
if ~isempty(varargin{6})
Data.angle=varargin{6};
end
end
if nargin>7 % Mag, angle, and reflect specified
if ~isempty(varargin{7})
Data.reflect=varargin{7};
end
end
end % aref
otherwise
error('Raith_element type must be ''polygon'', ''path'', ''dot'', ''circle'', ''ellipse'', ''text'', ''fbmspath'', ''fbmscircle'', ''sref'', or ''aref''.');
end
obj.type=Type;
obj.data=Data;
end
end % Constructor
function set.type(obj,Type)
Type=lower(Type);
global checkdata; % Global variable for argument checking
if checkdata==false
obj.type=Type;
else
if ~any(strcmp(Type,{'polygon','path','dot','arc','circle','ellipse','text','fbmspath','fbmscircle','sref','aref'}))
error('Raith_element type must be ''polygon'', ''path'', ''dot'', ''circle'', ''ellipse'', ''text'', ''fbmspath'', ''fbmscircle'', ''sref'', or ''aref''.')
end
obj.type=Type;
% Fill data with default fields, depending on type
switch obj.type
case {'polygon','dot'}
Data.layer=[];
Data.uv=[];
Data.DF=[];
case 'path'
Data.layer=[];
Data.uv=[];
Data.w=[];
Data.DF=[];
case 'arc'
Data.layer=[];
Data.uv_c=[];
Data.r=[];
Data.theta=[];
Data.angle=[];
Data.w=[];
Data.N=[];
Data.DF=[];
case 'circle'
Data.layer=[];
Data.uv_c=[];
Data.r=[];
Data.w=[];
Data.N=[];
Data.DF=[];
case 'ellipse'
Data.layer=[];
Data.uv_c=[];
Data.r=[];
Data.w=[];
Data.angle=[];
Data.N=[];
Data.DF=[];
case 'text'
Data.layer=[];
Data.uv_0=[];
Data.h=[];
Data.angle=[];
Data.uv_align=[];
Data.textlabel=[];
Data.DF=[];
case 'fbmspath'
Data.layer=[];
Data.uv=[];
Data.cvtr=[];
Data.w=[];
Data.DF=[];
case 'fbmscircle'
Data.layer=[];
Data.uv_c=[];
Data.r=[];
Data.w=[];
Data.DF=[];
case 'sref'
Data.name=[];
Data.uv_0=[];
Data.mag=[];
Data.angle=[];
Data.reflect=[];
case 'aref'
Data.name=[];
Data.uv_0=[];
Data.n_colrow=[];
Data.a_colrow=[];
Data.mag=[];
Data.angle=[];
Data.reflect=[];
end
obj.data=Data;
end
end % set.type
function set.data(obj,Data)
% Check that type is already assigned
if isempty(obj.type)
error('Raith_element: type must be set before data.');
end
if isempty(Data) % Clear all fields from obj.data
obj.data=struct;
return;
end
datafields=fieldnames(Data); % Cell array of all fields
global checkdata; % Global variable for argument checking
if checkdata==false % Round data as necessary, but do not otherwise check
for k=1:length(datafields)
switch datafields{k}
case 'uv'
Data.uv=round(Data.uv*1000)/1000; % Round uv to nearest nm (1 nm data grid for Raith)
case 'DF'
Data.DF=round(Data.DF*1000)/1000; % Round DF to nearest thousandth (precision expected by Raith GDSII)
case 'uv_c'
Data.uv_c=round(Data.uv_c*1000)/1000; % Round uv_c to nearest nm (1 nm data grid for Raith)
case 'r'
Data.r=round(Data.r*1000)/1000; % Round r to nearest nm (1 nm data grid for Raith)
case 'cvtr'
Data.cvtr=round(Data.cvtr*1000)/1000; % Round cvtr to nearest nm (1 nm data grid for Raith)
case 'w'
Data.w=round(Data.w*1000)/1000; % Round w to nearest nm (1 nm data grid for Raith)
case 'h'
Data.h=round(Data.h*1000)/1000; % Round h to nearest nm (1 nm data grid for Raith)
case 'uv_0'
Data.uv_0=round(Data.uv_0*1000)/1000; % Round uv_0 to nearest nm (1 nm data grid for Raith)
case 'a_colrow'
Data.a_colrow=round(Data.a_colrow*1000)/1000; % Round a_colrow to nearest nm (1 nm data grid for Raith)
end
end
else % Check all data
switch lower(obj.type) % Check for illegal field(s)
case 'polygon' % data fields: layer, uv, DF
if ~isempty(setdiff(datafields,{'layer','uv','DF'})) % Trying to set illegal field(s) for polygon
error('Raith_element: allowed data fields for ''polygon'' element type are ''layer'', ''uv'', and ''DF''.');
end
case 'path' % data fields: layer, uv, w, DF
if ~isempty(setdiff(datafields,{'layer','uv','w','DF'})) % Trying to set illegal field(s) for path
error('Raith_element: allowed data fields for ''path'' element type are ''layer'', ''uv'', ''w'', and ''DF''.');
end
case 'dot' % data fields: layer, uv, DF
if ~isempty(setdiff(datafields,{'layer','uv','DF'})) % Trying to set illegal field(s) for dot
error('Raith_element: allowed data fields for ''dot'' element type are ''layer'', ''uv'', and ''DF''.');
end
case 'arc' % data fields: layer, uv_c, r, theta, angle, w, N, DF
if ~isempty(setdiff(datafields,{'layer','uv_c','r','theta','angle','w','N','DF'})) % Trying to set illegal field(s) for arc
error('Raith_element: allowed data fields for ''arc'' element type are ''layer'', ''uv_c'', ''r'', ''theta'', ''angle'', ''w'', ''N'', and ''DF''.');
end
case 'circle' % data fields: layer, uv_c, r, w, N, DF
if ~isempty(setdiff(datafields,{'layer','uv_c','r','w','N','DF'})) % Trying to set illegal field(s) for circle
error('Raith_element: allowed data fields for ''circle'' element type are ''layer'', ''uv_c'', ''r'', ''w'', ''N'', and ''DF''.');
end
case 'ellipse' % data fields: layer, uv_c, r, w, angle, N, DF
if ~isempty(setdiff(datafields,{'layer','uv_c','r','w','angle','N','DF'})) % Trying to set illegal field(s) for ellipse
error('Raith_element: allowed data fields for ''ellipse'' element type are ''layer'', ''uv_c'', ''r'', ''w'', ''angle'', ''N'', and ''DF''.');
end
case 'text' % data fields: layer, uv_0, h, angle, uv_align, textlabel, DF
if ~isempty(setdiff(datafields,{'layer','uv_0','h','angle','uv_align','textlabel','DF'})) % Trying to set illegal field(s) for text
error('Raith_element: allowed data fields for ''text'' element type are ''layer'', ''uv_0'', ''h'', ''angle'', ''uv_align'', ''textlabel'', and ''DF''.');
end
case 'fbmspath' % data fields: layer, uv, cvtr, w, DF
if ~isempty(setdiff(datafields,{'layer','uv','cvtr','w','DF'})) % Trying to set illegal field(s) for fbmspath
error('Raith_element: allowed data fields for ''fbmspath'' element type are ''layer'', ''uv'', ''cvtr'', ''w'', and ''DF''.');
end
case 'fbmscircle' % data fields: layer, uv_c, r, w, DF
if ~isempty(setdiff(datafields,{'layer','uv_c','r','w','DF'})) % Trying to set illegal field(s) for fbmscircle
error('Raith_element: allowed data fields for ''fbmscircle'' element type are ''layer'', ''uv_c'', ''r'', ''w'', and ''DF''.');
end
case 'sref' % data fields: name, uv_0, mag, angle, reflect
if ~isempty(setdiff(datafields,{'name','uv_0','mag','angle','reflect','DF'})) % Trying to set illegal field(s) for sref
error('Raith_element: allowed data fields for ''sref'' element type are ''layer'', ''uv_0'', ''mag'', ''angle'', and ''reflect''.');
end
case 'aref' % data fields: name, uv_0, n_colrow, a_colrow, mag, angle, reflect
if ~isempty(setdiff(datafields,{'name','uv_0','n_colrow','a_colrow','mag','angle','reflect','DF'})) % Trying to set illegal field(s) for aref
error('Raith_element: allowed data fields for ''aref'' element type are ''layer'', ''uv_0'', ''n_colrow'', ''a_colrow'', ''mag'', ''angle'', and ''reflect''.');
end
end
% Argument checking for all data fields
for k=1:length(datafields)
f=getfield(Data,datafields{k});
if ~isempty(f)
% Check for infinities and NaNs
if any(isnan(f(:))) || any(isinf(f(:)))
error(['Raith_element ' obj.type ': ' datafields{k} ' must be finite.'])
end
switch datafields{k}
case 'layer'
% Check that layer is an integer between 0 and 63 (may be stored as a float, but must have no fraction part)
if ~isnumeric(Data.layer) || floor(Data.layer)~=Data.layer || Data.layer<0 || Data.layer>63
error(['Raith_element ' obj.type ': layer must be an integer between 0 and 63 (inclusive).']);
end
case 'uv'
% Check size of uv
if ~isnumeric(Data.uv) || size(Data.uv,1)~=2
error(['Raith_element ' obj.type ': uv must a 2 x n matrix.']);
end
Data.uv=round(Data.uv*1000)/1000; % Round uv to nearest nm (1 nm data grid for Raith)
switch obj.type
case 'polygon'
% Check for closedness and correct if not (with warning)
if any(Data.uv(:,1)~=Data.uv(:,end))
warning('Raith_element:openPolygon','Raith_element polygon is open; closing polygon.')
Data.uv(:,end+1)=Data.uv(:,1);
end
case {'path','fbmspath'}
% Check that uv contains at least two vertices
if size(Data.uv,2)<2
error(['Raith_element ' obj.type ': uv must contain at least two vertices.']);
end
end
case 'DF'
if strcmp(obj.type,'dot')
% Check that DF is either scalar or a vector of the same length as uv
if ~isnumeric(Data.DF) || ~isvector(Data.DF) || (length(Data.DF)~=size(Data.uv,2) && length(Data.DF)~=1)
error('Raith_element dot: DF must either be scalar or a vector of length size(data.uv,2).')
end
else
% Check that DF is scalar
if ~isnumeric(Data.DF) || ~isscalar(Data.DF)
error(['Raith_element ' obj.type ': DF must be a scalar.'])
end
end
if any(Data.DF<0)
error(['Raith_element ' obj.type ': DF must be non-negative.']);
end
Data.DF=round(Data.DF*1000)/1000; % Round DF to nearest thousandth (precision expected by Raith GDSII)
case 'uv_c'
% Check that uv_c is a vector of length 2
if ~isnumeric(Data.uv_c) || ~isvector(Data.uv_c) || length(Data.uv_c)~=2
error(['Raith_element ' obj.type ': uv_c must be a vector of length 2.'])
end
Data.uv_c=round(Data.uv_c*1000)/1000; % Round uv_c to nearest nm (1 nm data grid for Raith)
case 'r'
if strcmp(obj.type,'circle') || strcmp(obj.type,'fbmscircle')
% Check that r is scalar
if ~isnumeric(Data.r) || ~isscalar(Data.r) || Data.r<=0
error(['Raith_element ' obj.type ': r must be a positive scalar.'])
end
elseif strcmp(obj.type,'ellipse')
% Check that r is a vector of length 2
if ~isnumeric(Data.r) || ~isvector(Data.r) || length(Data.r)~=2 || any(Data.r<=0)
error('Raith_element ellipse: r must be a vector of length 2, with positive elements.')
end
else % Arc
% Check that r is either scalar or a vector of length 2
if ~isnumeric(Data.r) || ~isvector(Data.r) || ~any(length(Data.r)==[1 2]) || any(Data.r<=0)
error('Raith_element arc: r must be a vector of length 1 or 2, with positive elements.')
end
end
Data.r=round(Data.r*1000)/1000; % Round r to nearest nm (1 nm data grid for Raith)
case 'cvtr'
% Check that cvtr is either 0 or a vector of the same length as uv
if ~isnumeric(Data.cvtr) || ~isvector(Data.cvtr) || (length(Data.cvtr)~=size(Data.uv,2) && length(Data.cvtr)~=1) || (isscalar(Data.cvtr) && Data.cvtr~=0)
error('Raith_element fbmspath: cvtr must either be 0 or a vector of length size(data.uv,2).')
end
Data.cvtr=round(Data.cvtr*1000)/1000; % Round cvtr to nearest nm (1 nm data grid for Raith)
case 'w'
% Check that w is scalar (may be negative)
if ~isnumeric(Data.w) || ~isscalar(Data.w)
error(['Raith_element ' obj.type ': w must be a numeric scalar.'])
end
Data.w=round(Data.w*1000)/1000; % Round w to nearest nm (1 nm data grid for Raith)
case 'h'
% Check that h is scalar and positive
if ~isnumeric(Data.h) || ~isscalar(Data.h) || Data.h<=0
error('Raith_element text: h must be a positive scalar.')
end
Data.h=round(Data.h*1000)/1000; % Round h to nearest nm (1 nm data grid for Raith)
case 'N'
% Check that N is an integer greater than 2
if ~isnumeric(Data.N) || ~isscalar(Data.N) || round(Data.N)~=Data.N || Data.N<3
error(['Raith_element ' obj.type ': N must be an integer greater than 2.'])
end
case 'angle'
% Check that angle is scalar
if ~isnumeric(f) || ~isscalar(f)
error(['Raith_element ' obj.type ': angle must be a numeric scalar.'])
end
case 'name'
% Check that name is a string
if ~ischar(Data.name)
error(['Raith_element ' obj.type ': name must be a string.'])
end
case 'textlabel'
% Check that textlabel is a string
if ~ischar(Data.textlabel)
error('Raith_element text: textlabel must be a string.')
end
% Check for illegal characters
illegals=setdiff(Data.textlabel,obj.chars);
if ~isempty(illegals) % Trying to use illegal characters in textlabel
if length(illegals)==1 % For unnecessary elegance, format error message according to number of illegal characters.
ch='character ';
be=' is';
else
ch='characters ';
be=' are';
illegals=sprintf('%c,',illegals(1:end-1));
illegals=[illegals ' and ' illegals(end)];
end
error(['Raith_element text: ' ch illegals be ' not allowed in textlabel.'])
end
case 'uv_0'
% Check that uv_0 is a vector of length 2
if ~isnumeric(Data.uv_0) || ~isvector(Data.uv_0) || length(Data.uv_0)~=2
error(['Raith_element ' obj.type ': uv_0 must be a vector of length 2.'])
end
Data.uv_0=round(Data.uv_0*1000)/1000; % Round uv_0 to nearest nm (1 nm data grid for Raith)
case 'theta'
% Check that theta is a vector of length 2
if ~isnumeric(Data.theta) || ~isvector(Data.theta) || length(Data.theta)~=2
error('Raith_element arc: theta must be a vector of length 2.')
end
case 'mag'
% Check that mag is a positive scalar
if ~isnumeric(Data.mag) || ~isscalar(Data.mag) || Data.mag<=0
error(['Raith_element ' obj.type ': mag must be a positive scalar.'])
end
case 'reflect'
% Check that reflect is either 0 or 1
if Data.reflect~=1 && Data.reflect~=0
error(['Raith_element ' obj.type ': reflect must be either 0 or 1.'])
end
case 'uv_align'
% Check that uv_align is a vector of length 2
if ~isnumeric(Data.uv_align) || ~isvector(Data.uv_align) || length(Data.uv_align)~=2
error('Raith_element text: uv_align must be a vector of length 2.')
end
% Check that uv_align is either 0, 1, or 2
if ~isempty(setdiff(Data.uv_align,[0 1 2]))
error('Raith_element text: allowed values for uv_align elements are 0, 1, and 2.')
end
case 'n_colrow'
% Check that n_colrow is a vector of length 2
if ~isnumeric(Data.n_colrow) || ~isvector(Data.n_colrow) || length(Data.n_colrow)~=2
error('Raith_element aref: n_colrow must be of the form [n_columns n_rows].')
end
% Check that n_colrow elements are integers (though they may be stored as floats)
if ~all(round(Data.n_colrow)==Data.n_colrow)
error('Raith_element aref: n_colrow elements must be integers.')
end
case 'a_colrow'
% Check that a_colrow is a vector of length 2
if ~isnumeric(Data.a_colrow) || ~isvector(Data.a_colrow) || length(Data.a_colrow)~=2
error('Raith_element aref: a_colrow must be of the form [column_spacing row_spacing].')
end
Data.a_colrow=round(Data.a_colrow*1000)/1000; % Round a_colrow to nearest nm (1 nm data grid for Raith)
end
end
end
end
obj.data=Data;
end % set.data
function plot(obj,varargin)
%
% Raith_element.plot([M,scDF])
%
% Plot element with Raith dose factor colouring (filled polygons where applicable)
%
% Argument:
%
% M - augmented transformation matrix for plot [optional]
% scDF - overall multiplicative scaling factor for DF specified
% in obj.data.DF (e.g., passed from a positionlist entry)
% [optional]
%
if nargin==1
M=[];
scDF=1; % Scaling for DF specified in obj.data.DF
elseif nargin==2
M=varargin{1};
scDF=1;
elseif nargin==3
M=varargin{1};
scDF=varargin{2};
else
error('Raith_element.plot: Too many input arguments.');
end
if isempty(M)
M=eye(3); % Identity matrix (no transformations)
end
if isempty(scDF)
scDF=1; % Empty scDF defaults to unity
end
if ~all(size(M)==[3 3])
error('Raith_element.plot: augmented transformation matrix must be 3 x 3.');
end
if scDF<0
error('Raith_element.plot: scDF must be non-negative.')
end
hold on
obj.renderplot(M,scDF,1);
end % plot
function plotedges(obj,varargin)
%
% Raith_element.plotedges([M,scDF])
%
% Plot element with Raith dose factor colouring (edges of polygons where applicable)
%
% Argument:
%
% M - augmented transformation matrix for plot [optional]
% scDF - overall multiplicative scaling factor for DF specified
% in obj.data.DF (e.g., passed from a positionlist entry)
% [optional]
%
if nargin==1
M=[];
scDF=1; % Scaling for DF specified in obj.data.DF
elseif nargin==2
M=varargin{1};
scDF=1;
elseif nargin==3
M=varargin{1};
scDF=varargin{2};
else
error('Raith_element.plotedges: Too many input arguments.');
end
if isempty(M)
M=eye(3); % Identity matrix (no transformations)
end
if isempty(scDF)
scDF=1; % Empty scDF defaults to unity
end
if ~all(size(M)==[3 3])
error('Raith_element.plotedges: augmented transformation matrix must be 3 x 3.');
end
if scDF<0
error('Raith_element.plotedges: scDF must be non-negative.')
end
obj.renderplot(M,scDF,0);
end % plotedges
end % methods
methods(Hidden)
function UV=renderplot(obj,M,scDF,plflag)
%
% UV=Raith_element.renderplot(obj,M,scDF,plflag)
%
% Plot element with Raith dose factor colouring (called from
% Raith_element.plot or Raith_element.plotedges)
%
% If plflag==1, plot as filled polygons where applicable
% (Raith_element.plot). If plflag==0, plot as polygon outlines where
% applicable (Raith_element.plotedges). If plflag==2, do not
% plot, but only return UV.
%
% Arguments:
%
% M - augmented transformation matrix for plot
% scDF - overall multiplicative scaling factor for DF specified
% in obj.data.DF (e.g., passed from a positionlist entry)
% plflag - flag for type of plot (1 for .plot, 0 for .plotedges)
%
%
% Return value:
%
% UV - 2 x n matrix [u;v] of points being plotted (um); for paths
% with nonzero width, returns points of underlying path;
% required by Raith_library.writegds for plain GDSII export
hold on
switch obj.type
case 'polygon'
UV=M*[obj.data.uv;ones(1,size(obj.data.uv,2))];
if plflag==1
fill(UV(1,:),UV(2,:),obj.RaithDF(obj.data.DF*scDF),'EdgeColor','none');
elseif plflag==0
plot(UV(1,:),UV(2,:),'color',obj.RaithDF(obj.data.DF*scDF));
else % plflag==2
% Do not plot
end
case 'path'
mag=sqrt(abs(det(M))); % Total magnification
UV=M*[obj.data.uv;ones(1,size(obj.data.uv,2))];
w=obj.data.w;
if w>0
w=abs(w)*mag; % Positive w, so scale with everything else
else % Negative w: default to zero (Raith software interpretation)
w=0;
end
if plflag~=2
if w==0 % Single-pixel line
plot(UV(1,:),UV(2,:),'color',obj.RaithDF(obj.data.DF*scDF));
else % Finite-thickness line
[outx,outy]=obj.plotpathwidth(UV(1,:),UV(2,:),w);
if plflag==1
fill(outx,outy,obj.RaithDF(obj.data.DF*scDF),'EdgeColor','none');
elseif plflag==0
plot(outx,outy,'color',obj.RaithDF(obj.data.DF*scDF));
end
end
end
case 'dot'
if isscalar(obj.data.DF)
DF=obj.data.DF*scDF*ones(1,size(obj.data.uv,2));
else
DF=obj.data.DF*scDF;
end
UV=M*[obj.data.uv;ones(1,size(obj.data.uv,2))];
if plflag~=2
for k=1:size(obj.data.uv,2)
plot(UV(1,k),UV(2,k),'.','color',obj.RaithDF(DF(k)));
end
end
case 'arc'
mag=sqrt(abs(det(M))); % Total magnification
w=obj.data.w;
if w>=0
w=w*mag; % Positive w, so scale with everything else
else % Negative w: default to filled element (Raith behaviour)
w=[];
end
if length(obj.data.r)==1 % Circular arc
r=obj.data.r*[1 1];
else % Elliptical arc