Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyScene.cpp @ 1336:379c00958553 broker
integration mainline->broker
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 31 Mar 2020 15:51:02 +0200 |
parents | 1f877e0846fe a72c2c9af49a |
children | 6ea4062c1a0d |
comparison
equal
deleted
inserted
replaced
1334:04055b6b9e2c | 1336:379c00958553 |
---|---|
331 if (isCenterGeometry) | 331 if (isCenterGeometry) |
332 { | 332 { |
333 // modify geometry to reference the top left corner | 333 // modify geometry to reference the top left corner |
334 double tlx = centerGeometry->GetPanX(); | 334 double tlx = centerGeometry->GetPanX(); |
335 double tly = centerGeometry->GetPanY(); | 335 double tly = centerGeometry->GetPanY(); |
336 Extent2D textExtent = alpha->GetExtent(); | 336 Extent2D textExtent = alpha->GetSceneExtent(false); |
337 tlx = tlx - (textExtent.GetWidth() / 2) * centerGeometry->GetPixelSpacingX(); | 337 tlx = tlx - (textExtent.GetWidth() / 2) * centerGeometry->GetPixelSpacingX(); |
338 tly = tly - (textExtent.GetHeight() / 2) * centerGeometry->GetPixelSpacingY(); | 338 tly = tly - (textExtent.GetHeight() / 2) * centerGeometry->GetPixelSpacingY(); |
339 centerGeometry->SetPan(tlx, tly); | 339 centerGeometry->SetPan(tlx, tly); |
340 } | 340 } |
341 alpha->SetGeometry(*centerGeometry); | 341 alpha->SetGeometry(*centerGeometry); |
540 BroadcastMessage(ContentChangedMessage(*this, *(layer->second))); | 540 BroadcastMessage(ContentChangedMessage(*this, *(layer->second))); |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 | 544 |
545 Extent2D RadiographyScene::GetSceneExtent() const | 545 Extent2D RadiographyScene::GetSceneExtent(bool minimal) const |
546 { | 546 { |
547 Extent2D extent; | 547 Extent2D extent; |
548 | 548 |
549 for (Layers::const_iterator it = layers_.begin(); | 549 for (Layers::const_iterator it = layers_.begin(); |
550 it != layers_.end(); ++it) | 550 it != layers_.end(); ++it) |
551 { | 551 { |
552 assert(it->second != NULL); | 552 assert(it->second != NULL); |
553 extent.Union(it->second->GetExtent()); | 553 extent.Union(it->second->GetSceneExtent(minimal)); |
554 } | 554 } |
555 | 555 |
556 return extent; | 556 return extent; |
557 } | 557 } |
558 | 558 |
660 } | 660 } |
661 | 661 |
662 void RadiographyScene::ExtractLayerFromRenderedScene(Orthanc::ImageAccessor& layer, | 662 void RadiographyScene::ExtractLayerFromRenderedScene(Orthanc::ImageAccessor& layer, |
663 const Orthanc::ImageAccessor& renderedScene, | 663 const Orthanc::ImageAccessor& renderedScene, |
664 size_t layerIndex, | 664 size_t layerIndex, |
665 bool isCropped, | |
665 ImageInterpolation interpolation) | 666 ImageInterpolation interpolation) |
666 { | 667 { |
667 Extent2D sceneExtent = GetSceneExtent(); | 668 Extent2D sceneExtent = GetSceneExtent(isCropped); |
668 | 669 |
669 double pixelSpacingX = sceneExtent.GetWidth() / renderedScene.GetWidth(); | 670 double pixelSpacingX = sceneExtent.GetWidth() / renderedScene.GetWidth(); |
670 double pixelSpacingY = sceneExtent.GetHeight() / renderedScene.GetHeight(); | 671 double pixelSpacingY = sceneExtent.GetHeight() / renderedScene.GetHeight(); |
671 | 672 |
672 AffineTransform2D view = AffineTransform2D::Combine( | 673 AffineTransform2D view = AffineTransform2D::Combine( |
684 Orthanc::Image* RadiographyScene::ExportToImage(double pixelSpacingX, | 685 Orthanc::Image* RadiographyScene::ExportToImage(double pixelSpacingX, |
685 double pixelSpacingY, | 686 double pixelSpacingY, |
686 ImageInterpolation interpolation, | 687 ImageInterpolation interpolation, |
687 bool invert, | 688 bool invert, |
688 int64_t maxValue /* for inversion */, | 689 int64_t maxValue /* for inversion */, |
690 bool autoCrop, | |
689 bool applyWindowing) | 691 bool applyWindowing) |
690 { | 692 { |
691 if (pixelSpacingX <= 0 || | 693 if (pixelSpacingX <= 0 || |
692 pixelSpacingY <= 0) | 694 pixelSpacingY <= 0) |
693 { | 695 { |
694 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 696 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
695 } | 697 } |
696 | 698 |
697 Extent2D extent = GetSceneExtent(); | 699 Extent2D extent = GetSceneExtent(autoCrop); |
698 | 700 |
699 int w = boost::math::iround(extent.GetWidth() / pixelSpacingX); | 701 int w = boost::math::iround(extent.GetWidth() / pixelSpacingX); |
700 int h = boost::math::iround(extent.GetHeight() / pixelSpacingY); | 702 int h = boost::math::iround(extent.GetHeight() / pixelSpacingY); |
701 | 703 |
702 if (w < 0 || h < 0) | 704 if (w < 0 || h < 0) |
739 const Json::Value& dicomTags, | 741 const Json::Value& dicomTags, |
740 const std::string& parentOrthancId, | 742 const std::string& parentOrthancId, |
741 double pixelSpacingX, | 743 double pixelSpacingX, |
742 double pixelSpacingY, | 744 double pixelSpacingY, |
743 bool invert, | 745 bool invert, |
746 bool autoCrop, | |
744 ImageInterpolation interpolation) | 747 ImageInterpolation interpolation) |
745 { | 748 { |
746 LOG(INFO) << "Exporting RadiographyScene to DICOM"; | 749 LOG(INFO) << "Exporting RadiographyScene to DICOM"; |
747 | 750 |
748 std::unique_ptr<Orthanc::Image> rendered(ExportToImage(pixelSpacingX, pixelSpacingY, interpolation, false)); // note: we don't invert the image in the pixels data because we'll set the PhotometricDisplayMode correctly in the DICOM tags | 751 std::unique_ptr<Orthanc::Image> rendered(ExportToImage(pixelSpacingX, pixelSpacingY, interpolation, autoCrop, false)); // note: we don't invert the image in the pixels data because we'll set the PhotometricDisplayMode correctly in the DICOM tags |
749 | 752 |
750 createDicomRequestContent["Tags"] = dicomTags; | 753 createDicomRequestContent["Tags"] = dicomTags; |
751 | 754 |
752 RadiographyPhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); | 755 RadiographyPhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); |
753 if ((invert && photometricMode != RadiographyPhotometricDisplayMode_Monochrome2) || | 756 if ((invert && photometricMode != RadiographyPhotometricDisplayMode_Monochrome2) || |
792 const Json::Value& dicomTags, | 795 const Json::Value& dicomTags, |
793 const std::string& parentOrthancId, | 796 const std::string& parentOrthancId, |
794 double pixelSpacingX, | 797 double pixelSpacingX, |
795 double pixelSpacingY, | 798 double pixelSpacingY, |
796 bool invert, | 799 bool invert, |
800 bool autoCrop, | |
797 ImageInterpolation interpolation, | 801 ImageInterpolation interpolation, |
798 bool usePam) | 802 bool usePam) |
799 { | 803 { |
800 LOG(INFO) << "Exporting RadiographyScene to DICOM"; | 804 LOG(INFO) << "Exporting RadiographyScene to DICOM"; |
801 VLOG(1) << "Exporting RadiographyScene to: export to image"; | 805 VLOG(1) << "Exporting RadiographyScene to: export to image"; |
802 | 806 |
803 std::unique_ptr<Orthanc::Image> rendered(ExportToCreateDicomRequestAndImage(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation)); | 807 std::unique_ptr<Orthanc::Image> rendered(ExportToCreateDicomRequestAndImage(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, autoCrop, interpolation)); |
804 | 808 |
805 // convert the image into base64 for inclusing in the createDicomRequest | 809 // convert the image into base64 for inclusing in the createDicomRequest |
806 std::string base64; | 810 std::string base64; |
807 | 811 |
808 { | 812 { |
837 const Json::Value& dicomTags, | 841 const Json::Value& dicomTags, |
838 const std::string& parentOrthancId, | 842 const std::string& parentOrthancId, |
839 double pixelSpacingX, | 843 double pixelSpacingX, |
840 double pixelSpacingY, | 844 double pixelSpacingY, |
841 bool invert, | 845 bool invert, |
846 bool autoCrop, | |
842 ImageInterpolation interpolation, | 847 ImageInterpolation interpolation, |
843 bool usePam) | 848 bool usePam) |
844 { | 849 { |
845 Json::Value createDicomRequestContent; | 850 Json::Value createDicomRequestContent; |
846 | 851 |
847 ExportToCreateDicomRequest(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation, usePam); | 852 ExportToCreateDicomRequest(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, autoCrop, interpolation, usePam); |
848 | 853 |
849 orthanc.PostJsonAsyncExpectJson( | 854 orthanc.PostJsonAsyncExpectJson( |
850 "/tools/create-dicom", createDicomRequestContent, | 855 "/tools/create-dicom", createDicomRequestContent, |
851 new Deprecated::DeprecatedCallable<RadiographyScene, Deprecated::OrthancApiClient::JsonResponseReadyMessage> | 856 new Deprecated::DeprecatedCallable<RadiographyScene, Deprecated::OrthancApiClient::JsonResponseReadyMessage> |
852 (GetSharedObserver(), &RadiographyScene::OnDicomExported), | 857 (GetSharedObserver(), &RadiographyScene::OnDicomExported), |
861 const Orthanc::DicomMap& dicom, | 866 const Orthanc::DicomMap& dicom, |
862 const std::string& parentOrthancId, | 867 const std::string& parentOrthancId, |
863 double pixelSpacingX, | 868 double pixelSpacingX, |
864 double pixelSpacingY, | 869 double pixelSpacingY, |
865 bool invert, | 870 bool invert, |
871 bool autoCrop, | |
866 ImageInterpolation interpolation, | 872 ImageInterpolation interpolation, |
867 bool usePam) | 873 bool usePam) |
868 { | 874 { |
869 std::set<Orthanc::DicomTag> tags; | 875 std::set<Orthanc::DicomTag> tags; |
870 dicom.GetTags(tags); | 876 dicom.GetTags(tags); |
880 { | 886 { |
881 jsonTags[tag->Format()] = value.GetContent(); | 887 jsonTags[tag->Format()] = value.GetContent(); |
882 } | 888 } |
883 } | 889 } |
884 | 890 |
885 ExportDicom(orthanc, jsonTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation, usePam); | 891 ExportDicom(orthanc, jsonTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, autoCrop, interpolation, usePam); |
886 } | 892 } |
887 | 893 |
888 void RadiographyScene::OnDicomExported(const Deprecated::OrthancApiClient::JsonResponseReadyMessage& message) | 894 void RadiographyScene::OnDicomExported(const Deprecated::OrthancApiClient::JsonResponseReadyMessage& message) |
889 { | 895 { |
890 LOG(INFO) << "DICOM export was successful: " | 896 LOG(INFO) << "DICOM export was successful: " |