SlideIO 2.9.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
phtdescription.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/svs/svs_api_def.hpp"
7#include <string>
8#include <string_view>
9#include <vector>
10#include <memory>
11#include <tinyxml2.h>
12
13namespace slideio
14{
15 class PHTDescription
16 {
17 public:
18 class Attribute
19 {
20 public:
21 std::string_view Name;
22 std::string_view Group;
23 std::string_view Element;
24 };
25 public:
26 explicit PHTDescription(const std::string& description);
27 ~PHTDescription();
28 // The class owns the parsed xml document and cannot be copied.
29 PHTDescription(const PHTDescription&) = delete;
30 PHTDescription& operator=(const PHTDescription&) = delete;
31 PHTDescription(PHTDescription&& other) noexcept;
32 PHTDescription& operator=(PHTDescription&& other) noexcept;
33
34 // True if the text is the xml metadata of a philips tiff file. Used to tell a
35 // philips file from any other tiff, which the *.tif extension cannot do.
36 static bool isPhilipsDescription(const std::string& description);
37
38 // The data objects of the given type held by the array of `arrayAttribute`, e.g.
39 // the DPScannedImage objects of PIM_DP_SCANNED_IMAGES. If the parent does not
40 // carry that attribute, every attribute of the parent is searched for an array
41 // instead, so a file that declares its objects elsewhere is still read.
42 std::vector<const tinyxml2::XMLElement*> getObjectList(const tinyxml2::XMLElement* parent,
43 const Attribute& arrayAttribute, std::string_view name) const;
44 int getAttributeInt(const tinyxml2::XMLElement* element, const Attribute& attribute) const;
45 std::string getAttributeText(const tinyxml2::XMLElement* element, const Attribute& attribute) const;
46 // The values of an IStringArray attribute, e.g. "1.6.6186" "20150402_R48" "4.0.3".
47 // getAttributeText cannot read those: it strips the outer quotes only and hands back
48 // the interior ones as part of the value.
49 std::vector<std::string> getAttributeTextList(const tinyxml2::XMLElement* element, const Attribute& attribute) const;
50 std::vector<double> getAttributeDoubleList(const tinyxml2::XMLElement* element, const Attribute& attribute) const;
51 const tinyxml2::XMLElement* getRoot() const;
52 bool hasAttribute(const tinyxml2::XMLElement* element, const Attribute& attribute) const;
53 private:
54 std::unique_ptr<tinyxml2::XMLDocument> m_doc;
55 };
56
57 // The philips metadata vocabulary. Nested so that names like MANUFACTURER, WSI
58 // and BITS_STORED do not sit at slideio scope, where they are collision prone.
59 // inline constexpr rather than namespace-scope const: one object for the whole
60 // program instead of a copy per translation unit.
61 namespace phtiff
62 {
63 // Slide (root DataObject) level attributes
64 inline constexpr PHTDescription::Attribute MANUFACTURER = { "DICOM_MANUFACTURER", "0x0008", "0x0070" };
65 inline constexpr PHTDescription::Attribute SOFTWARE_VERSIONS = { "DICOM_SOFTWARE_VERSIONS", "0x0018", "0x1020" };
66 inline constexpr PHTDescription::Attribute UFS_INTERFACE_VERSION = { "PIM_DP_UFS_INTERFACE_VERSION", "0x301D", "0x1001" };
67 inline constexpr PHTDescription::Attribute UFS_BARCODE = { "PIM_DP_UFS_BARCODE", "0x301D", "0x1002" };
68 inline constexpr PHTDescription::Attribute SCANNED_IMAGES = { "PIM_DP_SCANNED_IMAGES", "0x301D", "0x1003" };
69
70 // Scanned image (DPScannedImage) attributes
71 inline constexpr PHTDescription::Attribute IMAGE_TYPE = { "PIM_DP_IMAGE_TYPE", "0x301D", "0x1004" };
72 inline constexpr PHTDescription::Attribute IMAGE_DATA = { "PIM_DP_IMAGE_DATA", "0x301D", "0x1005" };
73 inline constexpr PHTDescription::Attribute IMAGE_ROWS = { "PIM_DP_IMAGE_ROWS", "0x301D", "0x1006" };
74 inline constexpr PHTDescription::Attribute IMAGE_COLUMNS = { "PIM_DP_IMAGE_COLUMNS", "0x301D", "0x1007" };
75 inline constexpr PHTDescription::Attribute SOURCE_FILE = { "PIM_DP_SOURCE_FILE", "0x301D", "0x1000" };
76 inline constexpr PHTDescription::Attribute PIXEL_TRANSFORMATION_METHOD = { "UFS_IMAGE_PIXEL_TRANSFORMATION_METHOD", "0x301D", "0x2013" };
77 inline constexpr PHTDescription::Attribute DERIVATION_DESCRIPTION = { "DICOM_DERIVATION_DESCRIPTION", "0x0008", "0x2111" };
78 inline constexpr PHTDescription::Attribute IMAGE_RESOLUTION = { "DICOM_PIXEL_SPACING", "0x0028", "0x0030" };
79
80 // Pixel format attributes
81 inline constexpr PHTDescription::Attribute SAMPLES_PER_PIXEL = { "DICOM_SAMPLES_PER_PIXEL", "0x0028", "0x0002" };
82 inline constexpr PHTDescription::Attribute PHOTOMETRIC_INTERPRETATION = { "DICOM_PHOTOMETRIC_INTERPRETATION", "0x0028", "0x0004" };
83 inline constexpr PHTDescription::Attribute PLANAR_CONFIGURATION = { "DICOM_PLANAR_CONFIGURATION", "0x0028", "0x0006" };
84 inline constexpr PHTDescription::Attribute BITS_ALLOCATED = { "DICOM_BITS_ALLOCATED", "0x0028", "0x0100" };
85 inline constexpr PHTDescription::Attribute BITS_STORED = { "DICOM_BITS_STORED", "0x0028", "0x0101" };
86 inline constexpr PHTDescription::Attribute HIGH_BIT = { "DICOM_HIGH_BIT", "0x0028", "0x0102" };
87 inline constexpr PHTDescription::Attribute PIXEL_REPRESENTATION = { "DICOM_PIXEL_REPRESENTATION", "0x0028", "0x0103" };
88
89 // Compression attributes
90 inline constexpr PHTDescription::Attribute LOSSY_IMAGE_COMPRESSION = { "DICOM_LOSSY_IMAGE_COMPRESSION", "0x0028", "0x2110" };
91 inline constexpr PHTDescription::Attribute LOSSY_IMAGE_COMPRESSION_RATIO = { "DICOM_LOSSY_IMAGE_COMPRESSION_RATIO", "0x0028", "0x2112" };
92 inline constexpr PHTDescription::Attribute LOSSY_IMAGE_COMPRESSION_METHOD = { "DICOM_LOSSY_IMAGE_COMPRESSION_METHOD", "0x0028", "0x2114" };
93
94 // Zoom level (PixelDataRepresentation) attributes
95 inline constexpr PHTDescription::Attribute LEVEL_SEQUENCE = { "PIIM_PIXEL_DATA_REPRESENTATION_SEQUENCE", "0x1001", "0x8B01" };
96 inline constexpr PHTDescription::Attribute LEVEL_NUMBER = { "PIIM_PIXEL_DATA_REPRESENTATION_NUMBER", "0x1001", "0x8B02" };
97 inline constexpr PHTDescription::Attribute LEVEL_ROWS = { "PIIM_PIXEL_DATA_REPRESENTATION_ROWS", "0x2001", "0x115D" };
98 inline constexpr PHTDescription::Attribute LEVEL_COLUMNS = { "PIIM_PIXEL_DATA_REPRESENTATION_COLUMNS", "0x2001", "0x115E" };
99 inline constexpr PHTDescription::Attribute LEVEL_POSITION = { "PIIM_DP_PIXEL_DATA_REPRESENTATION_POSITION", "0x101D", "0x100B" };
100
101 inline constexpr std::string_view SCANNED_IMAGE = "DPScannedImage";
102 inline constexpr std::string_view WSI = "WSI";
103 inline constexpr std::string_view PIXEL_DATA_REPRESENTATION = "PixelDataRepresentation";
104 inline constexpr std::string_view DP_UFS_IMPORT = "DPUfsImport";
105 }
106}
107
Definition: exceptions.hpp:15