1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
|
/************************************************************************
*
* Copyright (C) 2024 IRCAD France
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
// cspell:ignore asmt bdus ctprotocol ivoct ivus optbsv optenf rtdose rtimage rtintent rtrad rtrecord rtsegann rtstruct
// cspell:ignore rtplan texturemap xaprotocol
#pragma once
#include <sight/data/config.hpp>
#include <cstdint>
#include <optional>
#include <stdexcept>
#include <string_view>
namespace sight::data::dicom
{
/// Enum that defines modalities
enum class modality_t : std::uint8_t
{
unknown = 0,
ann,
ar,
asmt,
au,
bdus,
bi,
bmd,
cfm,
cr,
ct,
ctprotocol,
dms,
dg,
doc,
dx,
ecg,
eeg,
emg,
eog,
eps,
es,
fid,
gm,
hc,
hd,
io,
iol,
ivoct,
ivus,
ker,
ko,
len,
ls,
mg,
mr,
m3d,
nm,
oam,
oct,
op,
opm,
opt,
optbsv,
optenf,
opv,
oss,
ot,
pa,
plan,
pos,
pr,
pt,
px,
reg,
resp,
rf,
rg,
rtdose,
rtimage,
rtintent,
rtplan,
rtrad,
rtrecord,
rtsegann,
rtstruct,
rwv,
seg,
sm,
smr,
sr,
srf,
stain,
texturemap,
tg,
us,
va,
xa,
xaprotocol,
xc
};
/// Convenience function to convert from modality_t enum value to string
/// @param[in] _modality the modality_t enum value to convert
static constexpr std::optional<std::string_view> to_string(modality_t _modality)
{
/// @see @link https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.3.html#sect_C.7.3.1.1.1
switch(_modality)
{
case modality_t::ann:
return "ANN";
case modality_t::ar:
return "AR";
case modality_t::asmt:
return "ASMT";
case modality_t::au:
return "AU";
case modality_t::bdus:
return "BDUS";
case modality_t::bi:
return "BI";
case modality_t::bmd:
return "BMD";
case modality_t::cfm:
return "CFM";
case modality_t::cr:
return "CR";
case modality_t::ct:
return "CT";
case modality_t::ctprotocol:
return "CTPROTOCOL";
case modality_t::dms:
return "DMS";
case modality_t::dg:
return "DG";
case modality_t::doc:
return "DOC";
case modality_t::dx:
return "DX";
case modality_t::ecg:
return "ECG";
case modality_t::eeg:
return "EEG";
case modality_t::emg:
return "EMG";
case modality_t::eog:
return "EOG";
case modality_t::eps:
return "EPS";
case modality_t::es:
return "ES";
case modality_t::fid:
return "FID";
case modality_t::gm:
return "GM";
case modality_t::hc:
return "HC";
case modality_t::hd:
return "HD";
case modality_t::io:
return "IO";
case modality_t::iol:
return "IOL";
case modality_t::ivoct:
return "IVOCT";
case modality_t::ivus:
return "IVUS";
case modality_t::ker:
return "KER";
case modality_t::ko:
return "KO";
case modality_t::len:
return "LEN";
case modality_t::ls:
return "LS";
case modality_t::mg:
return "MG";
case modality_t::mr:
return "MR";
case modality_t::m3d:
return "M3D";
case modality_t::nm:
return "NM";
case modality_t::oam:
return "OAM";
case modality_t::oct:
return "OCT";
case modality_t::op:
return "OP";
case modality_t::opm:
return "OPM";
case modality_t::opt:
return "OPT";
case modality_t::optbsv:
return "OPTBSV";
case modality_t::optenf:
return "OPTENF";
case modality_t::opv:
return "OPV";
case modality_t::oss:
return "OSS";
case modality_t::ot:
return "OT";
case modality_t::pa:
return "PA";
case modality_t::plan:
return "PLAN";
case modality_t::pos:
return "POS";
case modality_t::pr:
return "PR";
case modality_t::pt:
return "PT";
case modality_t::px:
return "PX";
case modality_t::reg:
return "REG";
case modality_t::resp:
return "RESP";
case modality_t::rf:
return "RF";
case modality_t::rg:
return "RG";
case modality_t::rtdose:
return "RTDOSE";
case modality_t::rtimage:
return "RTIMAGE";
case modality_t::rtintent:
return "RTINTENT";
case modality_t::rtplan:
return "RTPLAN";
case modality_t::rtrad:
return "RTRAD";
case modality_t::rtrecord:
return "RTRECORD";
case modality_t::rtsegann:
return "RTSEGANN";
case modality_t::rtstruct:
return "RTSTRUCT";
case modality_t::rwv:
return "RWV";
case modality_t::seg:
return "SEG";
case modality_t::sm:
return "SM";
case modality_t::smr:
return "SMR";
case modality_t::sr:
return "SR";
case modality_t::srf:
return "SRF";
case modality_t::stain:
return "STAIN";
case modality_t::texturemap:
return "TEXTUREMAP";
case modality_t::tg:
return "TG";
case modality_t::us:
return "US";
case modality_t::va:
return "VA";
case modality_t::xa:
return "XA";
case modality_t::xaprotocol:
return "XAPROTOCOL";
case modality_t::xc:
return "XC";
case modality_t::unknown:
return std::nullopt;
default:
throw std::invalid_argument("Invalid modality");
}
}
SIGHT_DATA_API modality_t to_modality(const std::string_view& _modality) noexcept;
enum class ultrasound_acquisition_geometry_t : std::uint8_t
{
unknown = 0,
apex,
patient
};
//------------------------------------------------------------------------------
static constexpr std::optional<std::string_view> to_string(
ultrasound_acquisition_geometry_t _ultrasound_acquisition_geometry
)
{
// APEX: there exists an apex of the scan lines from which the volume data was acquired.
// PATIENT: the ultrasound acquisition geometry is patient relative
switch(_ultrasound_acquisition_geometry)
{
case ultrasound_acquisition_geometry_t::apex:
return "APEX";
case ultrasound_acquisition_geometry_t::patient:
return "PATIENT";
case ultrasound_acquisition_geometry_t::unknown:
return std::nullopt;
default:
throw std::invalid_argument("Invalid ultrasound acquisition geometry");
}
}
//------------------------------------------------------------------------------
static constexpr ultrasound_acquisition_geometry_t to_ultrasound_acquisition_geometry(
const std::string_view& _ultrasound_acquisition_geometry
) noexcept
{
// APEX: there exists an apex of the scan lines from which the volume data was acquired.
// PATIENT: the ultrasound acquisition geometry is patient relative
if(constexpr auto apex = to_string(ultrasound_acquisition_geometry_t::apex);
_ultrasound_acquisition_geometry == apex)
{
return ultrasound_acquisition_geometry_t::apex;
}
if(constexpr auto patient = to_string(ultrasound_acquisition_geometry_t::patient);
_ultrasound_acquisition_geometry == patient)
{
return ultrasound_acquisition_geometry_t::patient;
}
return ultrasound_acquisition_geometry_t::unknown;
}
enum class patient_frame_of_reference_source_t : std::uint8_t
{
unknown = 0,
table,
estimated,
registration
};
//------------------------------------------------------------------------------
static constexpr std::optional<std::string_view> to_string(
patient_frame_of_reference_source_t _patient_frame_of_reference_source
)
{
// TABLE: A positioning device, such as a gantry, was used to generate these values.
// ESTIMATED: Estimated patient position / orientation (e.g., estimated by the user), or if reliable
// information is not available.
// REGISTRATION: Acquisition has been spatially registered to a prior image set.
switch(_patient_frame_of_reference_source)
{
case patient_frame_of_reference_source_t::table:
return "TABLE";
case patient_frame_of_reference_source_t::estimated:
return "ESTIMATED";
case patient_frame_of_reference_source_t::registration:
return "REGISTRATION";
case patient_frame_of_reference_source_t::unknown:
return std::nullopt;
default:
throw std::invalid_argument("Invalid patient frame of reference source");
}
}
//------------------------------------------------------------------------------
static constexpr patient_frame_of_reference_source_t to_patient_frame_of_reference_source(
const std::string_view& _patient_frame_of_reference_source
) noexcept
{
// TABLE: A positioning device, such as a gantry, was used to generate these values.
// ESTIMATED: Estimated patient position / orientation (e.g., estimated by the user), or if reliable
// information is not available.
// REGISTRATION: Acquisition has been spatially registered to a prior image set.
if(constexpr auto table = to_string(patient_frame_of_reference_source_t::table);
_patient_frame_of_reference_source == table)
{
return patient_frame_of_reference_source_t::table;
}
if(constexpr auto estimated = to_string(patient_frame_of_reference_source_t::estimated);
_patient_frame_of_reference_source == estimated)
{
return patient_frame_of_reference_source_t::estimated;
}
if(constexpr auto registration = to_string(patient_frame_of_reference_source_t::registration);
_patient_frame_of_reference_source == registration)
{
return patient_frame_of_reference_source_t::registration;
}
return patient_frame_of_reference_source_t::unknown;
}
/// Enum that defines the kind of multi-frame dimension we are
enum class dimension_organization_t : std::uint8_t
{
unknown = 0,
volume, // "3D in DICOM",
volume_temporal, // "3D_TEMPORAL in DICOM",
tiled_full,
tiled_sparse
};
//------------------------------------------------------------------------------
static constexpr std::optional<std::string_view> to_string(
dimension_organization_t _dimension_organization_type
)
{
// 3D: Spatial Multi-frame image of equally spaced parallel planes (3D volume set)
// 3D_TEMPORAL: Temporal loop of equally spaced parallel-plane 3D volume sets.
// TILED_FULL: Tiled image in which each frame represents a single tile and the positions of the tiles are
// implicitly defined as per Section C.7.6.17.3.
// TILED_SPARSE: Tiled image in which each frame represents a single tile and the positions of tiles are
// explicitly defined by per-frame Functional Group Macro entries.
switch(_dimension_organization_type)
{
case dimension_organization_t::volume:
return "3D";
case dimension_organization_t::volume_temporal:
return "3D_TEMPORAL";
case dimension_organization_t::tiled_full:
return "TILED_FULL";
case dimension_organization_t::tiled_sparse:
return "TILED_SPARSE";
case dimension_organization_t::unknown:
return std::nullopt;
default:
throw std::invalid_argument("Invalid dimension organization type");
}
}
//------------------------------------------------------------------------------
static constexpr dimension_organization_t to_dimension_organization_type(
const std::string_view& _dimension_organization_type
) noexcept
{
// 3D: Spatial Multi-frame image of equally spaced parallel planes (3D volume set)
// 3D_TEMPORAL: Temporal loop of equally spaced parallel-plane 3D volume sets.
// TILED_FULL: Tiled image in which each frame represents a single tile and the positions of the tiles are
// implicitly defined as per Section C.7.6.17.3.
// TILED_SPARSE: Tiled image in which each frame represents a single tile and the positions of tiles are
// explicitly defined by per-frame Functional Group Macro entries.
if(constexpr auto volume = to_string(dimension_organization_t::volume);
_dimension_organization_type == volume)
{
return dimension_organization_t::volume;
}
if(constexpr auto volume_temporal = to_string(dimension_organization_t::volume_temporal);
_dimension_organization_type == volume_temporal)
{
return dimension_organization_t::volume_temporal;
}
if(constexpr auto tiled_full = to_string(dimension_organization_t::tiled_full);
_dimension_organization_type == tiled_full)
{
return dimension_organization_t::volume_temporal;
}
if(constexpr auto tiled_sparse = to_string(dimension_organization_t::tiled_sparse);
_dimension_organization_type == tiled_sparse)
{
return dimension_organization_t::tiled_sparse;
}
return dimension_organization_t::unknown;
}
/// Enum that defines the relationship between the volume and the transducer
enum class volume_to_transducer_relationship_t : std::uint8_t
{
unknown = 0,
fixed,
position_var,
orientation_var,
variable
};
//------------------------------------------------------------------------------
static constexpr std::optional<std::string_view> to_string(
volume_to_transducer_relationship_t _volume_to_transducer_relationship
)
{
// FIXED: The transducer position and orientation relative to the volume is constant and specified by Volume to
// Transducer Mapping Matrix (0020,9309).
// POSITION_VAR: The transducer position relative to the volume varies during acquisition and the position specified
// by Volume to Transducer Mapping Matrix (0020,9309) is a nominal value. The transducer orientation
// relative to the volume is constant and specified by Volume to Transducer Mapping Matrix
// (0020,9309).
// ORIENTATION_VAR: The transducer orientation relative to the volume varies during acquisition and the orientation
// specified by Volume to Transducer Mapping Matrix (0020,9309) is a nominal value. The transducer
// position relative to the volume is constant and specified by Volume to Transducer Mapping Matrix
// (0020,9309).
// VARIABLE: The transducer position and orientation relative to the volume varies during acquisition and the
// position and orientation specified by Volume to Transducer Mapping Matrix (0020,9309) are nominal.
switch(_volume_to_transducer_relationship)
{
case volume_to_transducer_relationship_t::fixed:
return "FIXED";
case volume_to_transducer_relationship_t::position_var:
return "POSITION_VAR";
case volume_to_transducer_relationship_t::orientation_var:
return "ORIENTATION_VAR";
case volume_to_transducer_relationship_t::variable:
return "VARIABLE";
case volume_to_transducer_relationship_t::unknown:
return std::nullopt;
default:
throw std::invalid_argument("Invalid volume to transducer relationship");
}
}
//------------------------------------------------------------------------------
static constexpr volume_to_transducer_relationship_t to_volume_to_transducer_relationship(
const std::string_view& _volume_to_transducer_relationship
) noexcept
{
// FIXED: The transducer position and orientation relative to the volume is constant and specified by Volume to
// Transducer Mapping Matrix (0020,9309).
// POSITION_VAR: The transducer position relative to the volume varies during acquisition and the position specified
// by Volume to Transducer Mapping Matrix (0020,9309) is a nominal value. The transducer orientation
// relative to the volume is constant and specified by Volume to Transducer Mapping Matrix
// (0020,9309).
// ORIENTATION_VAR: The transducer orientation relative to the volume varies during acquisition and the orientation
// specified by Volume to Transducer Mapping Matrix (0020,9309) is a nominal value. The transducer
// position relative to the volume is constant and specified by Volume to Transducer Mapping Matrix
// (0020,9309).
// VARIABLE: The transducer position and orientation relative to the volume varies during acquisition and the
// position and orientation specified by Volume to Transducer Mapping Matrix (0020,9309) are nominal.
if(constexpr auto fixed = to_string(volume_to_transducer_relationship_t::fixed);
_volume_to_transducer_relationship == fixed)
{
return volume_to_transducer_relationship_t::fixed;
}
if(constexpr auto position_var = to_string(volume_to_transducer_relationship_t::position_var);
_volume_to_transducer_relationship == position_var)
{
return volume_to_transducer_relationship_t::position_var;
}
if(constexpr auto orientation_var = to_string(volume_to_transducer_relationship_t::orientation_var);
_volume_to_transducer_relationship == orientation_var)
{
return volume_to_transducer_relationship_t::orientation_var;
}
if(constexpr auto variable = to_string(volume_to_transducer_relationship_t::variable);
_volume_to_transducer_relationship == variable)
{
return volume_to_transducer_relationship_t::variable;
}
return volume_to_transducer_relationship_t::unknown;
}
/// Enum that defines the position measuring device used
enum class position_measuring_device_used_t : std::uint8_t
{
unknown = 0,
rigid,
tracked,
freehand
};
//------------------------------------------------------------------------------
static constexpr std::optional<std::string_view> to_string(
position_measuring_device_used_t _position_measuring_device_used
)
{
// See: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.8.24.3.html#table_C.8.24.3-1
switch(_position_measuring_device_used)
{
case position_measuring_device_used_t::rigid:
return "RIGID";
case position_measuring_device_used_t::tracked:
return "TRACKED";
case position_measuring_device_used_t::freehand:
return "FREEHAND";
case position_measuring_device_used_t::unknown:
return std::nullopt;
default:
throw std::invalid_argument("Invalid dimension organization type");
}
}
//------------------------------------------------------------------------------
static constexpr std::optional<position_measuring_device_used_t> to_position_measuring_device_used(
const std::string_view& _position_measuring_device_used
) noexcept
{
// See: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.8.24.3.html#table_C.8.24.3-1
if(_position_measuring_device_used == to_string(position_measuring_device_used_t::rigid))
{
return position_measuring_device_used_t::rigid;
}
if(_position_measuring_device_used == to_string(position_measuring_device_used_t::tracked))
{
return position_measuring_device_used_t::tracked;
}
if(_position_measuring_device_used == to_string(position_measuring_device_used_t::freehand))
{
return position_measuring_device_used_t::freehand;
}
return std::nullopt;
}
/// Enum that defines the Pixel Data cc
enum class pixel_data_characteristics_t : std::uint8_t
{
unknown = 0,
original,
derived
};
//------------------------------------------------------------------------------
static constexpr std::optional<std::string_view> to_string(
pixel_data_characteristics_t _pixel_data_characteristics
)
{
// See: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.html
switch(_pixel_data_characteristics)
{
case pixel_data_characteristics_t::original:
return "ORIGINAL";
case pixel_data_characteristics_t::derived:
return "DERIVED";
case pixel_data_characteristics_t::unknown:
return std::nullopt;
default:
throw std::invalid_argument("Invalid pixel data characteristics");
}
}
//------------------------------------------------------------------------------
static constexpr std::optional<pixel_data_characteristics_t> to_pixel_data_characteristics(
const std::string_view& _pixel_data_characteristics
) noexcept
{
// See: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.html
if(_pixel_data_characteristics == to_string(pixel_data_characteristics_t::original))
{
return pixel_data_characteristics_t::original;
}
if(_pixel_data_characteristics == to_string(pixel_data_characteristics_t::derived))
{
return pixel_data_characteristics_t::derived;
}
return std::nullopt;
}
/// Enum that defines the Patient Examination Characteristics
enum class patient_examination_characteristics_t : std::uint8_t
{
unknown = 0,
primary,
secondary
};
//------------------------------------------------------------------------------
static constexpr std::optional<std::string_view> to_string(
patient_examination_characteristics_t _patient_examination_characteristics
)
{
// See: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.html
switch(_patient_examination_characteristics)
{
case patient_examination_characteristics_t::primary:
return "PRIMARY";
case patient_examination_characteristics_t::secondary:
return "SECONDARY";
case patient_examination_characteristics_t::unknown:
return std::nullopt;
default:
throw std::invalid_argument("Invalid patient examination characteristics");
}
}
//------------------------------------------------------------------------------
static constexpr std::optional<patient_examination_characteristics_t> to_patient_examination_characteristics(
const std::string_view& _patient_examination_characteristics
) noexcept
{
// See: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.html
if(_patient_examination_characteristics == to_string(patient_examination_characteristics_t::primary))
{
return patient_examination_characteristics_t::primary;
}
if(_patient_examination_characteristics == to_string(patient_examination_characteristics_t::secondary))
{
return patient_examination_characteristics_t::secondary;
}
return std::nullopt;
}
} // namespace sight::data::dicom
|