Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary reader for Matlab #235

Merged
merged 12 commits into from
Feb 23, 2019
4 changes: 2 additions & 2 deletions src/matlab/add_patch2slice.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function add_patch2slice(sdir,sval,snum,xc,yc,zc, xe,ye,ze, q,level,...
contourlevels,mappedgrid,manifold,maskflag,grid_number,blockno,...
colormapping);
colormapping)

% Internal matlab routine for Clawpack graphics.

Expand All @@ -13,7 +13,7 @@ function add_patch2slice(sdir,sval,snum,xc,yc,zc, xe,ye,ze, q,level,...
% Mask any patches that might be underneath the new patch we want to add.
if (maskflag == 1)
mask_patches(slice,sdir,level,xe(1),xe(end),ye(1),ye(end),ze(1),ze(end));
end;
end

% Get the new patch
new_patch = create_patch(xc,yc,zc,xe,ye,ze,q,sdir,sval,contourlevels,...
Expand Down
86 changes: 43 additions & 43 deletions src/matlab/create_clines.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,52 @@
global creatingclines

if (isempty(c))
% No contour lines on this patch
h = [];
return;
end;
% No contour lines on this patch
h = [];
return;
end

st_idx = 1;
line_cnt = 0;
while (1)
cval = c(1,st_idx);
next_length = c(2,st_idx);
line_cnt = line_cnt + 1;
x_like = zeros(1,next_length) + sval;
y_like = c(1,st_idx+1:st_idx+next_length);
z_like = c(2,st_idx+1:st_idx+next_length);

[xdata,ydata,zdata] = get_xyz(x_like,y_like,z_like,sdir);

udata.cartCoords = [xdata', ydata', zdata'];
if (mappedgrid == 1 | manifold == 1)
if (mappedgrid == 1)
if (nargin('mapc2p') == 2)
[xdata,ydata] = mapc2p(xdata,ydata);
else
[xdata, ydata, zdata] = mapc2p(xdata,ydata,zdata);
end;
end;
if (manifold == 1)
creatingclines = 1; % flag for mapc2m to indicate contour lines
% are being generated: may want to shift off
% manifold slightly to avoid hidden line removal
% causing apparent gaps in contours.
set_blocknumber(blockno);
[xdata, ydata, zdata] = mapc2m(xdata,ydata);
creatingclines = 0;
end;
end;
udata.phys_vertices = [xdata', ydata', zdata'];

h(line_cnt) = line('XData',xdata,'YData',ydata,'ZData',zdata,'Color','k');
set(h(line_cnt),'Tag','on');
udata.cval = cval;
set(h(line_cnt),'UserData',udata);
st_idx = st_idx + next_length + 1;
if (st_idx > length(c))
return;
end;
end;
cval = c(1,st_idx);
next_length = c(2,st_idx);
line_cnt = line_cnt + 1;
x_like = zeros(1,next_length) + sval;
y_like = c(1,st_idx+1:st_idx+next_length);
z_like = c(2,st_idx+1:st_idx+next_length);
[xdata,ydata,zdata] = get_xyz(x_like,y_like,z_like,sdir);
udata.cartCoords = [xdata', ydata', zdata'];
if (mappedgrid == 1 || manifold == 1)
if (mappedgrid == 1)
if (nargin('mapc2p') == 2)
[xdata,ydata] = mapc2p(xdata,ydata);
else
[xdata, ydata, zdata] = mapc2p(xdata,ydata,zdata);
end
end
if (manifold == 1)
creatingclines = 1; % flag for mapc2m to indicate contour lines
% are being generated: may want to shift off
% manifold slightly to avoid hidden line removal
% causing apparent gaps in contours.
set_blocknumber(blockno);
[xdata, ydata, zdata] = mapc2m(xdata,ydata);
creatingclines = 0;
end
end
udata.phys_vertices = [xdata', ydata', zdata'];
h(line_cnt) = line('XData',xdata,'YData',ydata,'ZData',zdata,'Color','k');
set(h(line_cnt),'Tag','on');
udata.cval = cval;
set(h(line_cnt),'UserData',udata);
st_idx = st_idx + next_length + 1;
if (st_idx > length(c))
break;
end
end

set_clines(h);
48 changes: 28 additions & 20 deletions src/matlab/create_patch.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

% Internal matlab routine for Clawpack graphics.

[xe_like, ye_like, ze_like] = get_xyzlike(xe,ye,ze,sdir);
[xc_like, yc_like, zc_like] = get_xyzlike(xc,yc,zc,sdir);
[~, ye_like, ze_like] = get_xyzlike(xe,ye,ze,sdir);
[~, yc_like, zc_like] = get_xyzlike(xc,yc,zc,sdir);

% -----------x---------------------------------------
% Create patch with q data
Expand Down Expand Up @@ -49,43 +49,51 @@
[mv_names{1:3}] = get_xyzlike('mx','my','mz',sdir);
[dv_names{1:3}] = get_xyzlike('dx','dy','dz',sdir);

for i = 1:3,
userdata = setfield(userdata,(vc_names{i}),vc{i});
userdata = setfield(userdata,(ve_names{i}), ve{i});
userdata = setfield(userdata,(mv_names{i}),length(vc{i}));
for i = 1:3
% userdata = setfield(userdata,(vc_names{i}),vc{i});
% userdata = setfield(userdata,(ve_names{i}), ve{i});
% userdata = setfield(userdata,(mv_names{i}),length(vc{i}));
userdata.(vc_names{i}) = vc{i};
userdata.(ve_names{i}) = ve{i};
userdata.(mv_names{i}) = numel(vc{i});

% If we are doing a manifold, then dz==1.
dv = ve{i}(2) - ve{i}(1);
userdata = setfield(userdata,(dv_names{i}),(dv == 0) + dv*(dv ~= 0));
end;
% userdata = setfield(userdata,(dv_names{i}),(dv == 0) + dv*(dv ~= 0));
userdata.(dv_names{i}) = (dv == 0) + dv*(dv ~= 0);
end

[vmin_names{1:3}] = get_xyzlike('xmin','ymin','zmin',sdir);
[vmax_names{1:3}] = get_xyzlike('xmax','ymax','zmax',sdir);
userdata = setfield(userdata,vmin_names{1},sval);
userdata = setfield(userdata,vmax_names{1},sval);
for i = 2:3,
userdata = setfield(userdata,(vmin_names{i}), ve{i}(1));
userdata = setfield(userdata,(vmax_names{i}), ve{i}(end));
end;
% userdata = setfield(userdata,vmin_names{1},sval);
% userdata = setfield(userdata,vmax_names{1},sval);
userdata.(vmin_names{1}) = sval;
userdata.(vmax_names{1}) = sval;
for i = 2:3
%userdata = setfield(userdata,(vmin_names{i}), ve{i}(1));
%userdata = setfield(userdata,(vmax_names{i}), ve{i}(end));
userdata.(vmin_names{i}) = ve{i}(1);
userdata.(vmax_names{i}) = ve{i}(end);
end

% Store Cartesian coodinates for use in mask_patches, and convert patch
% vertices to physical coordinates.
v = get(p,'Vertices');
userdata.cartCoords = v;

if (mappedgrid == 1 | manifold == 1)
if (mappedgrid == 1 || manifold == 1)
if (mappedgrid == 1)
if (nargin('mapc2p') == 2)
[v(:,1),v(:,2)] = mapc2p(v(:,1),v(:,2));
else
[v(:,1),v(:,2),v(:,3)] = mapc2p(v(:,1),v(:,2),v(:,3));
end;
end;
end
end
if (manifold == 1)
[v(:,1),v(:,2), v(:,3)] = mapc2m(v(:,1),v(:,2));
end;
end
set(p,'Vertices',v);
end;
end
userdata.phys_vertices = v;

% -------------------------------------------------------
Expand All @@ -97,7 +105,7 @@
if (~isempty(contourlevels))
c = contourc(yc_like,zc_like,qcm2,contourlevels);
userdata.contourLines = create_clines(c,sval,sdir,mappedgrid,manifold,blockno);
end;
end

% Mesh data for showing coarsened mesh later...
% userdata.mesh = create_mesh(sdir,sval,xe,ye,ze,mappedgrid,manifold);
Expand Down
175 changes: 98 additions & 77 deletions src/matlab/create_sliceintersections.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,101 @@ function create_sliceintersections(mappedgrid)
ve_names = {'xe','ye','ze'};
isect_names = {'yzIntersect','xzIntersect','xyIntersect'};

for idir = 1:3,
for jdir = (idir+1):3,
slices_idir = get_slices(sdirs{idir});
slices_jdir = get_slices(sdirs{jdir});

% Now consider all pair-wise combinations of these two sets of slices
for n = 1:length(slices_idir);
for m = 1:length(slices_jdir);

% cell2mat doesn't seem to exist on some versions of Matlab
% so I have copied my matlab version to ../matlab2 files.
% pvec = cell2mat_claw(slices_idir{n});
% qvec = cell2mat_claw(slices_jdir{m});

pvec = [];
qvec = [];
% Need a big list of all patches we can intersect
for ll = 1:length(slices_idir{n}),
pvec = [pvec slices_idir{n}{ll}];
end;

for ll = 1:length(slices_jdir{m}),
qvec = [qvec slices_jdir{m}{ll}];
end;

for k = 1:length(pvec),
for l = 1:length(qvec),
p = pvec(k);
q = qvec(l);

udata_p = get(p,'UserData');
udata_q = get(q,'UserData');

np = udata_p.grid_number;
nq = udata_q.grid_number;
if (np == nq)
% This sets two of the coordinates for the line we are going
% to draw
sval_p = udata_p.sval;
sval_q = udata_q.sval;

kdir = (1:3);
kdir([idir; jdir]) = [];

% Third direction is all that is left
ke = getfield(udata_p,ve_names{kdir});
vdata{idir} = sval_p + 0*ke;
vdata{jdir} = sval_q + 0*ke;
vdata{kdir} = ke;

if (mappedgrid == 1)
[xdata, ydata, zdata] = mapc2p(vdata{:});
else
[xdata, ydata, zdata] = deal(vdata{:});
end;

h = line('XData',xdata, 'YData',ydata,'ZData',zdata);

sp = getfield(udata_p,isect_names{kdir});
sp(end+1).line = h;
sp(end+1).sharedPatch = q;

sq = getfield(udata_q,isect_names{kdir});
sq(end+1).line = h;
sq(end+1).sharedPatch = p;

udata_p = setfield(udata_p,isect_names{kdir},sp);
udata_q = setfield(udata_q,isect_names{kdir},sq);
set(p,'UserData',udata_p);
set(q,'UserData',udata_q);
end; % np == nq
end; % (l) loop over all patches
end; % (k) loop over all patches
end; % (m) loop over all slices
end; % (n) loop over all slices
end; % jdir
end; % idir
vdata = cell(3,1);

for idir = 1:3
for jdir = (idir+1):3
slices_idir = get_slices(sdirs{idir});
slices_jdir = get_slices(sdirs{jdir});

% Now consider all pair-wise combinations of these two sets of slices
for n = 1:length(slices_idir)
for m = 1:length(slices_jdir)

l1 = 0;
for ll = 1:length(slices_idir{n})
l1 = l1 + numel(slices_idir{n}{ll});
end

pvec = zeros(l1,1);
% Need a big list of all patches we can intersect
k = 1;
for ll = 1:length(slices_idir{n})
ps = slices_idir{n}{ll};
for jj = 1:length(ps)
pvec(k) = ps(jj);
k = k + 1;
end
end

l2 = 0;
for ll = 1:length(slices_jdir{m})
l2 = l2 + numel(slices_jdir{m}{ll});
end

qvec = zeros(l2,1);
% Need a big list of all patches we can intersect
k = 1;
for ll = 1:length(slices_jdir{m})
ps = slices_jdir{m}{ll};
for jj = 1:length(ps)
qvec(k) = ps(jj);
k = k + 1;
end
end

for k = 1:length(pvec)
for l = 1:length(qvec)
p = pvec(k);
q = qvec(l);

udata_p = get(p,'UserData');
udata_q = get(q,'UserData');

np = udata_p.grid_number;
nq = udata_q.grid_number;
if (np == nq)
% This sets two of the coordinates for the line we are going
% to draw
sval_p = udata_p.sval;
sval_q = udata_q.sval;

kdir = (1:3);
kdir([idir; jdir]) = [];

% Third direction is all that is left
% ke = getfield(udata_p,ve_names{kdir});
ke = udata_p.(ve_names{kdir});
vdata{idir} = sval_p + 0*ke;
vdata{jdir} = sval_q + 0*ke;
vdata{kdir} = ke;

if (mappedgrid == 1)
[xdata, ydata, zdata] = mapc2p(vdata{:});
else
[xdata, ydata, zdata] = deal(vdata{:});
end

h = line('XData',xdata, 'YData',ydata,'ZData',zdata);

% sp = getfield(udata_p,isect_names{kdir});
sp = udata_p.(isect_names{kdir});
sp(end+1).line = h;
sp(end+1).sharedPatch = q;

%sq = getfield(udata_q,isect_names{kdir});
sq = udata_q.(isect_names{kdir});
sq(end+1).line = h;
sq(end+1).sharedPatch = p;

udata_p.(isect_names{kdir}) = sp;
udata_q.(isect_names{kdir}) = sq;
set(p,'UserData',udata_p);
set(q,'UserData',udata_q);
end % np == nq
end % (l) loop over all patches
end % (k) loop over all patches
end % (m) loop over all slices
end % (n) loop over all slices
end % jdir
end % idir
Loading