Skip to content

Commit 53659dd

Browse files
committed
add support for new defocus keyword
1 parent a1091d1 commit 53659dd

13 files changed

Lines changed: 120 additions & 8 deletions
66 KB
Loading
3.75 KB
Loading

doc/visualization.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ there are:
236236
fades distant objects toward a fog color for a stronger sense of
237237
depth. The intensity, fog color, and start position are configured
238238
in the :ref:`Global image settings dialog <global_settings>`.
239+
- **Defocus** (toggle): Enable or disable defocusing, which blurs
240+
distant objects as if the camera were focused on the front of the
241+
scene, while leaving their colors untouched. This can be combined
242+
with depth cueing. The intensity and start position are configured
243+
in the :ref:`Global image settings dialog <global_settings>`.
239244
- **Shininess** (toggle): Switch between shiny and matte surface
240245
rendering of graphics objects like atoms and bonds.
241246
- **VDW style** (toggle): Switch between space-filling (Van der Waals)
@@ -331,10 +336,10 @@ in this dialog correspond to options of the LAMMPS `dump image and
331336
dump_modify commands <https://docs.lammps.org/dump_image.html>`_.
332337

333338
.. |boxaxes| image:: JPG/lammps-gui-image-box-axes.png
334-
:width: 42%
339+
:width: 40%
335340

336341
.. |global| image:: JPG/lammps-gui-image-settings.png
337-
:width: 57%
342+
:width: 59%
338343

339344
|boxaxes| |global|
340345

@@ -413,6 +418,26 @@ The dialog is organized into the following sections:
413418
the camera, 1.0 = far side), or "auto" (the default) to start at
414419
the nearest rendered object.
415420

421+
**Defocus**
422+
Controls defocusing, which blurs distant objects as if the camera
423+
were focused on the front of the scene. Like depth cueing this
424+
draws the attention to the objects in front, but it leaves their
425+
colors untouched, and the two effects may be combined. There is no
426+
color setting for this effect, so that field is left empty.
427+
428+
- **Defocus** (checkbox): Enable or disable defocusing. This is
429+
the same setting that the defocus toolbar button toggles.
430+
- **Intensity**: The strength of the blur (range: 0.0 -- 1.0). At
431+
1.0 the most distant objects are blurred over a radius of 1
432+
percent of the image height. Blurring over much more than the
433+
size of the rendered particles turns them into a uniform haze,
434+
so moderate values usually give the best result.
435+
- **Start**: Where the blurring starts, as a fraction of the
436+
simulation box along the view direction (0.0 = side nearest to
437+
the camera, 1.0 = far side), or "auto" (the default) to start at
438+
the nearest rendered object, which keeps the front of the scene
439+
sharp.
440+
416441
**Quality**
417442
Controls rendering quality options.
418443

resources/icons/defocus.svg

Lines changed: 1 addition & 0 deletions
Loading

resources/lammpsgui.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<file>icons/chart-smooth.svg</file>
5151
<file>icons/comment-out.svg</file>
5252
<file>icons/csv-file-icon.svg</file>
53+
<file>icons/defocus.svg</file>
5354
<file>icons/depth-cue.svg</file>
5455
<file>icons/dialog-cancel.svg</file>
5556
<file>icons/dialog-no.svg</file>

src/dumpimage.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,13 @@ DumpImageCommand buildDumpImageCommand(const DumpImageParams &p)
256256
d += QString(" view %1 %2").arg(hhrot).arg(p.vrot);
257257
}
258258
if (p.usessao) d += QString(" ssao yes %1 %2").arg(Cfg::SSAO_SEED).arg(p.ssaoval);
259-
// depth cueing and outlines default to "no" in LAMMPS, so emit them only when on
259+
// depth cueing, defocus, and outlines default to "no" in LAMMPS, so emit
260+
// them only when on
260261
if (p.usedepthcue)
261262
d += QString(" depthcue yes %1 %2 %3")
262263
.arg(p.depthcuefactor)
263264
.arg(p.depthcuecolor, p.depthcuestart);
265+
if (p.usedefocus) d += QString(" defocus yes %1 %2").arg(p.defocusfactor).arg(p.defocusstart);
264266
if (p.useoutline) d += QString(" outline yes %1 %2").arg(p.outlinewidth).arg(p.outlinecolor);
265267
if (p.showbox)
266268
d += QString(" box yes %1").arg(p.boxdiam);

