Mercurial > hg > orthanc-stone
changeset 1340:c7dbe89c82d7 broker
Merge
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 03 Apr 2020 16:55:11 +0200 |
parents | 556b4bc19118 (current diff) 379c00958553 (diff) |
children | d80a3e3cc800 |
files | |
diffstat | 9 files changed, 87 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/SingleFrameEditorApplication.h Fri Apr 03 16:47:46 2020 +0200 +++ b/Applications/Samples/SingleFrameEditorApplication.h Fri Apr 03 16:55:11 2020 +0200 @@ -347,7 +347,7 @@ { widget.GetScene().ExportDicom(*context_->GetOrthancApiClient(), tags, std::string(), 0.1, 0.1, widget.IsInverted(), - widget.GetInterpolation(), EXPORT_USING_PAM); + false /* autoCrop */, widget.GetInterpolation(), EXPORT_USING_PAM); } break;
--- a/Framework/Radiography/RadiographyDicomLayer.cpp Fri Apr 03 16:47:46 2020 +0200 +++ b/Framework/Radiography/RadiographyDicomLayer.cpp Fri Apr 03 16:55:11 2020 +0200 @@ -108,9 +108,9 @@ SetSize(image->GetWidth(), image->GetHeight()); #if __cplusplus < 201103L - source_.reset(raii.release()); + source_.reset(raii.release()); #else - source_ = std::move(raii); + source_ = std::move(raii); #endif ApplyConverter();
--- a/Framework/Radiography/RadiographyLayer.cpp Fri Apr 03 16:47:46 2020 +0200 +++ b/Framework/Radiography/RadiographyLayer.cpp Fri Apr 03 16:55:11 2020 +0200 @@ -237,8 +237,7 @@ } } - - Extent2D RadiographyLayer::GetExtent() const + Extent2D RadiographyLayer::GetSceneExtent(bool /*minimal*/) const { Extent2D extent; @@ -250,6 +249,7 @@ double dwidth = static_cast<double>(width); double dheight = static_cast<double>(height); + // AddToExtent transforms the coordinates from image to scene AddToExtent(extent, dx, dy); AddToExtent(extent, dx + dwidth, dy); AddToExtent(extent, dx, dy + dheight);
--- a/Framework/Radiography/RadiographyLayer.h Fri Apr 03 16:47:46 2020 +0200 +++ b/Framework/Radiography/RadiographyLayer.h Fri Apr 03 16:55:11 2020 +0200 @@ -21,6 +21,8 @@ #pragma once +#include <algorithm> + #include "../Toolbox/AffineTransform2D.h" #include "../Toolbox/Extent2D.h" #include "../Wrappers/CairoContext.h" @@ -273,11 +275,37 @@ void ResetCrop(); - void SetCrop(unsigned int x, + void SetCrop(unsigned int x, // those are pixel coordinates/size unsigned int y, unsigned int width, unsigned int height); + void SetCrop(const Extent2D& sceneExtent) + { + Extent2D imageCrop; + + { + double x = sceneExtent.GetX1(); + double y = sceneExtent.GetY1(); + GetTransformInverse().Apply(x, y); + imageCrop.AddPoint(x, y); + } + + { + double x = sceneExtent.GetX2(); + double y = sceneExtent.GetY2(); + GetTransformInverse().Apply(x, y); + imageCrop.AddPoint(x, y); + } + + SetCrop(static_cast<unsigned int>(std::max(0.0, std::floor(imageCrop.GetX1()))), + static_cast<unsigned int>(std::max(0.0, std::floor(imageCrop.GetY1()))), + std::min(width_, static_cast<unsigned int>(std::ceil(imageCrop.GetWidth()))), + std::min(height_, static_cast<unsigned int>(std::ceil(imageCrop.GetHeight()))) + ); + } + + void GetCrop(unsigned int& x, unsigned int& y, unsigned int& width, @@ -316,7 +344,7 @@ return height_; } - Extent2D GetExtent() const; + virtual Extent2D GetSceneExtent(bool minimal) const; virtual bool GetPixel(unsigned int& imageX, unsigned int& imageY,
--- a/Framework/Radiography/RadiographyMaskLayer.cpp Fri Apr 03 16:47:46 2020 +0200 +++ b/Framework/Radiography/RadiographyMaskLayer.cpp Fri Apr 03 16:55:11 2020 +0200 @@ -75,6 +75,31 @@ BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); } + Extent2D RadiographyMaskLayer::GetSceneExtent(bool minimal) const + { + if (!minimal) + { + return RadiographyLayer::GetSceneExtent(minimal); + } + else + { // get the extent of the in-mask area + Extent2D sceneExtent; + + for (std::vector<Orthanc::ImageProcessing::ImagePoint>::const_iterator + corner = corners_.begin(); corner != corners_.end(); ++corner) + { + double x = static_cast<double>(corner->GetX()); + double y = static_cast<double>(corner->GetY()); + + dicomLayer_.GetTransform().Apply(x, y); + sceneExtent.AddPoint(x, y); + } + return sceneExtent; + } + } + + + void RadiographyMaskLayer::Render(Orthanc::ImageAccessor& buffer, const AffineTransform2D& viewTransform, ImageInterpolation interpolation,
--- a/Framework/Radiography/RadiographyMaskLayer.h Fri Apr 03 16:47:46 2020 +0200 +++ b/Framework/Radiography/RadiographyMaskLayer.h Fri Apr 03 16:55:11 2020 +0200 @@ -100,6 +100,8 @@ cpScene = cp; } + virtual Extent2D GetSceneExtent(bool minimal) const; + virtual bool GetDefaultWindowing(float& center, float& width) const {
--- a/Framework/Radiography/RadiographyScene.cpp Fri Apr 03 16:47:46 2020 +0200 +++ b/Framework/Radiography/RadiographyScene.cpp Fri Apr 03 16:55:11 2020 +0200 @@ -333,7 +333,7 @@ // modify geometry to reference the top left corner double tlx = centerGeometry->GetPanX(); double tly = centerGeometry->GetPanY(); - Extent2D textExtent = alpha->GetExtent(); + Extent2D textExtent = alpha->GetSceneExtent(false); tlx = tlx - (textExtent.GetWidth() / 2) * centerGeometry->GetPixelSpacingX(); tly = tly - (textExtent.GetHeight() / 2) * centerGeometry->GetPixelSpacingY(); centerGeometry->SetPan(tlx, tly); @@ -542,7 +542,7 @@ } - Extent2D RadiographyScene::GetSceneExtent() const + Extent2D RadiographyScene::GetSceneExtent(bool minimal) const { Extent2D extent; @@ -550,7 +550,7 @@ it != layers_.end(); ++it) { assert(it->second != NULL); - extent.Union(it->second->GetExtent()); + extent.Union(it->second->GetSceneExtent(minimal)); } return extent; @@ -662,9 +662,10 @@ void RadiographyScene::ExtractLayerFromRenderedScene(Orthanc::ImageAccessor& layer, const Orthanc::ImageAccessor& renderedScene, size_t layerIndex, + bool isCropped, ImageInterpolation interpolation) { - Extent2D sceneExtent = GetSceneExtent(); + Extent2D sceneExtent = GetSceneExtent(isCropped); double pixelSpacingX = sceneExtent.GetWidth() / renderedScene.GetWidth(); double pixelSpacingY = sceneExtent.GetHeight() / renderedScene.GetHeight(); @@ -686,6 +687,7 @@ ImageInterpolation interpolation, bool invert, int64_t maxValue /* for inversion */, + bool autoCrop, bool applyWindowing) { if (pixelSpacingX <= 0 || @@ -694,7 +696,7 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } - Extent2D extent = GetSceneExtent(); + Extent2D extent = GetSceneExtent(autoCrop); int w = boost::math::iround(extent.GetWidth() / pixelSpacingX); int h = boost::math::iround(extent.GetHeight() / pixelSpacingY); @@ -741,11 +743,12 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation) { LOG(INFO) << "Exporting RadiographyScene to DICOM"; - 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 + 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 createDicomRequestContent["Tags"] = dicomTags; @@ -794,13 +797,14 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam) { LOG(INFO) << "Exporting RadiographyScene to DICOM"; VLOG(1) << "Exporting RadiographyScene to: export to image"; - std::unique_ptr<Orthanc::Image> rendered(ExportToCreateDicomRequestAndImage(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation)); + std::unique_ptr<Orthanc::Image> rendered(ExportToCreateDicomRequestAndImage(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, autoCrop, interpolation)); // convert the image into base64 for inclusing in the createDicomRequest std::string base64; @@ -839,12 +843,13 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam) { Json::Value createDicomRequestContent; - ExportToCreateDicomRequest(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation, usePam); + ExportToCreateDicomRequest(createDicomRequestContent, dicomTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, autoCrop, interpolation, usePam); orthanc.PostJsonAsyncExpectJson( "/tools/create-dicom", createDicomRequestContent, @@ -863,6 +868,7 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam) { @@ -882,7 +888,7 @@ } } - ExportDicom(orthanc, jsonTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, interpolation, usePam); + ExportDicom(orthanc, jsonTags, parentOrthancId, pixelSpacingX, pixelSpacingY, invert, autoCrop, interpolation, usePam); } void RadiographyScene::OnDicomExported(const Deprecated::OrthancApiClient::JsonResponseReadyMessage& message)
--- a/Framework/Radiography/RadiographyScene.h Fri Apr 03 16:47:46 2020 +0200 +++ b/Framework/Radiography/RadiographyScene.h Fri Apr 03 16:55:11 2020 +0200 @@ -281,7 +281,7 @@ void GetLayersIndexes(std::vector<size_t>& output) const; - Extent2D GetSceneExtent() const; + virtual Extent2D GetSceneExtent(bool minimal) const; virtual void Render(Orthanc::ImageAccessor& buffer, const AffineTransform2D& viewTransform, @@ -307,6 +307,7 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam); @@ -316,6 +317,7 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam); @@ -325,6 +327,7 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam); @@ -334,14 +337,16 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation); Orthanc::Image* ExportToImage(double pixelSpacingX, double pixelSpacingY, ImageInterpolation interpolation, + bool autoCrop, bool applyWindowing) { - return ExportToImage(pixelSpacingX, pixelSpacingY, interpolation, false, 0, applyWindowing); + return ExportToImage(pixelSpacingX, pixelSpacingY, interpolation, false, 0, autoCrop, applyWindowing); } Orthanc::Image* ExportToImage(double pixelSpacingX, @@ -349,11 +354,13 @@ ImageInterpolation interpolation, bool invert, int64_t maxValue /* for inversion */, + bool autoCrop, bool applyWindowing); void ExtractLayerFromRenderedScene(Orthanc::ImageAccessor& layer, const Orthanc::ImageAccessor& renderedScene, size_t layerIndex, + bool isCropped, ImageInterpolation interpolation); }; }
--- a/Framework/Radiography/RadiographyWidget.h Fri Apr 03 16:47:46 2020 +0200 +++ b/Framework/Radiography/RadiographyWidget.h Fri Apr 03 16:55:11 2020 +0200 @@ -54,7 +54,7 @@ protected: virtual Extent2D GetSceneExtent() { - return scene_->GetSceneExtent(); + return scene_->GetSceneExtent(false); } virtual bool RenderScene(CairoContext& context,