Quick fix broken volume clip planes

This commit is contained in:
Andreas Engberg
2025-05-06 11:29:00 +02:00
parent 64953cc6fd
commit e4c365af57
6 changed files with 54 additions and 26 deletions

View File

@@ -158,8 +158,7 @@ namespace {
// [[codegen::verbatim(GridTypeInfo.description)]]
std::optional<std::string> gridType [[codegen::inlist("Spherical", "Cartesian")]];
// @TODO Missing documentation
std::optional<ghoul::Dictionary> clipPlanes;
std::optional<std::vector<ghoul::Dictionary>> clipPlanes [[codegen::reference("volume_volumeclipplane")]];
};
#include "renderabletimevaryingvolume_codegen.cpp"
} // namespace
@@ -209,10 +208,8 @@ RenderableTimeVaryingVolume::RenderableTimeVaryingVolume(
_secondsBefore = p.secondsBefore.value_or(_secondsBefore);
_secondsAfter = p.secondsAfter;
const ghoul::Dictionary clipPlanesDict = p.clipPlanes.value_or(ghoul::Dictionary());
_clipPlanes = std::make_shared<volume::VolumeClipPlanes>(clipPlanesDict);
_clipPlanes->setIdentifier("clipPlanes");
_clipPlanes->setGuiName("Clip Planes");
const std::vector<ghoul::Dictionary> clipPlanes = p.clipPlanes.value_or(std::vector<ghoul::Dictionary>());
_clipPlanes = std::make_shared<volume::VolumeClipPlanes>(clipPlanes);
if (p.gridType.has_value()) {
const VolumeGridType gridType = volume::parseGridType(*p.gridType);

View File

@@ -54,8 +54,12 @@ namespace {
namespace openspace::volume {
documentation::Documentation VolumeClipPlane::Documentation() {
return codegen::doc<Parameters>("volume_volumeclipplane");
}
VolumeClipPlane::VolumeClipPlane(const ghoul::Dictionary& dictionary)
: properties::PropertyOwner({ "" }) // @TODO Missing name
: properties::PropertyOwner({ "" }) // Name set from parent
, _normal(
NormalInfo,
glm::vec3(1.f, 0.f, 0.f),

View File

@@ -32,6 +32,8 @@
namespace ghoul { class Dictionary; }
namespace openspace::documentation { struct Documentation; }
namespace openspace::volume {
class VolumeClipPlane : public properties::PropertyOwner {
@@ -42,6 +44,8 @@ public:
glm::vec3 normal() const;
glm::vec2 offsets() const;
static documentation::Documentation Documentation();
private:
properties::Vec3Property _normal;
properties::Vec2Property _offsets;

View File

@@ -25,36 +25,56 @@
#include <modules/volume/rendering/volumeclipplanes.h>
#include <openspace/documentation/documentation.h>
#include <ghoul/misc/dictionary.h>
namespace {
//constexpr openspace::properties::PropertyOwner::PropertyOwnerInfo ClipPlanesInfo = {
//"ClipPlanes",
//"Clip Planes",
//"Documentation"
//};
constexpr openspace::properties::Property::PropertyInfo NClipPlanesInfo = {
"nClipPlanes",
"# Clip Planes",
"Number of clip planes"
};
} // namespace
namespace openspace::volume {
VolumeClipPlanes::VolumeClipPlanes(const ghoul::Dictionary& dictionary)
: properties::PropertyOwner({ "" }) // @TODO Missing name
VolumeClipPlanes::VolumeClipPlanes(const std::vector<ghoul::Dictionary>& planes)
: properties::PropertyOwner({ "ClipPlanes", "Clip Planes" }) // @TODO Missing name
// @TODO Missing documentation
, _nClipPlanes({ "nClipPlanes", "Number of clip planes", "" }, 0, 0, 10)
, _nClipPlanes(NClipPlanesInfo, 0, 0, 10)
{
for (const std::string_view key : dictionary.keys()) {
const ghoul::Dictionary cutplane = dictionary.value<ghoul::Dictionary>(key);
VolumeClipPlane clipPlane = VolumeClipPlane(cutplane);
clipPlane.setIdentifier(std::string(key));
int index = 0;
for (const ghoul::Dictionary& c : planes) {
std::unique_ptr<VolumeClipPlane> clipPlane = std::make_unique<VolumeClipPlane>(c);
clipPlane->setIdentifier(std::format("clipPlane_{}", index++)); // TODO 2025-05-06 check if this is ok to do with Alex / Emma
addPropertySubOwner(clipPlane.get());
_clipPlanes.push_back(std::move(clipPlane));
}
_nClipPlanes = static_cast<int>(dictionary.keys().size());
_nClipPlanes = static_cast<int>(_clipPlanes.size());
addProperty(_nClipPlanes);
}
void VolumeClipPlanes::initialize() {
addProperty(_nClipPlanes);
for (VolumeClipPlane& clipPlane : _clipPlanes) {
addPropertySubOwner(clipPlane);
}
}
std::vector<glm::vec3> VolumeClipPlanes::normals() {
std::vector<glm::vec3> normals;
normals.reserve(_clipPlanes.size());
for (const VolumeClipPlane& clipPlane : _clipPlanes) {
normals.push_back(clipPlane.normal());
for (const std::unique_ptr<VolumeClipPlane>& clipPlane : _clipPlanes) {
normals.push_back(clipPlane->normal());
}
return normals;
}
@@ -62,8 +82,8 @@ std::vector<glm::vec3> VolumeClipPlanes::normals() {
std::vector<glm::vec2> VolumeClipPlanes::offsets() {
std::vector<glm::vec2> offsets;
offsets.reserve(_clipPlanes.size());
for (const VolumeClipPlane& clipPlane : _clipPlanes) {
offsets.push_back(clipPlane.offsets());
for (const std::unique_ptr<VolumeClipPlane>& clipPlane : _clipPlanes) {
offsets.push_back(clipPlane->offsets());
}
return offsets;
}

View File

@@ -32,6 +32,7 @@
#include <vector>
namespace ghoul { class Dictionary; }
namespace documentation { struct Documentation; }
namespace openspace::volume {
@@ -39,7 +40,7 @@ class VolumeClipPlane;
class VolumeClipPlanes : public properties::PropertyOwner {
public:
explicit VolumeClipPlanes(const ghoul::Dictionary& dictionary);
explicit VolumeClipPlanes(const std::vector<ghoul::Dictionary>& planes);
~VolumeClipPlanes() override = default;
void initialize();
@@ -49,7 +50,7 @@ public:
private:
properties::IntProperty _nClipPlanes;
std::vector<VolumeClipPlane> _clipPlanes;
std::vector<std::unique_ptr<VolumeClipPlane>> _clipPlanes;
};
} // namespace openspace::volume

View File

@@ -25,6 +25,7 @@
#include <modules/volume/volumemodule.h>
#include <modules/volume/rendering/renderabletimevaryingvolume.h>
#include <modules/volume/rendering/volumeclipplane.h>
#include <modules/volume/tasks/generaterawvolumetask.h>
#include <modules/volume/tasks/generaterawvolumefromfiletask.h>
#include <openspace/documentation/documentation.h>
@@ -57,7 +58,8 @@ void VolumeModule::internalInitialize(const ghoul::Dictionary&) {
std::vector<documentation::Documentation> VolumeModule::documentations() const {
return {
RenderableTimeVaryingVolume::Documentation(),
GenerateRawVolumeTask::Documentation()
GenerateRawVolumeTask::Documentation(),
VolumeClipPlane::Documentation()
};
}