Gerneric image codec abstraction init (#6)
* remove raw pointer from resource manager
* towards generic images
* 💅 and pin libCZI module
* remove raw pointer from resource manager
* towards generic images
* fix rendering
* fix rendering
* fix unit tests
* fix pipeline
* fix gcc build
* re-enable tests
* add czi impl
* remove resource button
* refactor user code app to being a "default app"
* ui resources
* missing lib?
* init czi render support
* typos
This commit is contained in:
committed by
Maximilian Kueffner
parent
bce12b0bb4
commit
0be064bb8e
@@ -4,6 +4,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/app_resources_default.h.in
|
||||
|
||||
set(APPLIBSRC
|
||||
AppGLFW.cpp
|
||||
DefaultApp.cpp
|
||||
${imgui_DIR}/imgui.cpp
|
||||
${imgui_DIR}/imgui_demo.cpp
|
||||
${imgui_DIR}/imgui_draw.cpp
|
||||
@@ -18,7 +19,9 @@ add_library(${APPLIBNAME}
|
||||
STATIC ${APPLIBSRC})
|
||||
|
||||
target_link_libraries(${APPLIBNAME}
|
||||
PRIVATE pixelariumutilslib)
|
||||
PRIVATE pixelariumutilslib
|
||||
PRIVATE pixelariumimagelib
|
||||
PRIVATE pixelariumrenderlib)
|
||||
|
||||
# This needs to be public to let the consumer know about it.
|
||||
if(WIN32)
|
||||
@@ -40,5 +43,7 @@ endif()
|
||||
target_include_directories(${APPLIBNAME}
|
||||
PRIVATE ${CMAKE_BINARY_DIR}
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/lib
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/lib/imaging
|
||||
PUBLIC ${pfd_DIR}
|
||||
PUBLIC ${imgui_DIR}
|
||||
PUBLIC ${imgui_DIR}/backends)
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
#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, 500));
|
||||
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()
|
||||
{
|
||||
size_t last_id{};
|
||||
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));
|
||||
}
|
||||
catch (pixelarium::resources::empty_resource_exception& e)
|
||||
{
|
||||
logger_.Error(std::format("{}: Failed to load file '{}' with '{}'", __PRETTY_FUNCTION__, p, e.what()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
#include "AppGLFW.hpp"
|
||||
#include "imgui.h"
|
||||
#include "rendering/RenderImageManager.hpp"
|
||||
#include "resources/resource.hpp"
|
||||
#include "utilities/ILog.hpp"
|
||||
|
||||
namespace pixelarium::ui
|
||||
{
|
||||
class DefaultApp : public application::AppGLFW
|
||||
{
|
||||
public:
|
||||
DefaultApp(const utils::log::ILog& log, pixelarium::resources::ImageResourcePool& pool)
|
||||
: application::AppGLFW(log),
|
||||
pool_(pool),
|
||||
render_manager_(std::make_unique<render::RenderImageManager>(pool, log))
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void MenuBarOptionsColumn1() override;
|
||||
void MenuBarOptionsColumn2() override;
|
||||
void Run() override;
|
||||
|
||||
private:
|
||||
void LoadImage();
|
||||
void ImageGalleryRender();
|
||||
void RenderImages();
|
||||
|
||||
private:
|
||||
resources::ImageResourcePool& pool_;
|
||||
std::unique_ptr<render::RenderImageManager> render_manager_;
|
||||
bool image_listp_{true};
|
||||
bool auto_show_selectd_image_{true};
|
||||
bool demop_{false};
|
||||
ImVec2 curr_dim_;
|
||||
size_t selected_image_{0};
|
||||
};
|
||||
} // namespace pixelarium::ui
|
||||
@@ -5,9 +5,17 @@
|
||||
|
||||
#cmakedefine PIXELARIUM_TITLE "@PIXELARIUM_TITLE@"
|
||||
|
||||
#define MAINMENUNAME "Menu"
|
||||
#define FILEMENUNAME "File"
|
||||
#define LOGLEVELSELECT "Log Level"
|
||||
|
||||
// clang-format off
|
||||
#define MAINMENUNAME "Menu"
|
||||
#define FILEMENUNAME "File"
|
||||
#define LOGLEVELSELECT "Log Level"
|
||||
#define SHOWIMGUIDEMOS "ImGui Demos"
|
||||
#define SHOWIMAGEGALLERY "Image Gallery"
|
||||
#define AUTOSHOWSELECTED "Auto View"
|
||||
#define OPENIMAGE "Open"
|
||||
#define LOADIMAGE "Load Image"
|
||||
#define REMOVEIMAGE "Remove Image"
|
||||
#define CLEARALL "Clear All"
|
||||
// clang-format on
|
||||
|
||||
inline constexpr std::array<std::string_view, 5> LOGLEVELS = {"Trace", "Debug", "Info", "Warning", "Error"};
|
||||
|
||||
Reference in New Issue
Block a user