SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
cziscene.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#ifndef OPENCV_slideio_cziscene_HPP
5#define OPENCV_slideio_cziscene_HPP
6#include "slideio/drivers/czi/czi_api_def.hpp"
7#include "slideio/core/cvscene.hpp"
8#include "slideio/core/tools/tilecomposer.hpp"
9#include "slideio/drivers/czi/czisubblock.hpp"
10#include "slideio/drivers/czi/czistructs.hpp"
11#include <map>
12
13#if defined(_MSC_VER)
14#pragma warning( push )
15#pragma warning(disable: 4251)
16#endif
17
18namespace slideio
19{
20 class CZISlide;
21 class SLIDEIO_CZI_EXPORTS CZIScene : public CVScene, public Tiler
22 {
23 public:
24 struct SceneParams
25 {
26 int illuminationIndex;
27 int bAcquisitionIndex;
28 int rotationIndex;
29 int sceneIndex;
30 int hPhaseIndex;
31 int viewIndex;
32 };
33 private:
34 struct Tile
35 {
36 Tile() { rect = { 0,0,0,0 }; }
37 std::vector<int> blockIndices;
38 cv::Rect rect;
39 };
40 typedef std::vector<Tile> Tiles;
41 struct ZoomLevel
42 {
43 double zoom{};
44 CZISubBlocks blocks;
45 Tiles tiles;
46 };
47 struct ComponentInfo
48 {
49 std::string name;
50 DataType dataType;
51 };
52 struct SceneChannelInfo
53 {
54 std::string name;
55 int32_t pixelType;
56 int32_t pixelSize;
57 int32_t firstComponent;
58 int32_t numComponents;
59 DataType componentType;
60 };
61 struct TilerData
62 {
63 int zoomLevelIndex;
64 int zSliceIndex;
65 int tFrameIndex;
66 double relativeZoom;
67 };
68 public:
69 CZIScene();
70 std::string getFilePath() const override;
71 cv::Rect getRect() const override;
72 int getNumChannels() const override;
73 int getNumZSlices() const override;
74 int getNumTFrames() const override;
75 double getZSliceResolution() const override;
76 double getTFrameResolution() const override;
77 slideio::DataType getChannelDataType(int channel) const override;
78 std::string getChannelName(int channel) const override;
79 Resolution getResolution() const override;
80 double getMagnification() const override;
81 void readResampledBlockChannels(const cv::Rect& blockRect, const cv::Size& blockSize,
82 const std::vector<int>& componentIndices, cv::OutputArray output) override;
83 std::string getName() const override;
84 void init(uint64_t sceneId, SceneParams& sceneParams, const std::string& filePath, const CZISubBlocks& blocks, CZISlide* slide);
85 // interface Tiler implementaton
86 int getTileCount(void* userData) override;
87 bool getTileRect(int tileIndex, cv::Rect& tileRect, void* userData) override;
88 bool readTile(int tileIndex, const std::vector<int>& componentIndices, cv::OutputArray tileRaster,
89 void* userData) override;
90 void initializeBlock(const cv::Size& blockSize, const std::vector<int>& channelIndices, cv::OutputArray output) override;
91 Compression getCompression() const override{
92 return m_compression;
93 }
94 void addAuxImage(const std::string& name, std::shared_ptr<CVScene> image);
95 std::shared_ptr<CVScene> getAuxImage(const std::string& sceneName) const override;
96 bool isMosaic() const { return m_bMosaic; }
97 protected:
98 void readResampledBlockChannelsEx(const cv::Rect& blockRect, const cv::Size& blockSize,
99 const std::vector<int>& componentIndices, int zSliceIndex, int tFrameIndex, cv::OutputArray output) override;
100 private:
101 void setMosaic(bool mosaic) { m_bMosaic = mosaic; }
102 void setupComponents(const std::map<int, int>& channelPixelType);
103 void generateSceneName();
104 void computeSceneRect();
105 void computeSceneTiles();
106 void compute4DParameters();
107 void updateTileRects(ZoomLevel& value);
108 void updateTileRects();
109 const ZoomLevel& getBaseZoomLevel() const;
110 void initZoomLevelInfo();
111 int findBlockIndex(const Tile& tile, const CZISubBlocks& blocks, int channelIndex, int zSliceIndex, int tFrameIndex) const ;
112 const Tile& getTile(const TilerData* tilerData, int tileIndex) const;
113 const CZISubBlocks& getBlocks(const TilerData* tilerData) const;
114 bool blockHasData(const CZISubBlock& block, const std::vector<int>& componentIndices, const TilerData* tilerData);
115 static std::vector<uint8_t> decodeData(const CZISubBlock& block, const std::vector<unsigned char>& encodedData);
116 void unpackChannels(const CZISubBlock& block, const std::vector<int>& orgComponentIndices, const std::vector<unsigned char>& blockData, const TilerData* tilerData, std::vector<cv::Mat>& componentRasters);
117 void computeSceneMetadata();
118 public:
119 // static members
120 static uint64_t sceneIdFromDims(int s, int i, int v, int h, int r, int b);
121 static uint64_t sceneIdFromDims(const std::vector<Dimension>& dims);
122 static void sceneIdsFromDims(const std::vector<Dimension>& dims, std::vector<uint64_t>& ids);
123 static uint64_t sceneIdFromDims(const SceneParams& params);
124 static void dimsFromSceneId(uint64_t sceneId, int& s, int& i, int& v, int& h, int& r, int& b);
125 static void dimsFromSceneId(uint64_t sceneId, SceneParams& params);
126 static void channelComponentInfo(CZIDataType channelType, DataType& componentType, int& numComponents, int& pixelSize);
127 private:
128 void combineBlockInTiles(ZoomLevel& zoomLevel);
129 // data members
130 private:
131 std::vector<ZoomLevel> m_zoomLevels;
132 std::vector<ComponentInfo> m_componentInfos;
133 std::vector<SceneChannelInfo> m_channelInfos;
134 std::string m_filePath;
135 cv::Rect m_sceneRect;
136 std::map<int, std::pair<int, int>> m_componentToChannelIndex;
137 CZISlide* m_slide;
138 std::string m_name;
139 uint64_t m_id{};
140 SceneParams m_sceneParams{};
141 int m_numZSlices;
142 int m_numTFrames;
143 int m_firstSliceIndex = 0;
144 int m_firstTFrameIndex = 0;
145 Compression m_compression;
146 std::map<std::string, std::shared_ptr<CVScene>> m_auxImages;
147 bool m_bMosaic;
148 };
149}
150
151
152#if defined(_MSC_VER)
153#pragma warning( pop )
154#endif
155
156#endif
Definition: exceptions.hpp:12
Compression
raster data compression enum
Definition: slideio_enums.hpp:12