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#pragma once
5#include "slideio/drivers/czi/czi_api_def.hpp"
6#include "slideio/core/cvslide.hpp"
7#include "slideio/drivers/czi/cziscene.hpp"
8#include "slideio/drivers/czi/czistructs.hpp"
9#include <fstream>
10
11
12namespace tinyxml2
13{
14 class XMLNode;
15 class XMLElement;
16 class XMLDocument;
17}
18
19#if defined(_MSC_VER)
20#pragma warning( push )
21#pragma warning(disable: 4251)
22#endif
23
24namespace slideio
25{
26 class SLIDEIO_CZI_EXPORTS CZISlide : public CVSlide
27 {
28 friend class CZIImageDriver;
29 protected:
30 CZISlide(const std::string& filePath, const std::string& driverId);
31 public:
32 virtual ~CZISlide() override;
33 int getNumScenes() const override;
34 std::string getFilePath() const override;
35 std::shared_ptr<CVScene> getScene(int index) const override;
36 double getMagnification() const { return m_magnification; }
37 Resolution getResolution() const { return m_res; }
38 double getZSliceResolution() const {return m_resZ;}
39 double getTFrameResolution() const {return m_resT;}
40 const CZIChannelInfos& getChannelInfo() const { return m_channels; }
41 const std::string& getTitle() const { return m_title; }
42 void readBlock(uint64_t pos, uint64_t size, std::vector<unsigned char>& data);;
43 std::shared_ptr<CVScene> getAuxImage(const std::string& sceneName) const override;
44 void readFileHeader(FileHeader& fileHeader);
45 void readSubBlocks(uint64_t pos, uint64_t originPos, std::vector<CZISubBlocks>& sceneBlocks, std::vector<uint64_t>& sceneIds);
46 std::shared_ptr<CZIScene> constructScene(int sceneIndex, uint64_t sceneId, const CZISubBlocks& blocks, bool mainScene = true);
47 private:
48 void readAttachments();
49 void init();
50 void readMetadata();
51 void readFileHeader();
52 void readDirectory();
53 void parseMagnification(tinyxml2::XMLNode* root);
54 void parseMetadataXmL(const char* xml, size_t dataSize);
55 void parseResolutions(tinyxml2::XMLNode* root);
56 void parseSizes(tinyxml2::XMLNode* root);
57 void createJpgAttachmentScenes(int64_t dataPosition, int64_t dataSize, const std::string& name);
58 void processBgrChannelAttributes();
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
Definition: exceptions.hpp:15