Files
pixelarium/lib/app/DefaultApp.cpp
T
m-aXimilian 1ea83d9d11 Czi rendering (#10)
* add dimension selector sliders to czi view

* version doc & version bump

* cosmetic

* fix build?

* multi-dimension selection enabled in czi view

* remove the parameterized reset function of the renderer

it is not and is conceptually questionable

doc updates & some minor improvements

auto-update CZI-view when sliders are moved

set initial window size

fix windows build and msvc build

For reasons I don not comprehend, on Windows, we must include
=opencv2/core/mat.hpp= as the very last header in the =CvMatRender.hpp=.
If this is at any other position building on Windows, compilation will
break w/ all kinds of cryptic errors regarding OpenCV.

When building w/ msvc =__PRETTY_FUNCTION__= is not defined. =ILog.hpp=
now defines it. This should be revised to only be set when the
compiler is msvc. For the time being, it is considered sufficient though.
2026-02-16 20:36:48 +01:00

139 lines
3.9 KiB
C++

#include "DefaultApp.hpp"
#include <cstddef>
#include <format>
#include <memory>
#include "PixelariumImageFactory.hpp"
#include "app_resources_default.h"
#include "imgui.h"
#include "portable-file-dialogs.h"
#include "rendering/RenderImageManager.hpp"
#include "resources/resource.hpp"
#include "utilities/ILog.hpp"
using namespace pixelarium::imaging;
void pixelarium::ui::DefaultApp::MenuBarOptionsColumn1()
{
ImGui::MenuItem(SHOWIMGUIDEMOS, NULL, &this->demop_);
ImGui::MenuItem(SHOWIMAGEGALLERY, NULL, &this->image_listp_);
}
void pixelarium::ui::DefaultApp::MenuBarOptionsColumn2()
{
if (ImGui::BeginMenu(FILEMENUNAME))
{
if (ImGui::MenuItem(LOADIMAGE))
{
this->LoadImage();
}
ImGui::EndMenu();
}
}
void pixelarium::ui::DefaultApp::Run()
{
if (demop_) ImGui::ShowDemoWindow(&this->demop_);
if (image_listp_) this->ImageGalleryRender();
this->RenderImages();
}
void pixelarium::ui::DefaultApp::RenderImages()
{
this->render_manager_->Enumerate(
[&](resources::ResourceKey key, render::RenderImageStateWrapper& render_state)
{
render_state.view->ShowImage();
if (!*render_state.view->GetStatus())
{
this->render_manager_->MarkForDeletion(key);
}
});
}
void pixelarium::ui::DefaultApp::ImageGalleryRender()
{
ImGui::SetNextWindowSize(ImVec2(300, 550));
ImGui::Begin(SHOWIMAGEGALLERY, &this->image_listp_);
// this updates the render collection
// essentially deleting render views that were
// marked for deletion
this->render_manager_->UpdateCollection();
static size_t selected_index{0};
int highlight_index{-1};
if (ImGui::BeginListBox("Image List", ImVec2(200, 400)))
{
pool_.EnumerateResources(
[&](size_t id, size_t idx, const imaging::IPixelariumImage& img) -> void
{
const bool is_selected = selected_index == idx;
if (ImGui::Selectable(std::format("{}", img.Name()).c_str(), is_selected))
{
selected_index = idx;
this->selected_image_ = id;
}
if (highlight_index && ImGui::IsItemHovered()) highlight_index = idx;
if (is_selected) ImGui::SetItemDefaultFocus();
});
ImGui::EndListBox();
}
ImGui::Checkbox(AUTOSHOWSELECTED, &this->auto_show_selectd_image_);
ImGui::SameLine(); // put the button next to the checkbox
// note that the button will only show when the checkbox is toggled off
// this is intended behavior as the selected image will render automatically
// when the checkbox is toggled on
if (this->auto_show_selectd_image_ || ImGui::Button(OPENIMAGE))
{
// Try add the selected index to the manager
this->render_manager_->Add(this->selected_image_);
}
if (ImGui::Button(LOADIMAGE))
{
this->LoadImage();
}
if (ImGui::Button(REMOVEIMAGE))
{
this->render_manager_->MarkForDeletion(this->selected_image_);
this->pool_.DeleteResource(this->selected_image_);
}
ImGui::SameLine();
if (ImGui::Button(CLEARALL))
{
this->render_manager_->Clear();
this->pool_.Clear();
}
ImGui::End(); // end gallery window
}
void pixelarium::ui::DefaultApp::LoadImage()
{
auto res{pfd::open_file("Load Inputs", pfd::path::home(), {"All Files", "*"}, pfd::opt::multiselect).result()};
for (auto& p : res)
{
this->logger_.Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
try
{
pool_.SetResource(PixelariumImageFactory::CreateImage(p, logger_));
}
catch (pixelarium::resources::empty_resource_exception& e)
{
logger_.Error(std::format("{}: Failed to load file '{}' with '{}'", __PRETTY_FUNCTION__, p, e.what()));
}
}
}