Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

opacity binding #1972

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions doc/user/INTERACTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Other options can be toggled directly by pressing the following hotkeys:
- <kbd>J</kbd>: the display of the HDRI skybox.
- <kbd>L</kbd>: increase lights intensity.
- <kbd>Shift</kbd>+<kbd>L</kbd>: decrease lights intensity.
- <kbd>Ctrl</kbd>+<kbd>P</kbd>: increase opacity.
- <kbd>Shift</kbd>+<kbd>P</kbd>: decrease opacity.
- <kbd>Shift</kbd>+<kbd>A</kbd>: toggle armature.

Note that the raytracing hotkeys are only available if F3D is build with raytracing enabled.

Expand Down
43 changes: 43 additions & 0 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@
this->Options.render.light.intensity = std::max(newIntensityPct, 0) / 100.0;
}

//----------------------------------------------------------------------------
// Increase/Decrease opacity
void IncreaseOpacity(bool negative)
{
// current opacity, interpreted as 1 if it does not exist
const double currentOpacity = this->Options.model.color.opacity.value_or(1.0);

// new opacity, clamped between 0 and 1 if not already set outside that range
const double increment = negative ? -0.05 : 0.05;
double newOpacity = currentOpacity + increment;
if (currentOpacity <= 1.0 && 0.0 <= currentOpacity)
{
newOpacity = std::min(1.0, std::max(0.0, newOpacity));
}

this->Options.model.color.opacity = newOpacity;
}

//----------------------------------------------------------------------------
// Synchronise options from the renderer properties
static void SynchronizeScivisOptions(f3d::options& opt, vtkF3DRenderer* ren)
Expand Down Expand Up @@ -699,6 +717,12 @@
this->addCommand("decrease_light_intensity",
[&](const std::vector<std::string>&) { this->Internals->IncreaseLightIntensity(true); });

this->addCommand("increase_opacity",
[&](const std::vector<std::string>&) { this->Internals->IncreaseOpacity(false); });

this->addCommand("decrease_opacity",
[&](const std::vector<std::string>&) { this->Internals->IncreaseOpacity(true); });

Check warning on line 724 in library/src/interactor_impl.cxx

View check run for this annotation

Codecov / codecov/patch

library/src/interactor_impl.cxx#L724

Added line #L724 was not covered by tests

this->addCommand("print_scene_info", [&](const std::vector<std::string>&)
{ this->Internals->Window.PrintSceneDescription(log::VerboseLevel::INFO); });

Expand Down Expand Up @@ -938,6 +962,23 @@
valStream << val;
return std::pair(doc, valStream.str());
};

// "doc", "value/Unset"
auto docDblOpt = [](const std::string& doc, const std::optional<double>& val)
{
std::stringstream valStream;
valStream.precision(2);
valStream << std::fixed;
if (val.has_value())
{
valStream << val.value();

Check warning on line 974 in library/src/interactor_impl.cxx

View check run for this annotation

Codecov / codecov/patch

library/src/interactor_impl.cxx#L974

Added line #L974 was not covered by tests
}
else
{
valStream << "Unset";
}
return std::pair(doc, valStream.str());
};

// "doc", "ON/OFF"
auto docTgl = [](const std::string& doc, const bool& val)
Expand Down Expand Up @@ -978,6 +1019,8 @@
this->addBinding({mod_t::NONE, "J"}, "toggle render.background.skybox","Scene", std::bind(docTgl, "Toggle HDRI skybox", std::cref(opts.render.background.skybox)));
this->addBinding({mod_t::NONE, "L"}, "increase_light_intensity", "Scene", std::bind(docDbl, "Increase lights intensity", std::cref(opts.render.light.intensity)));
this->addBinding({mod_t::SHIFT, "L"}, "decrease_light_intensity", "Scene", std::bind(docDbl, "Decrease lights intensity", std::cref(opts.render.light.intensity)));
this->addBinding({mod_t::CTRL, "P"}, "increase_opacity", "Scene", std::bind(docDblOpt, "Increase opacity", std::cref(opts.model.color.opacity)));
this->addBinding({mod_t::SHIFT, "P"}, "decrease_opacity", "Scene", std::bind(docDblOpt, "Decrease opacity", std::cref(opts.model.color.opacity)));
this->addBinding({mod_t::SHIFT, "A"}, "toggle render.armature.enable","Scene", std::bind(docTgl, "Toggle armature", std::cref(opts.render.armature.enable)));
this->addBinding({mod_t::ANY, "1"}, "set_camera front", "Camera", std::bind(docStr, "Front View camera"));
this->addBinding({mod_t::ANY, "3"}, "set_camera right", "Camera", std::bind(docStr, "Right View camera"));
Expand Down
1 change: 1 addition & 0 deletions library/testing/TestSDKInteractorCallBack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int TestSDKInteractorCallBack(int argc, char* argv[])
inter.removeBinding({ mod_t::NONE, "B" });
inter.removeBinding({ mod_t::NONE, "S" });
inter.removeBinding({ mod_t::NONE, "Z" });
inter.removeBinding({ mod_t::CTRL, "P" });

// Check that an binding can be added
inter.addBinding({ mod_t::NONE, "S" }, "toggle ui.axis");
Expand Down
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetAnimationName.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetConfigFile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetScalars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions vtkext/private/module/vtkF3DRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,7 @@ void vtkF3DRenderer::SetOpacity(const std::optional<double>& opacity)
{
this->Opacity = opacity;
this->ActorsPropertiesConfigured = false;
this->CheatSheetConfigured = false;
}
}

Expand Down
Loading