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

Feature/core config #9

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions gui/js/csp-volume-rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{"min": 0.001, "25%": 0.01, "50%": 0.1, "75%": 1, "max": 10}, [0.005]);
CosmoScout.gui.initSlider("volumeRendering.setMaxRenderPasses", 1, 100, 1, [10]);
CosmoScout.gui.initSlider("volumeRendering.setDensityScale", 0, 10, 0.1, [1]);

CosmoScout.gui.initSlider("volumeRendering.setPathlineSize", 1, 20, 1, [1]);

CosmoScout.gui.initSlider("volumeRendering.setSunStrength", 0, 10, 0.1, [1]);
Expand All @@ -42,6 +43,48 @@

this._enablePathlinesParcoordsCheckbox =
document.querySelector(`[data-callback="volumeRendering.setEnablePathlinesParcoords"]`);

this._scalarDropdown = document.querySelector(`[data-callback="volumeRendering.setScalar"]`);

this._coreRadiusSlider =
document.querySelector(`[data-callback="volumeRendering.setCoreRadius"]`);
this._coreScalarDropdown =
document.getElementById("volumeRendering-coreScalarDropdown").querySelector("button");
this._coreScalarCheckbox = document.getElementById("volumeRendering-coreScalarCheckbox");
this._coreColor = document.getElementById("volumeRendering-coreColor");

this._scalarDropdown.addEventListener("change", (e) => {
if (this._coreScalarCheckbox.checked) {
CosmoScout.gui.setDropdownValue("volumeRendering.setCoreScalar", e.target.value, true);
}
});

this._coreScalarCheckbox.addEventListener("change", (e) => {
this._coreScalarDropdown.disabled = e.target.checked;
if (e.target.checked) {
this._coreScalarDropdown.classList.add("unresponsive");
CosmoScout.gui.setDropdownValue(
"volumeRendering.setCoreScalar", this._scalarDropdown.value, true);
} else {
this._coreScalarDropdown.classList.remove("unresponsive");
}
});

this._coreColorHasHandler = false;
}

setCoreColor(r, g, b) {
this._coreColor.picker.value(r, g, b, 1);
if (!this._coreColorHasHandler) {
this._coreColor.picker.on("change", (r, g, b, a) => {
CosmoScout.callbacks.volumeRendering.setCoreColor(r, g, b);
});
this._coreColorHasHandler = true;
}
}

setMaxCoreRadius(radius) {
CosmoScout.gui.initSlider("volumeRendering.setCoreRadius", 1, radius, 1, [radius / 2]);
}

enableSettingsSection(section, enable = true) {
Expand Down
60 changes: 60 additions & 0 deletions gui/volume_rendering_tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,66 @@
</div>
</div>

<div class="settings-section" hidden>
<div class="section-header collapsed font-alegreya" id="headingVolume-core"
data-toggle="collapse" data-target="#collapseVolume-core" aria-expanded="false"
aria-controls="collapseVolume-core" type="button">
<i class="material-icons">adjust</i>
<span>Core</span>
<i class="material-icons caret-icon">keyboard_arrow_left</i>
</div>
<div class="section-body collapse container-fluid" id="collapseVolume-core"
aria-labelledby="headingVolume-core" data-parent="#volumeRenderingTab-accordion">
<div class="row">
<div class="col-7 offset-5">
<label class="checklabel">
<input type="checkbox" data-callback="volumeRendering.setEnableCore" />
<i class="material-icons"></i>
<span>Render core</span>
</label>
</div>
</div>

<div class="row">
<div class="col-5">
Core radius
</div>
<div class="col-7">
<div data-callback="volumeRendering.setCoreRadius">
</div>
</div>
</div>

<div class="row">
<div class="col-7 offset-5">
<label class="checklabel">
<input id="volumeRendering-coreScalarCheckbox" data-callback="volumeRendering.setEnableDependentCoreScalar" type="checkbox" />
<i class="material-icons"></i>
<span>Use same scalar as volume</span>
</label>
</div>
</div>

<div class="row">
<div class="col-5">
Scalar
</div>
<div id="volumeRendering-coreScalarDropdown" class="col-7">
<select data-callback="volumeRendering.setCoreScalar" class="simple-value-dropdown"></select>
</div>
</div>

<div class="row">
<div class="col-5">
Color
</div>
<div class="col-7">
<input type="text" class="form-control color-input" id="volumeRendering-coreColor" style="color: black;" value="">
</div>
</div>
</div>
</div>

<div class="settings-section" hidden>
<div class="section-header collapsed font-alegreya" id="headingVolume-pathlines"
data-toggle="collapse" data-target="#collapseVolume-pathlines" aria-expanded="false"
Expand Down
63 changes: 57 additions & 6 deletions src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ void Plugin::registerAllUICallbacks() {
}
}));