src/dumpimage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ struct DumpImageParams {
103103
double depthcuefactor; ///< depth cueing strength (0.0 - 1.0)
104104
QString depthcuecolor; ///< fog color name, or "auto" = fade toward the background
105105
QString depthcuestart; ///< fading start as a box fraction along the view direction, or "auto"
106+
bool usedefocus; ///< enable defocusing of distant objects
107+
double defocusfactor; ///< defocus blur strength (0.0 - 1.0)
108+
QString defocusstart; ///< blurring start as a box fraction along the view direction, or "auto"
106109
bool useoutline; ///< draw outlines at depth jumps
107110
int outlinewidth; ///< outline width in pixels (1 - 16)
108111
QString outlinecolor; ///< outline color name

src/imageviewer.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@ ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, Lammps
444444
dodepth->setCheckable(true);
445445
dodepth->setToolTip("Toggle depth cueing");
446446
dodepth->setObjectName("depthcue");
447+
auto *dodefocus = new QPushButton(QIcon(":/icons/defocus.svg"), "");
448+
dodefocus->setCheckable(true);
449+
dodefocus->setToolTip("Toggle defocusing of distant objects");
450+
dodefocus->setObjectName("defocus");
447451
auto *doshiny = new QPushButton(QIcon(":/icons/image-shiny.svg"), "");
448452
doshiny->setCheckable(true);
449453
doshiny->setToolTip("Toggle shininess");
@@ -502,8 +506,8 @@ ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, Lammps
502506

503507
// square toolbar buttons with a snug, uniform icon (shared policy)
504508
styleToolButtons(buttonhint,
505-
{dossao, doanti, dodepth, doshiny, dovdw, dobond, dobox, doaxes, zoomin,
506-
zoomout, rotleft, rotright, rotup, rotdown, recenter, reset, fitwin});
509+
{dossao, doanti, dodepth, dodefocus, doshiny, dovdw, dobond, dobox, doaxes,
510+
zoomin, zoomout, rotleft, rotright, rotup, rotdown, recenter, reset, fitwin});
507511

508512
// match the first-row controls (menu bar and size fields) to the toolbar
509513
// button height so both rows line up and the layout looks balanced
@@ -580,6 +584,7 @@ ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, Lammps
580584
buttonLayout->addWidget(dossao);
581585
buttonLayout->addWidget(doanti);
582586
buttonLayout->addWidget(dodepth);
587+
buttonLayout->addWidget(dodefocus);
583588
buttonLayout->addWidget(doshiny);
584589
buttonLayout->addWidget(dovdw);
585590
buttonLayout->addWidget(dobond);
@@ -621,6 +626,7 @@ ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, Lammps
621626
connect(dossao, &QPushButton::released, this, &ImageViewer::toggleSsao);
622627
connect(doanti, &QPushButton::released, this, &ImageViewer::toggleAnti);
623628
connect(dodepth, &QPushButton::released, this, &ImageViewer::toggleDepthcue);
629+
connect(dodefocus, &QPushButton::released, this, &ImageViewer::toggleDefocus);
624630
connect(doshiny, &QPushButton::released, this, &ImageViewer::toggleShiny);
625631
connect(dovdw, &QPushButton::released, this, &ImageViewer::toggleVdw);
626632
connect(dobond, &QPushButton::released, this, &ImageViewer::toggleBond);
@@ -670,6 +676,7 @@ ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, Lammps
670676
dossao->setChecked(usessao);
671677
doanti->setChecked(antialias);
672678
dodepth->setChecked(usedepthcue);
679+
dodefocus->setChecked(usedefocus);
673680

674681
scrollArea->setVisible(true);
675682
updateActions();
@@ -743,6 +750,9 @@ void ImageViewer::readImageSettings()
743750
depthcuefactor = 0.5;
744751
depthcuecolor = "auto";
745752
depthcuestart = "auto";
753+
usedefocus = false;
754+
defocusfactor = 0.5;
755+
defocusstart = "auto";
746756
useoutline = false;
747757
outlinewidth = 2;
748758
outlinecolor = "black";
@@ -818,6 +828,8 @@ void ImageViewer::resetView()
818828
if (button) button->setChecked(antialias);
819829
button = findChild<QPushButton *>("depthcue");
820830
if (button) button->setChecked(usedepthcue);
831+
button = findChild<QPushButton *>("defocus");
832+
if (button) button->setChecked(usedefocus);
821833
button = findChild<QPushButton *>("shiny");
822834
if (button) button->setChecked(shinyfactor > SHINY_CUT);
823835
button = findChild<QPushButton *>("vdw");
@@ -898,6 +910,15 @@ void ImageViewer::toggleDepthcue()
898910
createImage();
899911
}
900912

