Skip to content

Commit d0a0569

Browse files
committed
- bug fixes to bbox_tree.m (Alexandre Simard)
- bump version
1 parent 7d96f80 commit d0a0569

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

Basic/funcs/bbox_tree.m

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function [bbx] = bbox_tree(cas)
2-
%function [bbx] = bbox_tree(cas)
2+
% function [bbx] = bbox_tree(cas)
33
%
4-
% bbox_tree: calculate the boundary box of a GDSII structure tree
4+
% Calculates the boundary box of a GDSII structure tree
55
%
66
% Input:
77
% cas : a cell array of gds_structure objects
@@ -11,39 +11,40 @@
1111
% lower left and upper right corners of the bounding box.
1212

1313
% Initial version, Ulf Griesmann, December 2015
14+
% major bug fixes, Alexandre Simard, March 2021
1415

1516
% calculate boundary boxes before resolving the hierarchy
1617
% to minimize computations especially for leaf nodes
1718
caslen = numel(cas);
1819
bbdata = repmat(struct('bbox',[Inf,Inf,-Inf,-Inf], ...
19-
'ref',[]), caslen,1);
20+
'ref',[],'name',[]), caslen,1);
2021
for k = 1:caslen
2122
[bbdata(k).bbox, bbdata(k).ref] = bbox(cas{k});
23+
bbdata(k).name = get(cas{k},'sname');
2224
end
2325

2426
% find top level structure(s) - they have no parents
25-
A = adjmatrix(cas);
27+
[A,N] = adjmatrix(cas);
2628
T = find(sum(A)==0); % array with top parent indices
2729

2830
% calculate bounding boxes of all top level structures
2931
bbst = zeros(length(T),4);
3032
for k=1:length(T)
31-
bbst(k,:) = bbox_struct(A, bbdata, T(k));
33+
bbst(k,:) = bbox_struct(A, bbdata, T(k), N);
3234
end
3335

3436
bbx = [min(bbst(:,1:2),[],1),max(bbst(:,3:4),[],1)];
3537

3638
end
3739

3840

39-
function [bbst] = bbox_struct(A, bbdata, sidx)
41+
function [bbst] = bbox_struct(A, bbdata, sidx, N)
4042
%
4143
% This function is called recursively to apply strans
4244
% transformations to the pre-computed boundary boxes and to
4345
% calculate the boundary boxes for the resolved structure
4446
% hierarchy.
45-
%
46-
47+
%
4748
% indices of child structures referenced by structure sidx
4849
chi = find(A(sidx,:));
4950

@@ -60,20 +61,27 @@
6061
for k = 1:length(chi)
6162

6263
% recursively calculate boundary box of the referenced structures
63-
bbr = bbox_struct(A, bbdata, chi(k));
64+
bbr = bbox_struct(A, bbdata, chi(k), N);
6465

6566
% apply any transformations to the boundary box
66-
nref = length(bbdata(sidx).ref);
67+
68+
% Find the sref of this refrences structured
69+
refloc = bbdata(sidx).ref;
70+
ind = arrayfun(@(x)strcmp(N{chi(k)},x.sname), refloc, 'UniformOutput', false);
71+
ind = horzcat(ind{:});
72+
refloc = refloc(ind);
73+
74+
nref = length(refloc);
6775
b = zeros(nref,4);
6876
for m = 1:nref
69-
if isempty(bbdata(sidx).ref(m).adim) % sref
70-
b(m,:) = bbox_strans(bbr, bbdata(sidx).ref(m).strans);
77+
if isempty(refloc(m).adim) % sref
78+
b(m,:) = bbox_strans(bbr, refloc(m).strans);
7179
b(m,:) = b(m,:) + ...
72-
[bbdata(sidx).ref(m).xy, bbdata(sidx).ref(m).xy];
73-
else % aref
74-
b(m,:) = bbox_aref(bbr, bbdata(sidx).ref(m).strans, ...
75-
bbdata(sidx).ref(m).xy, ...
76-
bbdata(sidx).ref(m).adim);
80+
[refloc(m).xy, refloc(m).xy];
81+
else % aref
82+
b(m,:) = bbox_aref(bbr, refloc(m).strans, ...
83+
refloc(m).xy, ...
84+
refloc(m).adim);
7785
end
7886
end
7987

@@ -83,7 +91,6 @@
8391
% calculate the final boundary box
8492
B(k+1,:) = bbdata(sidx).bbox;
8593
bbst = [min(B(:,1:2),[],1), max(B(:,3:4),[],1)];
86-
8794
end
8895

8996

@@ -145,17 +152,17 @@
145152

146153

147154
function [box] = apply_strans(box, strans)
155+
156+
% reflection comes after rotation
157+
if isfield(strans,'reflect') && strans.reflect
158+
box(:,2) = -box(:,2);
159+
end
148160

149161
% first rotate
150162
if isfield(strans,'angle') && ~isempty(strans.angle) && strans.angle~=0
151163
box = poly_rotzd(box, strans.angle); % rotated box
152164
end
153-
154-
% reflection comes after rotation
155-
if isfield(strans,'reflect') && strans.reflect
156-
box(:,1) = -box(:,1);
157-
end
158-
165+
159166
% magnification
160167
if isfield(strans,'mag') && ~isempty(strans.mag)
161168
box = strans.mag * box;

Basic/gdsii_version.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
%
1717

1818
% toolbox version and version date
19-
tb_version = '145';
20-
tb_date = '2019 December 23';
19+
tb_version = '146';
20+
tb_date = '2021 March 28';
2121
ltb_ver = [tb_version, ' (', tb_date, ')'];
2222
if exist('OCTAVE_VERSION')
2323
interpreter = 'Octave';

0 commit comments

Comments
 (0)