Files
pixelarium/lib/rendering/RenderImageManager.hpp
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

77 lines
2.2 KiB
C++

#pragma once
#include <memory>
#include <mutex>
#include <unordered_map>
#include <unordered_set>
#include "ImageViewFactory.hpp"
#include "PixelariumImageViewDefault.hpp"
#include "rendering/IPixelariumImageView.hpp"
#include "resources/resource.hpp"
#include "utilities/ILog.hpp"
// This is intended as an additional abstraction
// aggregating views that should be rendered (or not)
namespace pixelarium::render
{
/// @brief Instead of directly using the view, we
/// proxy it through a wrapper. This allows for arbitrary additional data
/// to be added in future
struct RenderImageStateWrapper
{
std::unique_ptr<IPixelariumImageView> view;
const bool* show_state;
};
/// @brief Manage instances of IPixelariumImageView.
///
/// This class is used to keep track of what must be rendered.
/// It manages a set of IPixelariumImageView instances that can be traversed
/// via its Enumerate() function.
/// Views that shall not be rendered anymore should be marked for deletion
/// with MarkForDeletion()
class RenderImageManager
{
using Pool = resources::ImageResourcePool;
public:
explicit RenderImageManager(Pool& pool, const utils::log::ILog& log)
: view_factory_(std::make_unique<ImageViewFactory>(pool, log)), log_(log)
{
}
void Clear() noexcept;
void Add(resources::ResourceKey key) noexcept;
bool Remove(resources::ResourceKey key) noexcept;
// can't be const because func mutates the state
template <typename Callable>
requires std::invocable<Callable, resources::ResourceKey, RenderImageStateWrapper&>
void Enumerate(Callable&& func)
{
for (auto& [key, val] : this->render_image_map_)
{
if (val.view != nullptr)
{
func(key, val);
}
}
}
void MarkForDeletion(resources::ResourceKey key);
void UpdateCollection();
private:
std::unordered_map<resources::ResourceKey, RenderImageStateWrapper> render_image_map_;
std::unique_ptr<ImageViewFactory> view_factory_;
std::mutex mut_;
std::unordered_set<resources::ResourceKey> keys_to_delete_;
const utils::log::ILog& log_;
};
} // namespace pixelarium::render