913+
void ImageViewer::toggleDefocus()
914+
{
915+
auto *button = qobject_cast<QPushButton *>(sender());
916+
if (!button) return;
917+
usedefocus = !usedefocus;
918+
button->setChecked(usedefocus);
919+
createImage();
920+
}
921+
901922
void ImageViewer::toggleShiny()
902923
{
903924
auto *button = qobject_cast<QPushButton *>(sender());
@@ -1495,6 +1516,9 @@ DumpImageParams ImageViewer::gatherDumpImageParams(const QString &dumpfilename)
14951516
p.depthcuefactor = depthcuefactor;
14961517
p.depthcuecolor = depthcuecolor;
14971518
p.depthcuestart = depthcuestart;
1519+
p.usedefocus = usedefocus;
1520+
p.defocusfactor = defocusfactor;
1521+
p.defocusstart = defocusstart;
14981522
p.useoutline = useoutline;
14991523
p.outlinewidth = outlinewidth;
15001524
p.outlinecolor = outlinecolor;

src/imageviewer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private slots:
8787
void toggleSsao(); ///< Toggle screen-space ambient occlusion
8888
void toggleAnti(); ///< Toggle anti-aliasing
8989
void toggleDepthcue(); ///< Toggle depth cueing
90+
void toggleDefocus(); ///< Toggle defocusing of distant objects
9091
void toggleShiny(); ///< Toggle shiny/specular rendering
9192
void toggleVdw(); ///< Toggle Van der Waals radii
9293
void toggleBond(); ///< Toggle bond display
@@ -243,6 +244,8 @@ private slots:
243244
double depthcuefactor; ///< Depth cueing strength
244245
QString depthcuecolor; ///< Depth cueing fog color or "auto"
245246
QString depthcuestart; ///< Depth cueing start fraction or "auto"
247+
double defocusfactor; ///< Defocus blur strength
248+
QString defocusstart; ///< Defocus start fraction or "auto"
246249
int outlinewidth; ///< Outline width in pixels
247250
QString outlinecolor; ///< Outline color
248251
QString specular; ///< Specular preset or "auto"
@@ -284,6 +287,7 @@ private slots:
284287
bool antialias; ///< Anti-aliasing enabled flag
285288
bool usessao; ///< SSAO enabled flag
286289
bool usedepthcue; ///< Depth cueing enabled flag
290+
bool usedefocus; ///< Defocus enabled flag
287291
bool useoutline; ///< Outline drawing enabled flag
288292
bool showatoms; ///< Show atoms
289293
bool showbonds; ///< Show bonds if atom style supports it

src/imageviewersettings.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,43 @@ void ImageViewer::globalSettings()
249249
"(0.0 = near side, 1.0 = far side), or \"auto\" to start at the\n"
250250
"nearest rendered object");
251251
layout->addWidget(cuestart, idx++, n++, 1, 1);
252-
layout->addWidget(new QHline, idx++, 0, 1, MAXCOLS);
253252
connect(cuebutton, &QCheckBox::toggled, cueval, &QDoubleSpinBox::setEnabled);
254253
connect(cuebutton, &QCheckBox::toggled, cuecolor, &QLineEdit::setEnabled);
255254
connect(cuebutton, &QCheckBox::toggled, cuestart, &QLineEdit::setEnabled);
256255

257256
n = 0;
258257

258+
auto *focusbutton = new QCheckBox("Defocus ", this);
259+
focusbutton->setChecked(usedefocus);
260+
focusbutton->setToolTip("Blur distant objects as if the camera were focused on the front");
261+
layout->addWidget(focusbutton, idx, n++, 1, 1);
262+
layout->addWidget(new QLabel("Intensity: "), idx, n++, 1, 1, Qt::AlignVCenter | Qt::AlignRight);
263+
auto *focusval = new QDoubleSpinBox;
264+
focusval->setRange(0.0, 1.0);
265+
focusval->setSingleStep(0.05);
266+
focusval->setValue(defocusfactor);
267+
focusval->setMaximumWidth(fwidth);
268+
focusval->setEnabled(usedefocus);
269+
focusval->setToolTip("Strength of the blur; at 1.0 the most distant objects are\n"
270+
"blurred over a radius of 1 percent of the image height");
271+
layout->addWidget(focusval, idx, n++, 1, 1);
272+
// the defocus keyword has no color argument, so this column stays empty
273+
n += 2;
274+
layout->addWidget(new QLabel("Start: "), idx, n++, 1, 1, Qt::AlignVCenter | Qt::AlignRight);
275+
auto *focusstart = new QLineEdit(defocusstart);
276+
focusstart->setValidator(cuestartvalidator);
277+
focusstart->setMaximumWidth(fwidth);
278+
focusstart->setEnabled(usedefocus);
279+
focusstart->setToolTip("Box fraction along the view direction where the blurring starts\n"
280+
"(0.0 = near side, 1.0 = far side), or \"auto\" to start at the\n"
281+
"nearest rendered object");
282+
layout->addWidget(focusstart, idx++, n++, 1, 1);
283+
layout->addWidget(new QHline, idx++, 0, 1, MAXCOLS);
284+
connect(focusbutton, &QCheckBox::toggled, focusval, &QDoubleSpinBox::setEnabled);
285+
connect(focusbutton, &QCheckBox::toggled, focusstart, &QLineEdit::setEnabled);
286+
287+
n = 0;
288+
259289
layout->addWidget(new QLabel("Quality:"), idx, n++, 1, 1);
260290
n++;
261291
auto *fsaa = new QCheckBox("FSAA ", this);
@@ -514,6 +544,12 @@ void ImageViewer::globalSettings()
514544
button = findChild<QPushButton *>("depthcue");
515545
if (button) button->setChecked(usedepthcue);
516546

547+
usedefocus = focusbutton->isChecked();
548+
defocusfactor = focusval->value();
549+
if (focusstart->hasAcceptableInput()) defocusstart = focusstart->text();
550+
button = findChild<QPushButton *>("defocus");
551+
if (button) button->setChecked(usedefocus);
552+
517553
useoutline = outlinebutton->isChecked();
518554
outlinewidth = olwidth->value();
519555
if (olcolor->hasAcceptableInput()) outlinecolor = olcolor->text();

0 commit comments

Comments
 (0)