-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathftwindow.cpp
More file actions
2886 lines (2694 loc) · 150 KB
/
Copy pathftwindow.cpp
File metadata and controls
2886 lines (2694 loc) · 150 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
#include "ftwindow_common.h"
// ---------------------------------------------------------------------------
// Static configuration (used by embedding applications)
// ---------------------------------------------------------------------------
static QString g_exampleImagesDir;
// ---------------------------------------------------------------------------
// Checkbox styling
//
// A bare "color: white" stylesheet leaves the checkbox *indicator* to the
// native platform style. On Windows (including the WASM build) that indicator
// renders as a black box with no visible checkmark against our dark panels,
// so the user cannot tell whether the box is checked. Styling the indicator
// explicitly makes it render identically on every platform, including WASM:
// the box stays white in both states, and when checked a black checkmark is
// overlaid on it.
//
// The checkmark is supplied via "image: url(<path>)". Qt's stylesheet url()
// loads a file that QPixmap can open — it does NOT accept "data:" URIs (an
// inline data URI silently renders nothing on every platform). So we decode
// an embedded PNG to a temp file once and point the stylesheet at that path;
// this needs no .qrc/resource and works on native and WASM (MEMFS) alike.
// ---------------------------------------------------------------------------
static QString checkMarkPngPath()
{
// 16x16 black checkmark on a transparent background.
static const char kCheckPngB64[] =
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA4ElEQVR4nL3S"
"O04DMRAG4C/ZSDTQIE5ADwVSKLlETpBzpMoJaGhRCmrECWgpkXKGtEAD7ZIU"
"mUHGbFaAECNZtmc8/8M2/xwDDP8CqPkN8wCHOC9y345RzAu0mEfui51kKiPl"
"TrGOsYhzn6x0SUqGU7xG80MXWS72oylvu4nxGM3POFa9RiIdYYmbyO/FfBnN"
"LSaVrY9Ng/vC43XUJkXuKnIjVaTkCzzhPRpusYr1EgdB1Pl86WeMlwJkjTec"
"VOc6I6WNbS8rAaa7pPeBnOEOs9j/6OvWMnu/7K7isKi1fQAbxB0n6vwBzzMA"
"AAAASUVORK5CYII=";
static QString path;
if (!path.isEmpty())
return path;
const QByteArray png = QByteArray::fromBase64(QByteArray(kCheckPngB64));
const QString p = QDir::tempPath() + "/ft_checkmark.png";
QFile f(p);
if (f.open(QIODevice::WriteOnly)) {
f.write(png);
f.close();
path = p;
}
return path;
}
// Pass fontPx > 0 to also pin the label font size (used from resizeEvent,
// which re-applies checkbox styles on every resize — WASM fires one at
// startup — and must keep the indicator rules, or the box falls back to the
// invisible native rendering).
static QString checkBoxStyle(const QString &textColor, int fontPx = -1)
{
const QString check = checkMarkPngPath();
const QString font = fontPx > 0
? QStringLiteral("font-size: %1px;").arg(fontPx)
: QString();
return QStringLiteral(
"QCheckBox { color: %1; %3 }"
"QCheckBox::indicator {"
" width: 16px; height: 16px;"
" border: 1px solid #888; border-radius: 3px;"
" background: white;"
"}"
"QCheckBox::indicator:checked {"
" background: white; border: 1px solid #888;"
" image: url(\"%2\");"
"}")
.arg(textColor, check, font);
}
void FtWindow::setExampleImagesDir(const QString &dir)
{
g_exampleImagesDir = dir;
}
QString FtWindow::exampleImagesDir()
{
return g_exampleImagesDir;
}
// ---------------------------------------------------------------------------
// Constructor
// ---------------------------------------------------------------------------
FtWindow::FtWindow(QWidget *parent) : QWidget(parent)
{
setWindowTitle("ft");
setMouseTracking(true);
// Needed so the maximized image view can receive the ESC key that leaves it.
setFocusPolicy(Qt::StrongFocus);
grabGesture(Qt::PinchGesture);
buildToolGroups();
QScreen *screen = QApplication::primaryScreen();
QRect available = screen->availableGeometry();
setGeometry(available);
// Load button
m_loadBtn = new QPushButton("Load image", this);
m_loadBtn->setFixedSize(130, 30);
connect(m_loadBtn, &QPushButton::clicked, this, &FtWindow::onLoadImage);
new QShortcut(QKeySequence::Open, this, SLOT(onLoadImage()));
// Save button
m_saveBtn = new QPushButton("Save image", this);
m_saveBtn->setFixedSize(130, 30);
connect(m_saveBtn, &QPushButton::clicked, this, &FtWindow::onSaveImage);
// New image button (opens Create-or-Copy popup in panel 1)
m_createBtn = new QPushButton("New image", this);
m_createBtn->setFixedSize(130, 30);
connect(m_createBtn, &QPushButton::clicked, this, &FtWindow::onCreateImage);
// Reload / Save / Empty live in the gutter between the two history panels
// (3 and 4), since they all act on the buffer whose thumbnails sit there.
m_reloadBtn = new QPushButton("Reload image", this);
m_reloadBtn->setFixedSize(130, 30);
connect(m_reloadBtn, &QPushButton::clicked, this, &FtWindow::onReloadImage);
// Copy image button — sits just above Reload in the central gutter. It opens
// the same copy-buffer parameter window (bottom-left of panel 1) that the
// panel-1 tool menu used to host under "Math".
m_copyImageBtn = new QPushButton("Copy image", this);
m_copyImageBtn->setFixedSize(130, 30);
m_copyImageBtn->setToolTip("Copy the active image into another buffer");
connect(m_copyImageBtn, &QPushButton::clicked, this,
[this]() { activateP1Tool(20); });
// Empty-buffer button (clears the active buffer after a confirmation dialog)
m_deleteBtn = new QPushButton("Empty buffer", this);
m_deleteBtn->setFixedSize(130, 30);
connect(m_deleteBtn, &QPushButton::clicked, this, &FtWindow::onDeleteImage);
// Undo / Redo buttons
m_undoBtn = new QPushButton("Undo", this);
m_undoBtn->setFixedSize(130, 30);
connect(m_undoBtn, &QPushButton::clicked, this, &FtWindow::onUndo);
m_redoBtn = new QPushButton("Redo", this);
m_redoBtn->setFixedSize(130, 30);
connect(m_redoBtn, &QPushButton::clicked, this, &FtWindow::onRedo);
updateUndoRedoButtons();
// Fullscreen toggle button
m_fullscreenBtn = new QPushButton("Fullscreen", this);
m_fullscreenBtn->setFixedSize(88, 30);
m_fullscreenBtn->setToolTip(
"Fill the screen with the application window, or return it to a\n"
"normal window. The label names where the button leads.\n"
"Separately, the small maximize icon below either image opens a\n"
"display-only full-screen view of that image alone.");
connect(m_fullscreenBtn, &QPushButton::clicked, this, &FtWindow::onToggleFullscreen);
// Start with the label matching reality, and keep it matching from here on.
#ifdef __EMSCRIPTEN__
// In the browser the button tracks real browser fullscreen, which a freshly
// loaded page is never in (entering it needs a user gesture). Qt's
// isFullScreen() is unreliable here — the canvas-filling window always looks
// fullscreen — so start on "Fullscreen"; the fullscreenchange listener
// installed just below keeps the label in step from then on.
updateFullscreenButton(false);
#else
updateFullscreenButton(isWindow() && isFullScreen());
#endif
installFullscreenSync();
// User level button, immediately left of the fullscreen toggle
m_userLevelBtn = new QPushButton(userLevelLabel(), this);
m_userLevelBtn->setFixedSize(88, 30);
m_userLevelBtn->setToolTip(
"User level — the label shows the level you are on. Click to switch.\n"
" Advanced — every function is available (the default).\n"
" Basic — the function groups that need some background to use\n"
" are hidden: Filter, Amyloid, Particles and Align in\n"
" panel 1, and CTF in panel 2. Everything else is\n"
" unchanged, and nothing already in a buffer is lost.");
connect(m_userLevelBtn, &QPushButton::clicked, this, &FtWindow::onToggleUserLevel);
// Mode cycle button
m_modeBtn = new QPushButton(modeLabel(), this);
m_modeBtn->setFixedSize(180, 30);
m_modeBtn->setToolTip("Switch between display modes for the Fourier space");
connect(m_modeBtn, &QPushButton::clicked, this, &FtWindow::onCycleMode);
m_modeBtn->hide();
// m_maskBtn ("mask center for display") is custom-painted in paintEvent
// so the panel-2 tool dialog can cover it. Click handling lives in
// mousePressEvent via m_maskBtnRect.
// The platform's own button font size, before any scaling has touched it.
// resizeEvent() scales the labelled buttons down from here.
m_chromeBaseFontPx = std::max(8, QFontInfo(m_loadBtn->font()).pixelSize());
// Any top-level button click should dismiss the "New image" popup
// (these buttons intercept mouse events, so mousePressEvent does not run).
auto dismissNewImg = [this]() { if (m_newImageActive) onNewImageCancel(); };
for (QPushButton *b : {m_loadBtn, m_saveBtn, m_reloadBtn, m_copyImageBtn, m_deleteBtn,
m_undoBtn, m_redoBtn, m_fullscreenBtn, m_modeBtn,
m_userLevelBtn}) {
connect(b, &QPushButton::pressed, this, dismissNewImg);
}
// Bandpass filter widgets (hidden until bandpass mode active)
m_smoothEdit = new QLineEdit("0", this);
m_smoothEdit->setFixedSize(40, 22);
m_smoothEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_smoothEdit->setToolTip(
"Soft-edge width of the bandpass ring, in Fourier pixels.\n"
"0 = hard edge (sharp cutoff). Larger values give a smoother\n"
"Hanning-style transition between the kept and erased regions,\n"
"which reduces ringing artefacts in the back-transformed image.");
m_smoothEdit->hide();
m_bandEraseOutside = new QCheckBox("Erase pixels outside of band", this);
m_bandEraseOutside->setStyleSheet(checkBoxStyle("white"));
m_bandEraseOutside->setChecked(true);
m_bandEraseOutside->setToolTip(
"Checked: keep only Fourier pixels inside the ring (band-pass);\n"
" everything outside is set to zero.\n"
"Unchecked: erase Fourier pixels inside the ring (band-stop);\n"
" everything outside is left untouched.");
m_bandEraseOutside->hide();
m_applyBandBtn = new QPushButton("Apply filter", this);
m_applyBandBtn->setFixedSize(100, 26);
connect(m_applyBandBtn, &QPushButton::clicked, this, [this]() {
if (m_bandpassActive) onApplyBandpass();
else if (m_directionalActive) onApplyDirectional();
});
m_applyBandBtn->hide();
m_resetBandBtn = new QPushButton("Reset", this);
m_resetBandBtn->setFixedSize(80, 26);
connect(m_resetBandBtn, &QPushButton::clicked, this, [this]() {
m_bandInnerR = 0.1;
m_bandOuterR = 0.9;
update();
});
m_resetBandBtn->hide();
// Line filter widgets (hidden until line filter mode active)
m_lineWidthEdit = new QLineEdit("10", this);
m_lineWidthEdit->setFixedSize(40, 22);
m_lineWidthEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_lineWidthEdit->setToolTip(
"Half-width of the Fourier-space line, in pixels.\n"
"Sets how thick the kept (or erased) stripe is, measured\n"
"perpendicular to the chosen direction. A value of 10 means\n"
"the stripe spans 10 pixels on each side of its centre line.");
m_lineWidthEdit->hide();
m_lineDirectionEdit = new QLineEdit("0", this);
m_lineDirectionEdit->setFixedSize(50, 22);
m_lineDirectionEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_lineDirectionEdit->setToolTip(
"Orientation of the Fourier-space line, in degrees.\n"
"0\u00B0 = horizontal stripe through the Fourier centre,\n"
"90\u00B0 = vertical. Positive angles rotate counter-clockwise.\n"
"You can also drag the line in panel 2 to change this.");
m_lineDirectionEdit->hide();
m_lineOffsetEdit = new QLineEdit("0", this);
m_lineOffsetEdit->setFixedSize(50, 22);
m_lineOffsetEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_lineOffsetEdit->setToolTip(
"Signed offset of the line from the Fourier centre, in pixels,\n"
"measured perpendicular to the line direction. Drag the line in\n"
"the right half of panel 2 to change this interactively.");
m_lineOffsetEdit->hide();
connect(m_lineOffsetEdit, &QLineEdit::editingFinished, this, [this]() {
bool ok = false;
double v = m_lineOffsetEdit->text().toDouble(&ok);
if (ok) { m_lineOffset = v; update(); }
});
m_lineEraseOutsideBtn = new QCheckBox("Erase pixels outside of line", this);
m_lineEraseOutsideBtn->setStyleSheet(checkBoxStyle("white"));
m_lineEraseOutsideBtn->setChecked(true);
m_lineEraseOutsideBtn->setToolTip(
"Checked: keep only the line/stripe and zero everything else\n"
" (useful for extracting a single Fourier direction).\n"
"Unchecked: erase the line/stripe and keep everything else\n"
" (useful for removing directional noise such as\n"
" scan lines or grid artefacts).");
m_lineEraseOutsideBtn->hide();
m_applyLineBtn = new QPushButton("Apply filter", this);
m_applyLineBtn->setFixedSize(100, 26);
connect(m_applyLineBtn, &QPushButton::clicked, this, &FtWindow::onApplyLineFilter);
m_applyLineBtn->hide();
// Brush parameter widgets
m_brushValueLabel = new QLabel("Pixel value to enter:", this);
m_brushValueLabel->setStyleSheet("color: white;");
m_brushValueLabel->hide();
m_brushValueEdit = new QLineEdit("0", this);
m_brushValueEdit->setFixedSize(60, 22);
m_brushValueEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_brushValueEdit->setToolTip(
"Real part of the Fourier-space amplitude to paint.\n"
"The brush writes this value into the FFT (with zero imaginary\n"
"part) under the Gaussian footprint, weighted by the brush\n"
"profile. Use 0 to gently push amplitudes toward zero.");
m_brushValueEdit->hide();
m_brushDiamLabel = new QLabel("Paint brush Gaussian diameter:", this);
m_brushDiamLabel->setStyleSheet("color: white;");
m_brushDiamLabel->hide();
m_brushDiameterEdit = new QLineEdit("0", this);
m_brushDiameterEdit->setFixedSize(40, 22);
m_brushDiameterEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_brushDiameterEdit->setToolTip(
"Diameter of the Gaussian paint footprint, in Fourier pixels.\n"
"Sets the full-width of the smooth bell-shaped brush. Larger\n"
"values affect more Fourier pixels at once and produce a\n"
"softer fall-off at the edges of the painted region.");
m_brushDiameterEdit->hide();
// Eraser parameter widgets
m_eraserDiamLabel = new QLabel("Eraser Gaussian diameter:", this);
m_eraserDiamLabel->setStyleSheet("color: white;");
m_eraserDiamLabel->hide();
m_eraserDiameterEdit = new QLineEdit("0", this);
m_eraserDiameterEdit->setFixedSize(40, 22);
m_eraserDiameterEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_eraserDiameterEdit->setToolTip(
"Diameter of the Gaussian eraser footprint, in Fourier pixels.\n"
"Click in panel 2 to multiply the FFT by (1 \u2212 Gaussian) under\n"
"this footprint, smoothly attenuating Fourier components.\n"
"Larger diameters erase a wider region with a softer edge.");
m_eraserDiameterEdit->hide();
// Lattice filter widgets (hidden until lattice mode active)
m_latticeSmoothLabel = new QLabel("Smooth edge by pixels:", this);
m_latticeSmoothLabel->setStyleSheet("color: white;");
m_latticeSmoothLabel->hide();
m_latticeSmoothEdit = new QLineEdit("0", this);
m_latticeSmoothEdit->setFixedSize(40, 22);
m_latticeSmoothEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_latticeSmoothEdit->setToolTip(
"Soft-edge width of each lattice dot, in Fourier pixels.\n"
"0 = hard circular edge. Larger values give a smooth Hanning-\n"
"style fall-off around each spot, which suppresses ringing\n"
"in the back-transformed image.");
m_latticeSmoothEdit->hide();
m_latticeDotDiamLabel = new QLabel("Diameter of dots:", this);
m_latticeDotDiamLabel->setStyleSheet("color: white;");
m_latticeDotDiamLabel->hide();
m_latticeDotDiamEdit = new QLineEdit("3", this);
m_latticeDotDiamEdit->setFixedSize(40, 22);
m_latticeDotDiamEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_latticeDotDiamEdit->setToolTip(
"Diameter of each lattice spot, in Fourier pixels.\n"
"All reciprocal-lattice positions generated by the (u,v) basis\n"
"vectors will be selected as circles of this size. Use a\n"
"value just large enough to enclose the diffraction peaks.");
m_latticeDotDiamEdit->hide();
m_latticeEraseOutside = new QCheckBox("Erase pixels outside of lattice", this);
m_latticeEraseOutside->setStyleSheet(checkBoxStyle("white"));
m_latticeEraseOutside->setChecked(true);
m_latticeEraseOutside->setToolTip(
"Checked: keep only the lattice spots and zero everything else\n"
" (lattice band-pass; useful for crystal averaging).\n"
"Unchecked: erase the lattice spots and keep everything else\n"
" (removes the periodic component).");
m_latticeEraseOutside->hide();
m_latticeApplyBtn = new QPushButton("Apply filter", this);
m_latticeApplyBtn->setFixedSize(100, 26);
connect(m_latticeApplyBtn, &QPushButton::clicked, this, &FtWindow::onApplyLattice);
m_latticeApplyBtn->hide();
// Lattice basis vector entry (u = (Ux, Uy), v = (Vx, Vy))
auto makeLatticeVecEdit = [this](const QString &tip) {
auto *e = new QLineEdit(this);
e->setFixedSize(52, 22);
e->setStyleSheet("background:#222; color:white; border:1px solid #888;");
e->setToolTip(tip);
e->hide();
return e;
};
QString uTip = "x/y component of the reciprocal-lattice basis vector u,\n"
"in Fourier pixels relative to the FFT centre. All lattice\n"
"spots generated by integer combinations of u and v are\n"
"selected. Edit to set u numerically, or drag the u handle\n"
"in panel 2.";
QString vTip = "x/y component of the reciprocal-lattice basis vector v,\n"
"in Fourier pixels relative to the FFT centre. All lattice\n"
"spots generated by integer combinations of u and v are\n"
"selected. Edit to set v numerically, or drag the v handle\n"
"in panel 2.";
m_latticeUxEdit = makeLatticeVecEdit(uTip);
m_latticeUyEdit = makeLatticeVecEdit(uTip);
m_latticeVxEdit = makeLatticeVecEdit(vTip);
m_latticeVyEdit = makeLatticeVecEdit(vTip);
auto applyLatticeVecEdits = [this]() {
bool ok = false;
double v;
v = m_latticeUxEdit->text().toDouble(&ok); if (ok) m_latticeUx = v;
v = m_latticeUyEdit->text().toDouble(&ok); if (ok) m_latticeUy = v;
v = m_latticeVxEdit->text().toDouble(&ok); if (ok) m_latticeVx = v;
v = m_latticeVyEdit->text().toDouble(&ok); if (ok) m_latticeVy = v;
syncLatticeVectorEdits();
update();
};
connect(m_latticeUxEdit, &QLineEdit::editingFinished, this, applyLatticeVecEdits);
connect(m_latticeUyEdit, &QLineEdit::editingFinished, this, applyLatticeVecEdits);
connect(m_latticeVxEdit, &QLineEdit::editingFinished, this, applyLatticeVecEdits);
connect(m_latticeVyEdit, &QLineEdit::editingFinished, this, applyLatticeVecEdits);
syncLatticeVectorEdits();
// Fourier math widgets (hidden until Fourier math mode active)
{
auto ftMathComboStyle = [](QComboBox *cb) {
cb->setStyleSheet(
"QComboBox { background:white; color:black; border:1px solid #888;"
" padding: 2px 8px; font-size: 26px; font-weight: bold; }"
"QComboBox::drop-down { width: 28px; }"
"QComboBox QAbstractItemView { background:white; color:black;"
" selection-background-color:#ccc; min-width: 80px; padding: 4px;"
" font-size: 26px; }"
);
};
m_ftMathOutCombo = new QComboBox(this);
for (int i = 0; i < HISTORY_SLOTS; i++)
m_ftMathOutCombo->addItem(QString(QChar('A' + i)));
m_ftMathOutCombo->setFixedSize(100, 56);
ftMathComboStyle(m_ftMathOutCombo);
m_ftMathOutCombo->setToolTip(
"Output buffer (A\u2026P) that will receive the result of the\n"
"Fourier-space operation. Capital letters refer to the FFT\n"
"of the corresponding history slot. Any existing content of\n"
"the chosen buffer is overwritten.");
m_ftMathOutCombo->hide();
m_ftMathEqualsLabel = new QLabel("=", this);
m_ftMathEqualsLabel->setStyleSheet("color: black; font-size: 36px; font-weight: bold;");
m_ftMathEqualsLabel->setFixedSize(40, 56);
m_ftMathEqualsLabel->setAlignment(Qt::AlignCenter);
m_ftMathEqualsLabel->hide();
m_ftMathIn1Combo = new QComboBox(this);
for (int i = 0; i < HISTORY_SLOTS; i++)
m_ftMathIn1Combo->addItem(QString(QChar('A' + i)));
m_ftMathIn1Combo->setFixedSize(100, 56);
ftMathComboStyle(m_ftMathIn1Combo);
m_ftMathIn1Combo->setToolTip(
"First input buffer (A\u2026P) for the Fourier-space operation.\n"
"Refers to the FFT of the corresponding history slot.");
m_ftMathIn1Combo->hide();
m_ftMathOpCombo = new QComboBox(this);
m_ftMathOpCombo->addItem("+");
m_ftMathOpCombo->addItem("\u2212"); // minus sign
m_ftMathOpCombo->addItem("\u00D7"); // multiplication sign
m_ftMathOpCombo->addItem("\u00F7"); // division sign
m_ftMathOpCombo->setFixedSize(100, 56);
ftMathComboStyle(m_ftMathOpCombo);
m_ftMathOpCombo->setToolTip(
"Operation applied between the two Fourier-space inputs:\n"
" + complex addition\n"
" \u2212 complex subtraction\n"
" \u00D7 complex multiplication (= real-space convolution)\n"
" \u00F7 complex division (= real-space deconvolution)");
m_ftMathOpCombo->hide();
m_ftMathIn2Combo = new QComboBox(this);
for (int i = 0; i < HISTORY_SLOTS; i++)
m_ftMathIn2Combo->addItem(QString(QChar('A' + i)));
m_ftMathIn2Combo->setFixedSize(100, 56);
ftMathComboStyle(m_ftMathIn2Combo);
m_ftMathIn2Combo->setToolTip(
"Second input buffer (A\u2026P) for the Fourier-space operation.\n"
"Optionally complex-conjugated (see the \"*\" selector).");
m_ftMathIn2Combo->hide();
m_ftMathConjCombo = new QComboBox(this);
m_ftMathConjCombo->addItem(" ");
m_ftMathConjCombo->addItem("* (complex conjugate)");
m_ftMathConjCombo->setFixedSize(260, 56);
ftMathComboStyle(m_ftMathConjCombo);
m_ftMathConjCombo->setToolTip(
"If \"*\" is selected the second input is complex-conjugated\n"
"before the operation. Combined with \u00D7 this gives a\n"
"Fourier-space cross-correlation (A \u00D7 B*) instead of a\n"
"convolution.");
m_ftMathConjCombo->hide();
m_ftMathCancelBtn = new QPushButton("Cancel", this);
m_ftMathCancelBtn->setFixedSize(80, 28);
m_ftMathCancelBtn->setStyleSheet(
"QPushButton { background-color: #888; border: 2px outset #aaa; color: #eee; padding: 2px; }");
connect(m_ftMathCancelBtn, &QPushButton::clicked, this, &FtWindow::onFtMathCancel);
m_ftMathCancelBtn->hide();
m_ftMathComputeBtn = new QPushButton("Compute", this);
m_ftMathComputeBtn->setFixedSize(80, 28);
m_ftMathComputeBtn->setStyleSheet(
"QPushButton { background-color: #888; border: 2px outset #aaa; color: #eee; padding: 2px; }");
connect(m_ftMathComputeBtn, &QPushButton::clicked, this, &FtWindow::onFtMathCompute);
m_ftMathComputeBtn->hide();
}
// Fourier crop widgets (hidden until Fourier crop mode active)
m_ftCropCombo = new QComboBox(this);
for (int i = 2; i <= 8; i++)
m_ftCropCombo->addItem(QString::number(i), i);
m_ftCropCombo->setFixedSize(70, 28);
m_ftCropCombo->setStyleSheet(
"QComboBox { background:#222; color:white; border:1px solid #888;"
" padding: 2px 8px; }"
"QComboBox::drop-down { width: 20px; }"
"QComboBox QAbstractItemView { background:#222; color:white;"
" selection-background-color:#555; min-width: 60px; padding: 4px; }"
);
m_ftCropCombo->setToolTip(
"Fourier crop factor N. Only the central 1/N \u00D7 1/N of the\n"
"Fourier transform is kept; everything outside is discarded.\n"
"This is equivalent to low-pass filtering followed by Fourier\n"
"downsampling, and is the cleanest way to reduce resolution.");
m_ftCropCombo->hide();
m_ftCropKeepSizeBtn = new QCheckBox("Keep original size", this);
m_ftCropKeepSizeBtn->setStyleSheet(checkBoxStyle("white"));
m_ftCropKeepSizeBtn->setChecked(true);
m_ftCropKeepSizeBtn->setToolTip(
"Checked: the FFT array stays at its original dimensions and\n"
" pixels outside the central crop window are zeroed.\n"
" The real-space image keeps its sampling.\n"
"Unchecked: the FFT array is physically shrunk by N. The real-\n"
" space image becomes N\u00D7 smaller, with N\u00D7 larger pixels.");
m_ftCropKeepSizeBtn->hide();
m_applyFtCropBtn = new QPushButton("Fourier crop", this);
m_applyFtCropBtn->setFixedSize(120, 26);
connect(m_applyFtCropBtn, &QPushButton::clicked, this, &FtWindow::onApplyFtCrop);
m_applyFtCropBtn->hide();
m_applyFtPadBtn = new QPushButton("Fourier pad", this);
m_applyFtPadBtn->setFixedSize(120, 26);
m_applyFtPadBtn->setToolTip(
"Zero-pad the current Fourier transform to N\u00D7 its current\n"
"linear dimensions, where N is the selected factor. This\n"
"oversamples the real-space image (finer pixel sampling\n"
"without adding information). The FFT size is capped at\n"
"4096\u00D74096.");
connect(m_applyFtPadBtn, &QPushButton::clicked, this, &FtWindow::onApplyFtPad);
m_applyFtPadBtn->hide();
// Cross-section evaluation-line direction widget (degrees)
m_crossSectionDirEdit = new QLineEdit("0", this);
m_crossSectionDirEdit->setFixedSize(50, 22);
m_crossSectionDirEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_crossSectionDirEdit->setToolTip(
"Direction of the evaluation line through the Fourier-transform\n"
"center, in degrees (counter-clockwise from the horizontal axis).\n"
"Type a value to rotate the red lines, or drag them in panel 2 to\n"
"set the direction; the field and profiles update live.");
connect(m_crossSectionDirEdit, &QLineEdit::textChanged, this, [this]() {
if (m_crossSectionActive && m_ftComputed) {
bool ok = false;
double deg = m_crossSectionDirEdit->text().toDouble(&ok);
if (ok) {
m_crossSectionAngle = -deg; // math (y-up) -> screen (y-down)
computeCrossSectionProfile();
update();
}
}
});
m_crossSectionDirEdit->hide();
// Cross-section integration-width widget (reciprocal pixels, minimum 1)
m_crossSectionWidthEdit = new QLineEdit("5", this);
m_crossSectionWidthEdit->setFixedSize(50, 22);
m_crossSectionWidthEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_crossSectionWidthEdit->setValidator(new QDoubleValidator(1.0, 1.0e6, 2, m_crossSectionWidthEdit));
m_crossSectionWidthEdit->setToolTip(
"Width of the integration band used for the 1D profiles, in\n"
"reciprocal (Fourier) pixels. Pixels within this band around the\n"
"line are integrated into the amplitude and phase profiles.\n"
"Minimum 1. Increase to reduce noise, decrease for higher angular\n"
"resolution. The profiles update live as you type.");
connect(m_crossSectionWidthEdit, &QLineEdit::textChanged, this, [this]() {
if (m_crossSectionActive && m_ftComputed) {
computeCrossSectionProfile();
update();
}
});
m_crossSectionWidthEdit->hide();
// Panel 2 Fourier-space symmetrize widgets
m_p2SymmetryEdit = new QLineEdit("4", this);
m_p2SymmetryEdit->setFixedSize(50, 22);
m_p2SymmetryEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_p2SymmetryEdit->setToolTip(
"Rotational symmetry order N to enforce on the Fourier\n"
"transform around its center (DC term). The current FT is\n"
"averaged with its rotated copies at angles k·360°/N\n"
"(k = 0…N−1). The real-space image is updated via the\n"
"inverse FFT. Use N = 2 for two-fold, 3 for three-fold, etc.");
m_p2SymmetryEdit->hide();
m_applyP2SymmetryBtn = new QPushButton("Apply symmetry", this);
m_applyP2SymmetryBtn->setFixedSize(130, 26);
connect(m_applyP2SymmetryBtn, &QPushButton::clicked, this, &FtWindow::onApplyFtSymmetry);
m_applyP2SymmetryBtn->hide();
// CTF parameter widgets
auto makeCtfEdit = [this](const QString &def) {
auto *e = new QLineEdit(def, this);
e->setFixedSize(60, 22);
e->setStyleSheet("background:#222; color:white; border:1px solid #888;");
e->hide();
return e;
};
m_ctfVoltageEdit = makeCtfEdit("300");
m_ctfVoltageEdit->setToolTip(
"Acceleration voltage of the microscope in kV. Determines the\n"
"relativistic electron wavelength used in the Scherzer contrast\n"
"transfer function.");
m_ctfEnergySpreadEdit = makeCtfEdit("0.7");
m_ctfEnergySpreadEdit->setToolTip(
"Energy spread of the electron beam in eV. Used to model the\n"
"temporal coherence envelope of the CTF.");
m_ctfOpenAngleEdit = makeCtfEdit("0.1");
m_ctfOpenAngleEdit->setToolTip(
"Beam half-convergence angle (gun opening semi-angle) in mrad.\n"
"Controls the spatial-coherence envelope\n"
" E_s(q) = exp(-\u03C0\u00B2\u00B7\u03B1\u00B2\u00B7q\u00B2\u00B7(\u0394f + Cs\u00B7\u03BB\u00B2\u00B7q\u00B2)\u00B2)\n"
"that damps the CTF at high spatial frequencies due to a\n"
"non-zero illumination aperture.");
m_ctfDefocusSpreadEdit = makeCtfEdit("5");
m_ctfDefocusSpreadEdit->setToolTip(
"Defocus spread (\u0394z) in nm. Models the defocus-dependent\n"
"temporal-coherence envelope\n"
" E_t(q) = exp(-\u00BD(\u03C0\u00B7\u03BB\u00B7\u0394z\u00B7q\u00B2)\u00B2).\n"
"Combined in quadrature with the chromatic contribution from\n"
"the energy spread.");
m_ctfCsEdit = makeCtfEdit("2.7");
m_ctfCsEdit->setToolTip(
"Spherical aberration constant Cs of the objective lens in mm.");
m_ctfDefocusEdit = makeCtfEdit("1000");
m_ctfDefocusEdit->setToolTip(
"Defocus value in nm (positive = underfocus).");
m_ctfAstigEdit = makeCtfEdit("0");
m_ctfAstigEdit->setToolTip(
"Astigmatism amplitude in nm. This is the defocus deviation\n"
"along the astigmatism axis relative to the average defocus.\n"
"The defocus varies azimuthally as\n"
" \u0394f(\u03B8) = \u0394f_avg + \u0394f_A \u00B7 cos(2(\u03B8 - \u03B1))\n"
"so the average defocus is found 45\u00B0 away from the astigmatism\n"
"direction.");
m_ctfAstigAngleEdit = makeCtfEdit("0");
m_ctfAstigAngleEdit->setToolTip(
"Astigmatism direction in degrees, measured counter-clockwise\n"
"from the horizontal axis, following the usual EM convention.");
m_ctfAmpContrastEdit = makeCtfEdit("7");
m_ctfAmpContrastEdit->setToolTip(
"Amplitude contrast in percent. Used as the amplitude-contrast\n"
"term B in the CTF; the phase-contrast term is then\n"
" A = √(1 − B²),\n"
"and the CTF is A·sin(−χ) + B·cos(−χ).");
m_ctfBeamtiltEdit = makeCtfEdit("0");
m_ctfBeamtiltEdit->setToolTip(
"Beam tilt magnitude in mrad. A tilted illumination adds a\n"
"coma-like phase shift to the wave aberration\n"
" Δχ = 2π·Cs·λ²·q³·τ·cos(θ − τ_dir)\n"
"where τ is the tilt angle (rad) and τ_dir its direction.");
m_ctfBeamtiltDirEdit = makeCtfEdit("0");
m_ctfBeamtiltDirEdit->setToolTip(
"Beam tilt direction in degrees, measured counter-clockwise\n"
"from the horizontal axis, following the usual EM convention.");
m_ctfCancelBtn = new QPushButton("Cancel", this);
m_ctfCancelBtn->setFixedSize(80, 26);
m_ctfCancelBtn->setStyleSheet(
"QPushButton { background-color: #888; border: 2px outset #aaa; color: #eee; padding: 2px; }");
connect(m_ctfCancelBtn, &QPushButton::clicked, this, &FtWindow::onCtfCancel);
m_ctfCancelBtn->hide();
// Three ways to simulate the same microscope. They are genuinely different
// physics, not display options, so each gets its own button rather than
// hiding behind one "Compute".
const QString ctfBtnSS =
"QPushButton { background-color: #888; border: 2px outset #aaa; color: #eee; padding: 2px; }";
m_ctfPupilBtn = new QPushButton("Pupil Function", this);
m_ctfPupilBtn->setFixedSize(120, 26);
m_ctfPupilBtn->setStyleSheet(ctfBtnSS);
m_ctfPupilBtn->setToolTip(
"PUPIL FUNCTION P(q) = E(q)·exp(−iχ(q)) — wave optics\n"
"\n"
"Fourier space (panel 2) is filled with the aberrated lens pupil: the\n"
"phase is the full wave aberration χ (defocus, Cs, astigmatism and the\n"
"beam tilt), and the modulus is only the partial-coherence envelope E.\n"
"There are therefore NO Thon rings — rings belong to the intensity CTF\n"
"below, not to the pupil. With a beam tilt χ(q) ≠ χ(−q), so the pupil is\n"
"not Hermitian.\n"
"\n"
"Real space (panel 1) shows the point spread function |h|², where\n"
"h = FT⁻¹[P]: the image of a single luminous point, i.e. what the\n"
"microscope does to a delta function. Because P is not Hermitian, h is\n"
"genuinely complex and |h|² is asymmetric — the classic one-sided comet\n"
"of coma. The intensity, not the real part, is what a detector records.\n"
"\n"
"Note: amplitude contrast enters only as a constant phase and so leaves\n"
"|h|² unchanged in this model.\n"
"\n"
"Use this to see the aberration as an optician would: the shape of the\n"
"focused spot.");
connect(m_ctfPupilBtn, &QPushButton::clicked, this,
[this]() { computeCtfWithModel(CtfModel::Pupil); });
m_ctfPupilBtn->hide();
m_ctfComplexBtn = new QPushButton("Complex CTF", this);
m_ctfComplexBtn->setFixedSize(120, 26);
m_ctfComplexBtn->setStyleSheet(ctfBtnSS);
m_ctfComplexBtn->setToolTip(
"COMPLEX CTF T(q) = E(q)·(A·sin(−χ_even)+B·cos(−χ_even))·exp(−iχ_odd)\n"
"— the linear image-intensity transfer function of a weak-phase object.\n"
"\n"
"The tilted aberration is split into its even part χ_even (defocus, Cs,\n"
"astigmatism, and the defocus/astigmatism the tilt itself induces),\n"
"which produces the oscillating Thon rings, and its odd part χ_odd\n"
"(coma), which enters purely as a phase and leaves the modulus alone.\n"
"\n"
"T is Hermitian: T(−q) = T*(q). That is not an approximation — image\n"
"intensity is real, so its transform must be Hermitian, and the power\n"
"spectrum of any real image is centrosymmetric (Friedel's law). Panel 2\n"
"therefore shows SYMMETRIC Thon rings even under beam tilt; the tilt is\n"
"carried by the phase, exactly as in a real micrograph.\n"
"\n"
"Real space (panel 1) is real-valued but NOT symmetric: Hermitian means\n"
"a real image, even means a symmetric image, and T is Hermitian without\n"
"being even. The PSF therefore shows the one-sided coma while the image\n"
"stays real — no imaginary part is discarded here.\n"
"\n"
"This is the physically correct model for what a real micrograph and\n"
"its power spectrum look like.");
connect(m_ctfComplexBtn, &QPushButton::clicked, this,
[this]() { computeCtfWithModel(CtfModel::ComplexCTF); });
m_ctfComplexBtn->hide();
m_ctfRealBtn = new QPushButton("Real-valued CTF", this);
m_ctfRealBtn->setFixedSize(120, 26);
m_ctfRealBtn->setStyleSheet(ctfBtnSS);
m_ctfRealBtn->setToolTip(
"REAL-VALUED CTF C(q) = E(q)·(A·sin(−χ_tilt)+B·cos(−χ_tilt))\n"
"— the transfer function evaluated at the full tilted aberration and\n"
"kept purely real (no even/odd split, no phase factor).\n"
"\n"
"Panel 2 shows Thon rings that are themselves one-sided under beam tilt,\n"
"because χ_tilt(q) ≠ χ_tilt(−q) and nothing symmetrises them. C is real\n"
"but not even, hence NOT Hermitian.\n"
"\n"
"Caution — this is a didactic model, not a microscope: no real image can\n"
"have an asymmetric power spectrum. And because C is real, its inverse\n"
"transform obeys h(−r) = h*(r), so the real part shown in panel 1 is\n"
"EXACTLY centrosymmetric: the PSF shows no coma whatsoever. All of the\n"
"asymmetry sits in the imaginary part that is discarded.\n"
"\n"
"Compare with the two models above to see why an asymmetric CTF and an\n"
"asymmetric PSF cannot coexist in a single real-valued function: the\n"
"Pupil buys the comet with a complex transform, the Complex CTF buys it\n"
"with a Hermitian-but-uneven one, and this model buys asymmetric rings\n"
"at the cost of the comet.");
connect(m_ctfRealBtn, &QPushButton::clicked, this,
[this]() { computeCtfWithModel(CtfModel::RealCTF); });
m_ctfRealBtn->hide();
for (QLineEdit *e : { m_ctfVoltageEdit, m_ctfEnergySpreadEdit,
m_ctfDefocusSpreadEdit, m_ctfOpenAngleEdit,
m_ctfCsEdit, m_ctfDefocusEdit,
m_ctfAstigEdit, m_ctfAstigAngleEdit,
m_ctfAmpContrastEdit, m_ctfBeamtiltEdit,
m_ctfBeamtiltDirEdit })
connect(e, &QLineEdit::returnPressed, this, &FtWindow::onCtfCompute);
// CTF FIT parameter widgets (only kV, Cs and a target buffer; the defocus,
// astigmatism and astigmatism angle are recovered by the fit itself).
m_ctfFitVoltageEdit = makeCtfEdit("300");
m_ctfFitVoltageEdit->setToolTip(
"Acceleration voltage of the microscope in kV. Determines the\n"
"relativistic electron wavelength used in the CTF fit.");
m_ctfFitCsEdit = makeCtfEdit("2.7");
m_ctfFitCsEdit->setToolTip(
"Spherical aberration constant Cs of the objective lens in mm.");
m_ctfFitInputCombo = new QComboBox(this);
for (int i = 0; i < HISTORY_SLOTS; i++)
m_ctfFitInputCombo->addItem(QString(QChar('A' + i)));
m_ctfFitInputCombo->setFixedSize(60, 22);
m_ctfFitInputCombo->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_ctfFitInputCombo->setToolTip(
"Input buffer (A…P) whose Fourier transform the CTF is fitted to.\n"
"The fitted CTF composite is written into the currently selected\n"
"buffer.");
m_ctfFitInputCombo->hide();
// Switching the fitted buffer re-seeds the resolution limits, since they are
// derived from that buffer's pixel size.
connect(m_ctfFitInputCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, [this](int) { if (m_ctfFitActive) updateCtfFitResolutionDefaults(); });
m_ctfFitResHiEdit = makeCtfEdit("3");
m_ctfFitResHiEdit->setToolTip(
"Upper resolution limit in Ångström (the finest, i.e. smallest\n"
"d-spacing) that is included in the CTF fit. Frequencies beyond\n"
"this (finer than the Nyquist limit) are ignored.\n"
"Defaults to 90% of the Nyquist frequency of the fitted buffer.");
m_ctfFitResLoEdit = makeCtfEdit("30");
m_ctfFitResLoEdit->setToolTip(
"Lower resolution limit in Ångström (the coarsest, i.e. largest\n"
"d-spacing) that is included in the CTF fit. Very low frequencies\n"
"below this are ignored.\n"
"Defaults to 10% of the Nyquist frequency of the fitted buffer.");
m_ctfFitCancelBtn = new QPushButton("Cancel", this);
m_ctfFitCancelBtn->setFixedSize(80, 26);
m_ctfFitCancelBtn->setStyleSheet(
"QPushButton { background-color: #888; border: 2px outset #aaa; color: #eee; padding: 2px; }");
connect(m_ctfFitCancelBtn, &QPushButton::clicked, this, &FtWindow::onCtfFitCancel);
m_ctfFitCancelBtn->hide();
m_ctfFitExecuteBtn = new QPushButton("Execute", this);
m_ctfFitExecuteBtn->setFixedSize(80, 26);
m_ctfFitExecuteBtn->setStyleSheet(
"QPushButton { background-color: #888; border: 2px outset #aaa; color: #eee; padding: 2px; }");
connect(m_ctfFitExecuteBtn, &QPushButton::clicked, this, &FtWindow::onCtfFitExecute);
m_ctfFitExecuteBtn->hide();
for (QLineEdit *e : { m_ctfFitVoltageEdit, m_ctfFitCsEdit,
m_ctfFitResHiEdit, m_ctfFitResLoEdit })
connect(e, &QLineEdit::returnPressed, this, &FtWindow::onCtfFitExecute);
// Phase ramp parameter widgets
m_phaseRampSizeCombo = new QComboBox(this);
for (int sz : {512, 1024, 2048, 4096})
m_phaseRampSizeCombo->addItem(QString::number(sz), sz);
m_phaseRampSizeCombo->setCurrentIndex(1); // 1024 default
m_phaseRampSizeCombo->setFixedSize(80, 28);
m_phaseRampSizeCombo->setStyleSheet(
"QComboBox { background:#222; color:white; border:1px solid #888;"
" padding: 2px 8px; }"
"QComboBox::drop-down { width: 20px; }"
"QComboBox QAbstractItemView { background:#222; color:white;"
" selection-background-color:#555; min-width: 70px; padding: 4px; }"
);
m_phaseRampSizeCombo->setToolTip(
"Linear size N of the Fourier transform to be created (NxN).");
m_phaseRampSizeCombo->hide();
m_phaseRampDirEdit = new QLineEdit("30", this);
m_phaseRampDirEdit->setFixedSize(60, 22);
m_phaseRampDirEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_phaseRampDirEdit->setToolTip(
"Direction of the phase ramp, in degrees, measured counter-\n"
"clockwise from the +x axis. The phase increases linearly along\n"
"this direction.");
m_phaseRampDirEdit->hide();
m_phaseRampStepEdit = new QLineEdit("10", this);
m_phaseRampStepEdit->setFixedSize(60, 22);
m_phaseRampStepEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_phaseRampStepEdit->setToolTip(
"Phase increment per pixel along the ramp direction, in degrees.\n"
"The phase at the origin is zero and grows by this amount for\n"
"each unit step along the chosen direction.");
m_phaseRampStepEdit->hide();
m_phaseRampCancelBtn = new QPushButton("Cancel", this);
m_phaseRampCancelBtn->setFixedSize(80, 26);
m_phaseRampCancelBtn->setStyleSheet(
"QPushButton { background-color: #888; border: 2px outset #aaa; color: #eee; padding: 2px; }");
connect(m_phaseRampCancelBtn, &QPushButton::clicked, this, &FtWindow::onPhaseRampCancel);
m_phaseRampCancelBtn->hide();
m_phaseRampComputeBtn = new QPushButton("Compute", this);
m_phaseRampComputeBtn->setFixedSize(80, 26);
m_phaseRampComputeBtn->setStyleSheet(
"QPushButton { background-color: #888; border: 2px outset #aaa; color: #eee; padding: 2px; }");
connect(m_phaseRampComputeBtn, &QPushButton::clicked, this, &FtWindow::onPhaseRampCompute);
m_phaseRampComputeBtn->hide();
for (QLineEdit *e : {m_phaseRampDirEdit, m_phaseRampStepEdit})
connect(e, &QLineEdit::returnPressed, this, &FtWindow::onPhaseRampCompute);
// Panel 1 eraser parameter widgets
m_p1EraserDiamLabel = new QLabel("Eraser Gaussian diameter:", this);
m_p1EraserDiamLabel->setStyleSheet("color: white;");
m_p1EraserDiamLabel->hide();
m_p1EraserDiameterEdit = new QLineEdit("5", this);
m_p1EraserDiameterEdit->setFixedSize(40, 22);
m_p1EraserDiameterEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_p1EraserDiameterEdit->setToolTip(
"Diameter of the real-space eraser footprint, in image pixels.\n"
"Click in panel 1 to multiply pixel values by (1 \u2212 Gaussian)\n"
"under this footprint, smoothly fading them toward zero.\n"
"Larger diameters affect a wider area with a softer edge.");
m_p1EraserDiameterEdit->hide();
// Panel 1 brush parameter widgets
m_p1BrushValueLabel = new QLabel("Pixel value to enter:", this);
m_p1BrushValueLabel->setStyleSheet("color: white;");
m_p1BrushValueLabel->hide();
m_p1BrushValueEdit = new QLineEdit("1", this);
m_p1BrushValueEdit->setFixedSize(60, 22);
m_p1BrushValueEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_p1BrushValueEdit->setToolTip(
"Real-space pixel value the brush paints into the image.\n"
"The Gaussian footprint blends this value with the existing\n"
"pixels, weighted by the brush profile. Use the image min/max\n"
"scale shown below the panel as a reference.");
m_p1BrushValueEdit->hide();
m_p1BrushSolidLabel = new QLabel("Paint brush solid diameter:", this);
m_p1BrushSolidLabel->setStyleSheet("color: white;");
m_p1BrushSolidLabel->hide();
m_p1BrushSolidDiameterEdit = new QLineEdit("0", this);
m_p1BrushSolidDiameterEdit->setFixedSize(40, 22);
m_p1BrushSolidDiameterEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_p1BrushSolidDiameterEdit->setToolTip(
"Diameter, in image pixels, of a sharp-edged solid disk used\n"
"as the base paint brush footprint. Pixels inside the disk\n"
"are painted with the target value. If a Gaussian diameter\n"
"is also set, this disk is blurred by that Gaussian to soften\n"
"the edge. Set to 0 to use a pure Gaussian brush.");
m_p1BrushSolidDiameterEdit->hide();
m_p1BrushDiamLabel = new QLabel("Paint brush Gaussian diameter:", this);
m_p1BrushDiamLabel->setStyleSheet("color: white;");
m_p1BrushDiamLabel->hide();
m_p1BrushDiameterEdit = new QLineEdit("5", this);
m_p1BrushDiameterEdit->setFixedSize(40, 22);
m_p1BrushDiameterEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_p1BrushDiameterEdit->setToolTip(
"Diameter of the Gaussian paint footprint, in image pixels.\n"
"Sets the full-width of the smooth bell-shaped brush. Larger\n"
"values affect more pixels at once and produce a softer\n"
"fall-off at the edges of the painted region.");
m_p1BrushDiameterEdit->hide();
// Panel 1 taper widgets
m_p1TaperWidthLabel = new QLabel("Hanning width:", this);
m_p1TaperWidthLabel->setStyleSheet("color: white;");
m_p1TaperWidthLabel->hide();
m_p1TaperWidthEdit = new QLineEdit("32", this);
m_p1TaperWidthEdit->setFixedSize(50, 22);
m_p1TaperWidthEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_p1TaperWidthEdit->setToolTip(
"Width, in image pixels, of the Hanning edge taper applied\n"
"to all four image borders. Pixels closer than this distance\n"
"to an edge are smoothly faded toward the image mean. This\n"
"removes the FFT cross artefact caused by sharp image edges\n"
"and is recommended before computing a Fourier transform.");
m_p1TaperWidthEdit->hide();
m_applyP1TaperBtn = new QPushButton("Apply edge taper", this);
m_applyP1TaperBtn->setFixedSize(130, 26);
connect(m_applyP1TaperBtn, &QPushButton::clicked, this, &FtWindow::onApplyEdgeTaper);
m_applyP1TaperBtn->hide();
// Panel 1 symmetrize widgets
m_p1SymmetryLabel = new QLabel("Symmetry to apply:", this);
m_p1SymmetryLabel->setStyleSheet("color: white;");
m_p1SymmetryLabel->hide();
m_p1SymmetryEdit = new QLineEdit("4", this);
m_p1SymmetryEdit->setFixedSize(50, 22);
m_p1SymmetryEdit->setStyleSheet("background:#222; color:white; border:1px solid #888;");
m_p1SymmetryEdit->setToolTip(
"Rotational symmetry order N to apply around the image\n"
"center. The image is averaged with its rotated copies at\n"
"angles k·360°/N (k = 0…N−1), enforcing N-fold rotational\n"
"symmetry. Use N = 2 for two-fold, 3 for three-fold, etc.");
m_p1SymmetryEdit->hide();
// Histogram threshold / truncate widgets
m_threshModeCombo = new QComboBox(this);
m_threshModeCombo->addItem("Threshold histogram", ThresholdToImageRange);
m_threshModeCombo->addItem("Truncate histogram", TruncateToRange);
m_threshModeCombo->addItem("Select histogram", SelectRange);
m_threshModeCombo->setFixedSize(180, 22);
m_threshModeCombo->setStyleSheet(
"QComboBox { background:white; color:black; border:1px solid #888;"
" padding: 2px 4px; }"
"QComboBox::drop-down { width: 20px; }"
"QComboBox QAbstractItemView { background:white; color:black;"
" selection-background-color:#ccc; min-width: 140px; padding: 4px; }");
m_threshModeCombo->setToolTip(
"What happens to the pixels outside the kept range:\n"
" Threshold histogram — a pixel below the minimum is set to the\n"
" image's current minimum and one above the maximum to its\n"
" current maximum, so they are pushed out to full black and\n"
" full white and the range in between is left untouched.\n"
" Truncate histogram — a pixel below the minimum is set to that\n"
" minimum and one above the maximum to that maximum, so the\n"
" values are clipped and nothing outside the range survives.\n"
" Select histogram — everything outside the range, on either side,\n"
" is set to the image's current minimum, so only the pixels\n"
" whose grey value falls inside it are left standing against\n"
" a flat background. Use it to isolate one band of density.\n"
"All three leave every pixel inside the range exactly as it was.");
m_threshModeCombo->hide();
m_threshMinEdit = new QLineEdit("0", this);
m_threshMinEdit->setFixedSize(80, 22);
m_threshMinEdit->setStyleSheet("background:white; color:black; border:1px solid #888;");
m_threshMinEdit->setToolTip(
"Lowest grey value the image may keep. Opens on the left edge of the\n"
"selection in the histogram below the image, and follows it whenever\n"
"that selection is dragged, so marking a range there is enough to set\n"