-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_preview.m
58 lines (48 loc) · 2.23 KB
/
add_preview.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
function add_preview(handles)
global STL;
hSI = evalin('base', 'hSI');
hSICtl = evalin('base', 'hSICtl');
relevant_images = draw_on_image_get_images();
% Need to know the bounds that we'll be printing at. That's
% bounds_best, computed in voxelise. So make sure that's been called:
if STL.print.voxelise_needed
voxelise(handles, 'print');
if STL.logistics.abort
% Did we abort? That's okay for now... until I figure out how
% to do previews on stitched images. I guess just show the
% first piece, which should always exist even after an abort.
% Right?
STL.logistics.abort = false;
end
end
% Get current FOV
fov = hSI.hRoiManager.imagingFovUm;
if any(abs(fov) ~= abs(fov(1,1)))
error('It seems Ben''s assumptions about a square, centred FOV were wrong.');
end
bounds = [fov(3,1) - fov(1,1) fov(3,2) - fov(1,2)];
zind = get(handles.zslider, 'Value');
w = [1 1 1]; % Which metavoxel slice? This should be the one that prints first.
which_slice = max(1, round(zind * size(STL.print.metavoxels{w(1), w(2), w(3)}, 3)));
posx = STL.print.voxelpos{1,1,1}.x;
posx = posx - (max(posx) - min(posx))/2;
posy = STL.print.voxelpos{1,1,1}.y;
posy = posy - (max(posy) - min(posy))/2;
for i = relevant_images
fig_lims = [get(hSICtl.hManagedGUIs(i).CurrentAxes, 'XLim')' ...
get(hSICtl.hManagedGUIs(i).CurrentAxes, 'YLim')'];
fig_bounds = diff(fig_lims);
fov_transform = diag([1 1] .* fig_bounds ./ bounds);
z = draw_on_image_get_z(hSICtl.hManagedGUIs(i).CurrentAxes);
psz = fig_bounds ./ STL.print.resolution(1:2) / 2;
[pixx pixy] = find(STL.print.metavoxels{1,1,1}(:,:,which_slice));
scatterme = zeros(3, length(pixx));
for j = 1: length(pixx)
pos = [posx(pixx(j)) posy(pixy(j))] * fov_transform;
scatterme(:,j) = [pos(1); pos(2); z];
end
scatter3(hSICtl.hManagedGUIs(i).CurrentAxes, ...
scatterme(1,:), scatterme(2,:), scatterme(3,:), 1, [1 0 0], ...
'Marker', '.', 'MarkerFaceAlpha', 0.5, 'MarkerEdgeAlpha', 0.5);
end
end