Mercurial > hg > orthanc-stone
changeset 1201:ab958fd99b07
RadiographyScene fixes
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Fri, 29 Nov 2019 16:21:24 +0100 |
parents | 922d2e61aa5d |
children | 9added0d371e |
files | Framework/Radiography/RadiographyAlphaLayer.cpp Framework/Radiography/RadiographyDicomLayer.cpp Framework/Radiography/RadiographyMaskLayer.cpp Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h Framework/Radiography/RadiographyTextLayer.cpp Framework/Radiography/RadiographyTextLayer.h |
diffstat | 7 files changed, 79 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyAlphaLayer.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyAlphaLayer.cpp Fri Nov 29 16:21:24 2019 +0100 @@ -79,15 +79,19 @@ Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); - t.Apply(tmp, cropped, interpolation, true /* clear */); + unsigned int x1, y1, x2, y2; - unsigned int x1, y1, x2, y2; - OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, - t.GetHomogeneousMatrix(), - cropped.GetWidth(), - cropped.GetHeight(), - buffer.GetWidth(), - buffer.GetHeight()); + if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, + t.GetHomogeneousMatrix(), + cropped.GetWidth(), + cropped.GetHeight(), + buffer.GetWidth(), + buffer.GetHeight())) + { + return; // layer is outside the buffer + } + + t.Apply(tmp, cropped, interpolation, true /* clear */); float value = foreground_;
--- a/Framework/Radiography/RadiographyDicomLayer.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyDicomLayer.cpp Fri Nov 29 16:21:24 2019 +0100 @@ -161,14 +161,18 @@ Orthanc::ImageAccessor cropped; converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); + unsigned int x1, y1, x2, y2; + if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, + t.GetHomogeneousMatrix(), + cropped.GetWidth(), + cropped.GetHeight(), + buffer.GetWidth(), + buffer.GetHeight())) + { + return; // layer is outside the buffer + } + t.Apply(buffer, cropped, interpolation, false); - unsigned int x1, y1, x2, y2; - OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, - t.GetHomogeneousMatrix(), - cropped.GetWidth(), - cropped.GetHeight(), - buffer.GetWidth(), - buffer.GetHeight()); if (applyWindowing) {
--- a/Framework/Radiography/RadiographyMaskLayer.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyMaskLayer.cpp Fri Nov 29 16:21:24 2019 +0100 @@ -112,15 +112,19 @@ Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); - t.Apply(tmp, cropped, ImageInterpolation_Nearest, true /* clear */); unsigned int x1, y1, x2, y2; - OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, - t.GetHomogeneousMatrix(), - cropped.GetWidth(), - cropped.GetHeight(), - buffer.GetWidth(), - buffer.GetHeight()); + if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, + t.GetHomogeneousMatrix(), + cropped.GetWidth(), + cropped.GetHeight(), + buffer.GetWidth(), + buffer.GetHeight())) + { + return; // layer is outside the buffer + } + + t.Apply(tmp, cropped, ImageInterpolation_Nearest, true /* clear */); // we have observed vertical lines at the image border (probably due to bilinear filtering of the DICOM image when it is not aligned with the buffer pixels) // -> draw the mask one line further on each side
--- a/Framework/Radiography/RadiographyScene.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.cpp Fri Nov 29 16:21:24 2019 +0100 @@ -243,6 +243,21 @@ } } + RadiographyLayer& RadiographyScene::GetLayer(size_t layerIndex) + { + Layers::const_iterator found = layers_.find(layerIndex); + + if (found == layers_.end()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + else + { + assert(found->second != NULL); + return *found->second; + } + } + bool RadiographyScene::GetWindowing(float& center, float& width) const { @@ -281,13 +296,27 @@ } + RadiographyLayer& RadiographyScene::UpdateText(size_t layerIndex, + const std::string& utf8, + unsigned int fontSize, + uint8_t foreground) + { + RadiographyTextLayer& textLayer = dynamic_cast<RadiographyTextLayer&>(GetLayer(layerIndex)); + textLayer.SetText(utf8, fontSize, foreground); + + BroadcastMessage(RadiographyScene::ContentChangedMessage(*this, textLayer)); + BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, textLayer)); + return textLayer; + } + + RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8, unsigned int fontSize, uint8_t foreground, RadiographyLayer::Geometry* geometry) { std::auto_ptr<RadiographyTextLayer> alpha(new RadiographyTextLayer(IObservable::GetBroker(), *this)); - alpha->LoadText(utf8, fontSize, foreground); + alpha->SetText(utf8, fontSize, foreground); if (geometry != NULL) { alpha->SetGeometry(*geometry);
--- a/Framework/Radiography/RadiographyScene.h Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.h Fri Nov 29 16:21:24 2019 +0100 @@ -179,6 +179,7 @@ void OnDicomWebReceived(const Deprecated::IWebService::HttpRequestSuccessMessage& message); virtual void OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message); + public: RadiographyScene(MessageBroker& broker); @@ -201,7 +202,12 @@ unsigned int fontSize, uint8_t foreground, RadiographyLayer::Geometry* geometry); - + + RadiographyLayer& UpdateText(size_t layerIndex, + const std::string& utf8, + unsigned int fontSize, + uint8_t foreground); + RadiographyLayer& LoadTestBlock(unsigned int width, unsigned int height, RadiographyLayer::Geometry* geometry); @@ -231,10 +237,12 @@ void RemoveLayer(size_t layerIndex); + RadiographyLayer& GetLayer(size_t layerIndex); + const RadiographyLayer& GetLayer(size_t layerIndex) const; template <typename TypeLayer> - TypeLayer* GetLayer(size_t index = 0) + TypeLayer* GetTypedLayer(size_t indexOfType = 0) { std::vector<size_t> layerIndexes; GetLayersIndexes(layerIndexes); @@ -246,31 +254,7 @@ TypeLayer* typedLayer = dynamic_cast<TypeLayer*>(layers_[layerIndexes[i]]); if (typedLayer != NULL) { - if (count == index) - { - return typedLayer; - } - count++; - } - } - - return NULL; - } - - template <typename TypeLayer> - const TypeLayer* GetLayer(size_t index = 0) const - { - std::vector<size_t> layerIndexes; - GetLayersIndexes(layerIndexes); - - size_t count = 0; - - for (size_t i = 0; i < layerIndexes.size(); ++i) - { - const TypeLayer* typedLayer = dynamic_cast<const TypeLayer*>(layers_.at(layerIndexes[i])); - if (typedLayer != NULL) - { - if (count == index) + if (count == indexOfType) { return typedLayer; }
--- a/Framework/Radiography/RadiographyTextLayer.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.cpp Fri Nov 29 16:21:24 2019 +0100 @@ -29,7 +29,7 @@ bool RadiographyTextLayer::fontHasBeenConfigured_ = false; Orthanc::EmbeddedResources::FileResourceId RadiographyTextLayer::fontResourceId_; - void RadiographyTextLayer::LoadText(const std::string& utf8, + void RadiographyTextLayer::SetText(const std::string& utf8, unsigned int fontSize, uint8_t foreground) { @@ -45,6 +45,8 @@ SetAlpha(TextRenderer::Render(fontResourceId_, fontSize_, text_)); + SetForegroundValue(foreground * 256.0f); } + }
--- a/Framework/Radiography/RadiographyTextLayer.h Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.h Fri Nov 29 16:21:24 2019 +0100 @@ -42,7 +42,7 @@ { } - void LoadText(const std::string& utf8, unsigned int fontSize, uint8_t foreground); + void SetText(const std::string& utf8, unsigned int fontSize, uint8_t foreground); const std::string& GetText() const {