PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
xa_storage.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
11
12#include <algorithm>
13#include <array>
14#include <cmath>
15
17
18// =============================================================================
19// Transfer Syntaxes
20// =============================================================================
21
22std::vector<std::string> get_xa_transfer_syntaxes() {
23 return {
24 // Explicit VR Little Endian (preferred for interoperability)
25 "1.2.840.10008.1.2.1",
26 // Implicit VR Little Endian (universal baseline)
27 "1.2.840.10008.1.2",
28 // HTJ2K Lossless (high-throughput lossless for multi-frame)
29 "1.2.840.10008.1.2.4.201",
30 // JPEG Lossless (for diagnostic quality)
31 "1.2.840.10008.1.2.4.70",
32 // RLE Lossless (for multi-frame)
33 "1.2.840.10008.1.2.5"
34 };
35}
36
37// =============================================================================
38// Photometric Interpretation
39// =============================================================================
40
41std::string_view to_string(xa_photometric_interpretation interp) noexcept {
42 switch (interp) {
44 return "MONOCHROME1";
46 return "MONOCHROME2";
47 }
48 return "MONOCHROME2";
49}
50
52parse_xa_photometric_interpretation(std::string_view value) noexcept {
53 if (value == "MONOCHROME1") {
55 }
56 // Default to MONOCHROME2 for unknown or MONOCHROME2 values
58}
59
60bool is_valid_xa_photometric(std::string_view value) noexcept {
61 return value == "MONOCHROME1" || value == "MONOCHROME2";
62}
63
64// =============================================================================
65// SOP Class Information
66// =============================================================================
67
68namespace {
69
70// Static array of XA SOP class information
71constexpr std::array<xa_sop_class_info, 5> xa_sop_classes = {{
72 {
74 "XA Image Storage",
75 "Standard X-Ray Angiographic images (single/multi-frame)",
76 false, // not enhanced
77 false, // not 3D
78 true // supports multiframe
79 },
80 {
82 "Enhanced XA Image Storage",
83 "Enhanced X-Ray Angiographic IOD with extended attributes",
84 true, // enhanced
85 false, // not 3D
86 true // supports multiframe
87 },
88 {
90 "XRF Image Storage",
91 "X-Ray Radiofluoroscopic images for fluoroscopy procedures",
92 false, // not enhanced
93 false, // not 3D
94 true // supports multiframe
95 },
96 {
98 "X-Ray 3D Angiographic Image Storage",
99 "3D rotational angiography reconstructions",
100 true, // enhanced (by nature)
101 true, // 3D
102 true // supports multiframe
103 },
104 {
106 "X-Ray 3D Craniofacial Image Storage",
107 "3D craniofacial imaging (cone beam CT)",
108 true, // enhanced (by nature)
109 true, // 3D
110 true // supports multiframe
111 }
112}};
113
114} // namespace
115
116std::vector<std::string> get_xa_storage_sop_classes(bool include_3d) {
117 std::vector<std::string> result;
118 result.reserve(include_3d ? 5 : 3);
119
120 for (const auto& info : xa_sop_classes) {
121 if (!info.is_3d || include_3d) {
122 result.emplace_back(info.uid);
123 }
124 }
125
126 return result;
127}
128
129const xa_sop_class_info*
130get_xa_sop_class_info(std::string_view uid) noexcept {
131 auto it = std::find_if(
132 xa_sop_classes.begin(),
133 xa_sop_classes.end(),
134 [uid](const auto& info) { return info.uid == uid; }
135 );
136
137 if (it != xa_sop_classes.end()) {
138 return &(*it);
139 }
140 return nullptr;
141}
142
143bool is_xa_storage_sop_class(std::string_view uid) noexcept {
144 return get_xa_sop_class_info(uid) != nullptr;
145}
146
147bool is_xa_multiframe_sop_class(std::string_view uid) noexcept {
148 const auto* info = get_xa_sop_class_info(uid);
149 return info != nullptr && info->supports_multiframe;
150}
151
152bool is_enhanced_xa_sop_class(std::string_view uid) noexcept {
153 const auto* info = get_xa_sop_class_info(uid);
154 return info != nullptr && info->is_enhanced;
155}
156
157bool is_xa_3d_sop_class(std::string_view uid) noexcept {
158 const auto* info = get_xa_sop_class_info(uid);
159 return info != nullptr && info->is_3d;
160}
161
162// =============================================================================
163// Positioner Information
164// =============================================================================
165
166std::string_view to_string(xa_positioner_motion motion) noexcept {
167 switch (motion) {
169 return "STATIONARY";
171 return "DYNAMIC";
172 }
173 return "STATIONARY";
174}
175
176bool xa_positioner_angles::is_valid() const noexcept {
177 // Typical clinical range: primary angle -90 to +90 (LAO/RAO)
178 // Secondary angle: -45 to +45 (Cranial/Caudal)
179 return primary_angle >= -180.0 && primary_angle <= 180.0 &&
180 secondary_angle >= -90.0 && secondary_angle <= 90.0;
181}
182
183// =============================================================================
184// Calibration Information
185// =============================================================================
186
188 if (distance_source_to_patient <= 0.0 ||
190 return 0.0;
191 }
193}
194
196 double mag = magnification_factor();
197 if (mag <= 0.0 || imager_pixel_spacing[0] <= 0.0) {
198 return 0.0;
199 }
200 // Pixel spacing at isocenter = detector pixel spacing / magnification
201 return imager_pixel_spacing[0] / mag;
202}
203
211
212} // namespace kcenon::pacs::services::sop_classes
std::vector< std::string > get_xa_transfer_syntaxes()
Get recommended transfer syntaxes for XA images.
xa_photometric_interpretation
Supported photometric interpretations for XA/XRF images.
Definition xa_storage.h:99
@ monochrome1
Minimum pixel = white (traditional X-ray view)
constexpr std::string_view enhanced_xa_image_storage_uid
Enhanced XA Image Storage SOP Class UID (enhanced IOD)
Definition xa_storage.h:51
bool is_xa_multiframe_sop_class(std::string_view uid) noexcept
Check if a SOP Class UID is a multi-frame XA Storage SOP Class.
std::vector< std::string > get_xa_storage_sop_classes(bool include_3d=true)
Get all XA/XRF Storage SOP Class UIDs.
bool is_enhanced_xa_sop_class(std::string_view uid) noexcept
Check if a SOP Class UID is an enhanced XA SOP Class.
constexpr std::string_view xrf_image_storage_uid
XRF Image Storage SOP Class UID (X-Ray Radiofluoroscopic)
Definition xa_storage.h:55
bool is_valid_xa_photometric(std::string_view value) noexcept
Check if photometric interpretation is valid for XA.
constexpr std::string_view xray_3d_craniofacial_image_storage_uid
X-Ray 3D Craniofacial Image Storage SOP Class UID.
Definition xa_storage.h:68
constexpr std::string_view xray_3d_angiographic_image_storage_uid
X-Ray 3D Angiographic Image Storage SOP Class UID (3D rotational)
Definition xa_storage.h:64
const xa_sop_class_info * get_xa_sop_class_info(std::string_view uid) noexcept
Get information about a specific XA SOP Class.
bool is_xa_storage_sop_class(std::string_view uid) noexcept
Check if a SOP Class UID is an XA/XRF Storage SOP Class.
constexpr std::string_view xa_image_storage_uid
XA Image Storage SOP Class UID (single/multi-frame)
Definition xa_storage.h:47
xa_positioner_motion
Positioner motion type.
Definition xa_storage.h:204
@ dynamic
Positioner moves during acquisition (e.g., rotational)
xa_photometric_interpretation parse_xa_photometric_interpretation(std::string_view value) noexcept
Parse DICOM photometric interpretation string for XA.
bool is_xa_3d_sop_class(std::string_view uid) noexcept
Check if a SOP Class UID is a 3D XA SOP Class.
std::string_view to_string(dx_photometric_interpretation interp) noexcept
Convert photometric interpretation enum to DICOM string.
bool is_valid() const noexcept
Check if calibration data is valid for measurements.
double magnification_factor() const noexcept
Calculate magnification factor.
double imager_pixel_spacing[2]
Pixel spacing at detector (mm)
Definition xa_storage.h:280
double isocenter_pixel_spacing() const noexcept
Calculate pixel spacing at isocenter.
bool is_valid() const noexcept
Check if angles are within valid range.
double secondary_angle
Cranial/Caudal angle in degrees.
Definition xa_storage.h:224
std::string_view uid
X-Ray Angiographic (XA) Image Storage SOP Classes.