// Core settings
if (mPluginSettings.mCore.has_value()) {
mGuiManager->getGui()->registerCallback("volumeRendering.setCoreColor",
"Sets color for core when no scalar is selected.",
std::function([this](double r, double g, double b) {
invalidateCache();
glm::vec3 color = glm::vec3(r / 255.f, g / 255.f, b / 255.f);
mPluginSettings.mCore->mColor = color;
}));
}

// Pathline settings
if (mPluginSettings.mPathlines.has_value()) {
mGuiManager->getGui()->registerCallback("volumeRendering.setPathlinesScalarFilters",
Expand Down Expand Up @@ -363,13 +374,32 @@ void Plugin::connectAllSettings() {
mGuiManager->addScriptToGui(code);
});

// Core settings
if (mPluginSettings.mCore.has_value()) {
mPluginSettings.mCore->mColor.connectAndTouch([this](glm::vec3 value) {
mRenderer->setCoreColor(value);
mGuiManager->getGui()->callJavascript("CosmoScout.volumeRendering.setCoreColor",
value.r * 255.f, value.g * 255.f, value.b * 255.f);
});
}

// Connect to data manager properties
mDataManager->pScalars.connectAndTouch([this](std::vector<Scalar> scalars) {
mGuiManager->getGui()->callJavascript(
"CosmoScout.gui.clearDropdown", "volumeRendering.setScalar");
mGuiManager->getGui()->callJavascript(
"CosmoScout.gui.clearDropdown", "volumeRendering.setCoreScalar");
mGuiManager->getGui()->callJavascript(
"CosmoScout.gui.addDropdownValue", "volumeRendering.setCoreScalar", "none", "None", true);
for (Scalar scalar : scalars) {
mGuiManager->getGui()->callJavascript("CosmoScout.gui.addDropdownValue",
"volumeRendering.setScalar", scalar.getId(), scalar.mName, false);
bool correctCoreScalar = false;
if (mPluginSettings.mCore.has_value()) {
correctCoreScalar = (scalar.getId() == mPluginSettings.mCore->mScalar.get());
}
mGuiManager->getGui()->callJavascript("CosmoScout.gui.addDropdownValue",
"volumeRendering.setCoreScalar", scalar.getId(), scalar.mName, correctCoreScalar);
}
if (scalars.size() > 0) {
auto activeScalar = std::find_if(scalars.begin(), scalars.end(),
Expand Down Expand Up @@ -432,6 +462,8 @@ Plugin::Setting<bool>::getSettings(Settings& pluginSettings) {
? Setting<bool>{"setEnableCore", "Enable/disable rendering of core",
pluginSettings.mCore->mEnabled, &Renderer::setCoreEnabled}
: Setting<bool>{},
pluginSettings.mCore.has_value() ? Setting<bool>{"setEnableDependentCoreScalar", ""}
: Setting<bool>{},
// Pathline settings
pluginSettings.mPathlines.has_value()
? Setting<bool>{"setEnablePathlines", "Enable/disable rendering of pathlines.",
Expand Down Expand Up @@ -483,7 +515,7 @@ Plugin::Setting<float>::getSettings(Settings& pluginSettings) {
// Core settings
pluginSettings.mCore.has_value()
? Setting<float>{"setCoreRadius", "Sets the radius of the rendered core.",
pluginSettings.mCore->mRadius, &Renderer::setCoreRadius}
pluginSettings.mCore->mRadius, {}, &Plugin::setCoreRadius}
: Setting<float>{},
// Pathline settings
pluginSettings.mPathlines.has_value()
Expand Down Expand Up @@ -553,6 +585,14 @@ void Plugin::initUI() {
"CosmoScout.volumeRendering.initParcoords(`" + mDataManager->getCsvData() + "`, `" +
(mPluginSettings.mPathlines ? mDataManager->getPathlines().getCsvData() : "") + "`);");

mGuiManager->getGui()->callJavascript("CosmoScout.volumeRendering.setMaxCoreRadius",
mAllSettings->getAnchorRadii(mPluginSettings.mTransform.mAnchor.get())[0] / 1000. *
mPluginSettings.mTransform.mScale.get());

if (mPluginSettings.mCore.has_value()) {
mGuiManager->getGui()->callJavascript(
"CosmoScout.volumeRendering.enableSettingsSection", "core");
}
if (mPluginSettings.mPathlines.has_value()) {
mGuiManager->getGui()->callJavascript(
"CosmoScout.volumeRendering.enableSettingsSection", "pathlines");
Expand All @@ -561,7 +601,7 @@ void Plugin::initUI() {

////////////////////////////////////////////////////////////////////////////////////////////////////

void csp::volumerendering::Plugin::setResolution(int value) {
void Plugin::setResolution(int value) {
mNextFrame.mResolution = value;
}

Expand All @@ -573,23 +613,23 @@ void Plugin::setUseMaxDepth(bool value) {

////////////////////////////////////////////////////////////////////////////////////////////////////

void csp::volumerendering::Plugin::setDepthData(bool value) {
void Plugin::setDepthData(bool value) {
for (auto const& node : mDisplayNodes) {
node.second->setUseDepth(value);
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void csp::volumerendering::Plugin::setDrawDepth(bool value) {
void Plugin::setDrawDepth(bool value) {
for (auto const& node : mDisplayNodes) {
node.second->setDrawDepth(value);
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void csp::volumerendering::Plugin::setScalar(std::string const& value) {
void Plugin::setScalar(std::string const& value) {
invalidateCache();
if (mDataManager->isReady()) {
mDataManager->setActiveScalar(value);
Expand All @@ -600,7 +640,7 @@ void csp::volumerendering::Plugin::setScalar(std::string const& value) {

////////////////////////////////////////////////////////////////////////////////////////////////////

void csp::volumerendering::Plugin::setDisplayMode(DisplayMode value) {
void Plugin::setDisplayMode(DisplayMode value) {
for (auto const& node : mDisplayNodes) {
if (node.first == value) {
node.second->setEnabled(true);
Expand All @@ -620,6 +660,17 @@ void csp::volumerendering::Plugin::setDisplayMode(DisplayMode value) {

////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin::setCoreRadius(float value) {
invalidateCache();
// Normalize core radius for renderer
mRenderer->setCoreRadius(
value /
static_cast<float>(mAllSettings->getAnchorRadii(mPluginSettings.mTransform.mAnchor.get())[0] /
1000. * mPluginSettings.mTransform.mScale.get()));
}

////////////////////////////////////////////////////////////////////////////////////////////////////

bool Plugin::tryRequestFrame() {
if (mActiveDisplay->pVisible.get()) {
cs::utils::FrameTimings::ScopedTimer timer("Request frame");
Expand Down
3 changes: 2 additions & 1 deletion src/Plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct get_ui_type<float> {
template <typename T>
constexpr int SETTINGS_COUNT = 0;
template <>
inline constexpr int SETTINGS_COUNT<bool> = 12;
inline constexpr int SETTINGS_COUNT<bool> = 13;
template <>
inline constexpr int SETTINGS_COUNT<int> = 2;
template <>
Expand Down Expand Up @@ -260,6 +260,7 @@ class Plugin : public cs::core::PluginBase {
void setDrawDepth(bool value);
void setScalar(std::string const& value);
void setDisplayMode(DisplayMode value);
void setCoreRadius(float value);

bool tryRequestFrame();

Expand Down
5 changes: 3 additions & 2 deletions src/Render/OSPRayRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,14 @@ void OSPRayRenderer::updateWorld(
mCache.mCoreMaterial.setParam("map_kd", mCache.mCoreTexture);
mCache.mCoreMaterial.commit();
} else {
rkcommon::math::vec3f color = {0.8f, 0.8f, 0.8f};
rkcommon::math::vec3f color = {parameters.mWorld.mCore.mColor.r,
parameters.mWorld.mCore.mColor.g, parameters.mWorld.mCore.mColor.b};
mCache.mCoreMaterial.removeParam("map_kd");
mCache.mCoreMaterial.setParam("kd", color);
mCache.mCoreMaterial.commit();
}

mCache.mCore.setParam("radius", parameters.mWorld.mCore.mRadius);
mCache.mCore.setParam("radius", parameters.mWorld.mCore.mRadius * volume.mHeight);
mCache.mCore.commit();
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/Render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ void Renderer::setCoreRadius(float value) {

////////////////////////////////////////////////////////////////////////////////////////////////////

void Renderer::setCoreColor(glm::vec3 value) {
std::scoped_lock lock(mParameterMutex);
mParameters.mWorld.mCore.mColor = value;
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void Renderer::setPathlinesEnabled(bool enable) {
std::scoped_lock lock(mParameterMutex);
mParameters.mWorld.mPathlines.mEnable = enable;
Expand Down
5 changes: 4 additions & 1 deletion src/Render/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Renderer {
void setCoreEnabled(bool value);
void setCoreScalar(std::string value);
void setCoreRadius(float value);
void setCoreColor(glm::vec3 value);

void setPathlinesEnabled(bool enable);
void setPathlineSize(float value);
Expand Down Expand Up @@ -196,9 +197,11 @@ class Renderer {
bool mEnable = false;
std::string mScalar;
float mRadius = 0.0f;
glm::vec3 mColor;

bool operator==(const Core& other) const {
return mEnable == other.mEnable && mScalar == other.mScalar && mRadius == other.mRadius;
return mEnable == other.mEnable && mScalar == other.mScalar && mRadius == other.mRadius &&
mColor == other.mColor;
}
} mCore;

Expand Down
2 changes: 2 additions & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,14 @@ void from_json(nlohmann::json const& j, Settings::Core& o) {
cs::core::Settings::deserialize(j, "enabled", o.mEnabled);
cs::core::Settings::deserialize(j, "scalar", o.mScalar);
cs::core::Settings::deserialize(j, "radius", o.mRadius);
cs::core::Settings::deserialize(j, "color", o.mColor);
}

void to_json(nlohmann::json& j, Settings::Core const& o) {
cs::core::Settings::serialize(j, "enabled", o.mEnabled);
cs::core::Settings::serialize(j, "scalar", o.mScalar);
cs::core::Settings::serialize(j, "radius", o.mRadius);
cs::core::Settings::serialize(j, "color", o.mColor);
}

void from_json(nlohmann::json const& j, Settings::Pathlines& o) {
Expand Down
1 change: 1 addition & 0 deletions src/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct Settings {
cs::utils::DefaultProperty<bool> mEnabled{true};
cs::utils::DefaultProperty<std::string> mScalar{""};
cs::utils::Property<float> mRadius;
cs::utils::DefaultProperty<glm::vec3> mColor{glm::vec3(0.8f)};

// Needed for deserialization.
Core(){};
Expand Down