7#include "slideio/core/slideio_core_def.hpp"
8#include <unordered_map>
9#include <boost/container_hash/hash.hpp>
10#include <opencv2/core.hpp>
12#include "tilecomposer.hpp"
16#pragma warning( push )
17#pragma warning(disable: 4251)
22 class SLIDEIO_CORE_EXPORTS CacheManager
28 Level(
int id) : m_id(id)
32 int getId()
const {
return m_id; }
34 void addTile(
const cv::Rect& rect,
int cacheIndex)
36 tiles.emplace_back(rect, cacheIndex);
39 int getTileCount()
const
41 return static_cast<int>(tiles.size());
44 const cv::Rect& getTileRect(
int index)
const
46 return tiles[index].first;
49 int getTileCacheIndex(
int index)
const
51 return tiles[index].second;
56 std::vector<std::pair<cv::Rect, int>> tiles;
60 virtual ~CacheManager();
61 void addTile(
int level, cv::Point2i pos,
const cv::Mat& tile);
62 int getTileCount(
int level)
const;
63 cv::Mat getTile(
int levelId,
int index)
const;
64 const cv::Rect getTileRect(
int levelId,
int tileIndex)
const;
67 std::vector<cv::Mat> m_cache;
68 std::map<int, std::shared_ptr<Level>> m_levels;
71 class SLIDEIO_CORE_EXPORTS CacheManagerTiler :
public Tiler
74 CacheManagerTiler(std::shared_ptr<CacheManager>& cacheManager,
const cv::Size& tileSize,
int levelId) :
75 m_cacheManager(cacheManager), m_tileSize(tileSize), m_levelId(levelId) {
77 int getTileCount(
void* userData)
override {
78 return m_cacheManager->getTileCount(m_levelId);
80 bool getTileRect(
int tileIndex, cv::Rect& tileRect,
void* userData)
override {
81 tileRect = m_cacheManager->getTileRect(m_levelId, tileIndex);
84 bool readTile(
int tileIndex,
const std::vector<int>& channelIndices, cv::OutputArray tileRaster,
85 void* userData)
override {
86 cv::Mat tile = m_cacheManager->getTile(m_levelId, tileIndex);
87 tileRaster.create(tile.size(), tile.type());
88 Tools::extractChannels(tile, channelIndices, tileRaster);
91 void initializeBlock(
const cv::Size& blockSize,
const std::vector<int>& channelIndices,
92 cv::OutputArray output)
override {
93 cv::Mat tile = m_cacheManager->getTile(m_levelId, 0);
94 int channelCount =
static_cast<int>(channelIndices.size());
95 if (channelCount == 0) {
96 channelCount = tile.channels();
98 output.create(blockSize, CV_MAKETYPE(tile.depth(), channelCount));
103 std::shared_ptr<CacheManager> m_cacheManager;
Definition: exceptions.hpp:12