Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/DicomStructureSet.cpp @ 1504:d8af188ab545
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Jun 2020 20:35:16 +0200 |
parents | 30deba7bc8e2 |
children |
comparison
equal
deleted
inserted
replaced
1503:553084468225 | 1504:d8af188ab545 |
---|---|
21 | 21 |
22 #include "DicomStructureSet.h" | 22 #include "DicomStructureSet.h" |
23 #include "DicomStructureSetUtils.h" | 23 #include "DicomStructureSetUtils.h" |
24 | 24 |
25 #include "../Toolbox/GeometryToolbox.h" | 25 #include "../Toolbox/GeometryToolbox.h" |
26 #include "OrthancDatasets/DicomDatasetReader.h" | |
26 | 27 |
27 #include <Logging.h> | 28 #include <Logging.h> |
28 #include <OrthancException.h> | 29 #include <OrthancException.h> |
29 #include <Toolbox.h> | 30 #include <Toolbox.h> |
30 #include <DicomDatasetReader.h> | |
31 | 31 |
32 #if defined(_MSC_VER) | 32 #if defined(_MSC_VER) |
33 # pragma warning(push) | 33 # pragma warning(push) |
34 # pragma warning(disable:4244) | 34 # pragma warning(disable:4244) |
35 #endif | 35 #endif |
129 | 129 |
130 #endif | 130 #endif |
131 | 131 |
132 namespace OrthancStone | 132 namespace OrthancStone |
133 { | 133 { |
134 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_GEOMETRIC_TYPE(0x3006, 0x0042); | 134 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_GEOMETRIC_TYPE(0x3006, 0x0042); |
135 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_IMAGE_SEQUENCE(0x3006, 0x0016); | 135 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_IMAGE_SEQUENCE(0x3006, 0x0016); |
136 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_SEQUENCE(0x3006, 0x0040); | 136 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_SEQUENCE(0x3006, 0x0040); |
137 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_DATA(0x3006, 0x0050); | 137 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_DATA(0x3006, 0x0050); |
138 static const OrthancPlugins::DicomTag DICOM_TAG_NUMBER_OF_CONTOUR_POINTS(0x3006, 0x0046); | 138 static const Orthanc::DicomTag DICOM_TAG_NUMBER_OF_CONTOUR_POINTS(0x3006, 0x0046); |
139 static const OrthancPlugins::DicomTag DICOM_TAG_REFERENCED_SOP_INSTANCE_UID(0x0008, 0x1155); | 139 static const Orthanc::DicomTag DICOM_TAG_REFERENCED_SOP_INSTANCE_UID(0x0008, 0x1155); |
140 static const OrthancPlugins::DicomTag DICOM_TAG_ROI_CONTOUR_SEQUENCE(0x3006, 0x0039); | 140 static const Orthanc::DicomTag DICOM_TAG_ROI_CONTOUR_SEQUENCE(0x3006, 0x0039); |
141 static const OrthancPlugins::DicomTag DICOM_TAG_ROI_DISPLAY_COLOR(0x3006, 0x002a); | 141 static const Orthanc::DicomTag DICOM_TAG_ROI_DISPLAY_COLOR(0x3006, 0x002a); |
142 static const OrthancPlugins::DicomTag DICOM_TAG_ROI_NAME(0x3006, 0x0026); | 142 static const Orthanc::DicomTag DICOM_TAG_ROI_NAME(0x3006, 0x0026); |
143 static const OrthancPlugins::DicomTag DICOM_TAG_RT_ROI_INTERPRETED_TYPE(0x3006, 0x00a4); | 143 static const Orthanc::DicomTag DICOM_TAG_RT_ROI_INTERPRETED_TYPE(0x3006, 0x00a4); |
144 static const OrthancPlugins::DicomTag DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE(0x3006, 0x0080); | 144 static const Orthanc::DicomTag DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE(0x3006, 0x0080); |
145 static const OrthancPlugins::DicomTag DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE(0x3006, 0x0020); | 145 static const Orthanc::DicomTag DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE(0x3006, 0x0020); |
146 | 146 |
147 | 147 |
148 static uint8_t ConvertColor(double v) | 148 static uint8_t ConvertColor(double v) |
149 { | 149 { |
150 if (v < 0) | 150 if (v < 0) |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 static bool ParseVector(Vector& target, | 165 static bool ParseVector(Vector& target, |
166 const OrthancPlugins::IDicomDataset& dataset, | 166 const IDicomDataset& dataset, |
167 const OrthancPlugins::DicomPath& tag) | 167 const DicomPath& tag) |
168 { | 168 { |
169 std::string value; | 169 std::string value; |
170 return (dataset.GetStringValue(value, tag) && | 170 return (dataset.GetStringValue(value, tag) && |
171 LinearAlgebra::ParseVector(target, value)); | 171 LinearAlgebra::ParseVector(target, value)); |
172 } | 172 } |
463 } | 463 } |
464 | 464 |
465 return structures_[index]; | 465 return structures_[index]; |
466 } | 466 } |
467 | 467 |
468 void DicomStructureSet::Setup(const OrthancPlugins::IDicomDataset& tags) | 468 void DicomStructureSet::Setup(const IDicomDataset& tags) |
469 { | 469 { |
470 OrthancPlugins::DicomDatasetReader reader(tags); | 470 DicomDatasetReader reader(tags); |
471 | 471 |
472 size_t count, tmp; | 472 size_t count, tmp; |
473 if (!tags.GetSequenceSize(count, DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE) || | 473 if (!tags.GetSequenceSize(count, DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE) || |
474 !tags.GetSequenceSize(tmp, DICOM_TAG_ROI_CONTOUR_SEQUENCE) || | 474 !tags.GetSequenceSize(tmp, DICOM_TAG_ROI_CONTOUR_SEQUENCE) || |
475 tmp != count || | 475 tmp != count || |
481 | 481 |
482 structures_.resize(count); | 482 structures_.resize(count); |
483 for (size_t i = 0; i < count; i++) | 483 for (size_t i = 0; i < count; i++) |
484 { | 484 { |
485 structures_[i].interpretation_ = reader.GetStringValue | 485 structures_[i].interpretation_ = reader.GetStringValue |
486 (OrthancPlugins::DicomPath(DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE, i, | 486 (DicomPath(DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE, i, |
487 DICOM_TAG_RT_ROI_INTERPRETED_TYPE), | 487 DICOM_TAG_RT_ROI_INTERPRETED_TYPE), |
488 "No interpretation"); | 488 "No interpretation"); |
489 | 489 |
490 structures_[i].name_ = reader.GetStringValue | 490 structures_[i].name_ = reader.GetStringValue |
491 (OrthancPlugins::DicomPath(DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE, i, | 491 (DicomPath(DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE, i, |
492 DICOM_TAG_ROI_NAME), | 492 DICOM_TAG_ROI_NAME), |
493 "No name"); | 493 "No name"); |
494 | 494 |
495 Vector color; | 495 Vector color; |
496 if (ParseVector(color, tags, OrthancPlugins::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, | 496 if (ParseVector(color, tags, DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
497 DICOM_TAG_ROI_DISPLAY_COLOR)) && | 497 DICOM_TAG_ROI_DISPLAY_COLOR)) && |
498 color.size() == 3) | 498 color.size() == 3) |
499 { | 499 { |
500 structures_[i].red_ = ConvertColor(color[0]); | 500 structures_[i].red_ = ConvertColor(color[0]); |
501 structures_[i].green_ = ConvertColor(color[1]); | 501 structures_[i].green_ = ConvertColor(color[1]); |
502 structures_[i].blue_ = ConvertColor(color[2]); | 502 structures_[i].blue_ = ConvertColor(color[2]); |
507 structures_[i].green_ = 0; | 507 structures_[i].green_ = 0; |
508 structures_[i].blue_ = 0; | 508 structures_[i].blue_ = 0; |
509 } | 509 } |
510 | 510 |
511 size_t countSlices; | 511 size_t countSlices; |
512 if (!tags.GetSequenceSize(countSlices, OrthancPlugins::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, | 512 if (!tags.GetSequenceSize(countSlices, DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
513 DICOM_TAG_CONTOUR_SEQUENCE))) | 513 DICOM_TAG_CONTOUR_SEQUENCE))) |
514 { | 514 { |
515 countSlices = 0; | 515 countSlices = 0; |
516 } | 516 } |
517 | 517 |
518 LOG(INFO) << "New RT structure: \"" << structures_[i].name_ | 518 LOG(INFO) << "New RT structure: \"" << structures_[i].name_ |
521 << static_cast<int>(structures_[i].red_) << "," | 521 << static_cast<int>(structures_[i].red_) << "," |
522 << static_cast<int>(structures_[i].green_) << "," | 522 << static_cast<int>(structures_[i].green_) << "," |
523 << static_cast<int>(structures_[i].blue_) << ")"; | 523 << static_cast<int>(structures_[i].blue_) << ")"; |
524 | 524 |
525 // These temporary variables avoid allocating many vectors in the loop below | 525 // These temporary variables avoid allocating many vectors in the loop below |
526 OrthancPlugins::DicomPath countPointsPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, | 526 DicomPath countPointsPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
527 DICOM_TAG_CONTOUR_SEQUENCE, 0, | 527 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
528 DICOM_TAG_NUMBER_OF_CONTOUR_POINTS); | 528 DICOM_TAG_NUMBER_OF_CONTOUR_POINTS); |
529 | 529 |
530 OrthancPlugins::DicomPath geometricTypePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, | 530 DicomPath geometricTypePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
531 DICOM_TAG_CONTOUR_SEQUENCE, 0, | 531 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
532 DICOM_TAG_CONTOUR_GEOMETRIC_TYPE); | 532 DICOM_TAG_CONTOUR_GEOMETRIC_TYPE); |
533 | 533 |
534 OrthancPlugins::DicomPath imageSequencePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, | 534 DicomPath imageSequencePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
535 DICOM_TAG_CONTOUR_SEQUENCE, 0, | 535 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
536 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE); | 536 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE); |
537 | 537 |
538 // (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155) | 538 // (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155) |
539 OrthancPlugins::DicomPath referencedInstancePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, | 539 DicomPath referencedInstancePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
540 DICOM_TAG_CONTOUR_SEQUENCE, 0, | 540 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
541 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE, 0, | 541 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE, 0, |
542 DICOM_TAG_REFERENCED_SOP_INSTANCE_UID); | 542 DICOM_TAG_REFERENCED_SOP_INSTANCE_UID); |
543 | 543 |
544 OrthancPlugins::DicomPath contourDataPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, | 544 DicomPath contourDataPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
545 DICOM_TAG_CONTOUR_SEQUENCE, 0, | 545 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
546 DICOM_TAG_CONTOUR_DATA); | 546 DICOM_TAG_CONTOUR_DATA); |
547 | 547 |
548 for (size_t j = 0; j < countSlices; j++) | 548 for (size_t j = 0; j < countSlices; j++) |
549 { | 549 { |
550 unsigned int countPoints; | 550 unsigned int countPoints; |
551 | 551 |