# HG changeset patch # User Alain Mazy # Date 1584705133 -3600 # Node ID d4e6cd35107bcd1a4f83b0a5e5946e74c395731c # Parent d3c4f5e2b287f1c1d7ce3fbd6ec4d97620d61859 Clarified GetExtent/GetSceneExtent diff -r d3c4f5e2b287 -r d4e6cd35107b Framework/Radiography/RadiographyLayer.cpp --- a/Framework/Radiography/RadiographyLayer.cpp Mon Mar 02 18:29:50 2020 +0100 +++ b/Framework/Radiography/RadiographyLayer.cpp Fri Mar 20 12:52:13 2020 +0100 @@ -238,8 +238,7 @@ } } - - Extent2D RadiographyLayer::GetExtent() const + Extent2D RadiographyLayer::GetSceneExtent() const { Extent2D extent; @@ -251,6 +250,7 @@ double dwidth = static_cast(width); double dheight = static_cast(height); + // AddToExtent transforms the coordinates from image to scene AddToExtent(extent, dx, dy); AddToExtent(extent, dx + dwidth, dy); AddToExtent(extent, dx, dy + dheight); diff -r d3c4f5e2b287 -r d4e6cd35107b Framework/Radiography/RadiographyLayer.h --- a/Framework/Radiography/RadiographyLayer.h Mon Mar 02 18:29:50 2020 +0100 +++ b/Framework/Radiography/RadiographyLayer.h Fri Mar 20 12:52:13 2020 +0100 @@ -21,6 +21,8 @@ #pragma once +#include + #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(std::max(0.0, std::floor(imageCrop.GetX1()))), + static_cast(std::max(0.0, std::floor(imageCrop.GetY1()))), + std::min(width_, static_cast(std::ceil(imageCrop.GetWidth()))), + std::min(height_, static_cast(std::ceil(imageCrop.GetHeight()))) + ); + } + + void GetCrop(unsigned int& x, unsigned int& y, unsigned int& width, @@ -316,7 +344,7 @@ return height_; } - Extent2D GetExtent() const; + Extent2D GetSceneExtent() const; virtual bool GetPixel(unsigned int& imageX, unsigned int& imageY, diff -r d3c4f5e2b287 -r d4e6cd35107b Framework/Radiography/RadiographyMaskLayer.cpp --- a/Framework/Radiography/RadiographyMaskLayer.cpp Mon Mar 02 18:29:50 2020 +0100 +++ b/Framework/Radiography/RadiographyMaskLayer.cpp Fri Mar 20 12:52:13 2020 +0100 @@ -75,6 +75,23 @@ BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); } + Extent2D RadiographyMaskLayer::GetMaskMinimalSceneExtent() const + { + Extent2D sceneExtent; + + for (auto corner: corners_) + { + double x = static_cast(corner.GetX()); + double y = static_cast(corner.GetY()); + + dicomLayer_.GetTransform().Apply(x, y); + sceneExtent.AddPoint(x, y); + } + return sceneExtent; + } + + + void RadiographyMaskLayer::Render(Orthanc::ImageAccessor& buffer, const AffineTransform2D& viewTransform, ImageInterpolation interpolation, diff -r d3c4f5e2b287 -r d4e6cd35107b Framework/Radiography/RadiographyMaskLayer.h --- a/Framework/Radiography/RadiographyMaskLayer.h Mon Mar 02 18:29:50 2020 +0100 +++ b/Framework/Radiography/RadiographyMaskLayer.h Fri Mar 20 12:52:13 2020 +0100 @@ -100,6 +100,8 @@ cpScene = cp; } + Extent2D GetMaskMinimalSceneExtent() const; + virtual bool GetDefaultWindowing(float& center, float& width) const { diff -r d3c4f5e2b287 -r d4e6cd35107b Framework/Radiography/RadiographyScene.cpp --- a/Framework/Radiography/RadiographyScene.cpp Mon Mar 02 18:29:50 2020 +0100 +++ b/Framework/Radiography/RadiographyScene.cpp Fri Mar 20 12:52:13 2020 +0100 @@ -334,7 +334,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(); tlx = tlx - (textExtent.GetWidth() / 2) * centerGeometry->GetPixelSpacingX(); tly = tly - (textExtent.GetHeight() / 2) * centerGeometry->GetPixelSpacingY(); centerGeometry->SetPan(tlx, tly); @@ -551,7 +551,7 @@ it != layers_.end(); ++it) { assert(it->second != NULL); - extent.Union(it->second->GetExtent()); + extent.Union(it->second->GetSceneExtent()); } return extent; @@ -716,7 +716,7 @@ // wipe background before rendering if (GetPreferredPhotomotricDisplayMode() == RadiographyPhotometricDisplayMode_Monochrome1) { - Orthanc::ImageProcessing::Set(layers, 65535.0f); + Orthanc::ImageProcessing::Set(layers, 65535); } else { diff -r d3c4f5e2b287 -r d4e6cd35107b Framework/Radiography/RadiographyScene.h --- a/Framework/Radiography/RadiographyScene.h Mon Mar 02 18:29:50 2020 +0100 +++ b/Framework/Radiography/RadiographyScene.h Fri Mar 20 12:52:13 2020 +0100 @@ -280,7 +280,7 @@ void GetLayersIndexes(std::vector& output) const; - Extent2D GetSceneExtent() const; + virtual Extent2D GetSceneExtent() const; virtual void Render(Orthanc::ImageAccessor& buffer, const AffineTransform2D& viewTransform,