-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprintimage.m
More file actions
1612 lines (1235 loc) · 51.1 KB
/
printimage.m
File metadata and controls
1612 lines (1235 loc) · 51.1 KB
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
function varargout = printimage(varargin)
% PRINTIMAGE MATLAB code for printimage.fig
% PRINTIMAGE, by itself, creates a new PRINTIMAGE or raises the existing
% singleton*.
%
% H = PRINTIMAGE returns the handle to a new PRINTIMAGE or the handle to
% the existing singleton*.
%
% PRINTIMAGE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PRINTIMAGE.M with the given input arguments.
%
% PRINTIMAGE('Property','Value',...) creates a new PRINTIMAGE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before printimage_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to printimage_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help printimage
% Last Modified by GUIDE v2.5 10-Nov-2017 18:05:05
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @printimage_OpeningFcn, ...
'gui_OutputFcn', @printimage_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end
function printimage_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
clear -global STL;
global STL;
% Add a menubar
%hObject.MenuBar = 'none';
handles.menu_file = uimenu(hObject, 'Label', 'File');
handles.menu_file_OpenSTL = uimenu(handles.menu_file, 'Label', 'Load STL', 'Callback', @chooseSTL_Callback);
handles.menu_file_LoadState = uimenu(handles.menu_file, 'Label', 'Load State', 'Callback', @LoadState_Callback);
handles.menu_file_SaveState = uimenu(handles.menu_file, 'Label', 'Save State', 'Callback', @SaveState_Callback);
handles.menu_calibrate = uimenu(hObject, 'Label', 'Calibrate');
handles.menu_calibrate_set_hexapod_level = uimenu(handles.menu_calibrate, 'visible', 'off', 'Label', 'Save hexapod leveling coordinates', 'Callback', @hexapod_set_leveling);
handles.menu_calibrate_reset_rotation_to_centre = uimenu(handles.menu_calibrate, 'visible', 'off', 'Label', 'Reset hexapod to [ 0 0 0 0 0 0 ]', 'Callback', @hexapod_reset_to_centre);
handles.menu_calibrate_add_bullseye = uimenu(handles.menu_calibrate, 'visible', 'off', 'Label', 'MOM--PI alignment', 'Callback', @align_stages);
handles.menu_calibrate_rotation_centre = uimenu(handles.menu_calibrate, 'visible', 'off', 'Label', 'Save hexapod-centre alignment', 'Callback', @set_stage_true_rotation_centre_Callback);
handles.menu_calibrate_vignetting_compensation_save_baseline = uimenu(handles.menu_calibrate, 'visible', 'off', 'Label', 'Save baseline image', 'Callback', @calibrate_vignetting_save_baseline_Callback);
handles.menu_calibrate_vignetting_compensation = uimenu(handles.menu_calibrate, 'visible', 'off', 'Label', 'Calibrate vignetting compensation', 'Callback', @calibrate_vignetting_slide);
handles.menu_restore_last_vignetting_compensation = uimenu(handles.menu_calibrate, 'Label', 'Restore last vignetting compensation', 'Callback', @calibrate_vignetting_restore);
handles.menu_clear_vignetting_compensation = uimenu(handles.menu_calibrate, 'Label', 'Clear vignetting compensation', 'Callback', @clear_vignetting_compensation_functions);
handles.menu_test = uimenu(hObject, 'Label', 'Test');
handles.menu_test_linearity = uimenu(handles.menu_test, 'Label', 'Stitching Stage Linearity', 'Callback', @test_linearity_Callback);
handles.menu_debug = uimenu(hObject, 'Label', 'Debug');
handles.menu_debug_disarm = uimenu(handles.menu_debug, 'Label', 'Disarm ScanImage''s PrintImage hook (return control to ScanImage)', 'Callback', @disarm_callback);
try
hSI = evalin('base', 'hSI');
fprintf('Scanimage %s.%s\n', hSI.VERSION_MAJOR, hSI.VERSION_MINOR); % If the fields don't exist, this will throw an error and dump us into simulation mode.
if isfield(hSI, 'simulated')
if hSI.simulated
error('Catch me!');
end
end
STL.logistics.simulated = false;
catch ME
% Run in simulated mode.
% To voxelise offline (e.g. big stitching jobs on a fast cluster),
% the marked parameters should all be grabbed from the hSI
% structure created by ScanImage on the r3D2 machine, or defined
% here as you wish and copied manually to the r3D2 machine. FIXME
% easy to copy to target
% FIXME scanZoomFactor will probably only remain the same with
% stitched items, for which the auto-zoom doesn't happen. If it
% does auto-zoom, PrintImage will probably recalculate and
% revoxelise, but if you're not doing stitching, then voxelising
% one metavoxel is fast anyway, so there's probably no major need
% to voxelise on a faster computer.
STL.logistics.simulated = true;
STL.logistics.simulated_pos = [ 0 0 0 0 0 0 ];
hSI.simulated = true;
hSI.hRoiManager.linesPerFrame = 512; % define here as desired
hSI.hRoiManager.scanZoomFactor = 2.3; % define here as desired
hSI.hRoiManager.imagingFovUm = [-333 -333; 0 0; 333 333]; % copy from hSI
hSI.hScan_ResScanner.fillFractionSpatial = 0.9; % copy from hSI
hSI.hWaveformManager.scannerAO.ao_samplesPerTrigger.B = 152; % copy from hSI (available after a Focus)
hSI.hMotors.motorPosition = 10000 * [ 1 1 1 ];
STL.motors.hex.range = repmat([-10 10], 6, 1);
assignin('base', 'hSI', hSI);
end
set(gcf, 'CloseRequestFcn', @clean_shutdown);
STL.logistics.wbar_pos = [.05 .85];
hSI.hDisplay.roiDisplayEdgeAlpha = 0.1;
%% From this point onward, STL vars are not supposed to be user-configurable
set_up_params();
%foo = questdlg(sprintf('Stage rotation centre set to [%s ]. Ok?', ...
% sprintf(' %d', STL.motors.mom.understage_centre)), ...
% 'Stage setup', 'Yes', 'No', 'Yes');
%switch foo
% case 'Yes'
% ;
% case 'No'
% STL.motors.mom.understage_centre = [];
%end
if ~STL.logistics.simulated
switch STL.motors.special
case 'hex_pi'
hexapod_pi_connect();
set(handles.panel_rotation_hexapod, 'Visible', 'on');
case 'rot_esp301'
rot_esp301_connect();
set(handles.panel_rotation_infinite, 'Visible', 'on');
case 'none'
;
otherwise
warning('STL.motors.special: I don''t know what a ''%s'' is.', STL.motors.special);
end
if STL.motors.hex.connected
set(handles.menu_calibrate_set_hexapod_level, 'visible', 'on');
set(handles.menu_calibrate_reset_rotation_to_centre, 'visible', 'on');
set(handles.menu_calibrate_add_bullseye, 'visible', 'on');
set(handles.menu_calibrate_rotation_centre, 'visible', 'on');
set(handles.menu_calibrate_vignetting_compensation, 'visible', 'on');
set(handles.menu_calibrate_rotation_centre, 'visible', 'on');
end
end
% ScanImage freaks out if we pass an illegal command to its motor stage
% controller--and also if I can't move up the required amount, I
% probably shouldn't drop the fastZ stage. Error out:
zpos = hSI.hMotors.motorPosition(3);
while zpos < 500
foo = questdlg('Please safely drop the MOM''s Z axis to at least 500 microns.', ...
'Stage setup', 'I did it', 'Cancel');
switch foo
case 'I did it'
zpos = hSI.hMotors.motorPosition(3);
case 'Cancel'
hexapod_pi_disconnect()
return;
end
end
% Disable this for PI...
warning('Disabling warning "MATLAB:subscripting:noSubscriptsSpecified" because there will be A LOT of them!');
evalin('base', 'warning(''off'', ''MATLAB:subscripting:noSubscriptsSpecified'');');
STL.logistics.abort = false; % Bookkeeping; not user-configurable
% Some parameters are only computed on grab. So do one.
hSI.hStackManager.numSlices = 1;
hSI.hFastZ.enable = false;
hSI.hFastZ.actuatorLag = 13e-3; % Should calibrate with zstep = whatever you're going to use
legal_beams = {};
if STL.logistics.simulated
STL.motors.mom.understage_centre = [10000 10000 6000];
STL.motors.hex.tmp_origin = [0 0 0];
legal_beams = -1;
else
evalin('base', 'hSI.startGrab()');
while ~strcmpi(hSI.acqState, 'idle')
pause(0.1);
end
% Get the list of legal beam channels
for i = 1:length(hSI.hChannels.channelName)
legal_beams{i} = sprintf('%d', i);
end
% I'm going to drop the fastZ stage to 420. To make that safe, first
% I'll move the slow stage up in order to create sufficient clearance
% (with appropriate error checks).
foo = hSI.hMotors.motorPosition - [0 0 (STL.print.fastZhomePos - hSI.hFastZ.positionTarget)];
if foo(3) < 0
foo(3) = 0;
end
move('mom', foo);
hSI.hFastZ.positionTarget = STL.print.fastZhomePos;
end
set(handles.whichBeam, 'String', legal_beams);
addlistener(handles.zslider, 'Value', 'PreSet', @(~,~)zslider_Callback(hObject, [], handles));
addlistener(handles.rotate_infinite_slider, 'Value', 'PreSet', @(~,~)rotate_by_slider_show_Callback(hObject, [], handles));
guidata(hObject, handles);
UpdateBounds_Callback([], [], handles);
%hSI.hFastZ.positionTarget = STL.print.fastZhomePos;
%motorHold(handles, 'reset');
if ~STL.logistics.simulated
hSI.hFastZ.setHome(0);
end
%warning('Setting pixelsPerLine to 64 for faster testing.');
%hSI.hRoiManager.pixelsPerLine = 64;
hSI.hScan2D.bidirectional = false;
hSI.hScan2D.linePhase = STL.calibration.ScanImage.ScanPhase;
hSI.hScanner.linePhase = STL.calibration.ScanImage.ScanPhase;
colormap(handles.axes2, 'gray');
guidata(hObject, handles);
end
% This sets up default values for user-configurable STL parameters. Then,
% if printimage_config.m exists, we load that, and replace all valid
% parameters' default values with the user-configured versions. If the user
% tries to configure a parameter for which there is no default defined
% here, the user configuration parameter is ignored and a warning issued.
function set_up_params()
global STL;
STL.print.zstep = 1; % microns per step in z (vertical)
STL.print.xaxis = 1; % axis of raw STL over which the resonant scanner scans
STL.print.zaxis = 3; % axis of raw STL over which we print upwards (fastZ etc)
STL.print.power = 0.5;
STL.print.whichBeam = 1; % if scanimage gets to play with >1 laser...
STL.print.size = [400 400 360];
STL.print.zoom_min = 1;
STL.print.zoom = 1;
STL.print.zoom_best = 1;
STL.print.armed = false;
STL.preview.resolution = [120 120 120];
STL.print.metavoxel_overlap = [8 8 8]; % Microns of overlap (positive is more overlap) in order to get good bonding
STL.print.voxelise_needed = true;
STL.preview.voxelise_needed = true;
STL.print.invert_z = false;
STL.print.motor_reset_needed = false;
STL.preview.show_metavoxel_slice = NaN;
STL.print.fastZhomePos = 420;
STL.motors.stitching = 'mom'; % 'hex' is a hexapod (so far, only hex_pi), 'mom' is Sutter MOM
STL.motors.special = 'none'; % So far: 'hex_pi', 'rot_esp301', 'none'
STL.motors.rot.connected = false;
STL.motors.rot.com_port = 'com4';
STL.motors.mom.understage_centre = [12066 1.0896e+04 1.6890e+04];
STL.motors.hex.user_rotate_velocity = 20;
STL.motors.hex.pivot_z_um = 24900; % For hexapods, virtual pivot height offset of sample.
STL.motors.hex.ip_address = '0.0.0.0';
% Hexapod to image: [1 0 0] moves right
% [0 1 0] moves down
% [0 0 1] reduces height
STL.motors.hex.axis_signs = [ 1 1 -1 ];
STL.motors.hex.axis_order = [ 1 2 3 ];
STL.motors.hex.leveling = [0 0 0 0 0 0]; % This leveling zero pos will be manually applied
%STL.motors.mom.understage_centre = [11240 10547 19479]; % When are we centred over the hexapod's origin?
STL.motors.hex.slide_level = [ 0 0 0 0 0 0 ]; % Slide is mounted parallel to optical axis
STL.motors.hex.connected = false;
% MOM to image: [1 0 0] moves down
% [0 1 0] moves left
% [0 0 1] reduces height
% MOM to hex:
STL.motors.mom.coords_to_hex = [0 1 0; ...
-1 0 0; ...
0 0 -1];
STL.motors.mom.axis_signs = [ -1 1 -1 ];
STL.motors.mom.axis_order = [ 2 1 3 ];
% The Zeiss LCI PLAN-NEOFLUAR 25mm has a nominal working depth of
% 380um.
STL.calibration.lens_optical_working_distance = 380; % microns, for optical computations
STL.calibration.lens_working_distance_safety_um = 15; % microns
STL.calibration.pockelsFrequency = 3333333; % Frequency of Pockels cell controller
% ScanImage's LinePhase adjustment. Save it here, just for good measure.
STL.calibration.ScanImage.ScanPhase = 0;
%%%%%
%% Next, allow the user to override any of these:
%%%%%
params_file = 'printimage_config';
load_params(params_file, 'STL');
%%%%%
%% Finally, compute any dependencies:
%%%%%
zbound = min(STL.calibration.lens_optical_working_distance - STL.calibration.lens_working_distance_safety_um, STL.print.fastZhomePos);
STL.bounds_1 = [NaN NaN zbound ];
STL.print.bounds_max = [NaN NaN zbound ];
STL.print.bounds = [NaN NaN zbound ];
end
function varargout = printimage_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
end
function chooseSTL_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.stl');
if isequal(FileName, 0)
return;
end
handles = guidata(gcbo);
STLfile = strcat(PathName, FileName);
set(handles.lockAspectRatio, 'Value', 1);
set(gcf, 'Name', STLfile);
updateSTLfile(handles, STLfile);
update_3d_preview(handles);
end
function zslider_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
end
function printpowerpercent_Callback(hObject, eventdata, handles)
global STL;
STL.print.power = str2double(get(hObject, 'String')) / 100;
STL.print.power = min(max(STL.print.power, 0.01), 1);
set(hObject, 'String', sprintf('%d', round(100*STL.print.power)));
end
function printpowerpercent_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function powertest_Callback(hObject, eventdata, handles)
global STL;
hSI = evalin('base', 'hSI');
if ~strcmpi(hSI.acqState,'idle')
set(handles.messages, 'String', 'Some other ongoing operation (FOCUS?) prevents printing.');
return;
else
set(handles.messages, 'String', '');
end
if STL.print.motor_reset_needed
set(handles.messages, 'String', 'CRUSH THE THING!!! Reset lens position before printing!');
return;
else
set(handles.messages, 'String', '');
end
if STL.logistics.simulated
userZoomFactor = 1;
else
userZoomFactor = hSI.hRoiManager.scanZoomFactor;
end
%if isfield(STL, 'file') & ~isempty(STL.file) & STL.print.voxelise_needed
% voxelise(handles, 'print');
%else
% STL.print.zoom_best = STL.print.zoom;
%end
hSI.hRoiManager.scanZoomFactor = STL.print.zoom;
% Number of slices at 1 micron per slice:
hSI.hScan2D.bidirectional = false;
gridx = 1;
gridy = 1;
gridn = gridx * gridy;
low = str2double(get(handles.powertest_start, 'String'));
high = str2double(get(handles.powertest_end, 'String'));
if strcmp(handles.powertest_spacing.SelectedObject.String, 'Log')
pow_incr = (high/low)^(1/((gridn)-1));
powers = (low) * pow_incr.^[0:(gridn)-1];
powers(end) = high; % In case roundoff error resulted in 100.0000001
else
powers = linspace(low, high, gridn);
end
sx = 1/gridx;
sy = 1/gridy;
bufferx = 0.025;
buffery = 0.01;
% A bunch of stuff needs to be set up for this. Should undo it all later!
oldBeams = hSI.hBeams;
hSI.hBeams.powerBoxes = hSI.hBeams.powerBoxes([]);
for i = 1:gridy
for j = 1:gridx
ind = j+gridx*(i-1);
pb.rect = [sx*(j-1)+bufferx sy*(i-1)+buffery sx-2*bufferx sy-2*buffery];
pb.powers = powers(ind);
pb.name = sigfig(powers(ind), 2);
pb.oddLines = 1;
pb.evenLines = 1;
hSI.hBeams.powerBoxes(ind) = pb;
end
end
% 100 microns high
nframes = 100 / STL.print.zstep;
hSI.hFastZ.enable = 1;
hSI.hStackManager.stackZStepSize = -STL.print.zstep;
%hSI.hFastZ.flybackTime = 25; % SHOULD BE IN MACHINE_DATA_FILE?!?!
hSI.hStackManager.stackReturnHome = false; % This seems useless.
hSI.hScan2D.bidirectional = false;
hSI.hStackManager.numSlices = nframes;
hSI.hBeams.powerLimits = 100;
hSI.hBeams.enablePowerBox = true;
motorHold(handles, 'on');
hSI.startLoop();
% Clean up
while ~strcmpi(hSI.acqState,'idle')
pause(0.1);
end
hSI.hBeams.enablePowerBox = false;
hSI.hRoiManager.scanZoomFactor = userZoomFactor;
motorHold(handles, 'resetZ');
if get(handles.focusWhenDone, 'Value')
hSI.startFocus();
end
end
function powertest_start_Callback(hObject, eventdata, handles)
end
function powertest_start_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function powertest_end_Callback(hObject, eventdata, handles)
end
function powertest_end_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function powertest_spacing_lin_Callback(hObject, eventdata, handles)
end
function build_x_axis_Callback(hObject, eventdata, handles)
global STL;
STL.preview.voxelise_needed = true;
STL.print.voxelise_needed = true;
STL.print.xaxis = get(hObject, 'Value');
if STL.print.zaxis == STL.print.xaxis
STL.print.zaxis = setdiff([1 2 3], STL.print.xaxis);
STL.print.zaxis = STL.print.zaxis(1);
end
update_dimensions(handles);
end
function build_x_axis_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function build_z_axis_Callback(hObject, eventdata, handles)
global STL;
STL.preview.voxelise_needed = true;
STL.print.voxelise_needed = true;
STL.print.valid = 0;
STL.print.zaxis = get(hObject, 'Value');
if STL.print.zaxis == STL.print.xaxis
STL.print.xaxis = setdiff([1 2 3], STL.print.zaxis);
STL.print.xaxis = STL.print.xaxis(1);
end
update_dimensions(handles);
end
function build_z_axis_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject, 'String', {'x', 'y', 'z'});
end
function setFastZ_Callback(hObject, eventdata, handles)
global STL;
hSI = evalin('base', 'hSI');
hSI.hFastZ.positionTarget = STL.print.fastZhomePos;
end
function fastZhomePos_Callback(hObject, eventdata, handles)
global STL;
STL.print.fastZhomePos = str2double(get(hObject, 'String'));
end
function fastZhomePos_CreateFcn(hObject, eventdata, handles)
global STL;
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
%function fastZlower_Callback(hObject, eventdata, handles)
% global STL;
% hSI = evalin('base', 'hSI');
% hSI.hFastZ.positionTarget = 420;
% motorHold(handles, 'reset');
%end
function invert_z_Callback(hObject, eventdata, handles)
global STL;
set(handles.messages, 'String', 'Inverting Z...');
STL.print.invert_z = get(hObject, 'Value');
STL.print.rescale_needed = true;
STL.preview.rescale_needed = true;
update_3d_preview(handles);
set(handles.messages, 'String', '');
end
function crushThing_Callback(hObject, eventdata, handles)
hSI = evalin('base', 'hSI');
motorHold(handles, 'resetZ');
end
function size1_Callback(hObject, eventdata, handles)
global STL;
STL.print.rescale_needed = true;
foo = str2double(get(hObject, 'String'));
if foo > 0
update_dimensions(handles, 1, foo);
end
end
function size1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function size2_Callback(hObject, eventdata, handles)
global STL;
STL.print.rescale_needed = true;
foo = str2double(get(hObject, 'String'));
if foo > 0
update_dimensions(handles, 2, foo);
end
end
function size2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function size3_Callback(hObject, eventdata, handles)
global STL;
STL.print.rescale_needed = true;
foo = str2double(get(hObject, 'String'));
if foo > 0
update_dimensions(handles, 3, foo);
end
end
function size3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function whichBeam_Callback(hObject, eventdata, handles)
global STL;
STL.print.whichBeam = get(hObject, 'Value');
end
function whichBeam_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function minGoodZoom_Callback(hObject, eventdata, handles)
global STL;
contents = cellstr(get(hObject,'String'));
STL.print.zoom_min = str2double(contents{get(hObject, 'Value')});
if STL.print.zoom < STL.print.zoom_min
STL.print.zoom = STL.print.zoom_min;
end
possibleZooms = STL.print.zoom_min:0.1:6;
for i = 1:length(possibleZooms)
foo{i} = sprintf('%g', possibleZooms(i));
% Allows user choice of zoom to remain unchanged despite the indexing for this widget
if abs(STL.print.zoom - possibleZooms(i)) < 1e-15
zoomVal = i;
end
end
STL.print.voxelise_needed = true;
set(handles.printZoom, 'String', foo, 'Value', zoomVal);
UpdateBounds_Callback(hObject, eventdata, handles);
end
function minGoodZoom_CreateFcn(hObject, eventdata, handles)
% These are just some allowed values. Need 1 sigfig, so just add likely
% candidates manually... Could do it more cleverly!
possibleZooms = 1:0.1:2;
for i = 1:length(possibleZooms)
foo{i} = sprintf('%g', possibleZooms(i));
end
set(hObject, 'String', foo, 'Value', 1);
end
function printZoom_Callback(hObject, eventdata, handles)
global STL;
contents = cellstr(get(hObject,'String'));
STL.print.zoom = str2double(contents{get(hObject, 'Value')});
STL.print.voxelise_needed = true;
UpdateBounds_Callback(hObject, eventdata, handles);
end
function printZoom_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
global STL;
possibleZooms = 1:0.1:4;
for i = 1:length(possibleZooms)
foo{i} = sprintf('%g', possibleZooms(i));
end
set(hObject, 'String', foo, 'Value', 1);
end
function voxelise_preview_button_Callback(hObject, eventdata, handles)
%update_dimensions(handles);
zslider_Callback([], [], handles);
update_3d_preview(handles);
end
function crushReset_Callback(hObject, eventdata, handles)
global STL;
hSI = evalin('base', 'hSI');
STL.motors.mom.tmp_origin = move('mom');
STL.motors.hex.tmp_origin = hexapod_get_position_um();
STL.print.motor_reset_needed = false;
set(handles.crushThing, 'BackgroundColor', 0.94 * [1 1 1]);
set(handles.messages, 'String', '');
end
function abort_Callback(hObject, eventdata, handles)
global STL;
STL.logistics.abort = true;
end
function show_metavoxel_slice_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function voxelise_print_button_Callback(hObject, eventdata, handles)
global STL;
global wbar;
voxelise(handles, 'print');
if STL.logistics.abort
STL.logistics.abort = false;
set(handles.messages, 'String', 'Canceled.');
set(handles.show_metavoxel_slice, 'String', 'NaN');
return;
end
set(handles.show_metavoxel_slice, 'String', '1 1 1');
STL.preview.show_metavoxel_slice = [1 1 1];
zslider_Callback([], [], handles);
end
function test_linearity_Callback(varargin)
global STL;
global wbar;
hSI = evalin('base', 'hSI');
handles = guidata(gcbo);
if ~strcmpi(hSI.acqState,'idle')
set(handles.messages, 'String', 'Some other ongoing operation (FOCUS?) prevents your test.');
return;
else
set(handles.messages, 'String', '');
end
if STL.print.motor_reset_needed
set(handles.messages, 'String', 'CRUSH THE THING!!! Reset lens position before printing!');
return;
else
set(handles.messages, 'String', '');
end
hexapos = hexapod_get_position_um();
if any(abs(hexapos(1:3)) > 0.001)
set(handles.messages, 'String', 'Hexapod position is [%s ], not [ 0 0 0 ]. Please fix that first');
return;
else
set(handles.messages, 'String', '');
end
STL.motors.mom.tmp_origin = move('mom');
STL.motors.hex.tmp_origin = hexapod_get_position_um();
eval(sprintf('motor = STL.motors.%s', STL.motors.stitching));
if STL.logistics.simulated
userZoomFactor = 1;
else
userZoomFactor = hSI.hRoiManager.scanZoomFactor;
end
hSI.hRoiManager.scanZoomFactor = 6;
userPower = hSI.hBeams.powers;
hSI.hBeams.powers = 1.3;
% Number of slices at 1 micron per slice:
hSI.hScan2D.bidirectional = false;
% A bunch of stuff needs to be set up for this. Should undo it all later!
oldBeams = hSI.hBeams;
hSI.hBeams.powerBoxes = hSI.hBeams.powerBoxes([]);
ind = 1;
%pb.rect = [0.46 0.46 0.08 0.08];
pb.rect = [0.9 0.46 0.08 0.08];
pb.powers = STL.print.power * 100;
pb.name = 'hi';
pb.oddLines = 1;
pb.evenLines = 1;
hSI.hBeams.powerBoxes(ind) = pb;
nframes = 36;
hSI.hFastZ.enable = 1;
hSI.hStackManager.stackZStepSize = -STL.print.zstep;
%hSI.hFastZ.flybackTime = 25; % SHOULD BE IN MACHINE_DATA_FILE?!?!
hSI.hStackManager.stackReturnHome = false; % This seems useless.
motorHold(handles, 'on');
hSI.hScan2D.bidirectional = false;
hSI.hStackManager.numSlices = nframes;
hSI.hBeams.powerLimits = 100;
hSI.hBeams.enablePowerBox = true;
drawnow;
[X Y] = meshgrid(0:1000:4000, 0:1000:4000);
posns = [X(1:end) ; Y(1:end)];
%rng(1234);
metavoxel_counter = 0;
metavoxel_total = prod(size(X));
start_time = datetime('now');
eta = 'next weekend';
if exist('wbar', 'var') & ishandle(wbar) & isvalid(wbar)
waitbar(0, wbar, 'Printing...', 'CreateCancelBtn', 'cancel_button_callback');
else
wbar = waitbar(0, 'Printing...', 'CreateCancelBtn', 'cancel_button_callback');
set(wbar, 'Units', 'Normalized');
wp = get(wbar, 'Position');
wp(1:2) = STL.logistics.wbar_pos(1:2);
set(wbar, 'Position', wp);
drawnow;
end
%posns = posns(:, randperm(prod(size(X))));
posns = posns';
STL.motors.hex.C887.VLS(1);
for xy = 1:size(posns, 1)
if STL.logistics.abort
% The caller has to unset STL.logistics.abort
% (and presumably return).
disp('Aborting due to user.');
move('hex', [ 0 0 ], 20);
if ishandle(wbar) & isvalid(wbar)
STL.logistics.wbar_pos = get(wbar, 'Position');
delete(wbar);
end
if exist('handles', 'var');
set(handles.messages, 'String', 'Canceled.');
drawnow;
end
STL.logistics.abort = false;
STL.print.armed = false;
hSI.hStackManager.numSlices = 1;
hSI.hFastZ.enable = false;
hSI.hBeams.enablePowerBox = false;
hSI.hRoiManager.scanZoomFactor = 1;
hSI.hBeams.powers = userPower;
if ~STL.logistics.simulated
while ~strcmpi(hSI.acqState,'idle')
pause(0.1);
end
end
break;
end
newpos = posns(xy, :) + motor.tmp_origin(1:2);
move(STL.motors.stitching, newpos, 2);
hSI.hFastZ.positionTarget = STL.print.fastZhomePos;
hSI.startLoop();
while ~strcmpi(hSI.acqState, 'idle')
pause(0.1);
end
metavoxel_counter = metavoxel_counter + 1;
if exist('wbar', 'var') & ishandle(wbar) & isvalid(wbar)
current_time = datetime('now');
eta_date = start_time + (current_time - start_time) / (metavoxel_counter / metavoxel_total);
if strcmp(datestr(eta_date, 'yyyymmdd'), datestr(current_time, 'yyyymmdd'))
eta = datestr(eta_date, 'HH:MM:SS');
else
eta = datestr(eta_date, 'dddd HH:MM');
end
waitbar(metavoxel_counter / metavoxel_total, wbar, sprintf('Printing. Done around %s.', eta));
end
end
% Clean up
hSI.hBeams.enablePowerBox = false;
hSI.hRoiManager.scanZoomFactor = 1;
hSI.hBeams.powers = userPower;
motorHold(handles, 'resetXYZ');
if exist('wbar', 'var') & ishandle(wbar) & isvalid(wbar)
STL.logistics.wbar_pos = get(wbar, 'Position');
delete(wbar);
end
end
function lockAspectRatio_Callback(hObject, eventdata, handles)
end
function preview_Callback(hObject, eventdata, handles)
add_preview(handles);
end
function LoadState_Callback(varargin)
global STL;
% Some things should not be overwritten by the restored state:
simulated = STL.logistics.simulated;
STLmotors = STL.motors;
[FileName,PathName] = uigetfile('*.mat');
if isequal(FileName, 0)
return;
end
load(strcat(PathName, FileName));
% Restore the current stuff:
STL.logistics.simulated = simulated;
STL.motors = STLmotors;
% Pull Y axis voxels from loaded file:
hSI.hRoiManager.linesPerFrame = STL.print.resolution(2);
% No need to pull zoom from loaded file, since the selected zoom is
% stored in the STL, and ScanImage will be informed of it when printing
% starts... I hope... (?)
% hSI.hRoiManager.scanZoomFactor = 2.2; % define
handles = guidata(gcbo);
STLfile = strcat(PathName, FileName);
update_gui(handles);
update_3d_preview(handles);
draw_slice(handles, get(handles.zslider, 'Value'));
end
function SaveState_Callback(varargin)
global STL;
uisave('STL', 'CurrentSTL');