Skip to content

Commit

Permalink
Almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
Atraxus committed Feb 17, 2025
1 parent cb40102 commit b155290
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 62 deletions.
4 changes: 2 additions & 2 deletions Intern/rayx-core/src/Beamline/Beamline.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class RAYX_API Group : public BeamlineNode {
std::vector<glm::dvec4>& positions);

// Getters & setters for transforms.
const glm::dvec4& getPosition() const { return m_position; }
const glm::dmat4& getOrientation() const { return m_orientation; }
glm::dvec4 getPosition() const override { return m_position; }
glm::dmat4 getOrientation() const override { return m_orientation; }
void setPosition(const glm::dvec4& pos) { m_position = pos; }
void setOrientation(const glm::dmat4& orientation) { m_orientation = orientation; }

Expand Down
20 changes: 20 additions & 0 deletions Intern/rayx-core/src/Beamline/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <memory>

#include <glm.hpp>

#include "Core.h"

namespace RAYX {
Expand All @@ -14,6 +16,24 @@ class RAYX_API BeamlineNode {
virtual bool isElement() const { return false; }
virtual bool isSource() const { return false; }

virtual glm::dvec4 getPosition() const = 0;
virtual glm::dmat4 getOrientation() const = 0;

glm::dvec4 getWorldPosition() const {
glm::dvec4 localPos = getPosition();
if (!parent) return localPos;

glm::dmat4 parentOri = parent->getWorldOrientation();
glm::dvec4 parentPos = parent->getWorldPosition();
glm::dvec4 worldPos = parentOri * localPos + parentPos;
return worldPos;
}

glm::dmat4 getWorldOrientation() const {
const glm::dmat4& ori = getOrientation();
return parent ? parent->getWorldOrientation() * ori : ori;
}

private:
BeamlineNode* parent;
};
Expand Down
10 changes: 2 additions & 8 deletions Intern/rayx-core/src/Design/DesignElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@ struct RAYX_API DesignElement : public BeamlineNode {
ElementType getType() const;

void setPosition(glm::dvec4 p);
glm::dvec4 getPosition() const;

void setWorldPosition(glm::dvec4 p);
glm::dvec4 getWorldPosition() const;
glm::dvec4 getPosition() const override;

void setOrientation(glm::dmat4x4 o);
glm::dmat4x4 getOrientation() const;

void setWorldOrientation(glm::dmat4x4 o);
glm::dmat4x4 getWorldOrientation() const;
glm::dmat4x4 getOrientation() const override;

void setMisalignment(Misalignment m);
Misalignment getMisalignment() const;
Expand Down
2 changes: 1 addition & 1 deletion Intern/rayx-core/src/Design/DesignSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct RAYX_API DesignSource : public BeamlineNode {
double getNumberOfRays() const;

void setPosition(glm::dvec4 p);
glm::dvec4 getPosition() const;
glm::dvec4 getPosition() const override;

void setOrientation(glm::dmat4x4 o);
glm::dmat4x4 getOrientation() const;
Expand Down
12 changes: 1 addition & 11 deletions Intern/rayx-ui/src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ void Application::run() {

if (m_UIParams.rmlReady) {
m_RMLPath = m_UIParams.rmlPath.string();
m_UIParams.beamlineInfo = {};
beamlineFuture = std::async(std::launch::async, &Application::loadBeamline, this, m_RMLPath);
m_State = State::LoadingBeamline;
m_UIParams.rmlReady = false;
Expand All @@ -153,17 +154,6 @@ void Application::run() {
// Update elements and sources for UI
m_UIParams.beamlineInfo.beamline = m_Beamline.get();

// TODO: Set default selection in UI based on available sources or elements
// if (m_UIParams.beamlineInfo.sources.size() > 0) {
// m_UIParams.beamlineInfo.selectedType = SelectedType::LightSource;
// m_UIParams.beamlineInfo.selectedIndex = 0;
// } else if (m_UIParams.beamlineInfo.elements.size() > 0) {
// m_UIParams.beamlineInfo.selectedType = SelectedType::OpticalElement;
// m_UIParams.beamlineInfo.selectedIndex = 0;
// } else {
// m_UIParams.beamlineInfo.selectedType = SelectedType::None;
// }

// Prepare for ray loading or element preparation
size_t numElements = m_Beamline->numElements();
m_sortedRays.resize(numElements);
Expand Down
2 changes: 1 addition & 1 deletion Intern/rayx-ui/src/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void Simulator::setSimulationParameters(const std::filesystem::path& RMLPath, co
}

m_RMLPath = RMLPath;
m_Beamline = beamline.clone();
m_Beamline = std::move(*static_cast<RAYX::Beamline*>(beamline.clone().get()));
m_max_batch_size = simulationInfo.maxBatchSize;
m_seq = simulationInfo.sequential ? RAYX::Sequential::Yes : RAYX::Sequential::No;
m_maxEvents = simulationInfo.maxEvents;
Expand Down
16 changes: 8 additions & 8 deletions Intern/rayx-ui/src/UserInterface/BeamlineDesignHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ void BeamlineDesignHandler::showBeamlineDesignWindow(UIBeamlineInfo& uiInfo) {
return;
}

// The node is a std::variant<...>, so figure out which alternative we have
const auto& node = *uiInfo.selectedNode;

if (std::holds_alternative<std::unique_ptr<RAYX::DesignSource>>(node)) {
const auto& srcPtr = std::get<std::unique_ptr<RAYX::DesignSource>>(node);
if (uiInfo.selectedNode->isSource()) {
const auto srcPtr = dynamic_cast<RAYX::DesignSource*>(uiInfo.selectedNode);
if (srcPtr) {
// showParameters can now edit srcPtr->m_elementParameters
showParameters(srcPtr->m_elementParameters, uiInfo.elementsChanged, SelectedType::LightSource);
}
} else if (std::holds_alternative<std::unique_ptr<RAYX::DesignElement>>(node)) {
const auto& elemPtr = std::get<std::unique_ptr<RAYX::DesignElement>>(node);
} else if (uiInfo.selectedNode->isElement()) {
const auto elemPtr = dynamic_cast<RAYX::DesignElement*>(uiInfo.selectedNode);
if (elemPtr) {
showParameters(elemPtr->m_elementParameters, uiInfo.elementsChanged, SelectedType::OpticalElement);
}
} else if (std::holds_alternative<std::unique_ptr<RAYX::Group>>(node)) {
} else if (uiInfo.selectedNode->isGroup()) {
ImGui::Text("Group editing is to be implemented still...");
} else {
throw std::runtime_error("Tree element of unknown type encountered!");
}
}

Expand Down
50 changes: 22 additions & 28 deletions Intern/rayx-ui/src/UserInterface/BeamlineOutliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,60 @@ BeamlineOutliner::BeamlineOutliner() {}
BeamlineOutliner::~BeamlineOutliner() {}

// Recursive helper: render a Group and its children as an ImGui tree.
void BeamlineOutliner::renderImGuiTreeFromGroup(RAYX::Group* group, RAYX::BeamlineNode*& selected, int depth) {
void BeamlineOutliner::renderImGuiTreeFromGroup(RAYX::Group* group, RAYX::BeamlineNode*& selected, CameraController& cam, int depth) {
if (!group) return;
int ctr = 0;
for (auto& child : *group) {
RAYX::NodeType nodeType = child->data.getNodeType();
std::string label;

// Use the node's name if possible.
switch (nodeType) {
case RAYX::NodeType::OpticalElement:
label = std::get<std::unique_ptr<RAYX::DesignElement>>(child)->getName();
break;
case RAYX::NodeType::LightSource:
label = std::get<std::unique_ptr<RAYX::DesignSource>>(child)->getName();
break;
case RAYX::NodeType::Group:
label = "Group";
break;
if (child->isElement()) {
label = static_cast<RAYX::DesignElement*>(child.get())->getName();
} else if (child->isSource()) {
label = static_cast<RAYX::DesignSource*>(child.get())->getName();
} else if (child->isGroup()) {
label = "Group";
}

// Create a unique label ID for ImGui (so nodes with the same name are distinguished).
// ? Why is this needed?
// TODO: Either enforce unique names in DesignEl/Src or display the correct name in UI
std::stringstream ss;
ss << label << "##" << depth << "_" << ctr++;
std::string uniqueLabel = ss.str();
std::string buttonLabel = "<-##" + std::to_string(ctr++);
if (ImGui::Button(buttonLabel.c_str())) {
const glm::dvec4& pos = child->getWorldPosition();
cam.lookAtPoint({pos.x, pos.y, pos.z});
}

// Set tree node flags: if the node is a leaf (not a group), mark it as such.
ImGui::SameLine();
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
bool isLeaf = (nodeType != RAYX::NodeType::Group);
if (isLeaf) {
if (!child->isGroup()) {
flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen;
}
bool nodeOpen = ImGui::TreeNodeEx(uniqueLabel.c_str(), flags, "%s", label.c_str());
bool nodeOpen = ImGui::TreeNodeEx(label.c_str(), flags, "%s", label.c_str());

// If the user clicks the node, you can update selection info here.
if (ImGui::IsItemClicked()) {
selected = &child;
selected = child.get();
}

// If this node is a Group and is open, recursively render its children.
if (nodeOpen && !isLeaf) {
if (nodeOpen && child->isGroup()) {
// Get the group pointer from the variant.
const auto& childGroupPtr = std::get<std::unique_ptr<RAYX::Group>>(child);
auto* childGroupPtr = dynamic_cast<RAYX::Group*>(child.get());
// Dereference it to call the function.
renderImGuiTreeFromGroup(childGroupPtr.get(), selected, depth + 1);
renderImGuiTreeFromGroup(childGroupPtr, selected, cam, depth + 1);
ImGui::TreePop();
}
}
}

// This function displays the beamline outline window using the existing data structure.
void BeamlineOutliner::showBeamlineOutlineWindow(UIBeamlineInfo& blInfo) {
void BeamlineOutliner::showBeamlineOutlineWindow(UIParameters& uiParams) {
ImGui::Begin("Beamline Outline");

UIBeamlineInfo& blInfo = uiParams.beamlineInfo;
if (blInfo.beamline == nullptr) {
ImGui::Text("Beamline not loaded.");
} else {
// Render the tree starting from the beamline root.
renderImGuiTreeFromGroup(blInfo.beamline, blInfo.selectedNode, 0);
renderImGuiTreeFromGroup(blInfo.beamline, blInfo.selectedNode, uiParams.camController, 0);
}

ImGui::End();
Expand Down
4 changes: 2 additions & 2 deletions Intern/rayx-ui/src/UserInterface/BeamlineOutliner.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class BeamlineOutliner {
~BeamlineOutliner();

// Show the outline window (to be called every frame in your UI loop)
void showBeamlineOutlineWindow(UIBeamlineInfo& blInfo);
void showBeamlineOutlineWindow(UIParameters& uiParams);

private:
// Recursive helper that renders the tree starting at a given Group.
void renderImGuiTreeFromGroup(RAYX::Group* group, RAYX::BeamlineNode*& selected, int depth = 0);
void renderImGuiTreeFromGroup(RAYX::Group* group, RAYX::BeamlineNode*& selected, CameraController& cam, int depth = 0);
};
2 changes: 1 addition & 1 deletion Intern/rayx-ui/src/UserInterface/UIHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void UIHandler::setupUI(UIParameters& uiParams) {
showUISettingsWindow(uiParams);
showMissingFilePopupWindow(uiParams);
showSimulationSettingsPopupWindow(uiParams);
m_BeamlineOutliner.showBeamlineOutlineWindow(uiParams.beamlineInfo);
m_BeamlineOutliner.showBeamlineOutlineWindow(uiParams);
showHotkeysWindow();
ImGui::End();
ImGui::End();
Expand Down

0 comments on commit b155290

Please sign in to comment.