Mercurial > hg > orthanc-stone
changeset 1330:a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 30 Mar 2020 09:51:01 +0200 |
parents | d4e6cd35107b |
children | 35469f75faa2 0745bd7fdf70 |
files | Framework/Radiography/RadiographyDicomLayer.cpp Framework/Radiography/RadiographyLayer.cpp Framework/Radiography/RadiographyLayer.h Framework/Radiography/RadiographyMaskLayer.cpp Framework/Radiography/RadiographyMaskLayer.h Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h Framework/Radiography/RadiographyWidget.h |
diffstat | 8 files changed, 46 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyDicomLayer.cpp Fri Mar 20 12:52:13 2020 +0100 +++ b/Framework/Radiography/RadiographyDicomLayer.cpp Mon Mar 30 09:51:01 2020 +0200 @@ -107,9 +107,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 Mar 20 12:52:13 2020 +0100 +++ b/Framework/Radiography/RadiographyLayer.cpp Mon Mar 30 09:51:01 2020 +0200 @@ -238,7 +238,7 @@ } } - Extent2D RadiographyLayer::GetSceneExtent() const + Extent2D RadiographyLayer::GetSceneExtent(bool /*minimal*/) const { Extent2D extent;
--- a/Framework/Radiography/RadiographyLayer.h Fri Mar 20 12:52:13 2020 +0100 +++ b/Framework/Radiography/RadiographyLayer.h Mon Mar 30 09:51:01 2020 +0200 @@ -344,7 +344,7 @@ return height_; } - Extent2D GetSceneExtent() const; + virtual Extent2D GetSceneExtent(bool minimal) const; virtual bool GetPixel(unsigned int& imageX, unsigned int& imageY,
--- a/Framework/Radiography/RadiographyMaskLayer.cpp Fri Mar 20 12:52:13 2020 +0100 +++ b/Framework/Radiography/RadiographyMaskLayer.cpp Mon Mar 30 09:51:01 2020 +0200 @@ -75,19 +75,26 @@ BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); } - Extent2D RadiographyMaskLayer::GetMaskMinimalSceneExtent() const + Extent2D RadiographyMaskLayer::GetSceneExtent(bool minimal) const { - Extent2D sceneExtent; - - for (auto corner: corners_) + if (!minimal) { - double x = static_cast<double>(corner.GetX()); - double y = static_cast<double>(corner.GetY()); + return RadiographyLayer::GetSceneExtent(minimal); + } + else + { // get the extent of the in-mask area + Extent2D sceneExtent; - dicomLayer_.GetTransform().Apply(x, y); - sceneExtent.AddPoint(x, y); + 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; } - return sceneExtent; }
--- a/Framework/Radiography/RadiographyMaskLayer.h Fri Mar 20 12:52:13 2020 +0100 +++ b/Framework/Radiography/RadiographyMaskLayer.h Mon Mar 30 09:51:01 2020 +0200 @@ -100,7 +100,7 @@ cpScene = cp; } - Extent2D GetMaskMinimalSceneExtent() const; + virtual Extent2D GetSceneExtent(bool minimal) const; virtual bool GetDefaultWindowing(float& center, float& width) const
--- a/Framework/Radiography/RadiographyScene.cpp Fri Mar 20 12:52:13 2020 +0100 +++ b/Framework/Radiography/RadiographyScene.cpp Mon Mar 30 09:51:01 2020 +0200 @@ -334,7 +334,7 @@ // modify geometry to reference the top left corner double tlx = centerGeometry->GetPanX(); double tly = centerGeometry->GetPanY(); - Extent2D textExtent = alpha->GetSceneExtent(); + Extent2D textExtent = alpha->GetSceneExtent(false); tlx = tlx - (textExtent.GetWidth() / 2) * centerGeometry->GetPixelSpacingX(); tly = tly - (textExtent.GetHeight() / 2) * centerGeometry->GetPixelSpacingY(); centerGeometry->SetPan(tlx, tly); @@ -543,7 +543,7 @@ } - Extent2D RadiographyScene::GetSceneExtent() const + Extent2D RadiographyScene::GetSceneExtent(bool minimal) const { Extent2D extent; @@ -551,7 +551,7 @@ it != layers_.end(); ++it) { assert(it->second != NULL); - extent.Union(it->second->GetSceneExtent()); + extent.Union(it->second->GetSceneExtent(minimal)); } return extent; @@ -663,9 +663,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(); @@ -687,6 +688,7 @@ ImageInterpolation interpolation, bool invert, int64_t maxValue /* for inversion */, + bool autoCrop, bool applyWindowing) { if (pixelSpacingX <= 0 || @@ -695,7 +697,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); @@ -742,11 +744,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; @@ -795,13 +798,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; @@ -840,12 +844,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, @@ -864,6 +869,7 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam) { @@ -883,7 +889,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 Mar 20 12:52:13 2020 +0100 +++ b/Framework/Radiography/RadiographyScene.h Mon Mar 30 09:51:01 2020 +0200 @@ -280,7 +280,7 @@ void GetLayersIndexes(std::vector<size_t>& output) const; - virtual Extent2D GetSceneExtent() const; + virtual Extent2D GetSceneExtent(bool minimal) const; virtual void Render(Orthanc::ImageAccessor& buffer, const AffineTransform2D& viewTransform, @@ -306,6 +306,7 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam); @@ -315,6 +316,7 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam); @@ -324,6 +326,7 @@ double pixelSpacingX, double pixelSpacingY, bool invert, + bool autoCrop, ImageInterpolation interpolation, bool usePam); @@ -333,14 +336,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, @@ -348,11 +353,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 Mar 20 12:52:13 2020 +0100 +++ b/Framework/Radiography/RadiographyWidget.h Mon Mar 30 09:51:01 2020 +0200 @@ -53,7 +53,7 @@ protected: virtual Extent2D GetSceneExtent() { - return scene_->GetSceneExtent(); + return scene_->GetSceneExtent(false); } virtual bool RenderScene(CairoContext& context,