SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
dcmfile.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
6#include "slideio/drivers/dcm/dcm_api_def.hpp"
7#include "slideio/base/slideio_enums.hpp"
8#include <string>
9#include <memory>
10#include <opencv2/core.hpp>
11
12#include "slideio/base/slideio_enums.hpp"
13#include "slideio/base/resolution.hpp"
14
15#if defined(_MSC_VER)
16#pragma warning( push )
17#pragma warning(disable: 4251)
18#endif
19
20class DicomImage;
21class DcmDataset;
22class DcmFileFormat;
23class DcmTagKey;
24
25namespace slideio
26{
27 enum class EPhotoInterpetation
28 {
29 PHIN_UNKNOWN,
30 PHIN_MONOCHROME1,
31 PHIN_MONOCHROME2,
32 PHIN_RGB,
33 PHIN_PALETTE,
34 PHIN_YCBCR,
35 PHIN_YBR_FULL,
36 PHIN_YBR_422_FULL,
37 PHIN_HSV,
38 PHIN_ARGB,
39 PHIN_CMYK,
40 PHIN_YBR_FULL_422,
41 PHIN_YBR_PARTIAL_420,
42 PHIN_YBR_ICT,
43 PHIN_YBR_RCT
44 };
45
46 class SLIDEIO_DCM_EXPORTS DCMFile
47 {
48 public:
49 DCMFile(const std::string& filePath);
50 void loadFile();
51 void init();
52
53 int getWidth() const {
54 return m_width;
55 }
56
57 int getHeight() const {
58 return m_height;
59 }
60
61 int getNumSlices() const {
62 return m_slices;
63 }
64
65 const std::string& getFilePath() const {
66 return m_filePath;
67 }
68
69 const std::string& getSeriesUID() const {
70 return m_seriesUID;
71 }
72
73 int getInstanceNumber() const {
74 return m_instanceNumber;
75 }
76
77 int getNumChannels() const {
78 return m_numChannels;
79 }
80
81 const std::string& getSeriesDescription() const {
82 return m_seriesDescription;
83 }
84
85 DataType getDataType() const {
86 return m_dataType;
87 }
88
89 bool getPlanarConfiguration() const {
90 return m_planarConfiguration;
91 }
92
93 EPhotoInterpetation getPhotointerpretation() const {
94 return m_photoInterpretation;
95 }
96
97 Compression getCompression() const {
98 return m_compression;
99 }
100
101 const std::string& getModality() const {
102 return m_modality;
103 }
104
105 void logData();
106 void readPixelValues(std::vector<cv::Mat>& frames, int startFrame = 0, int numFrames = 1);
107
108 bool isWSIFile() const {
109 return m_WSISlide;
110 }
111
112 std::string getMetadata();
113 double getMagnification() const {
114 return m_magnification;
115 }
116 const Resolution& getResolution() const {
117 return m_resolution;
118 }
119 static bool isDicomDirFile(const std::string& filePath);
120 static bool isWSIFile(const std::string& filePath);
121
122 const cv::Size& getTileSize() const {
123 return m_tileSize;
124 }
125
126 int getNumFrames() const {
127 return m_frames;
128 }
129 bool getTileRect(int tileIndex, cv::Rect& tileRect) const;
130 bool readFrame(int tileIndex, cv::OutputArray tileRaster);
131 double getScale() const {
132 return m_scale;
133 }
134 void setScale(double scale) {
135 m_scale = scale;
136 }
137 bool isTiled() const {
138 return m_bTiled;
139 }
140 const std::string& getImageType() const {
141 return m_imageType;
142 }
143 bool isAuxImage() const {
144 return m_imageType != "VOLUME";
145 }
146 private:
147 void readFrames(std::vector<cv::Mat>& frames, int startFrame, int numFrames);
148 void extractPixelsWholeFileDecompression(std::vector<cv::Mat>& mats, int startFrame, int numFrames);
149 std::shared_ptr<DicomImage> createImage(int firstSlice = 0, int numSlices = 1);
150 void initPhotoInterpretaion();
151 void defineCompression();
152 DcmDataset* getDataset() const;
153 DcmDataset* getValidDataset() const;
154 bool getIntTag(const DcmTagKey& tag, int& value, int pos = 0) const;
155 bool getStringTag(const DcmTagKey& tag, std::string& value) const;
156 bool getStringTag(const DcmTagKey& tag, int index, std::string& value) const;
157 bool getDblTag(const DcmTagKey& tag, double& value, double defaultValue);
158 private:
159 std::string m_filePath;
160 std::shared_ptr<DcmFileFormat> m_file;
161 int m_width = 0;
162 int m_height = 0;
163 int m_slices = 1;
164 int m_instanceNumber = -1;
165 std::string m_seriesUID;
166 std::string m_seriesDescription;
167 int m_numChannels = 0;
168 DataType m_dataType = DataType::DT_Unknown;
169 bool m_planarConfiguration = false;
170 EPhotoInterpetation m_photoInterpretation = EPhotoInterpetation::PHIN_UNKNOWN;
171 double m_windowCenter = -1;
172 double m_windowWidth = -1;
173 double m_rescaleSlope = 1.;
174 double m_rescaleIntercept = 0.;
175 bool m_useWindowing = false;
176 bool m_useRescaling = false;
177 Compression m_compression = Compression::Unknown;
178 bool m_decompressWholeFile = false;
179 int m_bitsAllocated = 0;
180 std::string m_modality;
181 bool m_WSISlide = false;
182 int m_frames = 1;
183 cv::Size m_tileSize = {0, 0};
184 double m_magnification = 0.;
185 Resolution m_resolution = { 0., 0. };
186 double m_scale = 1.;
187 bool m_bTiled = false;
188 std::string m_imageType;
189 };
190}
191
192#if defined(_MSC_VER)
193#pragma warning( pop )
194#endif
Definition: exceptions.hpp:15
Compression
raster data compression enum
Definition: slideio_enums.hpp:12