SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
czislide.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_czislide_HPP
5#define OPENCV_slideio_czislide_HPP
6#include "slideio/drivers/czi/czi_api_def.hpp"
7#include "slideio/core/cvslide.hpp"
8#include "slideio/drivers/czi/cziscene.hpp"
9#include "slideio/drivers/czi/czistructs.hpp"
10#include <fstream>
11
12
13namespace tinyxml2
14{
15 class XMLNode;
16 class XMLElement;
17 class XMLDocument;
18}
19
20#if defined(_MSC_VER)
21#pragma warning( push )
22#pragma warning(disable: 4251)
23#endif
24
25namespace slideio
26{
27 class SLIDEIO_CZI_EXPORTS CZISlide : public CVSlide
28 {
29 friend class CZIImageDriver;
30 protected:
31 CZISlide(const std::string& filePath);
32 public:
33 virtual ~CZISlide() override;
34 int getNumScenes() const override;
35 std::string getFilePath() const override;
36 std::shared_ptr<CVScene> getScene(int index) const override;
37 double getMagnification() const { return m_magnification; }
38 Resolution getResolution() const { return m_res; }
39 double getZSliceResolution() const {return m_resZ;}
40 double getTFrameResolution() const {return m_resT;}
41 const CZIChannelInfos& getChannelInfo() const { return m_channels; }
42 const std::string& getTitle() const { return m_title; }
43 void readBlock(uint64_t pos, uint64_t size, std::vector<unsigned char>& data);;
44 std::shared_ptr<CVScene> getAuxImage(const std::string& sceneName) const override;
45 void readFileHeader(FileHeader& fileHeader);
46 void readSubBlocks(uint64_t pos, uint64_t originPos, std::vector<CZISubBlocks>& sceneBlocks, std::vector<uint64_t>& sceneIds);
47 std::shared_ptr<CZIScene> constructScene(uint64_t sceneId, const CZISubBlocks& blocks);
48 private:
49 void readAttachments();
50 void init();
51 void readMetadata();
52 void readFileHeader();
53 void readDirectory();
54 void parseMagnification(tinyxml2::XMLNode* root);
55 void parseMetadataXmL(const char* xml, size_t dataSize);
56 void parseResolutions(tinyxml2::XMLNode* root);
57 void parseSizes(tinyxml2::XMLNode* root);
58 void createJpgAttachmentScenes(int64_t dataPosition, int64_t dataSize, const std::string& name);
59 void parseChannels(tinyxml2::XMLNode* root);
60 void createCZIAttachmentScenes(const int64_t dataPos, int64_t dataSize, const std::string& attachmentName);
61 void addAuxiliaryImage(const std::string& name, const std::string& type, int64_t position);
62 static void updateSegmentHeaderBE(SegmentHeader& header);
63 static void updateFileHeaderBE(FileHeader& header);
64 static void updateMetadataHeaderBE(MetadataHeader& header);
65 static void updateDirectoryHeaderBE(DirectoryHeader& header);
66 static void updateDirectoryEntryBE(DirectoryEntryDV& entry);
67 static void updateDimensionEntryBE(DimensionEntryDV& entry);
68 static void updateSublockHeaderBE(SubBlockHeader& header);
69 static void updateAttachmentEntryBE(AttachmentEntry& entry);
70 static void updateAttachmentDirectorySegmentDataBE(AttachmentDirectorySegmentData& data);
71 static void updateAttachmentDirectorySegmentBE(AttachmentDirectorySegment& segment);
72 static void updateAttachmentEntryA1BE(AttachmentEntryA1& entry);
73 static void updateAttachmentSegmentDataBE(AttachmentSegmentData& data);
74 static void updateAttachmentSegmentBE(AttachmentSegment& segment);
75 static void updateDimensionBE(Dimension& dim);
76 private:
77 std::vector<std::shared_ptr<CZIScene>> m_scenes;
78 std::string m_filePath;
79 std::ifstream m_fileStream;
80 uint64_t m_directoryPosition{};
81 uint64_t m_metadataPosition{};
82 uint64_t m_attachmentDirectoryPosition;
83 // image parameters
84 int m_slideXs{};
85 int m_slideYs{};
86 int m_slideZs{};
87 int m_slideTs{};
88 int m_slideRs{};
89 int m_slideIs{};
90 int m_slideSs{};
91 int m_slideHs{};
92 int m_slideMs{};
93 int m_slideBs{};
94 int m_slideVs{};
95 double m_magnification{};
96 Resolution m_res{};
97 double m_resZ{};
98 double m_resT{};
99 CZIChannelInfos m_channels;
100 std::string m_title;
101 std::map<std::string, std::shared_ptr<CVScene >> m_auxImages;
102 };
103
104
105}
106
107#if defined(_MSC_VER)
108#pragma warning( pop )
109#endif
110
111#endif
Definition: exceptions.hpp:15