Mercurial > hg > orthanc-stone
comparison UnitTestsSources/UnitTestsMain.cpp @ 71:30c768873d47 wasm
OrthancSliceLoader::ScheduleLoadInstance
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 May 2017 10:27:18 +0200 |
parents | f73aed014bde |
children | c1cc3bdba18c |
comparison
equal
deleted
inserted
replaced
70:f73aed014bde | 71:30c768873d47 |
---|---|
88 | 88 |
89 GeometryToolbox::GetPixelSpacing(pixelSpacingX_, pixelSpacingY_, dataset); | 89 GeometryToolbox::GetPixelSpacing(pixelSpacingX_, pixelSpacingY_, dataset); |
90 | 90 |
91 std::string position, orientation; | 91 std::string position, orientation; |
92 if (dataset.GetStringValue(position, OrthancPlugins::DICOM_TAG_IMAGE_POSITION_PATIENT) && | 92 if (dataset.GetStringValue(position, OrthancPlugins::DICOM_TAG_IMAGE_POSITION_PATIENT) && |
93 dataset.GetStringValue(orientation, OrthancPlugins::DICOM_TAG_IMAGE_ORIENTATION_PATIENT) && | 93 dataset.GetStringValue(orientation, OrthancPlugins::DICOM_TAG_IMAGE_ORIENTATION_PATIENT)) |
94 reader.GetUnsignedIntegerValue(width_, OrthancPlugins::DICOM_TAG_COLUMNS) && | 94 { |
95 geometry_ = SliceGeometry(position, orientation); | |
96 } | |
97 | |
98 if (reader.GetUnsignedIntegerValue(width_, OrthancPlugins::DICOM_TAG_COLUMNS) && | |
95 reader.GetUnsignedIntegerValue(height_, OrthancPlugins::DICOM_TAG_ROWS)) | 99 reader.GetUnsignedIntegerValue(height_, OrthancPlugins::DICOM_TAG_ROWS)) |
96 { | 100 { |
97 orthancInstanceId_ = instanceId; | 101 orthancInstanceId_ = instanceId; |
98 frame_ = frame; | 102 frame_ = frame; |
99 geometry_ = SliceGeometry(position, orientation); | |
100 converter_.ReadParameters(dataset); | 103 converter_.ReadParameters(dataset); |
101 | 104 |
102 type_ = Type_OrthancInstance; | 105 type_ = Type_OrthancInstance; |
103 return true; | 106 return true; |
104 } | 107 } |
426 }; | 429 }; |
427 | 430 |
428 enum Mode | 431 enum Mode |
429 { | 432 { |
430 Mode_SeriesGeometry, | 433 Mode_SeriesGeometry, |
434 Mode_InstanceGeometry, | |
431 Mode_LoadImage | 435 Mode_LoadImage |
432 }; | 436 }; |
433 | 437 |
434 class Operation : public Orthanc::IDynamicObject | 438 class Operation : public Orthanc::IDynamicObject |
435 { | 439 { |
436 private: | 440 private: |
437 Mode mode_; | 441 Mode mode_; |
442 unsigned int frame_; | |
438 unsigned int sliceIndex_; | 443 unsigned int sliceIndex_; |
439 const Slice* slice_; | 444 const Slice* slice_; |
445 std::string instanceId_; | |
440 | 446 |
441 Operation(Mode mode) : | 447 Operation(Mode mode) : |
442 mode_(mode) | 448 mode_(mode) |
443 { | 449 { |
444 } | 450 } |
458 const Slice& GetSlice() const | 464 const Slice& GetSlice() const |
459 { | 465 { |
460 assert(mode_ == Mode_LoadImage && slice_ != NULL); | 466 assert(mode_ == Mode_LoadImage && slice_ != NULL); |
461 return *slice_; | 467 return *slice_; |
462 } | 468 } |
469 | |
470 unsigned int GetFrame() const | |
471 { | |
472 assert(mode_ == Mode_InstanceGeometry); | |
473 return frame_; | |
474 } | |
475 | |
476 const std::string& GetInstanceId() const | |
477 { | |
478 assert(mode_ == Mode_InstanceGeometry); | |
479 return instanceId_; | |
480 } | |
463 | 481 |
464 static Operation* DownloadSeriesGeometry() | 482 static Operation* DownloadSeriesGeometry() |
465 { | 483 { |
466 return new Operation(Mode_SeriesGeometry); | 484 return new Operation(Mode_SeriesGeometry); |
485 } | |
486 | |
487 static Operation* DownloadInstanceGeometry(const std::string& instanceId, | |
488 unsigned int frame) | |
489 { | |
490 std::auto_ptr<Operation> operation(new Operation(Mode_InstanceGeometry)); | |
491 operation->instanceId_ = instanceId; | |
492 operation->frame_ = frame; | |
493 return operation.release(); | |
467 } | 494 } |
468 | 495 |
469 static Operation* DownloadSliceImage(unsigned int sliceIndex, | 496 static Operation* DownloadSliceImage(unsigned int sliceIndex, |
470 const Slice& slice) | 497 const Slice& slice) |
471 { | 498 { |
534 callback_.NotifyGeometryReady(*this); | 561 callback_.NotifyGeometryReady(*this); |
535 } | 562 } |
536 else | 563 else |
537 { | 564 { |
538 LOG(ERROR) << "This series is empty"; | 565 LOG(ERROR) << "This series is empty"; |
566 callback_.NotifyGeometryError(*this); | |
567 } | |
568 } | |
569 | |
570 | |
571 void ParseInstanceGeometry(const std::string& instanceId, | |
572 unsigned int frame, | |
573 const void* answer, | |
574 size_t size) | |
575 { | |
576 Json::Value tags; | |
577 if (!MessagingToolbox::ParseJson(tags, answer, size) || | |
578 tags.type() != Json::objectValue) | |
579 { | |
580 callback_.NotifyGeometryError(*this); | |
581 return; | |
582 } | |
583 | |
584 OrthancPlugins::FullOrthancDataset dataset(tags); | |
585 | |
586 state_ = State_GeometryReady; | |
587 | |
588 Slice slice; | |
589 if (slice.ParseOrthancFrame(dataset, instanceId, frame)) | |
590 { | |
591 LOG(INFO) << "Loaded instance " << instanceId; | |
592 slices_.AddSlice(slice); | |
593 callback_.NotifyGeometryReady(*this); | |
594 } | |
595 else | |
596 { | |
597 LOG(WARNING) << "Skipping invalid instance " << instanceId; | |
539 callback_.NotifyGeometryError(*this); | 598 callback_.NotifyGeometryError(*this); |
540 } | 599 } |
541 } | 600 } |
542 | 601 |
543 | 602 |
599 std::string uri = "/series/" + seriesId + "/instances-tags"; | 658 std::string uri = "/series/" + seriesId + "/instances-tags"; |
600 orthanc_.ScheduleGetRequest(*this, uri, Operation::DownloadSeriesGeometry()); | 659 orthanc_.ScheduleGetRequest(*this, uri, Operation::DownloadSeriesGeometry()); |
601 } | 660 } |
602 } | 661 } |
603 | 662 |
663 void ScheduleLoadInstance(const std::string& instanceId, | |
664 unsigned int frame) | |
665 { | |
666 if (state_ != State_Initialization) | |
667 { | |
668 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
669 } | |
670 else | |
671 { | |
672 state_ = State_LoadingGeometry; | |
673 std::string uri = "/instances/" + instanceId + "/tags"; | |
674 orthanc_.ScheduleGetRequest | |
675 (*this, uri, Operation::DownloadInstanceGeometry(instanceId, frame)); | |
676 } | |
677 } | |
678 | |
604 size_t GetSliceCount() const | 679 size_t GetSliceCount() const |
605 { | 680 { |
606 if (state_ != State_GeometryReady) | 681 if (state_ != State_GeometryReady) |
607 { | 682 { |
608 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 683 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
665 | 740 |
666 switch (operation->GetMode()) | 741 switch (operation->GetMode()) |
667 { | 742 { |
668 case Mode_SeriesGeometry: | 743 case Mode_SeriesGeometry: |
669 ParseSeriesGeometry(answer, answerSize); | 744 ParseSeriesGeometry(answer, answerSize); |
745 break; | |
746 | |
747 case Mode_InstanceGeometry: | |
748 ParseInstanceGeometry(operation->GetInstanceId(), operation->GetFrame(), answer, answerSize); | |
670 break; | 749 break; |
671 | 750 |
672 case Mode_LoadImage: | 751 case Mode_LoadImage: |
673 ParseSliceImage(*operation, answer, answerSize); | 752 ParseSliceImage(*operation, answer, answerSize); |
674 break; | 753 break; |
746 orthanc.Start(); | 825 orthanc.Start(); |
747 | 826 |
748 OrthancStone::Tata tata; | 827 OrthancStone::Tata tata; |
749 OrthancStone::OrthancSliceLoader loader(tata, orthanc); | 828 OrthancStone::OrthancSliceLoader loader(tata, orthanc); |
750 //loader.ScheduleLoadSeries("c1c4cb95-05e3bd11-8da9f5bb-87278f71-0b2b43f5"); | 829 //loader.ScheduleLoadSeries("c1c4cb95-05e3bd11-8da9f5bb-87278f71-0b2b43f5"); |
751 loader.ScheduleLoadSeries("67f1b334-02c16752-45026e40-a5b60b6b-030ecab5"); | 830 //loader.ScheduleLoadSeries("67f1b334-02c16752-45026e40-a5b60b6b-030ecab5"); |
831 | |
832 loader.ScheduleLoadInstance("19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5", 0); | |
752 | 833 |
753 /*printf(">> %d\n", loader.GetSliceCount()); | 834 /*printf(">> %d\n", loader.GetSliceCount()); |
754 loader.ScheduleLoadSliceImage(31);*/ | 835 loader.ScheduleLoadSliceImage(31);*/ |
755 | 836 |
756 boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); | 837 boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); |