Mercurial > hg > orthanc-stone
changeset 1321:d4e6cd35107b
Clarified GetExtent/GetSceneExtent
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Fri, 20 Mar 2020 12:52:13 +0100 |
parents | d3c4f5e2b287 |
children | a72c2c9af49a |
files | Framework/Radiography/RadiographyLayer.cpp Framework/Radiography/RadiographyLayer.h Framework/Radiography/RadiographyMaskLayer.cpp Framework/Radiography/RadiographyMaskLayer.h Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h |
diffstat | 6 files changed, 55 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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<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 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 <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; + Extent2D GetSceneExtent() const; virtual bool GetPixel(unsigned int& imageX, unsigned int& imageY,
--- 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<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 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 {
--- 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 {
--- 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<size_t>& output) const; - Extent2D GetSceneExtent() const; + virtual Extent2D GetSceneExtent() const; virtual void Render(Orthanc::ImageAccessor& buffer, const AffineTransform2D& viewTransform,