build system and module refactoring + simple histogram scratch (#20)
* 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:
committed by
Maximilian Kueffner
parent
b37814204f
commit
c00c2c71ac
@@ -3,7 +3,7 @@
|
||||
#include <opencv2/core/mat.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include "imaging/IPixelariumImage.hpp"
|
||||
#include "IPixelariumImage.hpp"
|
||||
|
||||
using namespace pixelarium::imaging;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
-1
@@ -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_{};
|
||||
+2
-2
@@ -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
|
||||
{
|
||||
+2
-2
@@ -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
|
||||
{
|
||||
+12
-6
@@ -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();
|
||||
+3
-2
@@ -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_;
|
||||
};
|
||||
Reference in New Issue
Block a user