Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Toolbox/DicomStructuredReport.cpp @ 2089:63d77859edee dicom-sr
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 19:30:44 +0100 |
parents | 51c8b21b81e4 |
children | 35de56fb6f89 |
comparison
equal
deleted
inserted
replaced
2088:b98d159c7545 | 2089:63d77859edee |
---|---|
116 } | 116 } |
117 | 117 |
118 | 118 |
119 namespace OrthancStone | 119 namespace OrthancStone |
120 { | 120 { |
121 void DicomStructuredReport::ReferencedInstance::AddFrame(unsigned int frame) | |
122 { | |
123 if (frame == 0) | |
124 { | |
125 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
126 } | |
127 else | |
128 { | |
129 frames_.insert(frame); | |
130 } | |
131 } | |
132 | |
133 | |
121 class DicomStructuredReport::Structure : public boost::noncopyable | 134 class DicomStructuredReport::Structure : public boost::noncopyable |
122 { | 135 { |
123 private: | 136 private: |
124 std::string sopInstanceUid_; | 137 std::string sopInstanceUid_; |
125 bool hasFrameNumber_; | 138 bool hasFrameNumber_; |
367 std::string sopClassUid = GetStringValue(*referencedInstances->getItem(k), DCM_ReferencedSOPClassUID); | 380 std::string sopClassUid = GetStringValue(*referencedInstances->getItem(k), DCM_ReferencedSOPClassUID); |
368 std::string sopInstanceUid = GetStringValue(*referencedInstances->getItem(k), DCM_ReferencedSOPInstanceUID); | 381 std::string sopInstanceUid = GetStringValue(*referencedInstances->getItem(k), DCM_ReferencedSOPInstanceUID); |
369 | 382 |
370 if (instancesInformation_.find(sopInstanceUid) == instancesInformation_.end()) | 383 if (instancesInformation_.find(sopInstanceUid) == instancesInformation_.end()) |
371 { | 384 { |
372 instancesInformation_[sopInstanceUid] = ReferencedInstance(studyInstanceUid, seriesInstanceUid, sopClassUid); | 385 instancesInformation_[sopInstanceUid] = new ReferencedInstance(studyInstanceUid, seriesInstanceUid, sopClassUid); |
373 } | 386 } |
374 else | 387 else |
375 { | 388 { |
376 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, | 389 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
377 "Multiple occurrences of the same instance in DICOM-SR: " + sopInstanceUid); | 390 "Multiple occurrences of the same instance in DICOM-SR: " + sopInstanceUid); |
466 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, | 479 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
467 "Region cannot reference multiple instances in DICOM-SR"); | 480 "Region cannot reference multiple instances in DICOM-SR"); |
468 } | 481 } |
469 | 482 |
470 std::string sopInstanceUid = GetStringValue(*instances.getItem(0), DCM_ReferencedSOPInstanceUID); | 483 std::string sopInstanceUid = GetStringValue(*instances.getItem(0), DCM_ReferencedSOPInstanceUID); |
471 if (instancesInformation_.find(sopInstanceUid) == instancesInformation_.end()) | 484 std::map<std::string, ReferencedInstance*>::iterator instanceInformation = instancesInformation_.find(sopInstanceUid); |
485 | |
486 if (instanceInformation == instancesInformation_.end()) | |
472 { | 487 { |
473 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, | 488 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
474 "Referencing unknown instance in DICOM-SR: " + sopInstanceUid); | 489 "Referencing unknown instance in DICOM-SR: " + sopInstanceUid); |
475 } | 490 } |
491 | |
492 assert(instanceInformation->second != NULL); | |
476 | 493 |
477 if (instances.getItem(0)->tagExists(DCM_ReferencedFrameNumber)) | 494 if (instances.getItem(0)->tagExists(DCM_ReferencedFrameNumber)) |
478 { | 495 { |
479 std::string frames = GetStringValue(*instances.getItem(0), DCM_ReferencedFrameNumber); | 496 std::string frames = GetStringValue(*instances.getItem(0), DCM_ReferencedFrameNumber); |
480 std::vector<std::string> tokens; | 497 std::vector<std::string> tokens; |
488 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 505 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
489 } | 506 } |
490 else | 507 else |
491 { | 508 { |
492 AddStructure(sopInstanceUid, group, true, frame, hasProbabilityOfCancer, probabilityOfCancer); | 509 AddStructure(sopInstanceUid, group, true, frame, hasProbabilityOfCancer, probabilityOfCancer); |
510 instanceInformation->second->AddFrame(frame); | |
493 } | 511 } |
494 } | 512 } |
495 } | 513 } |
496 else | 514 else |
497 { | 515 { |
498 AddStructure(sopInstanceUid, group, false, 0, hasProbabilityOfCancer, probabilityOfCancer); | 516 AddStructure(sopInstanceUid, group, false, 0, hasProbabilityOfCancer, probabilityOfCancer); |
517 instanceInformation->second->AddFrame(1); | |
499 } | 518 } |
500 } | 519 } |
501 } | 520 } |
502 } | 521 } |
503 } | 522 } |
513 for (std::list<Structure*>::iterator it = structures_.begin(); it != structures_.end(); ++it) | 532 for (std::list<Structure*>::iterator it = structures_.begin(); it != structures_.end(); ++it) |
514 { | 533 { |
515 assert(*it != NULL); | 534 assert(*it != NULL); |
516 delete *it; | 535 delete *it; |
517 } | 536 } |
518 } | 537 |
519 } | 538 for (std::map<std::string, ReferencedInstance*>::iterator |
539 it = instancesInformation_.begin(); it != instancesInformation_.end(); ++it) | |
540 { | |
541 assert(it->second != NULL); | |
542 delete it->second; | |
543 } | |
544 } | |
545 | |
546 | |
547 void DicomStructuredReport::GetReferencedInstance(std::string& studyInstanceUid, | |
548 std::string& seriesInstanceUid, | |
549 std::string& sopInstanceUid, | |
550 std::string& sopClassUid, | |
551 size_t i) const | |
552 { | |
553 if (i >= orderedInstances_.size()) | |
554 { | |
555 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
556 } | |
557 | |
558 sopInstanceUid = orderedInstances_[i]; | |
559 | |
560 std::map<std::string, ReferencedInstance*>::const_iterator found = instancesInformation_.find(sopInstanceUid); | |
561 if (found == instancesInformation_.end()) | |
562 { | |
563 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
564 } | |
565 | |
566 assert(found->second != NULL); | |
567 studyInstanceUid = found->second->GetStudyInstanceUid(); | |
568 seriesInstanceUid = found->second->GetSeriesInstanceUid(); | |
569 sopClassUid = found->second->GetSopClassUid(); | |
570 } | |
571 | |
572 | |
573 void DicomStructuredReport::ExportOrderedFrames(std::list<Frame>& frames) const | |
574 { | |
575 frames.clear(); | |
576 | |
577 for (size_t i = 0; i < orderedInstances_.size(); i++) | |
578 { | |
579 std::map<std::string, ReferencedInstance*>::const_iterator found = instancesInformation_.find(orderedInstances_[i]); | |
580 if (found == instancesInformation_.end()) | |
581 { | |
582 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
583 } | |
584 | |
585 assert(found->second != NULL); | |
586 | |
587 for (std::set<unsigned int>::const_iterator frame = found->second->GetFrames().begin(); | |
588 frame != found->second->GetFrames().end(); ++frame) | |
589 { | |
590 frames.push_back(Frame(found->second->GetStudyInstanceUid(), | |
591 found->second->GetSeriesInstanceUid(), | |
592 orderedInstances_[i], | |
593 found->second->GetSopClassUid(), *frame)); | |
594 } | |
595 } | |
596 } | |
597 } |