build system and module refactoring + simple histogram scratch (#20)
MegaLinter / MegaLinter (push) Has been cancelled
CI Workflow / build-ubuntu (push) Has been cancelled
CI Workflow / build-windows (push) Has been cancelled
CI Workflow / generate-docs (push) Has been cancelled

* scratch adding histogram to image views

Histograms should come from some sort of histogram service. This is
currently just a POC.

* custom logger implementation w/o spdlog

* missing cmake file

* fix tests

* use operator<< over direct stream exposure

* rm print header

* add threading test + refactor towards interface libraries

omits the need for =target_include_directories= calls /everywhere/

* rm print header

* rm constexpr

* templated thread_pool

* fix doxyfile

* default enable doc building

* czi reader refactor

* rm erroneous include expression

* clang-format

* single lib include with PUBLIC visibility

* compile imgui stdlib

* clang format

* documentation update

centralize `LogLevelToString` to `ILog.hpp`

update docs and examples
This commit is contained in:
m-aXimilian
2026-02-08 12:09:02 +01:00
committed by Maximilian Kueffner
parent b37814204f
commit c00c2c71ac
60 changed files with 797 additions and 416 deletions
+3 -16
View File
@@ -5,7 +5,7 @@
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include "imgui_internal.h"
#include "utilities/simple_thread_pool.hpp"
#include "simple_thread_pool.hpp"
// see https://github.com/ocornut/imgui/issues/3518
bool PixelBeginStatusBar()
@@ -214,20 +214,7 @@ void pixelarium::application::AppGLFW::MenuBar()
// main menu
if (ImGui::BeginMenu(MAINMENUNAME))
{
if (ImGui::BeginCombo(LOGLEVELSELECT, LOGLEVELS[log_level_].data()))
{
for (int n = 0; n < static_cast<int>(LOGLEVELS.size()); n++)
{
bool is_selected = (LOGLEVELS[log_level_] == LOGLEVELS[n]);
if (ImGui::Selectable(LOGLEVELS[n].data(), is_selected))
{
log_level_ = n;
this->logger_.ChangeLevel(static_cast<utils::log::LogLevel>(1 << log_level_));
}
if (is_selected) ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
LogLevelSelect();
// consumer main menu bar entries
this->MenuBarOptionsColumn1();
@@ -279,7 +266,7 @@ void pixelarium::application::AppGLFW::LogLevelSelect()
void pixelarium::application::AppGLFW::SetStatusTimed(const std::string& status, size_t seconds)
{
SetStatus(status);
utils::simple_thread_pool::run_asynch(
utils::pixelarium_pool::enqueue(
[this, seconds]()
{
std::this_thread::sleep_for(std::chrono::seconds(seconds));
+48 -26
View File
@@ -1,45 +1,65 @@
# Fetch implot
include(implot)
message(STATUS "IMPLOT sources at ${IMPLOT_DIR}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/app_resources_default.h.in
${CMAKE_BINARY_DIR}/app_resources_default.h @ONLY)
set(IMPLOTSRC
"${IMPLOT_DIR}/implot.h"
"${IMPLOT_DIR}/implot_internal.h"
"${IMPLOT_DIR}/implot_items.cpp"
"${IMPLOT_DIR}/implot.cpp"
"${IMPLOT_DIR}/implot_demo.cpp"
)
set(IMGUISRC
"${imgui_DIR}/imgui.cpp"
"${imgui_DIR}/misc/cpp/imgui_stdlib.cpp"
"${imgui_DIR}/imgui_demo.cpp"
"${imgui_DIR}/imgui_draw.cpp"
"${imgui_DIR}/imgui_tables.cpp"
"${imgui_DIR}/imgui_widgets.cpp"
"${imgui_DIR}/backends/imgui_impl_opengl3.cpp"
"${imgui_DIR}/backends/imgui_impl_glfw.cpp")
set(APPLIBSRC
AppGLFW.hpp
include/imgui_proxy.hpp
include/AppGLFW.hpp
include/DefaultApp.hpp
include/PixelariumGallery.hpp
AppGLFW.cpp
DefaultApp.hpp
DefaultApp.cpp
PixelariumGallery.hpp
PixelariumGallery.cpp
${imgui_DIR}/imgui.cpp
${imgui_DIR}/imgui_demo.cpp
${imgui_DIR}/imgui_draw.cpp
${imgui_DIR}/imgui_tables.cpp
${imgui_DIR}/imgui_widgets.cpp
${imgui_DIR}/backends/imgui_impl_opengl3.cpp
${imgui_DIR}/backends/imgui_impl_glfw.cpp)
PixelariumGallery.cpp)
set(RENDERSRC
rendering/RenderHelpers.hpp
rendering/include/RenderHelpers.hpp
rendering/include/RenderImageManager.hpp
rendering/include/CvMatRender.hpp
rendering/include/IPixelariumImageView.hpp
rendering/include/PixelariumImageViewDefault.hpp
rendering/include/PixelariumImageViewCzi.hpp
rendering/include/ImageViewFactory.hpp
rendering/RenderHelpers.cpp
rendering/CvMatRender.hpp
rendering/CvMatRender.cpp
rendering/RenderImageManager.hpp
rendering/RenderImageManager.cpp
rendering/IPixelariumImageView.hpp
rendering/IPixelariumImageView.cpp
rendering/PixelariumImageViewDefault.hpp
rendering/RenderImageManager.cpp
rendering/PixelariumImageViewDefault.cpp
rendering/PixelariumImageViewCzi.hpp
rendering/PixelariumImageViewCzi.cpp
rendering/ImageViewFactory.hpp
rendering/ImageViewFactory.cpp)
set(APPLIBNAME pixelariumapplicationlib)
add_library(${APPLIBNAME}
STATIC ${APPLIBSRC} ${RENDERSRC})
STATIC ${APPLIBSRC} ${IMGUISRC} ${IMPLOTSRC} ${RENDERSRC})
add_library(pixelarium::lib::application_static ALIAS ${APPLIBNAME})
target_link_libraries(${APPLIBNAME}
PRIVATE pixelariumutilslib
PRIVATE pixelariumimagelib)
PUBLIC
pixelarium::lib::utilities_static
pixelarium::lib::imaging_static
pixelarium::lib::resources_static)
# This needs to be public to let the consumer know about it.
if(WIN32)
@@ -59,10 +79,12 @@ if(APPLE)
endif()
target_include_directories(${APPLIBNAME}
INTERFACE
PRIVATE ${CMAKE_BINARY_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/lib
PRIVATE ${PROJECT_SOURCE_DIR}/lib/imaging
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/rendering
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/rendering/include
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
PUBLIC ${pfd_DIR}
PUBLIC ${imgui_DIR}
PUBLIC ${imgui_DIR}/backends)
PUBLIC ${imgui_DIR}/misc/cpp
PUBLIC ${imgui_DIR}/backends
${IMPLOT_DIR})
+2 -2
View File
@@ -3,12 +3,12 @@
#include <cstddef>
#include <format>
#include "ILog.hpp"
#include "PixelariumImageFactory.hpp"
#include "app_resources_default.h"
#include "imgui.h"
#include "portable-file-dialogs.h"
#include "resources/resource.hpp"
#include "utilities/ILog.hpp"
#include "resource.hpp"
using namespace pixelarium::imaging;
using namespace pixelarium::application;
@@ -4,7 +4,8 @@
#include <format>
#include "utilities/ILog.hpp"
#include "ILog.hpp"
#include "imgui_proxy.hpp"
namespace pixelarium::application
{
@@ -13,7 +14,18 @@ namespace pixelarium::application
class AppGLFW
{
public:
explicit AppGLFW(const utils::log::ILog& log) : logger_(log) { this->InitMainWindow(); }
explicit AppGLFW(const utils::log::ILog& log) : logger_(log), plot_context_(ImPlot::CreateContext())
{
this->InitMainWindow();
}
~AppGLFW() { ImPlot::DestroyContext(plot_context_); }
AppGLFW(AppGLFW&) = delete;
AppGLFW(const AppGLFW&) = delete;
AppGLFW(AppGLFW&&) = delete;
AppGLFW& operator=(AppGLFW&) = delete;
AppGLFW& operator=(AppGLFW&&) = delete;
/// @brief Start the main render loop
void Start() { this->RunLoop(); }
@@ -61,6 +73,7 @@ class AppGLFW
void LogLevelSelect();
int log_level_{0};
GLFWwindow* window = nullptr;
ImPlotContext* plot_context_ = nullptr;
bool show_status_{false};
std::string status_message_{};
};
@@ -3,10 +3,10 @@
#include <cstddef>
#include "AppGLFW.hpp"
#include "app/PixelariumGallery.hpp"
#include "imgui.h"
#include "resources/resource.hpp"
#include "utilities/ILog.hpp"
#include "ILog.hpp"
#include "PixelariumGallery.hpp"
#include "imgui_proxy.hpp"
#include "resource.hpp"
namespace pixelarium::application
{
@@ -1,8 +1,8 @@
#pragma once
#include "rendering/RenderImageManager.hpp"
#include "resources/resource.hpp"
#include "utilities/ILog.hpp"
#include "ILog.hpp"
#include "RenderImageManager.hpp"
#include "resource.hpp"
namespace pixelarium::application
{
+5
View File
@@ -0,0 +1,5 @@
#pragma once
#include "imgui.h"
#include "imgui_stdlib.h"
#include "implot.h"
+1 -1
View File
@@ -3,7 +3,7 @@
#include <opencv2/core/mat.hpp>
#include <opencv2/imgproc.hpp>
#include "imaging/IPixelariumImage.hpp"
#include "IPixelariumImage.hpp"
using namespace pixelarium::imaging;
+15 -7
View File
@@ -3,22 +3,30 @@
#include <opencv2/imgcodecs.hpp>
#include "app_resources_default.h"
#include "imgui.h"
#include "portable-file-dialogs.h"
auto pixelarium::application::IPixelariumImageView::ImageViewMenuBar() -> void
{
if (ImGui::BeginMenuBar())
{
if (ImGui::MenuItem(SAVEAS))
if (ImGui::BeginMenu("File"))
{
auto dest = pfd::save_file("Save File", ".", {"Image Files", "*.png *.jpg *.jpeg *.tiff"},
pfd::opt::force_overwrite)
.result();
if (!dest.empty())
if (ImGui::MenuItem(SAVEAS))
{
// this->img_->SaveImage(dest);
cv::imwrite(dest, cached_image_);
auto dest = pfd::save_file("Save File", ".", {"Image Files", "*.png *.jpg *.jpeg *.tiff"},
pfd::opt::force_overwrite)
.result();
if (!dest.empty())
{
// this->img_->SaveImage(dest);
cv::imwrite(dest, cached_image_);
}
}
ImageViewMenuBarAdditions();
ImGui::EndMenu();
}
ImGui::EndMenuBar();
+21 -6
View File
@@ -3,11 +3,11 @@
#include <format>
#include <memory>
#include "IPixelariumImage.hpp"
#include "IPixelariumImageView.hpp"
#include "PixelariumImageFactory.hpp"
#include "PixelariumImageViewCzi.hpp"
#include "PixelariumImageViewDefault.hpp"
#include "imaging/IPixelariumImage.hpp"
#include "imaging/PixelariumImageFactory.hpp"
/// @brief Creates a PixelariumImageView from a resource image.
/// @param image_id The ID of the image resource to render.
@@ -19,7 +19,7 @@ std::unique_ptr<pixelarium::application::IPixelariumImageView> pixelarium::appli
using ImageType = imaging::ImageFileType;
auto res{this->image_pool_.GetResource(image_id)};
auto img{res.lock()};
const auto img{res.lock()};
if (img == nullptr)
{
@@ -48,11 +48,26 @@ std::unique_ptr<pixelarium::application::IPixelariumImageView> pixelarium::appli
case ImageType::kMemory:
log_.Info(std::format("{}: Creating a Default View", __PRETTY_FUNCTION__));
// beware: here we copy the actual image resource over to the new image
return std::make_unique<PixelariumImageViewDefault>(img);
try
{
auto view{std::make_unique<PixelariumImageViewDefault>(img)};
return view;
}
catch (const std::exception& ex)
{
log_.Error(std::format("{}: Creating view failed: {}", __PRETTY_FUNCTION__, ex.what()));
}
case ImageType::kCzi:
log_.Info(std::format("{}: Creating a CZI View", __PRETTY_FUNCTION__));
// beware: here we copy the actual image resource over to the new image
return std::make_unique<PixelariumImageViewCzi>(img, log_);
try
{
auto view{std::make_unique<PixelariumImageViewCzi>(img, log_)};
return view;
}
catch (const std::exception& ex)
{
log_.Error(std::format("{}: Creating view failed: {}", __PRETTY_FUNCTION__, ex.what()));
}
default:
return {};
}
+16 -3
View File
@@ -2,11 +2,12 @@
#include <format>
#include <memory>
#include <stdexcept>
#include "CvMatRender.hpp"
#include "IPixelariumImage.hpp"
#include "PixelariumCzi.hpp"
#include "RenderHelpers.hpp"
#include "imaging/IPixelariumImage.hpp"
#include "imaging/impl/PixelariumCzi.hpp"
#include "imgui.h"
void pixelarium::application::PixelariumImageViewCzi::RefreshCachedImage()
@@ -26,7 +27,7 @@ void pixelarium::application::PixelariumImageViewCzi::RefreshCachedImage()
}
pixelarium::application::PixelariumImageViewCzi::PixelariumImageViewCzi(std::shared_ptr<Image> img, const Log& log)
: log_(log), render_(std::make_unique<CvMatRender>(*img->TryGetImage()))
: log_(log)
{
img_ = img;
auto czi_img = std::static_pointer_cast<imaging::PixelariumCzi>(this->img_);
@@ -39,6 +40,18 @@ pixelarium::application::PixelariumImageViewCzi::PixelariumImageViewCzi(std::sha
return true;
});
auto render_mat = img->TryGetImage();
if (render_mat.has_value())
{
this->render_ = std::make_unique<CvMatRender>(render_mat.value());
}
else
{
auto msg{std::format("{}: fetching image failed: {}", __PRETTY_FUNCTION__, img->Name())};
log_.Error(msg);
throw std::runtime_error(msg);
}
// this->SetInitialSize();
log_.Info(std::format("{}: dimension map size: {}", __PRETTY_FUNCTION__, dimension_map_.size()));
}
@@ -1,11 +1,22 @@
#include "PixelariumImageViewDefault.hpp"
#include <format>
#include <opencv2/core/hal/interface.h>
#include <cstdio>
#include <format>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <ostream>
#include <ranges>
#include <utility>
#include "IPixelariumImage.hpp"
#include "RenderHelpers.hpp"
#include "app_resources_default.h"
#include "imaging/IPixelariumImage.hpp"
#include "imgui.h"
#include "implot.h"
#include "simple_thread_pool.hpp"
void pixelarium::application::PixelariumImageViewDefault::RefreshCachedImage()
{
@@ -16,6 +27,11 @@ void pixelarium::application::PixelariumImageViewDefault::RefreshCachedImage()
}
}
void pixelarium::application::PixelariumImageViewDefault::ImageViewMenuBarAdditions()
{
ImGui::MenuItem("Histogram", NULL, &this->show_hists_);
}
/// @brief Displays the image in an ImGui window.
///
/// If the image is null, empty, or has an empty name, the function returns immediately. Otherwise, it creates an ImGui
@@ -40,6 +56,7 @@ void pixelarium::application::PixelariumImageViewDefault::ShowImage()
const auto cached_heigth{cached_image_.rows};
const auto ratio{static_cast<float>(cached_heigth) / cached_width};
SetInitialSize(kInitialWindowWidth, (kInitialWindowWidth * ratio + 100));
utils::pixelarium_pool::enqueue([this]() { GenerateHistogram(); });
}
ImGui::Begin(this->img_->Name().c_str(), &this->open_p,
@@ -62,8 +79,67 @@ void pixelarium::application::PixelariumImageViewDefault::ShowImage()
aspect_const_dimensions(dim, new_dim));
ImGui::Separator();
if (show_hists_ && hist_available_)
{
if (ImPlot::BeginPlot("Histogram"))
{
ImPlot::SetupAxes(nullptr, nullptr, ImPlotAxisFlags_AutoFit, ImPlotAxisFlags_AutoFit);
using style_pair = std::pair<const char*, ImVec4>;
constexpr std::array<style_pair, 3> names = {
{{"Blue", ImVec4(0, 0, 1, 1)}, {"Green", ImVec4(0, 1, 0, 1)}, {"Red", ImVec4(1, 0, 0, 1)}}};
// for (auto& e : hist_planes_)
// {
// ImPlot::PlotHistogram(name.c_str(), e.data, e.rows * e.cols, 16);
// for (auto& e : name)
// {
// e++;
// }
// }
for (size_t i{0}; i < hist_planes_.size(); ++i)
{
if (hist_planes_.at(i).type() == CV_32F)
{
// ImPlot::PlotHistogram(names.at(i % 3), reinterpret_cast<float*>(hist_planes_[i].data),
// hist_planes_[i].rows * hist_planes_[i].cols, 16, 1.0, ImPlotRange(),
// ImPlotHistogramFlags_Horizontal);
ImPlot::PushStyleColor(ImPlotCol_Line, names.at(i % 3).second);
ImPlot::PlotLine(std::format("{}-line", names.at(i % 3).first).c_str(),
reinterpret_cast<float*>(hist_planes_[i].data),
hist_planes_[i].rows * hist_planes_[i].cols);
ImPlot::PopStyleColor();
}
}
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f);
ImPlot::SetNextMarkerStyle(ImPlotMarker_Square, 6, ImPlot::GetColormapColor(1), IMPLOT_AUTO,
ImPlot::GetColormapColor(1));
ImPlot::EndPlot();
}
}
ImGui::Text("%s", std::format(" Raw Dimensions W : {}, H: {}", dim.x, dim.y).c_str());
ImGui::Text("%s", std::format("Render Dimensions W : {}, H: {}", curr_dim_.x, curr_dim_.y).c_str());
ImGui::End();
}
auto pixelarium::application::PixelariumImageViewDefault::GenerateHistogram() -> void
{
cv::split(cached_image_, bgr_planes_);
hist_planes_.resize(bgr_planes_.size());
int histSize = 256;
float range[] = {0, 256}; // the upper boundary is exclusive
const float* histRange[] = {range};
for (auto [bgr, hist] : std::ranges::views::zip(bgr_planes_, hist_planes_))
{
cv::calcHist(&bgr, 1, 0, cv::Mat(), hist, 1, &histSize, histRange, true, false);
// cv::normalize(hist, hist);
}
hist_available_ = true;
}
+6 -3
View File
@@ -46,9 +46,10 @@ bool pixelarium::application::RenderImageManager::Remove(resources::ResourceKey
/// @return void. No exception is thrown.
void pixelarium::application::RenderImageManager::Add(resources::ResourceKey key) noexcept
{
// we don't want to add what's already there
// or empty render images
if (this->render_image_map_.contains(key))
// we don't want to add what's already there, render empty images, or failed keys
if (this->render_image_map_.contains(key)
// || this->failed_keys_cache_.contains(key)
)
{
return;
}
@@ -56,6 +57,8 @@ void pixelarium::application::RenderImageManager::Add(resources::ResourceKey key
auto current_view = this->view_factory_->RenderImage(key);
if (current_view == nullptr)
{
// failed to create view, cache this key to avoid repeated attempts
this->failed_keys_cache_.insert(key);
return;
}
@@ -2,7 +2,7 @@
#include <memory>
#include "imaging/IPixelariumImage.hpp"
#include "IPixelariumImage.hpp"
#include "imgui.h"
namespace pixelarium::application
@@ -29,6 +29,7 @@ class IPixelariumImageView
protected:
virtual void ImageViewMenuBar();
virtual void ImageViewMenuBarAdditions() {};
protected:
std::shared_ptr<imaging::IPixelariumImageCvMat> img_{};
@@ -1,8 +1,8 @@
#pragma once
#include "ILog.hpp"
#include "IPixelariumImageView.hpp"
#include "resources/resource.hpp"
#include "utilities/ILog.hpp"
#include "resource.hpp"
namespace pixelarium::application
{
@@ -4,11 +4,11 @@
#include <unordered_map>
#include "CvMatRender.hpp"
#include "ILog.hpp"
#include "IPixelariumImage.hpp"
#include "IPixelariumImageView.hpp"
#include "imaging/IPixelariumImage.hpp"
#include "imgui.h"
#include "libCZI_DimCoordinate.h"
#include "utilities/ILog.hpp"
namespace pixelarium::application
{
@@ -1,10 +1,11 @@
#pragma once
#include <memory>
#include <vector>
#include "CvMatRender.hpp"
#include "IPixelariumImage.hpp"
#include "IPixelariumImageView.hpp"
#include "imaging/IPixelariumImage.hpp"
#include "imgui.h"
namespace pixelarium::application
@@ -16,11 +17,8 @@ class PixelariumImageViewDefault : public IPixelariumImageView
using Image = imaging::IPixelariumImageCvMat;
public:
explicit PixelariumImageViewDefault(std::shared_ptr<Image> img) : render_(*img->TryGetImage())
{
img_ = img;
// this->SetInitialSize();
}
explicit PixelariumImageViewDefault(std::shared_ptr<Image> img) : render_(*img->TryGetImage()) { img_ = img; }
PixelariumImageViewDefault() = delete;
PixelariumImageViewDefault(PixelariumImageViewDefault&) = delete;
PixelariumImageViewDefault(const PixelariumImageViewDefault&) = delete;
@@ -30,9 +28,17 @@ class PixelariumImageViewDefault : public IPixelariumImageView
void ShowImage() override;
void ImageViewMenuBarAdditions() override;
void GenerateHistogram();
private:
ImVec2 curr_dim_{};
CvMatRender render_;
bool show_hists_{false};
bool hist_available_{false};
std::vector<cv::Mat> bgr_planes_;
std::vector<cv::Mat> hist_planes_;
private:
void RefreshCachedImage();
@@ -4,10 +4,10 @@
#include <unordered_map>
#include <unordered_set>
#include "ILog.hpp"
#include "IPixelariumImageView.hpp"
#include "ImageViewFactory.hpp"
#include "resources/resource.hpp"
#include "utilities/ILog.hpp"
#include "resource.hpp"
// This is intended as an additional abstraction
// aggregating views that should be rendered (or not)
@@ -68,6 +68,7 @@ class RenderImageManager
std::unique_ptr<ImageViewFactory> view_factory_;
std::mutex mut_;
std::unordered_set<resources::ResourceKey> keys_to_delete_;
std::unordered_set<resources::ResourceKey> failed_keys_cache_;
const utils::log::ILog& log_;
};